1
1
<?php
2
2
3
+ /**
4
+ * FhirEncounterService
5
+ *
6
+ * @package OpenEMR
7
+ * @link http://www.open-emr.org
8
+ * @author Yash Bothra <yashrajbothra786@gmail.com>
9
+ * @author Stephen Waite <stephen.waite@cmsvt.com>
10
+ * @author Vishnu Yarmaneni <vardhanvishnu@gmail.com>
11
+ * @author Brady Miller <brady.g.miller@gmail.com>
12
+ * @author Stephen Nielson snielson@discoverandchange.com
13
+ * @copyright Copyright (c) 2020 Yash Bothra <yashrajbothra786@gmail.com>
14
+ * @copyright Copyright (c) 2020, 2022 Stephen Waite <stephen.waite@cmsvt.com>
15
+ * @copyright Copyright (c) 2020 Vishnu Yarmaneni <vardhanvishnu@gmail.com>
16
+ * @copyright Copyright (c) 2021 Brady Miller <brady.g.miller@gmail.com>
17
+ * @copyright Copyright (c) 2022 Stephen Nielson <snielson@discoverandchange.com>
18
+ * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19
+ */
20
+
3
21
namespace OpenEMR \Services \FHIR ;
4
22
5
23
use DateTime ;
25
43
use OpenEMR \Services \Search \ServiceField ;
26
44
use OpenEMR \Validators \ProcessingResult ;
27
45
28
- class FhirEncounterService extends FhirServiceBase implements IFhirExportableResourceService, IPatientCompartmentResourceService, IResourceUSCIGProfileService
46
+ class FhirEncounterService extends FhirServiceBase implements
47
+ IFhirExportableResourceService,
48
+ IPatientCompartmentResourceService,
49
+ IResourceUSCIGProfileService
29
50
{
30
51
use PatientSearchTrait;
31
52
use FhirServiceBaseEmptyTrait;
32
53
use BulkExportSupportAllOperationsTrait;
33
54
use FhirBulkExportDomainResourceTrait;
34
55
35
- const ENCOUNTER_STATUS_FINISHED = "finished " ;
56
+ public const ENCOUNTER_STATUS_FINISHED = "finished " ;
57
+
58
+ public const ENCOUNTER_TYPE_CHECK_UP = "185349003 " ;
59
+ public const ENCOUNTER_TYPE_CHECK_UP_DESCRIPTION = "Encounter for check up (procedure) " ;
36
60
37
- const ENCOUNTER_TYPE_CHECK_UP = "185349003 " ;
38
- const ENCOUNTER_TYPE_CHECK_UP_DESCRIPTION = "Encounter for check up (procedure) " ;
61
+ public const ENCOUNTER_PARTICIPANT_TYPE_PRIMARY_PERFORMER = "PPRF " ;
62
+ public const ENCOUNTER_PARTICIPANT_TYPE_PRIMARY_PERFORMER_TEXT = "Primary Performer " ;
39
63
40
- const ENCOUNTER_PARTICIPANT_TYPE_PRIMARY_PERFORMER = "PPRF " ;
41
- const ENCOUNTER_PARTICIPANT_TYPE_PRIMARY_PERFORMER_TEXT = "Primary Performer " ;
64
+ public const ENCOUNTER_PARTICIPANT_TYPE_REFERRER = "REF " ;
65
+ public const ENCOUNTER_PARTICIPANT_TYPE_REFERRER_TEXT = "Referrer " ;
42
66
43
67
44
68
/**
@@ -59,7 +83,16 @@ public function __construct()
59
83
protected function loadSearchParameters ()
60
84
{
61
85
return [
62
- '_id ' => new FhirSearchParameterDefinition ('_id ' , SearchFieldType::TOKEN , [new ServiceField ('euuid ' , ServiceField::TYPE_UUID )]),
86
+ '_id ' => new FhirSearchParameterDefinition (
87
+ '_id ' ,
88
+ SearchFieldType::TOKEN ,
89
+ [
90
+ new ServiceField (
91
+ 'euuid ' ,
92
+ ServiceField::TYPE_UUID
93
+ )
94
+ ]
95
+ ),
63
96
'patient ' => $ this ->getPatientContextSearchField (),
64
97
'date ' => new FhirSearchParameterDefinition ('date ' , SearchFieldType::DATETIME , ['date ' ])
65
98
];
@@ -107,7 +140,8 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
107
140
$ encounterResource ->setClass (UtilsService::createDataAbsentUnknownCodeableConcept ());
108
141
}
109
142
110
- // TODO: @adunsulag check with @brady.miller and find out if this really is the only possible encounter type... it was here originally
143
+ // TODO: @adunsulag check with @brady.miller and find out if this really is the only possible encounter type
144
+ // ... it was here originally
111
145
$ type = UtilsService::createCodeableConcept (
112
146
[self ::ENCOUNTER_TYPE_CHECK_UP => [
113
147
'code ' => self ::ENCOUNTER_TYPE_CHECK_UP
@@ -127,7 +161,12 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
127
161
// participant - must support
128
162
if (!empty ($ dataRecord ['provider_uuid ' ])) {
129
163
$ participant = new FHIREncounterParticipant ();
130
- $ participant ->setIndividual (UtilsService::createRelativeReference ("Practitioner " , $ dataRecord ['provider_uuid ' ]));
164
+ $ participant ->setIndividual (
165
+ UtilsService::createRelativeReference (
166
+ "Practitioner " ,
167
+ $ dataRecord ['provider_uuid ' ]
168
+ )
169
+ );
131
170
$ period = new FHIRPeriod ();
132
171
$ period ->setStart (DateTime::createFromFormat ("Y-m-d H:i:s " , $ dataRecord ['date ' ])->format ('c ' ));
133
172
$ period ->setStart (gmdate ('c ' , strtotime ($ dataRecord ['date ' ])));
@@ -145,6 +184,32 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
145
184
$ encounterResource ->addParticipant ($ participant );
146
185
}
147
186
187
+ // referring provider
188
+ if (!empty ($ dataRecord ['referrer_uuid ' ])) {
189
+ $ participant = new FHIREncounterParticipant ();
190
+ $ participant ->setIndividual (
191
+ UtilsService::createRelativeReference (
192
+ "Practitioner " ,
193
+ $ dataRecord ['referrer_uuid ' ]
194
+ )
195
+ );
196
+ $ period = new FHIRPeriod ();
197
+ $ period ->setStart (DateTime::createFromFormat ("Y-m-d H:i:s " , $ dataRecord ['date ' ])->format ('c ' ));
198
+ $ period ->setStart (gmdate ('c ' , strtotime ($ dataRecord ['date ' ])));
199
+ $ participant ->setPeriod ($ period );
200
+
201
+ $ participantType = UtilsService::createCodeableConcept ([
202
+ self ::ENCOUNTER_PARTICIPANT_TYPE_REFERRER =>
203
+ [
204
+ 'code ' => self ::ENCOUNTER_PARTICIPANT_TYPE_REFERRER
205
+ ,'description ' => self ::ENCOUNTER_PARTICIPANT_TYPE_REFERRER_TEXT
206
+ ,'system ' => FhirCodeSystemConstants::HL7_PARTICIPATION_TYPE
207
+ ]
208
+ ]);
209
+ $ participant ->addType ($ participantType );
210
+ $ encounterResource ->addParticipant ($ participant );
211
+ }
212
+
148
213
// period - must support
149
214
if (!empty ($ dataRecord ['date ' ])) {
150
215
$ period = new FHIRPeriod ();
@@ -155,9 +220,10 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
155
220
// reasonCode - must support OR must support reasonReference
156
221
if (!empty ($ dataRecord ['reason ' ])) {
157
222
// Note: that we use the encounter textual representation for the reason here which is just fine as ccda
158
- // uses a textual representation of this. According to HL7 chat this is just fine as epoch and other systems
159
- // do it this way
160
- // @see https://chat.fhir.org/#narrow/stream/179175-argonaut/topic/Encounter.20Reason.20For.20Visit (beware of link rot)
223
+ // uses a textual representation of this. According to HL7 chat this is just fine as epoch and
224
+ // other systems do it this way
225
+ // @see https://chat.fhir.org/#narrow/stream/179175-argonaut/topic/Encounter.20Reason.20For.20Visit
226
+ // (beware of link rot)
161
227
$ reason = new FHIRCodeableConcept ();
162
228
$ reasonText = $ dataRecord ['reason ' ] ?? "" ;
163
229
$ reason ->setText (trim ($ reasonText ));
@@ -172,7 +238,13 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
172
238
173
239
$ hospitalization = new FHIREncounterHospitalization ();
174
240
$ hospitalization ->setDischargeDisposition (UtilsService::createCodeableConcept (
175
- [$ code => ['code ' => $ text , 'description ' => $ text , 'system ' => FhirCodeSystemConstants::HL7_DISCHARGE_DISPOSITION ]]
241
+ [
242
+ $ code => [
243
+ 'code ' => $ text ,
244
+ 'description ' => $ text ,
245
+ 'system ' => FhirCodeSystemConstants::HL7_DISCHARGE_DISPOSITION
246
+ ]
247
+ ]
176
248
));
177
249
$ encounterResource ->setHospitalization ($ hospitalization );
178
250
}
@@ -182,12 +254,22 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
182
254
// location.location - must support
183
255
// serviceProvider - must support
184
256
if (!empty ($ dataRecord ['facility_uuid ' ])) {
185
- $ encounterResource ->setServiceProvider (UtilsService::createRelativeReference ('Organization ' , $ dataRecord ['facility_uuid ' ]));
257
+ $ encounterResource ->setServiceProvider (
258
+ UtilsService::createRelativeReference (
259
+ 'Organization ' ,
260
+ $ dataRecord ['facility_uuid ' ]
261
+ )
262
+ );
186
263
187
264
// grab the facility location address
188
265
if (!empty ($ dataRecord ['facility_location_uuid ' ])) {
189
266
$ location = new FHIREncounterLocation ();
190
- $ location ->setLocation (UtilsService::createRelativeReference ("Location " , $ dataRecord ['facility_location_uuid ' ]));
267
+ $ location ->setLocation (
268
+ UtilsService::createRelativeReference (
269
+ "Location " ,
270
+ $ dataRecord ['facility_location_uuid ' ]
271
+ )
272
+ );
191
273
$ encounterResource ->addLocation ($ location );
192
274
}
193
275
}
0 commit comments