DGPFAPI1 ;ALB/RBS - PRF EXTERNAL API'S ; 9/27/06 3:00pm
;;5.3;Registration;**554,650,1015**;Aug 13, 1993;Build 21
;
Q ;no direct entry
;
GETHTIU(DGDFN,DGTITLE,DGHTIU) ;retrieve PRF/TIU PN link Assignment data
;This function is used to return a patient's ASSIGNMENT (active or
;inactive) based on the TIU PN title. If an ASSIGNMENT is found
;then all ASSIGNMENT HISTORY records will be returned.
;If the request is not from the Owner Site of the PRF Assignment,
;no data is returned.
;The TIU Progress Note Title IEN will be used to search for the
;patient assignment that is linked to the associated record flag.
;
; Associated DBIA: #4383 - DGPF ASSIGNMENT LINK TIU PN
;
; Input:
; DGDFN - [Required] IEN of PATIENT (#2) file
; DGTITLE - [Required] IEN of TIU DOCUMENT DEFINITION (#8925.1) file
; DGHTIU - [Optional] - default name is "DGPFHTIU"
; (Closed Root (local or global) array of return values)
;
; Output:
; Function result - returns 1 on success
; - returns two piece string on failure
; Format: 0^error text generated from EZBLD^DIALOG
;
; DGHTIU() - Array, passed by closed root reference.
; If this function is successful, this array will
; contain the PRF/TIU PN link Assignment data where
; the Subscript field value equals:
; Internal Value^External Value
; Note: The "HISTORY" subscript level will contain a
; unique node for each PRF Assignment History record
; associated with the Assignment where nn = a unique
; number for each History record.
;
; Subscript Field Name Field #/File #
; ----------------------- ----------- ------------
; "ASSIGNIEN" NUMBER (.001)/(#26.13)
; "FLAG" FLAG NAME (.02)/(#26.13)
; "HISTORY" # OF HISTORY RECORDS N/A
; "HISTORY",nn,"ACTION" ACTION (.03)/(#26.14)
; "HISTORY",nn,"DATETIME") DATE/TIME (.02)/(#26.14)
; "HISTORY",nn,"HISTIEN") NUMBER (.001)/(#26.14)
; "HISTORY",nn,"TIUIEN") TIU PN LINK (.06)/(#26.14)
;
N DGAIEN ;ien of record flag assignment in (#26.13) file
N DGDIALOG ;failure reason generated from EZBLD^DIALOG
N DGFIEN ;variable pointer to #26.11 or #26.15 ie. "1;DGPF(26.15,"
N DGFLAG ;flag name
N DGHIEN ;ien of history record in (#26.14) file
N DGHIENS ;array of all assignment history IEN's
N DGPFA ;flag assignment array
N DGPFAH ;flag assignment history array
N DGRSLT ;function result
N DGTHCNT ;"nn"=number of history records returned
;
S DGDFN=+$G(DGDFN)
S DGTITLE=+$G(DGTITLE)
;
;setup return array
S DGHTIU=$G(DGHTIU)
I DGHTIU']"" S DGHTIU="DGPFHTIU" ;setup default array name
K @DGHTIU ;Kill/initialize work array
;
S DGRSLT=0
;
;get IEN variable pointer of National or Local flag
S DGFIEN=$P($$FNDTITLE(DGTITLE),U,1) ;strip off flag name
;
I '$G(DGFIEN) S DGDIALOG=$$EZBLD^DIALOG(261107) ;no flag link
;
;if flag is assoc with TIU Progres Note Title (quit on failure)
I $G(DGFIEN) D
. ;
. ;get IEN of assignment linked to flag linked to TIU PN Title
. S DGAIEN=$$FNDASGN^DGPFAA(DGDFN,DGFIEN)
. I '$G(DGAIEN) S DGDIALOG=$$EZBLD^DIALOG(261108) Q
. ;
. ;get all assignment data for patient
. I '$$GETASGN^DGPFAA(DGAIEN,.DGPFA) S DGDIALOG=$$EZBLD^DIALOG(261102) Q
. ;
. ;check for owner site of assignment
. I '$$ISDIV^DGPFUT($P(DGPFA("OWNER"),U)) S DGDIALOG=$$EZBLD^DIALOG(261103) Q
. ;
. ;get all history ien's
. I '$$GETALL^DGPFAAH(DGAIEN,.DGHIENS) S DGDIALOG=$$EZBLD^DIALOG(261101) Q
. ;
. S DGHIEN="",DGTHCNT=0
. ;
. ;loop all assignment history ien's
. F S DGHIEN=$O(DGHIENS(DGHIEN)) Q:DGHIEN="" D Q:$D(DGDIALOG)
. . K DGPFAH
. . ;get assignment history record
. . I '$$GETHIST^DGPFAAH(DGHIEN,.DGPFAH) S DGDIALOG=$$EZBLD^DIALOG(261101),DGTHCNT=0 Q
. . ;
. . S DGTHCNT=DGTHCNT+1
. . S @DGHTIU@("HISTORY",DGTHCNT,"ACTION")=$G(DGPFAH("ACTION"))
. . S @DGHTIU@("HISTORY",DGTHCNT,"DATETIME")=$G(DGPFAH("ASSIGNDT"))
. . S @DGHTIU@("HISTORY",DGTHCNT,"HISTIEN")=DGHIEN_U_DGHIEN
. . S @DGHTIU@("HISTORY",DGTHCNT,"TIUIEN")=$G(DGPFAH("TIULINK"))
. ;
. Q:$D(DGDIALOG) ;stop on error
. ;
. I DGTHCNT D
. . S @DGHTIU@("ASSIGNIEN")=DGAIEN_U_$P($G(DGPFA("DFN")),U,2)
. . S @DGHTIU@("FLAG")=$G(DGPFA("FLAG"))
. . S @DGHTIU@("HISTORY")=DGTHCNT
. ;
. S DGRSLT=1 ;success
;
;if failure delete return array
I $D(DGDIALOG) K @DGHTIU
;
Q $S(DGRSLT:1,1:DGRSLT_"^"_$G(DGDIALOG))
;
FNDTITLE(DGTITLE) ;retrieve IEN of associated PRF (National or Local) Flag
;This function returns the IEN and Name of the National or Local flag
;that is associated with the TIU Progress Note Title.
;
; Input:
; DGTITLE - [Required] IEN of TIU DOCUMENT DEFINITION (#8925.1) file
;
; Output:
; Function Value - returns two piece ^ string on failure or success
; On Failure - 0^error text generated from EZBLD^DIALOG
; On Success - IEN^External Flag Name
; [example: 1;DGPF(26.15,^BEHAVIORAL]
; [Note: "1;DGPF(26.15," is a variable pointer]
;
S DGTITLE=+$G(DGTITLE)
;
N DGDIALOG ;failure reason
N DGFLAG ;flag name
N DGIEN ;ien of flag
;
; search for Local Flag
I $D(^DGPF(26.11,"ATIU",DGTITLE)) D
. S DGFLAG=$O(^DGPF(26.11,"ATIU",DGTITLE,""))
. I DGFLAG]"" D
. . S DGIEN=$O(^DGPF(26.11,"ATIU",DGTITLE,DGFLAG,0))
. . I '$D(^DGPF(26.11,DGIEN,0)) K DGIEN Q
. . S:$G(DGIEN) DGIEN=DGIEN_";DGPF(26.11,^"_DGFLAG ;add flag name
;
; search for National Flag - (if Title not found in Local Flag file)
I '$G(DGIEN),$D(^DGPF(26.15,"ATIU",DGTITLE)) D
. S DGFLAG=$O(^DGPF(26.15,"ATIU",DGTITLE,""))
. I DGFLAG]"" D
. . S DGIEN=$O(^DGPF(26.15,"ATIU",DGTITLE,DGFLAG,0))
. . I '$D(^DGPF(26.15,DGIEN,0)) K DGIEN Q
. . S:$G(DGIEN) DGIEN=DGIEN_";DGPF(26.15,^"_DGFLAG ;add flag name
;
I '$G(DGIEN) S DGDIALOG=$$EZBLD^DIALOG(261107)
;
Q $S($G(DGIEN)>0:DGIEN,1:"0^"_$G(DGDIALOG))
;
GETLINK(DGTIUIEN) ;get linked assignment history ien
;This function returns the IEN of a patient's record flag assignment
;history record that is linked to a specific TIU Progress Note.
;
; Associated DBIA: #4383 - DGPF ASSIGNMENT LINK TIU PN
;
; Input:
; DGTIUIEN - [Required] IEN of TIU DOCUMENT (#8925) file
;
; Output:
; Function result - returns IEN of linked history record on success
; - "0" if no link found
;
Q +$O(^DGPF(26.14,"ATIUPN",+$G(DGTIUIEN),0))
DGPFAPI1 ;ALB/RBS - PRF EXTERNAL API'S ; 9/27/06 3:00pm
+1 ;;5.3;Registration;**554,650,1015**;Aug 13, 1993;Build 21
+2 ;
+3 ;no direct entry
QUIT
+4 ;
GETHTIU(DGDFN,DGTITLE,DGHTIU) ;retrieve PRF/TIU PN link Assignment data
+1 ;This function is used to return a patient's ASSIGNMENT (active or
+2 ;inactive) based on the TIU PN title. If an ASSIGNMENT is found
+3 ;then all ASSIGNMENT HISTORY records will be returned.
+4 ;If the request is not from the Owner Site of the PRF Assignment,
+5 ;no data is returned.
+6 ;The TIU Progress Note Title IEN will be used to search for the
+7 ;patient assignment that is linked to the associated record flag.
+8 ;
+9 ; Associated DBIA: #4383 - DGPF ASSIGNMENT LINK TIU PN
+10 ;
+11 ; Input:
+12 ; DGDFN - [Required] IEN of PATIENT (#2) file
+13 ; DGTITLE - [Required] IEN of TIU DOCUMENT DEFINITION (#8925.1) file
+14 ; DGHTIU - [Optional] - default name is "DGPFHTIU"
+15 ; (Closed Root (local or global) array of return values)
+16 ;
+17 ; Output:
+18 ; Function result - returns 1 on success
+19 ; - returns two piece string on failure
+20 ; Format: 0^error text generated from EZBLD^DIALOG
+21 ;
+22 ; DGHTIU() - Array, passed by closed root reference.
+23 ; If this function is successful, this array will
+24 ; contain the PRF/TIU PN link Assignment data where
+25 ; the Subscript field value equals:
+26 ; Internal Value^External Value
+27 ; Note: The "HISTORY" subscript level will contain a
+28 ; unique node for each PRF Assignment History record
+29 ; associated with the Assignment where nn = a unique
+30 ; number for each History record.
+31 ;
+32 ; Subscript Field Name Field #/File #
+33 ; ----------------------- ----------- ------------
+34 ; "ASSIGNIEN" NUMBER (.001)/(#26.13)
+35 ; "FLAG" FLAG NAME (.02)/(#26.13)
+36 ; "HISTORY" # OF HISTORY RECORDS N/A
+37 ; "HISTORY",nn,"ACTION" ACTION (.03)/(#26.14)
+38 ; "HISTORY",nn,"DATETIME") DATE/TIME (.02)/(#26.14)
+39 ; "HISTORY",nn,"HISTIEN") NUMBER (.001)/(#26.14)
+40 ; "HISTORY",nn,"TIUIEN") TIU PN LINK (.06)/(#26.14)
+41 ;
+42 ;ien of record flag assignment in (#26.13) file
NEW DGAIEN
+43 ;failure reason generated from EZBLD^DIALOG
NEW DGDIALOG
+44 ;variable pointer to #26.11 or #26.15 ie. "1;DGPF(26.15,"
NEW DGFIEN
+45 ;flag name
NEW DGFLAG
+46 ;ien of history record in (#26.14) file
NEW DGHIEN
+47 ;array of all assignment history IEN's
NEW DGHIENS
+48 ;flag assignment array
NEW DGPFA
+49 ;flag assignment history array
NEW DGPFAH
+50 ;function result
NEW DGRSLT
+51 ;"nn"=number of history records returned
NEW DGTHCNT
+52 ;
+53 SET DGDFN=+$GET(DGDFN)
+54 SET DGTITLE=+$GET(DGTITLE)
+55 ;
+56 ;setup return array
+57 SET DGHTIU=$GET(DGHTIU)
+58 ;setup default array name
IF DGHTIU']""
SET DGHTIU="DGPFHTIU"
+59 ;Kill/initialize work array
KILL @DGHTIU
+60 ;
+61 SET DGRSLT=0
+62 ;
+63 ;get IEN variable pointer of National or Local flag
+64 ;strip off flag name
SET DGFIEN=$PIECE($$FNDTITLE(DGTITLE),U,1)
+65 ;
+66 ;no flag link
IF '$GET(DGFIEN)
SET DGDIALOG=$$EZBLD^DIALOG(261107)
+67 ;
+68 ;if flag is assoc with TIU Progres Note Title (quit on failure)
+69 IF $GET(DGFIEN)
Begin DoDot:1
+70 ;
+71 ;get IEN of assignment linked to flag linked to TIU PN Title
+72 SET DGAIEN=$$FNDASGN^DGPFAA(DGDFN,DGFIEN)
+73 IF '$GET(DGAIEN)
SET DGDIALOG=$$EZBLD^DIALOG(261108)
QUIT
+74 ;
+75 ;get all assignment data for patient
+76 IF '$$GETASGN^DGPFAA(DGAIEN,.DGPFA)
SET DGDIALOG=$$EZBLD^DIALOG(261102)
QUIT
+77 ;
+78 ;check for owner site of assignment
+79 IF '$$ISDIV^DGPFUT($PIECE(DGPFA("OWNER"),U))
SET DGDIALOG=$$EZBLD^DIALOG(261103)
QUIT
+80 ;
+81 ;get all history ien's
+82 IF '$$GETALL^DGPFAAH(DGAIEN,.DGHIENS)
SET DGDIALOG=$$EZBLD^DIALOG(261101)
QUIT
+83 ;
+84 SET DGHIEN=""
SET DGTHCNT=0
+85 ;
+86 ;loop all assignment history ien's
+87 FOR
SET DGHIEN=$ORDER(DGHIENS(DGHIEN))
IF DGHIEN=""
QUIT
Begin DoDot:2
+88 KILL DGPFAH
+89 ;get assignment history record
+90 IF '$$GETHIST^DGPFAAH(DGHIEN,.DGPFAH)
SET DGDIALOG=$$EZBLD^DIALOG(261101)
SET DGTHCNT=0
QUIT
+91 ;
+92 SET DGTHCNT=DGTHCNT+1
+93 SET @DGHTIU@("HISTORY",DGTHCNT,"ACTION")=$GET(DGPFAH("ACTION"))
+94 SET @DGHTIU@("HISTORY",DGTHCNT,"DATETIME")=$GET(DGPFAH("ASSIGNDT"))
+95 SET @DGHTIU@("HISTORY",DGTHCNT,"HISTIEN")=DGHIEN_U_DGHIEN
+96 SET @DGHTIU@("HISTORY",DGTHCNT,"TIUIEN")=$GET(DGPFAH("TIULINK"))
End DoDot:2
IF $DATA(DGDIALOG)
QUIT
+97 ;
+98 ;stop on error
IF $DATA(DGDIALOG)
QUIT
+99 ;
+100 IF DGTHCNT
Begin DoDot:2
+101 SET @DGHTIU@("ASSIGNIEN")=DGAIEN_U_$PIECE($GET(DGPFA("DFN")),U,2)
+102 SET @DGHTIU@("FLAG")=$GET(DGPFA("FLAG"))
+103 SET @DGHTIU@("HISTORY")=DGTHCNT
End DoDot:2
+104 ;
+105 ;success
SET DGRSLT=1
End DoDot:1
+106 ;
+107 ;if failure delete return array
+108 IF $DATA(DGDIALOG)
KILL @DGHTIU
+109 ;
+110 QUIT $SELECT(DGRSLT:1,1:DGRSLT_"^"_$GET(DGDIALOG))
+111 ;
FNDTITLE(DGTITLE) ;retrieve IEN of associated PRF (National or Local) Flag
+1 ;This function returns the IEN and Name of the National or Local flag
+2 ;that is associated with the TIU Progress Note Title.
+3 ;
+4 ; Input:
+5 ; DGTITLE - [Required] IEN of TIU DOCUMENT DEFINITION (#8925.1) file
+6 ;
+7 ; Output:
+8 ; Function Value - returns two piece ^ string on failure or success
+9 ; On Failure - 0^error text generated from EZBLD^DIALOG
+10 ; On Success - IEN^External Flag Name
+11 ; [example: 1;DGPF(26.15,^BEHAVIORAL]
+12 ; [Note: "1;DGPF(26.15," is a variable pointer]
+13 ;
+14 SET DGTITLE=+$GET(DGTITLE)
+15 ;
+16 ;failure reason
NEW DGDIALOG
+17 ;flag name
NEW DGFLAG
+18 ;ien of flag
NEW DGIEN
+19 ;
+20 ; search for Local Flag
+21 IF $DATA(^DGPF(26.11,"ATIU",DGTITLE))
Begin DoDot:1
+22 SET DGFLAG=$ORDER(^DGPF(26.11,"ATIU",DGTITLE,""))
+23 IF DGFLAG]""
Begin DoDot:2
+24 SET DGIEN=$ORDER(^DGPF(26.11,"ATIU",DGTITLE,DGFLAG,0))
+25 IF '$DATA(^DGPF(26.11,DGIEN,0))
KILL DGIEN
QUIT
+26 ;add flag name
IF $GET(DGIEN)
SET DGIEN=DGIEN_";DGPF(26.11,^"_DGFLAG
End DoDot:2
End DoDot:1
+27 ;
+28 ; search for National Flag - (if Title not found in Local Flag file)
+29 IF '$GET(DGIEN)
IF $DATA(^DGPF(26.15,"ATIU",DGTITLE))
Begin DoDot:1
+30 SET DGFLAG=$ORDER(^DGPF(26.15,"ATIU",DGTITLE,""))
+31 IF DGFLAG]""
Begin DoDot:2
+32 SET DGIEN=$ORDER(^DGPF(26.15,"ATIU",DGTITLE,DGFLAG,0))
+33 IF '$DATA(^DGPF(26.15,DGIEN,0))
KILL DGIEN
QUIT
+34 ;add flag name
IF $GET(DGIEN)
SET DGIEN=DGIEN_";DGPF(26.15,^"_DGFLAG
End DoDot:2
End DoDot:1
+35 ;
+36 IF '$GET(DGIEN)
SET DGDIALOG=$$EZBLD^DIALOG(261107)
+37 ;
+38 QUIT $SELECT($GET(DGIEN)>0:DGIEN,1:"0^"_$GET(DGDIALOG))
+39 ;
GETLINK(DGTIUIEN) ;get linked assignment history ien
+1 ;This function returns the IEN of a patient's record flag assignment
+2 ;history record that is linked to a specific TIU Progress Note.
+3 ;
+4 ; Associated DBIA: #4383 - DGPF ASSIGNMENT LINK TIU PN
+5 ;
+6 ; Input:
+7 ; DGTIUIEN - [Required] IEN of TIU DOCUMENT (#8925) file
+8 ;
+9 ; Output:
+10 ; Function result - returns IEN of linked history record on success
+11 ; - "0" if no link found
+12 ;
+13 QUIT +$ORDER(^DGPF(26.14,"ATIUPN",+$GET(DGTIUIEN),0))