Skip to content

Commit 5d44fd7

Browse files
authored
Merge pull request #62 from mozzy11/report
Report
2 parents 075b391 + d246144 commit 5d44fd7

File tree

77 files changed

+1652
-1070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1652
-1070
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,26 @@ jobs:
2222

2323
# Steps represent a sequence of tasks that will be executed as part of the job
2424
steps:
25-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26-
- uses: actions/checkout@v2
27-
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
2828
- name: Set up JDK 1.8
29-
uses: actions/setup-java@v1
29+
uses: actions/setup-java@v4
3030
with:
31-
java-version: 8.0.232
31+
distribution: temurin
32+
java-version: 8
33+
cache: 'maven'
34+
3235
- name: Set up Maven
3336
uses: stCarolas/setup-maven@v4
3437
with:
3538
maven-version: 3.6.3
36-
- name: Cache Maven packages
37-
uses: actions/cache@v2
38-
with:
39-
path: ~/.m2
40-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
41-
restore-keys: ${{ runner.os }}-m2
4239

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

4643
- name: Set settings.xml
47-
uses: s4u/maven-settings-action@v2.6.0
44+
uses: s4u/maven-settings-action@v3.1.0
4845
with:
4946
servers: |
5047
[{

api/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,32 @@
1717
<groupId>org.openmrs.web</groupId>
1818
<artifactId>openmrs-web</artifactId>
1919
</dependency>
20+
<dependency>
21+
<groupId>org.openmrs.module</groupId>
22+
<artifactId>reporting-api</artifactId>
23+
<scope>provided</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.openmrs.module</groupId>
27+
<artifactId>reporting-api-2.0</artifactId>
28+
<scope>provided</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.openmrs.module</groupId>
32+
<artifactId>calculation-api</artifactId>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.openmrs.module</groupId>
37+
<artifactId>serialization.xstream-api</artifactId>
38+
<version>${serialization.xstreamVersion}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.openmrs.module</groupId>
43+
<artifactId>serialization.xstream-api-2.0</artifactId>
44+
<version>${serialization.xstreamVersion}</version>
45+
<scope>test</scope>
46+
</dependency>
2047
</dependencies>
2148
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.openmrs.module.labintegration;
2+
3+
import org.openmrs.module.reporting.report.manager.BaseReportManager;
4+
5+
public abstract class ActivatedReportManager extends BaseReportManager {
6+
7+
public boolean isActivated() {
8+
return true;
9+
}
10+
11+
}

api/src/main/java/org/openmrs/module/labintegration/LabIntegrationActivator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.openmrs.api.context.Context;
1414
import org.openmrs.module.BaseModuleActivator;
1515
import org.openmrs.module.labintegration.api.event.SaveEncounterAfterAdvice;
16+
import org.openmrs.module.reporting.report.manager.ReportManagerUtil;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
1819

@@ -30,6 +31,18 @@ public class LabIntegrationActivator extends BaseModuleActivator {
3031
public void started() {
3132
LOGGER.info("Started Lab Integration");
3233
Context.addAdvice(EncounterService.class, getFormSubmitAfterAdvice());
34+
//ReportManagerUtil.setupAllReports(ActivatedReportManager.class);
35+
for (ActivatedReportManager reportManager : Context.getRegisteredComponents(ActivatedReportManager.class)) {
36+
if (reportManager.isActivated()) {
37+
LOGGER.info("Setting up report " + reportManager.getName() + "...");
38+
try {
39+
ReportManagerUtil.setupReport(reportManager);
40+
}
41+
catch (Exception e) {
42+
LOGGER.error("Failed to setup '" + reportManager.getName() + "' report because of: " + e.getMessage());
43+
}
44+
}
45+
}
3346
}
3447

3548
/**
@@ -42,7 +55,6 @@ public void stopped() {
4255
}
4356

4457
private SaveEncounterAfterAdvice getFormSubmitAfterAdvice() {
45-
return Context.getRegisteredComponent(
46-
"labintegration.SaveEncounterAfterAdvice", SaveEncounterAfterAdvice.class);
58+
return Context.getRegisteredComponent("labintegration.SaveEncounterAfterAdvice", SaveEncounterAfterAdvice.class);
4759
}
4860
}

api/src/main/java/org/openmrs/module/labintegration/PropertiesUtil.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
import org.openmrs.api.context.Context;
66

77
public final class PropertiesUtil {
8-
9-
private static final String GP_LAB_ORDER_ENCOUNTER_TYPE_UUID = "labintegration.orderEncounterTypeUuid";
10-
11-
public static String getGlobalProperty(String propertyName) {
12-
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
13-
if (StringUtils.isBlank(propertyValue)) {
14-
throw new APIException(String.format("Property value for '%s' is not set", propertyName));
15-
}
16-
return propertyValue;
17-
}
18-
19-
public static boolean isGlobalPropertySet(String propertyName) {
20-
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
21-
return !StringUtils.isBlank(propertyValue);
22-
}
23-
24-
public static String getLabOrderEncounterTypeUuid() {
25-
return getGlobalProperty(GP_LAB_ORDER_ENCOUNTER_TYPE_UUID);
26-
}
27-
28-
private PropertiesUtil() {
29-
}
8+
9+
private static final String GP_LAB_ORDER_ENCOUNTER_TYPE_UUID = "labintegration.orderEncounterTypeUuid";
10+
11+
public static String getGlobalProperty(String propertyName) {
12+
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
13+
if (StringUtils.isBlank(propertyValue)) {
14+
throw new APIException(String.format("Property value for '%s' is not set", propertyName));
15+
}
16+
return propertyValue;
17+
}
18+
19+
public static boolean isGlobalPropertySet(String propertyName) {
20+
String propertyValue = Context.getAdministrationService().getGlobalProperty(propertyName);
21+
return !StringUtils.isBlank(propertyValue);
22+
}
23+
24+
public static String getLabOrderEncounterTypeUuid() {
25+
return getGlobalProperty(GP_LAB_ORDER_ENCOUNTER_TYPE_UUID);
26+
}
27+
28+
private PropertiesUtil() {
29+
}
3030
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.openmrs.module.labintegration.api;
2+
3+
import org.openmrs.Obs;
4+
import org.openmrs.api.OpenmrsService;
5+
6+
import java.util.Date;
7+
import java.util.List;
8+
9+
public interface LabIntegrationReportService extends OpenmrsService {
10+
11+
List<Obs> getLabResults(Date startDate, Date endDate);
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.openmrs.module.labintegration.api;
2+
3+
import org.openmrs.module.labintegration.api.hl7.ObsSelector;
4+
5+
public final class LabIntegrationReportsConstants {
6+
7+
public static final int TESTS_ORDERED_CONCEPT_ID = ObsSelector.TESTS_ORDERED_CONCEPT_ID;
8+
9+
public static final int FREE_TEXT_RESULT_CONCEPT_ID = 165399;
10+
11+
public static final String LOCATION_ISANTE_CODE_UUID = "0e52924e-4ebb-40ba-9b83-b198b532653b";
12+
13+
public static final String ISANTEPLUS_IDENDTIFIER_TYPE_UUID = "05a29f94-c0ed-11e2-94be-8c13b969e334";
14+
15+
private LabIntegrationReportsConstants() {
16+
}
17+
18+
}

api/src/main/java/org/openmrs/module/labintegration/api/alerts/AlertCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
import org.openmrs.Obs;
55

66
public interface AlertCreator {
7-
8-
void createAlert(Encounter encounter, Obs obs, String status);
7+
8+
void createAlert(Encounter encounter, Obs obs, String status);
99
}

api/src/main/java/org/openmrs/module/labintegration/api/alerts/OpenMrsAlertCreator.java

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,39 @@
2121

2222
@Component("alertCreator")
2323
public class OpenMrsAlertCreator implements AlertCreator {
24-
25-
private static final Logger LOGGER = LoggerFactory.getLogger(OpenMrsAlertCreator.class);
26-
27-
@Autowired
28-
private AlertService alertService;
29-
30-
@Autowired
31-
private UserService userService;
32-
33-
@Override
34-
public void createAlert(Encounter encounter, Obs obs, String status) {
35-
List<User> users = findUsers(encounter);
36-
if (CollectionUtils.isEmpty(users)) {
37-
LOGGER.warn("No users found for encounter: {}", encounter.getUuid());
38-
} else {
39-
registerAlerts(obs.getConcept(), encounter.getPatient(), users, status);
40-
}
41-
}
42-
43-
44-
private List<User> findUsers(Encounter encounter) {
45-
List<User> users = new ArrayList<>();
46-
for (EncounterProvider encProvider : encounter.getEncounterProviders()) {
47-
Person person = encProvider.getProvider().getPerson();
48-
users.addAll(userService.getUsersByPerson(person, false));
49-
}
50-
return users;
51-
}
52-
53-
private void registerAlerts(Concept concept, Patient patient, List<User> users, String status) {
54-
String text = String.format("Lab: %s received for %s test for patient %s", status,
55-
concept.getName().getName(), patient.getPersonName().toString());
56-
Alert alert = new Alert(text, users);
57-
alert.setCreator(users.get(0));
58-
alertService.saveAlert(alert);
59-
}
24+
25+
private static final Logger LOGGER = LoggerFactory.getLogger(OpenMrsAlertCreator.class);
26+
27+
@Autowired
28+
private AlertService alertService;
29+
30+
@Autowired
31+
private UserService userService;
32+
33+
@Override
34+
public void createAlert(Encounter encounter, Obs obs, String status) {
35+
List<User> users = findUsers(encounter);
36+
if (CollectionUtils.isEmpty(users)) {
37+
LOGGER.warn("No users found for encounter: {}", encounter.getUuid());
38+
} else {
39+
registerAlerts(obs.getConcept(), encounter.getPatient(), users, status);
40+
}
41+
}
42+
43+
private List<User> findUsers(Encounter encounter) {
44+
List<User> users = new ArrayList<>();
45+
for (EncounterProvider encProvider : encounter.getEncounterProviders()) {
46+
Person person = encProvider.getProvider().getPerson();
47+
users.addAll(userService.getUsersByPerson(person, false));
48+
}
49+
return users;
50+
}
51+
52+
private void registerAlerts(Concept concept, Patient patient, List<User> users, String status) {
53+
String text = String.format("Lab: %s received for %s test for patient %s", status, concept.getName().getName(),
54+
patient.getPersonName().toString());
55+
Alert alert = new Alert(text, users);
56+
alert.setCreator(users.get(0));
57+
alertService.saveAlert(alert);
58+
}
6059
}

api/src/main/java/org/openmrs/module/labintegration/api/event/SaveEncounterAfterAdvice.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ public class SaveEncounterAfterAdvice implements AfterReturningAdvice {
2424

2525
@Override
2626
public void afterReturning(Object savedObject, Method method, Object[] args, Object target) {
27-
if (StringUtils.equals(method.getName(), SAVE_ENCOUNTER_METHOD_NAME)
28-
&& savedObject != null) {
27+
if (StringUtils.equals(method.getName(), SAVE_ENCOUNTER_METHOD_NAME) && savedObject != null) {
2928
Encounter encounter = (Encounter) savedObject;
30-
LOGGER.info("Invoked saveEncounter method in EncounterService. Saved encounter {}",
31-
encounter.getUuid());
29+
LOGGER.info("Invoked saveEncounter method in EncounterService. Saved encounter {}", encounter.getUuid());
3230

33-
if (StringUtils.equals(PropertiesUtil.getLabOrderEncounterTypeUuid(),
34-
encounter.getEncounterType().getUuid())) {
31+
if (StringUtils.equals(PropertiesUtil.getLabOrderEncounterTypeUuid(), encounter.getEncounterType().getUuid())) {
3532
LOGGER.info("Order encounter occurred {}", encounter.getUuid());
3633
try {
3734
labIntegrationService.doOrder(encounter);
38-
} catch (Exception e) {
35+
}
36+
catch (Exception e) {
3937
// TODO
4038
LOGGER.error("Unable to send order messages", e);
4139
}

0 commit comments

Comments
 (0)