VBECDC00 ;hoifo/gjc-data conversion & pre-implementation;Nov 21, 2002
 ;;2.0;VBEC;;Jun 05, 2015;Build 4
 ;
 ;Medical Device #:
 ;Note: The food and Drug Administration classifies this software as a
 ;medical device.  As such, it may not be changed in any way.
 ;Modifications to this software may result in an adulterated medical
 ;device under 21CFR820, the use of which is considered to be a
 ;violation of US Federal Statutes.  Acquiring and implementing this
 ;software through the Freedom of Information Act requires the
 ;implementer to assume total responsibility for the software, and
 ;become a registered manufacturer of a medical device, subject to FDA
 ;regulations.
 ;
 ;Call to $$NEWERR^%ZTER is supported by IA: 1621
 ;Call to $$S^%ZTLOAD is supported by IA: 10063
 ;Call to $$NOW^XLFDT is supported by IA: 10103
 ;Call to ^%ZTLOAD is supported by IA: 10063
 ;Call to UPDATE^DIE is supported by IA: 2053
 ;Execution of ^%ZOSF("TEST") is supported by IA: 10096
 ;Direct global read of ^DPT(DFN,"LR") supported by IA: 10035
 ;
START ; entry point queued/not queued.  Update the VBECS DATA INTEGRITY/CONV
 ; ERSION STATISTICS (#6001)
 ;
 ; Note: the variables VBECCNV & VBECIEN are defined in VBECDC01 and
 ; are passed into START subroutine via the ZTSAVE array when calling
 ; ^%ZTLOAD.
 ;
 S:$D(ZTQUEUED) ZTREQ="@"
 ;
 ; initialize error trap
 I $$NEWERR^%ZTER N $ETRAP,$ESTACK S $ETRAP="D ERR^VBECDCU1"
 E  S X="D ERR^VBECDCU1",@^%ZOSF("TRAP")
 ;
 D:VBECCNV EN^VBECDC19(1) ; lock out options when converting data
 ;
 S (CNT,DFN,LRSTOP)=0 S:$G(U)'="^" U="^" K ^TMP("VBEC 63",$J)
 ;
 ;initialize the global that keeps track of ALL data elements for ALL
 ;records
 ;
 K X S $P(X,"0^",28)="",^TMP("VBEC FINIS",$J,0)=X K X
 K ^TMP($J,"VBEC_TR_REACT"),^TMP($J,"VBEC_TR_TRD") S VBTRA=0 F  S VBTRA=$O(^LRD(65,VBTRA)) Q:'VBTRA  D
  . I $P($G(^LRD(65,VBTRA,6)),"^")]"",$P($G(^LRD(65,VBTRA,6)),"^",5)  D
  . . S VBLRDFN=$P(^LRD(65,VBTRA,6),"^"),VBDFN=$P(^LR(VBLRDFN,0),"^",3) Q:$P(^LR(VBLRDFN,0),"^",2)'=2
  . . S ^TMP($J,"VBEC_TR_REACT",VBDFN,VBTRA)=""
 ;
 ;Create an index in the TMP global to make it easier to find Transfusion Reactions by DFN ;RLM 04/20/2005
 ;
 F  S DFN=$O(^DPT(DFN)) Q:DFN'>0  D  Q:LRSTOP
 .;
 .I $$S^%ZTLOAD() S (ZTSTOP,LRSTOP)=1 Q  ; has the user stopped the task?
 .;
 .Q:'$D(^DPT(DFN,"LR"))#2  ; patient w/o Lab Data (#63) file data
 .;
 .S LRDFN=+$G(^DPT(DFN,"LR"))
 .;
 .I LRDFN'>0 D  Q
 ..K LRARY S LRARY(.01)=2,LRARY(.02)=DFN,LRARY(.09)=$P($T(ERRMSG+1^VBECDC02),";",4)
 ..D LOGEXC^VBECDC02(VBECIEN,.LRARY) K LRARY ; log this exception regardless of the task
 ..Q
 .;
 .I $$BRKPNT^VBECDCU1(LRDFN,DFN) D  Q
 ..K LRARY S LRARY(.01)=2,LRARY(.02)=DFN,LRARY(.03)=63,LRARY(.04)=LRDFN
 ..S LRARY(.09)=$P($T(ERRMSG+2^VBECDC02),";",4)
 ..D LOGEXC^VBECDC02(VBECIEN,.LRARY) K LRARY ; log this exception regardless of the task
 ..Q
 .;
 .I '$O(^LR(LRDFN,"BB",0)) Q  ; blood bank data missing for this patient
 .;
  . I 'LRSTOP,$P(^DPT(DFN,0),"^")["MERGING INTO" S DPTNAME=$P(^DPT(DFN,0),"^") D  Q
  . . S VBECMRG=$P($P(DPTNAME,"`",2)," ")
  . . K LRARY S LRARY(.01)=2,LRARY(.02)=DFN,LRARY(.03)=2,LRARY(.04)=VBECMRG,LRARY(.09)=$P($T(ERRMSG+3^VBECDC02),";",4)
  . . D LOGEXC^VBECDC02(VBECIEN,.LRARY) K LRARY ; log this exception
  . . Q
 .;
 .; if the data conversion process is active save off all LAB DATA file
 .; specific data into the appropriate ^TMP("VBEC 63"*,$J) global
 .;
 .I 'LRSTOP,VBECCNV D PAT^VBECDCX(DFN,LRDFN)
 .;
 .;
 .;save off patient specific data for each record in the Lab Data file
 .I VBECCNV D:$D(^TMP("VBEC FINIS",$J,VBECRTOT,0))#2 PATREC(VBECIEN)
 .Q
 ;
 ; kill off unnecessary ^TMP("VBEC 63",$J) global
 K ^TMP("VBEC 63",$J)
 ;
 ; actions if the user teminates process (a check exists within to
 ; execute specific code depending on if the anomaly check or the data
 ; conversion is executing)
 ;
 S VBECANOM=+$O(^VBEC(6001,VBECIEN,"ERR",0)) ; do anomalies exist?
 ;
 ; If the process was stopped by the user via TaskMan (1)
 ; If errored out, LRSTOP=-1 (set in ERR^VBECDCU1)
 I LRSTOP=1 D STOPPED^VBECDC01
 ;
 ; If the process has completed without user intervention:
 I 'LRSTOP D
 .;
 .; 1-if data to convert, save off the ^TMP("VBEC"*,$J) namespaced
 .;   global into system level files to be extracted by SQL Server
 .;   (make sure data tabulation globals are saved off properly)
 .I VBECCNV,($$DATA^VBECDCU1($J)) D
 ..S VBECNUSB=+$O(^TMP("VBEC FINIS",$J,$C(32)),-1)+1
 ..S ^TMP("VBEC FINIS",$J,0)=^TMP("VBEC FINIS",$J,0)_$C(13)
 ..S ^TMP("VBEC FINIS",$J,VBECNUSB,0)=^TMP("VBEC FINIS",$J,0)
 ..K VBECNUSB,^TMP("VBEC FINIS",$J,0)
 ..D SAVE^VBECDCU1 ;(1)
 ..;the last record in the VBEC FINIS file will be be comprised of the
 ..;totals for all data elements for all records.
 ..Q
 .;
 .; 2-if there is no data to convert, let the user know via an alert.
 .I VBECCNV,('$$DATA^VBECDCU1($J)) D
 ..D ALERT^VBECDCU(DUZ,VBECCNV,VBECANOM,-1) ;(2)
 ..Q
 .;
 .; 3-if there are anomalies, regardless of whether the anomaly check
 .;   or data conversion was run, inform the user via an alert.
 .E  D ALERT^VBECDCU(DUZ,VBECCNV,VBECANOM,"") ;(3)
 .;
 .; 4-file the date/time the data conversion/anomaly check finished
 .D UP6001F^VBECDC02(VBECIEN,+$E($$NOW^XLFDT(),1,12)) ;(4)
 .Q
 ;
XIT ; clean up symbol table, exit routine
 K CNT,DFN,LRD1,LRDFN,LRSTOP,VBECANOM,VBECIEN,VBECRTOT
 Q
 ;
PATREC(VBECIEN) ;file patient specific Lab Data file data into the DATA
 ;CONVERSION STATISTIC multiple (6001.02)
 ;Input: VBECIEN=the record number of the data conversion
 S LRTMP=$G(^TMP("VBEC FINIS",$J,VBECRTOT,0))
 S LRIEN="+"_LRDFN_","_VBECIEN_","
 S LROOT(1,6001.02,LRIEN,.01)=$P(LRTMP,U)
 F I=2:1:27 S LROOT(1,6001.02,LRIEN,I)=$P(LRTMP,U,I)
 D UPDATE^DIE("E","LROOT(1)","")
 K I,LRIEN,LROOT,LRTMP
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVBECDC00   5881     printed  Sep 23, 2025@20:20:03                                                                                                                                                                                                    Page 2
VBECDC00  ;hoifo/gjc-data conversion & pre-implementation;Nov 21, 2002
 +1       ;;2.0;VBEC;;Jun 05, 2015;Build 4
 +2       ;
 +3       ;Medical Device #:
 +4       ;Note: The food and Drug Administration classifies this software as a
 +5       ;medical device.  As such, it may not be changed in any way.
 +6       ;Modifications to this software may result in an adulterated medical
 +7       ;device under 21CFR820, the use of which is considered to be a
 +8       ;violation of US Federal Statutes.  Acquiring and implementing this
 +9       ;software through the Freedom of Information Act requires the
 +10      ;implementer to assume total responsibility for the software, and
 +11      ;become a registered manufacturer of a medical device, subject to FDA
 +12      ;regulations.
 +13      ;
 +14      ;Call to $$NEWERR^%ZTER is supported by IA: 1621
 +15      ;Call to $$S^%ZTLOAD is supported by IA: 10063
 +16      ;Call to $$NOW^XLFDT is supported by IA: 10103
 +17      ;Call to ^%ZTLOAD is supported by IA: 10063
 +18      ;Call to UPDATE^DIE is supported by IA: 2053
 +19      ;Execution of ^%ZOSF("TEST") is supported by IA: 10096
 +20      ;Direct global read of ^DPT(DFN,"LR") supported by IA: 10035
 +21      ;
START     ; entry point queued/not queued.  Update the VBECS DATA INTEGRITY/CONV
 +1       ; ERSION STATISTICS (#6001)
 +2       ;
 +3       ; Note: the variables VBECCNV & VBECIEN are defined in VBECDC01 and
 +4       ; are passed into START subroutine via the ZTSAVE array when calling
 +5       ; ^%ZTLOAD.
 +6       ;
 +7        if $DATA(ZTQUEUED)
               SET ZTREQ="@"
 +8       ;
 +9       ; initialize error trap
 +10       IF $$NEWERR^%ZTER
               NEW $ETRAP,$ESTACK
               SET $ETRAP="D ERR^VBECDCU1"
 +11      IF '$TEST
               SET X="D ERR^VBECDCU1"
               SET @^%ZOSF("TRAP")
 +12      ;
 +13      ; lock out options when converting data
           if VBECCNV
               DO EN^VBECDC19(1)
 +14      ;
 +15       SET (CNT,DFN,LRSTOP)=0
           if $GET(U)'="^"
               SET U="^"
           KILL ^TMP("VBEC 63",$JOB)
 +16      ;
 +17      ;initialize the global that keeps track of ALL data elements for ALL
 +18      ;records
 +19      ;
 +20       KILL X
           SET $PIECE(X,"0^",28)=""
           SET ^TMP("VBEC FINIS",$JOB,0)=X
           KILL X
 +21       KILL ^TMP($JOB,"VBEC_TR_REACT"),^TMP($JOB,"VBEC_TR_TRD")
           SET VBTRA=0
           FOR 
               SET VBTRA=$ORDER(^LRD(65,VBTRA))
               if 'VBTRA
                   QUIT 
               Begin DoDot:1
 +22               IF $PIECE($GET(^LRD(65,VBTRA,6)),"^")]""
                       IF $PIECE($GET(^LRD(65,VBTRA,6)),"^",5)
                           Begin DoDot:2
 +23                           SET VBLRDFN=$PIECE(^LRD(65,VBTRA,6),"^")
                               SET VBDFN=$PIECE(^LR(VBLRDFN,0),"^",3)
                               if $PIECE(^LR(VBLRDFN,0),"^",2)'=2
                                   QUIT 
 +24                           SET ^TMP($JOB,"VBEC_TR_REACT",VBDFN,VBTRA)=""
                           End DoDot:2
               End DoDot:1
 +25      ;
 +26      ;Create an index in the TMP global to make it easier to find Transfusion Reactions by DFN ;RLM 04/20/2005
 +27      ;
 +28       FOR 
               SET DFN=$ORDER(^DPT(DFN))
               if DFN'>0
                   QUIT 
               Begin DoDot:1
 +29      ;
 +30      ; has the user stopped the task?
                   IF $$S^%ZTLOAD()
                       SET (ZTSTOP,LRSTOP)=1
                       QUIT 
 +31      ;
 +32      ; patient w/o Lab Data (#63) file data
                   if '$DATA(^DPT(DFN,"LR"))#2
                       QUIT 
 +33      ;
 +34               SET LRDFN=+$GET(^DPT(DFN,"LR"))
 +35      ;
 +36               IF LRDFN'>0
                       Begin DoDot:2
 +37                       KILL LRARY
                           SET LRARY(.01)=2
                           SET LRARY(.02)=DFN
                           SET LRARY(.09)=$PIECE($TEXT(ERRMSG+1^VBECDC02),";",4)
 +38      ; log this exception regardless of the task
                           DO LOGEXC^VBECDC02(VBECIEN,.LRARY)
                           KILL LRARY
 +39                       QUIT 
                       End DoDot:2
                       QUIT 
 +40      ;
 +41               IF $$BRKPNT^VBECDCU1(LRDFN,DFN)
                       Begin DoDot:2
 +42                       KILL LRARY
                           SET LRARY(.01)=2
                           SET LRARY(.02)=DFN
                           SET LRARY(.03)=63
                           SET LRARY(.04)=LRDFN
 +43                       SET LRARY(.09)=$PIECE($TEXT(ERRMSG+2^VBECDC02),";",4)
 +44      ; log this exception regardless of the task
                           DO LOGEXC^VBECDC02(VBECIEN,.LRARY)
                           KILL LRARY
 +45                       QUIT 
                       End DoDot:2
                       QUIT 
 +46      ;
 +47      ; blood bank data missing for this patient
                   IF '$ORDER(^LR(LRDFN,"BB",0))
                       QUIT 
 +48      ;
 +49               IF 'LRSTOP
                       IF $PIECE(^DPT(DFN,0),"^")["MERGING INTO"
                           SET DPTNAME=$PIECE(^DPT(DFN,0),"^")
                           Begin DoDot:2
 +50                           SET VBECMRG=$PIECE($PIECE(DPTNAME,"`",2)," ")
 +51                           KILL LRARY
                               SET LRARY(.01)=2
                               SET LRARY(.02)=DFN
                               SET LRARY(.03)=2
                               SET LRARY(.04)=VBECMRG
                               SET LRARY(.09)=$PIECE($TEXT(ERRMSG+3^VBECDC02),";",4)
 +52      ; log this exception
                               DO LOGEXC^VBECDC02(VBECIEN,.LRARY)
                               KILL LRARY
 +53                           QUIT 
                           End DoDot:2
                           QUIT 
 +54      ;
 +55      ; if the data conversion process is active save off all LAB DATA file
 +56      ; specific data into the appropriate ^TMP("VBEC 63"*,$J) global
 +57      ;
 +58               IF 'LRSTOP
                       IF VBECCNV
                           DO PAT^VBECDCX(DFN,LRDFN)
 +59      ;
 +60      ;
 +61      ;save off patient specific data for each record in the Lab Data file
 +62               IF VBECCNV
                       if $DATA(^TMP("VBEC FINIS",$JOB,VBECRTOT,0))#2
                           DO PATREC(VBECIEN)
 +63               QUIT 
               End DoDot:1
               if LRSTOP
                   QUIT 
 +64      ;
 +65      ; kill off unnecessary ^TMP("VBEC 63",$J) global
 +66       KILL ^TMP("VBEC 63",$JOB)
 +67      ;
 +68      ; actions if the user teminates process (a check exists within to
 +69      ; execute specific code depending on if the anomaly check or the data
 +70      ; conversion is executing)
 +71      ;
 +72      ; do anomalies exist?
           SET VBECANOM=+$ORDER(^VBEC(6001,VBECIEN,"ERR",0))
 +73      ;
 +74      ; If the process was stopped by the user via TaskMan (1)
 +75      ; If errored out, LRSTOP=-1 (set in ERR^VBECDCU1)
 +76       IF LRSTOP=1
               DO STOPPED^VBECDC01
 +77      ;
 +78      ; If the process has completed without user intervention:
 +79       IF 'LRSTOP
               Begin DoDot:1
 +80      ;
 +81      ; 1-if data to convert, save off the ^TMP("VBEC"*,$J) namespaced
 +82      ;   global into system level files to be extracted by SQL Server
 +83      ;   (make sure data tabulation globals are saved off properly)
 +84               IF VBECCNV
                       IF ($$DATA^VBECDCU1($JOB))
                           Begin DoDot:2
 +85                           SET VBECNUSB=+$ORDER(^TMP("VBEC FINIS",$JOB,$CHAR(32)),-1)+1
 +86                           SET ^TMP("VBEC FINIS",$JOB,0)=^TMP("VBEC FINIS",$JOB,0)_$CHAR(13)
 +87                           SET ^TMP("VBEC FINIS",$JOB,VBECNUSB,0)=^TMP("VBEC FINIS",$JOB,0)
 +88                           KILL VBECNUSB,^TMP("VBEC FINIS",$JOB,0)
 +89      ;(1)
                               DO SAVE^VBECDCU1
 +90      ;the last record in the VBEC FINIS file will be be comprised of the
 +91      ;totals for all data elements for all records.
 +92                           QUIT 
                           End DoDot:2
 +93      ;
 +94      ; 2-if there is no data to convert, let the user know via an alert.
 +95               IF VBECCNV
                       IF ('$$DATA^VBECDCU1($JOB))
                           Begin DoDot:2
 +96      ;(2)
                               DO ALERT^VBECDCU(DUZ,VBECCNV,VBECANOM,-1)
 +97                           QUIT 
                           End DoDot:2
 +98      ;
 +99      ; 3-if there are anomalies, regardless of whether the anomaly check
 +100     ;   or data conversion was run, inform the user via an alert.
 +101     ;(3)
                  IF '$TEST
                       DO ALERT^VBECDCU(DUZ,VBECCNV,VBECANOM,"")
 +102     ;
 +103     ; 4-file the date/time the data conversion/anomaly check finished
 +104     ;(4)
                   DO UP6001F^VBECDC02(VBECIEN,+$EXTRACT($$NOW^XLFDT(),1,12))
 +105              QUIT 
               End DoDot:1
 +106     ;
XIT       ; clean up symbol table, exit routine
 +1        KILL CNT,DFN,LRD1,LRDFN,LRSTOP,VBECANOM,VBECIEN,VBECRTOT
 +2        QUIT 
 +3       ;
PATREC(VBECIEN) ;file patient specific Lab Data file data into the DATA
 +1       ;CONVERSION STATISTIC multiple (6001.02)
 +2       ;Input: VBECIEN=the record number of the data conversion
 +3        SET LRTMP=$GET(^TMP("VBEC FINIS",$JOB,VBECRTOT,0))
 +4        SET LRIEN="+"_LRDFN_","_VBECIEN_","
 +5        SET LROOT(1,6001.02,LRIEN,.01)=$PIECE(LRTMP,U)
 +6        FOR I=2:1:27
               SET LROOT(1,6001.02,LRIEN,I)=$PIECE(LRTMP,U,I)
 +7        DO UPDATE^DIE("E","LROOT(1)","")
 +8        KILL I,LRIEN,LROOT,LRTMP
 +9        QUIT