Search in sources :

Example 1 with SimpleObject

use of org.openmrs.module.webservices.rest.SimpleObject in project openmrs-module-pihcore by PIH.

the class LabLabelPrinterRestController method printLabel.

@RequestMapping(method = RequestMethod.GET, value = LAB_LABEL_PRINTER)
@ResponseBody
public Object printLabel(@RequestParam(value = "patient") String patientUuid, @RequestParam(value = "sessionLocation") String sessionLocationUuid) {
    SimpleObject response = new SimpleObject();
    if (StringUtils.isNotBlank(patientUuid)) {
        Patient patient = patientService.getPatientByUuid(patientUuid);
        Location location = locationService.getLocationByUuid(sessionLocationUuid);
        if (patient != null && location != null) {
            Printer printer = printerService.getDefaultPrinter(location, PrinterType.LABEL);
            if (printer != null) {
                Map<String, Object> paramMap = new HashMap<String, Object>();
                ZplLabLabelTemplate zplLabLabelTemplate = Context.getRegisteredComponent("zplLabLabelTemplate", ZplLabLabelTemplate.class);
                paramMap.put("data", zplLabLabelTemplate.generateLabel(patient));
                paramMap.put("encoding", zplLabLabelTemplate.getEncoding());
                paramMap.put("wait", 500);
                try {
                    printerService.print(paramMap, printer, false);
                    response = (SimpleObject) ConversionUtil.convertToRepresentation(patient, Representation.DEFAULT);
                } catch (UnableToPrintException e) {
                    response.put("error", true);
                    response.put("message", messageSourceService.getMessage("mirebalais.error.unableToContactPrinter"));
                }
            } else {
                response.put("error", true);
                response.put("message", messageSourceService.getMessage("mirebalais.error.noLabelPrinterConfiguredforLocation"));
            }
        }
    }
    return response;
}
Also used : SimpleObject(org.openmrs.module.webservices.rest.SimpleObject) HashMap(java.util.HashMap) Patient(org.openmrs.Patient) SimpleObject(org.openmrs.module.webservices.rest.SimpleObject) Printer(org.openmrs.module.printer.Printer) ZplLabLabelTemplate(org.openmrs.module.pihcore.printer.template.ZplLabLabelTemplate) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException) Location(org.openmrs.Location) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

HashMap (java.util.HashMap)1 Location (org.openmrs.Location)1 Patient (org.openmrs.Patient)1 ZplLabLabelTemplate (org.openmrs.module.pihcore.printer.template.ZplLabLabelTemplate)1 Printer (org.openmrs.module.printer.Printer)1 UnableToPrintException (org.openmrs.module.printer.UnableToPrintException)1 SimpleObject (org.openmrs.module.webservices.rest.SimpleObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1