use of org.openmrs.module.printer.UnableToPrintViaSocketException 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");
}
}
use of org.openmrs.module.printer.UnableToPrintViaSocketException in project openmrs-module-mirebalais by PIH.
the class WristbandFragmentController method printWristband.
public SimpleObject printWristband(UiUtils ui, @RequestParam("patientId") Patient patient, @RequestParam(value = "locationId", required = false) Location location, @SpringBean("wristbandTemplate") WristbandTemplate wristbandTemplate, @SpringBean("printerService") PrinterService printerService, @SpringBean("paperRecordService") PaperRecordService paperRecordService, UiSessionContext uiSessionContext) throws UnableToPrintLabelException {
try {
if (location == null) {
location = uiSessionContext.getSessionLocation();
}
// make sure a paper record has been created
if (!paperRecordService.paperRecordExistsForPatient(patient, location)) {
paperRecordService.createPaperRecord(patient, location);
}
String data = wristbandTemplate.generateWristband(patient, location);
Printer printer = printerService.getDefaultPrinter(location, PrinterType.WRISTBAND);
if (printer == null) {
// TODO: better warning if no default printer
return SimpleObject.create("success", false, "message", ui.message("mirebalais.error.noWristbandPrinterConfiguredForLocation") + " " + ui.format(location));
}
printerService.printViaSocket(data, printer, "UTF-8");
return SimpleObject.create("success", true, "message", ui.message("mirebalais.printWristband.patientDashboard.successMessage") + " " + printer.getPhysicalLocation().getName());
} catch (UnableToPrintViaSocketException e) {
log.warn("User " + uiSessionContext.getCurrentUser() + " unable to print wristband at location " + location, e);
return SimpleObject.create("success", false, "message", ui.message("mirebalais.error.unableToPrintWristband"));
}
}
use of org.openmrs.module.printer.UnableToPrintViaSocketException in project openmrs-module-pihcore by PIH.
the class WristbandFragmentController method printWristband.
public SimpleObject printWristband(UiUtils ui, @RequestParam("patientId") Patient patient, @RequestParam(value = "locationId", required = false) Location location, @SpringBean("wristbandTemplate") WristbandTemplate wristbandTemplate, @SpringBean("printerService") PrinterService printerService, @SpringBean("paperRecordService") PaperRecordService paperRecordService, UiSessionContext uiSessionContext) throws UnableToPrintLabelException {
try {
if (location == null) {
location = uiSessionContext.getSessionLocation();
}
// make sure a paper record has been created
if (!paperRecordService.paperRecordExistsForPatient(patient, location)) {
paperRecordService.createPaperRecord(patient, location);
}
String data = wristbandTemplate.generateWristband(patient, location);
Printer printer = printerService.getDefaultPrinter(location, PrinterType.WRISTBAND);
if (printer == null) {
// TODO: better warning if no default printer
return SimpleObject.create("success", false, "message", ui.message("mirebalais.error.noWristbandPrinterConfiguredForLocation") + " " + ui.format(location));
}
printerService.printViaSocket(data, printer, "UTF-8");
return SimpleObject.create("success", true, "message", ui.message("mirebalais.printWristband.patientDashboard.successMessage") + " " + printer.getPhysicalLocation().getName());
} catch (UnableToPrintViaSocketException e) {
log.warn("User " + uiSessionContext.getCurrentUser() + " unable to print wristband at location " + location, e);
return SimpleObject.create("success", false, "message", ui.message("mirebalais.error.unableToPrintWristband"));
}
}
Aggregations