Skip to content
Open
Changes from all commits
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 @@ -2423,21 +2423,40 @@ private void deleteDirectory(Path path) throws IOException {
}

private boolean validateCPHLBarCode(String accessionNumber) {
Integer minimumCPHLBarCodeLength = Integer.parseInt(Context.getAdministrationService().getGlobalProperty("ugandaemrsync.minimumCPHLBarCodeLength"));
if (accessionNumber == null || accessionNumber.length() < minimumCPHLBarCodeLength) {
if (accessionNumber == null || accessionNumber.trim().isEmpty()) {
return false;
}
accessionNumber = accessionNumber.trim();

int minimumCPHLBarCodeLength = 10;
try {
String gpValue = Context.getAdministrationService()
.getGlobalProperty("ugandaemrsync.minimumCPHLBarCodeLength");
if (gpValue != null) {
minimumCPHLBarCodeLength = Integer.parseInt(gpValue);
}
} catch (NumberFormatException ignored) {
log.error(ignored);
}

if (accessionNumber.length() < minimumCPHLBarCodeLength || accessionNumber.length() < 2) {
return false;
}

int currentYearSuffix = Year.now().getValue() % 100;
int previousYearSuffix = (currentYearSuffix == 0) ? 99 : currentYearSuffix - 1;

int prefix;
try {
int prefix = Integer.parseInt(accessionNumber.substring(0, 2));
return prefix == currentYearSuffix || prefix == (currentYearSuffix - 1);
prefix = Integer.parseInt(accessionNumber.substring(0, 2));
} catch (NumberFormatException e) {
return false;
}

return prefix == currentYearSuffix || prefix == previousYearSuffix;
}


private boolean accessionNumberAlreadyUsed(String accessionNumber) {
// Escape single quotes to prevent SQL injection or errors
String safeAccessionNumber = accessionNumber.replace("'", "''");
Expand Down