Search in sources :

Example 96 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class InpatientLocationCohortDefinitionEvaluatorTest method testEvaluate.

@Test
public void testEvaluate() throws Exception {
    InpatientLocationCohortDefinition definition = new InpatientLocationCohortDefinition();
    definition.addParameter(new Parameter("ward", "Ward", Location.class));
    definition.addParameter(new Parameter("effectiveDate", "Date", Date.class));
    Location womensInternalMedicine = locationService.getLocation("Sal Fanm");
    EvaluationContext ec = new EvaluationContext();
    ec.addParameterValue("ward", womensInternalMedicine);
    ec.addParameterValue("effectiveDate", DateUtil.parseDate("2013-10-03", "yyyy-MM-dd"));
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, ec);
    assertThat(result, isCohortWithExactlyIds(patient1.getId(), patient5.getId()));
}
Also used : InpatientLocationCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientLocationCohortDefinition) Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 97 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldNotCloseVisitIfDateCreatedWithin12Hours.

@Test
public void test_shouldNotCloseVisitIfDateCreatedWithin12Hours() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    Location location = locationService.getLocation(1);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    // set the date created on this visit to now
    Visit visit = visitService.getVisit(1);
    visit.setDateCreated(new Date());
    // sanity check
    assertThat(visitService.getVisit(1).getStopDatetime(), nullValue());
    new PihCloseStaleVisitsTask().run();
    // this visit would have been closed, except that we updated the date created
    assertThat(visitService.getVisit(1).getStopDatetime(), nullValue());
}
Also used : Visit(org.openmrs.Visit) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 98 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfItHasADischargeEncounterEvenIfDateCreatedAndDateChangedAreWithin12Hours.

@Test
public void test_shouldCloseVisitIfItHasADischargeEncounterEvenIfDateCreatedAndDateChangedAreWithin12Hours() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    // patient already has one visit in test dataset
    Patient patient = patientService.getPatient(7);
    // need to tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
    Location unknownLocation = locationService.getLocation(1);
    unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(unknownLocation);
    Location location = locationService.getLocation(2);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    Visit visit = new Visit();
    visit.setDateCreated(new Date());
    visit.setDateChanged(new Date());
    visit.setStartDatetime(DateUtils.addHours(new Date(), -60));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create an exit from care encounter
    Encounter exitFromCareEncounter = new Encounter();
    exitFromCareEncounter.setPatient(patient);
    exitFromCareEncounter.setEncounterType(emrApiProperties.getExitFromInpatientEncounterType());
    exitFromCareEncounter.setEncounterDatetime(visit.getStartDatetime());
    encounterService.saveEncounter(exitFromCareEncounter);
    visit.addEncounter(exitFromCareEncounter);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNull(activeVisit);
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 99 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButMostRecentDispositionIsDischarge.

@Test
public void test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButMostRecentDispositionIsDischarge() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    // patient already has one visit in test dataset
    Patient patient = patientService.getPatient(7);
    // need to tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
    Location unknownLocation = locationService.getLocation(1);
    unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(unknownLocation);
    Location location = locationService.getLocation(2);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    Visit visit = new Visit();
    // because recently-created visits won't be closed
    visit.setDateCreated(DateUtils.addHours(new Date(), -30));
    visit.setStartDatetime(DateUtils.addHours(new Date(), -60));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create ED Triage encounter
    Encounter edTriage = new Encounter();
    edTriage.setPatient(patient);
    edTriage.setEncounterType(encounterService.getEncounterTypeByUuid(ED_TRIAGE_ENCOUNTER_TYPE_UUID));
    edTriage.setEncounterDatetime(visit.getStartDatetime());
    encounterService.saveEncounter(edTriage);
    // create another encounter within 48 hours
    Encounter consult = new Encounter();
    consult.setPatient(patient);
    consult.setEncounterType(emrApiProperties.getVisitNoteEncounterType());
    consult.setEncounterDatetime(DateUtils.addHours(new Date(), -47));
    encounterService.saveEncounter(consult);
    // create an encounter with a disposition obs of "discharge"
    Encounter encounterWithDisposition = new Encounter();
    encounterWithDisposition.setPatient(patient);
    encounterWithDisposition.setEncounterType(encounterService.getEncounterType(1));
    encounterWithDisposition.setEncounterDatetime(visit.getStartDatetime());
    Obs dispositionObsGroup = new Obs();
    dispositionObsGroup.setConcept(dispositionService.getDispositionDescriptor().getDispositionSetConcept());
    Obs dispositionObs = new Obs();
    dispositionObs.setConcept(dispositionService.getDispositionDescriptor().getDispositionConcept());
    // this fake code is set in ContextSensitiveMetadataTestUtils
    dispositionObs.setValueCoded(emrConceptService.getConcept(EmrApiConstants.EMR_CONCEPT_SOURCE_NAME + ":Discharged"));
    dispositionObsGroup.addGroupMember(dispositionObs);
    encounterWithDisposition.addObs(dispositionObsGroup);
    encounterService.saveEncounter(encounterWithDisposition);
    visit.addEncounter(edTriage);
    visit.addEncounter(consult);
    visit.addEncounter(encounterWithDisposition);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNull(activeVisit);
}
Also used : Obs(org.openmrs.Obs) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 100 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldNotCloseVisitIfMostRecentDispositionKeepsVisitOpen.

@Test
public void test_shouldNotCloseVisitIfMostRecentDispositionKeepsVisitOpen() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    // patient already has one visit in test dataset
    Patient patient = patientService.getPatient(7);
    // need o tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
    Location unknownLocation = locationService.getLocation(1);
    unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(unknownLocation);
    Location location = locationService.getLocation(2);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    Visit visit = new Visit();
    // because recently-created visits won't be closed
    visit.setDateCreated(DateUtils.addHours(new Date(), -30));
    visit.setStartDatetime(DateUtils.addHours(new Date(), -14));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create an encounter with a disposition obs
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    encounter.setEncounterType(encounterService.getEncounterType(1));
    encounter.setEncounterDatetime(visit.getStartDatetime());
    Obs dispositionObsGroup = new Obs();
    dispositionObsGroup.setConcept(dispositionService.getDispositionDescriptor().getDispositionSetConcept());
    Obs dispositionObs = new Obs();
    dispositionObs.setConcept(dispositionService.getDispositionDescriptor().getDispositionConcept());
    // this fake code is set in ContextSensitiveMetadataTestUtils
    dispositionObs.setValueCoded(emrConceptService.getConcept(EmrApiConstants.EMR_CONCEPT_SOURCE_NAME + ":Admit to hospital"));
    dispositionObsGroup.addGroupMember(dispositionObs);
    encounter.addObs(dispositionObsGroup);
    encounterService.saveEncounter(encounter);
    visit.addEncounter(encounter);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNotNull(activeVisit);
}
Also used : Obs(org.openmrs.Obs) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15