use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class MergeVisitsPageController method controller.
public Object controller(@RequestParam("patientId") Patient patient, @InjectBeans PatientDomainWrapper patientDomainWrapper, UiSessionContext sessionContext, PageModel model, @SpringBean AdtService service, @SpringBean("locationService") LocationService locationService, @RequestParam(value = "returnUrl", required = false) String returnUrl) {
if (patient.isVoided() || patient.isPersonVoided()) {
return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
}
patientDomainWrapper.setPatient(patient);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("returnUrl", returnUrl);
Location sessionLocation = sessionContext.getSessionLocation();
Location visitLocation = null;
if (sessionLocation != null) {
visitLocation = service.getLocationThatSupportsVisits(sessionLocation);
}
if (visitLocation != null) {
VisitDomainWrapper activeVisit = service.getActiveVisit(patient, visitLocation);
model.addAttribute("activeVisit", activeVisit);
} else {
throw new IllegalStateException("Configuration required: no visit location found based on session location");
}
return null;
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldFailIfActiveVisitAlreadyExists.
@Test
public void shouldFailIfActiveVisitAlreadyExists() throws Exception {
Patient patient = new Patient();
Location visitLocation = new Location();
when(adtService.getActiveVisit(patient, visitLocation)).thenReturn(new VisitDomainWrapper(null, null));
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, null, emrContext, request);
assertThat(result, is(instanceOf(FailureResult.class)));
verify(adtService, never()).ensureVisit(eq(patient), any(Date.class), eq(visitLocation));
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class VisitsSectionFragmentController method controller.
public void controller(FragmentConfiguration config, PageModel pageModel, FragmentModel model, UiUtils ui, UiSessionContext sessionContext, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper) {
config.require("patient");
Object patient = config.get("patient");
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
config.addAttribute("patient", patientWrapper);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
}
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(patientWrapper.getPatient()));
// backwards-compatible for links that still specify patient uuid substitution with "{{patientId}}"
contextModel.put("patientId", patientWrapper.getPatient().getUuid());
AppDescriptor app = (AppDescriptor) pageModel.get("app");
String visitsPageWithSpecificVisitUrl = null;
String visitsPageUrl = null;
// see if the app specifies urls to use
if (app != null) {
try {
visitsPageWithSpecificVisitUrl = app.getConfig().get("visitUrl").getTextValue();
} catch (Exception ex) {
}
try {
visitsPageUrl = app.getConfig().get("visitsUrl").getTextValue();
} catch (Exception ex) {
}
}
if (visitsPageWithSpecificVisitUrl == null) {
visitsPageWithSpecificVisitUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
}
visitsPageWithSpecificVisitUrl = "/" + ui.contextPath() + "/" + visitsPageWithSpecificVisitUrl;
if (visitsPageUrl == null) {
visitsPageUrl = coreAppsProperties.getVisitsPageUrl();
}
// hack fix for RA-1002--if there is an active visit, and we are using the "regular" visit dashboard we actually want to link to the specific visit
Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patientWrapper.getPatient(), visitLocation);
if (visitsPageUrl.contains("/coreapps/patientdashboard/patientDashboard.page?") && activeVisit != null) {
visitsPageUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
contextModel.put("visit", activeVisit.getVisit());
}
visitsPageUrl = "/" + ui.contextPath() + "/" + visitsPageUrl;
model.addAttribute("visitsUrl", templateFactory.handlebars(visitsPageUrl, contextModel));
List<VisitDomainWrapper> recentVisits = patientWrapper.getAllVisitsUsingWrappers();
if (recentVisits.size() > 5) {
recentVisits = recentVisits.subList(0, 5);
}
Map<VisitDomainWrapper, String> recentVisitsWithLinks = new LinkedHashMap<VisitDomainWrapper, String>();
for (VisitDomainWrapper recentVisit : recentVisits) {
contextModel.put("visit", new VisitContextModel(recentVisit));
// since the "recentVisit" isn't part of the context module, we bind it first to the visit url, before doing the handlebars binding against the context
recentVisitsWithLinks.put(recentVisit, templateFactory.handlebars(ui.urlBind(visitsPageWithSpecificVisitUrl, recentVisit.getVisit()), contextModel));
}
Map<Integer, Map<String, Object>> recentVisitsWithAttr = visitTypeHelper.getVisitColorAndShortName(recentVisits);
model.addAttribute("recentVisitsWithAttr", recentVisitsWithAttr);
model.addAttribute("recentVisitsWithLinks", recentVisitsWithLinks);
config.addAttribute("showVisitTypeOnPatientHeaderSection", visitTypeHelper.showVisitTypeOnPatientHeaderSection());
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class CustomLinksWidgetFragmentController method controller.
public void controller(FragmentConfiguration config, UiUtils uiUtils, @FragmentParam("app") AppDescriptor app, @SpringBean("adtService") AdtService adtService, @RequestParam("patientId") Patient patient, UiSessionContext sessionContext) {
Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, visitLocation);
ObjectMapper mapper = new ObjectMapper();
Map<String, String> links = mapper.convertValue(app.getConfig().get("links"), Map.class);
replacePatientVariables(links, patient, uiUtils);
if (activeVisit != null) {
replaceVisitVariables(links, activeVisit.getVisit(), uiUtils);
}
config.addAttribute("icon", app.getIcon());
config.addAttribute("label", app.getLabel());
config.addAttribute("links", links);
}
use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandler method doStartTag.
@Override
public boolean doStartTag(FormEntrySession session, PrintWriter out, Node parent, Node node) throws BadFormDesignException {
Set<Obs> exisitingDispositionObsGroup = null;
if (session.getContext().getExistingEncounter() != null && session.getContext().getExistingObsInGroups() != null) {
exisitingDispositionObsGroup = getObsGroupByGroupingConcept(session.getContext().getExistingObsInGroups(), HtmlFormEntryUtil.getConcept(EmrApiConstants.EMR_CONCEPT_SOURCE_NAME + ": " + EmrApiConstants.CONCEPT_CODE_DISPOSITION_CONCEPT_SET));
}
List<Disposition> dispositions = null;
VisitDomainWrapper visitDomainWrapper = session.getContext().getVisit() != null ? adtService.wrap((Visit) session.getContext().getVisit()) : null;
if (visitDomainWrapper == null) {
dispositions = dispositionService.getDispositions();
} else {
dispositions = dispositionService.getValidDispositions(visitDomainWrapper);
}
Element dispositionObsGroup = node.getOwnerDocument().createElement("obsgroup");
dispositionObsGroup.setAttribute("groupingConceptId", emrApiProperties.getEmrApiConceptSource().getName() + ":" + EmrApiConstants.CONCEPT_CODE_DISPOSITION_CONCEPT_SET);
// TODO: allow the label text to be overwritten, move the message code to the coreapps module
Element label = node.getOwnerDocument().createElement("label");
Element uimessageLabel = node.getOwnerDocument().createElement("uimessage");
uimessageLabel.setAttribute("code", "emr.consult.disposition");
label.appendChild(uimessageLabel);
dispositionObsGroup.appendChild(label);
// TODO: allow the id to be passed in from the form?
Element dispositionObs = node.getOwnerDocument().createElement("obs");
dispositionObs.setAttribute("id", "disposition-" + UUID.randomUUID().toString());
dispositionObs.setAttribute("style", "dropdown");
dispositionObs.setAttribute("conceptId", emrApiProperties.getEmrApiConceptSource().getName() + ":" + EmrApiConstants.CONCEPT_CODE_DISPOSITION);
if (((Element) node).hasAttribute("required") && ((Element) node).getAttribute("required").equalsIgnoreCase("true")) {
dispositionObs.setAttribute("required", "true");
}
// add the possible dispositions from the configured disposition retrieved from disposition factory
List<Control> controls = new ArrayList<Control>();
String answerConceptIds = "";
StringBuilder answerCodes = new StringBuilder();
Iterator<Disposition> i = dispositions.iterator();
while (i.hasNext()) {
Disposition disposition = i.next();
answerConceptIds = answerConceptIds + disposition.getConceptCode() + (i.hasNext() ? "," : "");
answerCodes.append(disposition.getName());
if (i.hasNext()) {
answerCodes.append(",");
}
// determine if there are any additional observations we need to collect for this disposition
if (disposition.getAdditionalObs() != null && disposition.getAdditionalObs().size() > 0) {
controls.add(buildNewControl(disposition, disposition.getAdditionalObs()));
}
}
dispositionObs.setAttribute("answerConceptIds", answerConceptIds);
dispositionObs.setAttribute("answerCodes", answerCodes.toString());
if (controls != null && controls.size() > 0) {
generateControlsElement(dispositionObs, controls);
}
dispositionObsGroup.appendChild(dispositionObs);
if (controls != null && controls.size() > 0) {
generateAdditionalObsElements(dispositionObsGroup, controls, exisitingDispositionObsGroup);
}
node.appendChild(dispositionObsGroup);
return true;
}
Aggregations