Skip to content

Commit

Permalink
Merge pull request AMPATH#4 from jecihjoy/enhancements
Browse files Browse the repository at this point in the history
Update patients and facilities reference to use CR and Khmfl respectively
  • Loading branch information
patryllus authored Aug 29, 2023
2 parents cf13be1 + e495a64 commit a1ff357
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class InteropConstant {

public static String SYSTEM_URL = "interop.system.url.configuration";

public static String CR_SYSTEM_URL = "interop.cr.system.url.configuration";

public static String KMHFL_SYSTEM_URL = "interop.kmhfl.system.url.configuration";

public static String APPOINTMENT_PROCESSOR_ENCOUNTER_TYPE_UUIDS = "interop.encounterTypes.appointments";

public static String APPOINTMENT_WITH_CODED_TYPES = "interop.appointmentWithCodedTypes";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ private void prepareEncounterMessage(@NotNull EventMetadata metadata) {
Bundle preparedBundle = new Bundle();

org.hl7.fhir.r4.model.Encounter fhirEncounter = encounterTranslator.toFhirResource(encounter);
fhirEncounter.getSubject().setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));
fhirEncounter.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent locationComponent = new org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent();
ReferencesUtil.buildLocationReference(encounter.getLocation(), locationComponent.getLocation());
locationComponent.setLocation(ReferencesUtil.buildKhmflLocationReference(encounter.getLocation()));
fhirEncounter.setLocation(Collections.singletonList(locationComponent));
fhirEncounter.getParticipantFirstRep().getIndividual().setIdentifier(buildProviderIdentifier(encounter));

Expand All @@ -130,7 +130,7 @@ private void prepareEncounterMessage(@NotNull EventMetadata metadata) {
Observation fhirObs = observationTranslator.toFhirResource(obs);
fhirObs.addIdentifier(new Identifier().setSystem(InteropConstant.SYSTEM_URL).setValue(obs.getUuid())
.setUse(Identifier.IdentifierUse.OFFICIAL));
fhirObs.getSubject().setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));
fhirObs.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));

// provence references
List<Resource> resources = ReferencesUtil.resolveProvenceReference(fhirObs.getContained(), encounter);
Expand Down Expand Up @@ -205,7 +205,7 @@ private void processFhirResources(@Nonnull Encounter encounter, @NotNull Bundle

List<Condition> conditions = conditionProcessor.process(encounter);
conditions.forEach(condition -> {
condition.getSubject().setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));
condition.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
condition.getRecorder().setIdentifier(buildProviderIdentifier(encounter));
condition.setEncounter(encounterReferenceTranslator.toFhirResource(encounter));

Expand All @@ -223,21 +223,21 @@ private void processFhirResources(@Nonnull Encounter encounter, @NotNull Bundle
//appointment.setContained(resources);

for (Appointment.AppointmentParticipantComponent participantComponent : appointment.getParticipant()) {
participantComponent.getActor()
.setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));
participantComponent.setActor(ReferencesUtil.buildPatientReference(encounter.getPatient()));
}
bundle.addEntry(createAppointmentBundleComponent(appointment));
});

List<DiagnosticReport> diagnosticReports = diagnosticReportProcessor.process(encounter);
if (!diagnosticReports.isEmpty()) {
diagnosticReports.get(0).setEncounter(encounterReferenceTranslator.toFhirResource(encounter));
diagnosticReports.get(0).setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
bundle.addEntry(createDiagnosticReportComponent(diagnosticReports.get(0)));
}

List<AllergyIntolerance> allergyIntolerancesList = allergyIntoleranceProcessor.process(encounter);
allergyIntolerancesList.forEach(allergy -> {
allergy.getPatient().setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));
allergy.setPatient(ReferencesUtil.buildPatientReference(encounter.getPatient()));
allergy.setEncounter(encounterReferenceTranslator.toFhirResource(encounter));
bundle.addEntry(createAllergyComponent(allergy));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public DiagnosticReport toFhirResource(@Nonnull Encounter encounter) {
diagnosticReport.setEncounter(encounterReferenceTranslator.toFhirResource(encounter));
diagnosticReport.setIssued(encounter.getEncounterDatetime());
diagnosticReport.setSubject(patientReferenceTranslator.toFhirResource(encounter.getPatient()));
diagnosticReport.getSubject().setIdentifier(ReferencesUtil.buildPatientUpiIdentifier(encounter.getPatient()));

diagnosticReport.addResultsInterpreter(practitionerReferenceTranslator.toFhirResource(encounter.getCreator()));
diagnosticReport.getResultsInterpreterFirstRep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ public static String getSystemUrlConfiguration() {
return Context.getAdministrationService().getGlobalPropertyValue(InteropConstant.SYSTEM_URL, "");
}

public static String getCRSystemUrlConfiguration() {
return Context.getAdministrationService().getGlobalPropertyValue(InteropConstant.CR_SYSTEM_URL, "");
}

public static String getKhmflSystemUrlConfiguration() {
return Context.getAdministrationService().getGlobalPropertyValue(InteropConstant.KMHFL_SYSTEM_URL, "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openmrs.ProviderAttribute;
import org.openmrs.User;
import org.openmrs.api.context.Context;
import org.openmrs.module.interop.InteropConstant;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
Expand All @@ -46,6 +47,21 @@ public static void buildLocationReference(@NotNull Location location, @NotNull R
}
}

public static Reference buildKhmflLocationReference(@NotNull Location location) {
Reference locationRef = new Reference(ObserverUtils.getKhmflSystemUrlConfiguration()).setType("Organization");
if (ObserverUtils.getMFLCODELocationAttributeType() != null) {
String mflCodeUuid = ObserverUtils.getMFLCODELocationAttributeType().getUuid();
List<LocationAttribute> mflCodeAttribute = location.getActiveAttributes().stream()
.filter(loc -> loc.getAttributeType().getUuid().equals(mflCodeUuid)).collect(Collectors.toList());
if (!mflCodeAttribute.isEmpty()) {
locationRef.setIdentifier(new Identifier().setSystem(ObserverUtils.getKhmflSystemUrlConfiguration())
.setValue(mflCodeAttribute.get(0).getValue().toString()).setUse(Identifier.IdentifierUse.OFFICIAL));

}
}
return locationRef;
}

public static List<Resource> resolveProvenceReference(List<Resource> resources, @NotNull Encounter encounter) {
List<Resource> result = resources.stream().filter(resource -> resource.fhirType().equals("Provenance"))
.collect(Collectors.toList());
Expand Down Expand Up @@ -104,13 +120,14 @@ public static Identifier buildProviderIdentifierByUser(User user) {
return identifier;
}

public static Identifier buildPatientUpiIdentifier(@NotNull Patient patient) {
public static Reference buildPatientReference(@NotNull Patient patient) {
Reference reference = new Reference(ObserverUtils.getCRSystemUrlConfiguration()).setType("Patient");
Identifier identifier = new Identifier();
identifier.setSystem(ObserverUtils.getSystemUrlConfiguration());
identifier.setSystem(ObserverUtils.getCRSystemUrlConfiguration());
identifier.setUse(Identifier.IdentifierUse.OFFICIAL);
identifier.setValue(getPatientNUPI(patient));

return identifier;
reference.setIdentifier(identifier);
return reference;
}

private static String getPatientNUPI(Patient patient) {
Expand Down
10 changes: 10 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,15 @@
<description>coma separated list of treatment plan(concept questions)</description>
<defaultValue></defaultValue>
</globalProperty>
<globalProperty>
<property>@[email protected]</property>
<description>CR System Configuration URL</description>
<defaultValue>https://dhpstagingapi.health.go.ke/partners/registry/search/upi/</defaultValue>
</globalProperty>
<globalProperty>
<property>@[email protected]</property>
<description>KMHFL System Configuration URL</description>
<defaultValue>https://api.kmhfl.health.go.ke/api/</defaultValue>
</globalProperty>

</module>

0 comments on commit a1ff357

Please sign in to comment.