SCDXFU03 ;ALB/JRP - AMBULATORY CARE FILE UTILITIES;01-JUL-1996
;;5.3;Scheduling;**44,110,121,126,128,1015**;AUG 13, 1993;Build 21
;
DELXMIT(PTR,PTR2) ;Delete entry in TRANSMITTED OUTPATIENT ENCOUNTER
; file (#409.73)
;
;Input : PTR - Pointer to entry in one of the following files
; * TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
; * OUTPATIENT ENCOUNTER file (#409.68)
; * DELETED OUTPATIENT ENCOUNTER file (#409.74)
; PTR2 - Denotes which file PTR points to
; 0 = TRANSMITTED OUTPATIENT ENCOUNTER file (Default)
; 1 = OUTPATIENT ENCOUNTER file
; 2 = DELETED OUTPATIENT ENCOUNTER file
;Output : 0 - Success
; -1 - Unable to delete entry
;Note : Success (0) is returned when a valid pointer to the
; specified file is not passed or an entry in the
; TRANSMITTED OUTPATIENT ENCOUNTER file can not be found
; (Deleting an entry that doesn't exist is successful)
; : If the TRANSMITTED OUTPATIENT ENCOUNTER points to an entry
; in the DELETED OUTPATIENT ENCOUNTER file, the DELETED
; OUTPATIENT ENCOUNTER will also be deleted
;
;Check input
S PTR=+$G(PTR)
S PTR2=+$G(PTR2)
S:((PTR2<0)!(PTR2>2)) PTR2=0
;Declare variables
N DIK,DA,X,Y,DIC,XMITPTR,DELPTR
;Get pointer to TRANSMITTED OUTPATIENT ENCOUNTER file
S XMITPTR=PTR
S:(PTR2=1) XMITPTR=+$O(^SD(409.73,"AENC",PTR,0))
S:(PTR2=2) XMITPTR=+$O(^SD(409.73,"ADEL",PTR,0))
;Entry in TRANSMITTED OUTPATIENT ENCOUNTER file doesn't exist - success
Q:('$D(^SD(409.73,XMITPTR,0))) 0
;Delete all entries in TRANSMITTED OUTPATIENT ENCOUNTER ERROR file
; (#409.75) that refer to entry being deleted
D DELAERR^SCDXFU02(XMITPTR)
;Delete all entries in ACRP Transmission History file (#409.77)
D DELAHIST^SCDXFU10(XMITPTR)
;Delete entry in DELETED OUTPATIENT ENCOUNTER file (#409.74)
S DELPTR=+$$XMIT4DEL^SCDXFU11(XMITPTR)
S:(DELPTR>0) X=$$DELDEL^SCDXFU02(DELPTR)
;Delete entry
S DIK="^SD(409.73,"
S DA=XMITPTR
D ^DIK
;Done
Q 0
;
XMITDATA(XMITPTR,XMITDATE,MID,BID) ;Store transmission data for entry in
; TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
;
;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
; ENCOUNTER file (#409.73)
; XMITDATE - FileMan ate/time entry was transmitted to National
; Patient Care Database (Defaults to NOW)
; MID - Message Control ID used when entry was transmitted
; to National Patient Care Database
; BID - Batch Control ID used when entry was transmitted
; to National Patient Care Database
;Output : None
;
;Check input
S XMITPTR=+$G(XMITPTR)
Q:('$D(^SD(409.73,XMITPTR)))
S XMITDATE=+$G(XMITDATE)
S:('XMITDATE) XMITDATE="NOW"
S MID=$G(MID)
S BID=$G(BID)
;Declare variables
N DIE,DA,DR,DIDEL,X,Y,DIC
;Store transmission data
S DIE="^SD(409.73,"
S DA=XMITPTR
S DR="11///^S X=XMITDATE;12///^S X=MID;13///^S X=BID"
D ^DIE
;Done
Q
;
ACKDATA(XMITPTR,ACKDATE,ACKCODE) ;Store acknowledgement data for entry
; in TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
;
;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
; ENCOUNTER file (#409.73)
; ACKDATE - FileMan date/time acknowledgement from National
; Patient Care Database was received (Defaults to NOW)
; ACKCODE - Denotes type of acknowledgement received
; A = Transmission was accepted (DEFAULT)
; R = Transmission was rejected
; E = Error
;Output : None
;
;Check input
S XMITPTR=+$G(XMITPTR)
Q:('$D(^SD(409.73,XMITPTR)))
S ACKDATE=+$G(ACKDATE)
S:('ACKDATE) ACKDATE="NOW"
S ACKCODE=$G(ACKCODE)
S:("ARE"'[ACKCODE) ACKCODE="A"
;Declare variables
N DIE,DA,DR,DIDEL,X,Y,DIC
;Store acknowledgement data
S DIE="^SD(409.73,"
S DA=XMITPTR
S DR="14///^S X=ACKDATE;15////^S X=ACKCODE"
D ^DIE
;Done
Q
;
XMITED(ENCPTR) ;Determine if Outpatient Encounter was ever transmitted to the
; National Patient Care Database
;
;Input : ENCPTR - Pointer to Outpatient Encounter
;Output : DateTime - Date of last transmission (FileMan format)
; 0 - Encounter never transmitted
;Notes : Zero (0) will be returned on bad input
;
;Check input
S ENCPTR=+$G(ENCPTR)
Q:('ENCPTR) 0
;Declare variables
N XMITPTR,XMITDATE,XMITHIST
S XMITHIST=$NA(^TMP("SCDXFU03",$J,"XMITED"))
K @XMITHIST
;Find entry in transmission file (#409.73)
S XMITPTR=+$O(^SD(409.73,"AENC",ENCPTR,0))
Q:('XMITPTR) 0
Q:('$D(^SD(409.73,XMITPTR,0))) 0
;Get transmission history
S XMITDATE=$$HST4XMIT^SCDXFU13(XMITPTR,XMITHIST,1)
;Get last transmission date/time
S XMITDATE=+$O(@XMITHIST@(""),-1)
;Clean up and return date/time of last transmission
K @XMITHIST
Q XMITDATE
;
ACCEPTED(ENCPTR) ;Determine if Outpatient Encounter was ever accepted
; by the National Patient Care Database (i.e. ACK = Accept)
;
;Input : ENCPTR - Pointer to Outpatient Encounter
;Output : DateTime - Date/time of last successfull ack (FileMan)
; 0 - Encounter never accepted
;Notes : Zero (0) will be returned on bad input
;
;Check input
S ENCPTR=+$G(ENCPTR)
Q:('ENCPTR) 0
;Declare variables
N XMITPTR,ACKDATE,ACKHIST
S ACKHIST=$NA(^TMP("SCDXFU03",$J,"ACCEPTED"))
K @ACKHIST
;Find entry in transmission file (#409.73)
S XMITPTR=+$O(^SD(409.73,"AENC",ENCPTR,0))
Q:('XMITPTR) 0
Q:('$D(^SD(409.73,XMITPTR,0))) 0
;Get acknowledgement history
S ACKDATE=$$HST4XMIT^SCDXFU13(XMITPTR,ACKHIST,2)
;Search history for last ack with code of ACCEPT
S ACKDATE=""
F S ACKDATE=+$O(@ACKHIST@(ACKDATE),-1) Q:('ACKDATE) Q:($P($G(@ACKHIST@(ACKDATE)),"^",3)="A")
;Clean up and return date/time of last successfull ack
K @ACKHIST
Q ACKDATE
;
VIDCNT(VSITID,EXCLUDE) ;Determine the number of parent Outpatient
; Encounters that have the given Visit ID
;
;Input : VSITID - Visit ID to check for (NOT THE POINTER TO 9000010)
; EXCLUDE - Encounter to optionally exclude from count
;Output : N - Number of parent encounters found
;Notes : Stand alone add/edits are considered a parent encounter
; : Zero (0) is returned if the Visit ID is not valid
;
;Check input
S VSITID=$G(VSITID)
Q:(VSITID="") 0
S EXCLUDE=+$G(EXCLUDE)
S:('$D(^SCE(EXCLUDE,0))) EXCLUDE=0
;Declare variables
N ENCPTR,VSITPTR,COUNT
;Get pointer to Visit
S VSITPTR=$$VID2IEN^VSIT(VSITID)
Q:(VSITPTR<1) 0
;Count parent encounters for visit
S COUNT=0
S ENCPTR=0
F S ENCPTR=+$O(^SCE("AVSIT",VSITPTR,ENCPTR)) Q:('ENCPTR) D
.;Bad entry in x-ref
.Q:('$D(^SCE(ENCPTR,0)))
.;Exclude input encounter
.Q:(ENCPTR=EXCLUDE)
.;Screen out children
.Q:(+$P($G(^SCE(ENCPTR,0)),"^",6))
.;Increment count
.S COUNT=COUNT+1
Q COUNT
SCDXFU03 ;ALB/JRP - AMBULATORY CARE FILE UTILITIES;01-JUL-1996
+1 ;;5.3;Scheduling;**44,110,121,126,128,1015**;AUG 13, 1993;Build 21
+2 ;
DELXMIT(PTR,PTR2) ;Delete entry in TRANSMITTED OUTPATIENT ENCOUNTER
+1 ; file (#409.73)
+2 ;
+3 ;Input : PTR - Pointer to entry in one of the following files
+4 ; * TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
+5 ; * OUTPATIENT ENCOUNTER file (#409.68)
+6 ; * DELETED OUTPATIENT ENCOUNTER file (#409.74)
+7 ; PTR2 - Denotes which file PTR points to
+8 ; 0 = TRANSMITTED OUTPATIENT ENCOUNTER file (Default)
+9 ; 1 = OUTPATIENT ENCOUNTER file
+10 ; 2 = DELETED OUTPATIENT ENCOUNTER file
+11 ;Output : 0 - Success
+12 ; -1 - Unable to delete entry
+13 ;Note : Success (0) is returned when a valid pointer to the
+14 ; specified file is not passed or an entry in the
+15 ; TRANSMITTED OUTPATIENT ENCOUNTER file can not be found
+16 ; (Deleting an entry that doesn't exist is successful)
+17 ; : If the TRANSMITTED OUTPATIENT ENCOUNTER points to an entry
+18 ; in the DELETED OUTPATIENT ENCOUNTER file, the DELETED
+19 ; OUTPATIENT ENCOUNTER will also be deleted
+20 ;
+21 ;Check input
+22 SET PTR=+$GET(PTR)
+23 SET PTR2=+$GET(PTR2)
+24 IF ((PTR2<0)!(PTR2>2))
SET PTR2=0
+25 ;Declare variables
+26 NEW DIK,DA,X,Y,DIC,XMITPTR,DELPTR
+27 ;Get pointer to TRANSMITTED OUTPATIENT ENCOUNTER file
+28 SET XMITPTR=PTR
+29 IF (PTR2=1)
SET XMITPTR=+$ORDER(^SD(409.73,"AENC",PTR,0))
+30 IF (PTR2=2)
SET XMITPTR=+$ORDER(^SD(409.73,"ADEL",PTR,0))
+31 ;Entry in TRANSMITTED OUTPATIENT ENCOUNTER file doesn't exist - success
+32 IF ('$DATA(^SD(409.73,XMITPTR,0)))
QUIT 0
+33 ;Delete all entries in TRANSMITTED OUTPATIENT ENCOUNTER ERROR file
+34 ; (#409.75) that refer to entry being deleted
+35 DO DELAERR^SCDXFU02(XMITPTR)
+36 ;Delete all entries in ACRP Transmission History file (#409.77)
+37 DO DELAHIST^SCDXFU10(XMITPTR)
+38 ;Delete entry in DELETED OUTPATIENT ENCOUNTER file (#409.74)
+39 SET DELPTR=+$$XMIT4DEL^SCDXFU11(XMITPTR)
+40 IF (DELPTR>0)
SET X=$$DELDEL^SCDXFU02(DELPTR)
+41 ;Delete entry
+42 SET DIK="^SD(409.73,"
+43 SET DA=XMITPTR
+44 DO ^DIK
+45 ;Done
+46 QUIT 0
+47 ;
XMITDATA(XMITPTR,XMITDATE,MID,BID) ;Store transmission data for entry in
+1 ; TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
+2 ;
+3 ;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
+4 ; ENCOUNTER file (#409.73)
+5 ; XMITDATE - FileMan ate/time entry was transmitted to National
+6 ; Patient Care Database (Defaults to NOW)
+7 ; MID - Message Control ID used when entry was transmitted
+8 ; to National Patient Care Database
+9 ; BID - Batch Control ID used when entry was transmitted
+10 ; to National Patient Care Database
+11 ;Output : None
+12 ;
+13 ;Check input
+14 SET XMITPTR=+$GET(XMITPTR)
+15 IF ('$DATA(^SD(409.73,XMITPTR)))
QUIT
+16 SET XMITDATE=+$GET(XMITDATE)
+17 IF ('XMITDATE)
SET XMITDATE="NOW"
+18 SET MID=$GET(MID)
+19 SET BID=$GET(BID)
+20 ;Declare variables
+21 NEW DIE,DA,DR,DIDEL,X,Y,DIC
+22 ;Store transmission data
+23 SET DIE="^SD(409.73,"
+24 SET DA=XMITPTR
+25 SET DR="11///^S X=XMITDATE;12///^S X=MID;13///^S X=BID"
+26 DO ^DIE
+27 ;Done
+28 QUIT
+29 ;
ACKDATA(XMITPTR,ACKDATE,ACKCODE) ;Store acknowledgement data for entry
+1 ; in TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
+2 ;
+3 ;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
+4 ; ENCOUNTER file (#409.73)
+5 ; ACKDATE - FileMan date/time acknowledgement from National
+6 ; Patient Care Database was received (Defaults to NOW)
+7 ; ACKCODE - Denotes type of acknowledgement received
+8 ; A = Transmission was accepted (DEFAULT)
+9 ; R = Transmission was rejected
+10 ; E = Error
+11 ;Output : None
+12 ;
+13 ;Check input
+14 SET XMITPTR=+$GET(XMITPTR)
+15 IF ('$DATA(^SD(409.73,XMITPTR)))
QUIT
+16 SET ACKDATE=+$GET(ACKDATE)
+17 IF ('ACKDATE)
SET ACKDATE="NOW"
+18 SET ACKCODE=$GET(ACKCODE)
+19 IF ("ARE"'[ACKCODE)
SET ACKCODE="A"
+20 ;Declare variables
+21 NEW DIE,DA,DR,DIDEL,X,Y,DIC
+22 ;Store acknowledgement data
+23 SET DIE="^SD(409.73,"
+24 SET DA=XMITPTR
+25 SET DR="14///^S X=ACKDATE;15////^S X=ACKCODE"
+26 DO ^DIE
+27 ;Done
+28 QUIT
+29 ;
XMITED(ENCPTR) ;Determine if Outpatient Encounter was ever transmitted to the
+1 ; National Patient Care Database
+2 ;
+3 ;Input : ENCPTR - Pointer to Outpatient Encounter
+4 ;Output : DateTime - Date of last transmission (FileMan format)
+5 ; 0 - Encounter never transmitted
+6 ;Notes : Zero (0) will be returned on bad input
+7 ;
+8 ;Check input
+9 SET ENCPTR=+$GET(ENCPTR)
+10 IF ('ENCPTR)
QUIT 0
+11 ;Declare variables
+12 NEW XMITPTR,XMITDATE,XMITHIST
+13 SET XMITHIST=$NAME(^TMP("SCDXFU03",$JOB,"XMITED"))
+14 KILL @XMITHIST
+15 ;Find entry in transmission file (#409.73)
+16 SET XMITPTR=+$ORDER(^SD(409.73,"AENC",ENCPTR,0))
+17 IF ('XMITPTR)
QUIT 0
+18 IF ('$DATA(^SD(409.73,XMITPTR,0)))
QUIT 0
+19 ;Get transmission history
+20 SET XMITDATE=$$HST4XMIT^SCDXFU13(XMITPTR,XMITHIST,1)
+21 ;Get last transmission date/time
+22 SET XMITDATE=+$ORDER(@XMITHIST@(""),-1)
+23 ;Clean up and return date/time of last transmission
+24 KILL @XMITHIST
+25 QUIT XMITDATE
+26 ;
ACCEPTED(ENCPTR) ;Determine if Outpatient Encounter was ever accepted
+1 ; by the National Patient Care Database (i.e. ACK = Accept)
+2 ;
+3 ;Input : ENCPTR - Pointer to Outpatient Encounter
+4 ;Output : DateTime - Date/time of last successfull ack (FileMan)
+5 ; 0 - Encounter never accepted
+6 ;Notes : Zero (0) will be returned on bad input
+7 ;
+8 ;Check input
+9 SET ENCPTR=+$GET(ENCPTR)
+10 IF ('ENCPTR)
QUIT 0
+11 ;Declare variables
+12 NEW XMITPTR,ACKDATE,ACKHIST
+13 SET ACKHIST=$NAME(^TMP("SCDXFU03",$JOB,"ACCEPTED"))
+14 KILL @ACKHIST
+15 ;Find entry in transmission file (#409.73)
+16 SET XMITPTR=+$ORDER(^SD(409.73,"AENC",ENCPTR,0))
+17 IF ('XMITPTR)
QUIT 0
+18 IF ('$DATA(^SD(409.73,XMITPTR,0)))
QUIT 0
+19 ;Get acknowledgement history
+20 SET ACKDATE=$$HST4XMIT^SCDXFU13(XMITPTR,ACKHIST,2)
+21 ;Search history for last ack with code of ACCEPT
+22 SET ACKDATE=""
+23 FOR
SET ACKDATE=+$ORDER(@ACKHIST@(ACKDATE),-1)
IF ('ACKDATE)
QUIT
IF ($PIECE($GET(@ACKHIST@(ACKDATE)),"^",3)="A")
QUIT
+24 ;Clean up and return date/time of last successfull ack
+25 KILL @ACKHIST
+26 QUIT ACKDATE
+27 ;
VIDCNT(VSITID,EXCLUDE) ;Determine the number of parent Outpatient
+1 ; Encounters that have the given Visit ID
+2 ;
+3 ;Input : VSITID - Visit ID to check for (NOT THE POINTER TO 9000010)
+4 ; EXCLUDE - Encounter to optionally exclude from count
+5 ;Output : N - Number of parent encounters found
+6 ;Notes : Stand alone add/edits are considered a parent encounter
+7 ; : Zero (0) is returned if the Visit ID is not valid
+8 ;
+9 ;Check input
+10 SET VSITID=$GET(VSITID)
+11 IF (VSITID="")
QUIT 0
+12 SET EXCLUDE=+$GET(EXCLUDE)
+13 IF ('$DATA(^SCE(EXCLUDE,0)))
SET EXCLUDE=0
+14 ;Declare variables
+15 NEW ENCPTR,VSITPTR,COUNT
+16 ;Get pointer to Visit
+17 SET VSITPTR=$$VID2IEN^VSIT(VSITID)
+18 IF (VSITPTR<1)
QUIT 0
+19 ;Count parent encounters for visit
+20 SET COUNT=0
+21 SET ENCPTR=0
+22 FOR
SET ENCPTR=+$ORDER(^SCE("AVSIT",VSITPTR,ENCPTR))
IF ('ENCPTR)
QUIT
Begin DoDot:1
+23 ;Bad entry in x-ref
+24 IF ('$DATA(^SCE(ENCPTR,0)))
QUIT
+25 ;Exclude input encounter
+26 IF (ENCPTR=EXCLUDE)
QUIT
+27 ;Screen out children
+28 IF (+$PIECE($GET(^SCE(ENCPTR,0)),"^",6))
QUIT
+29 ;Increment count
+30 SET COUNT=COUNT+1
End DoDot:1
+31 QUIT COUNT