Search in sources :

Example 16 with Encounter

use of org.openmrs.Encounter 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)

Example 17 with Encounter

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

the class BmiEncounterDataEvaluatorTest method shouldReturnNullIfNoHeight.

@Test
public void shouldReturnNullIfNoHeight() throws Exception {
    EncounterBuilder eb = data.encounter();
    eb.patient(createPatient());
    eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
    eb.location(locationService.getLocation("CDI Klinik Ekstèn Jeneral"));
    eb.encounterType(getVitalsEncounterType());
    eb.obs(Metadata.getConcept("PIH:HEIGHT (CM)"), 152.4);
    Encounter enc = eb.save();
    EncounterEvaluationContext context = new EncounterEvaluationContext();
    context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
    EvaluatedEncounterData res = encounterDataService.evaluate(new BmiEncounterDataDefinition(), context);
    assertNull(res.getData().get(enc.getEncounterId()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) BmiEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.BmiEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 18 with Encounter

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

the class BmiEncounterDataEvaluatorTest method shouldReturnNullIfNoWeight.

@Test
public void shouldReturnNullIfNoWeight() throws Exception {
    EncounterBuilder eb = data.encounter();
    eb.patient(createPatient());
    eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
    eb.location(locationService.getLocation("CDI Klinik Ekstèn Jeneral"));
    eb.encounterType(getVitalsEncounterType());
    eb.obs(Metadata.getConcept("PIH:WEIGHT (KG)"), 45.4);
    Encounter enc = eb.save();
    EncounterEvaluationContext context = new EncounterEvaluationContext();
    context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
    EvaluatedEncounterData res = encounterDataService.evaluate(new BmiEncounterDataDefinition(), context);
    assertNull(res.getData().get(enc.getEncounterId()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) BmiEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.BmiEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 19 with Encounter

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

the class RetrospectiveEncounterDataEvaluatorTest method shouldFindEncounterToBeRetrospective.

@Test
public void shouldFindEncounterToBeRetrospective() throws Exception {
    EncounterBuilder eb = data.encounter();
    eb.patient(createPatient());
    eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
    eb.location(locationService.getLocation("CDI Klinik Ekstèn Jeneral"));
    eb.encounterType(encounterService.getAllEncounterTypes().get(0));
    Encounter enc = eb.save();
    EncounterEvaluationContext context = new EncounterEvaluationContext();
    context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
    EvaluatedEncounterData res = encounterDataService.evaluate(new RetrospectiveEncounterDataDefinition(), context);
    assertTrue((Boolean) res.getData().get(enc.getEncounterId()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) RetrospectiveEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.RetrospectiveEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 20 with Encounter

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

the class PihCloseStaleVisitsTaskTest method test_shouldNotCloseVisitIfHasEncounterWithinExpirationRange.

@Test
public void test_shouldNotCloseVisitIfHasEncounterWithinExpirationRange() 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 within the expiration range
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    encounter.setEncounterType(encounterService.getEncounterType(1));
    // expire hours - 1
    encounter.setEncounterDatetime(DateUtils.addHours(new Date(), -(emrApiProperties.getVisitExpireHours() - 1)));
    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 : 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

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19