-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRESTHandler.csp
632 lines (553 loc) · 21.5 KB
/
RESTHandler.csp
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
Class GLHC.ResultsViewer.ResultsViewerDispatch Extends %CSP.REST
{
Parameter HandleCorsRequest = 0;
// Parameter UseSession = 1;
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/routes/:inData" Method="GET" Call="GetRoutes" Cors="false"/>
<Route Url="/test" Method="GET" Call="Get" Cors="false"/>
<Route Url="/search/:inData" Method="GET" Call="GetSearchResult" Cors="false"/>
<Route Url="/destinationsearch/:inData" Method="GET" Call="DDDestinationSearch" Cors="false"/>
<Route Url="/destinationroute/:inData" Method="GET" Call="DDDestinationRoute" Cors="false"/>
<Route Url="/source/:inData" Method="GET" Call="DDSource" Cors="false"/>
<Route Url="/providersnames/:inData" Method="GET" Call="DDProvider" Cors="false"/>
<Route Url="/emr/:inData" Method="GET" Call="DDEMR" Cors="false"/>
<Route Url="/detail/:inData" Method="GET" Call="GetDetail" Cors="false"/>
<Route Url="/pdfhl7/:inData" Method="GET" Call="GetPDFHL7" Cors="false"/>
<Route Url="/providers/:inData" Method="GET" Call="GetProviders" Cors="false"/>
<Route Url="/replay/:inData" Method="GET" Call="GetReplay" Cors="false"/>
<Route Url="/refresh" Method="GET" Call="Get" Cors="false"/>
<Route Url="/login" Method="GET" Call="LoginAudit" Cors="false"/>
<Route Url="/logout" Method="GET" Call="LogoutAudit" Cors="false"/>
</Routes>
}
// Method for pooling user activity
ClassMethod Get() As %Status
{
write "success!"
return $$$OK
}
// Message replay
ClassMethod GetReplay(inData As %String) As %Status
{
set data = {}.%FromJSON(inData)
set messageid = data.messageid
set pEventName = "Login"
//do ##class(GLHC.ResultsViewer.Helpers).CustomAuditEvent(pEventName)
return $$$OK
}
// Login event tracking
ClassMethod LoginAudit() As %Status
{
set pEventName = "Login"
//do ##class(GLHC.ResultsViewer.Helpers).CustomAuditEvent(pEventName)
return $$$OK
}
// Logout event tracking
ClassMethod LogoutAudit() As %Status
{
write "Logged out"
set pEventName = "Logout"
//do ##class(GLHC.ResultsViewer.Helpers).CustomAuditEvent(pEventName)
return $$$OK
}
/// Gives HL7 using the rawcontentget for full, longer messages
ClassMethod GetPDFHL7(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
set messageid = data.messageid
//set messageid = "96758313"
// Sanitation
set messageid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(messageid)
do ##class(LinkedProcedure.GeneratePDF).GeneratePDF(messageid)
&sql(SELECT pdf INTO :stream FROM LinkedTable.PDFs WHERE pdfid = :messageid)
While (stream.AtEnd = 0) {
Set len = $$$MaxStringLength
write $system.Encryption.Base64Encode(stream.Read(.len))
}
}
catch ex {
write ex.Name
}
// Attempt to delete regardless
try { do ##class(LinkedProcedure.KillPDF).KillPDF(messageid) } catch ex { write ex.Name }
return $$$OK
}
// Drop down query to get destinations applicable to user
ClassMethod DDDestinationRoute(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
// Sanitation
set optional = "-()."
set data.source = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(data.source,optional)
set user = $username
set source = ""
if data.source '= "" {
set source = " and sourceorganization = '"_data.source_"' "
}
// SQL definitions
set tSelect = "SELECT Distinct OrganizationName"
set tFrom = "FROM LinkedTable.vwAdminProviderRoutes"
set tWhere = "where sourceorganization in ("_..GetFacilities()_") "_source_
"ORDER BY OrganizationName Asc"
//write tSelect_" "_tFrom_" "_tWhere
write ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
}
catch ex {
write ex.Name
}
return $$$OK
}
// Drop down query to get destinations applicable to user
ClassMethod DDDestinationSearch(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
set user = $username
// Sanitation
set optional = "-()."
set data.source = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(data.source,optional)
set source = ""
if data.source '= "" {
set source = " and sourceorganization = '"_data.source_"' "
}
// SQL definitions
set tSelect = "SELECT Distinct OrganizationName, OrganizationID"
set tFrom = "FROM LinkedTable.vwAdminProviderRoutes"
set tWhere = "where sourceorganization in ("_..GetFacilities()_") and active=1 "_source_
"ORDER BY OrganizationName Asc"
//write tSelect_" "_tFrom_" "_tWhere
write ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
}
catch ex {
write ex.Name
}
return $$$OK
}
// Drop down query to get providers
ClassMethod DDProvider(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
set destination = data.destination
set source = data.source
// Sanitation
set optional = ""
set destination = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(destination,optional)
set source = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(source,optional)
set tDest = ""
if destination '= "" {
set tDest = "DestinationID = "_destination_" and"
}
// SQL definitions
set tSelect = "SELECT distinct ProvNPI, LastName, FirstName"
set tFrom = "FROM LinkedTable.vwAdminProviderPicklist"
set tWhere = "where "_tDest_" Source = '"_source_"' order by LastName Asc"
write ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
}
catch ex {
write ex.Name
}
return $$$OK
}
ClassMethod SQLBuilder(pquery) As %String
{
return ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(pquery)
}
ClassMethod GetFacilities(pUser As %String = "", pWhich As %String = "OrganizationName") As %Status
{
try {
set query = "SELECT "_pWhich_" FROM LinkedTable.Organizations where FacilityID in ("_##class(GLHC.Notifications.WebService.GatewayDispatchClass).GetFacilities()_")"
set facilities = ..SQLBuilder(query)
//return facilities
set returnFacilities = ""
set sc = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(facilities,,.obj,1)
for i=1:1:obj.Count() {
if pWhich = "id" {
set returnFacilities = returnFacilities_"'"_obj.GetAt(i).ID_"',"
} else {
set returnFacilities = returnFacilities_"'"_obj.GetAt(i).OrganizationName_"',"
}
}
return $extract(returnFacilities,",",*-1)
}
catch(e) {
w e.Name
}
return $$$OK
}
// Drop down query to get sources applicable to user
ClassMethod DDSource(inData As %String) As %Status
{
try {
//set data = {}.%FromJSON(inData)
set user = $username
// SQL definitions
//set tStatement=##class(%SQL.Statement).%New()
set query = "SELECT OrganizationName FROM LinkedTable.Organizations where FacilityID in ("_##class(GLHC.Notifications.WebService.GatewayDispatchClass).GetFacilities()_")"
write ..SQLBuilder(query)
}
catch ex {
write ex.Name
}
return $$$OK
}
// Drop down query to get EMR filter choices
ClassMethod DDEMR(inData As %String) As %Status
{
try {
//set data = {}.%FromJSON(inData)
set user = $username
// SQL definitions
set tSelect = "SELECT Distinct EMR"
set tFrom = "FROM LinkedTable.vwAdminProviderRoutes"
set tWhere = "where EMR is not null and sourceorganization in ("_..GetFacilities()_") "_
"ORDER BY EMR Asc"
set pQuery = tSelect_" "_tFrom_" "_tWhere
write ..SQLBuilder(pQuery)
}
catch ex {
write ex.Name
}
return $$$OK
}
ClassMethod GetRawContent(pId) As %String
{
return ##class(LinkedProcedure.GetRawContent).GetRawContent(pId)
}
ClassMethod GeneratePDF(hl7) As %String
{
return ##class(LinkedProcedure.GeneratePDF).GeneratePDF(hl7)
}
// Gets details from a specific search result as json
ClassMethod GetDetail(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
set sessionid = data.payload.sessionid
set routeid = data.payload.routeid
set controlid = data.payload.controlid
set orgid = data.payload.orgid
set deliveredmsgid = data.payload.messagebodyid
// Sanitation
set sessionid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(sessionid)
set routeid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(routeid)
set controlid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(controlid,"_-.")
set orgid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(orgid)
set deliveredmsgid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerNumber(deliveredmsgid)
set user = $username
set details = {}
set tSelect = "select *, %vid from (select t.SessionID, t.RouteID, Delivered_Config, Delivery_Status, DeliveryQueued, DeliveredMessageBodyID, ConnectionEnabled, ConnectionType, Port, IPAddress, ACKReceived, ACK "
set tFrom = "FROM LinkedTable.vwAdminMessageDetailDelivered t inner join LinkedTable.logroutesviewer r on r.sessionid = t.sessionid "
set tWhere = "WHERE DeliveredMessageBodyID = '"_deliveredmsgid_"' and r.sourceorgid in ("_..GetFacilities(,"id")_")) v where %vid between 1 and 1"
//w tSelect_tFrom_tWhere
//return $$$OK
// Store query for logging
set deliveryquery = tSelect_" "_tFrom_" "_tWhere
set Delivery = ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
set tSelect = "select *, %vid from (select Original_Source, CommonMessageBodyID, OriginalMessageBodyID, Original_Status, Original_TimeProcessed, Common_Router, Common_Status, Common_TimeProcessed "
set tFrom = "FROM LinkedTable.vwAdminMessageDetailCommon t inner join LinkedTable.logroutesviewer r on r.sessionid = t.sessionid "
set tWhere = "WHERE t.sessionid = '"_sessionid_"' and r.sourceorgid in ("_..GetFacilities(,"id")_")) v where %vid between 1 and 1"
//w tSelect_tFrom_tWhere
//return $$$OK
// Store query for logging
set predeliveryquery = tSelect_" "_tFrom_" "_tWhere
set PreDelivery = ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
// Audit detail formation
// Define the object that will hold our json event details
set eventDetails = {}
set eventDetails.sessionid = data.payload.sessionid
set eventDetails.routeid = data.payload.routeid
set eventDetails.firstname = data.payload.firstname
set eventDetails.lastname = data.payload.lastname
set eventDetails.mrn = data.payload.mrn
set eventDetails.source = data.payload.source
set eventDetails.dob = data.payload.dob
set eventDetails.resulttype = data.payload.resulttype
set eventDetails.deliveryquery = deliveryquery
set eventDetails.predeliveryquery = predeliveryquery
do ##class(GLHC.ResultsViewer.Helpers).AuditEvent("GetDetail",eventDetails.%ToJSON(),"User viewed data from a specific message, invoking SQL queries defined in Event Data")
// Continue forming data for user
try {
// Extracts the hl7 so that it isn't truncated
set mutation = {}.%FromJSON(PreDelivery)
set Common = ..GetRawContent(mutation.tRow.CommonMessageBodyID)
set mutation.tRow."Common_HL7" = Common
set Original = ..GetRawContent(mutation.tRow.OriginalMessageBodyID)
set mutation.tRow."Original_HL7" = Original
set PreDelivery = mutation.%ToJSON()
set details.PreDelivery = PreDelivery
}
catch(e) {
//write "predelivery error"
}
try {
set mutation = {}.%FromJSON(Delivery)
set Delivered = ..GetRawContent(mutation.tRow.DeliveredMessageBodyID)
set mutation.tRow."Delivered_HL7" = Delivered
set Delivery = mutation.%ToJSON()
set details.Delivery = Delivery
}
catch(e) {
//write "delivery error"
}
write details.%ToJSON()
}
catch ex {
write ex.Name
}
return $$$OK
}
// Gets list of providers for use in a drop down
ClassMethod GetProviders(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
//set user = $username
set organizationid = data.payload.organizationid
set sourceorgid = data.payload.sourceorgid
// SQL injection sanitation
set optional = ".-()"
set sourceorgid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(sourceorgid,optional) //$REPLACE(sourceorganization,"'","''")
set organizationid = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(organizationid,optional) //$REPLACE(organizationid,"'","''")
set tSelect = "SELECT DISTINCT o.OrganizationName, o.Type, o3.OrganizationName as EMR, o.Contact, o.Phone, o.Email, p.ProvNPI as NPI, p.LastName, p.FirstName, p2.ProvID as Code "
set tFrom = "FROM LinkedTable.Organizations o LEFT JOIN LinkedTable.Organizations o3 on o.EMR = o3.id INNER JOIN LinkedTable.OrganizationProviderList pl on pl.Organizationid = o.id "_
"INNER JOIN LinkedTable.OrganizationProviderListProviders p on p.providerlistid = pl.id "_
"INNER JOIN LinkedTable.OrganizationProviderListProviders p2 on p.provNPI = p2.provNPI "_
"INNER JOIN LinkedTable.OrganizationProviderList pl2 on pl2.id = p2.providerlistid "_
"INNER JOIN LinkedTable.Organizations o2 on pl2.organizationid = o2.id "
set tWhere = "where o.id = "_organizationid_" and o2.id = '"_sourceorgid_"'"
//set tWhere = "where o.id = 98 and pl2.organizationid = "_organizationid
//w tSelect_tFrom_tWhere
//write tSelect_tFrom_tWhere
set pQuery = tSelect_" "_tFrom_" "_tWhere
write ..SQLBuilder(pQuery)
}
catch ex {
write ex.Name
}
return $$$OK
}
// Method for handling form data query building
ClassMethod Foreach(pInData) As %String
{
//write pInData.%ToJSON()
try {
// Instantiate the query string, it may be empty by design
set tFilterParam = ""
// We get the key value pairs from our dynamic object
set tIter = pInData.%GetIterator()
// Init date beginning
set tFrom = ""
// Init ResultType tracker
set tFoundResult = 0
// Init Delivery Status tracker
set tFoundStatus = 0
// Loop through these values and add to our query depending on their contents
while tIter.%GetNext(.key, .value) {
set tIterw = value.%GetIterator()
while tIterw.%GetNext(.key, .value) {
set tIters = value.%GetIterator()
while tIters.%GetNext(.key, .value) {
//write key_" "_value
if value '= "" {
// Sanitation
set key = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerKey(key)
// If this is the first occurance of a delivery status
if tFoundStatus = 0 {
if key = "DeliveryStatus" {
// set trigger because we've hit the first result type
set tFoundStatus = 1
// Init element tracking
set counter = 0
// Init size of dynamic object
set size = 0
set tSubIter = value.%GetIterator()
// Loop to get the size of dynamic object
while tSubIter.%GetNext() {
set size = size + 1
}
// Get new iterator so that we can loop through object again
set tSubIter = value.%GetIterator()
while tSubIter.%GetNext(.subkey, .subvalue) {
if subkey '= "" {
set subvalue = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(subvalue,"-")
// If this is the first field in the object
if counter = 0 {
set tFilterParam = tFilterParam_" and ("_key_"='"_subvalue_"'"
}
// Otherwise we make 'or' logic in the string for subsquent fields
else {
set tFilterParam = tFilterParam_" or "_key_"='"_subvalue_"'"
}
// Increment counter so that we know future fields aren't the first occurance
set counter = counter + 1
}
}
// Close 'or' logic
set tFilterParam = tFilterParam_")"
}
}
// If this is the first occurance of a result type
if tFoundResult = 0 {
if key = "ResultType" {
// set trigger because we've hit the first result type
set tFoundResult = 1
set tSubIter = value.%GetIterator()
// Init element tracking
set counter = 0
// Init size of dynamic object
set size = 0
// Loop to get the size of dynamic object
while tSubIter.%GetNext() {
set size = size + 1
}
// Get new iterator so that we can loop through object again
set tSubIter = value.%GetIterator()
while tSubIter.%GetNext(.subkey, .subvalue) {
if subkey '= "" {
set subvalue = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(subvalue,"-")
// If this is the first field in the object
if counter = 0 {
set tFilterParam = tFilterParam_" and ("_key_"='"_subvalue_"'"
}
// Otherwise we make 'or' logic in the string for subsquent fields
else {
set tFilterParam = tFilterParam_" or "_key_"='"_subvalue_"'"
}
// Increment counter so that we know future fields aren't the first occurance
set counter = counter + 1
}
}
// Close 'or' logic
set tFilterParam = tFilterParam_")"
}
}
// Sanitation
set value = ##class(GLHC.ResultsViewer.Helpers).SQLInjectionHandlerValue(value,".-()")
// Removes single quotes from user input so that the query isn't messed up
set value = $REPLACE(value,"'","''")
// Date handling section
if key = "ProcessedDateTimeFrom" {
// set higher level var to the from date
set tFrom = value
continue
}
if key = "ProcessedDateTimeTo" {
// Combine from and to for a full sql string
set tFrom = $extract(tFrom,1,13)_":"_$extract(tFrom,14,15)
set value = $extract(value,1,13)_":"_$extract(value,14,15)
set tFilterParam = tFilterParam_" and l.CreateTS BETWEEN '"_tFrom_":00' and '"_value_":00'"
continue
}
if key = "DeliveredResults" {
if value = "Delivered" {
set tFilterParam = tFilterParam_" and RouteID IS NOT NULL"
}
else {
set tFilterParam = tFilterParam_" and RouteID IS NULL"
}
continue
}
// Handler to skip adding ghost DynamicArray object to string building
if key = "ResultType" {
continue
}
if key = "DeliveryStatus" {
continue
}
if key = "DestOrgID" {
set tFilterParam = tFilterParam_" and DestOrgID="_value
continue
}
// If the key isn't special, just use its key name and value to make a sql string
set tFilterParam = tFilterParam_" and "_key_"='"_value_"'"
}
}
}
}
}
catch(e) {
//write e
}
// Pass the full sql clauses
return tFilterParam
}
// Builds search params from user and gets result as json
ClassMethod GetSearchResult(inData As %String) As %Status
{
try {
set data = {}.%FromJSON(inData)
set user = $username
// SQL definitions
set tStatement = ##class(%SQL.Statement).%New()
set myquery = 4
set tSelect = "SELECT top 1000 l.providerfirstname as ProvFirstName, "_
"l.providerlastname as ProvLastName, l.CreateTS as ProcessedDateTime, l.SourceOID,"_
" l.ResultType, l.RouteID, l.MessageControlID, l.MessageDateTime, l.PatientLastName,"_
"l.PatientFirstName, l.PatientDOB, l.MRN, l.AccessionID, l.ResultStatus, l.PatientClass, "_
"l.OBRLOINCDescription,l.DocumentType, COALESCE(l.OBRLOINCDescription,l.DocumentType) as Report,"_
" l.OBRUniversalServiceID, l.SessionID, l.DelayEntry, l.DestinationStatus, l.SourceOrgName"_
" as Source, l.DestOrgName as Destination, l.providerid, l.providerrole, l.deliverystatus, l.DestOrgId, l.DeliveredMsgId"
set tFrom = "FROM LinkedTable.LogRoutesViewer l"
set tWhere = "where l.sourceorgid in ("_..GetFacilities(,"id")_")"_ ..Foreach(data)_" ORDER BY l.ID DESC"
// Return json result of query
set query = tSelect_" "_tFrom_" "_tWhere
//write query
//return $$$OK
set x = ##class(GLHC.ResultsViewer.Helpers).AuditEvent("GetSearchResult",query,"User searched for messages, invoking SQL queries and viewing special information defined in Event Data")
set result = ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
// Custom format manipulations
set mutation = {}.%FromJSON(result)
set iter = mutation.%GetIterator()
while iter.%GetNext(.key, .value) {
// Name formatting
set value.PatientFullName = value.PatientLastName_", "_value.PatientFirstName
if value.ProvLastName '= "" {
set value.ProvLastName = value.ProvLastName_", "
}
set value.ProviderName = value.ProvLastName_value.ProvFirstName_" "_value.ProviderID_" - "_value.ProviderRole
// Manual formatting from ill-formed dates
try {
set preDOB = value.PatientDOB
set value.PatientDOB = $extract(preDOB,5)_$extract(preDOB,6)_"/"_$extract(preDOB,7)_$extract(preDOB,8)_"/"_$extract(preDOB,1)_$extract(preDOB,2)_$extract(preDOB,3)_$extract(preDOB,4)
} catch(e) {
set value.PatientDOB = preDOB
}
}
write mutation.%ToJSON()
}
catch ex {
write ex.Name
}
return $$$OK
}
// Returns all the route data from a query as json to the client
ClassMethod GetRoutes(inData As %String) As %Status
{
try {
//set data = {}.%FromJSON(inData)
// Gets the logged in user
set user = $username
// SQL definitions
set tSelect = "select Active, Aggregate, CreateTS, Delay, EMR, InterestedProvider,MSH3,MSH4,MSH5,MSH6,OrganizationID,PV13Location,"_
"PatientClass,PreserveProviders,ProviderRole,ResultStatus,ResultType,SendTo,SourceOID,Transformations,OrganizationName,sourceorganization,sourceorgid"
set tFrom = "from LinkedTable.vwAdminProviderRoutes"
set tWhere = "where sourceorganization in ("_..GetFacilities()_")"
set query = tSelect_" "_tFrom_" "_tWhere
w query
return $$$OK
// Return our json object result from the query
set result = ##class(GLHC.ResultsViewer.Helpers).SQLBuilder(tSelect,tFrom,tWhere)
do ##class(GLHC.ResultsViewer.Helpers).AuditEvent("GetRoutes",query, "User searched for routes, invoking an SQL query defined in Event Data")
write result
}
catch ex {
write ex.Name
}
return $$$OK
}
}