use of org.openmrs.module.pihcore.printer.template.ZplLabLabelTemplate in project openmrs-module-pihcore by PIH.
the class ZplLabLabelTemplateTest method setup.
@Before
public void setup() {
primaryIdentifierType = new PatientIdentifierType();
template = new ZplLabLabelTemplate();
EmrApiProperties emrApiProperties = mock(EmrApiProperties.class);
when(emrApiProperties.getPrimaryIdentifierType()).thenReturn(primaryIdentifierType);
template.setEmrApiProperties(emrApiProperties);
}
use of org.openmrs.module.pihcore.printer.template.ZplLabLabelTemplate 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;
}
Aggregations