Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -46,6 +49,7 @@
import org.openmrs.module.reporting.report.renderer.RenderingException;
import org.openmrs.module.reporting.report.renderer.ReportDesignRenderer;
import org.openmrs.module.reporting.report.renderer.ReportRenderer;
import org.openmrs.util.OpenmrsClassLoader;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -239,16 +243,24 @@ private void configureHeader(Document doc, Element templatePIDElement) {
}

private void configureLogo(Document doc, Element header, String logoUrlPath) {
String logoPath;
String logoPath = "";
File logoFile = new File(logoUrlPath);
boolean isValidFile = logoFile.exists() && logoFile.canRead() && logoFile.isAbsolute();

if (isValidFile) {
logoPath = logoFile.getAbsolutePath();
} else {
throw new RenderingException("Logo file not found or not accessible: " + logoUrlPath);
try {
URL res = OpenmrsClassLoader.getInstance().getResource(logoUrlPath);

if (res != null) {
logoPath = Paths.get(res.toURI()).toString();
}
}
catch (URISyntaxException e) {
throw new RenderingException("Logo file not found or not accessible: " + logoUrlPath);
}
}

Element branding = doc.createElement("branding");
Element image = doc.createElement("logo");
image.setTextContent(logoPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is displayed for the image when logoPath is an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have conditionally added logo creation.

Expand Down Expand Up @@ -365,15 +377,16 @@ && shouldIncludeColumn("patientdocuments.patientIdSticker.fields.secondaryIdenti

// Process address
if (shouldIncludeColumn("patientdocuments.patientIdSticker.fields.fulladdress")) {
Map<String, String> addressData = (Map<String, String>) patientData.get("preferredAddress");
if (addressData != null) {
List<Map<String, String>> addressData = (List<Map<String, String>>) patientData.get("addresses");
if (addressData != null && !addressData.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also related to the logo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! This ensures that the address data is pulled from the right variable in the Patient Data object.
Since its a single line of change and related to intended field field not showing, i thought its better merging the work with the logo not showing.

Map<String, String> preferredAddress = addressData.get(0);
StringBuilder address = new StringBuilder();
appendIfNotNull(address, addressData.get("address1"));
appendIfNotNull(address, addressData.get("address2"));
appendIfNotNull(address, addressData.get("cityVillage"));
appendIfNotNull(address, addressData.get("stateProvince"));
appendIfNotNull(address, addressData.get("country"));
appendIfNotNull(address, addressData.get("postalCode"));
appendIfNotNull(address, preferredAddress.get("address1"));
appendIfNotNull(address, preferredAddress.get("address2"));
appendIfNotNull(address, preferredAddress.get("cityVillage"));
appendIfNotNull(address, preferredAddress.get("stateProvince"));
appendIfNotNull(address, preferredAddress.get("country"));
appendIfNotNull(address, preferredAddress.get("postalCode"));

if (address.length() > 0) {
addField(doc, fields, addressKey, address.toString().trim());
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/resources/msfStickerFopStylesheet.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<fo:layout-master-set>
<fo:simple-page-master master-name="sticker"
page-width="{$sticker-width}" page-height="{$sticker-height}"
margin="1.5mm">
margin="3mm">
<fo:region-body margin="0"/>
</fo:simple-page-master>
</fo:layout-master-set>
Expand Down Expand Up @@ -227,7 +227,7 @@
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="fields/field[@label = $patientIdKey]/@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="fields/field[@label = $patientIdKey]"/>
</fo:block>
</fo:block-container>
Expand All @@ -238,7 +238,7 @@
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="fields/field[@label = $patientNameKey]/@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="fields/field[@label = $patientNameKey]"/>
</fo:block>
</fo:block-container>
Expand All @@ -255,7 +255,7 @@
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="."/>
</fo:block>
</fo:block-container>
Expand Down
34 changes: 22 additions & 12 deletions api/src/main/resources/patientIdStickerFopStylesheet.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Attribute for dynamic page height and width -->
<xsl:variable name="sticker-height" select="/patientIdStickers/@sticker-height"/>
<xsl:variable name="sticker-width" select="/patientIdStickers/@sticker-width"/>

<!-- Calculate effective body height (page height minus margins) -->
<xsl:variable name="body-height" select="concat(number(substring-before($sticker-height, 'mm')) - 4, 'mm')"/>
<xsl:variable name="body-height-value" select="number(substring-before($sticker-height, 'mm')) - 4"/>
Expand Down Expand Up @@ -80,7 +80,7 @@
<fo:layout-master-set>
<fo:simple-page-master master-name="sticker"
page-width="{$sticker-width}" page-height="{$sticker-height}"
margin="1.5mm">
margin="3mm">
<fo:region-body margin="0"/>
</fo:simple-page-master>
</fo:layout-master-set>
Expand Down Expand Up @@ -211,6 +211,17 @@

<!-- Main data section -->
<fo:block-container height="{$table-height}" display-align="before">
<xsl:if test="fields/field[@label = $patientSecondaryIdKey]">
<fo:block-container margin-bottom="{$field-vertical-gap}">
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="fields/field[@label = $patientSecondaryIdKey]/@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="fields/field[@label = $patientSecondaryIdKey]"/>
</fo:block>
</fo:block-container>
</xsl:if>

<xsl:if test="fields/field[@label = $patientIdKey]">
<fo:block-container margin-bottom="{$field-vertical-gap}">
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
Expand All @@ -235,17 +246,16 @@

<xsl:for-each select="fields/field[
@label != $patientNameKey and
@label != $patientSecondaryIdKey and
@label != $patientIdKey]">
<xsl:if test="not(preceding-sibling::field[@label = current()/@label])">
<fo:block-container margin-bottom="{$field-vertical-gap}">
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="."/>
</fo:block>
</fo:block-container>
</xsl:if>
<fo:block-container margin-bottom="{$field-vertical-gap}">
<fo:block font-size="{$label-font-size}pt" font-weight="normal" font-family="{$label-font-family}" color="#444444">
<xsl:value-of select="@label"/>
</fo:block>
<fo:block font-size="{$title-font-size}pt" font-weight="bold" font-family="{$value-font-family}" margin-top="0.2mm">
<xsl:value-of select="."/>
</fo:block>
</fo:block-container>
</xsl:for-each>
</fo:block-container>
</fo:block-container>
Expand Down
5 changes: 5 additions & 0 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
<include>**/*.xml</include>
</includes>
</testResource>
<testResource>
<directory>../omod/src/main/webapp/resources</directory>
<targetPath>web/module/resources/</targetPath>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
Expand Down
Binary file added omod/src/main/webapp/resources/OpenMRS_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.