-
Notifications
You must be signed in to change notification settings - Fork 4k
TRUNK-6442: ObsValidator should allow user-supplied reference ranges #5392
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
Open
ibacher
wants to merge
1
commit into
master
Choose a base branch
from
TRUNK-6442
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,10 @@ | |
| package org.openmrs.validator; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| import org.apache.commons.text.StringEscapeUtils; | ||
| import org.openmrs.BaseReferenceRange; | ||
| import org.openmrs.Concept; | ||
| import org.openmrs.ConceptDatatype; | ||
| import org.openmrs.ConceptNumeric; | ||
|
|
@@ -27,7 +25,6 @@ | |
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.api.db.hibernate.HibernateUtil; | ||
| import org.openmrs.util.ConceptReferenceRangeUtility; | ||
| import org.openmrs.util.OpenmrsUtil; | ||
| import org.springframework.validation.Errors; | ||
| import org.springframework.validation.Validator; | ||
|
|
||
|
|
@@ -198,7 +195,7 @@ else if (!isObsGroup) { | |
| } | ||
| } | ||
|
|
||
| validateConceptReferenceRange(obs, errors, atRootNode); | ||
| validateReferenceRange(obs, errors, atRootNode); | ||
| } else if (dt.isText() && obs.getValueText() == null) { | ||
| if (atRootNode) { | ||
| errors.rejectValue("valueText", "error.null"); | ||
|
|
@@ -259,18 +256,22 @@ else if (!isObsGroup) { | |
| * @param obs Observation to validate | ||
| * @param errors Errors to record validation issues | ||
| */ | ||
| private void validateConceptReferenceRange(Obs obs, Errors errors, boolean atRootNode) { | ||
| ConceptReferenceRange conceptReferenceRange = getReferenceRange(obs); | ||
| private void validateReferenceRange(Obs obs, Errors errors, boolean atRootNode) { | ||
| BaseReferenceRange referenceRange = obs.getReferenceRange(); | ||
| if (referenceRange == null) { | ||
| referenceRange = getReferenceRange(obs); | ||
| } | ||
|
|
||
| if (conceptReferenceRange != null) { | ||
| validateAbsoluteRanges(obs, conceptReferenceRange, errors, atRootNode); | ||
| if (referenceRange != null) { | ||
| validateAbsoluteRanges(obs, referenceRange, errors, atRootNode); | ||
|
|
||
| if (obs.getId() == null) { | ||
| setObsReferenceRange(obs, conceptReferenceRange); | ||
| setObsReferenceRange(obs, referenceRange); | ||
| } | ||
| } else if (obs.getId() == null) { | ||
| setObsReferenceRange(obs); | ||
| } | ||
|
|
||
| setObsInterpretation(obs); | ||
| } | ||
|
|
||
|
|
@@ -410,16 +411,16 @@ private ConceptReferenceRange findStrictestReferenceRange(List<ConceptReferenceR | |
| * Validates the high and low absolute values of the Obs. | ||
| * | ||
| * @param obs Observation to validate | ||
| * @param conceptReferenceRange ConceptReferenceRange containing the range values | ||
| * @param referenceRange ConceptReferenceRange containing the range values | ||
| * @param errors Errors to record validation issues | ||
| */ | ||
| private void validateAbsoluteRanges(Obs obs, ConceptReferenceRange conceptReferenceRange, Errors errors, boolean atRootNode) { | ||
| if (conceptReferenceRange.getHiAbsolute() != null && conceptReferenceRange.getHiAbsolute() < obs.getValueNumeric()) { | ||
| private void validateAbsoluteRanges(Obs obs, BaseReferenceRange referenceRange, Errors errors, boolean atRootNode) { | ||
| if (referenceRange.getHiAbsolute() != null && referenceRange.getHiAbsolute() < obs.getValueNumeric()) { | ||
| if (atRootNode) { | ||
| errors.rejectValue( | ||
| "valueNumeric", | ||
| "error.value.outOfRange.high", | ||
| new Object[] { conceptReferenceRange.getHiAbsolute() }, | ||
| new Object[] { referenceRange.getHiAbsolute() }, | ||
| null | ||
| ); | ||
| } else { | ||
|
|
@@ -432,12 +433,12 @@ private void validateAbsoluteRanges(Obs obs, ConceptReferenceRange conceptRefere | |
| } | ||
| } | ||
|
|
||
| if (conceptReferenceRange.getLowAbsolute() != null && conceptReferenceRange.getLowAbsolute() > obs.getValueNumeric()) { | ||
| if (referenceRange.getLowAbsolute() != null && referenceRange.getLowAbsolute() > obs.getValueNumeric()) { | ||
| if (atRootNode) { | ||
| errors.rejectValue( | ||
| "valueNumeric", | ||
| "error.value.outOfRange.low", | ||
| new Object[] { conceptReferenceRange.getLowAbsolute() }, | ||
| new Object[] { referenceRange.getLowAbsolute() }, | ||
| null | ||
| ); | ||
| } else { | ||
|
|
@@ -455,20 +456,23 @@ private void validateAbsoluteRanges(Obs obs, ConceptReferenceRange conceptRefere | |
| * Builds and sets the ObsReferenceRange for the given Obs. | ||
| * | ||
| * @param obs Observation to set the reference range | ||
| * @param conceptReferenceRange ConceptReferenceRange used to build the ObsReferenceRange | ||
| * @param referenceRange ConceptReferenceRange used to build the ObsReferenceRange | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intend to replace |
||
| */ | ||
| private void setObsReferenceRange(Obs obs, ConceptReferenceRange conceptReferenceRange) { | ||
| ObsReferenceRange obsRefRange = new ObsReferenceRange(); | ||
|
|
||
| obsRefRange.setHiAbsolute(conceptReferenceRange.getHiAbsolute()); | ||
| obsRefRange.setHiCritical(conceptReferenceRange.getHiCritical()); | ||
| obsRefRange.setHiNormal(conceptReferenceRange.getHiNormal()); | ||
| obsRefRange.setLowAbsolute(conceptReferenceRange.getLowAbsolute()); | ||
| obsRefRange.setLowCritical(conceptReferenceRange.getLowCritical()); | ||
| obsRefRange.setLowNormal(conceptReferenceRange.getLowNormal()); | ||
| obsRefRange.setObs(obs); | ||
|
|
||
| obs.setReferenceRange(obsRefRange); | ||
| private void setObsReferenceRange(Obs obs, BaseReferenceRange referenceRange) { | ||
| if (referenceRange instanceof ObsReferenceRange) { | ||
| if (((ObsReferenceRange) referenceRange).getObs() == null) { | ||
| obs.setReferenceRange((ObsReferenceRange) referenceRange); | ||
| } | ||
| } else { | ||
| ObsReferenceRange obsRefRange = new ObsReferenceRange(); | ||
| obsRefRange.setHiAbsolute(referenceRange.getHiAbsolute()); | ||
| obsRefRange.setHiCritical(referenceRange.getHiCritical()); | ||
| obsRefRange.setHiNormal(referenceRange.getHiNormal()); | ||
| obsRefRange.setLowAbsolute(referenceRange.getLowAbsolute()); | ||
| obsRefRange.setLowCritical(referenceRange.getLowCritical()); | ||
| obsRefRange.setLowNormal(referenceRange.getLowNormal()); | ||
| obs.setReferenceRange(obsRefRange); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -479,33 +483,37 @@ private void setObsReferenceRange(Obs obs, ConceptReferenceRange conceptReferenc | |
| private void setObsReferenceRange(Obs obs) { | ||
| if (obs.getConcept() == null) { | ||
| return; | ||
| } else if (obs.getReferenceRange() != null) { | ||
| return; | ||
| } | ||
|
|
||
| ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(obs.getConcept().getId()); | ||
|
|
||
| if (conceptNumeric != null) { | ||
| ObsReferenceRange obsRefRange = new ObsReferenceRange(); | ||
|
|
||
| obsRefRange.setHiAbsolute(conceptNumeric.getHiAbsolute()); | ||
| obsRefRange.setHiCritical(conceptNumeric.getHiCritical()); | ||
| obsRefRange.setHiNormal(conceptNumeric.getHiNormal()); | ||
| obsRefRange.setLowAbsolute(conceptNumeric.getLowAbsolute()); | ||
| obsRefRange.setLowCritical(conceptNumeric.getLowCritical()); | ||
| obsRefRange.setLowNormal(conceptNumeric.getLowNormal()); | ||
| obsRefRange.setObs(obs); | ||
|
|
||
| obs.setReferenceRange(obsRefRange); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * This method sets Obs interpretation based on the current obs' numeric value. | ||
| * | ||
| * @param obs Observation to set the interpretation | ||
| */ | ||
| private void setObsInterpretation(Obs obs) { | ||
| if (obs.getInterpretation() != null || obs.getValueNumeric() == null) { | ||
| return; | ||
| } | ||
|
|
||
| ObsReferenceRange referenceRange = obs.getReferenceRange(); | ||
| if (referenceRange == null || obs.getValueNumeric() == null) { | ||
| if (referenceRange == null) { | ||
| return; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to replace
ConceptReferenceRangewith maybeBaseReferenceRange?