Skip to content

Commit

Permalink
Populate address fields & phone number (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
akileng56 authored Oct 31, 2023
1 parent a463625 commit 2cebbec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ export function handleRegistryResponse(clientResponse: RegistryResponse, props:
});
} else if (clientResponse?.total === 1) {
const {
resource: { identifier, name, gender, birthDate, address },
resource: { identifier, name, gender, birthDate, address, telecom },
} = clientResponse.entry[0];

const { family, given } = name[0];

const { city, country } = address[0];

let patientUIC;
identifier?.map((id) => {
if (id['type']['text'] === 'Patient Unique ID Code (UIC)') {
Expand Down Expand Up @@ -79,11 +77,11 @@ export function handleRegistryResponse(clientResponse: RegistryResponse, props:
givenName: given[0],
gender: gender === 'male' ? 'Male' : 'Female',
birthdate: new Date(birthDate),
address: {
address1: city,
country: country,
},
address: getAddress(address),
identifiers: { ...props.values.identifiers, ...(emrIdentifier ?? {}) },
attributes: {
'14d4f066-15f5-102d-96e4-000c29c2a5d7': telecom?.find((item) => item.system === 'phone')?.value,
},
});
dispose();
},
Expand All @@ -94,10 +92,9 @@ export function handleRegistryResponse(clientResponse: RegistryResponse, props:
let patientData = [];
clientResponse?.entry?.map((registryPatient) => {
const {
resource: { name, gender, birthDate, address },
resource: { name, gender, birthDate, address, telecom },
} = registryPatient;
const { family, given } = name[0];
const { city, country } = address[0];

patientData.push({
names: `${family} ${given}`,
Expand All @@ -112,11 +109,11 @@ export function handleRegistryResponse(clientResponse: RegistryResponse, props:
givenName: given[0],
gender: gender === 'male' ? 'Male' : 'Female',
birthdate: new Date(birthDate),
address: {
address1: city,
country: country,
},
address: getAddress(address),
identifiers: { ...props.values.identifiers },
attributes: {
'14d4f066-15f5-102d-96e4-000c29c2a5d7': telecom?.find((item) => item.system === 'phone')?.value,
},
});
dispose();
}),
Expand All @@ -131,7 +128,33 @@ export function handleRegistryResponse(clientResponse: RegistryResponse, props:
}
}

const extractAddress = function (formAddressValue) {
const getAddress = (address) => {
const { extension, district, country } = address[0];

const county = extension[0].extension.find(
(ext) => ext.url === 'http://fhir.openmrs.org/ext/address#county',
)?.valueString;
const subcounty = extension[0].extension.find(
(ext) => ext.url === 'http://fhir.openmrs.org/ext/address#subcounty',
)?.valueString;
const parish = extension[0].extension.find(
(ext) => ext.url === 'http://fhir.openmrs.org/ext/address#parish',
)?.valueString;
const village = extension[0].extension.find(
(ext) => ext.url === 'http://fhir.openmrs.org/ext/address#village',
)?.valueString;

return {
country: country,
countyDistrict: district,
stateProvince: county,
address3: subcounty,
address4: parish,
address5: village,
};
};

const extractAddress = (formAddressValue) => {
let address: Address = {
extension: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export interface CRPatientDetails {
city: string;
country: string;
}>;

telecom?: Array<{
system: string;
value: string;
}>;
managingOrganization?: {
reference: string;
type: string;
Expand Down

0 comments on commit 2cebbec

Please sign in to comment.