forked from PSMRI/HWC-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservationExtProvider.java
More file actions
147 lines (131 loc) · 8.01 KB
/
ObservationExtProvider.java
File metadata and controls
147 lines (131 loc) · 8.01 KB
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
package com.iemr.hwc.fhir.provider.observation;
import ca.uhn.fhir.rest.annotation.Create;
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.DateParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastHistoryDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastIllnessDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastSurgeryDTO;
import com.iemr.hwc.fhir.model.observation.ObservationExt;
import com.iemr.hwc.fhir.service.observation.ObservationService;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@Component
public class ObservationExtProvider implements IResourceProvider {
@Autowired
private ObservationService observationService;
@Override
public Class<? extends IBaseResource> getResourceType() {
return ObservationExt.class;
}
@Create()
public MethodOutcome createObservation(HttpServletRequest theRequest, @ResourceParam ObservationExt observationExt) throws Exception{
MethodOutcome method = new MethodOutcome();
method.setCreated(true);
OperationOutcome opOutcome = new OperationOutcome();
method.setOperationOutcome(opOutcome);
method.setResource(observationService.createObservation(theRequest,observationExt));
return method;
}
@Search()
public List<ObservationExt> findHistoryByLocationAndLastModifDate(@RequiredParam(name = "providerServiceMapId") StringParam providerServiceMapId, @RequiredParam(name = "vanID") StringParam vanID,
@RequiredParam(name = "lastModif") DateParam lastModifyDate) {
List<ObservationExt> listRes = new ArrayList<>();
List<PastHistoryDTO> ListHistoryDTO = observationService.getBenMedHistoryByLocationAndLastModifDate(Integer.parseInt(providerServiceMapId.getValue()), Integer.parseInt(vanID.getValue()),
new Timestamp(lastModifyDate.getValue().getTime()));
try {
for (int i = 0; i < ListHistoryDTO.size(); i++) {
PastHistoryDTO historyDTO = ListHistoryDTO.get(i);
ObservationExt historyObservation = new ObservationExt();
historyObservation.setId(historyDTO.getId()+"");
historyObservation.setVanID(new StringType(historyDTO.getVanID()+""));
historyObservation.setParkingPlaceID(new StringType(historyDTO.getParkingPlaceID()+""));
historyObservation.setCreatedBy(new StringType(historyDTO.getCreatedBy()));
historyObservation.setProviderServiceMapId(new StringType(historyDTO.getProviderServiceMapID()+""));
historyObservation.setBeneficiaryRegID(new StringType(historyDTO.getBeneficiaryRegID()+""));
historyObservation.setBeneficiaryID(new StringType(historyDTO.getBeneficiaryID()+""));
historyObservation.setBenFlowID(new StringType(historyDTO.getBenFlowID()+""));
List<CodeableConcept> codeableConceptList1 = new ArrayList<>();
CodeableConcept codeableConcept1 = new CodeableConcept();
codeableConcept1.setText("History");
List<Coding> codingList1 = new ArrayList<>();
Coding coding1 = new Coding();
coding1.setSystem("http://terminology.hl7.org/CodeSystem/observation-category");
coding1.setCode("social-history");
coding1.setDisplay("Social History");
codingList1.add(coding1);
codeableConcept1.setCoding(codingList1);
codeableConceptList1.add(codeableConcept1);
historyObservation.setCategory(codeableConceptList1);
CodeableConcept codeableConcept2 = new CodeableConcept();
codeableConcept2.setText("Past medical history");
List<Coding> codingList2 = new ArrayList<>();
Coding coding2 = new Coding();
coding2.setSystem("http://loinc.org/");
coding2.setCode("11348-0");
coding2.setDisplay("Past medical history");
codingList2.add(coding2);
codeableConcept2.setCoding(codingList2);
historyObservation.setCode(codeableConcept2);
List<Observation.ObservationComponentComponent> listComponent = new ArrayList<>();
List<PastIllnessDTO> pastIllnessDTOList = historyDTO.getPastIllness();
List<PastSurgeryDTO> pastSurgeryDTOList = historyDTO.getPastSurgery();
if(pastIllnessDTOList!=null && !pastIllnessDTOList.isEmpty()){
for (int j = 0; j < pastIllnessDTOList.size(); j++) {
Observation.ObservationComponentComponent observation1 = new Observation.ObservationComponentComponent();
CodeableConcept codeableConcept3 = new CodeableConcept();
List<Coding> codingList3 = new ArrayList<>();
Coding coding3 = new Coding();
coding3.setCode(pastIllnessDTOList.get(j).getIllnessTypeID());
coding3.setDisplay(pastIllnessDTOList.get(j).getIllnessType());
codingList3.add(coding3);
codeableConcept3.setCoding(codingList3);
codeableConcept3.setText("pastIllness");
observation1.setCode(codeableConcept3);
Type type = new Quantity();
if(pastIllnessDTOList.get(j).getTimePeriodAgo() !=null && !pastIllnessDTOList.get(j).getTimePeriodAgo().equals("null")){
type = new Quantity(Quantity.QuantityComparator.NULL, 0L, "", pastIllnessDTOList.get(j).getTimePeriodAgo(), pastIllnessDTOList.get(j).getTimePeriodUnit());
}
observation1.setValue(type);
listComponent.add(observation1);
}
}
if(pastSurgeryDTOList!=null && !pastSurgeryDTOList.isEmpty()){
for (int j = 0; j < pastSurgeryDTOList.size(); j++) {
Observation.ObservationComponentComponent observation2 = new Observation.ObservationComponentComponent();
CodeableConcept codeableConcept3 = new CodeableConcept();
List<Coding> codingList3 = new ArrayList<>();
Coding coding3 = new Coding();
coding3.setCode(pastSurgeryDTOList.get(j).getSurgeryID());
coding3.setDisplay(pastSurgeryDTOList.get(j).getSurgeryType());
codingList3.add(coding3);
codeableConcept3.setCoding(codingList3);
codeableConcept3.setText("pastSurgery");
observation2.setCode(codeableConcept3);
Type type = new Quantity();
if(pastSurgeryDTOList.get(j).getTimePeriodAgo() !=null && !pastSurgeryDTOList.get(j).getTimePeriodAgo().equals("null")){
type = new Quantity(Quantity.QuantityComparator.NULL, 0L, "", pastSurgeryDTOList.get(j).getTimePeriodAgo(), pastSurgeryDTOList.get(j).getTimePeriodUnit());
}
observation2.setValue(type);
listComponent.add(observation2);
}
}
historyObservation.setComponent(listComponent);
listRes.add(historyObservation);
}
}
catch (Exception e){
}
return listRes;
}
}