1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.ihe.fhir.iti67;
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.DocumentReference;
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public class Iti67ResourceProvider extends AbstractPlainProvider {
57
58 @SuppressWarnings("unused")
59 @Search(type = DocumentReference.class)
60 public IBundleProvider documentReferenceSearch(
61 @RequiredParam(name = DocumentReference.SP_PATIENT, chainWhitelist = {"", Patient.SP_IDENTIFIER}) ReferenceParam patient,
62 @OptionalParam(name = DocumentReference.SP_STATUS) TokenOrListParam status,
63 @OptionalParam(name = DocumentReference.SP_INDEXED) DateRangeParam indexed,
64 @OptionalParam(name = DocumentReference.SP_AUTHOR + "." + Practitioner.SP_FAMILY) StringParam authorFamilyName,
65 @OptionalParam(name = DocumentReference.SP_AUTHOR + "." + Practitioner.SP_GIVEN) StringParam authorGivenName,
66 @OptionalParam(name = DocumentReference.SP_CLASS) TokenOrListParam class_,
67 @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type,
68 @OptionalParam(name = DocumentReference.SP_SETTING) TokenOrListParam setting,
69 @OptionalParam(name = DocumentReference.SP_PERIOD) DateRangeParam period,
70 @OptionalParam(name = DocumentReference.SP_FACILITY) TokenOrListParam facility,
71 @OptionalParam(name = DocumentReference.SP_EVENT) TokenOrListParam event,
72 @OptionalParam(name = DocumentReference.SP_SECURITYLABEL) TokenOrListParam securityLabel,
73 @OptionalParam(name = DocumentReference.SP_FORMAT) TokenOrListParam format,
74 @OptionalParam(name = DocumentReference.SP_RELATED_ID) TokenOrListParam relatedId,
75
76 @OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId,
77 @Sort SortSpec sortSpec,
78 @IncludeParam Set<Include> includeSpec,
79 HttpServletRequest httpServletRequest,
80 HttpServletResponse httpServletResponse) {
81
82 Iti67SearchParameters searchParameters = Iti67SearchParameters.builder()
83 .status(status)
84 .indexed(indexed)
85 .authorFamilyName(authorFamilyName)
86 .authorGivenName(authorGivenName)
87 .class_(class_)
88 .type(type)
89 .setting(setting)
90 .period(period)
91 .facility(facility)
92 .event(event)
93 .securityLabel(securityLabel)
94 .format(format)
95 .relatedId(relatedId)
96 ._id(resourceId)
97 .sortSpec(sortSpec)
98 .includeSpec(includeSpec)
99 .fhirContext(getFhirContext())
100 .build();
101
102 String chain = patient.getChain();
103 if (Patient.SP_IDENTIFIER.equals(chain)) {
104 searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext()));
105 } else if (chain == null || chain.isEmpty()) {
106 searchParameters.setPatientReference(patient);
107 }
108
109
110 return requestBundleProvider(null, searchParameters, httpServletRequest, httpServletResponse);
111 }
112
113
114
115
116
117
118
119
120
121
122
123 @SuppressWarnings("unused")
124 @Read(version = true, type = DocumentReference.class)
125 public DocumentReference documentReferenceRetrieve(
126 @IdParam IdType id,
127 HttpServletRequest httpServletRequest,
128 HttpServletResponse httpServletResponse) {
129 if (id == null) throw new InvalidRequestException("Must provide ID with READ request");
130
131 return requestResource(id, DocumentReference.class, httpServletRequest, httpServletResponse);
132 }
133 }