Skip to content

Commit 8fc5274

Browse files
codeforgreennathandoef
authored andcommitted
Add support for response parameter issues for validate-code operation (#6360)
* Add support for response parameter issues for validate-code operation. Implement workaround for missing error for invalid codes by adding an issue when it is absent. * address minor code review comments * revert functionality of adding original code from remote validate-code call to the CodeValidationResult * revert change to FhirInstanceValidatorR4Test * Revert some of the code review addressal after responding. * Remove populating message in success scenarios. * Fix compilation failure in test after reverting method rename. * Revert change to populate the code from the response again as it implies more refactoring. --------- Co-authored-by: nathaniel.doef <[email protected]>
1 parent b911ec7 commit 8fc5274

File tree

29 files changed

+1814
-1214
lines changed

29 files changed

+1814
-1214
lines changed

hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public CodeValidationResult setCode(String theCode) {
727727
return this;
728728
}
729729

730-
String getCodeSystemName() {
730+
public String getCodeSystemName() {
731731
return myCodeSystemName;
732732
}
733733

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.Collection;
4545
import java.util.List;
46+
import java.util.Objects;
4647
import java.util.Optional;
4748
import java.util.function.Function;
4849
import java.util.stream.Collectors;
@@ -58,20 +59,20 @@ public class ParametersUtil {
5859
public static Optional<String> getNamedParameterValueAsString(
5960
FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
6061
Function<IPrimitiveType<?>, String> mapper = t -> defaultIfBlank(t.getValueAsString(), null);
61-
return extractNamedParameters(theCtx, theParameters, theParameterName, mapper).stream()
62+
return extractNamedParameterValues(theCtx, theParameters, theParameterName, mapper).stream()
6263
.findFirst();
6364
}
6465

6566
public static List<String> getNamedParameterValuesAsString(
6667
FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
6768
Function<IPrimitiveType<?>, String> mapper = t -> defaultIfBlank(t.getValueAsString(), null);
68-
return extractNamedParameters(theCtx, theParameters, theParameterName, mapper);
69+
return extractNamedParameterValues(theCtx, theParameters, theParameterName, mapper);
6970
}
7071

7172
public static List<Integer> getNamedParameterValuesAsInteger(
7273
FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
7374
Function<IPrimitiveType<?>, Integer> mapper = t -> (Integer) t.getValue();
74-
return extractNamedParameters(theCtx, theParameters, theParameterName, mapper);
75+
return extractNamedParameterValues(theCtx, theParameters, theParameterName, mapper);
7576
}
7677

7778
public static Optional<Integer> getNamedParameterValueAsInteger(
@@ -80,6 +81,19 @@ public static Optional<Integer> getNamedParameterValueAsInteger(
8081
.findFirst();
8182
}
8283

84+
/**
85+
* Returns the resource within a parameter.
86+
* @param theCtx thr FHIR context
87+
* @param theParameters the parameters instance where to look for the resource
88+
* @param theParameterName the parameter name
89+
* @return the resource
90+
*/
91+
public static Optional<IBaseResource> getNamedParameterResource(
92+
FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
93+
return extractNamedParameterResources(theCtx, theParameters, theParameterName).stream()
94+
.findFirst();
95+
}
96+
8397
public static Optional<IBase> getNamedParameter(
8498
FhirContext theCtx, IBaseResource theParameters, String theParameterName) {
8599
return getNamedParameters(theCtx, theParameters, theParameterName).stream()
@@ -153,7 +167,7 @@ public static Optional<Integer> getParameterPartValueAsInteger(
153167
.map(t -> (Integer) t);
154168
}
155169

156-
private static <T> List<T> extractNamedParameters(
170+
private static <T> List<T> extractNamedParameterValues(
157171
FhirContext theCtx,
158172
IBaseParameters theParameters,
159173
String theParameterName,
@@ -170,7 +184,25 @@ private static <T> List<T> extractNamedParameters(
170184
.filter(t -> t instanceof IPrimitiveType<?>)
171185
.map(t -> ((IPrimitiveType<?>) t))
172186
.map(theMapper)
173-
.filter(t -> t != null)
187+
.filter(Objects::nonNull)
188+
.forEach(retVal::add);
189+
}
190+
return retVal;
191+
}
192+
193+
private static List<IBaseResource> extractNamedParameterResources(
194+
FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
195+
List<IBaseResource> retVal = new ArrayList<>();
196+
197+
List<IBase> namedParameters = getNamedParameters(theCtx, theParameters, theParameterName);
198+
for (IBase nextParameter : namedParameters) {
199+
BaseRuntimeElementCompositeDefinition<?> nextParameterDef =
200+
(BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(nextParameter.getClass());
201+
BaseRuntimeChildDefinition resourceChild = nextParameterDef.getChildByName("resource");
202+
List<IBase> resourceValues = resourceChild.getAccessor().getValues(nextParameter);
203+
resourceValues.stream()
204+
.filter(IBaseResource.class::isInstance)
205+
.map(t -> ((IBaseResource) t))
174206
.forEach(retVal::add);
175207
}
176208
return retVal;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 6359
4+
title: "After upgrading org.hl7.fhir.core from 6.1.2.2 to 6.3.11, the $validate-code operation stopped returning an
5+
error for invalid codes using remote terminology. This has been fixed."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: add
3+
issue: 6359
4+
title: "Remote Terminology validation has been enhanced to support output parameter `issues` for the $validate-code
5+
operation."

0 commit comments

Comments
 (0)