Skip to content

Commit

Permalink
#201:modify author parameters in MHD query transactions in order to f…
Browse files Browse the repository at this point in the history
…ix the capability statement
  • Loading branch information
ohr committed Jun 8, 2018
1 parent 4643d7a commit bd3d0c4
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,4 +63,19 @@ public List<TokenParam> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,4 +70,19 @@ public List<TokenParam> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
17 changes: 17 additions & 0 deletions commons/ihe/fhir/stu3/mhd/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT" follow="true">
<PatternLayout charset="UTF-8">
<Pattern>%d{ABSOLUTE} [%t] %-5p - %C{1}.%M(%L) | %m%n</Pattern>
</PatternLayout>
</Console>
</Appenders>

<Loggers>
<Root level="WARN">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bd3d0c4

Please sign in to comment.