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

PSJPAD70.m

Go to the documentation of this file.
  1. PSJPAD70 ;BIR/JCH - HL7 UTILITY FOR PADE INBOUND POCKET ACTIVITY ;01/06/16 1:34 PM
  1. ;;5.0;INPATIENT MEDICATIONS;**317,356,376**;16 DEC 97;Build 4
  1. ;
  1. ; Reference to $$HLDATE^HLFNC is supported by DBIA 10106
  1. ; Reference to ^XMD is supported by DBIA 10070
  1. ; Reference to ^XLFDT is supported by DBIA# 10103.
  1. ;
  1. Q
  1. ;
  1. DWO(PSJOMS) ; Send Dispensed Without Order (DWO) Alert
  1. N GROUPS
  1. S GROUPS=""
  1. Q:'$$ACTDWO(.PSJOMS)
  1. D GETGRPS(.PSJOMS,.GROUPS)
  1. D DWOSEND(.PSJOMS,.GROUPS)
  1. Q
  1. ;
  1. ACTDWO(PSJOMS) ; Check if dispensing device (cabinet) is active for DWO messages
  1. N CABNAME,CABIEN,RESULT,ERROR,PSJPSYS
  1. ; Get PADE Inbound System name
  1. S PSJPSYS=$G(PSJOMS("DISPSYS")) Q:(PSJPSYS="") 0
  1. S PSJPSYS=$$FIND1^DIC(58.601,"","",PSJPSYS) K DIERR Q:'PSJPSYS "" ;*356
  1. ; Get Cabinet name
  1. S CABNAME=$G(PSJOMS("CABID")) Q:(CABNAME="") 0
  1. K DIERR S CABIEN=$$FIND1^DIC(58.63,"","",CABNAME) K DIERR Q:'CABIEN "" ;*356
  1. ; Get value in SEND DWO MESSAGES field (#3) in PADE DISPENSING DEVICE file (#58.63)
  1. K DIERR D GETS^DIQ(58.63,CABIEN_",",3,"I","RESULT","ERROR") K DIERR ;*356
  1. Q +$G(RESULT(58.63,CABIEN_",",3,"I"))
  1. ;
  1. GETGRPS(PSJOMS,GROUPS) ; Find Entity mail group in mail group variable pointer field
  1. ; DWO MAIL GROUP (#3) in the PADE INVENTORY SYSTEM file (58.601)
  1. ;
  1. ; Input: PSJOMS("DISPSYS") = Inbound Dispensing System name.
  1. ; PSJOMS("CABID") = PADE cabinet name.
  1. ;
  1. ; Output: GROUPS(EntityPointer,Count)=MailGroupName
  1. ;
  1. ; Dispensed Without Orders (DWO) mail groups may be associated with up to seven entities.
  1. ; Each entity is associated with a precedence level, creating a hierarchy such that only mail groups
  1. ; associated with the entity(ies) with the highest precedence will receive a DWO message.
  1. ;
  1. ; If two entities have the same precedence, and both have DWO mail groups defined, both will receive
  1. ; a DWO message. For example, if an incoming PADE inventory HL7 message is associated with a cabinet
  1. ; that does not have a DWO mail group defined, but the cabinet is associated with a ward and a clinic,
  1. ; each of which DOES have a DWO mail group defined, the DWO message will go the both the ward mail
  1. ; group and the clinic mail group, because the ward and the clinic have the same precedence.
  1. ;
  1. ; If none of the entities associated with an incoming PADE inventory HL7 message is associated with
  1. ; a DWO mail group, no DWO message is sent.
  1. ;
  1. ; PADE DWO message entities, in order of precedence
  1. ; 1)PADE CABINET : PADE DISPENSING DEVICE file (#58.63)
  1. ; 2)........WARD : WARD LOCATION file (#42)
  1. ; ........CLINIC : HOSPITAL LOCATION file (#44)
  1. ; 3)..WARD GROUP : WARD GROUP file (#57.5)
  1. ; ..CLINIC GROUP : CLINIC GROUP file (#57.8)
  1. ; 4).PADE SYSTEM : PADE INVENTORY SYSTEM file (#58.601)
  1. ; ......DIVISION : DIVISION file (#40.8)
  1. ;
  1. N PSJPSYS,PSJECNT,PSJMCT,PSJDWINS,PSJDWMG,PSJRSLT,PSJRSLT1,PSJDWENT,PRIO,TEMPGRP,PSJHI,NEXT
  1. K GROUPS N PSJCL,PSJCLGRP,PSJWRD,PSJWGRP,PSJCAB,PSJDIV,PSJFICHK,PSJENTYP
  1. ; Get PADE Inbound System pointer to file 58.601, store in "FICHK" node
  1. S PSJPSYS=$G(PSJOMS("DISPSYS")) Q:(PSJPSYS="") 0
  1. K DIERR S PSJPSYS=$$FIND1^DIC(58.601,"","",PSJPSYS) K DIERR Q:'PSJPSYS 0 ;*356
  1. S PSJPSYS("FICHK",PSJPSYS)=PSJOMS("DISPSYS")
  1. ; Get PADE Cabinet pointer to file 58.63, store in "FICHK" node
  1. K DIERR S PSJCAB=+$$FIND1^DIC(58.63,,,PSJOMS("CABID")),PSJCAB("FICHK",PSJCAB)=PSJOMS("CABID") K DIERR ;*356
  1. K DIERR D GETS^DIQ(58.63,PSJCAB,2,"IE","PSJDIV") K DIERR ;*356
  1. ; Get PADE device Division pointer to file 40.8, store in "FICHK" node
  1. S PSJDIV("FICHK",+$G(PSJDIV(58.63,PSJCAB_",",2,"I")))=$G(PSJDIV(58.63,PSJCAB_",",2,"E"))
  1. ; Get PADE device Clinic pointer to file 44, store in "FICHK" node
  1. D LIST^DIC(58.638,","_PSJCAB_",",".01IE","P",,,,,,,"PSJCL") N CL,CC S CC=0 F S CC=$O(PSJCL("DILIST",CC)) Q:'CC D
  1. .S CL=$P($G(PSJCL("DILIST",CC,0)),"^",3) I CL S PSJCL("FICHK",+CL)=$P(PSJCL("DILIST",CC,0),"^",2)
  1. K PSJCL("DILIST")
  1. ; Get PADE device Clinic Group pointer to file 57.8, store in "FICHK" node
  1. D LIST^DIC(58.637,","_PSJCAB_",",".01IE","P",,,,,,,"PSJCLGRP") N CG,CC S CC=0 F S CC=$O(PSJCLGRP("DILIST",CC)) Q:'CC D
  1. .S CG=$P($G(PSJCLGRP("DILIST",CC,0)),"^",3) I CG S PSJCLGRP("FICHK",+CG)=$P(PSJCLGRP("DILIST",CC,0),"^",2)
  1. K PSJCLGRP("DILIST")
  1. ; Get PADE device Ward pointer to file 42, store in "FICHK" node
  1. D LIST^DIC(58.636,","_PSJCAB_",",".01IE","P",,,,,,,"PSJWRD") N WD,WC S WC=0 F S WC=$O(PSJWRD("DILIST",WC)) Q:'WC D
  1. .S WD=$P($G(PSJWRD("DILIST",WC,0)),"^",3) I WD S PSJWRD("FICHK",+WD)=$P(PSJWRD("DILIST",WC,0),"^",2)
  1. K PSJWRD("DILIST")
  1. ; Get PADE Ward Group pointer to file 57.5, store in "FICHK" node
  1. D LIST^DIC(58.635,","_PSJCAB_",",".01IE","P",,,,,,,"PSJWGRP") N WG,WC S WC=0 F S WC=$O(PSJWGRP("DILIST",WC)) Q:'WC D
  1. .S WG=$P($G(PSJWGRP("DILIST",WC,0)),"^",3) I WG S PSJWGRP("FICHK",+WG)=$P(PSJWGRP("DILIST",WC,0),"^",2)
  1. K PSJWGRP("DILIST")
  1. ; Get list of DWO MESSAGE ENTITY values for PADE system in PSJRSLT
  1. D LIST^DIC(58.6014,","_+PSJPSYS_",",.01,"P",,,,,,,"PSJRSLT","PSJROOT")
  1. ;
  1. ; Go through each DWO MESSAGE ENTITY, determine if the entity applies to this cabinet/device
  1. ; by comparing each DWO MESSAGE ENTITY to the list of entities defined for the cabinet.
  1. ;
  1. S PSJECNT=0 F S PSJECNT=$O(PSJRSLT("DILIST",PSJECNT)) Q:'PSJECNT D
  1. .; Find the source file pointed to by the variable pointer DWO MESSAGE ENTITY field (#4) in the PADE INVENTORY SYSTEM file (#58.601)
  1. .S PSJDWINS=+$G(PSJRSLT("DILIST",PSJECNT,0))
  1. .; Get list of mail groups associated with this entity
  1. .D LIST^DIC(58.60141,","_+PSJDWINS_","_+PSJPSYS_",",.01,"P",,,,,,,"PSJRSLT1")
  1. .S PSJDWENT=$G(^PS(58.601,PSJPSYS,2,PSJDWINS,0))
  1. .; Define priority for this entity
  1. .S PSJENTYP=$S(PSJDWENT["PS(58.63":"1^PSJCAB",PSJDWENT["DG(40.8":"4^PSJDIV",PSJDWENT["PS(58.601":"4^PSJPSYS",PSJDWENT["DIC(42":"2^PSJWRD",PSJDWENT["PS(57.8":"3^PSJCLGRP",PSJDWENT["PS(57.5":"3^PSJWGRP",PSJDWENT["SC(":"2^PSJCL",1:99)
  1. .S PRIO=+PSJENTYP ;S PRIO=$S((PSJDWENT[58.63):1,(PSJDWENT["DIC(42,")!(PSJDWENT["SC("):2,(PSJDWENT[57.5)!(PSJDWENT[57.8):3,(PSJDWENT[58.601)!(PSJDWENT[40.8):4,1:99)
  1. .; Quit if this DWO MESSAGE ENTITY from PADE INVENTORY SYSTEM (#58.601) is not applicable to this PADE DISPENSING DEVICE (#58.63)
  1. .S PSJFICHK=$P(PSJENTYP,"^",2)_"(""FICHK"","_+PSJDWENT_")" Q:'$D(@PSJFICHK)
  1. .; Go through mail groups, set into TMPGRP by priority
  1. .S PSJMCT=0 F S PSJMCT=$O(PSJRSLT1("DILIST",PSJMCT)) Q:'PSJMCT D
  1. ..S PSJDWMG=$G(PSJRSLT1("DILIST",PSJMCT,0)) Q:'PSJDWMG
  1. ..S NEXT=+$O(TEMPGRP(PRIO,PSJDWENT,999),-1)+1
  1. ..S TEMPGRP(PRIO,PSJDWENT,NEXT)=$P(PSJDWMG,"^",2)
  1. ;
  1. ; Move highest priority entity mail groups into GROUPS
  1. S PSJHI=$O(TEMPGRP("")) I PSJHI]"" M GROUPS=TEMPGRP(PSJHI)
  1. Q
  1. ;
  1. DWOSEND(PSJOMS,GROUPS) ;This routine will generate a mailman message when an order is dispensed without an order, and a DWO mail group is defined
  1. ;
  1. ;Input: PSJOMS - Array generated from incoming OMS^O05 HL7 PADE pocket activity message
  1. ; GROUPS - VistA Mail Groups to send the DWO message
  1. ;
  1. N MSGTEXT,XMTEXT,XMSUB,XMY,XMZ,XMDUZ,MSGTYPE,MSHREC,ENTITY,MAILGRP
  1. N HLFS,HLCS,MTXTLN,MGCNT,DRGFILNM
  1. S DRGFILNM="" I $G(PSJOMS("DRGITM")) S:PSJOMS("DRGITM")=+PSJOMS("DRGITM") DRGFILNM=$P($G(^PSDRUG(PSJOMS("DRGITM"),0)),"^")
  1. I DRGFILNM="" S DRGFILNM=$G(PSJOMS("DRGTXT"))
  1. S:'$G(PSJOMS("PSJDT")) PSJOMS("PSJDT")=$P($$FMTHL7^XLFDT($$NOW^XLFDT()),"-")
  1. Q:'($G(PSJOMS("TTYPE"))["V")
  1. S MTXTLN=0
  1. S MSGTEXT(MTXTLN)=" ",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="A medication was dispensed from a PADE device without an order",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)=" ",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="PADE Device: "_$G(PSJOMS("CABID")),MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="Date: "_$$FMTE^XLFDT($$FMDATE^HLFNC(PSJOMS("PSJDT"))),MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="Drug: "_DRGFILNM,MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="Patient: "_$G(PSJOMS("PTNAMA"))_","_$G(PSJOMS("PTNAMB"))_" "_$G(PSJOMS("PTNAMC")) D
  1. .S MSGTEXT(MTXTLN)=MSGTEXT(MTXTLN)_" "_$S($G(PSJOMS("SSN")):" ("_$G(PSJOMS("SSN"))_")",$G(PSJOMS("PTID"))]"":"(Unknown ID: "_$G(PSJOMS("PTID"))_")",1:" ()"),MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="",MTXTLN=MTXTLN+1
  1. S MSGTEXT(MTXTLN)="User: "_$G(PSJOMS("NUR1B"))_$S($G(PSJOMS("NUR1C"))]"":","_PSJOMS("NUR1C"),1:"")_" - ID: "_$G(PSJOMS("NUR1A")),MTXTLN=MTXTLN+1
  1. ; Send message to mail groups
  1. S XMSUB="PADE DWO:"_$G(PSJOMS("CABID"))_"-"_DRGFILNM
  1. S XMTEXT="MSGTEXT("
  1. I $D(GROUPS)>1 S ENTITY="" F S ENTITY=$O(GROUPS(ENTITY)) Q:ENTITY="" D
  1. .S MGCNT=0 F S MGCNT=$O(GROUPS(ENTITY,MGCNT)) Q:'MGCNT D
  1. ..S MAILGRP=GROUPS(ENTITY,MGCNT) Q:MAILGRP=""
  1. ..S XMY("G."_MAILGRP)=""
  1. I $D(XMY)<10 D GETPDMGR^PSJPAD7I(.XMY)
  1. Q:$D(XMY)<10
  1. S XMDUZ="PADE-SYSTEM"
  1. D ^XMD
  1. Q
  1. ;
  1. UNLOAD(PSJPSYS,PADIEN,DRWIEN,DRGIEN,DRGDEV,PCKIEN) ; Unload (delete) a drug from pocket and drawer for device DEV and system SYS
  1. ; INPUT
  1. ; PSJPSYS - Inventory System entry from file 58.601
  1. ; PADIEN - Dispensing Device (#1) field (subfile 58.6011) from file 58.601
  1. ; DRWIEN - Drawer (#2) field (subfile 58.60112) from dispensing device subfile (#58.60111) in file 58.601
  1. ; DRGIEN - Drug (Drawer) (#1) field (subfile 58.601121) from drawer subfile (#58.60112) in file 58.61
  1. ; DRGDEV - Drug (Device) (#2) field (subfile 58.60111) from dispensing device subfile (#58.6011) in file 58.601
  1. ; PCKIEN - Pocket/Subdrawer (#2) field (subfile 58.601122) from drawer subfile (58.60112) in file 58.601
  1. ;
  1. N DIK,DA,PSERR
  1. ; If the unique location in the device,
  1. I $G(PSJPSYS)&$G(PADIEN)&$G(DRWIEN) I $D(^PS(58.601,+PSJPSYS,"DEVICE",+PADIEN,"DRAWER",+DRWIEN)) D
  1. .S DIK="^PS(58.601,"_+PSJPSYS_",""DEVICE"","_+PADIEN_",""DRAWER"","_+DRWIEN_",""SUB"","
  1. .S DA(3)=+PSJPSYS,DA(2)=+PADIEN,DA(1)=DRWIEN,DA=PCKIEN D ^DIK
  1. .S DIK="^PS(58.601,"_+PSJPSYS_",""DEVICE"","_+PADIEN_",""DRAWER"","_+DRWIEN_",""DRUG"","
  1. .S DA(3)=+PSJPSYS,DA(2)=+PADIEN,DA(1)=DRWIEN,DA=DRGIEN D ^DIK
  1. ;
  1. ; Kill Drug (DEVICE) only if balance is less than 1
  1. N DA,DIK,DEVBAL
  1. S DEVBAL=$P($G(^PS(58.601,+$G(PSJPSYS),"DEVICE",+$G(PADIEN),"DRUG",+$G(DRGDEV),0)),"^",3)
  1. Q:DEVBAL>0 ; Don't delete drug from device/cabinet/station if there it's stocked somewhere else
  1. S DIK="^PS(58.601,"_+PSJPSYS_",""DEVICE"","_+PADIEN_",""DRUG"","
  1. S DA(2)=+PSJPSYS,DA(1)=+PADIEN,DA=DRGDEV D ^DIK
  1. Q
  1. ;
  1. MANUN(PADEV) ; Manually unload one drug at a time from PADE INVENTORY SYSTEM (#58.601) file for device PADEV pointer to DISPENSING DEVICE (#58.63) file
  1. ; Input : PADEV - Pointer to PADE DISPENSING DEVICE (#58.63) file
  1. ;
  1. N DIR,X,Y
  1. S DIR(0)="Y",DIR("A")="DELETE SINGLE DRUG FROM PADE CABINET"
  1. S DIR("?")="^D UNLHLP^PSJPAD70"
  1. S DIR("B")="N" D ^DIR
  1. Q:'Y
  1. ; User wants to go through with removing drug from device
  1. N PSJSTOP S PSJSTOP=0
  1. F Q:$G(PSJSTOP) D UNLDONE(PADEV)
  1. Q
  1. ;
  1. UNLDONE(PADEV) ; Manually unload a drug from a pocket
  1. ; Input : PADIEN = PADE Dispensing Device IEN (required)
  1. ;
  1. N PSJINP,PSDRG,PSJCSUB,SCHLST,PADIEN,DRWIEN,DRGIEN,DRGDEV,PCKIEN,DRWPCK,DRGDEV,PSJDRC,DRUG
  1. S PSJSTOP=0,DRWPCK="",DRWIEN="",DRGIEN="",PCKIEN=""
  1. Q:'$G(PADEV) ; Quit if device IEN not passed in
  1. S PSJPSYS=$P($G(^PS(58.63,+PADEV,0)),"^",2)
  1. Q:'$G(PSJPSYS) ; Quit if device not in inventory file
  1. ; Get internal pointer to device from inventory file
  1. S PADIEN=$O(^PS(58.601,+PSJPSYS,"DEVICE","B",+PADEV,""))
  1. S PSJINP("PADEV",PADEV)="",PSJINP("PADEV")=PADEV
  1. S PSJINP("PSJPSYS")=PSJPSYS
  1. ; Find drugs stocked in device, all CS schedules
  1. S SCHLST="1:Schedule I;2:Schedule II;2n:Schedule II Non-Narcotics;3:Schedule III;3n:Schedule III Non-Narcotics;4:Schedule IV;5:Schedule V"
  1. S PSJCSUB="ALL" D ALLSCHED^PSJPDRIP(.PSJCSUB,SCHLST) S PSJCSUB="ALL" M PSJINP("PSJCSUB")=PSJCSUB
  1. S PSJINP("PSJCSUB",0)="Unscheduled"
  1. S PSJINP("MANUNLOD")=1
  1. D DRCAB^PSJPDRIN(.PSJINP,.PSJDRC)
  1. ; Prompt user to select drug
  1. D DRUGSEL^PSJPDRTR(.PSJINP,.PSJDRC,.DRUG,.DRWPCK,.PSJSTOP) ; Prompt for drug items
  1. I $G(DRWPCK)="" S PSJSTOP=1
  1. Q:$G(PSJSTOP) ; nothing selected
  1. ; If ALL drugs selected, reset device and quit
  1. I DRWPCK="ALL" S PSJINP("PSDRG")="ALL" D ASKRESET^PSJPADPT(PADEV) Q
  1. N PCKSTR,SELCNT,PCKCNT,PSJSELY,PCKSEL,DIR
  1. S PCKSTR="",PCKCNT=0
  1. ; If specific drugs selected, find pockets containing drug, display for selection
  1. I DRWPCK'="ALL" S PSJINP("PSDRG")=DRWPCK D
  1. .N POCKET
  1. .S DRWIEN=0 F S DRWIEN=$O(DRWPCK(DRWPCK,DRWIEN)) Q:'DRWIEN D
  1. ..S POCKET=0 F S POCKET=$O(DRWPCK(DRWPCK,DRWIEN,POCKET)) Q:'POCKET D
  1. ...N PCKNAME,DRGDRW,SUBID
  1. ...S PCKNAME=$P($G(DRWPCK(DRWPCK,DRWIEN,POCKET)),"^")
  1. ...S DRGDRW=$P($G(DRWPCK(DRWPCK,DRWIEN,POCKET)),"^",2)
  1. ...S SUBID=$P($P($G(DRWPCK(DRWPCK,DRWIEN,POCKET)),"^",4),"~~") S:SUBID="" SUBID="-"
  1. ...S PCKSEL=PCKCNT+1_":"_PCKNAME
  1. ...S PCKSEL(PCKCNT+1)=DRWPCK_"^"_DRWIEN_"^"_POCKET_"^"_PCKNAME_"^"_DRGDRW_$S($L(SUBID):"^"_SUBID,1:"")
  1. ...I PCKCNT=0 S PCKSTR=PCKSEL,PCKCNT=PCKCNT+1 Q
  1. ...S PCKSTR=$G(PCKSTR)_";"_PCKSEL
  1. ...S PCKCNT=PCKCNT+1
  1. .Q:'PCKCNT
  1. .S DIR(0)="SA^"_PCKSTR,DIR("A")="Select Pocket: "
  1. .F SELCNT=1:1:$L(PCKSTR,";") Q:$P(PCKSTR,";",SELCNT)="" D
  1. ..N SUBID S SUBID=$P($G(PCKSEL(SELCNT)),"^",6)
  1. ..S DIR("A",SELCNT)=" "_$P($P(PCKSTR,";",SELCNT),":")_" - Drawer "_$P($P($P(PCKSTR,";",SELCNT),":",2),"_")_" Pocket "_$P($P($P(PCKSTR,";",SELCNT),":",2),"_",2)_$S($L(SUBID):" Subdrawer: "_SUBID,1:"")
  1. .D ^DIR I Y'>0 S PSJSTOP=1 Q
  1. .S PSJSELY=$G(PCKSEL(+Y))
  1. ; Get sub-file pointers to drawer and pocket selected by user
  1. Q:$G(PSJSTOP)
  1. S DRWIEN=$P($G(PSJSELY),"^",2)
  1. S PCKIEN=$P($G(PSJSELY),"^",3)
  1. S DRGDRW=$P($G(PSJSELY),"^",5)
  1. S DRGDEV=$G(DRWPCK(DRWPCK,"DRGDEV"))
  1. ; If the drug is not stocked in more than one pocket, set the device balance to zero so the UNLOAD removes it completely from device
  1. I '(PCKCNT>1) D
  1. .S DEVBAL=$P($G(^PS(58.601,+$G(PSJPSYS),"DEVICE",+$G(PADIEN),"DRUG",+$G(DRGDEV),0)),"^",3)
  1. .I DEVBAL S $P(^PS(58.601,+$G(PSJPSYS),"DEVICE",+$G(PADIEN),"DRUG",+$G(DRGDEV),0),"^",3)=0
  1. D UNLOAD(PSJPSYS,PADIEN,DRWIEN,DRGDRW,DRGDEV,PCKIEN)
  1. W " ...Done."
  1. N DIR,X,Y S DIR(0)="Y"
  1. S DIR("A")="Delete another drug"
  1. D ^DIR
  1. I '$G(Y) S PSJSTOP=1
  1. Q
  1. ;
  1. UNLHLP ; Display help text explaining PADE manual unload
  1. N HELPAR
  1. S HELPAR(1)="This action removes one drug item from a specific pocket from this"
  1. S HELPAR(2)="PADE dispensing device in VistA. Manually deleting a drug item does"
  1. S HELPAR(3)="not affect the PADE vendor, and does not trigger any HL7 messages to"
  1. S HELPAR(4)="the PADE vendor system. Manually deleting a drug item reduces the"
  1. S HELPAR(5)="quantity of the drug that displays as available in VistA when running"
  1. S HELPAR(6)="the PADE INVENTORY REPORT, and also removes the drug from balances"
  1. S HELPAR(7)="displayed in Inpatient Order Entry."
  1. S HELPAR(8)="After a drug is deleted, the drug may be added back to the cabinet's"
  1. S HELPAR(9)="inventory as new HL7 messages are received from the vendor."
  1. D EN^DDIOL(.HELPAR)
  1. Q
  1. ;
  1. OLDPKUP(TMPADATA,ERRMSG,PS586IEN) ; Return 1 if data in TMPADATA indicates this pocket was updated more recently than the current transaction's date/time
  1. N POCKSUB ; POCKET_SUBDRAWER concatenated
  1. N PSPRVDT ; The last transaction date/time (date/time of the activity at the cabinet) this pocket was updated
  1. N PSPRVDIE ; The IEN of the last transaction date/time in the "PKUPDT" multiple
  1. N FDA,PSJPSYS,PSJSCR,PSJSCR
  1. ;
  1. K DIERR,ERR S TMPADATA("SYS IEN")=$$FIND1^DIC(58.601,"","MX",$G(TMPADATA(1)),,,"ERR") K DIERR ;*356
  1. I '$G(TMPADATA("SYS IEN")) Q 0
  1. ;
  1. I '($G(TMPADATA(2))]"") Q 0
  1. I $G(PSJPSYS),$G(^PS(58.601,+PSJPSYS,0))]"" S TMPADATA("SYS IEN")=PSJPSYS
  1. S PSJPSYS=TMPADATA("SYS IEN"),PSJSCR="I $S('$G(PSJPSYS):1,1:PSJPSYS=$P(^(0),U,2))"
  1. I ($G(TMPADATA(1))=""&$G(PSJPSYS)) S TMPADATA(1)=$P(^PS(58.601,PSJPSYS,0),"^")
  1. K ERR,DIERR S TMPADATA("DEVICE IEN")=$$FIND1^DIC(58.63,,"BX",TMPADATA(2),,PSJSCR,"ERR") K DIERR ;*356
  1. Q:'$G(TMPADATA("DEVICE IEN")) 0
  1. S TMPADATA("DEVICE IEN")=$O(^PS(58.601,+$G(TMPADATA("SYS IEN")),"DEVICE","B",TMPADATA("DEVICE IEN"),0))
  1. Q:'$G(TMPADATA("DEVICE IEN")) 0
  1. ;
  1. I $G(TMPADATA(3))="" S TMPADATA(3)="zz"
  1. S TMPADATA("DRAWER IEN")=$O(^PS(58.601,+$G(TMPADATA("SYS IEN")),"DEVICE",+$G(TMPADATA("DEVICE IEN")),"DRAWER","B",$G(TMPADATA(3)),0))
  1. I '$G(TMPADATA("DRAWER IEN")) Q 0
  1. ;
  1. N DRUG,DEVIEN,SYSIEN
  1. S DRUG=$G(TMPADATA(4)) ; Drug
  1. S DEVIEN=$G(TMPADATA("DEVICE IEN")) ; Dispensing Device IEN
  1. S SYSIEN=$G(TMPADATA("SYS IEN")) ; PADE System IEN
  1. I '(DRUG]"") Q 0 ; No drug, no go
  1. I '$D(^PSDRUG(DRUG,0)) Q 0 ; No valid drug
  1. ; Must have PADE system and Dispensing Device
  1. I '$G(DEVIEN) Q 0
  1. I '$G(SYSIEN) Q 0
  1. ;
  1. N DA,FDA,X,Y,DIC,DIE,DR,D0,ERR,D,DD,DICR,DICRS,DO
  1. S TMPADATA("DRUG DEV IEN")=$$FIND1^DIC(58.60111,","_DEVIEN_","_SYSIEN_",","MXQ",DRUG,,,"ERR") K DIERR ;*356
  1. ;
  1. S TMPADATA(10)=$TR(TMPADATA(10),"~~")_"~~"_+$G(TMPADATA(4)) ; Append subdrawer unique drug IEN suffix to handle different drugs in same subdr-pocket combo
  1. S:$G(TMPADATA(10))="" TMPADATA(10)=$P($G(^PS(58.6,+$G(PS586IEN),0)),"^",12) S:TMPADATA(10)="" TMPADATA(10)="~~"_+$G(TMPADATA(4))
  1. S POCKSUB=$G(TMPADATA(7))_"_"_$G(TMPADATA(10)) ; "POCKET_SUBDRAWER" storage location
  1. K ERR,DIERR S TMPADATA("POCK/SUB IEN")=$$FIND1^DIC(58.601122,","_TMPADATA("DRAWER IEN")_","_TMPADATA("DEVICE IEN")_","_TMPADATA("SYS IEN")_",","MX",POCKSUB,,,"ERR") K DIERR ;*356
  1. ; Get the last date/time this drawer/subdrawer~drug/pocket was updated
  1. S PSPRVDIE=$O(^PS(58.601,+$G(TMPADATA("SYS IEN")),"DEVICE",+$G(TMPADATA("DEVICE IEN")),"DRAWER",+$G(TMPADATA("DRAWER IEN")),"PKUPDT","B",POCKSUB,""))
  1. ;
  1. S PSPRVDT=$P($G(^PS(58.601,+$G(TMPADATA("SYS IEN")),"DEVICE",+$G(TMPADATA("DEVICE IEN")),"DRAWER",+$G(TMPADATA("DRAWER IEN")),"PKUPDT",+$G(PSPRVDIE),0)),"^",2)
  1. ; If this current update contains a transaction date/time (i.e., activity date/time) older than the last update, don't update inventory
  1. I $G(PSPRVDT)&$G(TMPADATA(9)) I TMPADATA(9)<PSPRVDT D Q 1
  1. .S ERRMSG="- OUTDATED TRANSACTION - "_$G(TMPADATA(1))_"."_$G(TMPADATA(2))_".DRUG="_$P($G(^PSDRUG(+$G(TMPADATA(4)),0)),"^")_"("_$G(TMPADATA(4))_").POCKET="_$G(TMPADATA(7))
  1. .S ERRMSG=ERRMSG_".LAST UPDATED="_PSPRVDT_".TRANS DT="_TMPADATA(9)
  1. Q 0