-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#114): Create OpenMRS Mediator for Patient resource
- Loading branch information
Showing
5 changed files
with
71 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
import joi from 'joi'; | ||
|
||
export const PatientSchema = joi.object({ | ||
identifier: joi | ||
.array() | ||
.items( | ||
joi.object({ | ||
system: joi.string().valid('cht').required(), | ||
value: joi.string().uuid().required(), | ||
}) | ||
) | ||
.min(1) | ||
.required(), | ||
name: joi | ||
.array() | ||
.items( | ||
joi.object({ | ||
family: joi.string().required(), | ||
given: joi.array().length(1).required(), | ||
}) | ||
) | ||
.min(1) | ||
.required(), | ||
id: joi.string().uuid().required(), | ||
name: joi.string().required(), | ||
gender: joi.string().required(), | ||
birthDate: joi.string().required(), | ||
phone: joi.string().required(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { randomUUID } from 'crypto'; | ||
|
||
interface OpenMRSIdentifier extends fhir4.Identifier { | ||
id: string //uuid | ||
} | ||
|
||
interface OpenMRSHumanName extends fhir4.HumanName { | ||
id: string //uuid | ||
} | ||
|
||
const phoneIdentifierType: fhir4.CodeableConcept = { | ||
text: 'Phone Number' | ||
} | ||
|
||
const chtIdentifierType: fhir4.CodeableConcept = { | ||
text: 'CHT ID' | ||
} | ||
|
||
export function buildOpenMRSPatient(chtPatient: Record<string, any>): fhir4.Patient { | ||
const nameParts = chtPatient.name.split(" "); | ||
const familyName = nameParts.pop() || ""; | ||
const givenNames = nameParts; | ||
|
||
const name: OpenMRSHumanName = { | ||
family: familyName, | ||
given: givenNames, | ||
id: randomUUID(), | ||
}; | ||
|
||
const phoneIdentifier: OpenMRSIdentifier = { | ||
id: randomUUID(), | ||
type: phoneIdentifierType, | ||
value: chtPatient.phone, | ||
use: 'usual' | ||
}; | ||
|
||
const chtIdentifier: OpenMRSIdentifier = { | ||
id: randomUUID(), | ||
type: chtIdentifierType, | ||
value: chtPatient.id, | ||
system: 'cht', | ||
use: 'official' | ||
}; | ||
|
||
const patient: fhir4.Patient = { | ||
resourceType: 'Patient', | ||
name: [name], | ||
birthDate: chtPatient.birthDate, | ||
id: chtPatient.id, | ||
identifier: [phoneIdentifier, chtIdentifier], | ||
gender: chtPatient.gender | ||
}; | ||
|
||
return patient; | ||
} |