View Javadoc
1   /*
2    * Copyright 2015 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.iti78;
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.*;
24  import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
25  import org.hl7.fhir.dstu3.model.IdType;
26  import org.hl7.fhir.dstu3.model.Patient;
27  import org.hl7.fhir.instance.model.api.IAnyResource;
28  import org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import java.util.Set;
33  
34  /**
35   * Resource Provider for PDQm (ITI-78) for DSTU2
36   *
37   * @author Christian Ohr
38   * @since 3.4
39   */
40  public class Iti78ResourceProvider extends AbstractPlainProvider {
41  
42      /**
43       * Handles the PDQm Query request
44       *
45       * @param identifiers         patient identifier search parameter
46       * @param active              the active state indicates whether the patient record is active
47       * @param family              family name search parameter(s)
48       * @param given               family name search parameter(s)
49       * @param birthDate           birth date search parameter
50       * @param address             address search parameter
51       * @param gender              gender search parameter
52       * @param resourceId          _id search parameter
53       * @param telecom             telecom search parameter
54       * @param httpServletRequest  servlet request
55       * @param httpServletResponse servlet response
56       * @param sortSpec            sort specification
57       * @param includeSpec         include specification
58       * @return {@link IBundleProvider} instance that manages retrieving patients
59       */
60      @SuppressWarnings("unused")
61      @Search(type = PdqPatient.class)
62      public IBundleProvider pdqmSearch(
63              @OptionalParam(name = Patient.SP_IDENTIFIER) TokenAndListParam identifiers,
64              @OptionalParam(name = Patient.SP_ACTIVE) TokenParam active,
65              @OptionalParam(name = Patient.SP_FAMILY) StringAndListParam family,
66              @OptionalParam(name = Patient.SP_GIVEN) StringAndListParam given,
67              @OptionalParam(name = Patient.SP_BIRTHDATE) DateAndListParam birthDate,
68              @OptionalParam(name = Patient.SP_ADDRESS) StringParam address,
69              @OptionalParam(name = Patient.SP_ADDRESS_CITY) StringParam city,
70              @OptionalParam(name = Patient.SP_ADDRESS_COUNTRY) StringParam country,
71              @OptionalParam(name = Patient.SP_ADDRESS_STATE) StringParam state,
72              @OptionalParam(name = Patient.SP_ADDRESS_POSTALCODE) StringParam postalCode,
73              @OptionalParam(name = Patient.SP_GENDER) TokenParam gender,
74              @OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId,
75              @OptionalParam(name = Patient.SP_TELECOM) StringParam telecom,
76              @Sort SortSpec sortSpec,
77              @IncludeParam Set<Include> includeSpec,
78  
79              HttpServletRequest httpServletRequest,
80              HttpServletResponse httpServletResponse) {
81  
82          Iti78SearchParameters searchParameters = Iti78SearchParameters.builder()
83                  .identifiers(identifiers)
84                  .active(active)
85                  .family(family)
86                  .given(given)
87                  .birthDate(birthDate)
88                  .address(address)
89                  .city(city)
90                  .country(country)
91                  .state(state)
92                  .postalCode(postalCode)
93                  .gender(gender)
94                  ._id(resourceId)
95                  .telecom(telecom)
96                  .sortSpec(sortSpec)
97                  .includeSpec(includeSpec)
98                  .fhirContext(getFhirContext())
99                  .build();
100 
101         // Run down the route
102         return requestBundleProvider(null, searchParameters, httpServletRequest, httpServletResponse);
103     }
104 
105 
106     /**
107      * Handles the PDQm Retrieve
108      *
109      * @param id                  resource ID
110      * @param httpServletRequest  servlet request
111      * @param httpServletResponse servlet response
112      * @return patient resource
113      */
114     @SuppressWarnings("unused")
115     @Read(version = true, type = Patient.class)
116     public Patient pdqmRetrieve(
117             @IdParam IdType id,
118             HttpServletRequest httpServletRequest,
119             HttpServletResponse httpServletResponse) {
120 
121         if (id == null) throw new InvalidRequestException("Must provide ID with READ request");
122         // Run down the route
123         return requestResource(id, Patient.class, httpServletRequest, httpServletResponse);
124     }
125 
126 }