From bd3d0c4bb973c9d7e0893b70f77e688d832bf713 Mon Sep 17 00:00:00 2001 From: Christian Ohr Date: Fri, 8 Jun 2018 10:42:42 +0200 Subject: [PATCH] #201:modify author parameters in MHD query transactions in order to fix the capability statement --- .../ihe/fhir/iti66/Iti66ResourceProvider.java | 21 ++++----- .../ihe/fhir/iti66/Iti66SearchParameters.java | 23 +++++++--- .../ihe/fhir/iti67/Iti67ResourceProvider.java | 19 +++----- .../ihe/fhir/iti67/Iti67SearchParameters.java | 22 ++++++--- .../fhir/iti66/Iti66SearchParametersTest.java | 45 +++++++++++++++++++ .../fhir/iti67/Iti67SearchParametersTest.java | 45 +++++++++++++++++++ .../stu3/mhd/src/test/resources/log4j2.xml | 17 +++++++ .../ihe/fhir/iti78/Iti78ResourceProvider.java | 5 ++- 8 files changed, 161 insertions(+), 36 deletions(-) create mode 100644 commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParametersTest.java create mode 100644 commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParametersTest.java create mode 100644 commons/ihe/fhir/stu3/mhd/src/test/resources/log4j2.xml diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ResourceProvider.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ResourceProvider.java index 9923fd888e..ec39f62bd9 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ResourceProvider.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ResourceProvider.java @@ -20,11 +20,7 @@ import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.dstu3.model.DocumentManifest; import org.hl7.fhir.dstu3.model.IdType; @@ -50,8 +46,7 @@ public class Iti66ResourceProvider extends AbstractPlainProvider { public IBundleProvider documentManifestSearch( @RequiredParam(name = DocumentManifest.SP_PATIENT, chainWhitelist = {"", Patient.SP_IDENTIFIER}) ReferenceParam patient, @OptionalParam(name = DocumentManifest.SP_CREATED) DateRangeParam created, - @OptionalParam(name = DocumentManifest.SP_AUTHOR + "." + Practitioner.SP_FAMILY) StringParam authorFamilyName, - @OptionalParam(name = DocumentManifest.SP_AUTHOR + "." + Practitioner.SP_GIVEN) StringParam authorGivenName, + @OptionalParam(name = DocumentManifest.SP_AUTHOR, chainWhitelist = { Practitioner.SP_FAMILY, Practitioner.SP_GIVEN }) ReferenceAndListParam author, @OptionalParam(name = DocumentManifest.SP_TYPE) TokenOrListParam type, @OptionalParam(name = DocumentManifest.SP_SOURCE) TokenOrListParam source, @OptionalParam(name = DocumentManifest.SP_STATUS) TokenOrListParam status, @@ -63,10 +58,8 @@ public IBundleProvider documentManifestSearch( HttpServletResponse httpServletResponse) { - Iti66SearchParameters parameters = Iti66SearchParameters.builder() + Iti66SearchParameters searchParameters = Iti66SearchParameters.builder() .created(created) - .authorFamilyName(authorFamilyName) - .authorGivenName(authorGivenName) .type(type) .source(source) .status(status) @@ -76,15 +69,17 @@ public IBundleProvider documentManifestSearch( .fhirContext(getFhirContext()) .build(); + searchParameters.setAuthor(author); + String chain = patient.getChain(); if (Patient.SP_IDENTIFIER.equals(chain)) { - parameters.setPatientIdentifier(patient.toTokenParam(getFhirContext())); + searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext())); } else if (chain == null || chain.isEmpty()) { - parameters.setPatientReference(patient); + searchParameters.setPatientReference(patient); } // Run down the route - return requestBundleProvider(null, parameters, httpServletRequest, httpServletResponse); + return requestBundleProvider(null, searchParameters, httpServletRequest, httpServletResponse); } /** diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java index 8fe4b5ca25..afe2c6eb2d 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java @@ -19,16 +19,14 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.param.*; import lombok.Builder; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.hl7.fhir.dstu3.model.Practitioner; import org.openehealth.ipf.commons.ihe.fhir.FhirSearchParameters; +import org.openehealth.ipf.commons.ihe.fhir.iti67.Iti67SearchParameters; import java.util.Collections; import java.util.List; @@ -65,4 +63,19 @@ public List getPatientIdParam() { return Collections.singletonList(patientIdentifier); } + + public Iti66SearchParameters setAuthor(ReferenceAndListParam author) { + if (author != null) { + author.getValuesAsQueryTokens().forEach(param -> { + ReferenceParam ref = param.getValuesAsQueryTokens().get(0); + String authorChain = ref.getChain(); + if (Practitioner.SP_FAMILY.equals(authorChain)) { + setAuthorFamilyName(ref.toStringParam(getFhirContext())); + } else if (Practitioner.SP_GIVEN.equals(authorChain)) { + setAuthorGivenName(ref.toStringParam(getFhirContext())); + } + }); + } + return this; + } } diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java index 5e8465b338..b5442bb343 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java @@ -20,11 +20,7 @@ import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.dstu3.model.DocumentReference; import org.hl7.fhir.dstu3.model.IdType; @@ -61,8 +57,7 @@ public IBundleProvider documentReferenceSearch( @RequiredParam(name = DocumentReference.SP_PATIENT, chainWhitelist = {"", Patient.SP_IDENTIFIER}) ReferenceParam patient, @OptionalParam(name = DocumentReference.SP_STATUS) TokenOrListParam status, @OptionalParam(name = DocumentReference.SP_INDEXED) DateRangeParam indexed, - @OptionalParam(name = DocumentReference.SP_AUTHOR + "." + Practitioner.SP_FAMILY) StringParam authorFamilyName, - @OptionalParam(name = DocumentReference.SP_AUTHOR + "." + Practitioner.SP_GIVEN) StringParam authorGivenName, + @OptionalParam(name = DocumentReference.SP_AUTHOR, chainWhitelist = { Practitioner.SP_FAMILY, Practitioner.SP_GIVEN }) ReferenceAndListParam author, @OptionalParam(name = DocumentReference.SP_CLASS) TokenOrListParam class_, @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type, @OptionalParam(name = DocumentReference.SP_SETTING) TokenOrListParam setting, @@ -82,8 +77,6 @@ public IBundleProvider documentReferenceSearch( Iti67SearchParameters searchParameters = Iti67SearchParameters.builder() .status(status) .indexed(indexed) - .authorFamilyName(authorFamilyName) - .authorGivenName(authorGivenName) .class_(class_) .type(type) .setting(setting) @@ -99,10 +92,12 @@ public IBundleProvider documentReferenceSearch( .fhirContext(getFhirContext()) .build(); - String chain = patient.getChain(); - if (Patient.SP_IDENTIFIER.equals(chain)) { + searchParameters.setAuthor(author); + + String patientChain = patient.getChain(); + if (Patient.SP_IDENTIFIER.equals(patientChain)) { searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext())); - } else if (chain == null || chain.isEmpty()) { + } else if (patientChain == null || patientChain.isEmpty()) { searchParameters.setPatientReference(patient); } diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java index b9d24dc2cf..04d48bef2a 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java @@ -19,15 +19,12 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.param.*; import lombok.Builder; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.hl7.fhir.dstu3.model.Practitioner; import org.openehealth.ipf.commons.ihe.fhir.FhirSearchParameters; import java.util.Collections; @@ -73,4 +70,19 @@ public List getPatientIdParam() { return Collections.singletonList(patientIdentifier); } + + public Iti67SearchParameters setAuthor(ReferenceAndListParam author) { + if (author != null) { + author.getValuesAsQueryTokens().forEach(param -> { + ReferenceParam ref = param.getValuesAsQueryTokens().get(0); + String authorChain = ref.getChain(); + if (Practitioner.SP_FAMILY.equals(authorChain)) { + setAuthorFamilyName(ref.toStringParam(getFhirContext())); + } else if (Practitioner.SP_GIVEN.equals(authorChain)) { + setAuthorGivenName(ref.toStringParam(getFhirContext())); + } + }); + } + return this; + } } diff --git a/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParametersTest.java b/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParametersTest.java new file mode 100644 index 0000000000..3c9830f9f4 --- /dev/null +++ b/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParametersTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti66; + +import ca.uhn.fhir.rest.param.ReferenceAndListParam; +import ca.uhn.fhir.rest.param.ReferenceOrListParam; +import ca.uhn.fhir.rest.param.ReferenceParam; +import org.hl7.fhir.dstu3.model.Practitioner; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author Christian Ohr + */ +public class Iti66SearchParametersTest { + + @Test + public void setAuthor() { + Iti66SearchParameters searchParameters = Iti66SearchParameters.builder().build(); + + ReferenceAndListParam param = new ReferenceAndListParam() + .addAnd(new ReferenceOrListParam() + .addOr(new ReferenceParam(Practitioner.SP_FAMILY, "family"))) + .addAnd(new ReferenceOrListParam() + .addOr(new ReferenceParam(Practitioner.SP_GIVEN, "given"))); + searchParameters.setAuthor(param); + assertEquals("family", searchParameters.getAuthorFamilyName().getValue()); + assertEquals("given", searchParameters.getAuthorGivenName().getValue()); + } +} diff --git a/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParametersTest.java b/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParametersTest.java new file mode 100644 index 0000000000..fae3dbfa85 --- /dev/null +++ b/commons/ihe/fhir/stu3/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParametersTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti67; + +import ca.uhn.fhir.rest.param.ReferenceAndListParam; +import ca.uhn.fhir.rest.param.ReferenceOrListParam; +import ca.uhn.fhir.rest.param.ReferenceParam; +import org.hl7.fhir.dstu3.model.Practitioner; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author Christian Ohr + */ +public class Iti67SearchParametersTest { + + @Test + public void setAuthor() { + Iti67SearchParameters searchParameters = Iti67SearchParameters.builder().build(); + + ReferenceAndListParam param = new ReferenceAndListParam() + .addAnd(new ReferenceOrListParam() + .addOr(new ReferenceParam(Practitioner.SP_FAMILY, "family"))) + .addAnd(new ReferenceOrListParam() + .addOr(new ReferenceParam(Practitioner.SP_GIVEN, "given"))); + searchParameters.setAuthor(param); + assertEquals("family", searchParameters.getAuthorFamilyName().getValue()); + assertEquals("given", searchParameters.getAuthorGivenName().getValue()); + } +} diff --git a/commons/ihe/fhir/stu3/mhd/src/test/resources/log4j2.xml b/commons/ihe/fhir/stu3/mhd/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..30fb1c5298 --- /dev/null +++ b/commons/ihe/fhir/stu3/mhd/src/test/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + %d{ABSOLUTE} [%t] %-5p - %C{1}.%M(%L) | %m%n + + + + + + + + + + + diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78ResourceProvider.java b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78ResourceProvider.java index 789c887880..25d8c6acdb 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78ResourceProvider.java +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78ResourceProvider.java @@ -17,6 +17,7 @@ package org.openehealth.ipf.commons.ihe.fhir.iti78; import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -60,7 +61,9 @@ public class Iti78ResourceProvider extends AbstractPlainProvider { @SuppressWarnings("unused") @Search(type = PdqPatient.class) public IBundleProvider pdqmSearch( - @OptionalParam(name = Patient.SP_IDENTIFIER) TokenAndListParam identifiers, + @Description(shortDefinition = "Logical id of this artifact") + @OptionalParam(name = Patient.SP_IDENTIFIER) + TokenAndListParam identifiers, @OptionalParam(name = Patient.SP_ACTIVE) TokenParam active, @OptionalParam(name = Patient.SP_FAMILY) StringAndListParam family, @OptionalParam(name = Patient.SP_GIVEN) StringAndListParam given,