Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,26 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 8.0.232
distribution: temurin
java-version: 8
cache: 'maven'

- name: Set up Maven
uses: stCarolas/setup-maven@v4
with:
maven-version: 3.6.3
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and Test
run: mvn --batch-mode --update-snapshots clean package

- name: Set settings.xml
uses: s4u/maven-settings-action@v2.6.0
uses: s4u/maven-settings-action@v3.1.0
with:
servers: |
[{
Expand Down
27 changes: 27 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,32 @@
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api-2.0</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>calculation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api</artifactId>
<version>${serialization.xstreamVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api-2.0</artifactId>
<version>${serialization.xstreamVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.openmrs.module.labintegration;

import org.openmrs.module.reporting.report.manager.BaseReportManager;

public abstract class ActivatedReportManager extends BaseReportManager {

public boolean isActivated() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.labintegration.api.event.SaveEncounterAfterAdvice;
import org.openmrs.module.reporting.report.manager.ReportManagerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -30,6 +31,18 @@ public class LabIntegrationActivator extends BaseModuleActivator {
public void started() {
LOGGER.info("Started Lab Integration");
Context.addAdvice(EncounterService.class, getFormSubmitAfterAdvice());
//ReportManagerUtil.setupAllReports(ActivatedReportManager.class);
for (ActivatedReportManager reportManager : Context.getRegisteredComponents(ActivatedReportManager.class)) {
if (reportManager.isActivated()) {
LOGGER.info("Setting up report " + reportManager.getName() + "...");
try {
ReportManagerUtil.setupReport(reportManager);
}
catch (Exception e) {
LOGGER.error("Failed to setup '" + reportManager.getName() + "' report because of: " + e.getMessage());
}
}
}
}

/**
Expand All @@ -42,7 +55,6 @@ public void stopped() {
}

private SaveEncounterAfterAdvice getFormSubmitAfterAdvice() {
return Context.getRegisteredComponent(
"labintegration.SaveEncounterAfterAdvice", SaveEncounterAfterAdvice.class);
return Context.getRegisteredComponent("labintegration.SaveEncounterAfterAdvice", SaveEncounterAfterAdvice.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
import org.openmrs.api.context.Context;

public final class PropertiesUtil {
private static final String GP_LAB_ORDER_ENCOUNTER_TYPE_UUID = "labintegration.orderEncounterTypeUuid";
public static String getGlobalProperty(String propertyName) {
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
if (StringUtils.isBlank(propertyValue)) {
throw new APIException(String.format("Property value for '%s' is not set", propertyName));
}
return propertyValue;
}

public static boolean isGlobalPropertySet(String propertyName) {
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
return !StringUtils.isBlank(propertyValue);
}

public static String getLabOrderEncounterTypeUuid() {
return getGlobalProperty(GP_LAB_ORDER_ENCOUNTER_TYPE_UUID);
}

private PropertiesUtil() {
}
private static final String GP_LAB_ORDER_ENCOUNTER_TYPE_UUID = "labintegration.orderEncounterTypeUuid";
public static String getGlobalProperty(String propertyName) {
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
if (StringUtils.isBlank(propertyValue)) {
throw new APIException(String.format("Property value for '%s' is not set", propertyName));
}
return propertyValue;
}
public static boolean isGlobalPropertySet(String propertyName) {
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
return !StringUtils.isBlank(propertyValue);
}
public static String getLabOrderEncounterTypeUuid() {
return getGlobalProperty(GP_LAB_ORDER_ENCOUNTER_TYPE_UUID);
}
private PropertiesUtil() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openmrs.module.labintegration.api;

import org.openmrs.Obs;
import org.openmrs.api.OpenmrsService;

import java.util.Date;
import java.util.List;

public interface LabIntegrationReportService extends OpenmrsService {

List<Obs> getLabResults(Date startDate, Date endDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openmrs.module.labintegration.api;

import org.openmrs.module.labintegration.api.hl7.ObsSelector;

public final class LabIntegrationReportsConstants {

public static final int TESTS_ORDERED_CONCEPT_ID = ObsSelector.TESTS_ORDERED_CONCEPT_ID;

public static final int FREE_TEXT_RESULT_CONCEPT_ID = 165399;

public static final String LOCATION_ISANTE_CODE_UUID = "0e52924e-4ebb-40ba-9b83-b198b532653b";

public static final String ISANTEPLUS_IDENDTIFIER_TYPE_UUID = "05a29f94-c0ed-11e2-94be-8c13b969e334";

private LabIntegrationReportsConstants() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import org.openmrs.Obs;

public interface AlertCreator {

void createAlert(Encounter encounter, Obs obs, String status);
void createAlert(Encounter encounter, Obs obs, String status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,39 @@

@Component("alertCreator")
public class OpenMrsAlertCreator implements AlertCreator {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenMrsAlertCreator.class);

@Autowired
private AlertService alertService;

@Autowired
private UserService userService;

@Override
public void createAlert(Encounter encounter, Obs obs, String status) {
List<User> users = findUsers(encounter);
if (CollectionUtils.isEmpty(users)) {
LOGGER.warn("No users found for encounter: {}", encounter.getUuid());
} else {
registerAlerts(obs.getConcept(), encounter.getPatient(), users, status);
}
}


private List<User> findUsers(Encounter encounter) {
List<User> users = new ArrayList<>();
for (EncounterProvider encProvider : encounter.getEncounterProviders()) {
Person person = encProvider.getProvider().getPerson();
users.addAll(userService.getUsersByPerson(person, false));
}
return users;
}

private void registerAlerts(Concept concept, Patient patient, List<User> users, String status) {
String text = String.format("Lab: %s received for %s test for patient %s", status,
concept.getName().getName(), patient.getPersonName().toString());
Alert alert = new Alert(text, users);
alert.setCreator(users.get(0));
alertService.saveAlert(alert);
}

private static final Logger LOGGER = LoggerFactory.getLogger(OpenMrsAlertCreator.class);

@Autowired
private AlertService alertService;

@Autowired
private UserService userService;

@Override
public void createAlert(Encounter encounter, Obs obs, String status) {
List<User> users = findUsers(encounter);
if (CollectionUtils.isEmpty(users)) {
LOGGER.warn("No users found for encounter: {}", encounter.getUuid());
} else {
registerAlerts(obs.getConcept(), encounter.getPatient(), users, status);
}
}

private List<User> findUsers(Encounter encounter) {
List<User> users = new ArrayList<>();
for (EncounterProvider encProvider : encounter.getEncounterProviders()) {
Person person = encProvider.getProvider().getPerson();
users.addAll(userService.getUsersByPerson(person, false));
}
return users;
}

private void registerAlerts(Concept concept, Patient patient, List<User> users, String status) {
String text = String.format("Lab: %s received for %s test for patient %s", status, concept.getName().getName(),
patient.getPersonName().toString());
Alert alert = new Alert(text, users);
alert.setCreator(users.get(0));
alertService.saveAlert(alert);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ public class SaveEncounterAfterAdvice implements AfterReturningAdvice {

@Override
public void afterReturning(Object savedObject, Method method, Object[] args, Object target) {
if (StringUtils.equals(method.getName(), SAVE_ENCOUNTER_METHOD_NAME)
&& savedObject != null) {
if (StringUtils.equals(method.getName(), SAVE_ENCOUNTER_METHOD_NAME) && savedObject != null) {
Encounter encounter = (Encounter) savedObject;
LOGGER.info("Invoked saveEncounter method in EncounterService. Saved encounter {}",
encounter.getUuid());
LOGGER.info("Invoked saveEncounter method in EncounterService. Saved encounter {}", encounter.getUuid());

if (StringUtils.equals(PropertiesUtil.getLabOrderEncounterTypeUuid(),
encounter.getEncounterType().getUuid())) {
if (StringUtils.equals(PropertiesUtil.getLabOrderEncounterTypeUuid(), encounter.getEncounterType().getUuid())) {
LOGGER.info("Order encounter occurred {}", encounter.getUuid());
try {
labIntegrationService.doOrder(encounter);
} catch (Exception e) {
}
catch (Exception e) {
// TODO
LOGGER.error("Unable to send order messages", e);
}
Expand Down
Loading