use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class VisitIncludesFragmentController method controller.
public void controller(FragmentConfiguration config, FragmentModel model, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext, HttpServletRequest request, @SpringBean("patientService") PatientService patientService) {
Object patient = config.get("patient");
if (patient == null) {
// retrieve patient id from parameter map
if (request.getParameter("patientId") != null) {
String patientId = request.getParameter("patientId");
if (patientId != null) {
if (!NumberUtils.isDigits(patientId)) {
patient = patientService.getPatientByUuid(patientId);
} else {
patient = patientService.getPatient(NumberUtils.toInt(patientId));
}
}
}
}
if (patient instanceof Patient) {
wrapper.setPatient((Patient) patient);
} else if (patient instanceof PatientDomainWrapper) {
wrapper = (PatientDomainWrapper) patient;
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
model.addAttribute("patient", wrapper);
List<VisitType> visitTypes = visitTypeHelper.getUnRetiredVisitTypes();
// send active visits to the view, if any.
List<Visit> activeVisits = visitService.getActiveVisitsByPatient(wrapper.getPatient());
// get visit attributes
List<VisitAttributeType> visitAttributeTypes = visitService.getAllVisitAttributeTypes();
// get the current visit's visit type, if any active visit at the current visit location
VisitDomainWrapper activeVisitWrapper = adtService.getActiveVisit(wrapper.getPatient(), sessionContext.getSessionLocation());
if (activeVisitWrapper != null) {
VisitType currentVisitType = activeVisitWrapper.getVisit().getVisitType();
model.addAttribute("currentVisitType", currentVisitType);
} else {
model.addAttribute("currentVisitType", null);
}
model.addAttribute("activeVisits", activeVisits);
model.addAttribute("visitTypes", visitTypes);
model.addAttribute("visitAttributeTypes", visitAttributeTypes);
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfDoesNotEncounterWithinExpirationRange.
@Test
public void test_shouldCloseVisitIfDoesNotEncounterWithinExpirationRange() 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();
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().execute();
activeVisit = adtService.getActiveVisit(patient, location);
assertNull(activeVisit);
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasCheckinAtEmergencyLocationButNoEncounterWithinFortyEightHours.
@Test
public void test_shouldNotKeepVisitOpenIfItHasCheckinAtEmergencyLocationButNoEncounterWithinFortyEightHours() 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 a check-in at Ijans Location
Encounter checkIn = new Encounter();
checkIn.setPatient(patient);
checkIn.setEncounterType(emrApiProperties.getCheckInEncounterType());
checkIn.setEncounterDatetime(visit.getStartDatetime());
// we've added this to the test dataset
checkIn.setLocation(locationService.getLocation("Ijans"));
encounterService.saveEncounter(checkIn);
// create another encounter, but not within 48 hours
Encounter consult = new Encounter();
consult.setPatient(patient);
consult.setEncounterType(emrApiProperties.getVisitNoteEncounterType());
consult.setEncounterDatetime(DateUtils.addHours(new Date(), -49));
encounterService.saveEncounter(consult);
visit.addEncounter(consult);
visitService.saveVisit(visit);
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
// sanity check
assertNotNull(activeVisit);
new PihCloseStaleVisitsTask().run();
activeVisit = adtService.getActiveVisit(patient, location);
assertNull(activeVisit);
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTaskTest method test_shouldKeepVisitOpenIfItHasCheckinAtEmergencyLocationAndEncounterWithinFortyEightHours.
@Test
public void test_shouldKeepVisitOpenIfItHasCheckinAtEmergencyLocationAndEncounterWithinFortyEightHours() 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 a check-in at Ijans Location
Encounter checkIn = new Encounter();
checkIn.setPatient(patient);
checkIn.setEncounterType(emrApiProperties.getCheckInEncounterType());
checkIn.setEncounterDatetime(visit.getStartDatetime());
// we've added this to the test dataset
checkIn.setLocation(locationService.getLocation("Ijans"));
encounterService.saveEncounter(checkIn);
// create a 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);
visit.addEncounter(checkIn);
visit.addEncounter(consult);
visitService.saveVisit(visit);
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
// sanity check
assertNotNull(activeVisit);
new PihCloseStaleVisitsTask().run();
activeVisit = adtService.getActiveVisit(patient, location);
assertNotNull(activeVisit);
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfDoesNotHaveEncounterWithinExpirationRange.
@Test
public void test_shouldCloseVisitIfDoesNotHaveEncounterWithinExpirationRange() 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 earlier than the expire 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);
assertNull(activeVisit);
}
Aggregations