Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. ;You have to init variables in M before you can set data to them
  2.  
  3. GetGlucose n eptID,now,startDt,endDt,matchComponents,patDAT,i,ordID,ordDAT,j,hsbID,inpCSN,inpID,fsdDAT,fsdID,row,BLU,glucINST,result,lev
  4. ; $$zECFGet grabs parameters sent across in the request, throws an exception
  5. s eptID=$$zECFGet("eptID")
  6. i eptID="" s%=$$zECFThrow("NO-PATIENT-ID","No patient ID provided. Patient ID and ID type are required")
  7. ; Get the current timestamp, $h is short for $HORALOG and $p gets the substring of that. Used to calculate an "instant" in Epic.
  8. s now=($p($h,",",1)*86400)+$p($h,",",2)
  9. ;
  10. ; Load the start date - if none is passed, use 14 days ago
  11. s startDt=$$zECFGet("startDt")
  12. i startDt'="" s startDt=$zdh(startDt,3)*86400
  13. e s startDt=(now-(86400*14))
  14. ;
  15. ; Load the end date - if none is passed, use today
  16. s endDt=$$zECFGet("endDt")
  17. i endDt'="" s endDt=($zdh(endDt,3)*86400)+86400
  18. e s endDt=now
  19. ;
  20. ;You're going to iterate through components in ORD 2000. Here is a list of valid ORD 2000 values which should evaluate to positive checks for glucose
  21. ; Specify the Order Components that contain glucose levels to retrieve
  22. s matchComponents=$lb("799","809","815","1209","1756","2558","5526","5527","5528","5529","5530","7602","16459","16828","1810051","1810133","1230100704","1230100708","1230100881","1230100887","1230100888","1230100892","1230100902","1230100903","1230101128","1230101140","1230101149","1230101150","1230101535","1230101543")
  23. ;
  24. ;Epic's Chronicles stores data, as named, chronlogically. Each "entry" gets assigned a DAT, which is calculated from DTE. DTE is the days since
  25. ;12/31/1840, DAT is 121531-DTE. Epic does this to store records in reverse chronological order
  26. ;The data organization EPT is the Patient "master file" in Epic.
  27. ; Retrieve inpatient glucose data
  28. ;So, go get all of the "encounters" that have a DAT in Epic. Quit "q" if you fail"
  29. s patDAT="" f s patDAT=$o(^ER1("EPT",eptID,20,patDAT)) q:patDAT="" d
  30. ; Orders for an encounter are seemingly stored in EPT-19000. See if there are any orders in 19000, if not, quit
  31. ;You can directly access data from globals, but Epic provides standard functions that handle things like locking and data lookup
  32. ; $$geti is one of those functions
  33. ; It's format is $$geti(Master file name, master file ID (the .1 in Epic terms), Item Number, Multi-response response #, DAT)
  34. . f i=1:1: $$geti("EPT",eptID,19000,0,patDAT) d
  35. . . s ordID=$$geti("EPT",eptID,19000,i,patDAT)
  36. ; The data in EPT-19000 just points towards data stored in the ORD masterfile, so now find the the orderDAT based upon that Order ID
  37. . . f s ordDAT=$o(^ER1("ORD",ordID,20,ordDAT)) q:ordDAT="" d
  38. ; I'm pretty sure that ORD-90 is Order Status and that 5 is "Final Status", so if the order has a preliminary result, skip it
  39. . . . i$$geti("ORD",ordID,90,1,99999)=5 d
  40. ; Now iterate through order components in ORD-2000 and see if they match the components in the array set above
  41. . . . . f j=1:1: $$geti("ORD",ordID,2000,0,ordDAT) d: $lf(matchComponents, $$geti("ORD",ordID,2000,j,ordDAT))
  42. ; The instant of the order
  43. . . . . . s glucINST=$$geti("ORD",ordID,24,1,99999) ; instant data taken
  44. . . . . . q:((glucINST<startDt)!(glucINST>endDt))
  45. ;ORD-2010 actually stores the Glucose value.
  46. . . . . . s lev=+$$geti("ORD",ordID,2010,j,ordDAT)
  47. . . . . . s:lev'=0 result("glucose",glucINST)=lev
  48. ;
  49. ; Generate Web Service output
  50. s glucArr=$$zECFNew("glucose",,"A")
  51. s ts="" f s ts=$o(result("glucose",ts)) q:ts="" d
  52. . s glucObj=$$zECFNewElmtObj(glucArr)
  53. . s%=$$zECFSet("time", (ts\86400)_","_(ts#86400),glucObj)
  54. . s%=$$zECFSet("value",result("glucose",ts),glucObj)
  55. ;
  56. q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement