Search in sources :

Example 6 with Printer

use of org.openmrs.module.printer.Printer in project openmrs-module-pihcore 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
    // Clinic Reception
    Location location = locationService.getLocation("Biwo Resepsyon");
    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, ZlConfigConstants.PATIENTIDENTIFIERTYPE_ZLEMRID_UUID), "X2ECEX", location);
    pb.personAttribute(Metadata.getPhoneNumberAttributeType(), "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();
}
Also used : PatientBuilder(org.openmrs.contrib.testdata.builder.PatientBuilder) PrinterModel(org.openmrs.module.printer.PrinterModel) Patient(org.openmrs.Patient) Printer(org.openmrs.module.printer.Printer) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 7 with Printer

use of org.openmrs.module.printer.Printer in project openmrs-module-pihcore 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^FDMirebalais  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++;
    }
}
Also used : Printer(org.openmrs.module.printer.Printer) PrinterServiceImpl(org.openmrs.module.printer.PrinterServiceImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Printer

use of org.openmrs.module.printer.Printer in project openmrs-module-mirebalais by PIH.

the class ZlEmrIdCardPrinter method print.

/**
 * Prints a ZL EMR ID Card for the given patient at the given location
 */
public void print(Patient patient, Location location) throws UnableToPrintException {
    Location issuingLocation;
    try {
        issuingLocation = paperRecordService.getMedicalRecordLocationAssociatedWith(location);
    } catch (Exception e) {
        throw new UnableToPrintException(getMessage("zl.registration.patient.idcard.locationNotAssociatedWithMedicalRecordLocation", location.getName()));
    }
    Printer printer = printerService.getDefaultPrinter(location, PrinterType.ID_CARD);
    if (printer == null) {
        throw new UnableToPrintException(getMessage("zl.registration.patient.idcard.noPrinterConfiguredForLocation", location.getName()));
    }
    DateFormat df = new SimpleDateFormat("dd MMM yyyy", Context.getLocale());
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("name", getName(patient));
    paramMap.put("patientIdentifier", getIdentifier(patient));
    paramMap.put("gender", patient.getGender());
    paramMap.put("birthdate", df.format(patient.getBirthdate()));
    paramMap.put("birthdateEstimated", patient.getBirthdateEstimated());
    paramMap.put("issuingLocation", getIssuingLocationName(issuingLocation));
    paramMap.put("issuedDate", df.format(new Date()));
    paramMap.put("telephoneNumber", getTelephoneNumber(patient));
    paramMap.put("customCardLabel", config.getIdCardLabel());
    paramMap.put("addressLines", getAddressLines(patient));
    paramMap.put("locale", config.getIdCardLocale());
    // but if it is a GX430t, it's just a simple socket print with raw ZPL code, so we need to generate the data using the label template
    if (printer.getModel().getPrintHandler().equals("gx430tPrintHandler")) {
        ZplCardTemplate zlCardTemplate = Context.getRegisteredComponent("zplCardTemplate", ZplCardTemplate.class);
        paramMap.put("data", zlCardTemplate.generateLabel(paramMap));
        paramMap.put("encoding", zlCardTemplate.getEncoding());
        paramMap.put("wait", 500);
    }
    printerService.print(paramMap, printer, false);
}
Also used : HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Printer(org.openmrs.module.printer.Printer) SimpleDateFormat(java.text.SimpleDateFormat) ZplCardTemplate(org.openmrs.module.mirebalais.printer.template.ZplCardTemplate) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException) Date(java.util.Date) Location(org.openmrs.Location)

Example 9 with Printer

use of org.openmrs.module.printer.Printer in project openmrs-module-pihcore by PIH.

the class ZlEmrIdCardPrinter method print.

/**
 * Prints a ZL EMR ID Card for the given patient at the given location
 */
public void print(Patient patient, Location location) throws UnableToPrintException {
    Location issuingLocation;
    try {
        issuingLocation = paperRecordService.getMedicalRecordLocationAssociatedWith(location);
    } catch (Exception e) {
        throw new UnableToPrintException(getMessage("zl.registration.patient.idcard.locationNotAssociatedWithMedicalRecordLocation", location.getName()));
    }
    Printer printer = printerService.getDefaultPrinter(location, PrinterType.ID_CARD);
    if (printer == null) {
        throw new UnableToPrintException(getMessage("zl.registration.patient.idcard.noPrinterConfiguredForLocation", location.getName()));
    }
    DateFormat df = new SimpleDateFormat("dd MMM yyyy", Context.getLocale());
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("name", getName(patient));
    paramMap.put("patientIdentifier", getIdentifier(patient));
    paramMap.put("gender", patient.getGender());
    paramMap.put("birthdate", df.format(patient.getBirthdate()));
    paramMap.put("birthdateEstimated", patient.getBirthdateEstimated());
    paramMap.put("issuingLocation", getIssuingLocationName(issuingLocation));
    paramMap.put("issuedDate", df.format(new Date()));
    paramMap.put("telephoneNumber", getTelephoneNumber(patient));
    paramMap.put("customCardLabel", config.getIdCardLabel());
    paramMap.put("addressLines", getAddressLines(patient));
    paramMap.put("locale", config.getIdCardLocale());
    // but if it is a GX430t, it's just a simple socket print with raw ZPL code, so we need to generate the data using the label template
    if (printer.getModel().getPrintHandler().equals("gx430tPrintHandler")) {
        ZplCardTemplate zlCardTemplate = Context.getRegisteredComponent("zplCardTemplate", ZplCardTemplate.class);
        paramMap.put("data", zlCardTemplate.generateLabel(paramMap));
        paramMap.put("encoding", zlCardTemplate.getEncoding());
        paramMap.put("wait", 500);
    }
    printerService.print(paramMap, printer, false);
}
Also used : HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IdPrinter(org.openmrs.module.pihcore.printer.IdPrinter) Printer(org.openmrs.module.printer.Printer) SimpleDateFormat(java.text.SimpleDateFormat) ZplCardTemplate(org.openmrs.module.pihcore.printer.template.ZplCardTemplate) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException) Date(java.util.Date) Location(org.openmrs.Location)

Example 10 with Printer

use of org.openmrs.module.printer.Printer in project openmrs-module-pihcore by PIH.

the class ZplLabLabelTemplateTest method shouldPrintToPrinter.

@Test
// just used to print against a test printer when one is on the network
@Ignore
public void shouldPrintToPrinter() throws Exception {
    Patient patient = new Patient();
    PersonName name = new PersonName();
    name.setGivenName("Mark");
    name.setFamilyName("Goodrich");
    patient.addName(name);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("YXB123");
    patientIdentifier.setIdentifierType(primaryIdentifierType);
    patient.addIdentifier(patientIdentifier);
    String data = template.generateLabel(patient);
    Printer printer = new Printer();
    printer.setIpAddress("10.10.216.207");
    printer.setPort("9100");
    printer.setId(1);
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("data", data);
    paramMap.put("encoding", "UTF-8");
    new PrinterServiceImpl().print(paramMap, printer, false, new SocketPrintHandler());
}
Also used : PersonName(org.openmrs.PersonName) HashMap(java.util.HashMap) Patient(org.openmrs.Patient) Printer(org.openmrs.module.printer.Printer) PrinterServiceImpl(org.openmrs.module.printer.PrinterServiceImpl) PatientIdentifier(org.openmrs.PatientIdentifier) SocketPrintHandler(org.openmrs.module.printer.handler.SocketPrintHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Printer (org.openmrs.module.printer.Printer)11 Test (org.junit.Test)5 Location (org.openmrs.Location)5 HashMap (java.util.HashMap)4 Patient (org.openmrs.Patient)4 Ignore (org.junit.Ignore)3 PrinterServiceImpl (org.openmrs.module.printer.PrinterServiceImpl)3 UnableToPrintException (org.openmrs.module.printer.UnableToPrintException)3 UnableToPrintViaSocketException (org.openmrs.module.printer.UnableToPrintViaSocketException)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 PatientIdentifierType (org.openmrs.PatientIdentifierType)2 PatientBuilder (org.openmrs.contrib.testdata.builder.PatientBuilder)2 PrinterModel (org.openmrs.module.printer.PrinterModel)2 PatientIdentifier (org.openmrs.PatientIdentifier)1 PersonAttributeType (org.openmrs.PersonAttributeType)1 PersonName (org.openmrs.PersonName)1 ZplCardTemplate (org.openmrs.module.mirebalais.printer.template.ZplCardTemplate)1 DefaultZplPaperFormLabelTemplate (org.openmrs.module.paperrecord.template.DefaultZplPaperFormLabelTemplate)1