Search in sources :

Example 1 with DefaultZplPaperFormLabelTemplate

use of org.openmrs.module.paperrecord.template.DefaultZplPaperFormLabelTemplate in project openmrs-module-mirebalais by PIH.

the class LabelFragmentController method printLabel.

public SimpleObject printLabel(UiUtils ui, @RequestParam("patientId") Patient patient, @RequestParam(value = "locationId", required = false) Location location, @SpringBean("printerService") PrinterService printerService, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("messageSourceService") MessageSourceService messageSourceService, UiSessionContext uiSessionContext) throws UnableToPrintLabelException {
    try {
        if (location == null) {
            location = uiSessionContext.getSessionLocation();
        }
        // TODO hack, we should wire in the DefaultZlpPaperFormLabel bean here instead
        DefaultZplPaperFormLabelTemplate template = new DefaultZplPaperFormLabelTemplate();
        template.setEmrApiProperties(emrApiProperties);
        template.setMessageSourceService(messageSourceService);
        String data = template.generateLabel(patient, null);
        Printer printer = printerService.getDefaultPrinter(location, PrinterType.LABEL);
        if (printer == null) {
            // TODO: better warning if no default printer
            return SimpleObject.create("success", false, "message", "No printer configured for " + ui.format(location));
        }
        printerService.printViaSocket(data, printer, "UTF-8");
        // TODO switch all these to message codes
        return SimpleObject.create("success", true, "message", "Label printed for " + " " + printer.getPhysicalLocation().getName());
    } catch (UnableToPrintViaSocketException e) {
        log.warn("User " + uiSessionContext.getCurrentUser() + " unable to print at location " + location, e);
        return SimpleObject.create("success", false, "message", "Unable to print label");
    }
}
Also used : DefaultZplPaperFormLabelTemplate(org.openmrs.module.paperrecord.template.DefaultZplPaperFormLabelTemplate) UnableToPrintViaSocketException(org.openmrs.module.printer.UnableToPrintViaSocketException) Printer(org.openmrs.module.printer.Printer)

Aggregations

DefaultZplPaperFormLabelTemplate (org.openmrs.module.paperrecord.template.DefaultZplPaperFormLabelTemplate)1 Printer (org.openmrs.module.printer.Printer)1 UnableToPrintViaSocketException (org.openmrs.module.printer.UnableToPrintViaSocketException)1