diff --git a/README.md b/README.md index 2d6b576..d5cfebb 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=admin +CLIENTREGISTRY_PASSWORD=Admin123 +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..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}") + + @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() { 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 bde5225..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,21 +2,23 @@ public class ClientRegistryConstants { - public static final String GP_CLIENT_REGISTRY_SERVER_URL = "clientregistry.clientRegistryServerUrl"; + 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"; + 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..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; @@ -12,6 +14,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,6 +96,10 @@ private void processMessage(Message message) throws JMSException { 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)) @@ -97,6 +108,27 @@ private void processMessage(Message message) throws JMSException { patient.setId(openmrsUniqueId.getValue()); + + 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) { + 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 { @@ -115,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 6f91773..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 @@ -17,6 +17,7 @@ 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,10 +28,9 @@ public class FhirCRPatientServiceImpl implements CRPatientService { @Autowired + @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" + +