Skip to content

Commit

Permalink
6662 remote terminology boolean properties as string (#6663)
Browse files Browse the repository at this point in the history
* Add test for failing use case and fix by adding Boolean property for remote validation

* changelog

* Revert not yet supported change
  • Loading branch information
jmarchionatto authored Jan 29, 2025
1 parent fc8ce73 commit 8d60820
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ public String getPropertyName() {
// Some of the types in the spec are not yet implemented as well.
// @see https://github.com/hapifhir/hapi-fhir/issues/5700
String TYPE_STRING = "string";
String TYPE_BOOLEAN = "boolean";
String TYPE_CODING = "Coding";
String TYPE_GROUP = "group";

Expand All @@ -800,6 +801,29 @@ public String getType() {
}
}

class BooleanConceptProperty extends BaseConceptProperty {
private final boolean myValue;

/**
* Constructor
*
* @param theName The name
*/
public BooleanConceptProperty(String theName, boolean theValue) {
super(theName);
myValue = theValue;
}

public boolean getValue() {
return myValue;
}

@Override
public String getType() {
return TYPE_BOOLEAN;
}
}

class CodingConceptProperty extends BaseConceptProperty {
private final String myCode;
private final String myCodeSystem;
Expand Down Expand Up @@ -1073,7 +1097,7 @@ class ValueSetExpansionOutcome {
private final IBaseResource myValueSet;
private final String myError;

private boolean myErrorIsFromServer;
private final boolean myErrorIsFromServer;

public ValueSetExpansionOutcome(String theError, boolean theErrorIsFromServer) {
myValueSet = null;
Expand Down Expand Up @@ -1199,7 +1223,7 @@ public LookupCodeResult setFound(boolean theFound) {
}

public void throwNotFoundIfAppropriate() {
if (isFound() == false) {
if (!isFound()) {
throw new ResourceNotFoundException(Msg.code(1738) + "Unable to find code[" + getSearchedForCode()
+ "] in system[" + getSearchedForSystem() + "]");
}
Expand Down Expand Up @@ -1270,6 +1294,10 @@ private void populateProperty(
StringConceptProperty stringConceptProperty = (StringConceptProperty) theConceptProperty;
ParametersUtil.addPartString(theContext, theProperty, "value", stringConceptProperty.getValue());
break;
case TYPE_BOOLEAN:
BooleanConceptProperty booleanConceptProperty = (BooleanConceptProperty) theConceptProperty;
ParametersUtil.addPartBoolean(theContext, theProperty, "value", booleanConceptProperty.getValue());
break;
case TYPE_CODING:
CodingConceptProperty codingConceptProperty = (CodingConceptProperty) theConceptProperty;
ParametersUtil.addPartCoding(
Expand Down Expand Up @@ -1321,7 +1349,7 @@ class TranslateCodeRequest {
private final String myTargetValueSetUrl;
private final IIdType myResourceId;
private final boolean myReverse;
private List<IBaseCoding> myCodings;
private final List<IBaseCoding> myCodings;

public TranslateCodeRequest(List<IBaseCoding> theCodings, String theTargetSystemUrl) {
myCodings = theCodings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: fix
issue: 6662
title: "Fixed remote terminology lookup results showing boolean properties as strings."
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.CodeableConcept;
Expand Down Expand Up @@ -457,6 +458,10 @@ private static BaseConceptProperty createConceptPropertyR4(final String theName,
StringType stringType = (StringType) theValue;
conceptProperty = new StringConceptProperty(theName, stringType.getValue());
break;
case IValidationSupport.TYPE_BOOLEAN:
BooleanType booleanType = (BooleanType) theValue;
conceptProperty = new BooleanConceptProperty(theName, booleanType.getValue());
break;
case IValidationSupport.TYPE_CODING:
Coding coding = (Coding) theValue;
conceptProperty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ca.uhn.fhir.context.support.IValidationSupport.GroupConceptProperty;
import ca.uhn.fhir.context.support.IValidationSupport.LookupCodeResult;
import ca.uhn.fhir.context.support.IValidationSupport.StringConceptProperty;
import ca.uhn.fhir.context.support.IValidationSupport.BooleanConceptProperty;
import ca.uhn.fhir.context.support.LookupCodeRequest;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.test.utilities.validation.IValidationProviders;
Expand All @@ -17,17 +18,18 @@
import java.util.List;
import java.util.Optional;

import static ca.uhn.fhir.context.support.IValidationSupport.TYPE_BOOLEAN;
import static ca.uhn.fhir.context.support.IValidationSupport.TYPE_CODING;
import static ca.uhn.fhir.context.support.IValidationSupport.TYPE_GROUP;
import static ca.uhn.fhir.context.support.IValidationSupport.TYPE_STRING;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.CODE;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.CODE_SYSTEM;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.CODE_SYSTEM_NAME;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.CODE_SYSTEM_VERSION;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.DISPLAY;
import static ca.uhn.fhir.test.utilities.validation.IValidationProviders.LANGUAGE;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hl7.fhir.common.hapi.validation.support.RemoteTerminologyServiceValidationSupport.createConceptProperty;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -198,7 +200,8 @@ default void verifyLookupCodeResult(LookupCodeRequest theRequest, LookupCodeResu
assertEquals(theExpectedResult.isCodeIsAbstract(), outcome.isCodeIsAbstract());

assertEquals(theExpectedResult.getProperties().size(), outcome.getProperties().size());
range(0, outcome.getProperties().size()).forEach(i -> assertEqualConceptProperty(theExpectedResult.getProperties().get(i), outcome.getProperties().get(i)));
range(0, outcome.getProperties().size()).forEach(i ->
assertEqualConceptProperty(theExpectedResult.getProperties().get(i), outcome.getProperties().get(i)));

assertEquals(theExpectedResult.getDesignations().size(), outcome.getDesignations().size());
range(0, outcome.getDesignations().size()).forEach(i -> assertEqualConceptDesignation(theExpectedResult.getDesignations().get(i), outcome.getDesignations().get(i)));
Expand All @@ -225,6 +228,11 @@ private void assertEqualConceptProperty(BaseConceptProperty theProperty, BaseCon
StringConceptProperty actual = (StringConceptProperty) theProperty;
assertEquals(expected.getValue(), actual.getValue());
}
case TYPE_BOOLEAN -> {
BooleanConceptProperty expected = (BooleanConceptProperty) theExpectedProperty;
IValidationSupport.BooleanConceptProperty actual = (BooleanConceptProperty) theProperty;
assertEquals(expected.getValue(), actual.getValue());
}
case TYPE_CODING -> {
CodingConceptProperty expected = (CodingConceptProperty) theExpectedProperty;
CodingConceptProperty actual = (CodingConceptProperty) theProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static Stream<Arguments> getPropertyValueListArguments() {
@ParameterizedTest
@MethodSource(value = "getPropertyValueArguments")
public void lookupCode_forCodeSystemWithProperty_returnsCorrectProperty(IBaseDatatype thePropertyValue) {
verifyLookupWithProperty(List.of(thePropertyValue), List.of());
verifyLookupWithProperty(List.of(thePropertyValue), List.of(0));
}

@ParameterizedTest
Expand Down

0 comments on commit 8d60820

Please sign in to comment.