From cf7c477a8400854bddc6f9efe094062ffb45fb21 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 24 May 2024 12:15:53 -0400 Subject: [PATCH 01/15] Upgrade testdatamanager and ensures test data follows correct modeling for dispositions to use obs groups --- ...itingAdmissionVisitQueryEvaluatorTest.java | 141 ++++-------------- .../VisitDomainWrapperComponentTest.java | 18 ++- pom.xml | 2 +- 3 files changed, 37 insertions(+), 124 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java index 2e2b267e..69a85b91 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java @@ -11,8 +11,8 @@ import org.openmrs.Patient; import org.openmrs.Visit; import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; import org.openmrs.contrib.testdata.TestDataManager; +import org.openmrs.contrib.testdata.builder.ObsBuilder; import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; @@ -72,6 +72,12 @@ public void setup() throws Exception { patient = testDataManager.randomPatient().birthdate("2010-01-01").save(); } + private Obs createDispositionObs(Encounter encounter, Concept disposition) { + ObsBuilder groupBuilder = testDataManager.obs().encounter(encounter).concept(dispositionDescriptor.getDispositionSetConcept()); + groupBuilder.member(testDataManager.obs().encounter(encounter).concept(dispositionDescriptor.getDispositionConcept()).value(disposition).get()); + return groupBuilder.save(); + } + @Test public void shouldFindVisitAwaitingAdmission() throws Exception { @@ -88,12 +94,7 @@ public void shouldFindVisitAwaitingAdmission() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - Obs obs = testDataManager.obs() - .person(patient) - .encounter(encounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(encounter, admitToHospital); VisitQueryResult result = visitQueryService.evaluate(query, null); assertThat(result.getMemberIds().size(), is(1)); @@ -120,12 +121,7 @@ public void shouldNotCountDispositionOnVoidedEncounter() throws Exception { .dateVoided(new Date()) .voidReason("test") .save(); - Obs obs = testDataManager.obs() - .person(patient) - .encounter(encounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(encounter, admitToHospital); VisitQueryResult result = visitQueryService.evaluate(query, null); assertThat(result.getMemberIds().size(), is(0)); @@ -151,12 +147,7 @@ public void shouldNotFindVisitIfPatientAdmitted() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter admissionEncounter = testDataManager.encounter() .patient(patient) .encounterDatetime(admitDatetime) @@ -187,12 +178,7 @@ public void shouldNotConsiderVoidedAdmissionEncounter() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter admissionEncounter = testDataManager.encounter() .patient(patient) .encounterDatetime(admitDatetime) @@ -227,12 +213,7 @@ public void shouldFindVisitEvenIfPatientHasMoreRecentVisitNoteWithoutAdmissionDi .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter secondVisitNoteEncounter = testDataManager.encounter() .patient(patient) .encounterDatetime(secondVisitNoteDatetime) @@ -269,12 +250,7 @@ public void shouldNotFindVisitIfNoAdmitDisposition() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(emrConceptService.getConcept("org.openmrs.module.emrapi:Death")) - .save(); + createDispositionObs(visitNoteEncounter, emrConceptService.getConcept("org.openmrs.module.emrapi:Death")); VisitQueryResult result = visitQueryService.evaluate(query, null); assertThat(result.getMemberIds().size(), is(0)); @@ -301,12 +277,7 @@ public void shouldNotFindVisitIfAtAnotherLocation() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); query.setLocation(queryLocation); VisitQueryResult result = visitQueryService.evaluate(query, null); @@ -333,12 +304,7 @@ public void shouldFindVisitIfAtSameLocation() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); query.setLocation(queryLocation); VisitQueryResult result = visitQueryService.evaluate(query, null); @@ -361,12 +327,7 @@ public void shouldNotReturnSameVisitTwice() throws Exception { .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new Date()) @@ -401,12 +362,7 @@ public void shouldNotFindVisitAwaitingAdmissionIfPatientNotInContext() throws Ex .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); EvaluationContext context = new EvaluationContext(); context.setBaseCohort(new Cohort(Collections.singleton(2))); @@ -430,12 +386,7 @@ public void shouldNotFindVisitAwaitingAdmissionIfVisitNotInContext() throws Exce .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); VisitEvaluationContext context = new VisitEvaluationContext(); context.setBaseVisits(new VisitIdSet(10101)); // random visit id @@ -459,12 +410,7 @@ public void shouldNotFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialO .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,10,11,0,0).toDate()) @@ -497,12 +443,7 @@ public void shouldFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialObsF .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,10,11,0,0).toDate()) @@ -548,12 +489,7 @@ public void shouldNotFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialO .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,10,11,0,0).toDate()) @@ -572,12 +508,7 @@ public void shouldNotFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialO .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter3) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter3, admitToHospital); Encounter visitNoteEncounter4 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,10,13,0,0).toDate()) @@ -610,12 +541,7 @@ public void shouldFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDecisionTh .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,10,11,0,0).toDate()) @@ -649,12 +575,7 @@ public void shouldFindVisitWithDispositionOfAdmitIfPrecededByAdmissionDenialObs( .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,9,10,0,0).toDate()) @@ -688,12 +609,7 @@ public void shouldFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialObsT .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); Encounter visitNoteEncounter2 = testDataManager.encounter() .patient(patient) .encounterDatetime(new DateTime(2014,10,11,10,0,0).toDate()) @@ -736,12 +652,7 @@ public void shouldNotFindVisitAwaitingAdmissionIfPatientIsDead() throws Exceptio .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter, admitToHospital); VisitQueryResult result = visitQueryService.evaluate(query, null); assertThat(result.getMemberIds().size(), is(0)); diff --git a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java index 201f5c1e..44f58041 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java @@ -4,6 +4,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.openmrs.Concept; import org.openmrs.Encounter; import org.openmrs.EncounterType; import org.openmrs.Location; @@ -14,6 +15,7 @@ import org.openmrs.api.VisitService; import org.openmrs.api.context.Context; import org.openmrs.contrib.testdata.TestDataManager; +import org.openmrs.contrib.testdata.builder.ObsBuilder; import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.concept.EmrConceptService; @@ -76,6 +78,12 @@ public void setup() throws Exception { Context.flushSession(); } + private Obs createDispositionObs(Encounter encounter, Concept disposition) { + ObsBuilder groupBuilder = testDataManager.obs().encounter(encounter).concept(dispositionDescriptor.getDispositionSetConcept()); + groupBuilder.member(testDataManager.obs().encounter(encounter).concept(dispositionDescriptor.getDispositionConcept()).value(disposition).get()); + return groupBuilder.save(); + } + @Test public void testThatBeanCanHavePropertiesAutowired() throws Exception { VisitDomainWrapper visitDomainWrapper = factory.newVisitDomainWrapper(); @@ -102,11 +110,8 @@ public void isAwaitingAdmission_shouldReturnTrueIfVisitAwaitingAdmission() throw .visit(visit) .encounterDatetime(new Date()) .encounterType(emrApiProperties.getVisitNoteEncounterType()) - .obs(testDataManager.obs() - .concept(dispositionDescriptor.getDispositionConcept()) - .value(emrConceptService.getConcept("org.openmrs.module.emrapi:Admit to hospital")) - .get()) .save(); + createDispositionObs(encounter, emrConceptService.getConcept("org.openmrs.module.emrapi:Admit to hospital")); VisitDomainWrapper visitDomainWrapper = factory.newVisitDomainWrapper(visit); assertThat(visitDomainWrapper.isAwaitingAdmission(), is(true)); @@ -135,11 +140,8 @@ public void isAwaitingAdmission_shouldReturnFalseIfVisitNotAwaitingAdmission() t .voided(true) .dateVoided(new Date()) .voidReason("test") - .obs(testDataManager.obs() - .concept(dispositionDescriptor.getDispositionConcept()) - .value(emrConceptService.getConcept("org.openmrs.module.emrapi:Admit to hospital")) - .get()) .save(); + createDispositionObs(encounter, emrConceptService.getConcept("org.openmrs.module.emrapi:Admit to hospital")); VisitDomainWrapper visitDomainWrapper = factory.newVisitDomainWrapper(visit); assertThat(visitDomainWrapper.isAwaitingAdmission(), is(false)); diff --git a/pom.xml b/pom.xml index b84947e8..a319b9d8 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ UTF-8 2.2.1 1.16.0 - 1.7.0 + 1.8.0-SNAPSHOT 1.25.0 0.2.16 1.3.0 From 94482cf2685bf17b7c56f491b41002bb2ee27d3d Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 24 May 2024 12:30:13 -0400 Subject: [PATCH 02/15] Additional fix --- .../AwaitingAdmissionVisitQueryEvaluatorTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java index 69a85b91..72614589 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java @@ -462,12 +462,7 @@ public void shouldFindVisitWithDispositionOfAdmitIfFollowedByAdmissionDenialObsF .encounterType(emrApiProperties.getVisitNoteEncounterType()) .visit(visit) .save(); - testDataManager.obs() - .person(patient) - .encounter(visitNoteEncounter3) - .concept(dispositionDescriptor.getDispositionConcept()) - .value(admitToHospital) - .save(); + createDispositionObs(visitNoteEncounter3, admitToHospital); VisitQueryResult result = visitQueryService.evaluate(query, null); assertThat(result.getMemberIds().size(), is(1)); From 00bfd8deaefe505a76b780e036a9bf3c5d3bacc7 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 24 May 2024 20:45:42 -0400 Subject: [PATCH 03/15] EA-184 - Initial work to make hql available for awaiting admission --- .../openmrs/module/emrapi/db/EmrVisitDAO.java | 17 +-- .../module/emrapi/db/EmrVisitDAOImpl.java | 105 ++++-------------- .../diagnosis/ObsGroupDiagnosisService.java | 50 +++++++-- .../main/resources/hql/patients_diagnoses.hql | 2 +- .../hql/visit_confirmed_diagnoses.hql | 6 +- .../main/resources/hql/visit_diagnoses.hql | 4 +- .../resources/hql/visit_primary_diagnoses.hql | 6 +- 7 files changed, 79 insertions(+), 111 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java index 0a90ff2d..a7314488 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java +++ b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java @@ -1,20 +1,11 @@ package org.openmrs.module.emrapi.db; import java.util.List; - -import org.openmrs.Obs; -import org.openmrs.Visit; -import org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata; +import java.util.Map; public interface EmrVisitDAO { - - List getDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata); - - List getPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata); - - List getConfirmedDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata); - - List getConfirmedPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata); - List getAllPatientsWithDiagnosis(DiagnosisMetadata diagnosisMetadata); + List executeHql(String queryString, Map parameters, Class clazz); + + List executeHqlFromResource(String resource, Map parameters, Class clazz); } diff --git a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java index 9855283f..c4f31fbe 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java @@ -1,109 +1,52 @@ package org.openmrs.module.emrapi.db; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Query; -import org.openmrs.Obs; -import org.openmrs.Visit; import org.openmrs.api.db.hibernate.DbSessionFactory; -import org.openmrs.module.emrapi.diagnosis.Diagnosis; -import org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; public class EmrVisitDAOImpl implements EmrVisitDAO { protected final Log log = LogFactory.getLog(getClass()); - protected static String RESOURCE_NOT_FOUND = "The HQL query resource file was not found."; - - protected static String DIAGNOSES_HQL = "hql/visit_diagnoses.hql"; - protected static String PRIMARY_DIAGNOSES_HQL = "hql/visit_primary_diagnoses.hql"; - protected static String CONFIRMED_DIAGNOSES_HQL = "hql/visit_confirmed_diagnoses.hql"; - protected static String CONFIRMED_PRIMARY_DIAGNOSES_HQL = "hql/visit_confirmed_primary_diagnoses.hql"; - protected static String PATIENTS_DIAGNOSES_HQL = "hql/patients_diagnoses.hql"; - private DbSessionFactory sessionFactory; public void setSessionFactory(DbSessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } - @SuppressWarnings("unchecked") @Override - public List getDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { - String queryString = ""; - try { - queryString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(DIAGNOSES_HQL)); - } catch (IOException e) { - log.error(RESOURCE_NOT_FOUND, e); - return Collections.emptyList(); - } - Query query = sessionFactory.getCurrentSession().createQuery(queryString); - query.setInteger("visitId", visit.getId()); - query.setInteger("diagnosisOrderConceptId", diagnosisMetadata.getDiagnosisOrderConcept().getId()); - - return (List) query.list(); - } - @SuppressWarnings("unchecked") - @Override - public List getPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { - String queryString = ""; - try { - queryString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(PRIMARY_DIAGNOSES_HQL)); - } catch (IOException e) { - log.error(RESOURCE_NOT_FOUND, e); - return Collections.emptyList(); - } + public List executeHql(String queryString, Map parameters, Class clazz) { Query query = sessionFactory.getCurrentSession().createQuery(queryString); - query.setInteger("visitId", visit.getId()); - query.setInteger("diagnosisOrderConceptId", diagnosisMetadata.getDiagnosisOrderConcept().getId()); - query.setInteger("primaryOrderConceptId", diagnosisMetadata.getConceptFor(Diagnosis.Order.PRIMARY).getId()); - return (List) query.list(); - } - - @SuppressWarnings("unchecked") - @Override - public List getConfirmedDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { - String queryString = ""; - try { - queryString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(CONFIRMED_DIAGNOSES_HQL)); - } catch (IOException e) { - log.error(RESOURCE_NOT_FOUND, e); - return Collections.emptyList(); + for (String parameter : parameters.keySet()) { + Object value = parameters.get(parameter); + query.setParameter(parameter, value); } - Query query = sessionFactory.getCurrentSession().createQuery(queryString); - query.setInteger("visitId", visit.getId()); - query.setInteger("diagnosisCertaintyConceptId", diagnosisMetadata.getDiagnosisCertaintyConcept().getId()); - query.setInteger("confirmedCertaintyConceptId", diagnosisMetadata.getConceptFor(Diagnosis.Certainty.CONFIRMED).getId()); - return (List) query.list(); - } - - @SuppressWarnings("unchecked") - @Override - public List getConfirmedPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { - List confirmedDiagnoses = getConfirmedDiagnoses(visit, diagnosisMetadata); - List primaryDiagnoses = getPrimaryDiagnoses(visit, diagnosisMetadata); - confirmedDiagnoses.retainAll(primaryDiagnoses); - return confirmedDiagnoses; + return query.list(); } @Override - public List getAllPatientsWithDiagnosis(DiagnosisMetadata diagnosisMetadata) { - String queryString = ""; - try { - queryString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(PATIENTS_DIAGNOSES_HQL)); - } catch (IOException e) { - log.error(RESOURCE_NOT_FOUND, e); - return Collections.emptyList(); + public List executeHqlFromResource(String resource, Map parameters, Class clazz) { + String hql = null; + try (InputStream is = getClass().getClassLoader().getResourceAsStream(resource)) { + if (is != null) { + hql = IOUtils.toString(is, StandardCharsets.UTF_8); + } } - Query query = sessionFactory.getCurrentSession().createQuery(queryString); - query.setInteger("diagnosisSetConceptId", diagnosisMetadata.getDiagnosisSetConcept().getConceptId()); - return query.list(); + catch (IOException e) { + throw new RuntimeException("Error loading " + resource, e); + } + if (hql == null) { + throw new RuntimeException("No resource found for " + resource); + } + return executeHql(hql, parameters, clazz); } } diff --git a/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java b/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java index bcba2f3b..c3682988 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java @@ -17,9 +17,11 @@ import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; public class ObsGroupDiagnosisService { @@ -196,23 +198,55 @@ public List getUniqueDiagnoses(Patient patient, Date fromDate) { return diagnoses; } + public List getDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { + Map parameters = new HashMap<>(); + parameters.put("visit", visit); + parameters.put("diagnosisOrderConcept", diagnosisMetadata.getDiagnosisOrderConcept()); + return emrVisitDAO.executeHqlFromResource("hql/visit_diagnoses.hql", parameters, Obs.class); + } + + public List getPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { + Map parameters = new HashMap<>(); + parameters.put("visit", visit); + parameters.put("diagnosisOrderConcept", diagnosisMetadata.getDiagnosisOrderConcept()); + parameters.put("primaryOrderConcept", diagnosisMetadata.getConceptFor(Diagnosis.Order.PRIMARY)); + return emrVisitDAO.executeHqlFromResource("hql/visit_primary_diagnoses.hql", parameters, Obs.class); + } + + public List getConfirmedDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { + Map parameters = new HashMap<>(); + parameters.put("visit", visit); + parameters.put("diagnosisCertaintyConcept", diagnosisMetadata.getDiagnosisCertaintyConcept()); + parameters.put("confirmedCertaintyConcept", diagnosisMetadata.getConceptFor(Diagnosis.Certainty.CONFIRMED)); + return emrVisitDAO.executeHqlFromResource("hql/visit_confirmed_diagnoses.hql", parameters, Obs.class); + } + + public List getConfirmedPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { + List confirmedDiagnoses = getConfirmedDiagnoses(visit, diagnosisMetadata); + List primaryDiagnoses = getPrimaryDiagnoses(visit, diagnosisMetadata); + confirmedDiagnoses.retainAll(primaryDiagnoses); + return confirmedDiagnoses; + } + + public List getAllPatientsWithDiagnosis(DiagnosisMetadata diagnosisMetadata) { + Map parameters = new HashMap<>(); + parameters.put("diagnosisSetConcept", diagnosisMetadata.getDiagnosisSetConcept()); + return emrVisitDAO.executeHqlFromResource("hql/patients_diagnoses.hql", parameters, Integer.class); + } + public List getDiagnosesAsObs(Visit visit, DiagnosisMetadata diagnosisMetadata, Boolean primaryOnly, Boolean confirmedOnly) { if (primaryOnly == true) { if (confirmedOnly == false) { - return emrVisitDAO.getPrimaryDiagnoses(visit, diagnosisMetadata); + return getPrimaryDiagnoses(visit, diagnosisMetadata); } else { - return emrVisitDAO.getConfirmedPrimaryDiagnoses(visit, diagnosisMetadata); + return getConfirmedPrimaryDiagnoses(visit, diagnosisMetadata); } } else { if (confirmedOnly == false) { - return emrVisitDAO.getDiagnoses(visit, diagnosisMetadata); + return getDiagnoses(visit, diagnosisMetadata); } else { - return emrVisitDAO.getConfirmedDiagnoses(visit, diagnosisMetadata); + return getConfirmedDiagnoses(visit, diagnosisMetadata); } } } - - public List getAllPatientsWithDiagnosis(DiagnosisMetadata diagnosisMetadata) { - return emrVisitDAO.getAllPatientsWithDiagnosis(diagnosisMetadata); - } } diff --git a/api/src/main/resources/hql/patients_diagnoses.hql b/api/src/main/resources/hql/patients_diagnoses.hql index dc4ce612..e133deab 100644 --- a/api/src/main/resources/hql/patients_diagnoses.hql +++ b/api/src/main/resources/hql/patients_diagnoses.hql @@ -6,5 +6,5 @@ where p.voided = 'false' and p.patientId in(select distinct personId from Obs o where - o.concept.conceptId = :diagnosisSetConceptId + o.concept = :diagnosisSetConcept ) diff --git a/api/src/main/resources/hql/visit_confirmed_diagnoses.hql b/api/src/main/resources/hql/visit_confirmed_diagnoses.hql index 6eb10218..fdb34a38 100644 --- a/api/src/main/resources/hql/visit_confirmed_diagnoses.hql +++ b/api/src/main/resources/hql/visit_confirmed_diagnoses.hql @@ -4,8 +4,8 @@ from Obs o where o.voided = 'false' - and (o.encounter.visit = :visitId) - and o.concept.conceptId = :diagnosisCertaintyConceptId - and o.valueCoded.conceptId = :confirmedCertaintyConceptId + and (o.encounter.visit = :visit) + and o.concept = :diagnosisCertaintyConcept + and o.valueCoded = :confirmedCertaintyConcept group by o.encounter, o.obsGroup order by o.encounter.encounterDatetime desc, o.obsGroup.obsDatetime desc \ No newline at end of file diff --git a/api/src/main/resources/hql/visit_diagnoses.hql b/api/src/main/resources/hql/visit_diagnoses.hql index b36fd0a4..28166a2f 100644 --- a/api/src/main/resources/hql/visit_diagnoses.hql +++ b/api/src/main/resources/hql/visit_diagnoses.hql @@ -4,7 +4,7 @@ from Obs o where o.voided = 'false' - and (o.encounter.visit = :visitId) - and o.concept.conceptId = :diagnosisOrderConceptId + and (o.encounter.visit = :visit) + and o.concept = :diagnosisOrderConcept group by o.encounter, o.obsGroup order by o.encounter.encounterDatetime desc, o.obsGroup.obsDatetime desc \ No newline at end of file diff --git a/api/src/main/resources/hql/visit_primary_diagnoses.hql b/api/src/main/resources/hql/visit_primary_diagnoses.hql index b8ab2738..bd19a556 100644 --- a/api/src/main/resources/hql/visit_primary_diagnoses.hql +++ b/api/src/main/resources/hql/visit_primary_diagnoses.hql @@ -2,8 +2,8 @@ select o1 from Obs o inner join o.obsGroup o1 where o.voided = 'false' - and (o.encounter.visit = :visitId) - and o.concept.conceptId = :diagnosisOrderConceptId - and o.valueCoded.conceptId = :primaryOrderConceptId + and (o.encounter.visit = :visit) + and o.concept = :diagnosisOrderConcept + and o.valueCoded = :primaryOrderConcept group by o.encounter, o1.obsId, o.encounter.encounterDatetime order by o.encounter.encounterDatetime desc, o.obsGroup.obsDatetime desc From db678589530a93cf24238e3ede91c0003ac75842 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 24 May 2024 21:47:29 -0400 Subject: [PATCH 04/15] EA-184 - Demonstrate moving out of hql query builder and into an hql script --- .../AwaitingAdmissionVisitQueryEvaluator.java | 65 +++++++------------ .../module/emrapi/db/EmrVisitDAOImpl.java | 8 ++- .../hql/visits_awaiting_admission.hql | 36 ++++++++++ 3 files changed, 67 insertions(+), 42 deletions(-) create mode 100644 api/src/main/resources/hql/visits_awaiting_admission.hql diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java index 2b3e6a01..2c7e1ad5 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java @@ -1,24 +1,25 @@ package org.openmrs.module.emrapi.adt.reporting.evaluator; import org.openmrs.Location; -import org.openmrs.Visit; import org.openmrs.annotation.Handler; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; import org.openmrs.module.emrapi.adt.util.AdtUtil; import org.openmrs.module.emrapi.concept.EmrConceptService; +import org.openmrs.module.emrapi.db.EmrVisitDAO; import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.reporting.evaluation.EvaluationContext; import org.openmrs.module.reporting.evaluation.EvaluationException; -import org.openmrs.module.reporting.evaluation.querybuilder.HqlQueryBuilder; -import org.openmrs.module.reporting.evaluation.service.EvaluationService; +import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext; import org.openmrs.module.reporting.query.visit.VisitQueryResult; import org.openmrs.module.reporting.query.visit.definition.VisitQuery; import org.openmrs.module.reporting.query.visit.evaluator.VisitQueryEvaluator; import org.springframework.beans.factory.annotation.Autowired; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Handler(supports = AwaitingAdmissionVisitQuery.class) public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator { @@ -36,7 +37,7 @@ public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator EmrApiProperties emrApiProperties; @Autowired - EvaluationService evaluationService; + EmrVisitDAO visitDAO; @Override public VisitQueryResult evaluate(VisitQuery visitQuery, EvaluationContext evaluationContext) throws EvaluationException { @@ -49,44 +50,26 @@ public VisitQueryResult evaluate(VisitQuery visitQuery, EvaluationContext evalua visitLocation = adtService.getLocationThatSupportsVisits(location); } - HqlQueryBuilder query = new HqlQueryBuilder(); - - // distinct *active* visits with a disposition of type ADMIT (on any encounter from that visit) - // that is NOT followed by a admission decision obs with a value of "DENY" and with no Admission Encounters - query.select("distinct visit.visitId").from(Visit.class, "visit") - .innerJoin("visit.encounters", "dispoEncounter") - .innerJoin("dispoEncounter.obs", "dispo") - .whereEqual("dispo.concept", dispositionService.getDispositionDescriptor().getDispositionConcept()) - .whereIn("dispo.valueCoded", AdtUtil.getAdmissionDispositionsConcepts(emrConceptService, dispositionService)) - .whereEqual("dispo.voided", false) - .whereEqual("dispoEncounter.voided", false) - .whereEqual("visit.voided", false) - .whereEqual("visit.location", visitLocation) - .whereEqual("visit.patient.dead", false) // exclude dead patients - .whereNull("visit.stopDatetime") // stopDatetime = null means "active visit" - .where("(select count(*) from Encounter as admission " // count=0, ie no admission encounters - + "where admission.visit = visit " - + "and admission.voided = false " - + "and admission.encounterType = :admissionEncounterType" - + ") = 0") - .where("(select count(*) from Obs as admitDecision inner join admitDecision.encounter as encounterInVisit " // count=0, ie no admission decision obs with value=deny - + "where encounterInVisit.visit = visit " - + "and encounterInVisit.voided = false " - + "and admitDecision.voided = false " - + "and admitDecision.concept = :admissionDecisionConcept " - + "and admitDecision.valueCoded = :denyAdmissionConcept " - + "and encounterInVisit.encounterDatetime > dispoEncounter.encounterDatetime " // see https://issues.openmrs.org/browse/EA-31 - + ") = 0") - // restrict by context - .whereVisitIn("visit", evaluationContext) - // add parameters - .withValue("admissionEncounterType", emrApiProperties.getAdmissionEncounterType()) - .withValue("admissionDecisionConcept", emrApiProperties.getAdmissionDecisionConcept()) - .withValue("denyAdmissionConcept", emrApiProperties.getDenyAdmissionConcept()); - + Map parameters = new HashMap<>(); + parameters.put("dispositionConcept", dispositionService.getDispositionDescriptor().getDispositionConcept()); + parameters.put("admissionDispositions", AdtUtil.getAdmissionDispositionsConcepts(emrConceptService, dispositionService)); + parameters.put("visitLocation", visitLocation); + parameters.put("admissionEncounterType", emrApiProperties.getAdmissionEncounterType()); + parameters.put("admissionDecisionConcept", emrApiProperties.getAdmissionDecisionConcept()); + parameters.put("denyAdmissionConcept", emrApiProperties.getDenyAdmissionConcept()); + parameters.put("patientIds", null); + parameters.put("visitIds", null); + if (evaluationContext.getBaseCohort() != null) { + parameters.put("patientIds", evaluationContext.getBaseCohort().getMemberIds()); + } + if (evaluationContext instanceof VisitEvaluationContext) { + VisitEvaluationContext visitEvaluationContext = (VisitEvaluationContext) evaluationContext; + if (visitEvaluationContext.getBaseVisits() != null) { + parameters.put("visitIds", visitEvaluationContext.getBaseVisits().getMemberIds()); + } + } + List results = visitDAO.executeHqlFromResource("hql/visits_awaiting_admission.hql", parameters, Integer.class); VisitQueryResult result = new VisitQueryResult(visitQuery, evaluationContext); - - List results= evaluationService.evaluateToList(query, Integer.class, evaluationContext); result.add(results.toArray(new Integer[results.size()])); return result; diff --git a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java index c4f31fbe..81a7b06b 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -28,7 +29,12 @@ public List executeHql(String queryString, Map parameters Query query = sessionFactory.getCurrentSession().createQuery(queryString); for (String parameter : parameters.keySet()) { Object value = parameters.get(parameter); - query.setParameter(parameter, value); + if (value instanceof Collection) { + query.setParameterList(parameter, (Collection) value); + } + else { + query.setParameter(parameter, value); + } } return query.list(); } diff --git a/api/src/main/resources/hql/visits_awaiting_admission.hql b/api/src/main/resources/hql/visits_awaiting_admission.hql new file mode 100644 index 00000000..f1c9fbf0 --- /dev/null +++ b/api/src/main/resources/hql/visits_awaiting_admission.hql @@ -0,0 +1,36 @@ +select + distinct visit.visitId +from + Obs as dispo +inner join dispo.encounter as dispoEncounter +inner join dispoEncounter.visit as visit +inner join dispo.person as person +where + dispo.voided = false + and dispoEncounter.voided = false + and visit.voided = false + and dispo.concept = :dispositionConcept + and dispo.valueCoded in :admissionDispositions + and (:visitLocation is null or visit.location = :visitLocation) + and (:patientIds is null or person.personId in :patientIds) + and (:visitIds is null or visit.visitId in :visitIds) + and person.dead = false + and visit.stopDatetime is null + and ( + select count(*) + from Encounter as admission + where admission.visit = visit + and admission.voided = false + and admission.encounterType = :admissionEncounterType + ) = 0 + and ( + select count(*) + from Obs as admitDecision + inner join admitDecision.encounter as encounterInVisit + where encounterInVisit.visit = visit + and encounterInVisit.voided = false + and admitDecision.voided = false + and admitDecision.concept = :admissionDecisionConcept + and admitDecision.valueCoded = :denyAdmissionConcept + and encounterInVisit.encounterDatetime > dispoEncounter.encounterDatetime + ) = 0 From 03d6b78f2e14dbee3495c499d003a3116b94d777 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 10:24:14 -0400 Subject: [PATCH 05/15] EA-184 - Rename EmrVisitDAO to EmrApiDAO to reflect more generic intent --- .../AwaitingAdmissionVisitQueryEvaluator.java | 4 +- .../db/{EmrVisitDAO.java => EmrApiDAO.java} | 2 +- ...mrVisitDAOImpl.java => EmrApiDAOImpl.java} | 2 +- .../diagnosis/ObsGroupDiagnosisService.java | 16 ++++---- .../resources/moduleApplicationContext.xml | 40 +++++++++---------- 5 files changed, 32 insertions(+), 32 deletions(-) rename api/src/main/java/org/openmrs/module/emrapi/db/{EmrVisitDAO.java => EmrApiDAO.java} (90%) rename api/src/main/java/org/openmrs/module/emrapi/db/{EmrVisitDAOImpl.java => EmrApiDAOImpl.java} (97%) diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java index 2c7e1ad5..3c591b2f 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java @@ -7,7 +7,7 @@ import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; import org.openmrs.module.emrapi.adt.util.AdtUtil; import org.openmrs.module.emrapi.concept.EmrConceptService; -import org.openmrs.module.emrapi.db.EmrVisitDAO; +import org.openmrs.module.emrapi.db.EmrApiDAO; import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.reporting.evaluation.EvaluationContext; import org.openmrs.module.reporting.evaluation.EvaluationException; @@ -37,7 +37,7 @@ public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator EmrApiProperties emrApiProperties; @Autowired - EmrVisitDAO visitDAO; + EmrApiDAO visitDAO; @Override public VisitQueryResult evaluate(VisitQuery visitQuery, EvaluationContext evaluationContext) throws EvaluationException { diff --git a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java b/api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAO.java similarity index 90% rename from api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java rename to api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAO.java index a7314488..7ab3fbd8 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAO.java +++ b/api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAO.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Map; -public interface EmrVisitDAO { +public interface EmrApiDAO { List executeHql(String queryString, Map parameters, Class clazz); diff --git a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java b/api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAOImpl.java similarity index 97% rename from api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java rename to api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAOImpl.java index 81a7b06b..908bbb8f 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/db/EmrVisitDAOImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/db/EmrApiDAOImpl.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; -public class EmrVisitDAOImpl implements EmrVisitDAO { +public class EmrApiDAOImpl implements EmrApiDAO { protected final Log log = LogFactory.getLog(getClass()); diff --git a/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java b/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java index c3682988..325d8474 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisService.java @@ -11,7 +11,7 @@ import org.openmrs.api.EncounterService; import org.openmrs.api.ObsService; import org.openmrs.module.emrapi.EmrApiProperties; -import org.openmrs.module.emrapi.db.EmrVisitDAO; +import org.openmrs.module.emrapi.db.EmrApiDAO; import java.util.ArrayList; import java.util.Arrays; @@ -34,7 +34,7 @@ public class ObsGroupDiagnosisService { private EncounterService encounterService; - private EmrVisitDAO emrVisitDAO; + private EmrApiDAO emrApiDAO; public void setEmrApiProperties(EmrApiProperties emrApiProperties) { this.emrApiProperties = emrApiProperties; @@ -48,8 +48,8 @@ public void setEncounterService(EncounterService encounterService) { this.encounterService = encounterService; } - public void setEmrVisitDAO(EmrVisitDAO emrVisitDAO) { - this.emrVisitDAO = emrVisitDAO; + public void setEmrApiDAO(EmrApiDAO emrApiDAO) { + this.emrApiDAO = emrApiDAO; } public List codeNonCodedDiagnosis(Obs nonCodedObs, List diagnoses) { @@ -202,7 +202,7 @@ public List getDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) Map parameters = new HashMap<>(); parameters.put("visit", visit); parameters.put("diagnosisOrderConcept", diagnosisMetadata.getDiagnosisOrderConcept()); - return emrVisitDAO.executeHqlFromResource("hql/visit_diagnoses.hql", parameters, Obs.class); + return emrApiDAO.executeHqlFromResource("hql/visit_diagnoses.hql", parameters, Obs.class); } public List getPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { @@ -210,7 +210,7 @@ public List getPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMet parameters.put("visit", visit); parameters.put("diagnosisOrderConcept", diagnosisMetadata.getDiagnosisOrderConcept()); parameters.put("primaryOrderConcept", diagnosisMetadata.getConceptFor(Diagnosis.Order.PRIMARY)); - return emrVisitDAO.executeHqlFromResource("hql/visit_primary_diagnoses.hql", parameters, Obs.class); + return emrApiDAO.executeHqlFromResource("hql/visit_primary_diagnoses.hql", parameters, Obs.class); } public List getConfirmedDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { @@ -218,7 +218,7 @@ public List getConfirmedDiagnoses(Visit visit, DiagnosisMetadata diagnosisM parameters.put("visit", visit); parameters.put("diagnosisCertaintyConcept", diagnosisMetadata.getDiagnosisCertaintyConcept()); parameters.put("confirmedCertaintyConcept", diagnosisMetadata.getConceptFor(Diagnosis.Certainty.CONFIRMED)); - return emrVisitDAO.executeHqlFromResource("hql/visit_confirmed_diagnoses.hql", parameters, Obs.class); + return emrApiDAO.executeHqlFromResource("hql/visit_confirmed_diagnoses.hql", parameters, Obs.class); } public List getConfirmedPrimaryDiagnoses(Visit visit, DiagnosisMetadata diagnosisMetadata) { @@ -231,7 +231,7 @@ public List getConfirmedPrimaryDiagnoses(Visit visit, DiagnosisMetadata dia public List getAllPatientsWithDiagnosis(DiagnosisMetadata diagnosisMetadata) { Map parameters = new HashMap<>(); parameters.put("diagnosisSetConcept", diagnosisMetadata.getDiagnosisSetConcept()); - return emrVisitDAO.executeHqlFromResource("hql/patients_diagnoses.hql", parameters, Integer.class); + return emrApiDAO.executeHqlFromResource("hql/patients_diagnoses.hql", parameters, Integer.class); } public List getDiagnosesAsObs(Visit visit, DiagnosisMetadata diagnosisMetadata, Boolean primaryOnly, Boolean confirmedOnly) { diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index c8be1d00..5875a049 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -9,7 +9,7 @@ - + @@ -29,7 +29,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.account.AccountService + org.openmrs.module.emrapi.account.AccountService @@ -42,7 +42,7 @@ - + @@ -63,7 +63,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.adt.AdtService + org.openmrs.module.emrapi.adt.AdtService @@ -74,7 +74,7 @@ - + @@ -93,7 +93,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.exitfromcare.ExitFromCareService + org.openmrs.module.emrapi.exitfromcare.ExitFromCareService @@ -106,7 +106,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -155,7 +155,7 @@ - + @@ -284,7 +284,7 @@ - + @@ -336,7 +336,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.encounter.EmrEncounterService + org.openmrs.module.emrapi.encounter.EmrEncounterService @@ -345,7 +345,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.concept.EmrConceptService + org.openmrs.module.emrapi.concept.EmrConceptService @@ -354,7 +354,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.patient.EmrPatientService + org.openmrs.module.emrapi.patient.EmrPatientService @@ -363,7 +363,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.event.ApplicationEventService + org.openmrs.module.emrapi.event.ApplicationEventService @@ -373,7 +373,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.person.image.EmrPersonImageService + org.openmrs.module.emrapi.person.image.EmrPersonImageService @@ -382,13 +382,13 @@ - ${project.parent.groupId}.${project.parent.artifactId}.disposition.DispositionService + org.openmrs.module.emrapi.disposition.DispositionService - + @@ -448,7 +448,7 @@ - + @@ -456,7 +456,7 @@ - + @@ -473,7 +473,7 @@ - ${project.parent.groupId}.${project.parent.artifactId}.diagnosis.DiagnosisService + org.openmrs.module.emrapi.diagnosis.DiagnosisService From 4addd763b6d8d9739659e696a40016729b1d626a Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 12:32:12 -0400 Subject: [PATCH 06/15] EA-184 - Remove dependencies on reporting objects from other code in the module --- .../openmrs/module/emrapi/adt/AdtService.java | 9 ++++ .../module/emrapi/adt/AdtServiceImpl.java | 42 +++++++++++++++ .../AwaitingAdmissionVisitQueryEvaluator.java | 51 ++++--------------- .../emrapi/patient/PatientDomainWrapper.java | 10 ---- .../emrapi/visit/VisitDomainWrapper.java | 41 +++------------ .../hql/visits_awaiting_admission.hql | 2 +- .../resources/moduleApplicationContext.xml | 3 ++ .../module/emrapi/adt/AdtServiceTest.java | 5 -- ...ObsGroupDiagnosisServiceComponentTest.java | 21 +++++--- .../emrapi/diagnosis/OldDiagnosisBuilder.java | 15 +++++- 10 files changed, 101 insertions(+), 98 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/AdtService.java b/api/src/main/java/org/openmrs/module/emrapi/adt/AdtService.java index 56acdefb..d16be9fd 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/AdtService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/AdtService.java @@ -27,6 +27,7 @@ import org.openmrs.module.emrapi.merge.VisitMergeAction; import org.openmrs.module.emrapi.visit.VisitDomainWrapper; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -336,4 +337,12 @@ VisitDomainWrapper createRetrospectiveVisit(Patient patient, Location location, */ List getInpatientLocations(); + /** + * returns patients awaiting admission + * @param location - if supplied, only checks waiting admissions at the visit location associated with this location + * @param patientIds - if non-null, only returns matches for patients with the given ids + * @param visitIds - if non-null, only returns matches for visits with the given ids + * @return List of the matching visits + */ + List getVisitsAwaitingAdmission(Location location, Collection patientIds, Collection visitIds); } diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/AdtServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/adt/AdtServiceImpl.java index e65f3067..08a0abf7 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/AdtServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/AdtServiceImpl.java @@ -41,7 +41,11 @@ import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException; +import org.openmrs.module.emrapi.adt.util.AdtUtil; +import org.openmrs.module.emrapi.concept.EmrConceptService; +import org.openmrs.module.emrapi.db.EmrApiDAO; import org.openmrs.module.emrapi.disposition.Disposition; +import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; import org.openmrs.module.emrapi.merge.PatientMergeAction; import org.openmrs.module.emrapi.merge.VisitMergeAction; @@ -58,6 +62,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -81,6 +86,12 @@ public class AdtServiceImpl extends BaseOpenmrsService implements AdtService { private LocationService locationService; + private EmrApiDAO emrApiDAO; + + private DispositionService dispositionService; + + private EmrConceptService emrConceptService; + private DomainWrapperFactory domainWrapperFactory; private List patientMergeActions; @@ -95,6 +106,18 @@ public void setLocationService(LocationService locationService) { this.locationService = locationService; } + public void setEmrApiDAO(EmrApiDAO emrApiDAO) { + this.emrApiDAO = emrApiDAO; + } + + public void setDispositionService(DispositionService dispositionService) { + this.dispositionService = dispositionService; + } + + public void setEmrConceptService(EmrConceptService emrConceptService) { + this.emrConceptService = emrConceptService; + } + public void setEmrApiProperties(EmrApiProperties emrApiProperties) { this.emrApiProperties = emrApiProperties; } @@ -871,8 +894,27 @@ public boolean hasVisitDuring(Patient patient, Location location, Date startDate } @Override + @Transactional(readOnly = true) public List getInpatientLocations() { return locationService.getLocationsByTag(emrApiProperties.getSupportsAdmissionLocationTag()); } + @Override + @Transactional(readOnly = true) + public List getVisitsAwaitingAdmission(Location location, Collection patientIds, Collection visitIds) { + Location visitLocation = null ; + if (location != null ) { + visitLocation = getLocationThatSupportsVisits(location); + } + Map parameters = new HashMap<>(); + parameters.put("dispositionConcept", dispositionService.getDispositionDescriptor().getDispositionConcept()); + parameters.put("admissionDispositions", AdtUtil.getAdmissionDispositionsConcepts(emrConceptService, dispositionService)); + parameters.put("visitLocation", visitLocation); + parameters.put("admissionEncounterType", emrApiProperties.getAdmissionEncounterType()); + parameters.put("admissionDecisionConcept", emrApiProperties.getAdmissionDecisionConcept()); + parameters.put("denyAdmissionConcept", emrApiProperties.getDenyAdmissionConcept()); + parameters.put("patientIds", patientIds); + parameters.put("visitIds", visitIds); + return emrApiDAO.executeHqlFromResource("hql/visits_awaiting_admission.hql", parameters, Visit.class); + } } diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java index 3c591b2f..b96a9f6d 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java @@ -1,14 +1,10 @@ package org.openmrs.module.emrapi.adt.reporting.evaluator; import org.openmrs.Location; +import org.openmrs.Visit; import org.openmrs.annotation.Handler; -import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; -import org.openmrs.module.emrapi.adt.util.AdtUtil; -import org.openmrs.module.emrapi.concept.EmrConceptService; -import org.openmrs.module.emrapi.db.EmrApiDAO; -import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.reporting.evaluation.EvaluationContext; import org.openmrs.module.reporting.evaluation.EvaluationException; import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext; @@ -17,9 +13,8 @@ import org.openmrs.module.reporting.query.visit.evaluator.VisitQueryEvaluator; import org.springframework.beans.factory.annotation.Autowired; -import java.util.HashMap; +import java.util.Collection; import java.util.List; -import java.util.Map; @Handler(supports = AwaitingAdmissionVisitQuery.class) public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator { @@ -27,52 +22,26 @@ public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator @Autowired AdtService adtService; - @Autowired - DispositionService dispositionService; - - @Autowired - EmrConceptService emrConceptService; - - @Autowired - EmrApiProperties emrApiProperties; - - @Autowired - EmrApiDAO visitDAO; - @Override public VisitQueryResult evaluate(VisitQuery visitQuery, EvaluationContext evaluationContext) throws EvaluationException { - AwaitingAdmissionVisitQuery eq = (AwaitingAdmissionVisitQuery) visitQuery; Location location = eq.getLocation(); - - Location visitLocation = null ; - if (location != null ) { - visitLocation = adtService.getLocationThatSupportsVisits(location); - } - - Map parameters = new HashMap<>(); - parameters.put("dispositionConcept", dispositionService.getDispositionDescriptor().getDispositionConcept()); - parameters.put("admissionDispositions", AdtUtil.getAdmissionDispositionsConcepts(emrConceptService, dispositionService)); - parameters.put("visitLocation", visitLocation); - parameters.put("admissionEncounterType", emrApiProperties.getAdmissionEncounterType()); - parameters.put("admissionDecisionConcept", emrApiProperties.getAdmissionDecisionConcept()); - parameters.put("denyAdmissionConcept", emrApiProperties.getDenyAdmissionConcept()); - parameters.put("patientIds", null); - parameters.put("visitIds", null); + Collection patientIds = null; + Collection visitIds = null; if (evaluationContext.getBaseCohort() != null) { - parameters.put("patientIds", evaluationContext.getBaseCohort().getMemberIds()); + patientIds = evaluationContext.getBaseCohort().getMemberIds(); } if (evaluationContext instanceof VisitEvaluationContext) { VisitEvaluationContext visitEvaluationContext = (VisitEvaluationContext) evaluationContext; if (visitEvaluationContext.getBaseVisits() != null) { - parameters.put("visitIds", visitEvaluationContext.getBaseVisits().getMemberIds()); + visitIds = visitEvaluationContext.getBaseVisits().getMemberIds(); } } - List results = visitDAO.executeHqlFromResource("hql/visits_awaiting_admission.hql", parameters, Integer.class); + List results = adtService.getVisitsAwaitingAdmission(location, patientIds, visitIds); VisitQueryResult result = new VisitQueryResult(visitQuery, evaluationContext); - result.add(results.toArray(new Integer[results.size()])); + for (Visit v : results) { + result.add(v.getVisitId()); + } return result; - } - } diff --git a/api/src/main/java/org/openmrs/module/emrapi/patient/PatientDomainWrapper.java b/api/src/main/java/org/openmrs/module/emrapi/patient/PatientDomainWrapper.java index 22e74e55..3e8c37af 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/patient/PatientDomainWrapper.java +++ b/api/src/main/java/org/openmrs/module/emrapi/patient/PatientDomainWrapper.java @@ -45,7 +45,6 @@ import org.openmrs.module.emrapi.domainwrapper.DomainWrapper; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; import org.openmrs.module.emrapi.visit.VisitDomainWrapper; -import org.openmrs.module.reporting.query.visit.service.VisitQueryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -75,9 +74,6 @@ public class PatientDomainWrapper implements DomainWrapper { @Qualifier("emrDiagnosisService") @Autowired protected DiagnosisService diagnosisService; - - @Autowired - protected VisitQueryService visitQueryService; @Qualifier("domainWrapperFactory") @Autowired @@ -122,12 +118,6 @@ public void setDiagnosisService(DiagnosisService diagnosisService) { this.diagnosisService = diagnosisService; } - public void setVisitQueryService(VisitQueryService visitQueryService) { - this.visitQueryService = visitQueryService; - } - - - public Patient getPatient() { return patient; } diff --git a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java index 3b4c7e20..5f6c84d4 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java +++ b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java @@ -26,7 +26,7 @@ import org.openmrs.Visit; import org.openmrs.VisitAttribute; import org.openmrs.module.emrapi.EmrApiProperties; -import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; +import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.descriptor.MissingConceptException; import org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer; import org.openmrs.module.emrapi.diagnosis.Diagnosis; @@ -38,11 +38,6 @@ import org.openmrs.module.emrapi.disposition.DispositionType; import org.openmrs.module.emrapi.domainwrapper.DomainWrapper; import org.openmrs.module.emrapi.encounter.EncounterDomainWrapper; -import org.openmrs.module.reporting.evaluation.EvaluationException; -import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext; -import org.openmrs.module.reporting.query.visit.VisitIdSet; -import org.openmrs.module.reporting.query.visit.VisitQueryResult; -import org.openmrs.module.reporting.query.visit.service.VisitQueryService; import org.openmrs.util.OpenmrsUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -56,9 +51,7 @@ import java.util.List; import java.util.Map; -import static java.util.Collections.EMPTY_LIST; -import static java.util.Collections.reverseOrder; -import static java.util.Collections.sort; +import static java.util.Collections.*; import static org.apache.commons.collections.CollectionUtils.find; import static org.apache.commons.collections.CollectionUtils.select; @@ -82,13 +75,13 @@ public enum SortOrder { @Autowired protected DispositionService dispositionService; - @Autowired - protected VisitQueryService visitQueryService; - @Qualifier("emrDiagnosisService") @Autowired protected DiagnosisService diagnosisService; + @Autowired + protected AdtService adtService; + private Visit visit; public VisitDomainWrapper(){ @@ -138,10 +131,6 @@ public void setDispositionService(DispositionService dispositionService) { this.dispositionService = dispositionService; } - public void setVisitQueryService(VisitQueryService visitQueryService) { - this.visitQueryService = visitQueryService; - } - public Encounter getAdmissionEncounter() { return (Encounter) find(getSortedEncounters(SortOrder.MOST_RECENT_FIRST), new EncounterTypePredicate(emrApiProperties.getAdmissionEncounterType())); } @@ -514,23 +503,9 @@ public boolean isAwaitingAdmission() { if (!isActive() || !dispositionService.dispositionsSupported()) { // prevents a stack trace if dispositions are supported return false; } - - VisitQueryResult result = null; - - VisitEvaluationContext context = new VisitEvaluationContext(); - context.setBaseVisits(new VisitIdSet(getVisitId())); - - AwaitingAdmissionVisitQuery query = new AwaitingAdmissionVisitQuery(); - query.setLocation(visit.getLocation()); - - try { - result = visitQueryService.evaluate(query, context); - } - catch (EvaluationException e) { - throw new IllegalStateException("Unable to evaluate awaiting admission query", e); - } - - return result != null && result.getMemberIds().size() > 0; + List visitIds = Collections.singletonList(getVisitId()); + List matches = adtService.getVisitsAwaitingAdmission(visit.getLocation(), null, visitIds); + return matches.contains(visit); } public Location getInpatientLocation(Date onDate) { diff --git a/api/src/main/resources/hql/visits_awaiting_admission.hql b/api/src/main/resources/hql/visits_awaiting_admission.hql index f1c9fbf0..facfa430 100644 --- a/api/src/main/resources/hql/visits_awaiting_admission.hql +++ b/api/src/main/resources/hql/visits_awaiting_admission.hql @@ -1,5 +1,5 @@ select - distinct visit.visitId + distinct visit from Obs as dispo inner join dispo.encounter as dispoEncounter diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 5875a049..c9edd645 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -47,6 +47,9 @@ + + + diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceTest.java index 3ac78ab6..d09f3820 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceTest.java @@ -55,7 +55,6 @@ import org.openmrs.module.emrapi.merge.VisitMergeAction; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; import org.openmrs.module.emrapi.visit.VisitDomainWrapper; -import org.openmrs.module.reporting.query.visit.service.VisitQueryService; import org.openmrs.serialization.SerializationException; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -112,7 +111,6 @@ public class AdtServiceTest { private ProviderService mockProviderService; private PatientService mockPatientService; private DispositionService mockDispositionService; - private VisitQueryService mockVisitQueryService; private DomainWrapperFactory mockDomainWrapperFactory; private EmrApiProperties emrApiProperties; @@ -155,7 +153,6 @@ public void setup() { mockLocationService = mock(LocationService.class); mockPatientService = mock(PatientService.class); mockDispositionService = mock(DispositionService.class); - mockVisitQueryService = mock(VisitQueryService.class); mockDomainWrapperFactory = new MockDomainWrapperFactory(); @@ -1194,7 +1191,6 @@ private class MockDomainWrapperFactory extends DomainWrapperFactory{ @Override public VisitDomainWrapper newVisitDomainWrapper() { VisitDomainWrapper visitDomainWrapper = new VisitDomainWrapper(); - visitDomainWrapper.setVisitQueryService(mockVisitQueryService); visitDomainWrapper.setEmrApiProperties(emrApiProperties); visitDomainWrapper.setDispositionService(mockDispositionService); return visitDomainWrapper; @@ -1212,7 +1208,6 @@ public VisitDomainWrapper newVisitDomainWrapper(Visit visit) { public PatientDomainWrapper newPatientDomainWrapper() { PatientDomainWrapper patientDomainWrapper = new PatientDomainWrapper(); patientDomainWrapper.setEmrApiProperties(emrApiProperties); - patientDomainWrapper.setVisitQueryService(mockVisitQueryService); patientDomainWrapper.setAdtService(service); return patientDomainWrapper; } diff --git a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java index 4a7ffc35..01636fab 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java @@ -14,11 +14,11 @@ import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; import org.openmrs.module.emrapi.test.builder.ObsBuilder; -import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Set; @@ -56,11 +56,20 @@ public void setUp() throws Exception { dmd = ContextSensitiveMetadataTestUtils.setupDiagnosisMetadata(conceptService, emrApiProperties); } + + private Date parseYmd(String ymd) { + try { + return new SimpleDateFormat("yyyy-MM-dd").parse(ymd); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } private ObsBuilder buildDiagnosis(Patient patient, String dateYmd, Diagnosis.Order order, Diagnosis.Certainty certainty, Object diagnosis) { ObsBuilder builder = new ObsBuilder() .setPerson(patient) - .setObsDatetime(DateUtil.parseDate(dateYmd, "yyyy-MM-dd")) + .setObsDatetime(parseYmd(dateYmd)) .setConcept(dmd.getDiagnosisSetConcept()) .addMember(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(order)) .addMember(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(certainty)); @@ -128,7 +137,7 @@ public void getDiagnosesShouldReturnDiagnosesAfterDate() { Obs obs = buildDiagnosis(patient, "2013-09-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded pain").save().get(); buildDiagnosis(patient, "2013-08-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded disease").save(); - List diagnoses = diagnosisService.getDiagnoses(patient, DateUtil.parseDate("2013-09-01", "yyyy-MM-dd")); + List diagnoses = diagnosisService.getDiagnoses(patient, parseYmd("2013-09-01")); assertThat(diagnoses, contains(hasObs(obs))); } @@ -141,7 +150,7 @@ public void getDiagnosesShouldReturnDiagnosesInReverseChronologicalOrder() { Obs expectedThirdObs = buildDiagnosis(patient, "2013-07-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded disease").save().get(); Obs expectedFirstObs = buildDiagnosis(patient, "2013-09-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded pain").save().get(); - List diagnoses = diagnosisService.getDiagnoses(patient, DateUtil.parseDate("2001-09-01", "yyyy-MM-dd")); + List diagnoses = diagnosisService.getDiagnoses(patient, parseYmd("2001-09-01")); assertThat(diagnoses.size(), is(3)); assertThat(diagnoses.get(0).getExistingObs(), is(expectedFirstObs)); assertThat(diagnoses.get(1).getExistingObs(), is(expectedSecondObs)); @@ -154,7 +163,7 @@ public void getUniqueDiagnosesShouldReturnNoTextDuplicates() { Obs olderObs = buildDiagnosis(patient, "2013-08-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded pain").save().get(); Obs mostRecentObs = buildDiagnosis(patient, "2013-09-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, "non-coded pain").save().get(); - List diagnoses = diagnosisService.getUniqueDiagnoses(patient, DateUtil.parseDate("2013-01-01", "yyyy-MM-dd")); + List diagnoses = diagnosisService.getUniqueDiagnoses(patient, parseYmd("2013-01-01")); assertThat(diagnoses.size(), is(1)); assertThat(diagnoses.get(0).getExistingObs(), is(mostRecentObs)); } @@ -166,7 +175,7 @@ public void getUniqueDiagnosesShouldReturnNoCodedDuplicates() { Obs olderObs = buildDiagnosis(patient, "2013-08-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, malaria).save().get(); Obs mostRecentObs = buildDiagnosis(patient, "2013-09-10", Diagnosis.Order.PRIMARY, Diagnosis.Certainty.PRESUMED, malaria).save().get(); - List diagnoses = diagnosisService.getUniqueDiagnoses(patient, DateUtil.parseDate("2013-01-01", "yyyy-MM-dd")); + List diagnoses = diagnosisService.getUniqueDiagnoses(patient, parseYmd("2013-01-01")); assertThat(diagnoses.size(), is(1)); assertThat(diagnoses.get(0).getExistingObs(), is(mostRecentObs)); } diff --git a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/OldDiagnosisBuilder.java b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/OldDiagnosisBuilder.java index 01f00976..270fcc2a 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/OldDiagnosisBuilder.java +++ b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/OldDiagnosisBuilder.java @@ -4,7 +4,9 @@ import org.openmrs.Encounter; import org.openmrs.Patient; import org.openmrs.module.emrapi.test.builder.ObsBuilder; -import org.openmrs.module.reporting.common.DateUtil; + +import java.text.SimpleDateFormat; +import java.util.Date; public class OldDiagnosisBuilder { @@ -18,7 +20,7 @@ public ObsBuilder buildDiagnosis(Patient patient, String dateYmd, Diagnosis.Orde ObsBuilder builder = new ObsBuilder() .setPerson(patient) .setEncounter(encounter) - .setObsDatetime(DateUtil.parseDate(dateYmd, "yyyy-MM-dd")) + .setObsDatetime(parseYmd(dateYmd)) .setConcept(dmd.getDiagnosisSetConcept()) .addMember(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(order)) .addMember(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(certainty)); @@ -31,4 +33,13 @@ public ObsBuilder buildDiagnosis(Patient patient, String dateYmd, Diagnosis.Orde } return builder; } + + private Date parseYmd(String ymd) { + try { + return new SimpleDateFormat("yyyy-MM-dd").parse(ymd); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } } From 7786eebc82d1d03b0ad001bb2646136f85893827 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 15:52:33 -0400 Subject: [PATCH 07/15] EA-184 - Remove residual references to the condition submodule and move all reporting dependencies into a new submodule --- api-reporting/pom.xml | 111 +++++ ...ntAdmissionRequestVisitDataDefinition.java | 0 .../AwaitingAdmissionVisitQueryEvaluator.java | 0 ...entAdmissionRequestVisitDataEvaluator.java | 3 +- .../query/AwaitingAdmissionVisitQuery.java | 0 .../library/EmrApiPatientDataLibrary.java | 0 .../library/EmrApiVisitDataLibrary.java | 0 ...itingAdmissionVisitQueryEvaluatorTest.java | 2 + ...dmissionRequestVisitDataEvaluatorTest.java | 0 ...EmrApiPatientDataLibraryComponentTest.java | 0 .../resources/TestingApplicationContext.xml | 29 ++ .../src/test/resources/test-hibernate.cfg.xml | 19 + api/pom.xml | 43 -- api/src/test/resources/test-hibernate.cfg.xml | 1 - omod/pom.xml | 54 +-- .../web/controller/ConditionController.java | 428 ------------------ omod/src/main/resources/config.xml | 20 +- pom.xml | 53 +-- 18 files changed, 193 insertions(+), 570 deletions(-) create mode 100644 api-reporting/pom.xml rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/adt/reporting/definition/MostRecentAdmissionRequestVisitDataDefinition.java (100%) rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java (100%) rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java (97%) rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/adt/reporting/query/AwaitingAdmissionVisitQuery.java (100%) rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java (100%) rename {api => api-reporting}/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java (100%) rename {api => api-reporting}/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java (99%) rename {api => api-reporting}/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java (100%) rename {api => api-reporting}/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java (100%) create mode 100644 api-reporting/src/test/resources/TestingApplicationContext.xml create mode 100644 api-reporting/src/test/resources/test-hibernate.cfg.xml delete mode 100644 omod/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java diff --git a/api-reporting/pom.xml b/api-reporting/pom.xml new file mode 100644 index 00000000..5dc8593d --- /dev/null +++ b/api-reporting/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + + org.openmrs.module + emrapi + 2.0.0-SNAPSHOT + + + emrapi-api-reporting + jar + EMR API Reporting API + + + 1.25.0 + 0.2.16 + 1.3.0 + + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.version} + provided + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.version} + test + test-jar + + + org.openmrs.module + reporting-api + ${reportingVersion} + provided + + + org.openmrs.module + reporting-api-1.10 + ${reportingVersion} + provided + + + org.openmrs.module + reporting-api-2.0 + ${reportingVersion} + provided + + + org.openmrs.module + reporting-api-2.2 + ${reportingVersion} + provided + + + org.openmrs.module + serialization.xstream-api + ${serialization.xstreamVersion} + provided + + + org.openmrs.module + serialization.xstream-api-1.10 + ${serialization.xstreamVersion} + provided + + + org.openmrs.module + serialization.xstream-api-2.0 + ${serialization.xstreamVersion} + provided + + + org.openmrs.module + calculation-api + ${calculationVersion} + provided + + + + + + + src/main/resources + true + + + + + src/test/resources + + **/*.properties + **/*.xml + + true + + + src/test/resources + + **/*.properties + **/*.xml + + false + + + + \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/definition/MostRecentAdmissionRequestVisitDataDefinition.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/definition/MostRecentAdmissionRequestVisitDataDefinition.java similarity index 100% rename from api/src/main/java/org/openmrs/module/emrapi/adt/reporting/definition/MostRecentAdmissionRequestVisitDataDefinition.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/definition/MostRecentAdmissionRequestVisitDataDefinition.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java similarity index 100% rename from api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java similarity index 97% rename from api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java index 78116a7c..c0a28809 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java +++ b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java @@ -7,7 +7,6 @@ import org.openmrs.Provider; import org.openmrs.annotation.Handler; import org.openmrs.api.LocationService; -import org.openmrs.api.context.Context; import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition; import org.openmrs.module.emrapi.adt.util.AdtUtil; import org.openmrs.module.emrapi.concept.EmrConceptService; @@ -31,7 +30,7 @@ /** * Evaluates a MostRecentAdmissionRequestVisitDataDefinition to produce a VisitData */ -@Handler(supports=MostRecentAdmissionRequestVisitDataDefinition.class, order=50) +@Handler(supports= MostRecentAdmissionRequestVisitDataDefinition.class, order=50) public class MostRecentAdmissionRequestVisitDataEvaluator implements VisitDataEvaluator { @Autowired diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/reporting/query/AwaitingAdmissionVisitQuery.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/query/AwaitingAdmissionVisitQuery.java similarity index 100% rename from api/src/main/java/org/openmrs/module/emrapi/adt/reporting/query/AwaitingAdmissionVisitQuery.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/query/AwaitingAdmissionVisitQuery.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java similarity index 100% rename from api/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java similarity index 100% rename from api/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java rename to api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java similarity index 99% rename from api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java rename to api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java index 72614589..2774c4c8 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java @@ -27,6 +27,7 @@ import org.openmrs.module.reporting.query.visit.service.VisitQueryService; import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import java.util.Collections; import java.util.Date; @@ -45,6 +46,7 @@ public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseModuleContextS @Autowired private DispositionService dispositionService; + @Qualifier("reportingVisitQueryService") @Autowired private VisitQueryService visitQueryService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java similarity index 100% rename from api/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java rename to api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java diff --git a/api/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java similarity index 100% rename from api/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java rename to api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java diff --git a/api-reporting/src/test/resources/TestingApplicationContext.xml b/api-reporting/src/test/resources/TestingApplicationContext.xml new file mode 100644 index 00000000..8aa187e5 --- /dev/null +++ b/api-reporting/src/test/resources/TestingApplicationContext.xml @@ -0,0 +1,29 @@ + + + + + + + + classpath:hibernate.cfg.xml + classpath:test-hibernate.cfg.xml + + + + + + + + org.openmrs + + + + + + diff --git a/api-reporting/src/test/resources/test-hibernate.cfg.xml b/api-reporting/src/test/resources/test-hibernate.cfg.xml new file mode 100644 index 00000000..ab6d9527 --- /dev/null +++ b/api-reporting/src/test/resources/test-hibernate.cfg.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + diff --git a/api/pom.xml b/api/pom.xml index c4edc8c7..c9bd31bd 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -12,47 +12,6 @@ EMR API Module API API project for EMRAPI - - - - org.openmrs.api - openmrs-api - ${openMRSVersion} - jar - provided - - - javassist - javassist - - - - - - org.openmrs.api - openmrs-api - ${openMRSVersion} - test-jar - test - - - javassist - javassist - - - - - - org.openmrs.test - openmrs-test - ${openMRSVersion} - pom - test - - - - - @@ -60,8 +19,6 @@ true - - src/test/resources diff --git a/api/src/test/resources/test-hibernate.cfg.xml b/api/src/test/resources/test-hibernate.cfg.xml index ab6d9527..7ad80b99 100644 --- a/api/src/test/resources/test-hibernate.cfg.xml +++ b/api/src/test/resources/test-hibernate.cfg.xml @@ -10,7 +10,6 @@ - diff --git a/omod/pom.xml b/omod/pom.xml index 3737750f..780a2276 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -13,18 +13,20 @@ OMOD project for EMRAPI + - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.parent.version} - compile - - - ${project.parent.groupId} - ${project.parent.artifactId}-condition-list - ${project.parent.version} - compile - + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + compile + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api-reporting + ${project.parent.version} + compile + org.openmrs.web @@ -112,36 +114,6 @@ provided - - org.openmrs.test - openmrs-test - ${openMRSVersion} - pom - test - - - - org.openmrs.api - openmrs-api - jar - ${openMRSVersion} - provided - - - - org.openmrs.api - openmrs-api - ${openMRSVersion} - test-jar - test - - - javassist - javassist - - - - org.apache.tomcat jasper diff --git a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java deleted file mode 100644 index 853c4637..00000000 --- a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java +++ /dev/null @@ -1,428 +0,0 @@ -package org.openmrs.module.emrapi.web.controller; - -import org.apache.commons.lang3.StringUtils; -import org.openmrs.CodedOrFreeText; -import org.openmrs.Concept; -import org.openmrs.ConceptName; -import org.openmrs.ConditionClinicalStatus; -import org.openmrs.Patient; -import org.openmrs.api.ConceptService; -import org.openmrs.api.ConditionService; -import org.openmrs.api.PatientService; -import org.openmrs.api.context.Context; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.module.emrapi.conditionslist.ConditionHistory; -import org.openmrs.module.emrapi.conditionslist.ConditionListConstants; -import org.openmrs.module.emrapi.conditionslist.DateConverter; -import org.openmrs.module.emrapi.conditionslist.contract.ConditionHistoryMapper; -import org.openmrs.module.emrapi.conditionslist.contract.ConditionMapper; -import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.openmrs.util.LocaleUtility.getDefaultLocale; - -/** - * This class specifies data manipulation methods on a Condition. - */ -@Controller -@RequestMapping(value = "/rest/emrapi") -public class ConditionController extends BaseRestController { - - ConditionMapper conditionMapper = new ConditionMapper(); - - ConditionHistoryMapper conditionHistoryMapper = new ConditionHistoryMapper(conditionMapper); - - ConditionService conditionService; - - PatientService patientService; - - ConceptService conceptService; - - /** - * Constructor to instantiate the ConditionController. - * - * @param conditionService - the condition service - * @param patientService - the patient service - * @param conceptService - the concept service - */ - @Autowired - public ConditionController(ConditionService conditionService, PatientService patientService, - ConceptService conceptService) { - this.conditionService = conditionService; - this.patientService = patientService; - this.conceptService = conceptService; - } - - /** - * Method to return a concept name - * - * @param names - a collection of concept name objects - * @param name - name of a concept - * - * @return null or currentName - */ - private ConceptName getName(Collection names, String name) { - if (name == null) { - return null; - } - - for (ConceptName currentName : names) { - if (name.equalsIgnoreCase(currentName.getName())) { - return currentName; - } - } - - return null; - } - - /** - * Method to convert clinical status of core condition objects into status of condition objects of the emrapi module - * - * @param clinicalStatus - a ConditionClinicalStatus object - * - * @return convertedStatus - */ - private Condition.Status convertClinicalStatus(ConditionClinicalStatus clinicalStatus) { - Condition.Status convertedStatus = Condition.Status.ACTIVE; - - if (clinicalStatus == ConditionClinicalStatus.ACTIVE) { - convertedStatus = Condition.Status.ACTIVE; - } else if (clinicalStatus == ConditionClinicalStatus.INACTIVE) { - convertedStatus = Condition.Status.INACTIVE; - } else if (clinicalStatus == ConditionClinicalStatus.HISTORY_OF) { - convertedStatus = Condition.Status.HISTORY_OF; - } - - return convertedStatus; - } - - /** - * Method to convert Condition.Status object of the emrapi module into ConditionClinicalStatus object of the core module - * - * @param status - a Condition.Status object - * - * @return convertedStatus - */ - private ConditionClinicalStatus convertConditionListStatus(Condition.Status status) { - ConditionClinicalStatus convertedStatus = ConditionClinicalStatus.ACTIVE; - - if (status == Condition.Status.ACTIVE) { - convertedStatus = ConditionClinicalStatus.ACTIVE; - } else if (status == Condition.Status.INACTIVE) { - convertedStatus = ConditionClinicalStatus.INACTIVE; - } else if (status == Condition.Status.HISTORY_OF) { - convertedStatus = ConditionClinicalStatus.HISTORY_OF; - } - - return convertedStatus; - } - - /** - * Method to convert an org.openmrs.Concept object into an - * org.openmrs.module.emrapi.conditionslist.contract.Concept object - * - * @param coreConcept - a Condition.Status object - * - * @return concept - */ - private org.openmrs.module.emrapi.conditionslist.contract.Concept convertCoreConceptToEmrapiConcept(Concept coreConcept) { - ConceptName fullySpecifiedName = coreConcept.getFullySpecifiedName(Context.getLocale()); - if (fullySpecifiedName == null) { - fullySpecifiedName = coreConcept.getFullySpecifiedName(getDefaultLocale()); - } - if (fullySpecifiedName == null) { - fullySpecifiedName = coreConcept.getFullySpecifiedName(new Locale("en")); - } - org.openmrs.module.emrapi.conditionslist.contract.Concept concept = - new org.openmrs.module.emrapi.conditionslist.contract.Concept(coreConcept.getUuid(), - fullySpecifiedName.getName()); - ConceptName shortName = coreConcept.getShortNameInLocale(Context.getLocale()); - - if (shortName != null) { - concept.setShortName(shortName.getName()); - } - return concept; - } - - /** - * Method to convert a list of org.openmrs.Condition objects into a list of - * org.openmrs.module.emrapi.conditionslist.Condition objects - * - * @param coreConditions - a list of org.openmrs.Condition objects - * - * @return conditions - */ - private List convertCoreConditionsToEmrapiConditions(List coreConditions) { - List conditions = new ArrayList(); - for (org.openmrs.Condition coreCondition : coreConditions) { - Condition condition = new Condition(); - Concept concept; - - if (coreCondition.getCondition().getCoded() != null) { - concept = conceptService.getConceptByUuid(coreCondition.getCondition().getCoded().getUuid()); - } else { - concept = new Concept(); - concept.setFullySpecifiedName(new ConceptName(coreCondition.getCondition().getNonCoded(), Context.getLocale())); - } - - condition.setId(coreCondition.getId()); - condition.setUuid(coreCondition.getUuid()); - condition.setAdditionalDetail(coreCondition.getAdditionalDetail()); - condition.setConcept(concept); - condition.setPatient(coreCondition.getPatient()); - - if (coreCondition.getCondition().getNonCoded() != null) { - condition.setConditionNonCoded(coreCondition.getCondition().getNonCoded()); - } - - if (coreCondition.getOnsetDate() != null) { - condition.setOnsetDate(coreCondition.getOnsetDate()); - } - condition.setVoided(coreCondition.getVoided()); - condition.setVoidReason(coreCondition.getVoidReason()); - condition.setEndDate(coreCondition.getEndDate()); - condition.setCreator(coreCondition.getCreator()); - condition.setDateCreated(coreCondition.getDateCreated()); - condition.setStatus(convertClinicalStatus(coreCondition.getClinicalStatus())); - if (coreCondition.getPreviousVersion() != null) { - condition.setPreviousCondition(convertCoreConditionToEmrapiCondition(coreCondition.getPreviousVersion())); - } - - conditions.add(condition); - } - return conditions; - } - - /** - * Method to convert a list of core active conditions into a list of condition history objects - * - * @param coreConditions - a list of org.openmrs.Condition objects - * - * @return conditionHistory - */ - private List convertHistory(List coreConditions) { - List convertedConditions = convertCoreConditionsToEmrapiConditions(coreConditions); - Map allConditions = new LinkedHashMap(); - - for (Condition condition : convertedConditions) { - Concept concept = condition.getConcept(); - - String nonCodedConceptUuid = Context.getAdministrationService().getGlobalProperty( - ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID); - - String key = concept.getUuid().equals(nonCodedConceptUuid) ? - condition.getConditionNonCoded() : - concept.getUuid(); - ConditionHistory conditionHistory = allConditions.get(key); - - if (conditionHistory != null) { - conditionHistory.getConditions().add(condition); - } else { - conditionHistory = new ConditionHistory(); - List conditions = new ArrayList(); - conditions.add(condition); - conditionHistory.setConditions(conditions); - conditionHistory.setCondition(condition.getConcept()); - if (concept.getUuid().equals(nonCodedConceptUuid)) { - conditionHistory.setNonCodedCondition(condition.getConditionNonCoded()); - } - } - allConditions.put(key, conditionHistory); - } - return new ArrayList(allConditions.values()); - } - - /** - * Method to convert an org.openmrs.module.emrapi.conditionslist.contract.Condition object into an org.openmrs.Condition - * object - * - * @param condition - an org.openmrs.module.emrapi.conditionslist.contract.Condition object - * - * @return cond - */ - private org.openmrs.Condition convertEmrapiContractConditionToCoreCondition(org.openmrs.module.emrapi.conditionslist.contract.Condition condition) { - - org.openmrs.Condition openmrsCondition = null; - - Patient patient = Context.getPatientService().getPatientByUuid(condition.getPatientUuid()); - - if (condition.getUuid() != null) { - openmrsCondition = conditionService.getConditionByUuid(condition.getUuid()); - } - if (openmrsCondition == null) { - openmrsCondition = new org.openmrs.Condition(); - openmrsCondition.setUuid(condition.getUuid()); - } - - // Map coded conditions - CodedOrFreeText codedOrFreeText = new CodedOrFreeText(); - if (condition.getConcept() != null) { - if (condition.getConcept().getUuid() != null) { - codedOrFreeText.setCoded(conceptService.getConceptByUuid(condition.getConcept().getUuid())); - } - if (condition.getConcept().getName() != null && codedOrFreeText.getCoded() != null) { - codedOrFreeText.setSpecificName(getName(codedOrFreeText.getCoded().getNames(), condition.getConcept().getName())); - } - } - - // Map non-coded conditions - if (codedOrFreeText.getCoded() == null) { - if (!isEmpty(condition.getConditionNonCoded())) { - String gpName = ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID; - String nonCodedConditionConcept = Context.getAdministrationService().getGlobalProperty(gpName); - if (StringUtils.isBlank(nonCodedConditionConcept)) { - throw new IllegalStateException("Configuration Required: " + gpName); - } - codedOrFreeText.setCoded(conceptService.getConceptByUuid(nonCodedConditionConcept)); - } - } - codedOrFreeText.setNonCoded(condition.getConditionNonCoded()); - - openmrsCondition.setCondition(codedOrFreeText); - openmrsCondition.setAdditionalDetail(condition.getAdditionalDetail()); - openmrsCondition.setClinicalStatus(convertConditionListStatus(condition.getStatus())); - openmrsCondition.setCondition(codedOrFreeText); - openmrsCondition.setPatient(patient); - openmrsCondition.setOnsetDate(DateConverter.deserialize(condition.getOnSetDate())); - openmrsCondition.setEndDate(DateConverter.deserialize(condition.getEndDate())); - openmrsCondition.setVoided(condition.getVoided()); - openmrsCondition.setVoidReason(condition.getVoidReason()); - - return openmrsCondition; - } - - /** - * Method to convert an org.openmrs.Condition object into an org.openmrs.module.emrapi.conditionslist.contract.Condition - * object - * - * @param coreCondition -a core condition object - * - * @return contractCondition - */ - private org.openmrs.module.emrapi.conditionslist.contract.Condition convertCoreConditionToEmrapiContractCondition(org.openmrs.Condition coreCondition) { - org.openmrs.module.emrapi.conditionslist.contract.Concept concept = new org.openmrs.module.emrapi.conditionslist.contract.Concept(); - if (coreCondition.getCondition().getCoded() != null) { - concept = convertCoreConceptToEmrapiConcept(coreCondition.getCondition().getCoded()); - } - org.openmrs.module.emrapi.conditionslist.contract.Condition contractCondition = new org.openmrs.module.emrapi.conditionslist.contract.Condition(); - CodedOrFreeText codedOrFreeText = coreCondition.getCondition(); - - contractCondition.setUuid(coreCondition.getUuid()); - contractCondition.setAdditionalDetail(coreCondition.getAdditionalDetail()); - contractCondition.setStatus(convertClinicalStatus(coreCondition.getClinicalStatus())); - contractCondition.setConcept(concept); - contractCondition.setPatientUuid(coreCondition.getPatient().getUuid()); - contractCondition.setConditionNonCoded(codedOrFreeText.getNonCoded()); - contractCondition.setOnSetDate(DateConverter.serialize(coreCondition.getOnsetDate())); - contractCondition.setVoided(coreCondition.getVoided()); - contractCondition.setVoidReason(coreCondition.getVoidReason()); - contractCondition.setEndDate(DateConverter.serialize(coreCondition.getEndDate())); - contractCondition.setCreator(coreCondition.getCreator().getUuid()); - contractCondition.setDateCreated(coreCondition.getDateCreated()); - if (coreCondition.getPreviousVersion() != null) { - contractCondition.setPreviousConditionUuid(convertCoreConditionToEmrapiCondition(coreCondition.getPreviousVersion()).getUuid()); - } - - return contractCondition; - } - - /** - * Method to convert an org.openmrs.Condition object into an org.openmrs.module.emrapi.conditionslist.Condition - * object - * - * @param coreCondition - an org.openmrs.Condition object - * - * @return cListCondition - */ - private org.openmrs.module.emrapi.conditionslist.Condition convertCoreConditionToEmrapiCondition(org.openmrs.Condition coreCondition) { - org.openmrs.module.emrapi.conditionslist.Condition cListCondition = new org.openmrs.module.emrapi.conditionslist.Condition(); - Concept concept; - - if (coreCondition.getCondition().getCoded() != null) { - concept = conceptService.getConceptByUuid(coreCondition.getCondition().getCoded().getUuid()); - - if(coreCondition.getCondition().getSpecificName() == null) { - coreCondition.getCondition().setSpecificName(coreCondition.getCondition().getCoded().getName(Context.getLocale())); - } - } else { - concept = new Concept(); - } - - cListCondition.setUuid(coreCondition.getUuid()); - cListCondition.setConcept(concept); - cListCondition.setAdditionalDetail(coreCondition.getAdditionalDetail()); - cListCondition.setPatient(coreCondition.getPatient()); - cListCondition.setConditionNonCoded(coreCondition.getCondition().getNonCoded()); - cListCondition.setOnsetDate(coreCondition.getOnsetDate()); - cListCondition.setVoided(coreCondition.getVoided()); - cListCondition.setVoidReason(coreCondition.getVoidReason()); - cListCondition.setEndDate(coreCondition.getEndDate()); - cListCondition.setCreator(coreCondition.getCreator()); - cListCondition.setDateCreated(coreCondition.getDateCreated()); - cListCondition.setStatus(convertClinicalStatus(coreCondition.getClinicalStatus())); - if (coreCondition.getPreviousVersion() != null) { - cListCondition.setPreviousCondition(convertCoreConditionToEmrapiCondition(coreCondition.getPreviousVersion())); - } - - return cListCondition; - } - - /** - * Gets a list of active conditions. - * - * @param patientUuid - the uuid of a patient - * @return a list of active conditions - */ - @RequestMapping(method = RequestMethod.GET, value = "/conditionhistory") - @ResponseBody - public List getConditionHistory(@RequestParam("patientUuid") String patientUuid) { - List Conditions = conditionService.getAllConditions(patientService.getPatientByUuid(patientUuid)); - return conditionHistoryMapper.map(convertHistory(Conditions)); - } - - @RequestMapping(method = RequestMethod.GET, value = "/condition") - @ResponseBody - public List getCondition(@RequestParam("conditionUuid") String conditionUuid) { - org.openmrs.Condition condition = conditionService.getConditionByUuid(conditionUuid); - List conditionList =new ArrayList(); - conditionList.add(condition); - List result = new ArrayList(); - result.add(conditionMapper.map(convertCoreConditionsToEmrapiConditions(conditionList).get(0))); - return result; - } - - /** - * Saves a condition. - * - * @param conditions - a list of conditions to be saved - */ - @RequestMapping(method = RequestMethod.POST, value = "/condition") - @ResponseBody - public List save(@RequestBody org.openmrs.module.emrapi.conditionslist.contract.Condition[] conditions) { - - List savedConditions = new ArrayList(); - - for (org.openmrs.module.emrapi.conditionslist.contract.Condition condition : conditions) { - org.openmrs.Condition savedCondition = conditionService.saveCondition( - convertEmrapiContractConditionToCoreCondition(condition)); - savedConditions.add(convertCoreConditionToEmrapiContractCondition(savedCondition)); - } - return savedConditions; - } - -} - diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 34185fe1..608da118 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -14,13 +14,25 @@ https://modules.openmrs.org/modules/download/${project.parent.artifactId}/update.rdf ${openMRSVersion} + + + /lib/emr-api-reporting-${project.version}.jar + + + reporting + *.* + + + + + org.openmrs.module.legacyui org.openmrs.module.metadatasharing + org.openmrs.module.reporting - org.openmrs.module.reporting org.openmrs.module.providermanagement org.openmrs.module.metadatamapping org.openmrs.event @@ -29,12 +41,6 @@ ${project.parent.groupId}.${project.parent.artifactId}.EmrApiActivator - - - - Condition.hbm.xml - - diff --git a/pom.xml b/pom.xml index a319b9d8..690105ab 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ api + api-reporting omod @@ -39,9 +40,6 @@ 2.2.1 1.16.0 1.8.0-SNAPSHOT - 1.25.0 - 0.2.16 - 1.3.0 2.5.0 1.6.0 1.9.0 @@ -54,51 +52,10 @@ - org.openmrs.module - reporting-api - ${reportingVersion} - provided - - - org.openmrs.module - reporting-api-1.10 - ${reportingVersion} - provided - - - org.openmrs.module - reporting-api-2.0 - ${reportingVersion} - provided - - - org.openmrs.module - reporting-api-2.2 - ${reportingVersion} - provided - - - org.openmrs.module - serialization.xstream-api - ${serialization.xstreamVersion} - provided - - - org.openmrs.module - serialization.xstream-api-1.10 - ${serialization.xstreamVersion} - provided - - - org.openmrs.module - serialization.xstream-api-2.0 - ${serialization.xstreamVersion} - provided - - - org.openmrs.module - calculation-api - ${calculationVersion} + org.openmrs.api + openmrs-api + ${openMRSVersion} + jar provided From 5ab37a0ce967ef9025330d30994fbb39a68dadf0 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 17:02:35 -0400 Subject: [PATCH 08/15] OpenmrsProfileAnnotation --- .../AwaitingAdmissionVisitQueryEvaluator.java | 2 ++ .../library/EmrApiPatientDataLibrary.java | 3 ++- .../library/EmrApiVisitDataLibrary.java | 3 ++- .../module/emrapi/BaseReportingTest.java | 19 +++++++++++++++++++ ...itingAdmissionVisitQueryEvaluatorTest.java | 4 ++-- ...dmissionRequestVisitDataEvaluatorTest.java | 4 ++-- ...EmrApiPatientDataLibraryComponentTest.java | 4 ++-- 7 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java diff --git a/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java index b96a9f6d..5c4bc1ff 100644 --- a/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java +++ b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluator.java @@ -3,6 +3,7 @@ import org.openmrs.Location; import org.openmrs.Visit; import org.openmrs.annotation.Handler; +import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; import org.openmrs.module.reporting.evaluation.EvaluationContext; @@ -17,6 +18,7 @@ import java.util.List; @Handler(supports = AwaitingAdmissionVisitQuery.class) +@OpenmrsProfile(modules = { "reporting:*" }) public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator { @Autowired diff --git a/api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java index 24432725..a4937d48 100644 --- a/api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java +++ b/api-reporting/src/main/java/org/openmrs/module/emrapi/patient/reporting/library/EmrApiPatientDataLibrary.java @@ -14,6 +14,7 @@ package org.openmrs.module.emrapi.patient.reporting.library; import org.openmrs.PatientIdentifier; +import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.reporting.data.converter.PropertyConverter; import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition; @@ -27,7 +28,7 @@ /** * Basic patient data columns provided by emr-api module */ -@Component +@OpenmrsProfile(modules = { "reporting:*" }) public class EmrApiPatientDataLibrary extends BaseDefinitionLibrary { @Autowired diff --git a/api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java index 7fe1d241..6c57ac06 100644 --- a/api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java +++ b/api-reporting/src/main/java/org/openmrs/module/emrapi/visit/reporting/library/EmrApiVisitDataLibrary.java @@ -1,5 +1,6 @@ package org.openmrs.module.emrapi.visit.reporting.library; +import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition; import org.openmrs.module.reporting.data.visit.definition.VisitDataDefinition; import org.openmrs.module.reporting.definition.library.BaseDefinitionLibrary; @@ -9,7 +10,7 @@ /** * Basic visit data columns provided by module */ -@Component +@OpenmrsProfile(modules = { "reporting:*" }) public class EmrApiVisitDataLibrary extends BaseDefinitionLibrary { diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java new file mode 100644 index 00000000..0eff2150 --- /dev/null +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java @@ -0,0 +1,19 @@ +package org.openmrs.module.emrapi; + +import org.openmrs.module.Module; +import org.openmrs.module.ModuleFactory; +import org.openmrs.test.BaseModuleContextSensitiveTest; + +import java.io.File; + +public abstract class BaseReportingTest extends BaseModuleContextSensitiveTest { + + public BaseReportingTest() { + super(); + { + Module mod = new Module("", "reporting", "", "", "", "1.25.0"); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + } +} diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java index 2774c4c8..e010f67d 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java @@ -13,6 +13,7 @@ import org.openmrs.api.ConceptService; import org.openmrs.contrib.testdata.TestDataManager; import org.openmrs.contrib.testdata.builder.ObsBuilder; +import org.openmrs.module.emrapi.BaseReportingTest; import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery; @@ -25,7 +26,6 @@ import org.openmrs.module.reporting.query.visit.VisitIdSet; import org.openmrs.module.reporting.query.visit.VisitQueryResult; import org.openmrs.module.reporting.query.visit.service.VisitQueryService; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; -public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseModuleContextSensitiveTest { +public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseReportingTest { @Autowired private ConceptService conceptService; diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java index 071b94de..91f7c990 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java @@ -13,6 +13,7 @@ import org.openmrs.api.ConceptService; import org.openmrs.api.context.Context; import org.openmrs.contrib.testdata.TestDataManager; +import org.openmrs.module.emrapi.BaseReportingTest; import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition; @@ -26,7 +27,6 @@ import org.openmrs.module.reporting.data.visit.service.VisitDataService; import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext; import org.openmrs.module.reporting.query.visit.VisitIdSet; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; -public class MostRecentAdmissionRequestVisitDataEvaluatorTest extends BaseModuleContextSensitiveTest { +public class MostRecentAdmissionRequestVisitDataEvaluatorTest extends BaseReportingTest { @Autowired private VisitDataService visitDataService; diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java index 3ad8d7ea..9a33337d 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/patient/EmrApiPatientDataLibraryComponentTest.java @@ -4,6 +4,7 @@ import org.junit.Test; import org.openmrs.Cohort; import org.openmrs.api.PatientService; +import org.openmrs.module.emrapi.BaseReportingTest; import org.openmrs.module.emrapi.patient.reporting.library.EmrApiPatientDataLibrary; import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.module.reporting.data.patient.EvaluatedPatientData; @@ -11,7 +12,6 @@ import org.openmrs.module.reporting.data.patient.service.PatientDataService; import org.openmrs.module.reporting.evaluation.EvaluationContext; import org.openmrs.module.reporting.evaluation.EvaluationException; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.util.Arrays; @@ -19,7 +19,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -public class EmrApiPatientDataLibraryComponentTest extends BaseModuleContextSensitiveTest { +public class EmrApiPatientDataLibraryComponentTest extends BaseReportingTest { @Autowired private PatientDataService pds; From 79fc27d3f3e75c00d8fe824d77c26a72cbfa75be Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 19:40:41 -0400 Subject: [PATCH 09/15] EA-184 - Fixes to conditional loading --- ...entAdmissionRequestVisitDataEvaluator.java | 2 ++ .../module/emrapi/BaseReportingTest.java | 20 ++++++++++++------- omod/src/main/resources/config.xml | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java index c0a28809..1aaeb71c 100644 --- a/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java +++ b/api-reporting/src/main/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluator.java @@ -6,6 +6,7 @@ import org.openmrs.Obs; import org.openmrs.Provider; import org.openmrs.annotation.Handler; +import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.api.LocationService; import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition; import org.openmrs.module.emrapi.adt.util.AdtUtil; @@ -31,6 +32,7 @@ * Evaluates a MostRecentAdmissionRequestVisitDataDefinition to produce a VisitData */ @Handler(supports= MostRecentAdmissionRequestVisitDataDefinition.class, order=50) +@OpenmrsProfile(modules = { "reporting:*" }) public class MostRecentAdmissionRequestVisitDataEvaluator implements VisitDataEvaluator { @Autowired diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java index 0eff2150..01ab17c5 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/BaseReportingTest.java @@ -1,5 +1,7 @@ package org.openmrs.module.emrapi; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.openmrs.module.Module; import org.openmrs.module.ModuleFactory; import org.openmrs.test.BaseModuleContextSensitiveTest; @@ -8,12 +10,16 @@ public abstract class BaseReportingTest extends BaseModuleContextSensitiveTest { - public BaseReportingTest() { - super(); - { - Module mod = new Module("", "reporting", "", "", "", "1.25.0"); - mod.setFile(new File("")); - ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); - } + @BeforeClass + public static void beforeClass() { + Module mod = new Module("", "reporting", "", "", "", "1.25.0"); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); } + + @AfterClass + public static void afterClass() { + ModuleFactory.getStartedModulesMap().remove("reporting"); + } + } diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 608da118..5d21bee9 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -16,13 +16,13 @@ - /lib/emr-api-reporting-${project.version}.jar - - + /lib/emrapi-api-reporting-${project.version}.jar + + reporting *.* - - + + From cf56de4c011036699cbba3a94be2666ea478b69c Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 28 May 2024 21:13:48 -0400 Subject: [PATCH 10/15] EA-184 - Fixes to conditional loading --- omod/src/main/resources/config.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 5d21bee9..f14d853d 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -17,12 +17,12 @@ /lib/emrapi-api-reporting-${project.version}.jar - - + + reporting *.* - - + + From c18eabdec653016db1c34d61f3f5b1ef8efbbe81 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Wed, 29 May 2024 17:11:50 -0400 Subject: [PATCH 11/15] EA-186 - Make provider management optional --- .../emrapi/account/AccountDomainWrapper.java | 43 +++++----- .../emrapi/account/AccountServiceImpl.java | 10 --- .../emrapi/account/AccountValidator.java | 9 -- .../account/ProviderIdentifierGenerator.java | 2 +- .../account/provider/CoreProviderService.java | 49 +++++++++++ .../ProviderManagementProviderService.java | 82 +++++++++++++++++++ .../provider/ProviderServiceFacade.java | 23 ++++++ .../resources/moduleApplicationContext.xml | 1 - .../emrapi/EmrApiActivatorComponentTest.java | 2 +- .../emrapi/EmrApiContextSensitiveTest.java | 24 ++++++ .../emrapi/account/AccountComponentTest.java | 4 +- .../AccountDomainWrapperComponentTest.java | 5 +- .../account/AccountDomainWrapperTest.java | 23 +++--- .../emrapi/account/AccountServiceTest.java | 11 ++- .../emrapi/account/AccountValidatorTest.java | 10 ++- .../account/MockProviderServiceFacade.java | 55 +++++++++++++ .../emrapi/adt/AdtServiceComponentTest.java | 3 +- .../EncounterTypeToVisitTypeMapperTest.java | 11 ++- .../RetrospectiveCheckinComponentTest.java | 4 +- .../EmrConceptServiceComponentTest.java | 4 +- .../db/EmrEncounterDAOComponentTest.java | 10 +-- .../emrapi/diagnosis/EmrDiagnosisDAOTest.java | 6 +- .../diagnosis/MigrateDiagnosisTest.java | 4 +- ...ObsGroupDiagnosisServiceComponentTest.java | 4 +- .../DispositionDescriptorComponentTest.java | 4 +- .../EncounterDomainWrapperComponentTest.java | 8 +- .../encounter/ObservationMapperTest.java | 4 +- .../encounter/OrderMetadataServiceTest.java | 4 +- .../event/PatientViewedEventListenerTest.java | 4 +- .../ExitFromCareServiceComponentTest.java | 4 +- .../EmrPatientProfileServiceImplTest.java | 4 +- .../PatientDomainWrapperComponentTest.java | 5 +- .../module/emrapi/utils/MetadataUtilTest.java | 4 +- .../VisitDomainWrapperComponentTest.java | 4 +- omod/src/main/resources/config.xml | 2 +- pom.xml | 7 ++ 36 files changed, 339 insertions(+), 114 deletions(-) create mode 100644 api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java create mode 100644 api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java create mode 100644 api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java create mode 100644 api/src/test/java/org/openmrs/module/emrapi/EmrApiContextSensitiveTest.java create mode 100644 api/src/test/java/org/openmrs/module/emrapi/account/MockProviderServiceFacade.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/AccountDomainWrapper.java b/api/src/main/java/org/openmrs/module/emrapi/account/AccountDomainWrapper.java index c5c079b7..ea6b1267 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/AccountDomainWrapper.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/AccountDomainWrapper.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.StringUtils; import org.openmrs.Person; import org.openmrs.PersonName; +import org.openmrs.Provider; import org.openmrs.Role; import org.openmrs.User; import org.openmrs.api.APIException; @@ -10,16 +11,14 @@ import org.openmrs.api.ProviderService; import org.openmrs.api.UserService; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.account.provider.ProviderServiceFacade; import org.openmrs.module.emrapi.domainwrapper.DomainWrapper; import org.openmrs.module.emrapi.utils.GeneralUtils; -import org.openmrs.module.providermanagement.Provider; -import org.openmrs.module.providermanagement.ProviderRole; -import org.openmrs.module.providermanagement.api.ProviderManagementService; import org.openmrs.util.OpenmrsConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import java.lang.reflect.Method; +import java.util.Collection; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -55,9 +54,8 @@ public class AccountDomainWrapper implements DomainWrapper { @Autowired protected ProviderService providerService; - @Qualifier("providerManagementService") @Autowired - protected ProviderManagementService providerManagementService; + protected ProviderServiceFacade providerServiceFacade; @Autowired(required = false) protected ProviderIdentifierGenerator providerIdentifierGenerator; @@ -67,12 +65,11 @@ public AccountDomainWrapper() { @Deprecated // use DomainWrapperFactory instead public AccountDomainWrapper(Person person, AccountService accountService, UserService userService, ProviderService providerService, - ProviderManagementService providerManagementService, PersonService personService, - ProviderIdentifierGenerator providerIdentifierGenerator) { + ProviderServiceFacade providerServiceFacade, PersonService personService, ProviderIdentifierGenerator providerIdentifierGenerator) { this.accountService = accountService; this.userService = userService; this.providerService = providerService; - this.providerManagementService = providerManagementService; + this.providerServiceFacade = providerServiceFacade; this.personService = personService; this.providerIdentifierGenerator = providerIdentifierGenerator; @@ -95,8 +92,8 @@ public void setPersonService(PersonService personService) { this.personService = personService; } - public void setProviderManagementService(ProviderManagementService providerManagementService) { - this.providerManagementService = providerManagementService; + public void setProviderServiceFacade(ProviderServiceFacade providerServiceFacade) { + this.providerServiceFacade = providerServiceFacade; } public void setProviderIdentifierGenerator(ProviderIdentifierGenerator providerIdentifierGenerator) { @@ -125,21 +122,23 @@ public Provider getProvider() { return provider; } - public void setProviderRole(ProviderRole providerRole) { - + public void setProviderRole(Object providerRole) { if (providerRole != null) { initializeProviderIfNecessary(); - this.provider.setProviderRole(providerRole); + providerServiceFacade.setProviderRole(this.provider, providerRole); } else { // this prevents us from creating a new provider if we are only setting the provider role to null if (this.provider != null) { - provider.setProviderRole(null); + providerServiceFacade.setProviderRole(this.provider, null); } } } - public ProviderRole getProviderRole() { - return this.provider != null ? this.provider.getProviderRole() : null; + public Object getProviderRole() { + if (this.provider == null) { + return null; + } + return providerServiceFacade.getProviderRole(this.provider); } public void setGivenName(String givenName) { @@ -388,7 +387,7 @@ private void initializeUserIfNecessary() { private void initializeProviderIfNecessary() { if (provider == null) { - provider = new Provider(); + provider = providerServiceFacade.newProvider(); provider.setPerson(person); } } @@ -417,16 +416,14 @@ else if (users.size() > 1) } private Provider getProviderByPerson(Person person) { - List providers = providerManagementService.getProvidersByPerson(person, false); - - if (providers != null && providers.size() > 0) { + Collection providers = providerServiceFacade.getProvidersByPerson(person); + if (providers != null && !providers.isEmpty()) { if (providers.size() == 1) { - return providers.get(0); + return providers.iterator().next(); } else { throw new APIException("Multiple provider/provider roles per person not supported"); } } - return null; } diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/AccountServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/account/AccountServiceImpl.java index d875572b..9c7769a2 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/AccountServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/AccountServiceImpl.java @@ -13,7 +13,6 @@ import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; -import org.openmrs.module.providermanagement.api.ProviderManagementService; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; @@ -30,8 +29,6 @@ public class AccountServiceImpl extends BaseOpenmrsService implements AccountSer private ProviderService providerService; - private ProviderManagementService providerManagementService; - private DomainWrapperFactory domainWrapperFactory; private EmrApiProperties emrApiProperties; @@ -50,13 +47,6 @@ public void setProviderService(ProviderService providerService) { this.providerService = providerService; } - /** - * @param providerManagementService - */ - public void setProviderManagementService(ProviderManagementService providerManagementService) { - this.providerManagementService = providerManagementService; - } - /** * @param personService the personService to set */ diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/AccountValidator.java b/api/src/main/java/org/openmrs/module/emrapi/account/AccountValidator.java index 5cb94293..659bae06 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/AccountValidator.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/AccountValidator.java @@ -6,7 +6,6 @@ import org.openmrs.api.PasswordException; import org.openmrs.api.UserService; import org.openmrs.messagesource.MessageSourceService; -import org.openmrs.module.providermanagement.api.ProviderManagementService; import org.openmrs.util.OpenmrsUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -24,10 +23,6 @@ public class AccountValidator implements Validator { @Qualifier("userService") private UserService userService; - @Autowired - @Qualifier("providerManagementService") - private ProviderManagementService providerManagementService; - public static final String USERNAME_MIN_LENGTH = "2"; public static final String USERNAME_MAX_LENGTH = "50"; @@ -42,10 +37,6 @@ public void setUserService(UserService userService) { this.userService = userService; } - public void setProviderManagementService(ProviderManagementService providerManagementService) { - this.providerManagementService = providerManagementService; - } - /** * @see org.springframework.validation.Validator#supports(java.lang.Class) */ diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/ProviderIdentifierGenerator.java b/api/src/main/java/org/openmrs/module/emrapi/account/ProviderIdentifierGenerator.java index c910df49..679b3903 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/ProviderIdentifierGenerator.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/ProviderIdentifierGenerator.java @@ -1,6 +1,6 @@ package org.openmrs.module.emrapi.account; -import org.openmrs.module.providermanagement.Provider; +import org.openmrs.Provider; /** * Implementers can provide implementations of this interface if they wish diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java new file mode 100644 index 00000000..829e07a9 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java @@ -0,0 +1,49 @@ +package org.openmrs.module.emrapi.account.provider; + +import org.openmrs.OpenmrsMetadata; +import org.openmrs.Person; +import org.openmrs.Provider; +import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.api.ProviderService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Collection; + +/** + * Provides an abstraction over Provider services + */ +@OpenmrsProfile(modules = {"!providermanagement"}) +public class CoreProviderService implements ProviderServiceFacade { + + private final ProviderService providerService; + + @Autowired + public CoreProviderService(ProviderService providerService) { + this.providerService = providerService; + } + + @Override + public Provider newProvider() { + return new Provider(); + } + + @Override + public Collection getProvidersByPerson(Person person) { + return providerService.getProvidersByPerson(person, false); + } + + @Override + public Provider saveProvider(Provider provider) { + return providerService.saveProvider(provider); + } + + @Override + public Object getProviderRole(Provider provider) { + return null; + } + + @Override + public void setProviderRole(Provider provider, Object providerRole) { + throw new IllegalStateException("Unable to set the provider role, the provider management module is not installed"); + } +} diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java new file mode 100644 index 00000000..706795ca --- /dev/null +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java @@ -0,0 +1,82 @@ +package org.openmrs.module.emrapi.account.provider; + +import org.openmrs.Person; +import org.openmrs.Provider; +import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.api.ProviderService; +import org.openmrs.module.providermanagement.ProviderRole; +import org.openmrs.module.providermanagement.api.ProviderManagementService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Collection; + +/** + * Provides an abstraction over Provider services + */ +@OpenmrsProfile(modules = {"providermanagement:*"}) +public class ProviderManagementProviderService implements ProviderServiceFacade { + + private final ProviderService providerService; + + private final ProviderManagementService providerManagementService; + + @Autowired + public ProviderManagementProviderService(ProviderService providerService, ProviderManagementService providerManagementService) { + this.providerService = providerService; + this.providerManagementService = providerManagementService; + } + + @Override + public Provider newProvider() { + return new org.openmrs.module.providermanagement.Provider(); + } + + @Override + public Collection getProvidersByPerson(Person person) { + return providerManagementService.getProvidersByPerson(person, false); + } + + @Override + public Provider saveProvider(Provider provider) { + return providerService.saveProvider(provider); + } + + @Override + public Object getProviderRole(Provider provider) { + if (provider instanceof org.openmrs.module.providermanagement.Provider) { + return ((org.openmrs.module.providermanagement.Provider)provider).getProviderRole(); + } + return null; + } + + @Override + public void setProviderRole(Provider provider, Object providerRole) { + if (provider instanceof org.openmrs.module.providermanagement.Provider) { + org.openmrs.module.providermanagement.Provider p = (org.openmrs.module.providermanagement.Provider) provider; + if (providerRole == null) { + p.setProviderRole(null); + } + else { + if (providerRole instanceof ProviderRole) { + p.setProviderRole((ProviderRole) providerRole); + } + else if (providerRole instanceof String) { + p.setProviderRole(providerManagementService.getProviderRoleByUuid((String) providerRole)); + } + else if (providerRole instanceof Integer) { + p.setProviderRole(providerManagementService.getProviderRole((Integer) providerRole)); + } + else if (providerRole instanceof String[]) { + String[] uuids = (String[]) providerRole; + if (uuids.length > 1) { + throw new IllegalArgumentException("Only one provider role may be provided"); + } + p.setProviderRole(providerManagementService.getProviderRoleByUuid(uuids[0])); + } + else { + throw new IllegalArgumentException("Unable to set provider role from " + providerRole); + } + } + } + } +} diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java new file mode 100644 index 00000000..e94ad39e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java @@ -0,0 +1,23 @@ +package org.openmrs.module.emrapi.account.provider; + +import org.openmrs.OpenmrsMetadata; +import org.openmrs.Person; +import org.openmrs.Provider; + +import java.util.Collection; + +/** + * Provides an abstraction over Provider services + */ +public interface ProviderServiceFacade { + + Provider newProvider(); + + Collection getProvidersByPerson(Person person); + + Provider saveProvider(Provider provider); + + Object getProviderRole(Provider provider); + + void setProviderRole(Provider provider, Object providerRole); +} diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index c9edd645..835c0e07 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -13,7 +13,6 @@ - diff --git a/api/src/test/java/org/openmrs/module/emrapi/EmrApiActivatorComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/EmrApiActivatorComponentTest.java index 19be7df4..67370033 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/EmrApiActivatorComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/EmrApiActivatorComponentTest.java @@ -42,7 +42,7 @@ /** * */ -public class EmrApiActivatorComponentTest extends BaseModuleContextSensitiveTest { +public class EmrApiActivatorComponentTest extends EmrApiContextSensitiveTest { @Autowired @Qualifier("adminService") diff --git a/api/src/test/java/org/openmrs/module/emrapi/EmrApiContextSensitiveTest.java b/api/src/test/java/org/openmrs/module/emrapi/EmrApiContextSensitiveTest.java new file mode 100644 index 00000000..2b6ca277 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/emrapi/EmrApiContextSensitiveTest.java @@ -0,0 +1,24 @@ +package org.openmrs.module.emrapi; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.openmrs.module.Module; +import org.openmrs.module.ModuleFactory; +import org.openmrs.test.BaseModuleContextSensitiveTest; + +import java.io.File; + +public abstract class EmrApiContextSensitiveTest extends BaseModuleContextSensitiveTest { + + @BeforeClass + public static void beforeClass() { + Module mod = new Module("", "providermanagement", "", "", "", "2.5.0"); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + + @AfterClass + public static void afterClass() { + ModuleFactory.getStartedModulesMap().remove("providermanagement"); + } +} diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/AccountComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/account/AccountComponentTest.java index 19d05354..cc1fc05c 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/account/AccountComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/account/AccountComponentTest.java @@ -23,10 +23,10 @@ import org.openmrs.api.PersonService; import org.openmrs.api.UserService; import org.openmrs.api.context.Context; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.providermanagement.Provider; import org.openmrs.module.providermanagement.ProviderRole; import org.openmrs.module.providermanagement.api.ProviderManagementService; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.openmrs.util.OpenmrsConstants; import org.springframework.beans.factory.annotation.Autowired; @@ -35,7 +35,7 @@ import java.util.Locale; import java.util.Set; -public class AccountComponentTest extends BaseModuleContextSensitiveTest { +public class AccountComponentTest extends EmrApiContextSensitiveTest { @Autowired private AccountService accountService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperComponentTest.java index b05adc7f..373d74ec 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperComponentTest.java @@ -1,6 +1,7 @@ package org.openmrs.module.emrapi.account; import org.junit.Test; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; import org.openmrs.test.BaseModuleContextSensitiveTest; @@ -9,7 +10,7 @@ import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; -public class AccountDomainWrapperComponentTest extends BaseModuleContextSensitiveTest { +public class AccountDomainWrapperComponentTest extends EmrApiContextSensitiveTest { @Autowired private DomainWrapperFactory factory; @@ -19,7 +20,7 @@ public void testThatBeanCanHavePropertiesAutowired() throws Exception { AccountDomainWrapper accountDomainWrapper = factory.newAccountDomainWrapper(); assertThat(accountDomainWrapper.accountService, notNullValue()); assertThat(accountDomainWrapper.personService, notNullValue()); - assertThat(accountDomainWrapper.providerManagementService, notNullValue()); + assertThat(accountDomainWrapper.providerServiceFacade, notNullValue()); assertThat(accountDomainWrapper.providerService, notNullValue()); assertThat(accountDomainWrapper.userService, notNullValue()); } diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperTest.java b/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperTest.java index 582bb92d..a9f34b84 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/account/AccountDomainWrapperTest.java @@ -12,7 +12,10 @@ import org.openmrs.api.PersonService; import org.openmrs.api.ProviderService; import org.openmrs.api.UserService; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.account.provider.ProviderManagementProviderService; +import org.openmrs.module.emrapi.account.provider.ProviderServiceFacade; import org.openmrs.module.providermanagement.Provider; import org.openmrs.module.providermanagement.ProviderRole; import org.openmrs.module.providermanagement.api.ProviderManagementService; @@ -42,7 +45,7 @@ import static org.openmrs.util.OpenmrsConstants.USER_PROPERTY_LOCKOUT_TIMESTAMP; import static org.openmrs.util.OpenmrsConstants.USER_PROPERTY_LOGIN_ATTEMPTS; -public class AccountDomainWrapperTest { +public class AccountDomainWrapperTest extends EmrApiContextSensitiveTest { private AccountService accountService; @@ -54,6 +57,8 @@ public class AccountDomainWrapperTest { private ProviderManagementService providerManagementService; + private ProviderServiceFacade providerServiceFacade; + private ProviderIdentifierGenerator providerIdentifierGenerator = null; private Role fullPrivileges; @@ -73,6 +78,7 @@ public void setup() { personService = mock(PersonService.class); providerService = mock(ProviderService.class); providerManagementService = mock(ProviderManagementService.class); + providerServiceFacade = new MockProviderServiceFacade(new ProviderManagementProviderService(providerService, providerManagementService)); fullPrivileges = new Role(); fullPrivileges.setRole(EmrApiConstants.ROLE_PREFIX_PRIVILEGE_LEVEL + "Full"); @@ -328,8 +334,7 @@ public void shouldChangeExistingProviderRole() { Provider provider = new Provider(); ProviderRole originalProviderRole = new ProviderRole(); provider.setProviderRole(originalProviderRole); - - when(providerManagementService.getProvidersByPerson(eq(person), eq(false))).thenReturn(Collections.singletonList(provider)); + providerServiceFacade.saveProvider(provider); AccountDomainWrapper account = initializeNewAccountDomainWrapper(person); ProviderRole newProviderRole = new ProviderRole(); @@ -347,8 +352,6 @@ public void shouldChangeExistingProviderRoleToNull() { ProviderRole originalProviderRole = new ProviderRole(); provider.setProviderRole(originalProviderRole); - when(providerManagementService.getProvidersByPerson(eq(person), eq(false))).thenReturn(Collections.singletonList(provider)); - AccountDomainWrapper account = initializeNewAccountDomainWrapper(person); account.setProviderRole(null); @@ -485,8 +488,6 @@ public void testSaveAccountShouldNotPersistProviderIfRoleSetToNull() throws Exce Person person = new Person(); person.setId(1); - when(providerManagementService.getProvidersByPerson(eq(person), eq(false))).thenReturn(null); - AccountDomainWrapper account = initializeNewAccountDomainWrapper(person); account.setProviderRole(null); account.save(); @@ -507,8 +508,7 @@ public void testSaveAccountShouldNotRetireProviderIfProviderRoleSetToNull() thro provider.setId(1); // to mimic persistence ProviderRole originalProviderRole = new ProviderRole(); provider.setProviderRole(originalProviderRole); - - when(providerManagementService.getProvidersByPerson(eq(person), eq(false))).thenReturn(Collections.singletonList(provider)); + providerServiceFacade.saveProvider(provider); AccountDomainWrapper account = initializeNewAccountDomainWrapper(person); account.setProviderRole(null); @@ -525,8 +525,7 @@ public void testSaveAccountShouldNotRetireProviderIfProviderNotPersisted() throw Provider provider = new Provider(); ProviderRole originalProviderRole = new ProviderRole(); provider.setProviderRole(originalProviderRole); - - when(providerManagementService.getProvidersByPerson(eq(person), eq(false))).thenReturn(Collections.singletonList(provider)); + providerServiceFacade.saveProvider(provider); AccountDomainWrapper account = initializeNewAccountDomainWrapper(person); account.setProviderRole(null); @@ -603,7 +602,7 @@ public void testShouldNotFailIfProviderIdentifierGeneratorDefinedButNoProvider() private AccountDomainWrapper initializeNewAccountDomainWrapper(Person person) { return new AccountDomainWrapper(person, accountService, userService, - providerService, providerManagementService, personService, providerIdentifierGenerator); + providerService, providerServiceFacade, personService, providerIdentifierGenerator); } private class IsExpectedProvider extends ArgumentMatcher { diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/AccountServiceTest.java b/api/src/test/java/org/openmrs/module/emrapi/account/AccountServiceTest.java index 1ffd2a64..d7328857 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/account/AccountServiceTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/account/AccountServiceTest.java @@ -12,9 +12,12 @@ import org.openmrs.api.PersonService; import org.openmrs.api.ProviderService; import org.openmrs.api.UserService; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiConstants; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.TestUtils; +import org.openmrs.module.emrapi.account.provider.ProviderManagementProviderService; +import org.openmrs.module.emrapi.account.provider.ProviderServiceFacade; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; import org.openmrs.module.providermanagement.api.ProviderManagementService; import org.openmrs.util.OpenmrsConstants; @@ -31,7 +34,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class AccountServiceTest { +public class AccountServiceTest extends EmrApiContextSensitiveTest { private AccountServiceImpl accountService; @@ -43,6 +46,8 @@ public class AccountServiceTest { private ProviderManagementService providerManagementService; + private ProviderServiceFacade providerServiceFacade; + private EmrApiProperties emrApiProperties; private DomainWrapperFactory domainWrapperFactory; @@ -53,6 +58,7 @@ public void setup() { personService = mock(PersonService.class); providerService = mock(ProviderService.class); providerManagementService = mock(ProviderManagementService.class); + providerServiceFacade = new ProviderManagementProviderService(providerService, providerManagementService); emrApiProperties = mock(EmrApiProperties.class); domainWrapperFactory = new MockDomainWrapperFactory(); @@ -61,7 +67,6 @@ public void setup() { accountService.setUserService(userService); accountService.setPersonService(personService); accountService.setProviderService(providerService); - accountService.setProviderManagementService(providerManagementService); accountService.setEmrApiProperties(emrApiProperties); accountService.setDomainWrapperFactory(domainWrapperFactory); } @@ -249,7 +254,7 @@ public AccountDomainWrapper newAccountDomainWrapper() { accountDomainWrapper.setAccountService(accountService); accountDomainWrapper.setUserService(userService); accountDomainWrapper.setPersonService(personService); - accountDomainWrapper.setProviderManagementService(providerManagementService); + accountDomainWrapper.setProviderServiceFacade(providerServiceFacade); accountDomainWrapper.setProviderService(providerService); return accountDomainWrapper; } diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/AccountValidatorTest.java b/api/src/test/java/org/openmrs/module/emrapi/account/AccountValidatorTest.java index 96a37da9..e5967f7f 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/account/AccountValidatorTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/account/AccountValidatorTest.java @@ -13,10 +13,13 @@ import org.openmrs.api.UserService; import org.openmrs.messagesource.MessageSourceService; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.account.provider.ProviderManagementProviderService; +import org.openmrs.module.emrapi.account.provider.ProviderServiceFacade; import org.openmrs.module.providermanagement.ProviderRole; import org.openmrs.module.providermanagement.api.ProviderManagementService; import org.openmrs.util.OpenmrsUtil; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.validation.BindException; @@ -36,6 +39,7 @@ import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.management.*", "jdk.internal.reflect.*"}) @PrepareForTest(OpenmrsUtil.class) public class AccountValidatorTest { @@ -51,6 +55,8 @@ public class AccountValidatorTest { private ProviderManagementService providerManagementService; + private ProviderServiceFacade providerServiceFacade; + private PersonService personService; private ProviderIdentifierGenerator providerIdentifierGenerator; @@ -70,12 +76,12 @@ public void setValidator() { userService = Mockito.mock(UserService.class); providerService = Mockito.mock(ProviderService.class); providerManagementService = Mockito.mock(ProviderManagementService.class); + providerServiceFacade = new ProviderManagementProviderService(providerService, providerManagementService); personService = Mockito.mock(PersonService.class); validator = new AccountValidator(); validator.setMessageSourceService(Mockito.mock(MessageSourceService.class)); validator.setUserService(userService); - validator.setProviderManagementService(providerManagementService); fullPrivileges = new Role(EmrApiConstants.PRIVILEGE_LEVEL_FULL_ROLE); when(accountService.getAllPrivilegeLevels()).thenReturn(Collections.singletonList(fullPrivileges)); @@ -91,7 +97,7 @@ public void setValidator() { someProviderRole = new ProviderRole(); account = new AccountDomainWrapper(person, accountService, userService, providerService, - providerManagementService, personService, providerIdentifierGenerator); + providerServiceFacade, personService, providerIdentifierGenerator); } /** diff --git a/api/src/test/java/org/openmrs/module/emrapi/account/MockProviderServiceFacade.java b/api/src/test/java/org/openmrs/module/emrapi/account/MockProviderServiceFacade.java new file mode 100644 index 00000000..e814df95 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/emrapi/account/MockProviderServiceFacade.java @@ -0,0 +1,55 @@ +package org.openmrs.module.emrapi.account; + +import org.openmrs.OpenmrsMetadata; +import org.openmrs.Person; +import org.openmrs.Provider; +import org.openmrs.module.emrapi.account.provider.ProviderServiceFacade; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Provides an abstraction over Provider services + */ +public class MockProviderServiceFacade implements ProviderServiceFacade { + + private final ProviderServiceFacade providerServiceFacade; + private final List providers = new ArrayList<>(); + + public MockProviderServiceFacade(ProviderServiceFacade providerServiceFacade) { + this.providerServiceFacade = providerServiceFacade; + } + + @Override + public Provider newProvider() { + return providerServiceFacade.newProvider(); + } + + @Override + public Collection getProvidersByPerson(Person person) { + List ret = new ArrayList<>(); + for (Provider provider : providers) { + if (provider.getPerson() != null && provider.getPerson().equals(person)) { + ret.add(provider); + } + } + return ret; + } + + @Override + public Provider saveProvider(Provider provider) { + providers.add(provider); + return provider; + } + + @Override + public Object getProviderRole(Provider provider) { + return providerServiceFacade.getProviderRole(provider); + } + + @Override + public void setProviderRole(Provider provider, Object providerRole) { + providerServiceFacade.setProviderRole(provider, providerRole); + } +} diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java index 2a2dcddd..de808342 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java @@ -39,6 +39,7 @@ import org.openmrs.api.VisitService; import org.openmrs.api.context.Context; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.concept.EmrConceptService; import org.openmrs.module.emrapi.disposition.DispositionService; @@ -68,7 +69,7 @@ import static org.openmrs.module.emrapi.adt.AdtAction.Type.ADMISSION; import static org.openmrs.module.emrapi.adt.AdtAction.Type.DISCHARGE; -public class AdtServiceComponentTest extends BaseModuleContextSensitiveTest { +public class AdtServiceComponentTest extends EmrApiContextSensitiveTest { public static final Predicate NON_VOIDED = new Predicate() { @Override diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/EncounterTypeToVisitTypeMapperTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/EncounterTypeToVisitTypeMapperTest.java index 4e511f8c..2f5096f7 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/EncounterTypeToVisitTypeMapperTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/EncounterTypeToVisitTypeMapperTest.java @@ -1,8 +1,5 @@ package org.openmrs.module.emrapi.adt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -11,11 +8,13 @@ import org.openmrs.api.AdministrationService; import org.openmrs.api.EncounterService; import org.openmrs.api.VisitService; -import org.openmrs.api.context.Context; import org.openmrs.module.emrapi.EmrApiConstants; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -public class EncounterTypeToVisitTypeMapperTest extends BaseModuleContextSensitiveTest { +public class EncounterTypeToVisitTypeMapperTest extends EmrApiContextSensitiveTest { private EncounterTypetoVisitTypeMapper encounterTypetoVisitTypeMapper; private EncounterService encounterService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/RetrospectiveCheckinComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/RetrospectiveCheckinComponentTest.java index 17fcc4de..f066196b 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/RetrospectiveCheckinComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/RetrospectiveCheckinComponentTest.java @@ -2,13 +2,13 @@ import org.junit.Ignore; import org.junit.runner.RunWith; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; // Probably delete this test class, and its associated resources @Ignore("This was never completed, and it isn't possible to easily migrate from the EMR module due to PIH-specific data") @RunWith(SpringJUnit4ClassRunner.class) -public class RetrospectiveCheckinComponentTest extends BaseModuleContextSensitiveTest { +public class RetrospectiveCheckinComponentTest extends EmrApiContextSensitiveTest { /* @Autowired diff --git a/api/src/test/java/org/openmrs/module/emrapi/concept/EmrConceptServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/concept/EmrConceptServiceComponentTest.java index e6100a47..5e3eef84 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/concept/EmrConceptServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/concept/EmrConceptServiceComponentTest.java @@ -29,8 +29,8 @@ import org.openmrs.ConceptSource; import org.openmrs.api.ConceptService; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.test.builder.ConceptBuilder; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; @@ -46,7 +46,7 @@ /** * */ -public class EmrConceptServiceComponentTest extends BaseModuleContextSensitiveTest { +public class EmrConceptServiceComponentTest extends EmrApiContextSensitiveTest { @Autowired private ConceptService conceptService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/db/EmrEncounterDAOComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/db/EmrEncounterDAOComponentTest.java index ba03492b..0c267fa4 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/db/EmrEncounterDAOComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/db/EmrEncounterDAOComponentTest.java @@ -10,15 +10,15 @@ import org.openmrs.api.EncounterService; import org.openmrs.api.ObsService; import org.openmrs.api.PatientService; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.is; - import java.util.List; -public class EmrEncounterDAOComponentTest extends BaseModuleContextSensitiveTest { +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class EmrEncounterDAOComponentTest extends EmrApiContextSensitiveTest { @Autowired private EmrEncounterDAO emrEncounterDAO; diff --git a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/EmrDiagnosisDAOTest.java b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/EmrDiagnosisDAOTest.java index 94cbe37c..58c07c04 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/EmrDiagnosisDAOTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/EmrDiagnosisDAOTest.java @@ -6,16 +6,18 @@ import org.junit.runner.RunWith; import org.openmrs.ConditionVerificationStatus; import org.openmrs.Visit; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + import java.util.List; + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @RunWith(SpringJUnit4ClassRunner.class) -public class EmrDiagnosisDAOTest extends BaseModuleContextSensitiveTest { +public class EmrDiagnosisDAOTest extends EmrApiContextSensitiveTest { private static final String DIAGNOSIS_DATASET = "DiagnosisDataset.xml"; diff --git a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/MigrateDiagnosisTest.java b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/MigrateDiagnosisTest.java index 596e2b64..aa8193c2 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/MigrateDiagnosisTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/MigrateDiagnosisTest.java @@ -10,10 +10,10 @@ import org.openmrs.api.EncounterService; import org.openmrs.api.PatientService; import org.openmrs.api.context.Context; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; import org.openmrs.module.emrapi.test.builder.ObsBuilder; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -23,7 +23,7 @@ @RunWith(SpringJUnit4ClassRunner.class) -public class MigrateDiagnosisTest extends BaseModuleContextSensitiveTest { +public class MigrateDiagnosisTest extends EmrApiContextSensitiveTest { private static final String DIAGNOSIS_DATASET = "DiagnosisDataset.xml"; diff --git a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java index 01636fab..1dedd2a2 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/diagnosis/ObsGroupDiagnosisServiceComponentTest.java @@ -11,10 +11,10 @@ import org.openmrs.api.ConceptService; import org.openmrs.api.ObsService; import org.openmrs.api.PatientService; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; import org.openmrs.module.emrapi.test.builder.ObsBuilder; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -31,7 +31,7 @@ @RunWith(SpringJUnit4ClassRunner.class) -public class ObsGroupDiagnosisServiceComponentTest extends BaseModuleContextSensitiveTest { +public class ObsGroupDiagnosisServiceComponentTest extends EmrApiContextSensitiveTest { @Autowired ConceptService conceptService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionDescriptorComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionDescriptorComponentTest.java index ac21b9d1..ba6e0740 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionDescriptorComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionDescriptorComponentTest.java @@ -1,9 +1,9 @@ package org.openmrs.module.emrapi.disposition; import org.junit.Test; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; -public class DispositionDescriptorComponentTest extends BaseModuleContextSensitiveTest { +public class DispositionDescriptorComponentTest extends EmrApiContextSensitiveTest { @Test public void setupNewDispositionDescriptor() { diff --git a/api/src/test/java/org/openmrs/module/emrapi/encounter/EncounterDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/encounter/EncounterDomainWrapperComponentTest.java index a76c134c..c0b8af6a 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/encounter/EncounterDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/encounter/EncounterDomainWrapperComponentTest.java @@ -1,15 +1,11 @@ package org.openmrs.module.emrapi.encounter; import org.junit.Test; -import org.openmrs.module.emrapi.account.AccountDomainWrapper; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; - -public class EncounterDomainWrapperComponentTest extends BaseModuleContextSensitiveTest{ +public class EncounterDomainWrapperComponentTest extends EmrApiContextSensitiveTest { @Autowired private DomainWrapperFactory factory; diff --git a/api/src/test/java/org/openmrs/module/emrapi/encounter/ObservationMapperTest.java b/api/src/test/java/org/openmrs/module/emrapi/encounter/ObservationMapperTest.java index 6f7a9c88..336d5d21 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/encounter/ObservationMapperTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/encounter/ObservationMapperTest.java @@ -26,11 +26,11 @@ import org.openmrs.Drug; import org.openmrs.User; import org.openmrs.PersonName; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; import org.openmrs.module.emrapi.encounter.mapper.UserMapper; import org.openmrs.module.emrapi.test.builder.ConceptBuilder; import org.openmrs.module.emrapi.test.builder.ObsBuilder; -import org.openmrs.test.BaseModuleContextSensitiveTest; import java.util.UUID; @@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ObservationMapperTest extends BaseModuleContextSensitiveTest { +public class ObservationMapperTest extends EmrApiContextSensitiveTest { @Mock private Concept concept; diff --git a/api/src/test/java/org/openmrs/module/emrapi/encounter/OrderMetadataServiceTest.java b/api/src/test/java/org/openmrs/module/emrapi/encounter/OrderMetadataServiceTest.java index c62b09a2..4f2735e6 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/encounter/OrderMetadataServiceTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/encounter/OrderMetadataServiceTest.java @@ -21,7 +21,7 @@ import org.openmrs.OrderFrequency; import org.openmrs.api.OrderService; import org.openmrs.api.context.Context; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; -public class OrderMetadataServiceTest extends BaseModuleContextSensitiveTest { +public class OrderMetadataServiceTest extends EmrApiContextSensitiveTest { public static final String DAYS_CONCEPT_NAME = "Days"; public static final String WEEKS_CONCEPT_NAME = "Weeks"; diff --git a/api/src/test/java/org/openmrs/module/emrapi/event/PatientViewedEventListenerTest.java b/api/src/test/java/org/openmrs/module/emrapi/event/PatientViewedEventListenerTest.java index 7d9efb18..1840970d 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/event/PatientViewedEventListenerTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/event/PatientViewedEventListenerTest.java @@ -24,8 +24,8 @@ import org.openmrs.api.PatientService; import org.openmrs.api.UserService; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.utils.GeneralUtils; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import javax.jms.MapMessage; @@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals; -public class PatientViewedEventListenerTest extends BaseModuleContextSensitiveTest { +public class PatientViewedEventListenerTest extends EmrApiContextSensitiveTest { @Autowired private PatientService patientService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/exitfromcare/ExitFromCareServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/exitfromcare/ExitFromCareServiceComponentTest.java index c4696f5e..e178847e 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/exitfromcare/ExitFromCareServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/exitfromcare/ExitFromCareServiceComponentTest.java @@ -14,7 +14,7 @@ import org.openmrs.api.PatientService; import org.openmrs.api.ProgramWorkflowService; import org.openmrs.api.VisitService; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; @@ -29,7 +29,7 @@ import static org.junit.Assert.assertTrue; -public class ExitFromCareServiceComponentTest extends BaseModuleContextSensitiveTest { +public class ExitFromCareServiceComponentTest extends EmrApiContextSensitiveTest { @Autowired private ExitFromCareService exitFromCareService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/patient/EmrPatientProfileServiceImplTest.java b/api/src/test/java/org/openmrs/module/emrapi/patient/EmrPatientProfileServiceImplTest.java index 3e40ba66..1be8043d 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/patient/EmrPatientProfileServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/patient/EmrPatientProfileServiceImplTest.java @@ -7,8 +7,8 @@ import org.openmrs.Relationship; import org.openmrs.api.PatientService; import org.openmrs.api.PersonService; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.person.image.EmrPersonImageService; -import org.openmrs.test.BaseModuleContextSensitiveTest; import java.util.ArrayList; import java.util.List; @@ -18,7 +18,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class EmrPatientProfileServiceImplTest extends BaseModuleContextSensitiveTest { +public class EmrPatientProfileServiceImplTest extends EmrApiContextSensitiveTest { private EmrPatientProfileServiceImpl emrPatientProfileService; diff --git a/api/src/test/java/org/openmrs/module/emrapi/patient/PatientDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/patient/PatientDomainWrapperComponentTest.java index 1a43850c..f41ffeab 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/patient/PatientDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/patient/PatientDomainWrapperComponentTest.java @@ -14,10 +14,9 @@ package org.openmrs.module.emrapi.patient; -import org.junit.Before; import org.junit.Test; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.core.IsNull.notNullValue; @@ -26,7 +25,7 @@ /** * */ -public class PatientDomainWrapperComponentTest extends BaseModuleContextSensitiveTest { +public class PatientDomainWrapperComponentTest extends EmrApiContextSensitiveTest { @Autowired private DomainWrapperFactory factory; diff --git a/api/src/test/java/org/openmrs/module/emrapi/utils/MetadataUtilTest.java b/api/src/test/java/org/openmrs/module/emrapi/utils/MetadataUtilTest.java index 9fef74ab..a7a7681d 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/utils/MetadataUtilTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/utils/MetadataUtilTest.java @@ -15,14 +15,14 @@ import org.junit.Test; import org.openmrs.api.context.Context; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.nullValue; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -public class MetadataUtilTest extends BaseModuleContextSensitiveTest { +public class MetadataUtilTest extends EmrApiContextSensitiveTest { @Test public void testSetupStandardMetadata() throws Exception { diff --git a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java index 44f58041..f11d3ace 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java @@ -17,6 +17,7 @@ import org.openmrs.contrib.testdata.TestDataManager; import org.openmrs.contrib.testdata.builder.ObsBuilder; import org.openmrs.module.emrapi.EmrApiConstants; +import org.openmrs.module.emrapi.EmrApiContextSensitiveTest; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.concept.EmrConceptService; import org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer; @@ -26,7 +27,6 @@ import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.emrapi.domainwrapper.DomainWrapperFactory; import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.text.ParseException; @@ -43,7 +43,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class VisitDomainWrapperComponentTest extends BaseModuleContextSensitiveTest { +public class VisitDomainWrapperComponentTest extends EmrApiContextSensitiveTest { @Autowired private ConceptService conceptService; diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index f14d853d..7d16022b 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -29,11 +29,11 @@ org.openmrs.module.legacyui org.openmrs.module.metadatasharing + org.openmrs.module.providermanagement org.openmrs.module.reporting - org.openmrs.module.providermanagement org.openmrs.module.metadatamapping org.openmrs.event org.openmrs.module.webservices.rest diff --git a/pom.xml b/pom.xml index 690105ab..85285c8b 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,13 @@ test + + com.sun.activation + javax.activation + 1.2.0 + test + + javax.servlet From 7ef844bd043850b6a2a14a55211ed41aea59a2e9 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Wed, 29 May 2024 18:05:45 -0400 Subject: [PATCH 12/15] Follow-up fix --- .../ProviderManagementProviderService.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java index 706795ca..66eebf70 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java @@ -57,26 +57,41 @@ public void setProviderRole(Provider provider, Object providerRole) { p.setProviderRole(null); } else { + ProviderRole role = null; if (providerRole instanceof ProviderRole) { - p.setProviderRole((ProviderRole) providerRole); + role = (ProviderRole) providerRole; } else if (providerRole instanceof String) { - p.setProviderRole(providerManagementService.getProviderRoleByUuid((String) providerRole)); + role = getProviderRole((String) providerRole); } else if (providerRole instanceof Integer) { - p.setProviderRole(providerManagementService.getProviderRole((Integer) providerRole)); + role = providerManagementService.getProviderRole((Integer) providerRole); } else if (providerRole instanceof String[]) { - String[] uuids = (String[]) providerRole; - if (uuids.length > 1) { + String[] roles = (String[]) providerRole; + if (roles.length > 1) { throw new IllegalArgumentException("Only one provider role may be provided"); } - p.setProviderRole(providerManagementService.getProviderRoleByUuid(uuids[0])); + role = getProviderRole(roles[0]); } - else { + if (role == null) { throw new IllegalArgumentException("Unable to set provider role from " + providerRole); } + ((org.openmrs.module.providermanagement.Provider) provider).setProviderRole(role); } } } + + private ProviderRole getProviderRole(String ref) { + ProviderRole role = providerManagementService.getProviderRoleByUuid(ref); + if (role == null) { + try { + Integer roleId = Integer.parseInt(ref); + role = providerManagementService.getProviderRole(roleId); + } + catch (Exception ignored) { + } + } + return role; + } } From abae11bf422f743deb01f8ce980ab6e45dd1f520 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Wed, 29 May 2024 18:13:29 -0400 Subject: [PATCH 13/15] Follow-up fix --- pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index 85285c8b..690105ab 100644 --- a/pom.xml +++ b/pom.xml @@ -122,13 +122,6 @@ test - - com.sun.activation - javax.activation - 1.2.0 - test - - javax.servlet From f301b2526245464a3040949a19149cada0c01293 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Thu, 30 May 2024 11:21:40 -0400 Subject: [PATCH 14/15] Follow-up fix --- .../org/openmrs/module/emrapi/visit/VisitDomainWrapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java index 5f6c84d4..0de780e2 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java +++ b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitDomainWrapper.java @@ -51,7 +51,9 @@ import java.util.List; import java.util.Map; -import static java.util.Collections.*; +import static java.util.Collections.EMPTY_LIST; +import static java.util.Collections.reverseOrder; +import static java.util.Collections.sort; import static org.apache.commons.collections.CollectionUtils.find; import static org.apache.commons.collections.CollectionUtils.select; From 8f08c870b1fcbb22b54c612830042d930023f93b Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Thu, 30 May 2024 11:28:43 -0400 Subject: [PATCH 15/15] Remove unused imports --- .../module/emrapi/account/provider/CoreProviderService.java | 1 - .../module/emrapi/account/provider/ProviderServiceFacade.java | 1 - 2 files changed, 2 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java index 829e07a9..569e6ed5 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java @@ -1,6 +1,5 @@ package org.openmrs.module.emrapi.account.provider; -import org.openmrs.OpenmrsMetadata; import org.openmrs.Person; import org.openmrs.Provider; import org.openmrs.annotation.OpenmrsProfile; diff --git a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java index e94ad39e..1d67a96a 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java +++ b/api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java @@ -1,6 +1,5 @@ package org.openmrs.module.emrapi.account.provider; -import org.openmrs.OpenmrsMetadata; import org.openmrs.Person; import org.openmrs.Provider;