This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
/
RestfulEncounterResourceProvider.java
150 lines (135 loc) · 5.3 KB
/
RestfulEncounterResourceProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.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://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.fhir.providers;
import java.util.List;
import org.openmrs.module.fhir.api.util.FHIRConstants;
import org.openmrs.module.fhir.resources.FHIREncounterResource;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Encounter;
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
public class RestfulEncounterResourceProvider implements IResourceProvider {
private FHIREncounterResource encounterResource;
public RestfulEncounterResourceProvider() {
encounterResource = new FHIREncounterResource();
}
@Override
public Class<? extends IResource> getResourceType() {
return Encounter.class;
}
/**
* The "@Read" annotation indicates that this method supports the read operation. Read
* operations should return a single resource instance.
*
* @param theId The read operation takes one parameter, which must be of type IdDt and must be
* annotated with the "@Read.IdParam" annotation.
* @return Returns a resource matching this identifier, or nu ll if none exists.
*/
@Read()
public Encounter getResourceById(@IdParam IdDt theId) {
Encounter result = null;
result = encounterResource.getByUniqueId(theId);
return result;
}
/**
* Search locations by unique id
*
* @param id object containing the requested id
*/
@Search()
public List<Encounter> searchEncountersByUniqueId(@RequiredParam(name = Encounter.SP_RES_ID) TokenParam id) {
return encounterResource.searchEncountersById(id);
}
/**
* Search encounters by patient identifier
*
* @param identifier object containing the patient identifier
*/
@Search()
public List<Encounter> searchEncountersByPatientIdentifier(@RequiredParam(name = Encounter.SP_PATIENT, chainWhitelist = { Patient.SP_IDENTIFIER }) ReferenceParam identifier) {
return encounterResource.searchEncountersByPatientIdentifier(identifier);
}
/**
* Search encounters by patient identifier and encounter part of
*
* @param patientIdentifier the patient identifier
* @param partOf the top level visit
*/
@Search()
public List<Encounter> searchEncountersByPatientIdentifierAndPartOf(@RequiredParam(name = Encounter.SP_PATIENT, chainWhitelist = { Patient.SP_IDENTIFIER }) ReferenceParam patientIdentifier,
@RequiredParam(name = Encounter.SP_PART_OF) ReferenceParam partOf) {
return encounterResource.searchEncountersByPatientIdentifierAndPartOf(patientIdentifier, partOf);
}
/**
* Search encounters by patient identifier and encounter part of
*
* @param encounterId the encounter id
* @param partOf the top level visit
*/
@Search()
public List<Encounter> searchEncountersByIdAndPartOf(@RequiredParam(name = Encounter.SP_RES_ID) TokenParam encounterId,
@RequiredParam(name = Encounter.SP_PART_OF) ReferenceParam partOf) {
return encounterResource.searchEncountersByIdAndPartOf(encounterId, partOf);
}
/**
* Implementation of $everything operation which retunrs content of a encounter
*
* @param encounterId if of the encounter
* @return bundle
*/
@Operation(name = "$everything", type = Encounter.class)
public Bundle encounterInstanceOperation(@IdParam IdDt encounterId) {
return encounterResource.getEncounterOperationsById(encounterId);
}
/**
* Delete encounter by unique id
*
* @param theId
*/
@Delete
public void deleteEncounter(@IdParam IdDt theId) {
encounterResource.deleteEncounter(theId);
}
/**
* Create Encounter
*
* @param encounter fhir encounter oobject
* @return This method returns Meth codOutcome object, which contains information about the
* create operation
*/
@Create
public MethodOutcome createFHIRPatient(@ResourceParam Encounter encounter) {
encounter = encounterResource.createFHIREncounter(encounter);
MethodOutcome retVal = new MethodOutcome();
retVal.setId(new IdDt(FHIRConstants.ENCOUNTER, encounter.getId().getIdPart()));
OperationOutcome outcome = new OperationOutcome();
outcome.addIssue().setDetails("Encounter is successfully created");
retVal.setOperationOutcome(outcome);
return retVal;
}
}