Skip to content

Commit b5fa4bc

Browse files
authored
Merge pull request AMPATH#9 from jecihjoy/address-breaking-changes
Mapping of Omrs data models to Fhir resources
2 parents 2629b0c + 61d1209 commit b5fa4bc

19 files changed

Lines changed: 792 additions & 216 deletions

api/src/main/java/org/openmrs/module/interop/InteropConstant.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public class InteropConstant {
5353

5454
public static String ALLERGY_SEVERITY_SEVERE_CONCEPT_UUID = "interop.allergyReactionSevere";
5555

56-
public static String DIAGNOSIS_TREATMENT_PLAN_CONCEPT_UUID = "interop.treatmentPlan";
56+
public static String DIAGNOSIS_CONCEPTS = "interop.diagnosisConcepts";
57+
58+
public static String DIAGNOSIS_ENCOUNTER_TYPES = "interop.encounterTypes.diagnosis";
5759

5860
public static String LAB_RESULT_PROCESSOR_ENCOUNTER_TYPE_UUIDS = "interop.encounterTypes.labResults";
5961

@@ -77,6 +79,14 @@ public class InteropConstant {
7779

7880
public static String DEFAULT_FACILITY = "kenyaemr.defaultLocation";
7981

82+
public static String VITALS_PROCESSOR_ENCOUNTER_TYPE_UUIDS = "interop.encounterTypes.vitals";
83+
84+
public static String VITAL_CONCEPT_UUIDS = "interop.vitalsConcepts";
85+
86+
public static String COMPLAINTS_PROCESSOR_ENCOUNTER_TYPE_UUIDS = "interop.encounterTypes.complaints";
87+
88+
public static String COMPLAINTS_CONCEPT_UUIDS = "interop.complaintsConcepts";
89+
8090
public static final String GP_SHR_TOKEN = "interop.shr.token";
8191

8292
public static final String GP_SHR_TOKEN_URL = "interop.shr.token.url";

api/src/main/java/org/openmrs/module/interop/api/observers/AllergyObserver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public void onMessage(Message message) {
5050
private void prepareAllergyMessage(@NotNull EventMetadata metadata) {
5151
org.hl7.fhir.r4.model.AllergyIntolerance allergyIntolerance = allergyIntoleranceService
5252
.get(metadata.getString("uuid"));
53-
if (allergyIntolerance != null) {
53+
if (allergyIntolerance != null && !allergyIntolerance.getReaction().isEmpty()
54+
&& !(allergyIntolerance.getReactionFirstRep().getManifestation().isEmpty())) {
5455
this.publish(allergyIntolerance);
5556
} else {
56-
log.error("Couldn't find allergy with UUID {} ", metadata.getString("uuid"));
57+
log.error("Couldn't find allergy with UUID {} or resource missing required properties",
58+
metadata.getString("uuid"));
5759
}
5860
}
5961
}

api/src/main/java/org/openmrs/module/interop/api/observers/ConditionObserver.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
55
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6-
* <p>
6+
*
77
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
88
* graphic logo is a trademark of OpenMRS Inc.
99
*/
@@ -28,33 +28,33 @@
2828
@Slf4j
2929
@Component("interop.conditionCreationObserver")
3030
public class ConditionObserver extends BaseObserver implements Subscribable<Condition> {
31-
32-
@Autowired
33-
private InteropConditionTranslator<Condition> conditionTranslator;
34-
35-
@Override
36-
public Class<?> clazz() {
37-
return Condition.class;
38-
}
39-
40-
@Override
41-
public List<Event.Action> actions() {
42-
return ObserverUtils.defaultActions();
43-
}
44-
45-
@Override
46-
public void onMessage(Message message) {
47-
processMessage(message)
48-
.ifPresent(metadata -> Daemon.runInDaemonThread(() -> prepareConditionsMessage(metadata), getDaemonToken()));
49-
}
50-
51-
private void prepareConditionsMessage(@NotNull EventMetadata metadata) {
52-
Condition condition = Context.getConditionService().getConditionByUuid(metadata.getString("uuid"));
53-
org.hl7.fhir.r4.model.Condition fhirCondition = conditionTranslator.toFhirResource(condition);
54-
if (fhirCondition != null) {
55-
this.publish(fhirCondition);
56-
} else {
57-
log.error("Couldn't find condition with UUID {} ", metadata.getString("uuid"));
58-
}
59-
}
31+
32+
@Autowired
33+
private InteropConditionTranslator<Condition> conditionTranslator;
34+
35+
@Override
36+
public Class<?> clazz() {
37+
return Condition.class;
38+
}
39+
40+
@Override
41+
public List<Event.Action> actions() {
42+
return ObserverUtils.defaultActions();
43+
}
44+
45+
@Override
46+
public void onMessage(Message message) {
47+
processMessage(message)
48+
.ifPresent(metadata -> Daemon.runInDaemonThread(() -> prepareConditionsMessage(metadata), getDaemonToken()));
49+
}
50+
51+
private void prepareConditionsMessage(@NotNull EventMetadata metadata) {
52+
Condition condition = Context.getConditionService().getConditionByUuid(metadata.getString("uuid"));
53+
org.hl7.fhir.r4.model.Condition fhirCondition = conditionTranslator.toFhirResource(condition);
54+
if (fhirCondition != null) {
55+
this.publish(fhirCondition);
56+
} else {
57+
log.error("Couldn't find condition with UUID {} ", metadata.getString("uuid"));
58+
}
59+
}
6060
}

api/src/main/java/org/openmrs/module/interop/api/observers/DiagnosisObserver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.openmrs.module.interop.api.observers;
1111

1212
import lombok.extern.slf4j.Slf4j;
13+
import org.openmrs.ConditionVerificationStatus;
1314
import org.openmrs.Diagnosis;
1415
import org.openmrs.api.context.Context;
1516
import org.openmrs.api.context.Daemon;
@@ -50,6 +51,8 @@ public void onMessage(Message message) {
5051

5152
private void prepareDiagnosisMessage(@NotNull EventMetadata metadata) {
5253
Diagnosis diagnosis = Context.getDiagnosisService().getDiagnosisByUuid(metadata.getString("uuid"));
54+
if (diagnosis.getCertainty() == null || diagnosis.getCertainty().equals(ConditionVerificationStatus.PROVISIONAL))
55+
return;
5356
org.hl7.fhir.r4.model.Condition fhirCondition = diagnosisTranslator.toFhirResource(diagnosis);
5457
if (fhirCondition != null) {
5558
this.publish(fhirCondition);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.interop.api.observers;
11+
12+
import lombok.extern.slf4j.Slf4j;
13+
import org.hl7.fhir.r4.model.Medication;
14+
import org.openmrs.DrugOrder;
15+
import org.openmrs.Order;
16+
import org.openmrs.api.context.Context;
17+
import org.openmrs.api.context.Daemon;
18+
import org.openmrs.event.Event;
19+
import org.openmrs.module.fhir2.api.translators.MedicationTranslator;
20+
import org.openmrs.module.interop.api.Subscribable;
21+
import org.openmrs.module.interop.api.metadata.EventMetadata;
22+
import org.openmrs.module.interop.utils.ObserverUtils;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.stereotype.Component;
25+
26+
import javax.jms.Message;
27+
import javax.validation.constraints.NotNull;
28+
import java.util.List;
29+
30+
@Slf4j
31+
@Component("interop.drugOrderObserver")
32+
public class DrugOrderObserver extends BaseObserver implements Subscribable<Order> {
33+
34+
@Autowired
35+
private MedicationTranslator medicationTranslator;
36+
37+
@Override
38+
public Class<?> clazz() {
39+
return Order.class;
40+
}
41+
42+
@Override
43+
public List<Event.Action> actions() {
44+
return ObserverUtils.defaultActions();
45+
}
46+
47+
@Override
48+
public void onMessage(Message message) {
49+
processMessage(message)
50+
.ifPresent(metadata -> Daemon.runInDaemonThread(() -> prepareDrugMessage(metadata), getDaemonToken()));
51+
}
52+
53+
private void prepareDrugMessage(@NotNull EventMetadata metadata) {
54+
Order drugOrder = Context.getOrderService().getOrderByUuid(metadata.getString("uuid"));
55+
if (drugOrder.getOrderType().getUuid().equals("131168f4-15f5-102d-96e4-000c29c2a5d7")) {
56+
DrugOrder order = (DrugOrder) drugOrder;
57+
Medication medication = medicationTranslator.toFhirResource(order.getDrug());
58+
if (medication != null) {
59+
this.publish(medication);
60+
} else {
61+
log.error("Couldn't find allergy with UUID {} ", metadata.getString("uuid"));
62+
}
63+
}
64+
}
65+
}

api/src/main/java/org/openmrs/module/interop/api/observers/EncounterObserver.java

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
import org.openmrs.module.interop.api.metadata.EventMetadata;
3737
import org.openmrs.module.interop.api.processors.AllergyIntoleranceProcessor;
3838
import org.openmrs.module.interop.api.processors.AppointmentProcessor;
39+
import org.openmrs.module.interop.api.processors.ComplaintsProcessor;
3940
import org.openmrs.module.interop.api.processors.ConditionProcessor;
41+
import org.openmrs.module.interop.api.processors.DiagnosisProcessor;
4042
import org.openmrs.module.interop.api.processors.DiagnosticReportProcessor;
4143
import org.openmrs.module.interop.api.processors.ServiceRequestProcessor;
44+
import org.openmrs.module.interop.api.processors.LabResultsProcessor;
45+
import org.openmrs.module.interop.api.processors.VitalsProcessor;
4246
import org.openmrs.module.interop.api.processors.translators.AppointmentRequestTranslator;
4347
import org.openmrs.module.interop.utils.ObserverUtils;
4448
import org.openmrs.module.interop.utils.ReferencesUtil;
@@ -73,6 +77,9 @@ public class EncounterObserver extends BaseObserver implements Subscribable<org.
7377
@Autowired
7478
private ConditionProcessor conditionProcessor;
7579

80+
@Autowired
81+
private DiagnosisProcessor diagnosisProcessor;
82+
7683
@Autowired
7784
@Qualifier("interop.appointmentProcessor")
7885
private AppointmentProcessor appointmentProcessor;
@@ -87,11 +94,18 @@ public class EncounterObserver extends BaseObserver implements Subscribable<org.
8794
@Autowired
8895
private AllergyIntoleranceProcessor allergyIntoleranceProcessor;
8996

97+
@Autowired
98+
private VitalsProcessor vitalsProcessor;
99+
100+
@Autowired
101+
private ComplaintsProcessor complaintsProcessor;
102+
90103
@Autowired
91104
private ServiceRequestProcessor serviceRequestProcessor;
92105

93106
@Autowired
94107
private ConceptTranslator conceptTranslator;
108+
private LabResultsProcessor labResultsProcessor;
95109

96110
@Override
97111
public Class<?> clazz() {
@@ -143,14 +157,17 @@ private void prepareEncounterMessage(@NotNull EventMetadata metadata) {
143157
//Observations
144158
List<Obs> encounterObservations = new ArrayList<>(encounter.getObs());
145159
/*for (Obs obs : encounterObservations) {
160+
//Observations - Only enable this when you want to send all form obs as Fhir observations
161+
/**List<Obs> encounterObservations = new ArrayList<>(encounter.getObs());
162+
for (Obs obs : encounterObservations) {
146163
Observation fhirObs = observationTranslator.toFhirResource(obs);
147164
fhirObs.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
148-
165+
149166
// provence references
150167
List<Resource> resources = ReferencesUtil.resolveProvenceReference(fhirObs.getContained(), encounter);
151168
fhirObs.getContained().clear();
152169
//fhirObs.setContained(resources);
153-
170+
154171
Bundle.BundleEntryComponent obsBundleEntry = new Bundle.BundleEntryComponent();
155172
Bundle.BundleEntryRequestComponent requestComponent = new Bundle.BundleEntryRequestComponent();
156173
requestComponent.setMethod(Bundle.HTTPVerb.PUT);
@@ -159,6 +176,55 @@ private void prepareEncounterMessage(@NotNull EventMetadata metadata) {
159176
obsBundleEntry.setResource(fhirObs);
160177
preparedBundle.addEntry(obsBundleEntry);
161178
}*/
179+
/**
180+
* List<Obs> encounterObservations = new ArrayList<>(encounter.getObs()); for (Obs obs :
181+
* encounterObservations) { Observation fhirObs = observationTranslator.toFhirResource(obs);
182+
* fhirObs.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient())); // provence
183+
* references List<Resource> resources =
184+
* ReferencesUtil.resolveProvenceReference(fhirObs.getContained(), encounter);
185+
* fhirObs.getContained().clear(); //fhirObs.setContained(resources); Bundle.BundleEntryComponent
186+
* obsBundleEntry = new Bundle.BundleEntryComponent(); Bundle.BundleEntryRequestComponent
187+
* requestComponent = new Bundle.BundleEntryRequestComponent();
188+
* requestComponent.setMethod(Bundle.HTTPVerb.PUT); requestComponent.setUrl("Observation/" +
189+
* fhirObs.getId()); obsBundleEntry.setRequest(requestComponent);
190+
* obsBundleEntry.setResource(fhirObs); preparedBundle.addEntry(obsBundleEntry); }
191+
**/
192+
193+
//Vital obs
194+
List<Observation> vitalsObs = vitalsProcessor.process(encounter);
195+
for (Observation obs : vitalsObs) {
196+
Bundle.BundleEntryComponent obsBundleEntry = new Bundle.BundleEntryComponent();
197+
Bundle.BundleEntryRequestComponent requestComponent = new Bundle.BundleEntryRequestComponent();
198+
requestComponent.setMethod(Bundle.HTTPVerb.PUT);
199+
requestComponent.setUrl("Observation/" + obs.getId());
200+
obsBundleEntry.setRequest(requestComponent);
201+
obsBundleEntry.setResource(obs);
202+
preparedBundle.addEntry(obsBundleEntry);
203+
}
204+
205+
//Complaints obs
206+
List<Observation> complaintsObs = complaintsProcessor.process(encounter);
207+
for (Observation obs : complaintsObs) {
208+
Bundle.BundleEntryComponent obsBundleEntry = new Bundle.BundleEntryComponent();
209+
Bundle.BundleEntryRequestComponent requestComponent = new Bundle.BundleEntryRequestComponent();
210+
requestComponent.setMethod(Bundle.HTTPVerb.PUT);
211+
requestComponent.setUrl("Observation/" + obs.getId());
212+
obsBundleEntry.setRequest(requestComponent);
213+
obsBundleEntry.setResource(obs);
214+
preparedBundle.addEntry(obsBundleEntry);
215+
}
216+
217+
//Lab results obs
218+
List<Observation> labResultsObs = labResultsProcessor.process(encounter);
219+
for (Observation obs : labResultsObs) {
220+
Bundle.BundleEntryComponent obsBundleEntry = new Bundle.BundleEntryComponent();
221+
Bundle.BundleEntryRequestComponent requestComponent = new Bundle.BundleEntryRequestComponent();
222+
requestComponent.setMethod(Bundle.HTTPVerb.PUT);
223+
requestComponent.setUrl("Observation/" + obs.getId());
224+
obsBundleEntry.setRequest(requestComponent);
225+
obsBundleEntry.setResource(obs);
226+
preparedBundle.addEntry(obsBundleEntry);
227+
}
162228

163229
this.processFhirResources(encounter, preparedBundle);
164230
this.publish(preparedBundle);
@@ -295,14 +361,17 @@ private void processFhirResources(@Nonnull Encounter encounter, @NotNull Bundle
295361
condition.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
296362
condition.getRecorder().setIdentifier(buildProviderIdentifier(encounter));
297363
condition.setEncounter(encounterReferenceTranslator.toFhirResource(encounter));
298-
299-
List<Resource> resources = ReferencesUtil.resolveProvenceReference(condition.getContained(), encounter);
300-
condition.getContained().clear();
301-
//condition.setContained(resources);
302-
303364
bundle.addEntry(buildConditionBundleEntry(condition));
304365
});
305366
367+
List<Condition> diagnosis = diagnosisProcessor.process(encounter);
368+
diagnosis.forEach(d -> {
369+
d.setSubject(ReferencesUtil.buildPatientReference(encounter.getPatient()));
370+
d.getRecorder().setIdentifier(buildProviderIdentifier(encounter));
371+
d.setEncounter(encounterReferenceTranslator.toFhirResource(encounter));
372+
bundle.addEntry(buildConditionBundleEntry(d));
373+
});
374+
306375
List<Appointment> appointments = appointmentProcessor.process(encounter);
307376
if (!appointments.isEmpty()) {
308377
ServiceRequest serviceRequest = appointmentRequestTranslator.toFhirResource(encounter);

api/src/main/java/org/openmrs/module/interop/api/processors/AllergyIntoleranceProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public List<AllergyIntolerance> process(Encounter encounter) {
122122
});
123123

124124
allergy.addReaction(reactionComponent);
125-
allergyIntolerances.add(allergy);
125+
if (allergy != null && !allergy.getReaction().isEmpty()
126+
&& !(allergy.getReactionFirstRep().getManifestation().isEmpty())) {
127+
allergyIntolerances.add(allergy);
128+
}
126129
});
127130
}
128131

0 commit comments

Comments
 (0)