use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class VisitTypeHelper method getVisitColorAndShortName.
/**
* Returns a map of the color and short name for a given list of visits
*
* @param visits
* @return
*/
public Map<Integer, Map<String, Object>> getVisitColorAndShortName(List<VisitDomainWrapper> visits) {
Map<Integer, Map<String, Object>> visitsWithAttr = new LinkedHashMap<Integer, Map<String, Object>>();
for (VisitDomainWrapper visit : visits) {
Map<String, Object> visitColorAndShortName = getVisitTypeColorAndShortName(visit.getVisit().getVisitType());
visitsWithAttr.put(visit.getVisitId(), visitColorAndShortName);
}
return visitsWithAttr;
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class ActiveVisitStatusFragmentController method controller.
public void controller(FragmentConfiguration config, @FragmentParam("patient") PatientDomainWrapper pdw, @SpringBean("adtService") AdtService adtService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext, UiUtils uiUtils, FragmentModel model) {
config.addAttribute("activeVisitStartDatetime", null);
Patient patient = pdw.getPatient();
VisitDomainWrapper activeVisit = (VisitDomainWrapper) config.getAttribute("activeVisit");
if (activeVisit == null) {
try {
Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
activeVisit = adtService.getActiveVisit(patient, visitLocation);
} catch (IllegalArgumentException ex) {
// location does not support visits
}
}
if (activeVisit != null) {
config.addAttribute("activeVisit", activeVisit);
config.addAttribute("activeVisitStartDatetime", uiUtils.format(activeVisit.getStartDatetime()));
config.addAttribute("showVisitTypeOnPatientHeaderSection", visitTypeHelper.showVisitTypeOnPatientHeaderSection());
String color = "";
if (activeVisit != null) {
color = (String) visitTypeHelper.getVisitTypeColorAndShortName(activeVisit.getVisit().getVisitType()).get("color");
}
model.addAttribute("visitAttributeColor", color);
}
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentController method getVisitDetails.
public SimpleObject getVisitDetails(@SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @InjectBeans CoreAppsProperties coreAppsProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("encounterService") EncounterService encounterService, @RequestParam("visitId") Visit visit, @RequestParam(value = "fromEncounter", required = false) Integer encounterIndex, @RequestParam(value = "encounterCount", required = false) Integer encounterCount, UiUtils uiUtils, UiSessionContext sessionContext) throws ParseException {
if (encounterIndex == null)
encounterIndex = 0;
if (encounterCount == null) {
encounterCount = coreAppsProperties.getPatientDashboardEncounterCount();
}
ParseEncounterToJson parseEncounterToJson = new ParseEncounterToJson(appFrameworkService, uiUtils, encounterService);
SimpleObject simpleObject = SimpleObject.fromObject(visit, uiUtils, "id", "uuid", "location");
User authenticatedUser = sessionContext.getCurrentUser();
boolean canDeleteVisit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_VISIT);
Date startDatetime = visit.getStartDatetime();
Date stopDatetime = visit.getStopDatetime();
simpleObject.put("startDatetime", uiUtils.format(startDatetime));
if (stopDatetime != null) {
simpleObject.put("stopDatetime", uiUtils.format(stopDatetime));
} else {
simpleObject.put("stopDatetime", null);
}
VisitDomainWrapper visitWrapper = new VisitDomainWrapper(visit, emrApiProperties);
List<SimpleObject> encounters = getEncounterListAsJson(parseEncounterToJson, visitWrapper, authenticatedUser, encounterIndex, encounterCount);
simpleObject.put("encounters", encounters);
simpleObject.put("admitted", visitWrapper.isAdmitted());
simpleObject.put("canDeleteVisit", verifyIfUserHasPermissionToDeleteVisit(visit, authenticatedUser, canDeleteVisit));
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(visit.getPatient()));
contextModel.put("visit", new VisitContextModel(new VisitDomainWrapper(visit, emrApiProperties)));
List<Extension> visitActions = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.visitActions", contextModel);
Collections.sort(visitActions);
simpleObject.put("availableVisitActions", convertVisitActionsToSimpleObject(visitActions));
return simpleObject;
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method shouldReturnFalseIfLocationHasTagButVisitNotActive.
@Test
public void shouldReturnFalseIfLocationHasTagButVisitNotActive() {
Location sessionLocation = new Location();
SimpleObject sessionLocationRestRep = new SimpleObject();
sessionLocationRestRep.put("uuid", "123abc");
SimpleObject admitTag = new SimpleObject();
admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
PowerMockito.mockStatic(ConversionUtil.class);
when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
when(visit.isActive()).thenReturn(false);
uiSessionContext.setSessionLocation(sessionLocation);
AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
appContextModel.put("visit", visit);
assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION), patientHasActiveVisit())), appContextModel), is(false));
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper 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);
}
Aggregations