Skip to content

Commit

Permalink
Merge pull request #327 from ojwanganto/add-facility-name-to-manifest…
Browse files Browse the repository at this point in the history
…-label

Add facility name to the printed specimen label
  • Loading branch information
patryllus authored Nov 27, 2024
2 parents b1babaa + 1ac027f commit c90a917
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
import org.apache.commons.lang.WordUtils;
import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -37,6 +38,9 @@ public File downloadSpecimenLabel() throws Exception {
).concat(" ").concat(
patient.getMiddleName() != null ? order.getOrder().getPatient().getMiddleName() : ""
);
Location orderLocation = order.getOrder().getEncounter().getLocation() != null ? order.getOrder().getEncounter().getLocation() : Utils.getDefaultLocation();// we default to the default location if the order has no location
String facilityName = orderLocation.getName();

AdministrationService administrationService = Context.getAdministrationService();
final String isKDoD = (administrationService.getGlobalProperty("kenyaemr.isKDoD"));

Expand All @@ -59,19 +63,19 @@ public File downloadSpecimenLabel() throws Exception {
String patientCCCNumber = patient.getPatientIdentifier(Utils.getUniquePatientNumberIdentifierType()) != null ? patient.getPatientIdentifier(Utils.getUniquePatientNumberIdentifierType()).getIdentifier() : "";
String patientKDODNumber = patient.getPatientIdentifier(Utils.getKDODIdentifierType()) != null ? patient.getPatientIdentifier(Utils.getKDODIdentifierType()).getIdentifier() : "";

Text nameLabel = new Text(WordUtils.capitalizeFully(fullName));
Text cccNoLabel = new Text("");
Text sampleFacilityDetails = new Text(facilityName);
Text patientIdentifierLabel = new Text("");
if(isKDoD.trim().equalsIgnoreCase("true")) {
cccNoLabel = new Text(patientKDODNumber);
patientIdentifierLabel = new Text(patientKDODNumber);
} else {
cccNoLabel = new Text(patientCCCNumber);
patientIdentifierLabel = new Text(patientCCCNumber);
}
Text specimenDateLabel = new Text(Utils.getSimpleDateFormat("dd/MM/yyyy").format(order.getOrder().getDateActivated()));

Paragraph paragraph = new Paragraph();
paragraph.setFontSize(7);
paragraph.add(cccNoLabel).add("\n"); // patient ccc/kdod number
paragraph.add(nameLabel).add("\n"); // patient name
paragraph.setFontSize(6);
paragraph.add(patientIdentifierLabel).add("\n"); // patient ccc/kdod number
paragraph.add(sampleFacilityDetails).add("\n"); // sample facility details
paragraph.add(specimenDateLabel); // sample date

Barcode128 code128 = new Barcode128(pdfDoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,19 @@ public File generateReport(String dest) throws IOException {
File returnFile = File.createTempFile("labManifest", ".pdf");
FileOutputStream fos = new FileOutputStream(returnFile);

//Initialize PDF writer
PdfWriter writer = new PdfWriter(fos);


//Initialize PDF document
PdfDocument pdf = new PdfDocument(writer);

// The default page rotation is set to portrait in the custom event handler.
/*PageOrientationsEventHandler eventHandler = new PageOrientationsEventHandler();
pdf.addEventHandler(PdfDocumentEvent.START_PAGE, eventHandler);*/
//eventHandler.setOrientation(LANDSCAPE);

// Initialize document
Document document = new Document(pdf, PageSize.A4.rotate());


URL logoUrl = LabManifest.class.getClassLoader().getResource("img/moh.png");
// Compose Paragraph
Image logiImage = new Image(ImageDataFactory.create(logoUrl));
logiImage.scaleToFit(80, 80);
logiImage.setFixedPosition((PageSize.A4.rotate().getWidth() - logiImage.getImageScaledWidth()) /2, (PageSize.A4.rotate().getHeight() - logiImage.getImageScaledHeight()) - 40);

//logoSection.add(logiImage);


document.add(logiImage);
// Create a PdfFont
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont courier = PdfFontFactory.createFont(StandardFonts.COURIER_BOLD);
// Add a Paragraph

document.add(new Paragraph("\n"));
document.add(new Paragraph("\n"));
Expand Down

0 comments on commit c90a917

Please sign in to comment.