Skip to content

Commit

Permalink
BAH-2833 | Fix. Handle Error Due To Empty Document Size Limit In Bahm…
Browse files Browse the repository at this point in the history
…ni Standard (#259)
  • Loading branch information
parvathy00 authored Apr 4, 2024
1 parent 0b4ce7d commit 3645144
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ public ResponseEntity<HashMap<String, Object>> saveDocument(@RequestBody Documen
HashMap<String, Object> savedDocument = new HashMap<>();
Patient patient = Context.getPatientService().getPatientByUuid(document.getPatientUuid());
String encounterTypeName = document.getEncounterTypeName();
Long maxDocumentSizeMb = Long.parseLong(System.getenv("DOCUMENT_MAX_SIZE_MB"));
Long maxDocumentSizeBytes = maxDocumentSizeMb * 1024 * 1024;
String maxDocumentSize = System.getenv("DOCUMENT_MAX_SIZE_MB");

if (StringUtils.isEmpty(encounterTypeName)) {
encounterTypeName = administrationService.getGlobalProperty("bahmni.encounterType.default");
}
String fileName = sanitizeFileName(document.getFileName());
Paths.get(fileName);

if (document.getContent().length() > maxDocumentSizeBytes) {
logger.warn("Uploaded document size is greater than the maximum size " + maxDocumentSizeMb + "MB");
savedDocument.put("maxDocumentSizeMB", maxDocumentSizeMb);
return new ResponseEntity<>(savedDocument, HttpStatus.PAYLOAD_TOO_LARGE);
if (!StringUtils.isEmpty(maxDocumentSize)) {
Long maxDocumentSizeMb = Long.parseLong(maxDocumentSize);
Long maxDocumentSizeBytes = maxDocumentSizeMb * 1024 * 1024;
if (document.getContent().length() > maxDocumentSizeBytes) {
logger.warn("Uploaded document size is greater than the maximum size " + maxDocumentSizeMb + "MB");
savedDocument.put("maxDocumentSizeMB", maxDocumentSizeMb);
return new ResponseEntity<>(savedDocument, HttpStatus.PAYLOAD_TOO_LARGE);
}
}
// Old files will follow: patientid-encounterName-uuid.ext (eg. 6-Patient-Document-706a448b-3f10-11e4-adec-0800271c1b75.png)
// New ones will follow: patientid_encounterName_uuid__filename.ext (eg. 6-Patient-Document-706a448b-3f10-11e4-adec-0800271c1b75__doc1.png)
Expand Down

0 comments on commit 3645144

Please sign in to comment.