VAQHSH ;ALB/JRP - ENCRYPT A DISPLAY ARRAY;29-MAR-93
 ;;1.5;PATIENT DATA EXCHANGE;;NOV 17, 1993
ENCDSP(TRAN,ROOT,ENCPTR,DSPOFF,DSPCNT) ;ENCRYPT A DISPLAY
 ;INPUT  : TRAN - Pointer to VAQ - TRANSACTION file
 ;         ROOT - Where the Display Array is (full global reference)
 ;         ENCPTR - Pointer to VAQ - ENCRYPTION METHOD file
 ;         DSPOFF - Offset into Display Array to begin at
 ;                  Only used for Display Arrays (defaults to 0)
 ;         DSPCNT - Number of lines in Display Array
 ;                  Only used for Display Arrays (defaults to full array)
 ;OUTPUT : 0 - Success
 ;        -1^Error_Text - Error
 ;NOTES  : If TRAN>0
 ;           Encryption will be based on the transaction
 ;           Keys will come from the transaction
 ;         Else
 ;           Encryption will be based on ENCPTR
 ;           Keys based on current user
 ;       : Existance of TRAN takes precedence over ENCPTR
 ;
 ;CHECK INPUT
 S TRAN=+$G(TRAN)
 S ENCPTR=+$G(ENCPTR)
 Q:(('TRAN)&('ENCPTR)) "-1^Did not pass pointer to transaction or encryption method"
 I (TRAN) Q:('$D(^VAT(394.61,TRAN))) "-1^Did not pass valid pointer to VAQ - TRANSACTION file"
 I (TRAN) S ENCPTR=$$TRANENC^VAQUTL3(TRAN,1) Q:('ENCPTR) "-1^Transaction did not contain pointer to encryption method"
 Q:('ENCPTR) "-1^Did not pass encryption method"
 Q:($G(ROOT)="") "-1^Did not pass location of extracted segment"
 S DSPOFF=+$G(DSPOFF)
 S DSPCNT=+$G(DSPCNT)
 ;DECLARE VARIABLES
 N TMP,ENCMTHD,ENCSTR,STRING,KEY1,KEY2,ERROR,SEQ,SENDER
 S ERROR=0
 ;GET ENCRYPTION METHOD
 S TMP=$$ENCMTHD^VAQUTL2(ENCPTR,0)
 Q:(TMP="") "-1^Could not determine encryption method"
 S ENCMTHD="S ENCSTR="_TMP
 ;DETERMINE PRIMARY KEY
 I (TRAN) S SENDER=$$SENDER^VAQCON2(TRAN) Q:($P(SENDER,"^",1)="-1") "-1^Could not determine encryption keys"
 S:(TRAN) SENDER=$P(SENDER,"^",1)
 S:(TRAN) KEY1=$$NAMEKEY^VAQUTL3(SENDER,1)
 S:('TRAN) KEY1=$$DUZKEY^VAQUTL3($G(DUZ),1)
 ;DETERMINE SECONDARY KEY
 S:(TRAN) KEY2=$$NAMEKEY^VAQUTL3(SENDER,0)
 S:('TRAN) KEY2=$$DUZKEY^VAQUTL3($G(DUZ),0)
 Q:((KEY1="")!(KEY2="")) "-1^Could not determine encryption keys"
 ;LOOP THROUGH EACH LINE IN DISPLAY
 S TMP=DSPOFF-.999999999
 F SEQ=1:1 Q:((DSPCNT)&(SEQ>DSPCNT))  D  Q:((TMP="")!(ERROR))
 .S TMP=$O(@ROOT@("DISPLAY",TMP))
 .Q:(TMP="")
 .;GET LINE
 .S STRING=@ROOT@("DISPLAY",TMP,0)
 .;ENCRYPT LINE (DON'T ENCRYPT A NULL LINE)
 .Q:(STRING="")
 .X ENCMTHD
 .I (ENCSTR="") S ERROR="-1^Error using encryption method" Q
 .;STORE ENCRYPTED LINE
 .S @ROOT@("DISPLAY",TMP,0)=ENCSTR
 Q:(ERROR) ERROR
 Q 0
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAQHSH   2595     printed  Sep 23, 2025@20:01:36                                                                                                                                                                                                      Page 2
VAQHSH    ;ALB/JRP - ENCRYPT A DISPLAY ARRAY;29-MAR-93
 +1       ;;1.5;PATIENT DATA EXCHANGE;;NOV 17, 1993
ENCDSP(TRAN,ROOT,ENCPTR,DSPOFF,DSPCNT) ;ENCRYPT A DISPLAY
 +1       ;INPUT  : TRAN - Pointer to VAQ - TRANSACTION file
 +2       ;         ROOT - Where the Display Array is (full global reference)
 +3       ;         ENCPTR - Pointer to VAQ - ENCRYPTION METHOD file
 +4       ;         DSPOFF - Offset into Display Array to begin at
 +5       ;                  Only used for Display Arrays (defaults to 0)
 +6       ;         DSPCNT - Number of lines in Display Array
 +7       ;                  Only used for Display Arrays (defaults to full array)
 +8       ;OUTPUT : 0 - Success
 +9       ;        -1^Error_Text - Error
 +10      ;NOTES  : If TRAN>0
 +11      ;           Encryption will be based on the transaction
 +12      ;           Keys will come from the transaction
 +13      ;         Else
 +14      ;           Encryption will be based on ENCPTR
 +15      ;           Keys based on current user
 +16      ;       : Existance of TRAN takes precedence over ENCPTR
 +17      ;
 +18      ;CHECK INPUT
 +19       SET TRAN=+$GET(TRAN)
 +20       SET ENCPTR=+$GET(ENCPTR)
 +21       if (('TRAN)&('ENCPTR))
               QUIT "-1^Did not pass pointer to transaction or encryption method"
 +22       IF (TRAN)
               if ('$DATA(^VAT(394.61,TRAN)))
                   QUIT "-1^Did not pass valid pointer to VAQ - TRANSACTION file"
 +23       IF (TRAN)
               SET ENCPTR=$$TRANENC^VAQUTL3(TRAN,1)
               if ('ENCPTR)
                   QUIT "-1^Transaction did not contain pointer to encryption method"
 +24       if ('ENCPTR)
               QUIT "-1^Did not pass encryption method"
 +25       if ($GET(ROOT)="")
               QUIT "-1^Did not pass location of extracted segment"
 +26       SET DSPOFF=+$GET(DSPOFF)
 +27       SET DSPCNT=+$GET(DSPCNT)
 +28      ;DECLARE VARIABLES
 +29       NEW TMP,ENCMTHD,ENCSTR,STRING,KEY1,KEY2,ERROR,SEQ,SENDER
 +30       SET ERROR=0
 +31      ;GET ENCRYPTION METHOD
 +32       SET TMP=$$ENCMTHD^VAQUTL2(ENCPTR,0)
 +33       if (TMP="")
               QUIT "-1^Could not determine encryption method"
 +34       SET ENCMTHD="S ENCSTR="_TMP
 +35      ;DETERMINE PRIMARY KEY
 +36       IF (TRAN)
               SET SENDER=$$SENDER^VAQCON2(TRAN)
               if ($PIECE(SENDER,"^",1)="-1")
                   QUIT "-1^Could not determine encryption keys"
 +37       if (TRAN)
               SET SENDER=$PIECE(SENDER,"^",1)
 +38       if (TRAN)
               SET KEY1=$$NAMEKEY^VAQUTL3(SENDER,1)
 +39       if ('TRAN)
               SET KEY1=$$DUZKEY^VAQUTL3($GET(DUZ),1)
 +40      ;DETERMINE SECONDARY KEY
 +41       if (TRAN)
               SET KEY2=$$NAMEKEY^VAQUTL3(SENDER,0)
 +42       if ('TRAN)
               SET KEY2=$$DUZKEY^VAQUTL3($GET(DUZ),0)
 +43       if ((KEY1="")!(KEY2=""))
               QUIT "-1^Could not determine encryption keys"
 +44      ;LOOP THROUGH EACH LINE IN DISPLAY
 +45       SET TMP=DSPOFF-.999999999
 +46       FOR SEQ=1:1
               if ((DSPCNT)&(SEQ>DSPCNT))
                   QUIT 
               Begin DoDot:1
 +47               SET TMP=$ORDER(@ROOT@("DISPLAY",TMP))
 +48               if (TMP="")
                       QUIT 
 +49      ;GET LINE
 +50               SET STRING=@ROOT@("DISPLAY",TMP,0)
 +51      ;ENCRYPT LINE (DON'T ENCRYPT A NULL LINE)
 +52               if (STRING="")
                       QUIT 
 +53               XECUTE ENCMTHD
 +54               IF (ENCSTR="")
                       SET ERROR="-1^Error using encryption method"
                       QUIT 
 +55      ;STORE ENCRYPTED LINE
 +56               SET @ROOT@("DISPLAY",TMP,0)=ENCSTR
               End DoDot:1
               if ((TMP="")!(ERROR))
                   QUIT 
 +57       if (ERROR)
               QUIT ERROR
 +58       QUIT 0