ECV5RPC ;ALB/ACS - Event Capture Spreadsheet Data Validation ;12/2/22  16:11
 ;;2.0;EVENT CAPTURE;**25,30,36,47,114,131,159**;8 May 96;Build 61
 ;
 ; Reference to $$SINFO^ICDEX in ICR #5747
 ; Reference to $$ICDDX^ICDEX in ICR #5747
 ; Reference to ^SC( in ICR #10040
 ;
 ;----------------------------------------------------------------------
 ;  Validates the following Event Capture Spreadsheet Upload fields for
 ;  records sent to PCE:
 ;    1. DIAGNOSIS CODE
 ;    2. ASSOCIATED CLINIC
 ;----------------------------------------------------------------------
 ;======================================================================
 ;MODIFICATIONS
 ;08/2001    EC*2.0*30   Updated the Diagnosis validation logic
 ;08/2016    EC*2.0*131  Allow for Clinic IEN to be sent
 ;======================================================================
 ;
VALDIAG ;Validate Diagnosis Code.  Make sure it exists on the ICD file
 N ECDT,ECCS,DXPARAM,DXIEN
 S %DT="XST",X=$G(ECENCV,"NOW") D ^%DT S ECDT=+Y
 I ECDXV="" D  Q  ; Spreadsheet is missing diagnosis code 
 . S ECERRMSG=$P($T(DIAG1^ECV5RPC),";;",2)
 . S ECCOLERR=ECDXPC
 . D ERROR
 ;EC*2*159 begins
 ;if diag invalid, send error message
 ;I ECDXV'="" S (ECDXIEN,ECSFOUND)=0 D
 S ECCS=$$SINFO^ICDEX("DIAG",ECDT) ; Supported by ICR 5747
 F DXPARAM="ECDXV","ECSEC1V","ECSEC2V","ECSEC3V","ECSEC4V" D FINDDX(DXPARAM)
 ;EC*2*159 ends
 Q
FINDDX(PARAM) ;
 ; Updates for ICD10
 I @DXPARAM="" Q
 S (MYDXIEN,DXIEN)=0
 S MYDXIEN=$$ICDDX^ICDEX(@DXPARAM,ECDT,+ECCS,"E") ; Supported by ICR 5747
 S:(+MYDXIEN>0)&($P(MYDXIEN,"^",10)) DXIEN=+MYDXIEN
 I DXIEN>0 D  Q
 . S:PARAM="ECDXV" ECDXIEN=DXIEN
 . S:PARAM="ECSEC1V" ECSECDX1=DXIEN ;159
 . S:PARAM="ECSEC2V" ECSECDX2=DXIEN ;159
 . S:PARAM="ECSEC3V" ECSECDX3=DXIEN ;159
 . S:PARAM="ECSEC4V" ECSECDX4=DXIEN ;159
 ; Invalid Diagnosis code
 S ECERRMSG=$P($T(@DXPARAM^ECV5RPC),";;",2) ;159
 S ECCOLERR=ECDXPC
 D ERROR
 Q
 ;
VALCLIN ;Validate Associated Clinic.  Make sure the clinic is active for
 ;the date of the encounter
 S ECERRFLG=0
 I ECCLNNV=""&(ECCLNIV="") D  ;131
 . ; Spreadsheet is missing the associated clinic name and IEN, need one of them
 . S ECERRMSG=$P($T(CLIN1^ECV5RPC),";;",2)
 . S ECCOLERR=ECCLNNPC
 . D ERROR
 . Q
 I 'ECERRFLG,ECCLNIV'=+ECCLNIV,ECCLNIV'="" D  ;131 Make sure IEN is pure numeric
 .S ECERRMSG=$P($T(CLIN6^ECV5RPC),";;",2)
 .S ECCOLERR=ECCLNIPC
 .D ERROR
 .Q
 I 'ECERRFLG,ECCLNIV,'$D(^SC(+ECCLNIV,0)) D  ;131 Section added to check for IEN existence
 .S ECERRMSG=$P($T(CLIN3^ECV5RPC),";;",2)
 .S ECCOLERR=ECCLNIPC
 .D ERROR
 .Q
 I 'ECERRFLG,ECCLNIV S ECCLNIEN=ECCLNIV ;131 If no error and IEN exists then IEN is valid
 I 'ECERRFLG,'+ECCLNIV,'$D(^SC("B",ECCLNNV)) D  ;131
 . ; No B x-ref on file
 . S ECERRMSG=$P($T(CLIN2^ECV5RPC),";;",2)
 . S ECCOLERR=ECCLNNPC ;131
 . D ERROR
 . Q
 I 'ECERRFLG,'+ECCLNIV,$D(^SC("B",ECCLNNV)) D  ;131
 . ;get associated clinic ien
 . S ECCLNIEN=$O(^SC("B",ECCLNNV,0)) ;131
 . I '$D(^SC(ECCLNIEN,0)) D
 . . ; Associated clinic ien not on file
 . . S ECERRMSG=$P($T(CLIN3^ECV5RPC),";;",2)
 . . S ECCOLERR=ECCLNNPC ;131
 . . D ERROR
 . . Q
 .Q  ;131
 ;131 Removed one level of block structure from remaining code in this section so tests are done regardless of how clinic IEN was obtained.
 I 'ECERRFLG D
 . ;make sure it is of type 'clinic'
 . N CLINDATA
 . S CLINDATA=$G(^SC(ECCLNIEN,0))
 . I $P(CLINDATA,U,3)'="C" D
 . . S ECERRMSG=$P($T(CLIN4^ECV5RPC),";;",2)
 . . S ECCOLERR=ECCLNNPC ;131
 . . D ERROR
 . . Q
 . Q
 ;
 ;check for inactivate and reactivate dates
 I 'ECERRFLG,$D(^SC(ECCLNIEN,"I")) D
 . ;get inactivated and reactivated dates
 . N INACT,REACT
 . S INACT=$P(^SC(ECCLNIEN,"I"),U,1),REACT=$P(^SC(ECCLNIEN,"I"),U,2)
 . I INACT'="" D
 . . I REACT="",ECENCV'<INACT D CLINERR^ECV5RPC
 . . I REACT,ECENCV'<INACT,ECENCV<REACT D CLINERR^ECV5RPC
 . . Q
 . Q
 Q
 ;;
CLINERR ;Clinic inactive for this encounter date
 S ECERRMSG=$P($T(CLIN5^ECV5RPC),";;",2)
 S ECCOLERR=ECCLNNPC ;131
 D ERROR
 Q
 ;;
ERROR ;--Set up array entry to contain the following:
 ;1. record number
 ;2. column number on spreadsheet containing the record number
 ;3. column number on spreadsheet containing the data in error
 ;4. error message
 ;
 S ECINDEX=ECINDEX+1
 S RESULTS(ECINDEX)=ECRECV_"^"_ECRECPC_"^"_ECCOLERR_"^"_ECERRMSG_"^"
 S ECERRFLG=1
 Q
 ;
 ;Error messages:
 ;
DIAG1 ;;Diagnosis code is required for this DSS Unit
ECDXV ;;Invalid Diagnosis Code
ECSEC1V ;;Secondary Dx 1 is invalid
ECSEC2V ;;Secondary Dx 2 is invalid
ECSEC3V ;;Secondary Dx 3 is invalid
ECSEC4V ;;Secondary Dx 4 is invalid
CLIN1 ;;Associated Clinic Name or IEN is required for this DSS Unit
CLIN2 ;;Assoc Clinic "B" x-ref not found on Hosp Location File(#44)
CLIN3 ;;Assoc Clinic not found on Hosp Location File(#44)
CLIN4 ;;Assoc Clinic must be of type "C" (clinic)
CLIN5 ;;Assoc Clinic inactive for this encounter date
CLIN6 ;;Assoc Clinic IEN must be numeric
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HECV5RPC   5014     printed  Sep 23, 2025@19:35:25                                                                                                                                                                                                     Page 2
ECV5RPC   ;ALB/ACS - Event Capture Spreadsheet Data Validation ;12/2/22  16:11
 +1       ;;2.0;EVENT CAPTURE;**25,30,36,47,114,131,159**;8 May 96;Build 61
 +2       ;
 +3       ; Reference to $$SINFO^ICDEX in ICR #5747
 +4       ; Reference to $$ICDDX^ICDEX in ICR #5747
 +5       ; Reference to ^SC( in ICR #10040
 +6       ;
 +7       ;----------------------------------------------------------------------
 +8       ;  Validates the following Event Capture Spreadsheet Upload fields for
 +9       ;  records sent to PCE:
 +10      ;    1. DIAGNOSIS CODE
 +11      ;    2. ASSOCIATED CLINIC
 +12      ;----------------------------------------------------------------------
 +13      ;======================================================================
 +14      ;MODIFICATIONS
 +15      ;08/2001    EC*2.0*30   Updated the Diagnosis validation logic
 +16      ;08/2016    EC*2.0*131  Allow for Clinic IEN to be sent
 +17      ;======================================================================
 +18      ;
VALDIAG   ;Validate Diagnosis Code.  Make sure it exists on the ICD file
 +1        NEW ECDT,ECCS,DXPARAM,DXIEN
 +2        SET %DT="XST"
           SET X=$GET(ECENCV,"NOW")
           DO ^%DT
           SET ECDT=+Y
 +3       ; Spreadsheet is missing diagnosis code 
           IF ECDXV=""
               Begin DoDot:1
 +4                SET ECERRMSG=$PIECE($TEXT(DIAG1^ECV5RPC),";;",2)
 +5                SET ECCOLERR=ECDXPC
 +6                DO ERROR
               End DoDot:1
               QUIT 
 +7       ;EC*2*159 begins
 +8       ;if diag invalid, send error message
 +9       ;I ECDXV'="" S (ECDXIEN,ECSFOUND)=0 D
 +10      ; Supported by ICR 5747
           SET ECCS=$$SINFO^ICDEX("DIAG",ECDT)
 +11       FOR DXPARAM="ECDXV","ECSEC1V","ECSEC2V","ECSEC3V","ECSEC4V"
               DO FINDDX(DXPARAM)
 +12      ;EC*2*159 ends
 +13       QUIT 
FINDDX(PARAM) ;
 +1       ; Updates for ICD10
 +2        IF @DXPARAM=""
               QUIT 
 +3        SET (MYDXIEN,DXIEN)=0
 +4       ; Supported by ICR 5747
           SET MYDXIEN=$$ICDDX^ICDEX(@DXPARAM,ECDT,+ECCS,"E")
 +5        if (+MYDXIEN>0)&($PIECE(MYDXIEN,"^",10))
               SET DXIEN=+MYDXIEN
 +6        IF DXIEN>0
               Begin DoDot:1
 +7                if PARAM="ECDXV"
                       SET ECDXIEN=DXIEN
 +8       ;159
                   if PARAM="ECSEC1V"
                       SET ECSECDX1=DXIEN
 +9       ;159
                   if PARAM="ECSEC2V"
                       SET ECSECDX2=DXIEN
 +10      ;159
                   if PARAM="ECSEC3V"
                       SET ECSECDX3=DXIEN
 +11      ;159
                   if PARAM="ECSEC4V"
                       SET ECSECDX4=DXIEN
               End DoDot:1
               QUIT 
 +12      ; Invalid Diagnosis code
 +13      ;159
           SET ECERRMSG=$PIECE($TEXT(@DXPARAM^ECV5RPC),";;",2)
 +14       SET ECCOLERR=ECDXPC
 +15       DO ERROR
 +16       QUIT 
 +17      ;
VALCLIN   ;Validate Associated Clinic.  Make sure the clinic is active for
 +1       ;the date of the encounter
 +2        SET ECERRFLG=0
 +3       ;131
           IF ECCLNNV=""&(ECCLNIV="")
               Begin DoDot:1
 +4       ; Spreadsheet is missing the associated clinic name and IEN, need one of them
 +5                SET ECERRMSG=$PIECE($TEXT(CLIN1^ECV5RPC),";;",2)
 +6                SET ECCOLERR=ECCLNNPC
 +7                DO ERROR
 +8                QUIT 
               End DoDot:1
 +9       ;131 Make sure IEN is pure numeric
           IF 'ECERRFLG
               IF ECCLNIV'=+ECCLNIV
                   IF ECCLNIV'=""
                       Begin DoDot:1
 +10                       SET ECERRMSG=$PIECE($TEXT(CLIN6^ECV5RPC),";;",2)
 +11                       SET ECCOLERR=ECCLNIPC
 +12                       DO ERROR
 +13                       QUIT 
                       End DoDot:1
 +14      ;131 Section added to check for IEN existence
           IF 'ECERRFLG
               IF ECCLNIV
                   IF '$DATA(^SC(+ECCLNIV,0))
                       Begin DoDot:1
 +15                       SET ECERRMSG=$PIECE($TEXT(CLIN3^ECV5RPC),";;",2)
 +16                       SET ECCOLERR=ECCLNIPC
 +17                       DO ERROR
 +18                       QUIT 
                       End DoDot:1
 +19      ;131 If no error and IEN exists then IEN is valid
           IF 'ECERRFLG
               IF ECCLNIV
                   SET ECCLNIEN=ECCLNIV
 +20      ;131
           IF 'ECERRFLG
               IF '+ECCLNIV
                   IF '$DATA(^SC("B",ECCLNNV))
                       Begin DoDot:1
 +21      ; No B x-ref on file
 +22                       SET ECERRMSG=$PIECE($TEXT(CLIN2^ECV5RPC),";;",2)
 +23      ;131
                           SET ECCOLERR=ECCLNNPC
 +24                       DO ERROR
 +25                       QUIT 
                       End DoDot:1
 +26      ;131
           IF 'ECERRFLG
               IF '+ECCLNIV
                   IF $DATA(^SC("B",ECCLNNV))
                       Begin DoDot:1
 +27      ;get associated clinic ien
 +28      ;131
                           SET ECCLNIEN=$ORDER(^SC("B",ECCLNNV,0))
 +29                       IF '$DATA(^SC(ECCLNIEN,0))
                               Begin DoDot:2
 +30      ; Associated clinic ien not on file
 +31                               SET ECERRMSG=$PIECE($TEXT(CLIN3^ECV5RPC),";;",2)
 +32      ;131
                                   SET ECCOLERR=ECCLNNPC
 +33                               DO ERROR
 +34                               QUIT 
                               End DoDot:2
 +35      ;131
                           QUIT 
                       End DoDot:1
 +36      ;131 Removed one level of block structure from remaining code in this section so tests are done regardless of how clinic IEN was obtained.
 +37       IF 'ECERRFLG
               Begin DoDot:1
 +38      ;make sure it is of type 'clinic'
 +39               NEW CLINDATA
 +40               SET CLINDATA=$GET(^SC(ECCLNIEN,0))
 +41               IF $PIECE(CLINDATA,U,3)'="C"
                       Begin DoDot:2
 +42                       SET ECERRMSG=$PIECE($TEXT(CLIN4^ECV5RPC),";;",2)
 +43      ;131
                           SET ECCOLERR=ECCLNNPC
 +44                       DO ERROR
 +45                       QUIT 
                       End DoDot:2
 +46               QUIT 
               End DoDot:1
 +47      ;
 +48      ;check for inactivate and reactivate dates
 +49       IF 'ECERRFLG
               IF $DATA(^SC(ECCLNIEN,"I"))
                   Begin DoDot:1
 +50      ;get inactivated and reactivated dates
 +51                   NEW INACT,REACT
 +52                   SET INACT=$PIECE(^SC(ECCLNIEN,"I"),U,1)
                       SET REACT=$PIECE(^SC(ECCLNIEN,"I"),U,2)
 +53                   IF INACT'=""
                           Begin DoDot:2
 +54                           IF REACT=""
                                   IF ECENCV'<INACT
                                       DO CLINERR^ECV5RPC
 +55                           IF REACT
                                   IF ECENCV'<INACT
                                       IF ECENCV<REACT
                                           DO CLINERR^ECV5RPC
 +56                           QUIT 
                           End DoDot:2
 +57                   QUIT 
                   End DoDot:1
 +58       QUIT 
 +59      ;;
CLINERR   ;Clinic inactive for this encounter date
 +1        SET ECERRMSG=$PIECE($TEXT(CLIN5^ECV5RPC),";;",2)
 +2       ;131
           SET ECCOLERR=ECCLNNPC
 +3        DO ERROR
 +4        QUIT 
 +5       ;;
ERROR     ;--Set up array entry to contain the following:
 +1       ;1. record number
 +2       ;2. column number on spreadsheet containing the record number
 +3       ;3. column number on spreadsheet containing the data in error
 +4       ;4. error message
 +5       ;
 +6        SET ECINDEX=ECINDEX+1
 +7        SET RESULTS(ECINDEX)=ECRECV_"^"_ECRECPC_"^"_ECCOLERR_"^"_ECERRMSG_"^"
 +8        SET ECERRFLG=1
 +9        QUIT 
 +10      ;
 +11      ;Error messages:
 +12      ;
DIAG1     ;;Diagnosis code is required for this DSS Unit
ECDXV     ;;Invalid Diagnosis Code
ECSEC1V   ;;Secondary Dx 1 is invalid
ECSEC2V   ;;Secondary Dx 2 is invalid
ECSEC3V   ;;Secondary Dx 3 is invalid
ECSEC4V   ;;Secondary Dx 4 is invalid
CLIN1     ;;Associated Clinic Name or IEN is required for this DSS Unit
CLIN2     ;;Assoc Clinic "B" x-ref not found on Hosp Location File(#44)
CLIN3     ;;Assoc Clinic not found on Hosp Location File(#44)
CLIN4     ;;Assoc Clinic must be of type "C" (clinic)
CLIN5     ;;Assoc Clinic inactive for this encounter date
CLIN6     ;;Assoc Clinic IEN must be numeric