Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSBINJEC

PSBINJEC.m

Go to the documentation of this file.
  1. PSBINJEC ;BIRMINGHAM/GN-LAST INJECTION SITE BROKER ;03/06/16 3:06pm
  1. ;;3.0;BAR CODE MED ADMIN;**68,83**;Mar 2004;Build 89
  1. ;
  1. ; EN^PSJBCMA1/2829
  1. ;
  1. ;*83 - Add new parameter to allow return of Inj or Derm site info
  1. ; - New XPAR param for dermal site Hist
  1. ;
  1. ;*******************************************************************
  1. RPC(RESULTS,DFN,PSBOI,TIME,MAX,SITETYP) ;Get Last MAX Injection/Derm site
  1. ; admins per Patient by One Orderable Item or ALL Orderable Items
  1. ;*******************************************************************
  1. ;
  1. ;** Beginning with patch *83 this API will accept a New Site type
  1. ; parameter to allow it to return either Injection or Dermal Site
  1. ; info. ** Defaults to older Injection info only if not passed
  1. ;
  1. ; Return Array RESULTS
  1. ; RESULTS(0)=nn nn = total admin line items returned
  1. ; RESULTS(n)=string string = returned site data
  1. ; (date/time ^ OI ien ^ OI name ^ site)
  1. ; or string = an error line
  1. ; (-1 ^ error text message)
  1. ; Input Parameters:
  1. ; DFN= Patient IEN
  1. ; PSBOI= Orderable Item IEN
  1. ; TIME= Time range in hours to look back
  1. ; MAX = Maximum injections items to be returned
  1. ; SITETYP = "I" for Injections or "D" for Dermal. (I=def) *83
  1. ;
  1. ; ** Note: Time and Max work together, which every is reached first,
  1. ; then the search ends and returns what was found thus far.
  1. ;
  1. N ACDTE,DOSAGE,DSPIVPB,ENDDTE,INJ,SITE,IVOK,IVTYPE,INTERMIT,MXTIME
  1. N ORDIT,ORDITNM,ORDNO,PRMPTINJ,QT,QQ,ROUTE,RR,RTBL,STDROUTE,YY
  1. K RESULTS
  1. ;Injection or Dermal site type *83
  1. S SITETYP=$S($G(SITETYP)="":"I",1:SITETYP) ;def to "I"
  1. ;
  1. I '$G(DFN)!('$D(^DPT(DFN))) D Q
  1. . D ERR("Error, DFN missing or invalid (param 1)")
  1. ;
  1. ;load valid rotation type injection routes table
  1. D BLDTBL(.RTBL)
  1. ;
  1. D:$G(PSBOI) OI ;by One specific orderable item
  1. D:'$G(PSBOI) ALL ;by All orderable items
  1. Q
  1. ; ======== END RPC MAIN ========
  1. ;
  1. ;*******************************************************************
  1. OI ; Get Last MAX Injections per Patient for one Orderable Item only
  1. ;*******************************************************************
  1. ;
  1. N INDX ;*83
  1. ;default the OI call for Time if less than 1 hour to unlimited
  1. S TIME=+$G(TIME) I TIME<1 S TIME=9999999
  1. S ENDDTE=$$FMADD^XLFDT($$NOW^XLFDT,,-TIME)
  1. ;
  1. ;default the OI call for Max = last 4
  1. S MAX=+$G(MAX) I MAX<1 S MAX=4
  1. S (YY,QT)=0
  1. ;
  1. ; reverse date/time loop thru injection by Med, (AINJOI xref)
  1. ;
  1. S INDX=$S(SITETYP="D":"ADERMOI",1:"AINJOI") ;*83
  1. F ACDTE=9999999:0 S ACDTE=$O(^PSB(53.79,INDX,DFN,PSBOI,ACDTE),-1) Q:('ACDTE)!(ACDTE<ENDDTE) D
  1. .S INJ=""
  1. .F S INJ=$O(^PSB(53.79,INDX,DFN,PSBOI,ACDTE,INJ)) Q:INJ=""!QT D
  1. ..S RR=0
  1. ..F S RR=$O(^PSB(53.79,INDX,DFN,PSBOI,ACDTE,INJ,RR)) Q:'RR!QT D
  1. ...Q:'$$QUALIFY ;skip this rec, does not qualify
  1. ...D ADRESULT ;add rec to Results as a valid inj site rec
  1. ...I YY=MAX S QT=1 ;quit, max inj sites found
  1. ;
  1. I '$D(RESULTS) D ERR("<<No data to display>>")
  1. Q
  1. ;
  1. ;*************************************************************
  1. ALL ; Get Last MAX Injections per Patient for any Orderable Item
  1. ;*************************************************************
  1. ;
  1. N INDX ;*83
  1. ;default the ALL call for Time if less than 1 passed in. Use XPAR
  1. ;Param TIME shoud be passed in by GUI client with hours, calc if not
  1. S TIME=+$G(TIME)
  1. I TIME<1,SITETYP="D" S TIME=$$GET^XPAR("ALL","PSB DERMAL SITE MAX DAYS",,"I")*24 ;for derm convert days to hours *83
  1. I TIME<1,SITETYP'="D" S TIME=$$GET^XPAR("ALL","PSB INJECTION SITE MAX HOURS",,"I") ;*83
  1. S ENDDTE=$$FMADD^XLFDT($$NOW^XLFDT,,-TIME)
  1. ;
  1. ;default the ALL call for Max = last 4 Injections
  1. S MAX=+$G(MAX) I MAX<1 S MAX=9999999
  1. S (YY,QT)=0
  1. ;
  1. ; Reverse date/time loop thru injection xref, (AINJ), ALL MEDS
  1. ;
  1. S INDX=$S(SITETYP="D":"ADERM",1:"AINJ") ;*83
  1. F ACDTE=9999999:0 S ACDTE=$O(^PSB(53.79,INDX,DFN,ACDTE),-1) Q:('ACDTE)!(ACDTE<ENDDTE) D
  1. .S INJ=""
  1. .F S INJ=$O(^PSB(53.79,INDX,DFN,ACDTE,INJ)) Q:INJ=""!QT D
  1. ..S RR=0
  1. ..F S RR=$O(^PSB(53.79,INDX,DFN,ACDTE,INJ,RR)) Q:'RR!QT D
  1. ...Q:'$$QUALIFY ;skip this rec, does not qualify
  1. ...D ADRESULT ;add rec to Results as a valid inj site rec
  1. ...I YY=MAX S QT=1 ;quit, max inj sites found
  1. ;
  1. I '$D(RESULTS) D ERR("<<No data to display>>")
  1. Q
  1. ;
  1. ; ----------------- Supporting Tag calls below ------------------
  1. QUALIFY() ; Determine if a record qualifies as a last Injection Site we want
  1. ;
  1. ; Function return: 0 = false, this admin record should not be used
  1. ; 1 = true, this admin record shold be used
  1. ;
  1. ;Quit false, other than a "given type" for action status
  1. ; h=held,r=refused,n=not given,m=missing dose
  1. ;*83
  1. ; remove code "RM", this is valid action for MRR meds for last site
  1. I ",H,R,N,M,"[(","_$P(^PSB(53.79,RR,0),U,9)_",") Q 0
  1. ;
  1. S ORDNO=$P(^PSB(53.79,RR,.1),U)
  1. K ^TMP("PSJ1",$J)
  1. D EN^PSJBCMA1(DFN,ORDNO,1)
  1. S IVTYPE=$P($G(^TMP("PSJ1",$J,0)),U,6)
  1. S INTERMIT=$P($G(^TMP("PSJ1",$J,0)),U,7)
  1. S PRMPTINJ=$P($G(^TMP("PSJ1",$J,1,0)),U)
  1. S DSPIVPB=$P($G(^TMP("PSJ1",$J,1,0)),U,2)
  1. S ORDIT=$P($G(^TMP("PSJ1",$J,2)),U)
  1. S ORDITNM=$P($G(^TMP("PSJ1",$J,2)),U,2)
  1. S ROUTE=$P($G(^TMP("PSJ1",$J,1)),U,13)
  1. S STDROUTE=$P($G(^TMP("PSJ1",$J,1)),U,14)
  1. K ^TMP("PSJ1",$J)
  1. ;
  1. ; IV Orders
  1. ;Quit with T/F, is a valid rotation inj type
  1. I ORDNO["V" Q $$IVROTATN^PSBINJEC(.RTBL,STDROUTE,IVTYPE,INTERMIT)
  1. ;
  1. ; Unit Dose Orders since not an IV
  1. ;Quit False, if Prompt for Inj is No OR if display on IVPB is Yes
  1. I SITETYP="I",'PRMPTINJ!DSPIVPB Q 0 ;*83
  1. ;
  1. ;Quit True, is a valid rotation inj type
  1. Q 1
  1. ;
  1. ADRESULT ; Add line item to Results array
  1. ; get last dispense, this one has the dosage given by the nurse
  1. S DOSAGE=""
  1. I ORDNO["U" D
  1. .S QQ=99999999 S QQ=$O(^PSB(53.79,RR,.5,QQ),-1)
  1. .S:QQ DOSAGE=$P($G(^PSB(53.79,RR,.5,QQ,0)),U,4)
  1. I ORDNO["V" D
  1. .S QQ=99999999 S QQ=$O(^PSB(53.79,RR,.6,QQ),-1)
  1. .S:QQ DOSAGE=$P($G(^PSB(53.79,RR,.6,QQ,0)),U,3)
  1. S SITE=$S(SITETYP="D":$$GET1^DIQ(53.79,RR_",",.18),1:$$GET1^DIQ(53.79,RR_",",.16)) ;*83
  1. ;
  1. S YY=YY+1
  1. S RESULTS(YY)=ACDTE_U_ORDIT_U_ORDITNM_U_DOSAGE_U_ROUTE_U_SITE ;*83
  1. S RESULTS(0)=YY
  1. Q
  1. ;
  1. LASTSITE(DFN,OI) ;Get the last site via LIFO per OI for VDL - Injection/Dermal
  1. ; Returns the last body site per the Patient and Orderable Item
  1. ; If both an Injection site and Dermal site are found per an OI,
  1. ; then the site that occurred most recently (last) will be returned.
  1. ;
  1. N LI,LINJ,LDER,LSITE
  1. D RPC^PSBINJEC(.LI,DFN,OI,9999999,1,"I")
  1. S LINJ=$G(LI(1))
  1. D RPC^PSBINJEC(.LI,DFN,OI,9999999,1,"D")
  1. S LDER=$G(LI(1))
  1. S LSITE=$S($P(LINJ,U)>$P(LDER,U):$P(LINJ,U,6),1:$P(LDER,U,6))
  1. Q LSITE
  1. ;
  1. ERR(TXT) ; Error msg handler
  1. S RESULTS(0)=1
  1. S RESULTS(1)="-1^"_TXT
  1. Q
  1. ;
  1. OK(TXT) ; Success msg handler
  1. S RESULTS(0)=1
  1. S RESULTS(1)="1^"_TXT
  1. Q
  1. ;
  1. IVROTATN(RTAB,STDRT,IVTY,INT) ; IV of route and type for injection rotations
  1. N IVOK S IVOK=0
  1. I STDRT="" Q IVOK
  1. I IVTY="S",INT=1 S IVOK=1 ;IV type= Syringe & intermittent
  1. I IVTY="C",INT=1 S IVOK=1 ;IV type= Chemo & intermittent
  1. I IVOK,'$D(RTAB(STDRT)) S IVOK=0 ;Std Rte NOT mapped
  1. Q IVOK
  1. ;
  1. BLDTBL(TBL) ; Build Rotation table
  1. N QQ,RT F QQ=1:1 S RT=$P($T(ROUTES+QQ^PSBINJEC),";;",2) Q:RT="END" S TBL(RT)=""
  1. Q
  1. ;
  1. ROUTES ; Valid Rotation routes for returning admin record injection data
  1. ;;INTRADERMAL
  1. ;;INTRAMUSCULAR
  1. ;;SUBCUTANEOUS
  1. ;;END