View Javadoc
1   /*
2    * Copyright 2016 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.openehealth.ipf.commons.ihe.fhir.iti66;
18  
19  import ca.uhn.fhir.model.api.Include;
20  import ca.uhn.fhir.rest.annotation.*;
21  import ca.uhn.fhir.rest.api.SortSpec;
22  import ca.uhn.fhir.rest.api.server.IBundleProvider;
23  import ca.uhn.fhir.rest.param.DateRangeParam;
24  import ca.uhn.fhir.rest.param.ReferenceParam;
25  import ca.uhn.fhir.rest.param.StringParam;
26  import ca.uhn.fhir.rest.param.TokenOrListParam;
27  import ca.uhn.fhir.rest.param.TokenParam;
28  import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
29  import org.hl7.fhir.dstu3.model.DocumentManifest;
30  import org.hl7.fhir.dstu3.model.IdType;
31  import org.hl7.fhir.dstu3.model.Patient;
32  import org.hl7.fhir.dstu3.model.Practitioner;
33  import org.hl7.fhir.instance.model.api.IAnyResource;
34  import org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider;
35  
36  import javax.servlet.http.HttpServletRequest;
37  import javax.servlet.http.HttpServletResponse;
38  import java.util.Set;
39  
40  /**
41   * Resource Provider for MHD (ITI-66)
42   *
43   * @author Christian Ohr
44   * @since 3.2
45   */
46  public class Iti66ResourceProvider extends AbstractPlainProvider {
47  
48      @SuppressWarnings("unused")
49      @Search(type = DocumentManifest.class)
50      public IBundleProvider documentManifestSearch(
51              @RequiredParam(name = DocumentManifest.SP_PATIENT, chainWhitelist = {"", Patient.SP_IDENTIFIER}) ReferenceParam patient,
52              @OptionalParam(name = DocumentManifest.SP_CREATED) DateRangeParam created,
53              @OptionalParam(name = DocumentManifest.SP_AUTHOR + "." + Practitioner.SP_FAMILY) StringParam authorFamilyName,
54              @OptionalParam(name = DocumentManifest.SP_AUTHOR + "." + Practitioner.SP_GIVEN) StringParam authorGivenName,
55              @OptionalParam(name = DocumentManifest.SP_TYPE) TokenOrListParam type,
56              @OptionalParam(name = DocumentManifest.SP_SOURCE) TokenOrListParam source,
57              @OptionalParam(name = DocumentManifest.SP_STATUS) TokenOrListParam status,
58              // Extension to ITI-66
59              @OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId,
60              @Sort SortSpec sortSpec,
61              @IncludeParam Set<Include> includeSpec,
62              HttpServletRequest httpServletRequest,
63              HttpServletResponse httpServletResponse) {
64  
65  
66          Iti66SearchParameters parameters = Iti66SearchParameters.builder()
67                  .created(created)
68                  .authorFamilyName(authorFamilyName)
69                  .authorGivenName(authorGivenName)
70                  .type(type)
71                  .source(source)
72                  .status(status)
73                  ._id(resourceId)
74                  .sortSpec(sortSpec)
75                  .includeSpec(includeSpec)
76                  .fhirContext(getFhirContext())
77                  .build();
78  
79          String chain = patient.getChain();
80          if (Patient.SP_IDENTIFIER.equals(chain)) {
81              parameters.setPatientIdentifier(patient.toTokenParam(getFhirContext()));
82          } else if (chain == null || chain.isEmpty()) {
83              parameters.setPatientReference(patient);
84          }
85  
86          // Run down the route
87          return requestBundleProvider(null, parameters, httpServletRequest, httpServletResponse);
88      }
89  
90      /**
91       * Handles DocumentManifest Retrieve. This is not an actual part of the ITI-66 specification, but in the
92       * context of restful FHIR IHE transaction it makes sense to be able to retrieve a DocumentManifest by
93       * its resource ID.
94       *
95       * @param id resource ID
96       * @param httpServletRequest servlet request
97       * @param httpServletResponse servlet response
98       * @return {@link DocumentManifest} resource
99       */
100     @SuppressWarnings("unused")
101     @Read(version = true, type = DocumentManifest.class)
102     public DocumentManifest documentManifestRetrieve(
103             @IdParam IdType id,
104             HttpServletRequest httpServletRequest,
105             HttpServletResponse httpServletResponse) {
106         if (id == null) throw new InvalidRequestException("Must provide ID with READ request");
107         // Run down the route
108         return requestResource(id, DocumentManifest.class, httpServletRequest, httpServletResponse);
109     }
110 
111 }