Fix logo and address not showing in Sticker#3
Conversation
|
Don't we already have the openmrs logo in core? |
...ain/java/org/openmrs/module/patientdocuments/renderer/PatientIdStickerXmlReportRenderer.java
Outdated
Show resolved
Hide resolved
...ain/java/org/openmrs/module/patientdocuments/renderer/PatientIdStickerXmlReportRenderer.java
Outdated
Show resolved
Hide resolved
|
hello @ibacher and @dkayiwa I have improved logic to;
|
| } | ||
| } | ||
|
|
||
| private void loadAndCacheDefaultLogo(ServletContext servletContext) { |
There was a problem hiding this comment.
@dkayiwa since we can only get the default logo using the servlet context, yet we need to use it from the API, I thought it’s better saving it for better performance.
There was a problem hiding this comment.
What was the performance difference?
There was a problem hiding this comment.
@dkayiwa , the logo needs to be accessed for every patient document generated. In a busy hospital setting with potentially hundreds of patients per day, repeatedly reading from the servlet context for each document would mean hundreds of I/O operations daily for the same 8KB file. Caching it once to the application data directory eliminates this repeated overhead. The servlet context resource stream needs to be opened and closed on each access, whereas with caching, we read once and reuse. I've also added a check to ensure we only cache if the file doesn't already exist.
There was a problem hiding this comment.
Are you caching it in memory such that you do not do any further I/O on disk?
There was a problem hiding this comment.
@dkayiwa, good point. I've removed the caching mechanism entirely as it was adding unnecessary disk I/O and complexity without clear performance benefits.
The logo is now loaded directly from the servlet context and embedded as a base64 data URI in the XML output.
|
|
||
| The optional header section can contain: | ||
| - An organizational logo on the left (loaded from HTTP URL) | ||
| - An organizational logo on the left (from a file path under `OPENMRS_APPLICATION_DATA_DIRECTORY`) |
There was a problem hiding this comment.
Yes it is. We get the custom logo like new File(OpenmrsUtil.getDirectoryInApplicationDataDirectory(""), logoUrlPath)
...ain/java/org/openmrs/module/patientdocuments/renderer/PatientIdStickerXmlReportRenderer.java
Outdated
Show resolved
Hide resolved
| // 2. Fall back to default logo | ||
| if (isBlank(logoPath) && defaultLogoBytes != null && defaultLogoBytes.length > 0) { | ||
| String base64Image = Base64.getEncoder().encodeToString(defaultLogoBytes); | ||
| logoPath = "data:image/png;base64," + base64Image; |
There was a problem hiding this comment.
What happens when the logo is not a png?
There was a problem hiding this comment.
Thank you @dkayiwa. This is the default fallback logo, which we hardcoded to a PNG file at DEFAULT_LOGO_CLASSPATH = "/images/openmrs_logo_white_large.png"
Are we expecting the default logo format to change from PNG to something else? If so, I can make this more dynamic, but otherwise the hardcoded MIME type should match the hardcoded PNG file.
There was a problem hiding this comment.
What happens when someone's config has a JPG?
There was a problem hiding this comment.
The user-supplied logo will be retrieved using its absolute path (step 1 in configureLogo()) before falling back to the default logo. So if someone configures a JPG in their report.patientIdSticker.logourl setting, the absolute file path to that JPG will be used directly. The MIME type image/png only applies to our hardcoded default fallback logo (openmrs_logo_white_large.png), not to user-supplied images.
...ain/java/org/openmrs/module/patientdocuments/renderer/PatientIdStickerXmlReportRenderer.java
Outdated
Show resolved
Hide resolved
| 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()) { |
There was a problem hiding this comment.
Is this also related to the logo?
There was a problem hiding this comment.
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.
...mrs/module/patientdocuments/web/rest/controller/PatientIdStickerDataPdfExportController.java
Outdated
Show resolved
Hide resolved
...mrs/module/patientdocuments/web/rest/controller/PatientIdStickerDataPdfExportController.java
Outdated
Show resolved
Hide resolved
| // Create and append logo elements | ||
| Element branding = doc.createElement("branding"); | ||
| Element image = doc.createElement("logo"); | ||
| image.setTextContent(logoPath); |
There was a problem hiding this comment.
What is displayed for the image when logoPath is an empty string?
There was a problem hiding this comment.
I have conditionally added logo creation.
|
Is the pull request description still valid? |
I have revised the pull request description and believe it now provides a more comprehensive and accurate representation of the changes. |
|
@jnsereko though i have merged this, i would like us to limit this to only locations in the application data directory. Can you deal with the security safeguards against path traversal or unintended file reads? |
Thank you @dkayiwa! |
Description
This PR addresses two issues:
Logo not displaying
The logo could not be pulled from other modules using relative paths with Docker (e.g.,
moduleResources/legacyui/images/openmrs_logo_white_large.pngormoduleResources/legacyui/openmrs_logo_white_large.pngSolution: Added ability to supply a custom logo resolved under
OPENMRS_APPLICATION_DATA_DIRECTORY(e.g.,/openmrs/data/my_custom_logo.png) and as a fall back, an OpenMRS logo pulled from the servlet context ie/images/openmrs_logo_white_large.pngAddress not showing
The Address object from the patient object was being accessed with the wrong property name
Solution: Corrected the property name to properly retrieve patient address information
Screenshot
Related issue
https://openmrs.atlassian.net/browse/O3-5123