Search in sources :

Example 1 with PrinterModel

use of org.openmrs.module.printer.PrinterModel 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();
}
Also used : PatientBuilder(org.openmrs.contrib.testdata.builder.PatientBuilder) PrinterModel(org.openmrs.module.printer.PrinterModel) PersonAttributeType(org.openmrs.PersonAttributeType) Patient(org.openmrs.Patient) Printer(org.openmrs.module.printer.Printer) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with PrinterModel

use of org.openmrs.module.printer.PrinterModel 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)

Aggregations

Test (org.junit.Test)2 Location (org.openmrs.Location)2 Patient (org.openmrs.Patient)2 PatientIdentifierType (org.openmrs.PatientIdentifierType)2 PatientBuilder (org.openmrs.contrib.testdata.builder.PatientBuilder)2 Printer (org.openmrs.module.printer.Printer)2 PrinterModel (org.openmrs.module.printer.PrinterModel)2 PersonAttributeType (org.openmrs.PersonAttributeType)1 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1