use of org.openmrs.module.printer.Printer in project openmrs-module-mirebalais by PIH.
the class ZlEmrIdCardPrinterTest method testZlEmrIdCardPrinting.
@Test
public void testZlEmrIdCardPrinting() throws Exception {
// Register printer model
PrinterModel model = new PrinterModel();
model.setName("Test Zebra P110i");
model.setType(PrinterType.ID_CARD);
model.setPrintHandler("p110iPrintHandler");
printerService.savePrinterModel(model);
// Register instance of this printer model
Printer printer = new Printer();
printer.setName("Test ZL EMR ID Card Printer");
printer.setType(PrinterType.ID_CARD);
printer.setModel(model);
printer.setPhysicalLocation(null);
printer.setIpAddress("127.0.0.1");
printer.setPort("9105");
printerService.savePrinter(printer);
// Set location for this printer
Location location = MetadataUtils.existing(Location.class, MirebalaisLocations.CLINIC_REGISTRATION.uuid());
printerService.setDefaultPrinter(location, PrinterType.ID_CARD, printer);
// Create a patient for whom to print an id card
PatientBuilder pb = testDataManager.patient().birthdate("1948-02-16").gender("M").name("Ringo", "Starr");
pb.identifier(MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.ZL_EMR_ID.uuid()), "X2ECEX", location);
pb.personAttribute(MetadataUtils.existing(PersonAttributeType.class, HaitiPersonAttributeTypes.TELEPHONE_NUMBER.uuid()), "555-1212");
pb.address("should be line 2", "should be line 1", "should be line 4", "should be line 5a", "should not exist", "should be line 5b");
Patient patient = pb.save();
TestPrinter testPrinter = new TestPrinter("127.0.0.1", 9105, "Windows-1252");
testPrinter.start();
zlEmrIdCardPrinter.print(patient, location);
// Pause up to 30 seconds for printing to happen
for (int i = 0; i < 30 && testPrinter.getNumPrintJobs() == 0; i++) {
Thread.sleep(1000);
}
Assert.assertEquals(1, testPrinter.getNumPrintJobs());
TestPrinter.PrintJob job = testPrinter.getLatestPrintJob();
Assert.assertTrue(job.containsData("B 75 550 0 0 0 3 100 0 X2ECEX"));
testPrinter.stop();
}
use of org.openmrs.module.printer.Printer 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.Printer in project openmrs-module-mirebalais by PIH.
the class WristbandTemplateTest method testWristbandHack.
@Test
@Ignore
public void testWristbandHack() throws UnableToPrintViaSocketException {
int i = 0;
while (i < 1) {
StringBuffer data = new StringBuffer();
data.append("^XA");
// specify Unicode encoding
data.append("^CI28");
// set direct transfer type
data.append("^MTD");
// set orientation
data.append("^FWB");
// demographics
data.append("^FO050,200^FB2150,1,0,L,0^AS^FDHôpital Universitaire de Mirebalais 19-May-2014^FS");
data.append("^FO100,200^FB2150,1,0,L,0^AU^FDRingo Starr^FS");
data.append("^FO160,200^FB2150,1,0,L,0^AU^FD07 Jul 1940^FS");
data.append("^FO160,200^FB1850,1,0,L,0^AT^FD40 years^FS");
data.append("^FO160,200^FB1650,1,0,L,0^AU^FDMale A 000005^FS");
data.append("^FO220,200^FB2150,1,0,L,0^AS^FDAvant Eglise Chretienne des perlerlerin de la siant tete de moliere^FS");
data.append("^FO270,200^FB2150,1,0,L,0^AS^FDSaut D'Eau, 1ere Riviere Canot, Saut d'Eau, Centre^FS");
// barcode
data.append("^FO100,2400^AT^BY4^BC,150,N^FDABC^XZ");
Printer printer = new Printer();
printer.setIpAddress("10.3.18.113");
printer.setPort("9100");
printer.setId(1);
new PrinterServiceImpl().printViaSocket(data.toString(), printer, "UTF-8");
i++;
}
}
use of org.openmrs.module.printer.Printer 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.Printer 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