|
4 | 4 | import ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil;
|
5 | 5 | import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInputAndPartialOutput;
|
6 | 6 | import org.hl7.fhir.dstu3.model.CodeSystem;
|
| 7 | +import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; |
| 8 | +import org.hl7.fhir.dstu3.model.CodeSystem.ConceptPropertyComponent; |
7 | 9 | import org.hl7.fhir.dstu3.model.CodeType;
|
| 10 | +import org.hl7.fhir.dstu3.model.Coding; |
8 | 11 | import org.hl7.fhir.dstu3.model.Parameters;
|
| 12 | +import org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent; |
9 | 13 | import org.hl7.fhir.dstu3.model.StringType;
|
10 | 14 | import org.hl7.fhir.dstu3.model.UriType;
|
11 | 15 | import org.junit.jupiter.params.ParameterizedTest;
|
|
21 | 25 | import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourCodeSystemUrl;
|
22 | 26 | import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourPropertyA;
|
23 | 27 | import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourPropertyB;
|
| 28 | +import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourPropertyC; |
24 | 29 | import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourPropertyValueA;
|
25 | 30 | import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.ourPropertyValueB;
|
| 31 | +import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.propertyCode; |
| 32 | +import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.propertyCodeSystem; |
| 33 | +import static ca.uhn.fhir.jpa.provider.CodeSystemLookupWithPropertiesUtil.propertyDisplay; |
26 | 34 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
27 | 35 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
28 | 36 | import static org.junit.jupiter.api.Assertions.assertNull;
|
29 | 37 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
30 | 38 |
|
31 | 39 | public class ResourceProviderDstu3CodeSystemPropertiesTest extends BaseResourceProviderDstu3Test {
|
32 | 40 |
|
33 |
| - public static Stream<Arguments> parametersLookup() { |
34 |
| - return CodeSystemLookupWithPropertiesUtil.parametersLookupWithProperties(); |
35 |
| - } |
36 |
| - |
37 |
| - @ParameterizedTest |
38 |
| - @MethodSource(value = "parametersLookup") |
39 |
| - public void testLookup_withProperties_returnsCorrectParameters(List<String> theLookupProperties, List<String> theExpectedReturnedProperties) { |
40 |
| - // setup |
41 |
| - CodeSystem codeSystem = new CodeSystem(); |
42 |
| - codeSystem.setId(ourCodeSystemId); |
43 |
| - codeSystem.setUrl(ourCodeSystemUrl); |
44 |
| - CodeSystem.ConceptDefinitionComponent concept = codeSystem.addConcept().setCode(ourCode); |
45 |
| - CodeSystem.ConceptPropertyComponent propertyComponent = new CodeSystem.ConceptPropertyComponent() |
46 |
| - .setCode(ourPropertyA).setValue(new StringType(ourPropertyValueA)); |
47 |
| - concept.addProperty(propertyComponent); |
48 |
| - propertyComponent = new CodeSystem.ConceptPropertyComponent() |
49 |
| - .setCode(ourPropertyB).setValue(new StringType(ourPropertyValueB)); |
50 |
| - concept.addProperty(propertyComponent); |
51 |
| - myCodeSystemDao.create(codeSystem, mySrd); |
52 |
| - |
53 |
| - // test |
54 |
| - IOperationUntypedWithInputAndPartialOutput<Parameters> respParam = myClient |
55 |
| - .operation() |
56 |
| - .onType(CodeSystem.class) |
57 |
| - .named(JpaConstants.OPERATION_LOOKUP) |
58 |
| - .withParameter(Parameters.class, "code", new CodeType(ourCode)) |
59 |
| - .andParameter("system", new UriType(ourCodeSystemUrl)); |
60 |
| - |
61 |
| - theLookupProperties.forEach(p -> respParam.andParameter("property", new CodeType(p))); |
62 |
| - Parameters parameters = respParam.execute(); |
63 |
| - |
64 |
| - Iterator<Parameters.ParametersParameterComponent> paramIterator = parameters.getParameter().iterator(); |
65 |
| - Parameters.ParametersParameterComponent parameter = null; |
66 |
| - while (paramIterator.hasNext()) { |
67 |
| - Parameters.ParametersParameterComponent currentParameter = paramIterator.next(); |
68 |
| - if (currentParameter.getName().equals("property")) { |
69 |
| - parameter = currentParameter; |
70 |
| - break; |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - if (theExpectedReturnedProperties.isEmpty()) { |
75 |
| - assertNull(parameter); |
76 |
| - return; |
77 |
| - } |
78 |
| - |
79 |
| - Iterator<CodeSystem.ConceptPropertyComponent> propertyIterator = concept.getProperty().stream() |
80 |
| - .filter(property -> theExpectedReturnedProperties.contains(property.getCode())).iterator(); |
81 |
| - |
82 |
| - while (propertyIterator.hasNext()) { |
83 |
| - CodeSystem.ConceptPropertyComponent property = propertyIterator.next(); |
84 |
| - assertNotNull(parameter); |
85 |
| - |
86 |
| - Iterator<Parameters.ParametersParameterComponent> parameterPartIterator = parameter.getPart().iterator(); |
87 |
| - |
88 |
| - parameter = parameterPartIterator.next(); |
89 |
| - assertEquals("code", parameter.getName()); |
90 |
| - assertEquals(property.getCode(), ((CodeType)parameter.getValue()).getValue()); |
91 |
| - |
92 |
| - parameter = parameterPartIterator.next(); |
93 |
| - assertEquals("value", parameter.getName()); |
94 |
| - assertTrue(property.getValue().equalsShallow(parameter.getValue())); |
95 |
| - |
96 |
| - if (paramIterator.hasNext()) { |
97 |
| - parameter = paramIterator.next(); |
98 |
| - } |
99 |
| - } |
100 |
| - } |
| 41 | + public static Stream<Arguments> parametersLookup() { |
| 42 | + return CodeSystemLookupWithPropertiesUtil.parametersLookupWithProperties(); |
| 43 | + } |
| 44 | + |
| 45 | + @ParameterizedTest |
| 46 | + @MethodSource(value = "parametersLookup") |
| 47 | + public void testLookup_withProperties_returnsCorrectParameters(List<String> theLookupProperties, List<String> theExpectedReturnedProperties) { |
| 48 | + // setup |
| 49 | + CodeSystem codeSystem = new CodeSystem(); |
| 50 | + codeSystem.setId(ourCodeSystemId); |
| 51 | + codeSystem.setUrl(ourCodeSystemUrl); |
| 52 | + ConceptDefinitionComponent concept = codeSystem.addConcept().setCode(ourCode) |
| 53 | + .addProperty(new ConceptPropertyComponent().setCode(ourPropertyA).setValue(new StringType(ourPropertyValueA))) |
| 54 | + .addProperty(new ConceptPropertyComponent().setCode(ourPropertyB).setValue(new StringType(ourPropertyValueB))) |
| 55 | + .addProperty(new ConceptPropertyComponent().setCode(ourPropertyC).setValue(new Coding(propertyCodeSystem, propertyCode, propertyDisplay))); |
| 56 | + myCodeSystemDao.create(codeSystem, mySrd); |
| 57 | + |
| 58 | + // test |
| 59 | + IOperationUntypedWithInputAndPartialOutput<Parameters> respParam = myClient |
| 60 | + .operation() |
| 61 | + .onType(CodeSystem.class) |
| 62 | + .named(JpaConstants.OPERATION_LOOKUP) |
| 63 | + .withParameter(Parameters.class, "code", new CodeType(ourCode)) |
| 64 | + .andParameter("system", new UriType(ourCodeSystemUrl)); |
| 65 | + |
| 66 | + theLookupProperties.forEach(p -> respParam.andParameter("property", new CodeType(p))); |
| 67 | + Parameters parameters = respParam.execute(); |
| 68 | + |
| 69 | + Iterator<ParametersParameterComponent> paramIterator = parameters.getParameter().iterator(); |
| 70 | + ParametersParameterComponent parameter = null; |
| 71 | + while (paramIterator.hasNext()) { |
| 72 | + ParametersParameterComponent currentParameter = paramIterator.next(); |
| 73 | + if (currentParameter.getName().equals("property")) { |
| 74 | + parameter = currentParameter; |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + // verify |
| 80 | + if (theExpectedReturnedProperties.isEmpty()) { |
| 81 | + assertNull(parameter); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + Iterator<ConceptPropertyComponent> propertyIterator = concept.getProperty().stream() |
| 86 | + .filter(property -> theExpectedReturnedProperties.contains(property.getCode())).iterator(); |
| 87 | + |
| 88 | + while (propertyIterator.hasNext()) { |
| 89 | + ConceptPropertyComponent property = propertyIterator.next(); |
| 90 | + assertNotNull(parameter); |
| 91 | + |
| 92 | + Iterator<ParametersParameterComponent> parameterPartIterator = parameter.getPart().iterator(); |
| 93 | + |
| 94 | + parameter = parameterPartIterator.next(); |
| 95 | + assertEquals("code", parameter.getName()); |
| 96 | + assertEquals(property.getCode(), ((CodeType) parameter.getValue()).getValue()); |
| 97 | + |
| 98 | + parameter = parameterPartIterator.next(); |
| 99 | + assertEquals("value", parameter.getName()); |
| 100 | + assertTrue(property.getValue().equalsShallow(parameter.getValue())); |
| 101 | + |
| 102 | + if (paramIterator.hasNext()) { |
| 103 | + parameter = paramIterator.next(); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
101 | 107 | }
|
0 commit comments