Skip to content

Commit f8b0677

Browse files
authored
chore: map ranking a rank y visceversa (#29)
1 parent 79b7d0b commit f8b0677

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/lib/patient.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ function mapEstadoCivilFHIRToAndes(estadoCivil?: string): string {
118118
}
119119
}
120120

121+
function mapAndesRankingToFhirRank(andesRanking?: number): number {
122+
return typeof andesRanking === 'number' && Number.isInteger(andesRanking) && andesRanking >= 0
123+
? andesRanking + 1
124+
: 1;
125+
}
126+
127+
function mapFhirRankToAndesRanking(fhirRank?: number): number {
128+
return typeof fhirRank === 'number' && Number.isInteger(fhirRank) && fhirRank > 0
129+
? fhirRank - 1
130+
: 0;
131+
}
132+
133+
121134
/**
122135
* Encode a patient from ANDES to FHIR
123136
*/
@@ -170,7 +183,7 @@ export function encode(patient: AndesPatient | null | undefined): Patient | null
170183
.map((unContacto: AndesContacto): ContactPoint => {
171184
const cont: ContactPoint = {
172185
value: unContacto.valor,
173-
rank: unContacto.ranking
186+
rank: mapAndesRankingToFhirRank(unContacto.ranking)
174187
};
175188

176189
switch (unContacto.tipo) {
@@ -357,7 +370,7 @@ export function decode(patient: Patient): AndesPatient {
357370
? patient.telecom.map((unContacto: ContactPoint) => {
358371
const cont: any = {
359372
valor: unContacto.value,
360-
ranking: unContacto.rank
373+
ranking: mapFhirRankToAndesRanking(unContacto.rank)
361374
};
362375
switch (unContacto.system) {
363376
case 'phone':

0 commit comments

Comments
 (0)