use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesElement method getPriorDiagnoses.
private List<Diagnosis> getPriorDiagnoses(FormEntryContext context, DispositionType dispositionType) {
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
if (context.getVisit() != null) {
VisitDomainWrapper visitDomainWrapper;
if (context.getVisit() instanceof Visit) {
visitDomainWrapper = adtService.wrap((Visit) context.getVisit());
} else {
visitDomainWrapper = (VisitDomainWrapper) context.getVisit();
}
diagnoses = visitDomainWrapper.getDiagnosesFromMostRecentDispositionByType(dispositionType);
}
return diagnoses;
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class ActiveVisitsPageController method get.
public String get(UiSessionContext sessionContext, PageModel model, @SpringBean AdtService service, @SpringBean("visitService") VisitService visitService, @RequestParam("app") AppDescriptor app, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper) {
Location sessionLocation = sessionContext.getSessionLocation();
if (sessionLocation == null) {
return "redirect:login.htm";
}
Location visitLocation = null;
if (sessionLocation != null) {
visitLocation = service.getLocationThatSupportsVisits(sessionLocation);
}
if (visitLocation == null) {
throw new IllegalStateException("Configuration required: no visit location found based on session location");
}
List<VisitDomainWrapper> activeVisits = service.getActiveVisits(visitLocation);
model.addAttribute("visitSummaries", activeVisits);
String patientPageUrl = app.getConfig().get("patientPageUrl").getTextValue();
model.addAttribute("patientPageUrl", patientPageUrl);
// used to determine whether or not we display a link to the patient in the results list
model.addAttribute("canViewVisits", Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_VISITS));
// retrieve all different visit types, with their color and short name
Map<Integer, Object> visitTypesWithAttr = new HashMap<Integer, Object>();
List<VisitType> allVisitTypes = visitService.getAllVisitTypes();
for (VisitType type : allVisitTypes) {
Map<String, Object> typeAttr = visitTypeHelper.getVisitTypeColorAndShortName(type);
visitTypesWithAttr.put(type.getVisitTypeId(), typeAttr);
}
model.addAttribute("visitTypesWithAttr", visitTypesWithAttr);
return null;
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class PatientPageController method controller.
public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, UiSessionContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @SpringBean("patientService") PatientService patientService, @SpringBean("adtService") AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("referenceapplication.app.capturevitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient?app=referenceapplication.vitals"));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
Form vitalsForm = formService.getFormByUuid("a000cb34-9ec1-4344-a1c8-f692232f6edd");
Location visitLocation = adtService.getLocationThatSupportsVisits(emrContext.getSessionLocation());
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, visitLocation);
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (activeVisit != null) {
for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
if (!encounter.isVoided() && vitalsForm.equals(encounter.getForm())) {
existingEncounters.add(encounter);
}
}
}
model.addAttribute("visit", activeVisit != null ? activeVisit.getVisit() : null);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class RetrospectiveVisitFragmentControllerTest method test_shouldReturnConflictingVisits.
@Test
public void test_shouldReturnConflictingVisits() throws Exception {
Patient patient = new Patient();
Location location = new Location();
Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
// should round to the time components to the start and end of the days, respectively
Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();
Visit conflictingVisit = new Visit();
conflictingVisit.setStartDatetime(new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate());
conflictingVisit.setStopDatetime(new DateTime(2012, 1, 3, 0, 0, 0, 999).toDate());
when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenThrow(ExistingVisitDuringTimePeriodException.class);
when(adtService.getVisits(patient, location, expectedStartDate, expectedStopDate)).thenReturn(Collections.singletonList(new VisitDomainWrapper(conflictingVisit)));
when(ui.format(any())).thenReturn("someDate");
List<SimpleObject> result = (List<SimpleObject>) controller.create(adtService, patient, location, startDate, null, request, ui);
assertThat(result.size(), is(1));
assertThat(result.get(0).toJson(), is("{\"startDate\":\"someDate\",\"stopDate\":\"someDate\",\"id\":null,\"uuid\":\"" + conflictingVisit.getUuid() + "\"}"));
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class RetrospectiveVisitFragmentControllerTest method test_shouldSetEndDateToCurrentTimeIfEndDateIsCurrentDay.
@Test
public void test_shouldSetEndDateToCurrentTimeIfEndDateIsCurrentDay() throws Exception {
when(ui.message("coreapps.retrospectiveVisit.addedVisitMessage")).thenReturn("success message");
Patient patient = createPatient();
Location location = new Location();
Visit mockVisit = new Visit();
Date startDate = new DateTime().withTime(0, 0, 0, 0).toDate();
Date endDate = startDate;
// to prevent against NPE when generating success message
when(adtService.createRetrospectiveVisit(eq(patient), eq(location), eq(startDate), any(Date.class))).thenReturn(new VisitDomainWrapper(mockVisit));
Date expectedMinDateValue = new Date();
controller.create(adtService, patient, location, startDate, endDate, request, ui);
Date expectedMaxDateValue = new Date();
verify(adtService).createRetrospectiveVisit(eq(patient), eq(location), eq(startDate), argThat(new IsWithinDateRange(expectedMinDateValue, expectedMaxDateValue)));
}
Aggregations