DGPFAPI1 ;ALB/RBS - PRF EXTERNAL API'S ; 9/27/06 3:00pm
 ;;5.3;Registration;**554,650,951**;Aug 13, 1993;Build 135
 ;     Lasted Edited: SHRPE/SGM - Feb 16, 2018 12:48
 ;
 ; ICR# TYPE DESCRIPTION
 ;----- ---- -------------------------------------
 ; 2050 Sup  $$EZBLD^DIALOG
 ;
 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,"APPRVBY")   APPROVED BY     (.05)/(#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)
 ; "HISTORY",nn,"ORIGFAC")   ORIGINATING FACILITY (.09)/(#26.14)
 ; dg*3.5*951 - added apprvby, origfac
 ;
 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 Progress 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,1) D  Q
 . . . S DGDIALOG=$$EZBLD^DIALOG(261101),DGTHCNT=0
 . . . Q
 . . ;
 . . S DGTHCNT=DGTHCNT+1
 . . S @DGHTIU@("HISTORY",DGTHCNT,"ACTION")=$G(DGPFAH("ACTION"))
 . . S @DGHTIU@("HISTORY",DGTHCNT,"APPRVBY")=$G(DGPFAH("APPRVBY"))
 . . S @DGHTIU@("HISTORY",DGTHCNT,"DATETIME")=$G(DGPFAH("ASSIGNDT"))
 . . S @DGHTIU@("HISTORY",DGTHCNT,"HISTIEN")=DGHIEN_U_DGHIEN
 . . S @DGHTIU@("HISTORY",DGTHCNT,"TIUIEN")=$G(DGPFAH("TIULINK"))
 . . S @DGHTIU@("HISTORY",DGTHCNT,"ORIGFAC")=$G(DGPFAH("ORIGFAC"))
 . ;
 . 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))
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDGPFAPI1   7291     printed  Sep 23, 2025@20:23:19                                                                                                                                                                                                    Page 2
DGPFAPI1  ;ALB/RBS - PRF EXTERNAL API'S ; 9/27/06 3:00pm
 +1       ;;5.3;Registration;**554,650,951**;Aug 13, 1993;Build 135
 +2       ;     Lasted Edited: SHRPE/SGM - Feb 16, 2018 12:48
 +3       ;
 +4       ; ICR# TYPE DESCRIPTION
 +5       ;----- ---- -------------------------------------
 +6       ; 2050 Sup  $$EZBLD^DIALOG
 +7       ;
 +8       ;no direct entry
           QUIT 
 +9       ;
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,"APPRVBY")   APPROVED BY     (.05)/(#26.14)
 +39      ; "HISTORY",nn,"DATETIME")  DATE/TIME       (.02)/(#26.14)
 +40      ; "HISTORY",nn,"HISTIEN")   NUMBER          (.001)/(#26.14)
 +41      ; "HISTORY",nn,"TIUIEN")    TIU PN LINK     (.06)/(#26.14)
 +42      ; "HISTORY",nn,"ORIGFAC")   ORIGINATING FACILITY (.09)/(#26.14)
 +43      ; dg*3.5*951 - added apprvby, origfac
 +44      ;
 +45      ;ien of record flag assignment in (#26.13) file
           NEW DGAIEN
 +46      ;failure reason generated from EZBLD^DIALOG
           NEW DGDIALOG
 +47      ;variable pointer to #26.11 or #26.15 ie. "1;DGPF(26.15,"
           NEW DGFIEN
 +48      ;flag name
           NEW DGFLAG
 +49      ;ien of history record in (#26.14) file
           NEW DGHIEN
 +50      ;array of all assignment history IEN's
           NEW DGHIENS
 +51      ;flag assignment array
           NEW DGPFA
 +52      ;flag assignment history array
           NEW DGPFAH
 +53      ;function result
           NEW DGRSLT
 +54      ;"nn"=number of history records returned
           NEW DGTHCNT
 +55      ;
 +56       SET DGDFN=+$GET(DGDFN)
 +57       SET DGTITLE=+$GET(DGTITLE)
 +58      ;
 +59      ;setup return array
 +60       SET DGHTIU=$GET(DGHTIU)
 +61      ;setup default array name
           IF DGHTIU']""
               SET DGHTIU="DGPFHTIU"
 +62      ;Kill/initialize work array
           KILL @DGHTIU
 +63      ;
 +64       SET DGRSLT=0
 +65      ;
 +66      ;get IEN variable pointer of National or Local flag
 +67      ;strip off flag name
           SET DGFIEN=$PIECE($$FNDTITLE(DGTITLE),U,1)
 +68      ;
 +69      ;no flag link
           IF '$GET(DGFIEN)
               SET DGDIALOG=$$EZBLD^DIALOG(261107)
 +70      ;
 +71      ;if flag is assoc with TIU Progress Note Title (quit on failure)
 +72       IF $GET(DGFIEN)
               Begin DoDot:1
 +73      ;
 +74      ;get IEN of assignment linked to flag linked to TIU PN Title
 +75               SET DGAIEN=$$FNDASGN^DGPFAA(DGDFN,DGFIEN)
 +76               IF '$GET(DGAIEN)
                       SET DGDIALOG=$$EZBLD^DIALOG(261108)
                       QUIT 
 +77      ;
 +78      ;get all assignment data for patient
 +79               IF '$$GETASGN^DGPFAA(DGAIEN,.DGPFA)
                       SET DGDIALOG=$$EZBLD^DIALOG(261102)
                       QUIT 
 +80      ;
 +81      ;check for owner site of assignment
 +82               IF '$$ISDIV^DGPFUT($PIECE(DGPFA("OWNER"),U))
                       SET DGDIALOG=$$EZBLD^DIALOG(261103)
                       QUIT 
 +83      ;
 +84      ;get all history ien's
 +85               IF '$$GETALL^DGPFAAH(DGAIEN,.DGHIENS)
                       SET DGDIALOG=$$EZBLD^DIALOG(261101)
                       QUIT 
 +86      ;
 +87               SET DGHIEN=""
                   SET DGTHCNT=0
 +88      ;
 +89      ;loop all assignment history ien's
 +90               FOR 
                       SET DGHIEN=$ORDER(DGHIENS(DGHIEN))
                       if DGHIEN=""
                           QUIT 
                       Begin DoDot:2
 +91                       KILL DGPFAH
 +92      ;get assignment history record
 +93                       IF '$$GETHIST^DGPFAAH(DGHIEN,.DGPFAH,1)
                               Begin DoDot:3
 +94                               SET DGDIALOG=$$EZBLD^DIALOG(261101)
                                   SET DGTHCNT=0
 +95                               QUIT 
                               End DoDot:3
                               QUIT 
 +96      ;
 +97                       SET DGTHCNT=DGTHCNT+1
 +98                       SET @DGHTIU@("HISTORY",DGTHCNT,"ACTION")=$GET(DGPFAH("ACTION"))
 +99                       SET @DGHTIU@("HISTORY",DGTHCNT,"APPRVBY")=$GET(DGPFAH("APPRVBY"))
 +100                      SET @DGHTIU@("HISTORY",DGTHCNT,"DATETIME")=$GET(DGPFAH("ASSIGNDT"))
 +101                      SET @DGHTIU@("HISTORY",DGTHCNT,"HISTIEN")=DGHIEN_U_DGHIEN
 +102                      SET @DGHTIU@("HISTORY",DGTHCNT,"TIUIEN")=$GET(DGPFAH("TIULINK"))
 +103                      SET @DGHTIU@("HISTORY",DGTHCNT,"ORIGFAC")=$GET(DGPFAH("ORIGFAC"))
                       End DoDot:2
                       if $DATA(DGDIALOG)
                           QUIT 
 +104     ;
 +105     ;stop on error
                   if $DATA(DGDIALOG)
                       QUIT 
 +106     ;
 +107              IF DGTHCNT
                       Begin DoDot:2
 +108                      SET @DGHTIU@("ASSIGNIEN")=DGAIEN_U_$PIECE($GET(DGPFA("DFN")),U,2)
 +109                      SET @DGHTIU@("FLAG")=$GET(DGPFA("FLAG"))
 +110                      SET @DGHTIU@("HISTORY")=DGTHCNT
                       End DoDot:2
 +111     ;
 +112     ;success
                   SET DGRSLT=1
               End DoDot:1
 +113     ;
 +114     ;if failure delete return array
 +115      IF $DATA(DGDIALOG)
               KILL @DGHTIU
 +116     ;
 +117      QUIT $SELECT(DGRSLT:1,1:DGRSLT_"^"_$GET(DGDIALOG))
 +118     ;
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))