View Javadoc
1   /*
2    * Copyright 2018 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.pcc44;
18  
19  import ca.uhn.fhir.rest.annotation.IdParam;
20  import ca.uhn.fhir.rest.annotation.Read;
21  import org.hl7.fhir.dstu3.model.DocumentManifest;
22  import org.hl7.fhir.dstu3.model.IdType;
23  import org.hl7.fhir.instance.model.api.IBaseResource;
24  import org.openehealth.ipf.commons.ihe.fhir.AbstractResourceProvider;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * @author Christian Ohr
31   */
32  
33  // Must be public
34  public abstract class AbstractPcc44ResourceProvider<T extends IBaseResource> extends AbstractResourceProvider {
35  
36      private final Class<T> clazz;
37  
38      protected AbstractPcc44ResourceProvider(Class<T> clazz) {
39          this.clazz = clazz;
40      }
41  
42      @Override
43      public Class<T> getResourceType() {
44          return clazz;
45      }
46  
47      /**
48       * Handles Retrieve. This is not an actual part of the PCC-44 specification, but in the
49       * context of restful FHIR IHE transaction it makes sense to be able to retrieve a resource by
50       * its ID.
51       *
52       * @param id                  resource ID
53       * @param httpServletRequest  servlet request
54       * @param httpServletResponse servlet response
55       * @return {@link DocumentManifest} resource
56       */
57      @SuppressWarnings("unused")
58      @Read(version = true)
59      public T retrieve(
60              @IdParam IdType id,
61              HttpServletRequest httpServletRequest,
62              HttpServletResponse httpServletResponse) {
63  
64          // Run down the route
65          return requestResource(id, clazz, httpServletRequest, httpServletResponse);
66      }
67  }