/
ViewEncounterWithHtmlFormPageController.java
59 lines (50 loc) · 2.64 KB
/
ViewEncounterWithHtmlFormPageController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.openmrs.module.htmlformentryui.page.controller.htmlform;
import org.apache.commons.lang.StringUtils;
import org.openmrs.Encounter;
import org.openmrs.module.emrapi.patient.PatientDomainWrapper;
import org.openmrs.module.htmlformentry.HtmlForm;
import org.openmrs.module.htmlformentry.HtmlFormEntryService;
import org.openmrs.ui.framework.SimpleObject;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.InjectBeans;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.page.PageModel;
import org.springframework.web.bind.annotation.RequestParam;
public class ViewEncounterWithHtmlFormPageController {
public void get(@RequestParam("encounter") Encounter encounter,
@RequestParam(value = "showPatientHeader", defaultValue = "true") boolean showPatientHeader,
@RequestParam(value = "returnUrl", required = false) String returnUrl,
@RequestParam(value = "returnLabel", required = false) String returnLabel,
@RequestParam(value = "editStyle", defaultValue = "standard") String editStyle,
@InjectBeans PatientDomainWrapper patient,
@SpringBean("htmlFormEntryService") HtmlFormEntryService htmlFormEntryService,
UiUtils ui,
PageModel model) {
patient.setPatient(encounter.getPatient());
if (StringUtils.isEmpty(returnUrl)) {
returnUrl = ui.pageLink("coreapps", "patientdashboard/patientDashboard", SimpleObject.create("patientId", patient.getId()));
}
if (StringUtils.isEmpty(returnLabel)) {
returnLabel = ui.escapeJs(ui.format(patient.getPatient()));
}
model.addAttribute("patient", patient);
model.addAttribute("visit", encounter.getVisit());
model.addAttribute("encounter", encounter);
model.addAttribute("returnUrl", returnUrl);
model.addAttribute("returnLabel", returnLabel);
model.addAttribute("editStyle", fixCase(editStyle));
model.addAttribute("showPatientHeader", showPatientHeader);
HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm());
if (htmlForm == null) {
throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
}
model.addAttribute("htmlForm", htmlForm);
}
/**
* @param word
* @return word with the first letter uppercase, and the rest lowercase
*/
private String fixCase(String word) {
return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase();
}
}