Search in sources :

Example 1 with ZplCardTemplate

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

Aggregations

DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Location (org.openmrs.Location)1 IdPrinter (org.openmrs.module.pihcore.printer.IdPrinter)1 ZplCardTemplate (org.openmrs.module.pihcore.printer.template.ZplCardTemplate)1 Printer (org.openmrs.module.printer.Printer)1 UnableToPrintException (org.openmrs.module.printer.UnableToPrintException)1