From b44fce1e16770a513ff6ab67ac8be2ccce726d99 Mon Sep 17 00:00:00 2001 From: reagan-meant Date: Sat, 4 May 2024 23:18:15 +0300 Subject: [PATCH 1/5] Use env var --- README.md | 6 ++++++ .../module/clientregistry/ClientRegistryConfig.java | 8 ++++---- .../clientregistry/ClientRegistryConstants.java | 12 +++++------- .../api/event/PatientCreateUpdateListener.java | 7 ++++++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2d6b576..bbbd44d 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,9 @@ If uploads are not allowed from the web (changable via a runtime property), you into the ~/.OpenMRS/modules folder. (Where ~/.OpenMRS is assumed to be the Application Data Directory that the running openmrs is currently using.) After putting the file in there simply restart OpenMRS/tomcat and the module will be loaded and started. + +Set variable below via docker env file or runtime properties file +CLIENTREGISTRY_SERVERURL=https://localhost/openhimcore/CR/fhir +CLIENTREGISTRY_USERNAME=sigdep3 +CLIENTREGISTRY_PASSWORD=sigdep3 +CLIENTREGISTRY_IDENTIFIERROOT=http://clientregistry.org/openmrs \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java index 574e7f7..627fc67 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java @@ -28,16 +28,16 @@ public class ClientRegistryConfig { @Qualifier("adminService") AdministrationService administrationService; - @Value("${clientregistry.serverUrl}") + @Value("${CLIENTREGISTRY_SERVERURL}") private String serverUrl; - @Value("${clientregistry.username}") + @Value("${CLIENTREGISTRY_USERNAME}") private String username; - @Value("${clientregistry.password}") + @Value("${CLIENTREGISTRY_PASSWORD}") private String password; - @Value("${clientregistry.identifierRoot}") + @Value("${CLIENTREGISTRY_IDENTIFIERROOT}") private String identifierRoot; public boolean clientRegistryConnectionEnabled() { diff --git a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java index bde5225..35c486e 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java @@ -2,20 +2,18 @@ public class ClientRegistryConstants { - public static final String GP_CLIENT_REGISTRY_SERVER_URL = "clientregistry.clientRegistryServerUrl"; - + public static final String GP_CLIENT_REGISTRY_SERVER_URL = "CLIENTREGISTRY_SERVERURL"; public static final String GP_FHIR_CLIENT_REGISTRY_GET_PATIENT_ENDPOINT = "clientregistry.fhirGetPatientEndpoint"; - public static final String GP_CLIENT_REGISTRY_DEFAULT_PATIENT_IDENTIFIER_SYSTEM = "clientregistry.defaultPatientIdentifierSystem"; - public static final String GP_CLIENT_REGISTRY_USER_NAME = "clientregistry.username"; + public static final String GP_CLIENT_REGISTRY_USER_NAME = "CLIENTREGISTRY_USERNAME"; - public static final String GP_CLIENT_REGISTRY_PASSWORD = "clientregistry.password"; + public static final String GP_CLIENT_REGISTRY_PASSWORD = "CLIENTREGISTRY_PASSWORD"; - public static final String GP_CLIENT_REGISTRY_IDENTIFIER_ROOT = "clientregistry.identifierRoot"; + public static final String GP_CLIENT_REGISTRY_IDENTIFIER_ROOT = "CLIENTREGISTRY_IDENTIFIERROOT"; public static final String GP_CLIENT_REGISTRY_TRANSACTION_METHOD = "clientregistry.transactionMethod"; - + public static final String UPDATE_MESSAGE_DESTINATION = "topic://UPDATED:org.openmrs.Patient"; public static final String CLIENT_REGISTRY_INTERNAL_ID_SYSTEM = "http://clientregistry.org/openmrs"; diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java index bab5bce..752eef3 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java @@ -12,6 +12,7 @@ import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.ContactPoint; import org.openmrs.api.context.Daemon; import org.openmrs.event.EventListener; import org.openmrs.module.DaemonToken; @@ -88,7 +89,11 @@ private void processMessage(Message message) throws JMSException { Patient patient; patient = patientService.get(uuid); patient.getNameFirstRep().setUse(HumanName.NameUse.OFFICIAL); - + + for (ContactPoint contactPoint : patient.getTelecom()) { + contactPoint.setSystem(ContactPoint.ContactPointSystem.PHONE); + contactPoint.setUse(ContactPoint.ContactPointUse.MOBILE); + } Identifier openmrsUniqueId = new Identifier() .setSystem(ClientRegistryConstants.CLIENT_REGISTRY_INTERNAL_ID_SYSTEM) .setValue(String.format("%s/%s", config.getClientRegistryIdentifierRoot(), uuid)) From 0133630d720c8492b0daa1eb667e24f79cda6eca Mon Sep 17 00:00:00 2001 From: reagan-meant Date: Sun, 5 May 2024 00:55:46 +0300 Subject: [PATCH 2/5] Specify bean --- .../clientregistry/api/impl/FhirCRPatientServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java index 6f91773..3c39161 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java @@ -17,6 +17,8 @@ import org.openmrs.module.fhir2.api.search.param.PatientSearchParams; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.beans.factory.annotation.Qualifier; + import java.util.Collections; import java.util.List; @@ -27,6 +29,7 @@ public class FhirCRPatientServiceImpl implements CRPatientService { @Autowired + @Qualifier("clientRegistryFhirClient") private IGenericClient fhirClient; @Autowired From 3d596783ea6111c41eecebd97b75d1034cbc5756 Mon Sep 17 00:00:00 2001 From: reagan-meant Date: Sun, 5 May 2024 02:21:28 +0300 Subject: [PATCH 3/5] Add extensions --- .../event/PatientCreateUpdateListener.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java index 752eef3..02615b6 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java @@ -12,7 +12,11 @@ import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.ContactPoint; +import org.hl7.fhir.r4.model.Extension; +import org.openmrs.PersonAttribute; +import org.openmrs.api.context.Context; import org.openmrs.api.context.Daemon; import org.openmrs.event.EventListener; import org.openmrs.module.DaemonToken; @@ -89,7 +93,7 @@ private void processMessage(Message message) throws JMSException { Patient patient; patient = patientService.get(uuid); patient.getNameFirstRep().setUse(HumanName.NameUse.OFFICIAL); - + for (ContactPoint contactPoint : patient.getTelecom()) { contactPoint.setSystem(ContactPoint.ContactPointSystem.PHONE); contactPoint.setUse(ContactPoint.ContactPointUse.MOBILE); @@ -102,6 +106,27 @@ private void processMessage(Message message) throws JMSException { patient.setId(openmrsUniqueId.getValue()); + + //Configure via GP + String uuidAndExtensionString = "f1c8c615-1c73-4976-8218-a74ca67e22bb|patient_status,11e3f71d-c4b2-4b4b-a26b-59e43f2d5347|patient_status_date"; + String[] uuidAndExtensionPairs = uuidAndExtensionString.split(","); + + for (String pair : uuidAndExtensionPairs) { + String[] uuidAndExtension = pair.trim().split("\\|"); + if (uuidAndExtension.length == 2) { + String extuuid = uuidAndExtension[0].trim(); + String extensionUrl = uuidAndExtension[1].trim(); + Extension extension = new Extension().setUrl(extensionUrl); + for (PersonAttribute attribute : Context.getPersonService().getPersonByUuid(uuid).getActiveAttributes()) { + if (attribute.getAttributeType().getUuid().equals(extuuid)) { + extension.setValue(new StringType(attribute.toString())); + break; + } + } + patient.addExtension(extension); + } + } + if (mapMessage.getJMSDestination().toString().equals(ClientRegistryConstants.UPDATE_MESSAGE_DESTINATION)) { client.update().resource(patient).execute(); } else { From fb9137e52d3d82564d7834e534b0a0086395cc95 Mon Sep 17 00:00:00 2001 From: MAKOBA REAGAN PATRICK Date: Mon, 6 May 2024 12:54:42 +0000 Subject: [PATCH 4/5] Fix dependency injection --- .../clientregistry/ClientRegistryConfig.java | 20 +++++++++---------- .../ClientRegistryConstants.java | 10 +++++++--- .../event/PatientCreateUpdateListener.java | 11 +++++----- .../api/impl/FhirCRPatientServiceImpl.java | 3 --- .../r4/FhirCRPatientResourceProvider.java | 15 +++++++------- omod/src/main/resources/config.xml | 7 +++++++ 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java index 627fc67..884fab2 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java @@ -21,29 +21,29 @@ */ @Component public class ClientRegistryConfig { - + public final static String MODULE_PRIVILEGE = "Client Registry Privilege"; - + @Autowired @Qualifier("adminService") AdministrationService administrationService; - + @Value("${CLIENTREGISTRY_SERVERURL}") private String serverUrl; - + @Value("${CLIENTREGISTRY_USERNAME}") private String username; - + @Value("${CLIENTREGISTRY_PASSWORD}") private String password; - + @Value("${CLIENTREGISTRY_IDENTIFIERROOT}") private String identifierRoot; - + public boolean clientRegistryConnectionEnabled() { return StringUtils.isNotBlank(getClientRegistryServerUrl()); } - + public String getClientRegistryServerUrl() { return serverUrl; } @@ -65,11 +65,11 @@ public String getClientRegistryDefaultPatientIdentifierSystem() { public String getClientRegistryUserName() { return username; } - + public String getClientRegistryPassword() { return password; } - + public String getClientRegistryIdentifierRoot() { return identifierRoot; } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java index 35c486e..293842e 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConstants.java @@ -2,8 +2,14 @@ public class ClientRegistryConstants { + public static final String CLIENT_REGISTRY_INTERNAL_ID_SYSTEM = "http://clientregistry.org/openmrs"; + + public static final String GP_EXTENSION_UUID_EXTENSION_URLS = "clientregistry.uuidAndExtensionURL"; + public static final String GP_CLIENT_REGISTRY_SERVER_URL = "CLIENTREGISTRY_SERVERURL"; + public static final String GP_FHIR_CLIENT_REGISTRY_GET_PATIENT_ENDPOINT = "clientregistry.fhirGetPatientEndpoint"; + public static final String GP_CLIENT_REGISTRY_DEFAULT_PATIENT_IDENTIFIER_SYSTEM = "clientregistry.defaultPatientIdentifierSystem"; public static final String GP_CLIENT_REGISTRY_USER_NAME = "CLIENTREGISTRY_USERNAME"; @@ -13,8 +19,6 @@ public class ClientRegistryConstants { public static final String GP_CLIENT_REGISTRY_IDENTIFIER_ROOT = "CLIENTREGISTRY_IDENTIFIERROOT"; public static final String GP_CLIENT_REGISTRY_TRANSACTION_METHOD = "clientregistry.transactionMethod"; - - public static final String UPDATE_MESSAGE_DESTINATION = "topic://UPDATED:org.openmrs.Patient"; - public static final String CLIENT_REGISTRY_INTERNAL_ID_SYSTEM = "http://clientregistry.org/openmrs"; + public static final String UPDATE_MESSAGE_DESTINATION = "topic://UPDATED:org.openmrs.Patient"; } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java index 02615b6..e8b6fa1 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/event/PatientCreateUpdateListener.java @@ -1,5 +1,7 @@ package org.openmrs.module.clientregistry.api.event; +import java.util.Optional; + import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; @@ -107,10 +109,10 @@ private void processMessage(Message message) throws JMSException { patient.setId(openmrsUniqueId.getValue()); - //Configure via GP - String uuidAndExtensionString = "f1c8c615-1c73-4976-8218-a74ca67e22bb|patient_status,11e3f71d-c4b2-4b4b-a26b-59e43f2d5347|patient_status_date"; - String[] uuidAndExtensionPairs = uuidAndExtensionString.split(","); - + String uuidAndExtensionString = Context.getAdministrationService().getGlobalProperty(ClientRegistryConstants.GP_EXTENSION_UUID_EXTENSION_URLS); + String[] uuidAndExtensionPairs = Optional.ofNullable(uuidAndExtensionString) + .map(s -> s.split(",")) + .orElse(new String[0]); for (String pair : uuidAndExtensionPairs) { String[] uuidAndExtension = pair.trim().split("\\|"); if (uuidAndExtension.length == 2) { @@ -145,5 +147,4 @@ private void processMessage(Message message) throws JMSException { } } } - } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java index 3c39161..34beb01 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java @@ -19,7 +19,6 @@ import org.springframework.stereotype.Component; import org.springframework.beans.factory.annotation.Qualifier; - import java.util.Collections; import java.util.List; import java.util.Objects; @@ -32,8 +31,6 @@ public class FhirCRPatientServiceImpl implements CRPatientService { @Qualifier("clientRegistryFhirClient") private IGenericClient fhirClient; - @Autowired - private ClientRegistryConfig config; /** * Get patient identifiers from an external client registry's $ihe-pix implementation. Use the diff --git a/api/src/main/java/org/openmrs/module/clientregistry/providers/r4/FhirCRPatientResourceProvider.java b/api/src/main/java/org/openmrs/module/clientregistry/providers/r4/FhirCRPatientResourceProvider.java index c88cad7..7460570 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/providers/r4/FhirCRPatientResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/providers/r4/FhirCRPatientResourceProvider.java @@ -14,11 +14,12 @@ import org.hl7.fhir.r4.model.Patient; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; + +import org.openmrs.api.context.Context; import org.openmrs.module.clientregistry.ClientRegistryConfig; import org.openmrs.module.clientregistry.api.ClientRegistryManager; import org.openmrs.module.clientregistry.providers.FhirCRConstants; import org.openmrs.module.fhir2.api.annotations.R4Provider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Collections; @@ -33,12 +34,6 @@ @Setter(PACKAGE) public class FhirCRPatientResourceProvider implements IResourceProvider { - @Autowired - private ClientRegistryManager clientRegistryManager; - - @Autowired - private ClientRegistryConfig config; - @Override public Class getResourceType() { return Patient.class; @@ -60,7 +55,11 @@ public List getCRPatientById( @OperationParam(name = FhirCRConstants.SOURCE_IDENTIFIER) TokenParam sourceIdentifierParam, @OperationParam(name = FhirCRConstants.TARGET_SYSTEM) StringOrListParam targetSystemsParam ) { - + ClientRegistryManager clientRegistryManager = Context.getRegisteredComponent("clientRegistryManager", + ClientRegistryManager.class); + + ClientRegistryConfig config = Context.getRegisteredComponent("clientRegistryFhirClient", + ClientRegistryConfig.class); if (sourceIdentifierParam == null || sourceIdentifierParam.getValue() == null) { throw new InvalidRequestException("sourceIdentifier must be specified"); } diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 5eafd0d..6cee612 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -87,6 +87,13 @@ + + @MODULE_ID@.uuidAndExtensionURL + + + UUIDs of person attributes that are to be mapped to the fhir extension url like "50fada9c-6d6f-4575-bda6-448a719da919|http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName,4a4f9e2d-59de-45d2-92f4-015bc388b832|http://hl7.org/fhir/StructureDefinition/patient-sistersName" + + From b3bf5085e394a5aa43a7c347b011841e0b4ae1af Mon Sep 17 00:00:00 2001 From: MAKOBA REAGAN PATRICK Date: Mon, 6 May 2024 12:57:14 +0000 Subject: [PATCH 5/5] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbbd44d..d5cfebb 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,6 @@ simply restart OpenMRS/tomcat and the module will be loaded and started. Set variable below via docker env file or runtime properties file CLIENTREGISTRY_SERVERURL=https://localhost/openhimcore/CR/fhir -CLIENTREGISTRY_USERNAME=sigdep3 -CLIENTREGISTRY_PASSWORD=sigdep3 +CLIENTREGISTRY_USERNAME=admin +CLIENTREGISTRY_PASSWORD=Admin123 CLIENTREGISTRY_IDENTIFIERROOT=http://clientregistry.org/openmrs \ No newline at end of file