Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;You have to init variables in M before you can set data to them
- GetGlucose n eptID,now,startDt,endDt,matchComponents,patDAT,i,ordID,ordDAT,j,hsbID,inpCSN,inpID,fsdDAT,fsdID,row,BLU,glucINST,result,lev
- ; $$zECFGet grabs parameters sent across in the request, throws an exception
- s eptID=$$zECFGet("eptID")
- i eptID="" s%=$$zECFThrow("NO-PATIENT-ID","No patient ID provided. Patient ID and ID type are required")
- ; Get the current timestamp, $h is short for $HORALOG and $p gets the substring of that. Used to calculate an "instant" in Epic.
- s now=($p($h,",",1)*86400)+$p($h,",",2)
- ;
- ; Load the start date - if none is passed, use 14 days ago
- s startDt=$$zECFGet("startDt")
- i startDt'="" s startDt=$zdh(startDt,3)*86400
- e s startDt=(now-(86400*14))
- ;
- ; Load the end date - if none is passed, use today
- s endDt=$$zECFGet("endDt")
- i endDt'="" s endDt=($zdh(endDt,3)*86400)+86400
- e s endDt=now
- ;
- ;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
- ; Specify the Order Components that contain glucose levels to retrieve
- 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")
- ;
- ;Epic's Chronicles stores data, as named, chronlogically. Each "entry" gets assigned a DAT, which is calculated from DTE. DTE is the days since
- ;12/31/1840, DAT is 121531-DTE. Epic does this to store records in reverse chronological order
- ;The data organization EPT is the Patient "master file" in Epic.
- ; Retrieve inpatient glucose data
- ;So, go get all of the "encounters" that have a DAT in Epic. Quit "q" if you fail"
- s patDAT="" f s patDAT=$o(^ER1("EPT",eptID,20,patDAT)) q:patDAT="" d
- ; Orders for an encounter are seemingly stored in EPT-19000. See if there are any orders in 19000, if not, quit
- ;You can directly access data from globals, but Epic provides standard functions that handle things like locking and data lookup
- ; $$geti is one of those functions
- ; It's format is $$geti(Master file name, master file ID (the .1 in Epic terms), Item Number, Multi-response response #, DAT)
- . f i=1:1: $$geti("EPT",eptID,19000,0,patDAT) d
- . . s ordID=$$geti("EPT",eptID,19000,i,patDAT)
- ; 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
- . . f s ordDAT=$o(^ER1("ORD",ordID,20,ordDAT)) q:ordDAT="" d
- ; 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
- . . . i$$geti("ORD",ordID,90,1,99999)=5 d
- ; Now iterate through order components in ORD-2000 and see if they match the components in the array set above
- . . . . f j=1:1: $$geti("ORD",ordID,2000,0,ordDAT) d: $lf(matchComponents, $$geti("ORD",ordID,2000,j,ordDAT))
- ; The instant of the order
- . . . . . s glucINST=$$geti("ORD",ordID,24,1,99999) ; instant data taken
- . . . . . q:((glucINST<startDt)!(glucINST>endDt))
- ;ORD-2010 actually stores the Glucose value.
- . . . . . s lev=+$$geti("ORD",ordID,2010,j,ordDAT)
- . . . . . s:lev'=0 result("glucose",glucINST)=lev
- ;
- ; Generate Web Service output
- s glucArr=$$zECFNew("glucose",,"A")
- s ts="" f s ts=$o(result("glucose",ts)) q:ts="" d
- . s glucObj=$$zECFNewElmtObj(glucArr)
- . s%=$$zECFSet("time", (ts\86400)_","_(ts#86400),glucObj)
- . s%=$$zECFSet("value",result("glucose",ts),glucObj)
- ;
- q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement