Skip to content

Commit

Permalink
FM2-531 : Add Location Resource to lab bundle (#27)
Browse files Browse the repository at this point in the history
* add Location to lab bundle

* fix parsing uuid

* add openelis id system

* update fhir system on restart

* save or update identifier system
  • Loading branch information
mozzy11 authored Nov 22, 2022
1 parent f5b5bc2 commit 0a26d47
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
package org.openmrs.module.labonfhir;

import lombok.SneakyThrows;

import java.util.Optional;

import org.openmrs.PatientIdentifier;
import org.openmrs.PatientIdentifierType;
import org.openmrs.api.PatientService;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.DaemonToken;
import org.openmrs.module.DaemonTokenAware;
import org.openmrs.module.fhir2.api.FhirPatientIdentifierSystemService;
import org.openmrs.module.fhir2.model.FhirPatientIdentifierSystem;
import org.openmrs.module.labonfhir.api.OpenElisManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,51 +32,77 @@

@Component
public class LabOnFhirActivator extends BaseModuleActivator implements ApplicationContextAware, DaemonTokenAware {

private static final Logger log = LoggerFactory.getLogger(LabOnFhirActivator.class);

private static ApplicationContext applicationContext;

private static DaemonToken daemonToken;

@Autowired
private LabOnFhirConfig config;

@Autowired
private OpenElisManager openElisManager;


@Autowired
PatientService patientService;

@Autowired
FhirPatientIdentifierSystemService fhirPatientIdentifierSystemService;

@SneakyThrows
@Override
public void started() {
applicationContext.getAutowireCapableBeanFactory().autowireBean(this);

openElisManager.setDaemonToken(daemonToken);

// subscribe to encounter creation events
if (config.isOpenElisEnabled()) {
openElisManager.enableOpenElisConnector();
}

createFhirPatientIdentierSystem();

log.info("Lab on FHIR Module Started!");

}

@Override
public void stopped() {
if (openElisManager != null) {
openElisManager.disableOpenElisConnector();
}

log.info("Lab on FHIR Module Shut Down!");
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

@Override
public void setDaemonToken(DaemonToken token) {
this.daemonToken = token;
}

private void createFhirPatientIdentierSystem() {
PatientIdentifierType pidType = patientService
.getPatientIdentifierTypeByUuid(config.getPatientIentifierUuid().trim());

Optional<FhirPatientIdentifierSystem> existingIdSystem = fhirPatientIdentifierSystemService
.getFhirPatientIdentifierSystem(pidType);
if (existingIdSystem.isPresent()) {
existingIdSystem.get().setPatientIdentifierType(pidType);
existingIdSystem.get().setUrl(config.getLisIentifierSystemUrl().trim());
fhirPatientIdentifierSystemService.saveFhirPatientIdentifierSystem(existingIdSystem.get());
} else {
FhirPatientIdentifierSystem idSystem = new FhirPatientIdentifierSystem();
idSystem.setName("OpenLIS ID System");
idSystem.setPatientIdentifierType(pidType);
idSystem.setUrl(config.getLisIentifierSystemUrl().trim());
fhirPatientIdentifierSystemService.saveFhirPatientIdentifierSystem(idSystem);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public class LabOnFhirConfig implements ApplicationContextAware {

public static final String GP_PASSWORD = "labonfhir.password";

public static final String GP_PATIENT_IDENTIFIER_UUID = "labonfhir.openmrsPatientIdentifier.uuid";

public static final String GP_LIS_IDENTIFIER_SYSTEM_URL = "labonfhir.openElisIdentifierSystem.url";

public enum AuthType{
SSL,
BASIC
Expand Down Expand Up @@ -124,6 +128,14 @@ public String getOpenElisPassword() {
return administrationService.getGlobalProperty(GP_PASSWORD);
}

public String getPatientIentifierUuid() {
return administrationService.getGlobalProperty(GP_PATIENT_IDENTIFIER_UUID ,"05a29f94-c0ed-11e2-94be-8c13b969e334");
}

public String getLisIentifierSystemUrl() {
return administrationService.getGlobalProperty(GP_LIS_IDENTIFIER_SYSTEM_URL ,"http://openelis-global.org/pat_nationalId");
}

public AuthType getAuthType() {
String authTypeGp = administrationService.getGlobalProperty(GP_AUTH_TYPE);
switch (authTypeGp.toUpperCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public Task createOrder(Encounter encounter) throws OrderCreationException {

Reference encounterRef = newReference(encounter.getUuid(), FhirConstants.ENCOUNTER);

Reference locationRef = newReference(encounter.getLocation().getUuid(), FhirConstants.LOCATION);

Optional<EncounterProvider> requesterProvider = encounter.getActiveEncounterProviders().stream().findFirst();

Reference requesterRef = requesterProvider.isPresent() ? newReference(requesterProvider.get().getUuid(), FhirConstants.PRACTITIONER) : null;
Expand All @@ -62,6 +64,7 @@ public Task createOrder(Encounter encounter) throws OrderCreationException {
newTask.setFor(forReference);
newTask.setOwner(ownerRef);
newTask.setEncounter(encounterRef);
newTask.setLocation(locationRef);

if(!encounter.getActiveEncounterProviders().isEmpty()){
newTask.setRequester(requesterRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.openmrs.Encounter;
import org.openmrs.api.APIException;
import org.openmrs.api.EncounterService;
import org.openmrs.module.fhir2.api.FhirLocationService;
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.util.FhirUtils;
import org.openmrs.api.context.Daemon;
import org.openmrs.event.EventListener;
import org.openmrs.module.DaemonToken;
Expand Down Expand Up @@ -65,6 +67,9 @@ public void setDaemonToken(DaemonToken daemonToken) {

@Autowired
private FhirTaskService fhirTaskService;

@Autowired
FhirLocationService fhirLocationService ;

@Autowired
@Qualifier("fhirR4")
Expand Down Expand Up @@ -144,11 +149,13 @@ private Bundle createLabBundle(Task task) {
includes.add(new Include("Task:based-on"));

IBundleProvider labBundle = fhirTaskService.searchForTasks(null, null, null, uuid, null, null, includes);
labBundle.getAllResources();

Bundle transactionBundle = new Bundle();
transactionBundle.setType(Bundle.BundleType.TRANSACTION);
List<IBaseResource> labResources = labBundle.getAllResources();
if (!task.getLocation().isEmpty()) {
labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getLocation().getReference()).get()));
}
for (IBaseResource r : labResources) {
Resource resource = (Resource) r;
Bundle.BundleEntryComponent component = transactionBundle.addEntry();
Expand Down
11 changes: 11 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@
<description>Password for HTTP Basic Auth with the LIS</description>
<defaultValue>password</defaultValue>
</globalProperty>
<globalProperty>
<property>@[email protected]</property>
<description>Patient Identifier used to generate the FHIR Identifier System</description>
<defaultValue>05a29f94-c0ed-11e2-94be-8c13b969e334</defaultValue>
</globalProperty>

<globalProperty>
<property>@[email protected]</property>
<description>OpenElis Identifier System url</description>
<defaultValue>http://openelis-global.org/pat_nationalId</defaultValue>
</globalProperty>
</module>
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@
</profile>
</profiles>
<properties>
<revision>1.2.0</revision>
<fhir2Version>1.4.0</fhir2Version>
<revision>1.2.1</revision>
<fhir2Version>1.6.0</fhir2Version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 0a26d47

Please sign in to comment.