use of org.openmrs.Location 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.Location 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.Location 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.Location 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.Location in project openmrs-module-mirebalais by PIH.
the class ZlEmrIdCardPrinterTest method testZlEmrIdCardPrinting.
@Test
public void testZlEmrIdCardPrinting() throws Exception {
// Register printer model
PrinterModel model = new PrinterModel();
model.setName("Test Zebra P110i");
model.setType(PrinterType.ID_CARD);
model.setPrintHandler("p110iPrintHandler");
printerService.savePrinterModel(model);
// Register instance of this printer model
Printer printer = new Printer();
printer.setName("Test ZL EMR ID Card Printer");
printer.setType(PrinterType.ID_CARD);
printer.setModel(model);
printer.setPhysicalLocation(null);
printer.setIpAddress("127.0.0.1");
printer.setPort("9105");
printerService.savePrinter(printer);
// Set location for this printer
Location location = MetadataUtils.existing(Location.class, MirebalaisLocations.CLINIC_REGISTRATION.uuid());
printerService.setDefaultPrinter(location, PrinterType.ID_CARD, printer);
// Create a patient for whom to print an id card
PatientBuilder pb = testDataManager.patient().birthdate("1948-02-16").gender("M").name("Ringo", "Starr");
pb.identifier(MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.ZL_EMR_ID.uuid()), "X2ECEX", location);
pb.personAttribute(MetadataUtils.existing(PersonAttributeType.class, HaitiPersonAttributeTypes.TELEPHONE_NUMBER.uuid()), "555-1212");
pb.address("should be line 2", "should be line 1", "should be line 4", "should be line 5a", "should not exist", "should be line 5b");
Patient patient = pb.save();
TestPrinter testPrinter = new TestPrinter("127.0.0.1", 9105, "Windows-1252");
testPrinter.start();
zlEmrIdCardPrinter.print(patient, location);
// Pause up to 30 seconds for printing to happen
for (int i = 0; i < 30 && testPrinter.getNumPrintJobs() == 0; i++) {
Thread.sleep(1000);
}
Assert.assertEquals(1, testPrinter.getNumPrintJobs());
TestPrinter.PrintJob job = testPrinter.getLatestPrintJob();
Assert.assertTrue(job.containsData("B 75 550 0 0 0 3 100 0 X2ECEX"));
testPrinter.stop();
}
Aggregations