Skip to content
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

issue #679 - fix the fhirpathspectests #715

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import com.ibm.fhir.model.patch.FHIRPatch;
import com.ibm.fhir.model.patch.exception.FHIRPatchException;
Expand Down Expand Up @@ -38,7 +39,7 @@ public <T extends Resource> T apply(T resource) throws FHIRPatchException {
* Convert the FHIRPathPatch to a FHIR Parameters resource
*/
public Parameters toParameters() {
Parameters.Builder builder = Parameters.builder();
Parameters.Builder builder = Parameters.builder().id(UUID.randomUUID().toString());
for (FHIRPathPatchOperation operation : operations) {
builder.parameter(operation.toParameter());
}
Expand Down Expand Up @@ -127,14 +128,14 @@ public FHIRPathPatch build() {
public static FHIRPathPatch from(Parameters params) {
Objects.requireNonNull(params);
Builder builder = FHIRPathPatch.builder();

for (Parameter param : params.getParameter()) {
if (!FHIRPathPatchOperation.OPERATION.equals(param.getName().getValue())) {
throw new IllegalArgumentException("Each FHIRPath patch operation must have a name of 'operation'");
}
addOperation(builder, param);
}

return builder.build();
}

Expand All @@ -143,7 +144,7 @@ public static FHIRPathPatch from(Parameters params) {
*
* @throws IllegalArgumentException if the Parameter object does not represent a valid FHIRPath Patch operation
*/
private static FHIRPathPatchOperation addOperation(Builder builder, Parameter operation) {
private static void addOperation(Builder builder, Parameter operation) {
boolean foundType = false, foundPath = false, foundName = false, foundValue = false, foundIndex = false, foundSource = false, foundDestination = false;
FHIRPathPatchType type = null;
String fhirPath = null;
Expand Down Expand Up @@ -197,11 +198,21 @@ private static FHIRPathPatchOperation addOperation(Builder builder, Parameter op
}
try {
switch (type) {
case ADD: builder.add(fhirPath, name, value);
case DELETE: builder.delete(fhirPath);
case INSERT: builder.insert(fhirPath, value, index);
case MOVE: builder.move(fhirPath, source, destination);
case REPLACE: builder.replace(fhirPath, value);
case ADD:
builder.add(fhirPath, name, value);
break;
case DELETE:
builder.delete(fhirPath);
break;
case INSERT:
builder.insert(fhirPath, value, index);
break;
case MOVE:
builder.move(fhirPath, source, destination);
break;
case REPLACE:
builder.replace(fhirPath, value);
break;
default:
throw new IllegalArgumentException("Invalid FHIRPath patch operation type: " + type.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public Parameter toParameter() {
.name(string(OPERATION))
.part(Parameter.builder()
.name(string(TYPE))
.value(Code.of(FHIRPathPatchType.ADD.value()))
.value(Code.of(FHIRPathPatchType.INSERT.value()))
.build())
.part(Parameter.builder()
.name(string(PATH))
.value(string(fhirPath))
.build())
.part(Parameter.builder()
.name(string(VALUE))
.value(value)
.build())
.part(Parameter.builder()
.name(string(INDEX))
.value(com.ibm.fhir.model.type.Integer.of(index))
.build())
.part(Parameter.builder()
.name(string(VALUE))
.value(value)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Parameter toParameter() {
.name(string(OPERATION))
.part(Parameter.builder()
.name(string(TYPE))
.value(Code.of(FHIRPathPatchType.ADD.value()))
.value(Code.of(FHIRPathPatchType.MOVE.value()))
.build())
.part(Parameter.builder()
.name(string(PATH))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Parameter toParameter() {
.name(string(OPERATION))
.part(Parameter.builder()
.name(string(TYPE))
.value(Code.of(FHIRPathPatchType.ADD.value()))
.value(Code.of(FHIRPathPatchType.REPLACE.value()))
.build())
.part(Parameter.builder()
.name(string(PATH))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ private void executeTest() throws Exception {
}
try {
FHIRPathPatch patch = FHIRPathPatch.from(params);
assertEquals(patch.toParameters(), params);
// Set the id to match the expected parameters object so we can do a normal compare
Parameters serializedPatch = patch.toParameters().toBuilder().id(params.getId()).build();
assertEquals(serializedPatch, params);

Resource actualOutput = patch.apply(input);
assertEquals(actualOutput, expectedOutput);
Expand Down Expand Up @@ -117,7 +119,7 @@ public static Object[][] provideAllTestData() throws Exception {
domFactory.setIgnoringElementContentWhitespace(true);
domFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = domFactory.newDocumentBuilder();
try (InputStream in = FHIRPathPatchSpecTest.class.getClassLoader().getResourceAsStream("patch\\fhir-path-tests.xml")) {
try (InputStream in = FHIRPathPatchSpecTest.class.getClassLoader().getResourceAsStream("fhir-path-patch-tests.xml")) {
Document testDoc = documentBuilder.parse(in);

NodeList cases = testDoc.getDocumentElement().getElementsByTagName("case");
Expand Down
3 changes: 2 additions & 1 deletion fhir-path/src/test/resources/fhir-path-patch-tests.CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Renamed file from "patch\fhir-path-tests.xml" to "fhir-path-patch-tests.xml" to avoid git error: invalid path 'fhir-path/src/test/resources/patch\fhir-path-tests.CHANGELOG'
To workaround global-1 I added a Resource.id to all FHIR Resources in the file (except the "Full Resource" test case which already had one)
I commented out the Patient.text.div replace operation in the test case Full Resource
I commented out the Patient.text.div replace operation in the test case Full Resource
Replace tabs with spaces and remove trailing whitespace
Loading