Skip to content

Commit

Permalink
Merge pull request #15 from reagan-meant/ISSUE-2
Browse files Browse the repository at this point in the history
Use env variables and add extensions
  • Loading branch information
reagan-meant authored May 6, 2024
2 parents cdd2597 + b3bf508 commit 508a41f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 31 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -65,11 +65,11 @@ public String getClientRegistryDefaultPatientIdentifierSystem() {
public String getClientRegistryUserName() {
return username;
}

public String getClientRegistryPassword() {
return password;
}

public String getClientRegistryIdentifierRoot() {
return identifierRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -115,5 +147,4 @@ private void processMessage(Message message) throws JMSException {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,12 +34,6 @@
@Setter(PACKAGE)
public class FhirCRPatientResourceProvider implements IResourceProvider {

@Autowired
private ClientRegistryManager clientRegistryManager;

@Autowired
private ClientRegistryConfig config;

@Override
public Class<? extends IBaseResource> getResourceType() {
return Patient.class;
Expand All @@ -60,7 +55,11 @@ public List<Patient> 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");
}
Expand Down
7 changes: 7 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
</description>
</globalProperty>

<globalProperty>
<property>@[email protected]</property>
<defaultValue></defaultValue>
<description>
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"
</description>
</globalProperty>

<!-- Internationalization -->
<!-- All message codes should start with @MODULE_ID@.* -->
Expand Down

0 comments on commit 508a41f

Please sign in to comment.