Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-4029 | adding better logs in cases of outside range values or invalid values for coded answers #269

Merged
merged 2 commits into from
Jul 19, 2024
Merged
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 @@ -4,6 +4,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Concept;
import org.openmrs.ConceptNumeric;
import org.openmrs.Obs;
import org.openmrs.Order;
import org.openmrs.api.APIException;
Expand All @@ -14,13 +15,15 @@

import java.text.ParseException;
import java.util.Date;
import java.util.Optional;

import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Component
public class LabOrderResultMapper {
private static final Log log = LogFactory.getLog(LabOrderResultMapper.class);
private static final String EMPTY_STRING = "";
public static final String LAB_RESULT = "LAB_RESULT";
public static final String LAB_ABNORMAL = "LAB_ABNORMAL";
public static final String LAB_MINNORMAL = "LAB_MINNORMAL";
Expand Down Expand Up @@ -72,13 +75,14 @@ private Obs newResultObs(Order testOrder, Date obsDate, Concept concept, LabOrde
obs.setConcept(concept);
obs.setOrder(testOrder);
obs.setObsDatetime(obsDate);
String accessionUuid = Optional.ofNullable(labOrderResult.getAccessionUuid()).orElseGet(() -> Optional.ofNullable(obs.getOrder()).map(Order::getAccessionNumber).orElse(EMPTY_STRING));
if (concept.getDatatype().getHl7Abbreviation().equals("CWE")) {
String resultUuid = labOrderResult.getResultUuid();
Concept conceptAnswer = isEmpty(resultUuid) ? null : conceptService.getConceptByUuid(resultUuid);
obs.setValueCoded(conceptAnswer);
if (conceptAnswer == null) {
log.warn(String.format("Concept is not available in OpenMRS for ConceptUuid : [%s] , In Accession : [%s]"
, resultUuid,labOrderResult.getAccessionUuid()));
log.error(String.format("Concept [%s] does not not have coded answer with ConceptUuid [%s] in OpenMRS, In Accession [%s]",
obs.getConcept().getName(), resultUuid, accessionUuid));
return null;
}
return obs;
Expand All @@ -88,9 +92,28 @@ private Obs newResultObs(Order testOrder, Date obsDate, Concept concept, LabOrde
return null;
}
obs.setValueAsString(labOrderResult.getResult());
checkResultRangesForAbsolutes(obs, accessionUuid);
return obs;
}

/**
* This method just logs error if the results are out of absolute ranges. This will be errored out (ValidationException)
* by openmrs by the {@link org.openmrs.validator.ObsValidator} during save
*/
private void checkResultRangesForAbsolutes(Obs obs, String accessionUuid) {
if (obs.getConcept().isNumeric()) {
gsluthra marked this conversation as resolved.
Show resolved Hide resolved
if (obs.getValueNumeric() != null) {
ConceptNumeric cn = (ConceptNumeric) obs.getConcept();
gsluthra marked this conversation as resolved.
Show resolved Hide resolved
if (cn.getHiAbsolute() != null && cn.getHiAbsolute() < obs.getValueNumeric()) {
log.error(String.format("Test results for [%s] is beyond the absolute high range, in Accession [%s]", cn.getName(), accessionUuid));
}
if (cn.getLowAbsolute() != null && cn.getLowAbsolute() > obs.getValueNumeric()) {
log.error(String.format("Test results for [%s] is beyond the absolute low range, in Accession [%s]", cn.getName(), accessionUuid));
}
}
}
}

private Concept getConceptByName(String conceptName) {
return conceptService.getConceptByName(conceptName);
}
Expand Down
Loading