use of org.openmrs.module.emrapi.patient.PatientDomainWrapper 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.patient.PatientDomainWrapper in project openmrs-module-coreapps by openmrs.
the class DiagnosisWidgetFragmentController method controller.
public void controller(FragmentConfiguration config, @InjectBeans PatientDomainWrapper patientWrapper, @InjectBeans CoreAppsProperties properties) {
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;
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
int days = properties.getRecentDiagnosisPeriodInDays();
Calendar recent = Calendar.getInstance();
recent.set(Calendar.DATE, -days);
List<Diagnosis> recentDiagnoses = patientWrapper.getUniqueDiagnosesSince(recent.getTime());
config.addAttribute("recentDiagnoses", recentDiagnoses);
}
use of org.openmrs.module.emrapi.patient.PatientDomainWrapper in project openmrs-module-coreapps by openmrs.
the class DashboardWidgetFragmentController method controller.
public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adminService") AdministrationService adminService) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object patient = null;
patient = config.get("patient");
if (patient == null) {
patient = config.get("patientId");
}
ObjectNode appConfig = app.getConfig();
if (patient != null) {
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else if (patient instanceof Integer) {
// assume we have patientId
patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
}
if (appConfig.get("dateFormat") == null) {
appConfig.put("dateFormat", adminService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATE_FORMAT, "yyyy-MM-dd"));
}
appConfig.put("locale", Context.getLocale().toString());
appConfig.put("language", Context.getLocale().getLanguage().toString());
Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
config.merge(appConfigMap);
config.addAttribute("json", appConfig.toString().replace('\"', '\''));
}
use of org.openmrs.module.emrapi.patient.PatientDomainWrapper in project openmrs-module-coreapps by openmrs.
the class EditVisitFragmentController method controller.
public void controller(FragmentConfiguration config, FragmentModel model, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext) {
config.require("patient");
config.require("visit");
PatientDomainWrapper patientWrapper;
Object patient = config.get("patient");
if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else {
throw new IllegalArgumentException("Patient must be of type PatientDomainWrapper");
}
Visit visit = (Visit) config.get("visit");
// get visit types
List<VisitType> visitTypes = visitTypeHelper.getUnRetiredVisitTypes();
// get visit attribute types
List<VisitAttributeType> visitAttributeTypes = visitService.getAllVisitAttributeTypes();
model.addAttribute("patient", patientWrapper);
model.addAttribute("visit", visit);
model.addAttribute("visitTypes", visitTypes);
model.addAttribute("visitAttributeTypes", visitAttributeTypes);
}
use of org.openmrs.module.emrapi.patient.PatientDomainWrapper in project openmrs-module-coreapps by openmrs.
the class ProgramHistoryFragmentController method controller.
public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("programWorkflowService") ProgramWorkflowService programWorkflowService) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object patient = null;
patient = config.get("patient");
if (patient == null) {
patient = config.get("patientId");
}
if (patient == null) {
config.require("patient");
}
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else if (patient instanceof Integer) {
// assume we have patientId
patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
ObjectNode appConfig = app.getConfig();
appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
if (appConfig.get("program") == null || StringUtils.isEmpty(appConfig.get("program").getTextValue())) {
throw new MissingPropertyException("Program must be specified");
}
Program program = programWorkflowService.getProgramByUuid(appConfig.get("program").getTextValue());
if (program == null) {
throw new MissingPropertyException("Invalid program");
}
List<PatientProgram> patientPrograms = programWorkflowService.getPatientPrograms(patientWrapper.getPatient(), program, null, null, null, null, false);
// TODO: assumption here is that "getPatientPrograms" returns results in chronological order--need to confirm?
Collections.reverse(patientPrograms);
List<String> programJson = new ArrayList<String>();
Boolean includeActive = appConfig.get("includeActive") != null ? appConfig.get("includeActive").getBooleanValue() : true;
Boolean includeInactive = appConfig.get("includeInactive") != null ? appConfig.get("includeInactive").getBooleanValue() : true;
for (PatientProgram patientProgram : patientPrograms) {
if ((patientProgram.getDateCompleted() == null && includeActive) || (patientProgram.getDateCompleted() != null && includeInactive)) {
appConfig.put("patientProgram", patientProgram.getUuid());
programJson.add(appConfig.toString().replace('\"', '\''));
}
}
Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
config.merge(appConfigMap);
config.addAttribute("programJson", programJson);
}
Aggregations