Skip to content

Commit

Permalink
updated message template and other feedback comments
Browse files Browse the repository at this point in the history
  • Loading branch information
manimaarans committed Nov 15, 2023
1 parent c3c33fa commit 7b9f28b
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.io.FileReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -73,9 +72,9 @@ public class SnomedMedicationDefinedDailyDoseService {
public static final String INFO = "info";
private static final String NEW_LINE = "\n";
private static final String HIGH_DOSAGE_ALERT_TYPE = "High Dosage";
private static final String DOSAGE_EXCEPTION_ALERT_TYPE = "Dosage Exception";
private static final String DOSAGE_EXCEPTION_DOSE_INPUT = "Dose Inputs";
private static final String DOSAGE_EXCEPTION_ROUTE_INPUT = "Dose Route";
private static final String INVALID_DOSAGE_ALERT_TYPE = "Validation Error";
private static final String DOSAGE_EXCEPTION_DOSE_INPUT = "dose unit";
private static final String DOSAGE_EXCEPTION_ROUTE_INPUT = "dose route";

@Autowired
private FHIRTerminologyServerClient tsClient;
Expand Down Expand Up @@ -150,16 +149,18 @@ public List<CDSCard> checkMedications(List<MedicationRequest> medicationRequests
Optional<Coding> snomedMedication = codingList.stream().filter(coding -> SNOMEDCT_SYSTEM.equals(coding.getSystem())).findFirst();
if (snomedMedication.isPresent()) {
String snomedMedicationCode = snomedMedication.get().getCode();
String snomedMedicationLabel = snomedMedication.get().getDisplay();if ("NA".equals(doseQuantity.getUnit())) {
String snomedMedicationLabel = snomedMedication.get().getDisplay();
if ("NA".equals(doseQuantity.getUnit())) {
logger.debug("Prescribed dosage could not be validated for {}. Reason: Dose unit unknown to CDSS.", snomedMedicationLabel);
continue;
}
ConceptParameters conceptParameters = null;
try {
conceptParameters = tsClient.lookup(SNOMEDCT_SYSTEM, snomedMedicationCode);
} catch (Exception e) {
logger.error("");
throw new ResponseStatusException(HttpStatus.PRECONDITION_FAILED, String.format("Bahmni->SNOMED mapping is misconfigured for medication %s.", snomedMedicationLabel), null);
String errorMessage = String.format("Bahmni->SNOMED mapping is misconfigured for medication %s.", snomedMedicationLabel);
logger.error(errorMessage);
throw new ResponseStatusException(HttpStatus.PRECONDITION_FAILED, errorMessage, null);
}
if (conceptParameters == null) {
logger.debug("No SNOMED concept found for code {}, ignoring.", snomedMedicationCode);
Expand Down Expand Up @@ -188,9 +189,10 @@ public List<CDSCard> checkMedications(List<MedicationRequest> medicationRequests
logger.info("SNOMED dose form {} is not covered by the route of administration dynamic map, skipping", manufacturedDoseForm);
continue;
}
if (!dosage.getRoute().getText().equals(atcRouteOfAdministrationCode)) {
logger.info("");
composeCdssCardForDosageMismatch(cards, snomedMedicationLabel, codingList, atcRouteOfAdministrationCode, false);
if (!(dosage.getRoute() != null && atcRouteOfAdministrationCode.equals(dosage.getRoute().getText()))) {
String expectedUnit = atcRouteOfAdministrationCode + (routeOfAdministrationLabel.equals(atcRouteOfAdministrationCode) ? "" : " (" + routeOfAdministrationLabel.trim() + ")" );
logger.info("Expected route {} for medication {}", expectedUnit, snomedMedicationLabel);
composeCdssCardForDosageMismatch(cards, snomedMedicationLabel, codingList, expectedUnit, false);
continue;
}
aggregateMedicationsBySubstance(aggregatedMedicationsBySubstanceMap, prescribedDailyDose, codingList, snomedMedicationLabel, atcRouteOfAdministrationCode, routeOfAdministrationLabel, normalForm, cards);
Expand Down Expand Up @@ -327,11 +329,11 @@ private void composeCdssCardForDosageMismatch(List<CDSCard> cards, String medica
UUID randomUuid = UUID.fromString(UUID.nameUUIDFromBytes(medicationLabel.getBytes()).toString());
String invalidMessage = isDoseUnit ? DOSAGE_EXCEPTION_DOSE_INPUT : DOSAGE_EXCEPTION_ROUTE_INPUT;
Optional<CDSCard> optionalCard = cards.stream().filter(cdsCard -> cdsCard.getUuid().equals(randomUuid.toString())).findFirst();
String cardDetailMsg = "%s found invalid. Expected %s for %s";
cardDetailMsg = new UnorderedListItem(String.format(cardDetailMsg, invalidMessage, expectedUnit, medicationLabel)).toString();
String cardSummaryMessage = "Invalid Dose";
String cardDetailMsg = "Expected %s for %s";
cardDetailMsg = new UnorderedListItem(String.format(cardDetailMsg, expectedUnit, invalidMessage)).toString();
String cardSummaryMessage = String.format("One or more dose Inputs are invalid for %s", medicationLabel);
if(optionalCard.isEmpty()) {
CDSCard cdsCard = new CDSCard(randomUuid.toString(), cardSummaryMessage, cardSummaryMessage + NEW_LINE + cardDetailMsg, CDSIndicator.valueOf(WARNING), new CDSSource("DummyService", null), Collections.singletonList(new CDSReference(getCodings(codingList))), null, DOSAGE_EXCEPTION_ALERT_TYPE);
CDSCard cdsCard = new CDSCard(randomUuid.toString(), cardSummaryMessage, NEW_LINE + cardDetailMsg, CDSIndicator.valueOf(WARNING), new CDSSource("DummyService", null), Collections.singletonList(new CDSReference(getCodings(codingList))), null, INVALID_DOSAGE_ALERT_TYPE);
cards.add(cdsCard);
return;
}
Expand Down

0 comments on commit 7b9f28b

Please sign in to comment.