use of org.hl7.fhir.r5.model.Range in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromQnValue method getHPOforObservation.
@Override
public HpoTermId4LoincTest getHPOforObservation() throws ReferenceNotFoundException, AmbiguousReferenceException, UnrecognizedCodeException {
HpoTermId4LoincTest hpoTermId4LoincTest = null;
// find applicable reference range
List<Observation.ObservationReferenceRangeComponent> references = this.references.stream().filter(p -> withinAgeRange(p)).collect(Collectors.toList());
if (references.size() < 1) {
throw new ReferenceNotFoundException();
} else if (references.size() == 1) {
Observation.ObservationReferenceRangeComponent targetReference = references.get(0);
double low = targetReference.hasLow() ? targetReference.getLow().getValue().doubleValue() : Double.MIN_VALUE;
double high = targetReference.hasHigh() ? targetReference.getHigh().getValue().doubleValue() : Double.MAX_VALUE;
double observed = valueQuantity.getValue().doubleValue();
Loinc2HPOCodedValue result;
if (observed < low) {
result = Loinc2HPOCodedValue.fromCode("L");
} else if (observed > high) {
result = Loinc2HPOCodedValue.fromCode("H");
} else {
result = Loinc2HPOCodedValue.fromCode("N");
}
Code resultCode = Code.getNewCode().setSystem(Loinc2HPOCodedValue.CODESYSTEM).setCode(result.toCode());
hpoTermId4LoincTest = annotationMap.get(loincId).loincInterpretationToHPO(resultCode);
} else if (references.size() == 2) {
// what does it mean with multiple references
throw new AmbiguousReferenceException();
} else if (references.size() == 3) {
// it can happen when there is actually one range but coded in three ranges
// e.g. normal 20-30
// in this case, one range ([20, 30]) is sufficient;
// however, it is written as three ranges: ( , 20) [20, 30] (30, )
// We should handle this case
} else {
throw new AmbiguousReferenceException();
}
// if we can still not find an answer, it is probably that we did not have the annotation
if (hpoTermId4LoincTest == null)
throw new UnrecognizedCodeException();
return hpoTermId4LoincTest;
}
use of org.hl7.fhir.r5.model.Range in project loinc2hpo by monarch-initiative.
the class CodeSystemInternal method init.
@Override
protected void init() {
final Coding BELOWNORMAL = new Coding(INTERNALSYSTEM, "L", "below normal range");
final Coding NORMAL = new Coding(INTERNALSYSTEM, "N", "within normal range");
final Coding ABOVENORMAL = new Coding(INTERNALSYSTEM, "H", "above normal range");
final Coding ABSENCE = new Coding(INTERNALSYSTEM, "NP", "not present");
final Coding PRESENCE = new Coding(INTERNALSYSTEM, "P", "present");
final Coding UNKNOWN = new Coding(INTERNALSYSTEM, "unknown", "unknown");
codes.put(BELOWNORMAL.getCode(), BELOWNORMAL);
codes.put(NORMAL.getCode(), NORMAL);
codes.put(ABOVENORMAL.getCode(), ABOVENORMAL);
codes.put(ABSENCE.getCode(), ABSENCE);
codes.put(PRESENCE.getCode(), PRESENCE);
codes.put(UNKNOWN.getCode(), UNKNOWN);
}
use of org.hl7.fhir.r5.model.Range in project loinc2hpo by monarch-initiative.
the class ObservationWithValueRangeTest method highHbWithReferenceRange.
/**
* This observation does not have an Interpretation, but we can infer the value to be high
* based on the reference range.
*/
@Test
public void highHbWithReferenceRange() {
Observation observation = highHemoglobinWithValueRangeObservation();
Uberobservation uberobservation = new ObservationDtu3(observation);
LoincId erysInBlood = new LoincId("789-8");
Optional<LoincId> opt = uberobservation.getLoincId();
assertTrue(opt.isPresent());
assertEquals(erysInBlood, opt.get());
Optional<Outcome> outcomeOpt = uberobservation.getOutcome();
assertTrue(outcomeOpt.isPresent());
assertEquals(Outcome.HIGH(), outcomeOpt.get());
}
use of org.hl7.fhir.r5.model.Range in project clinical_quality_language by cqframework.
the class ElmDataRequirement method applyConditionRequirementTo.
private void applyConditionRequirementTo(ElmConditionRequirement conditionRequirement, Retrieve retrieve, ElmRequirementsContext context) {
if (retrieve.getDataType() == null) {
// If the retrieve has no data type, it is neither useful nor possible to apply requirements to it
return;
}
if (!conditionRequirement.isTargetable()) {
// If the comparand of the condition requirement is not targetable, requirements cannot be applied
return;
}
// if the column is terminology-valued, express as a code filter
// if the column is date-valued, express as a date filter
// else express as an other filter
Property property = conditionRequirement.getProperty().getProperty();
// DataType propertyType = property.getResultType();
// Use the comparison type due to the likelihood of conversion operators along the property
DataType comparisonType = conditionRequirement.getComparand().getExpression().getResultType();
if (comparisonType != null) {
if (context.getTypeResolver().isTerminologyType(comparisonType)) {
CodeFilterElement codeFilter = new CodeFilterElement();
if (property instanceof Search) {
codeFilter.setSearch(property.getPath());
} else {
codeFilter.setProperty(property.getPath());
}
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
codeFilter.setComparator("=");
break;
case "Equivalent":
codeFilter.setComparator("~");
break;
case "In":
case "InValueSet":
case "AnyInValueSet":
codeFilter.setComparator("in");
break;
}
if (codeFilter.getComparator() != null && (conditionRequirement.isTargetable())) {
codeFilter.setValue(conditionRequirement.getComparand().getExpression());
if (!ComparableElmRequirement.hasCodeFilter(retrieve.getCodeFilter(), codeFilter)) {
retrieve.getCodeFilter().add(codeFilter);
}
}
} else if (context.getTypeResolver().isDateType(comparisonType)) {
DateFilterElement dateFilter = new DateFilterElement();
if (property instanceof Search) {
dateFilter.setSearch(property.getPath());
} else {
dateFilter.setProperty(property.getPath());
}
// Determine operation and appropriate range
// If right is interval-valued
// If the operation is equal, equivalent, same as, in, or included in, the date range is the comparand
Expression comparand = conditionRequirement.getComparand().getExpression();
if (conditionRequirement.isTargetable()) {
if (context.getTypeResolver().isIntervalType(comparisonType)) {
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
case "Equivalent":
case "SameAs":
case "In":
case "IncludedIn":
dateFilter.setValue(comparand);
break;
case "Before":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(false));
break;
case "SameOrBefore":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(true));
break;
case "After":
dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(false).withHighClosed(true));
break;
case "SameOrAfter":
dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(true).withHighClosed(true));
break;
case "Includes":
case "Meets":
case "MeetsBefore":
case "MeetsAfter":
case "Overlaps":
case "OverlapsBefore":
case "OverlapsAfter":
case "Starts":
case "Ends":
// TODO: Might be better to turn these into date-based conjunctive requirements as part of condition requirement inference
break;
}
} else {
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
case "Equivalent":
case "SameAs":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHigh(comparand).withHighClosed(true));
break;
case "Less":
case "Before":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(false));
break;
case "LessOrEqual":
case "SameOrBefore":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(true));
break;
case "Greater":
case "After":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(false).withHighClosed(true));
break;
case "GreaterOrEqual":
case "SameOrAfter":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHighClosed(true));
break;
}
}
}
if (dateFilter.getValue() != null) {
if (!ComparableElmRequirement.hasDateFilter(retrieve.getDateFilter(), dateFilter)) {
retrieve.getDateFilter().add(dateFilter);
}
}
} else {
}
}
}
use of org.hl7.fhir.r5.model.Range in project molgenis by molgenis.
the class AttributeRequestMapperImpl method updateAttributeValue.
private void updateAttributeValue(Attribute attribute, String key, Object value) {
switch(key) {
case "id":
attribute.setIdentifier(getStringValue(value));
break;
case "name":
attribute.setName(getStringValue(value));
break;
case "sequenceNr":
setSequenceNumber(attribute, value);
break;
case "type":
setAttributeType(attribute, value);
break;
case "refEntityType":
setRefEntityType(attribute, value);
break;
case "cascadeDelete":
String cascadeValue = getStringValue(value);
Boolean isCascade = cascadeValue != null ? Boolean.valueOf(cascadeValue) : null;
attribute.setCascadeDelete(isCascade);
break;
case "orderBy":
mapOrderBy(value).ifPresent(attribute::setOrderBy);
break;
case "expression":
attribute.setExpression(getStringValue(value));
break;
case "nullable":
String nullableValue = getStringValue(value);
attribute.setNillable(Boolean.parseBoolean(nullableValue));
break;
case "auto":
String autoValue = getStringValue(value);
attribute.setAuto(Boolean.parseBoolean(autoValue));
break;
case "visible":
String visibleValue = getStringValue(value);
attribute.setVisible(Boolean.parseBoolean(visibleValue));
break;
case "label":
I18nValue i18Label = I18nValueMapper.toI18nValue(value);
processI18nLabel(i18Label, attribute);
break;
case "description":
I18nValue i18Description = I18nValueMapper.toI18nValue(value);
processI18nDescription(i18Description, attribute);
break;
case "aggregatable":
attribute.setAggregatable(Boolean.parseBoolean(value.toString()));
break;
case "enumOptions":
setEnumOptions(attribute, value);
break;
case "range":
Range range = mapRange(value);
if (range != null) {
attribute.setRange(map(range));
}
break;
case "readonly":
setBooleanValue(attribute, value, IS_READ_ONLY);
break;
case "unique":
setBooleanValue(attribute, value, IS_UNIQUE);
break;
case "defaultValue":
attribute.setDefaultValue(getStringValue(value));
break;
case "nullableExpression":
attribute.setNullableExpression(getStringValue(value));
break;
case "visibleExpression":
attribute.setVisibleExpression(getStringValue(value));
break;
case "validationExpression":
attribute.setValidationExpression(getStringValue(value));
break;
case "mappedByAttribute":
case "parent":
// Skip now and process after all attributes in the request have been processed
break;
case "tags":
throw new UnsupportedFieldException(key);
case "idAttribute":
attribute.setIdAttribute(DataConverter.toBoolean(value));
break;
case "labelAttribute":
attribute.setLabelAttribute(DataConverter.toBoolean(value));
break;
case "lookupAttributeIndex":
attribute.setLookupAttributeIndex(DataConverter.toInt(value));
break;
default:
throw new InvalidKeyException("attribute", key);
}
}
Aggregations