Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code to replace component annotations with xml configurations #48

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ nb-configuration.xml
##############################
.DS_Store

.flattened-pom.xml
.flattened-pom.xml
openmrs.log
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

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

private static final Logger log = LoggerFactory.getLogger(LabOnFhirActivator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component

@Configuration
public class LabOnFhirConfig implements ApplicationContextAware {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import org.openmrs.module.labonfhir.LabOnFhirConfig;
import org.openmrs.module.labonfhir.api.fhir.OrderCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component

public class LabOrderHandler {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LabOrderManager implements GlobalPropertyListener {

private static final Logger log = LoggerFactory.getLogger(LabOrderManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("labEncounterListener")
public class EncounterCreationListener extends LabCreationListener {
private static final Logger log = LoggerFactory.getLogger(OrderCreationListener.class);
@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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<LocationAttribute> 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())
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("labOrderListener")
public class OrderCreationListener extends LabCreationListener {

private static final Logger log = LoggerFactory.getLogger(OrderCreationListener.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import java.text.SimpleDateFormat;

@Component
@Setter(AccessLevel.PACKAGE)
public class FetchTaskUpdates extends AbstractTask implements ApplicationContextAware {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient;

@Component
public class RetryFailedTasks extends AbstractTask implements ApplicationContextAware {
private static Log log = LogFactory.getLog(RetryFailedTasks.class);

Expand Down
11 changes: 9 additions & 2 deletions api/src/main/resources/moduleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="org.openmrs.module.labonfhir"/>

<bean id="labEncounterListener" class="org.openmrs.module.labonfhir.api.event.EncounterCreationListener"></bean>
<bean id="labOrderListener" class="org.openmrs.module.labonfhir.api.event.OrderCreationListener"></bean>
<bean id="labOnFhirActivator" class="org.openmrs.module.labonfhir.LabOnFhirActivator"></bean>
<bean id="fetchTaskUpdates" class="org.openmrs.module.labonfhir.api.scheduler.FetchTaskUpdates"></bean>
<bean id="retryFailedTasks" class="org.openmrs.module.labonfhir.api.scheduler.RetryFailedTasks"></bean>
<bean id ="labOrderManager" class="org.openmrs.module.labonfhir.api.LabOrderManager"></bean>
<bean id="labOrderHandler" class="org.openmrs.module.labonfhir.api.LabOrderHandler"></bean>
<bean id="labOnFhirConfig" class="org.openmrs.module.labonfhir.LabOnFhirConfig"></bean>

<bean parent="openmrsEventListeners">
<property name="globalPropertyListeners">
<list merge="true">
Expand Down
44 changes: 30 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<url>https://wiki.openmrs.org/x/FQ4z</url>

<scm>
<connection>scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git</connection>
<developerConnection>scm:git:git@github.com:openmrs/openmrs-module-labonfhir.git</developerConnection>
<url>https://github.com/openmrs/openmrs-module-labonfhir/</url>
<tag>HEAD</tag>
<connection>scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git</connection>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moshonk do we need this change here??

<developerConnection>scm:git:git@bitbucket.org:botswana-emrs/openmrs-module-labonfhir.git</developerConnection>
<url>https://bitbucket.org/botswana-emrs/openmrs-module-labonfhir</url>
<tag>1.4.0</tag>
</scm>

<developers>
Expand Down Expand Up @@ -201,6 +201,11 @@
</build>

<repositories>
<repository>
<id>repsy</id>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this repository here ??

<name>Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/intellisoftdev/default</url>
</repository>
<repository>
<id>openmrs-repo</id>
<name>OpenMRS Nexus Repository</name>
Expand Down Expand Up @@ -229,18 +234,16 @@
<id>github-packages</id>
<distributionManagement>
<!-- Deploy to Github Packages -->
<repository>
<id>github-packages</id>
<name>Github Maven Repo</name>
<url>https://maven.pkg.github.com/openmrs/openmrs-module-labonfhir</url>
<uniqueVersion>false</uniqueVersion>
</repository>
<snapshotRepository>
<id>github-packages</id>
<name>Github Maven Repo</name>
<url>https://maven.pkg.github.com/openmrs/openmrs-module-labonfhir</url>
<uniqueVersion>true</uniqueVersion>
<id>repsy</id>
<name>My Private Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/intellisoftdev/default</url>
</snapshotRepository>
<repository>
<id>repsy</id>
<name>My Private Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/intellisoftdev/default</url>
</repository>
</distributionManagement>
</profile>
</profiles>
Expand All @@ -254,4 +257,17 @@
<openmrsPlatformVersion>2.3.1</openmrsPlatformVersion>
<hapifhirVersion>4.2.0</hapifhirVersion>
</properties>
<distributionManagement>
<!-- Deploy to Github Packages -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moshonk This is already deployed to OpenMRS Artifactory

<snapshotRepository>
<id>repsy</id>
<name>My Private Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/intellisoftdev/default</url>
</snapshotRepository>
<repository>
<id>repsy</id>
<name>My Private Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/intellisoftdev/default</url>
</repository>
</distributionManagement>
</project>
Loading