Search in sources :

Example 61 with Location

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;
}
Also used : Redirect(org.openmrs.ui.framework.page.Redirect) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location)

Example 62 with Location

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());
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Patient(org.openmrs.Patient) LinkedHashMap(java.util.LinkedHashMap) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) AppDescriptor(org.openmrs.module.appframework.domain.AppDescriptor) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Location(org.openmrs.Location)

Example 63 with Location

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);
}
Also used : VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Location(org.openmrs.Location)

Example 64 with Location

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);
    }
}
Also used : Patient(org.openmrs.Patient) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location)

Example 65 with Location

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();
}
Also used : PatientBuilder(org.openmrs.contrib.testdata.builder.PatientBuilder) PrinterModel(org.openmrs.module.printer.PrinterModel) PersonAttributeType(org.openmrs.PersonAttributeType) Patient(org.openmrs.Patient) Printer(org.openmrs.module.printer.Printer) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15