Search in sources :

Example 1 with IdPrinter

use of org.openmrs.module.pihcore.printer.IdPrinter in project openmrs-module-pihcore by PIH.

the class IdCardFragmentController method printIdCard.

/**
 * This method will attempt to print a new id card for the given patient at the given location,
 * @return a SimpleObject containing a flag indicating success, and a message suitable for display
 */
public SimpleObject printIdCard(UiUtils ui, UiSessionContext uiSessionContext, @RequestParam("patientId") Patient patient, @RequestParam(value = "locationId", required = false) Location location, @SpringBean ZlEmrIdCardPrinter zlEmrIdCardPrinter, @SpringBean Config config) {
    IdPrinter printer = zlEmrIdCardPrinter;
    if (location == null) {
        location = uiSessionContext.getSessionLocation();
    }
    StatusMessage status;
    try {
        // TODO this should actually handle errors!
        printer.print(patient, location);
        status = new StatusMessage(true, ui.message("zl.registration.patient.idcard.successMessage", location.getName()));
    } catch (Exception e) {
        status = new StatusMessage(false, ui.message(e.getMessage()));
        log.warn("User " + uiSessionContext.getCurrentUser() + " unable to print ID card at location " + location, e);
    }
    return SimpleObject.fromObject(status, ui, "success", "message");
}
Also used : IdPrinter(org.openmrs.module.pihcore.printer.IdPrinter)

Example 2 with IdPrinter

use of org.openmrs.module.pihcore.printer.IdPrinter in project openmrs-module-pihcore by PIH.

the class PrintIdCardPageController method controller.

// TODO change this so we dynamically wire the correct printer bean in instead of wiring in both and picking using an if/then!
public void controller(PageModel model, UiUtils ui, UiSessionContext uiSessionContext, @RequestParam("patientId") Patient patient, @RequestParam(value = "locationId", required = false) Location location, @RequestParam(value = "returnUrl", required = false) String returnUrl, @SpringBean ZlEmrIdCardPrinter zlEmrIdCardPrinter, @SpringBean Config config) {
    IdPrinter printer = zlEmrIdCardPrinter;
    if (location == null) {
        location = uiSessionContext.getSessionLocation();
    }
    if (StringUtils.isBlank(returnUrl)) {
        returnUrl = ui.pageLink("registrationapp", "registrationSummary", ObjectUtil.toMap("patientId", patient.getPatientId()));
    }
    model.addAttribute("patient", patient);
    model.addAttribute("location", location);
    model.addAttribute("returnUrl", returnUrl);
    model.addAttribute("printerAvailableAtLocation", printer.isAvailableAtLocation(location));
}
Also used : IdPrinter(org.openmrs.module.pihcore.printer.IdPrinter)

Aggregations

IdPrinter (org.openmrs.module.pihcore.printer.IdPrinter)2