From 6d91d2646c9d5aa40c5e001e780b7b605d7a2dee Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:21:49 +0300 Subject: [PATCH 01/15] chore: Update Maven repository URLs in pom.xml --- pom.xml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index e8519eb..2239ddd 100644 --- a/pom.xml +++ b/pom.xml @@ -201,6 +201,11 @@ + + repsy + Maven Repository on Repsy + https://repo.repsy.io/mvn/intellisoftdev/default + openmrs-repo OpenMRS Nexus Repository @@ -229,18 +234,16 @@ github-packages - - github-packages - Github Maven Repo - https://maven.pkg.github.com/openmrs/openmrs-module-labonfhir - false - - github-packages - Github Maven Repo - https://maven.pkg.github.com/openmrs/openmrs-module-labonfhir - true + repsy + My Private Maven Repository on Repsy + https://repo.repsy.io/mvn/intellisoftdev/default + + repsy + My Private Maven Repository on Repsy + https://repo.repsy.io/mvn/intellisoftdev/default + From 40ada671ca494cd067ae9b68a83abca22f110617 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:22:31 +0300 Subject: [PATCH 02/15] [maven-release-plugin] prepare release 1.4.0 --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 49410d3..c2faf42 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index 750b938..df702fa 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-omod diff --git a/pom.xml b/pom.xml index 2239ddd..3e85857 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based @@ -22,7 +22,7 @@ scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git https://github.com/openmrs/openmrs-module-labonfhir/ - HEAD + 1.4.0 From 1fcbd51939f77d0dd777d057df6feef04b61769a Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:28:58 +0300 Subject: [PATCH 03/15] chore: Update labonfhir version to 1.4.0-SNAPSHOT --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c2faf42..49410d3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index df702fa..750b938 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT labonfhir-omod diff --git a/pom.xml b/pom.xml index 3e85857..df82aed 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based @@ -19,9 +19,9 @@ https://wiki.openmrs.org/x/FQ4z - scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git - scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git - https://github.com/openmrs/openmrs-module-labonfhir/ + scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git + scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git + https://bitbucket.org/botswana-emrs/openmrs-module-labonfhir 1.4.0 From 7098e54328acefe7af2cd73e17aa02a486f71b24 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:29:06 +0300 Subject: [PATCH 04/15] chore: Update .gitignore to include openmrs.log --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c44140..00d36d4 100644 --- a/.gitignore +++ b/.gitignore @@ -80,4 +80,5 @@ nb-configuration.xml ############################## .DS_Store -.flattened-pom.xml \ No newline at end of file +.flattened-pom.xml +openmrs.log From ad543432750370e016ea36239ee74ff9304de2d8 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:29:50 +0300 Subject: [PATCH 05/15] [maven-release-plugin] prepare release 1.4.0 --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 49410d3..c2faf42 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index 750b938..df702fa 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-omod diff --git a/pom.xml b/pom.xml index df82aed..dbd97b7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based From d7ca689ede44301fbe6f3075e83a8ad9af3f1bca Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:34:36 +0300 Subject: [PATCH 06/15] chore: Update labonfhir version to 1.4.0-SNAPSHOT --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c2faf42..49410d3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index df702fa..750b938 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT labonfhir-omod diff --git a/pom.xml b/pom.xml index dbd97b7..df82aed 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.0-SNAPSHOT pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based From 757659fd48aeaf6105663fa2037d330e22daeecf Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:35:18 +0300 Subject: [PATCH 07/15] [maven-release-plugin] prepare release 1.4.0 --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 49410d3..c2faf42 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index 750b938..df702fa 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 labonfhir-omod diff --git a/pom.xml b/pom.xml index df82aed..dbd97b7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0-SNAPSHOT + 1.4.0 pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based From 22287e135241449362498e24d83f9543e0da8d43 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:35:34 +0300 Subject: [PATCH 08/15] [maven-release-plugin] prepare for next development iteration --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c2faf42..c625ddd 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.1-SNAPSHOT labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index df702fa..7a062d6 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.1-SNAPSHOT labonfhir-omod diff --git a/pom.xml b/pom.xml index dbd97b7..bacd5bc 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.0 + 1.4.1-SNAPSHOT pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based From 8c572a1ff67884aee749774c3e97ac0a1c0af703 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:39:37 +0300 Subject: [PATCH 09/15] chore: Update Maven repository URLs in pom.xml --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index bacd5bc..8614025 100644 --- a/pom.xml +++ b/pom.xml @@ -257,4 +257,17 @@ 2.3.1 4.2.0 + + + + repsy + My Private Maven Repository on Repsy + https://repo.repsy.io/mvn/intellisoftdev/default + + + repsy + My Private Maven Repository on Repsy + https://repo.repsy.io/mvn/intellisoftdev/default + + From 135bd4d2f917b8fedfcf2308cb9f0de2d8823d13 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:40:22 +0300 Subject: [PATCH 10/15] [maven-release-plugin] prepare release 1.4.1 --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c625ddd..9aa6ef3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.1-SNAPSHOT + 1.4.1 labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index 7a062d6..03374c5 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.1-SNAPSHOT + 1.4.1 labonfhir-omod diff --git a/pom.xml b/pom.xml index 8614025..7de0645 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.1-SNAPSHOT + 1.4.1 pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based @@ -22,7 +22,7 @@ scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git https://bitbucket.org/botswana-emrs/openmrs-module-labonfhir - 1.4.0 + 1.4.1 From 3ed852be86ec6dfe3213667c1f7a381a2e6cc6d0 Mon Sep 17 00:00:00 2001 From: moshonk Date: Sun, 12 May 2024 05:40:39 +0300 Subject: [PATCH 11/15] [maven-release-plugin] prepare for next development iteration --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 9aa6ef3..2eecf0a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,7 +15,7 @@ org.openmrs.module labonfhir - 1.4.1 + 1.4.2-SNAPSHOT labonfhir-api diff --git a/omod/pom.xml b/omod/pom.xml index 03374c5..f041b82 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module labonfhir - 1.4.1 + 1.4.2-SNAPSHOT labonfhir-omod diff --git a/pom.xml b/pom.xml index 7de0645..b2fca3e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.openmrs.module labonfhir - 1.4.1 + 1.4.2-SNAPSHOT pom Lab on FHIR A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based @@ -22,7 +22,7 @@ scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git https://bitbucket.org/botswana-emrs/openmrs-module-labonfhir - 1.4.1 + 1.4.0 From cde44ab1e8ba50ae1a6abb97153e379921954bb9 Mon Sep 17 00:00:00 2001 From: moshonk Date: Tue, 14 May 2024 14:44:15 +0300 Subject: [PATCH 12/15] chore: Add MFL Code as location identifier in LabCreationListener --- .../api/event/LabCreationListener.java | 54 ++++++++++++++++--- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java index 8f07841..e0de003 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java @@ -1,6 +1,8 @@ package org.openmrs.module.labonfhir.api.event; import javax.jms.Message; + +import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -10,10 +12,16 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenParam; +import org.hl7.fhir.r4.model.Location; + import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.Task; +import org.openmrs.LocationAttribute; +import org.openmrs.LocationAttributeType; +import org.openmrs.api.LocationService; import org.openmrs.api.context.Daemon; import org.openmrs.event.EventListener; import org.openmrs.module.DaemonToken; @@ -31,6 +39,10 @@ public abstract class LabCreationListener implements EventListener { + private static final String MFL_LOCATION_IDENTIFIER_URI = "http://moh.bw.org/ext/location/identifier/mfl"; + + private static final String MFL_LOCATION_ATTRIBUTE_TYPE_UUID = "8a845a89-6aa5-4111-81d3-0af31c45c002"; + private static final Logger log = LoggerFactory.getLogger(EncounterCreationListener.class); private DaemonToken daemonToken; @@ -47,14 +59,17 @@ public abstract class LabCreationListener implements EventListener { private FhirContext ctx; @Autowired - FhirLocationService fhirLocationService ; + FhirLocationService fhirLocationService; @Autowired private FhirTaskService fhirTaskService; @Autowired - private LabOnFhirService labOnFhirService ; + private LabOnFhirService labOnFhirService; + @Autowired + private LocationService locationService; + public DaemonToken getDaemonToken() { return daemonToken; } @@ -70,8 +85,7 @@ public void onMessage(Message message) { Daemon.runInDaemonThread(() -> { try { processMessage(message); - } - catch (Exception e) { + } catch (Exception e) { log.error("Failed to update the user's last viewed patients property", e); } }, daemonToken); @@ -96,8 +110,35 @@ public Bundle createLabBundle(Task task) { if (!task.getLocation().isEmpty()) { labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getLocation().getReference()).get())); } + for (IBaseResource r : labResources) { Resource resource = (Resource) r; + + // if resource is location, add MFL Code as location identifier + // TODO: Short term: Make the MFL Location attribute type to be a Global config variable + // TODO: Long term: Make the location translator pick enrich the MFL Code as appropriate + + if (resource instanceof Location) { + Location location = (Location) resource; + if (location != null) { + org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId()); + if (openmrsLocation != null) { + LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID); + Collection locationAttributeTypes = openmrsLocation.getActiveAttributes(); + if (!locationAttributeTypes.isEmpty()) { + locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> { + String mflCode = (String) locationAttribute.getValue(); + + Identifier mflIdentifier = new Identifier(); + mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI); + mflIdentifier.setValue(mflCode); + location.addIdentifier(mflIdentifier); + }); + } + } + } + } + Bundle.BundleEntryComponent component = transactionBundle.addEntry(); component.setResource(resource); component.getRequest().setUrl(resource.fhirType() + "/" + resource.getIdElement().getIdPart()) @@ -113,8 +154,7 @@ protected void sendTask(Task task) { Bundle labBundle = createLabBundle(task); try { client.transaction().withBundle(labBundle).execute(); - } - catch (Exception e) { + } catch (Exception e) { saveFailedTask(task.getIdElement().getIdPart(), e.getMessage()); log.error("Failed to send Task with UUID " + task.getIdElement().getIdPart(), e); } @@ -123,7 +163,7 @@ protected void sendTask(Task task) { } } - private void saveFailedTask(String taskUuid ,String error) { + private void saveFailedTask(String taskUuid, String error) { FailedTask failedTask = new FailedTask(); failedTask.setError(error); failedTask.setIsSent(false); From 8c3c90d23de7b7d99427d86e202fd8f7186664e9 Mon Sep 17 00:00:00 2001 From: moshonk Date: Fri, 7 Jun 2024 02:50:41 +0300 Subject: [PATCH 13/15] Chore: Fixes to set Task requester as Organization. and to add location identifier --- .../module/labonfhir/api/LabOrderHandler.java | 50 +++++++++---------- .../api/event/LabCreationListener.java | 19 ++++--- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java index cfbd8a2..586132d 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -17,7 +16,6 @@ import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.Task; import org.openmrs.Encounter; -import org.openmrs.EncounterProvider; import org.openmrs.Obs; import org.openmrs.Order; import org.openmrs.api.db.DAOException; @@ -92,23 +90,16 @@ public Task createOrder(Order order) throws OrderCreationException { Reference encounterRef = newReference(order.getEncounter().getUuid(), FhirConstants.ENCOUNTER); - Optional requesterProvider = order.getEncounter().getActiveEncounterProviders().stream() - .findFirst(); + Reference requesterRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.ORGANIZATION); - Reference requesterRef = requesterProvider.map( - encounterProvider -> newReference(encounterProvider.getUuid(), FhirConstants.PRACTITIONER)).orElse(null); - - Reference locationRef = null; - if (order.getEncounter().getLocation() != null) { - locationRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.LOCATION); - } + // Reference locationRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.LOCATION); // Create Task Resource for given Order - Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs); + Task newTask = createTask(basedOnRefs, forReference, null, encounterRef, null,requesterRef ,taskInputs); - if (order.getEncounter().getActiveEncounterProviders().isEmpty()) { - newTask.setRequester(requesterRef); - } +// if (order.getEncounter().getLocation() != null) { +// newTask.setRequester(requesterRef); +// } // Save the new Task Resource try { @@ -121,7 +112,7 @@ public Task createOrder(Order order) throws OrderCreationException { } private Task createTask(List basedOnRefs, Reference forReference, Reference ownerRef, - Reference encounterRef, Reference locationRef ,List taskInputs) { + Reference encounterRef, Reference locationRef, Reference organizationRef ,List taskInputs) { Task newTask = new Task(); newTask.setStatus(Task.TaskStatus.REQUESTED); newTask.setIntent(Task.TaskIntent.ORDER); @@ -130,6 +121,7 @@ private Task createTask(List basedOnRefs, Reference forReference, Ref newTask.setOwner(ownerRef); newTask.setEncounter(encounterRef); newTask.setLocation(locationRef); + newTask.setRequester(organizationRef); if (taskInputs != null) { newTask.setInput(taskInputs); } @@ -160,11 +152,7 @@ public Task createOrder(Encounter encounter) throws OrderCreationException { Reference locationRef = newReference(encounter.getLocation().getUuid(), FhirConstants.LOCATION); - Optional requesterProvider = encounter.getActiveEncounterProviders().stream().findFirst(); - - Reference requesterRef = requesterProvider.isPresent() ? - newReference(requesterProvider.get().getUuid(), FhirConstants.PRACTITIONER) : - null; + Reference requesterRef = newReference(encounter.getLocation().getUuid(), FhirConstants.ORGANIZATION); List taskInputs = null; if (config.addObsAsTaskInput()) { @@ -179,12 +167,20 @@ public Task createOrder(Encounter encounter) throws OrderCreationException { } // Create Task Resource for given Order - Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs); - newTask.setLocation(locationRef); - - if (!encounter.getActiveEncounterProviders().isEmpty()) { - newTask.setRequester(requesterRef); - } + // ========================================= + // Summary of Payload requirements in terms of location and organization: + // Payload coming from OpenMRS should include only the Location and Organization resources corresponding to the MFL-based location that represents the physical spot where a lab order is being collected. This MFL code will then be mapped to the proper IPMS location (in some cases based on the type of test being ordered as well) + // The incoming Location should reference the Organization as a managing organization, just like a normal Org/Location pair + // For the incoming task resource: + // `for` should reference the patient + // `requester` should reference the Organization + // `owner` and `location` can be left blank + // Once the task is processed, owner will reference the mapped IPMS Organization, and location the IPMS location. + // Leave the `location ref` and `owner ref` blank. Once the task is processed, owner will reference the mapped Lab Systems Organization, and location the Lab System's location. + Task newTask = createTask(basedOnRefs, forReference, null, encounterRef, null, requesterRef, taskInputs); + //newTask.setLocation(locationRef); + + //newTask.setRequester(requesterRef); // Save the new Task Resource try { diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java index e0de003..5ebb004 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java @@ -13,7 +13,7 @@ import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenParam; import org.hl7.fhir.r4.model.Location; - +import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Identifier; @@ -101,6 +101,7 @@ public Bundle createLabBundle(Task task) { includes.add(new Include("Task:encounter")); includes.add(new Include("Task:based-on")); includes.add(new Include("Task:location")); + includes.add(new Include("Task:requester")); IBundleProvider labBundle = fhirTaskService.searchForTasks(new TaskSearchParams(null, null, null, uuid, null, null, includes)); @@ -111,14 +112,19 @@ public Bundle createLabBundle(Task task) { labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getLocation().getReference()).get())); } + if (!task.getRequester().isEmpty()) { + labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getRequester().getReference()).get())); + } + for (IBaseResource r : labResources) { Resource resource = (Resource) r; // if resource is location, add MFL Code as location identifier // TODO: Short term: Make the MFL Location attribute type to be a Global config variable - // TODO: Long term: Make the location translator pick enrich the MFL Code as appropriate + // TODO: Long term: Make the location translator pick and enrich the MFL Code as appropriate - if (resource instanceof Location) { + Bundle.BundleEntryComponent component = transactionBundle.addEntry(); + if (resource instanceof Location || resource instanceof Organization) { Location location = (Location) resource; if (location != null) { org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId()); @@ -128,19 +134,20 @@ public Bundle createLabBundle(Task task) { if (!locationAttributeTypes.isEmpty()) { locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> { String mflCode = (String) locationAttribute.getValue(); - + Identifier mflIdentifier = new Identifier(); mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI); mflIdentifier.setValue(mflCode); location.addIdentifier(mflIdentifier); + component.setResource(location); }); } } } + } else { + component.setResource(resource); } - Bundle.BundleEntryComponent component = transactionBundle.addEntry(); - component.setResource(resource); component.getRequest().setUrl(resource.fhirType() + "/" + resource.getIdElement().getIdPart()) .setMethod(Bundle.HTTPVerb.PUT); From cd5efbc53a5ba6e055894ea1d6ee34c1d7707ed7 Mon Sep 17 00:00:00 2001 From: moshonk Date: Fri, 7 Jun 2024 03:14:01 +0300 Subject: [PATCH 14/15] chore: Refactor LabCreationListener to add MFL Code as location identifier --- .../api/event/LabCreationListener.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java index 5ebb004..5cd4fb1 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java @@ -125,23 +125,27 @@ public Bundle createLabBundle(Task task) { Bundle.BundleEntryComponent component = transactionBundle.addEntry(); if (resource instanceof Location || resource instanceof Organization) { - Location location = (Location) resource; - if (location != null) { - org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId()); - if (openmrsLocation != null) { - LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID); - Collection locationAttributeTypes = openmrsLocation.getActiveAttributes(); - if (!locationAttributeTypes.isEmpty()) { - locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> { - String mflCode = (String) locationAttribute.getValue(); - - Identifier mflIdentifier = new Identifier(); - mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI); - mflIdentifier.setValue(mflCode); + org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId()); + if (openmrsLocation != null) { + LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID); + Collection locationAttributeTypes = openmrsLocation.getActiveAttributes(); + if (!locationAttributeTypes.isEmpty()) { + locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> { + String mflCode = (String) locationAttribute.getValue(); + + Identifier mflIdentifier = new Identifier(); + mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI); + mflIdentifier.setValue(mflCode); + if (resource instanceof Organization) { + Organization organization = (Organization) resource; + organization.addIdentifier(mflIdentifier); + component.setResource(organization); + } else if (resource instanceof Location) { + Location location = (Location) resource; location.addIdentifier(mflIdentifier); component.setResource(location); - }); - } + } + }); } } } else { From 1673f8e9ae8dd708a6c4fc28b6ba7529baa5a5f5 Mon Sep 17 00:00:00 2001 From: Piotr Mankowski Date: Sun, 9 Jun 2024 15:19:54 +0200 Subject: [PATCH 15/15] Debugging requester reference issue --- .../module/labonfhir/api/LabOrderHandler.java | 8 +-- .../api/event/LabCreationListener.java | 2 +- .../labonfhir/api/LabOrderHandlerTest.java | 67 ++++++++++++++++++- pom.xml | 8 ++- 4 files changed, 75 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java index 586132d..47c6f81 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java @@ -85,9 +85,7 @@ public Task createOrder(Order order) throws OrderCreationException { newReference(order.getUuid(), FhirConstants.SERVICE_REQUEST)); Reference forReference = newReference(order.getPatient().getUuid(), FhirConstants.PATIENT); - - Reference ownerRef = newReference(config.getLisUserUuid(), FhirConstants.PRACTITIONER); - + Reference encounterRef = newReference(order.getEncounter().getUuid(), FhirConstants.ENCOUNTER); Reference requesterRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.ORGANIZATION); @@ -112,7 +110,7 @@ public Task createOrder(Order order) throws OrderCreationException { } private Task createTask(List basedOnRefs, Reference forReference, Reference ownerRef, - Reference encounterRef, Reference locationRef, Reference organizationRef ,List taskInputs) { + Reference encounterRef, Reference locationRef, Reference requesterRef ,List taskInputs) { Task newTask = new Task(); newTask.setStatus(Task.TaskStatus.REQUESTED); newTask.setIntent(Task.TaskIntent.ORDER); @@ -121,7 +119,7 @@ private Task createTask(List basedOnRefs, Reference forReference, Ref newTask.setOwner(ownerRef); newTask.setEncounter(encounterRef); newTask.setLocation(locationRef); - newTask.setRequester(organizationRef); + newTask.setRequester(requesterRef); if (taskInputs != null) { newTask.setInput(taskInputs); } diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java index 5cd4fb1..cba4aca 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java @@ -125,7 +125,7 @@ public Bundle createLabBundle(Task task) { Bundle.BundleEntryComponent component = transactionBundle.addEntry(); if (resource instanceof Location || resource instanceof Organization) { - org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId()); + org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(resource.getId()); if (openmrsLocation != null) { LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID); Collection locationAttributeTypes = openmrsLocation.getActiveAttributes(); diff --git a/api/src/test/java/org/openmrs/module/labonfhir/api/LabOrderHandlerTest.java b/api/src/test/java/org/openmrs/module/labonfhir/api/LabOrderHandlerTest.java index 942ea9d..1ca23ef 100644 --- a/api/src/test/java/org/openmrs/module/labonfhir/api/LabOrderHandlerTest.java +++ b/api/src/test/java/org/openmrs/module/labonfhir/api/LabOrderHandlerTest.java @@ -1,17 +1,78 @@ package org.openmrs.module.labonfhir.api; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; + +import org.hl7.fhir.r4.model.Task; import org.junit.Before; import org.junit.Test; +import org.mockito.MockitoAnnotations; +import org.mockito.Mock; +import org.openmrs.Encounter; +import org.openmrs.Location; +import org.openmrs.Obs; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.api.EncounterService; +import org.openmrs.api.LocationService; +import org.openmrs.api.ObsService; +import org.openmrs.api.OrderService; +import org.openmrs.api.PatientService; +import org.openmrs.module.labonfhir.api.fhir.OrderCreationException; public class LabOrderHandlerTest { + @Mock + private OrderService orderService; + @Mock + private EncounterService encounterService; + @Mock + private LocationService locationService; + @Mock + private PatientService patientService; + @Mock + private ObsService obsService; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } @Before public void setUp() throws Exception { } - @Test - public void createOrder_shouldCreateTaskAndERferenceOrder() { + @Test + public void createOrder_shouldCreateTask() throws OrderCreationException { + // Create a mock Order object + Order order = new Order(); + order.setUuid("orderUuid"); + + // Create a mock Encounter object + Encounter encounter = new Encounter(); + encounter.setUuid("encounterUuid"); + encounter.setLocation(new Location()); + encounter.getLocation().setUuid("locationUuid"); + encounter.setPatient(new Patient()); + encounter.getPatient().setUuid("patientUuid"); + + // Create a mock Obs object + Obs obs = new Obs(); + obs.setUuid("obsUuid"); + encounter.getObs().add(obs); + + // Mock the necessary dependencies + when(orderService.getOrderByUuid("orderUuid")).thenReturn(order); + when(encounterService.getEncounterByUuid("encounterUuid")).thenReturn(encounter); + when(locationService.getLocationByUuid("locationUuid")).thenReturn(new Location()); + when(patientService.getPatientByUuid("patientUuid")).thenReturn(new Patient()); + when(obsService.getObsByUuid("obsUuid")).thenReturn(new Obs()); + + // Call the createOrder method + LabOrderHandler labOrderHandler = new LabOrderHandler(); + Task task = labOrderHandler.createOrder(order); + + // Assert that the task is not null + assertNotNull(task); } -} +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index b2fca3e..e2c8bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,13 @@ tests test - + + org.mockito + mockito-core + 3.12.4 + test + + org.projectlombok lombok 1.18.12