Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) : Adapt response type from HIE to registration form structure #49

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
private mapTelecomToAttributes(telecom: Array<fhir.ContactPoint>): Record<string, string> {
return telecom.reduce<Record<string, string>>((acc, { system, value }) => {
if (system && value && this.config.teleComMap[system]) {
const filteredValue = value.replace(/^254/, '0');
const filteredValue = value.replace(/^\+254/, '0');
if (filteredValue) {
acc[this.config.teleComMap[system]] = filteredValue;
}
Expand All @@ -75,22 +75,24 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
currentFormValues: FormValues,
): Record<string, PatientIdentifierValue> {
const updatedIdentifiers: Record<string, PatientIdentifierValue> = { ...currentFormValues.identifiers };

// Map Social Health Authority Unique Identification Number to HIE Patient ID
// See https://github.com/palladiumkenya/openmrs-module-kenyaemr/blob/1e1d281eaba8041c45318e60ca0730449b8e4197/api/src/main/distro/metadata/identifierTypes.xml#L33
updatedIdentifiers.socialHealthAuthorityIdentificationNumber = {
...currentFormValues.identifiers['socialHealthAuthorityIdentificationNumber'],
updatedIdentifiers.socialHealthInsuranceNumber = {
...currentFormValues.identifiers['socialHealthInsuranceNumber'],
identifierValue: hiePatient.id,
};

// Map fhir.Patient.Identifier to identifiers
hiePatient.identifier?.forEach((identifier) => {
const system = identifier.system?.split('/').pop();
if (system && this.config.identifierMap[system]) {
const key = this.config.identifierMap[system];
updatedIdentifiers[key] = {
...currentFormValues.identifiers[key],
identifierValue: identifier.value || '',
hiePatient.identifier?.forEach((identifier: fhir.Identifier) => {
const identifierType = identifier.type?.coding?.[0]?.code;
const mappedIdentifierType = this.convertToCamelCase(identifierType);
const identifierValue = identifier.value;

const existingIdentifier = currentFormValues.identifiers[mappedIdentifierType];
if (existingIdentifier) {
updatedIdentifiers[mappedIdentifierType] = {
...existingIdentifier,
identifierValue,
};
}
});
Expand All @@ -117,6 +119,13 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
return acc;
}, {});
}

private convertToCamelCase(input: string): string {
return input
.split('-')
.map((word, index) => (index === 0 ? word : capitalize(word)))
.join('');
}
}

// Update MapperConfig interface in hie-types.ts
Expand Down
Loading