PXAICPTV ;ISL/JVS,PKR ISA/KWP,SCK - VALIDATE PROCEDURES(CPT) ;02/04/2021
;;1.0;PCE PATIENT CARE ENCOUNTER;**15,73,74,111,121,130,168,194,199,211**;Aug 12, 1996;Build 454
;
;Reference to ICDEX supported by ICR #5747.
;
ERRSET ;Set the rest of the error data.
S STOP=1
S PXAERRF("CPT")=1
S PXADI("DIALOG")=8390001.001
S PXAERR(7)="PROCEDURE"
Q
;
VAL ;Validate the input.
I $G(PXAA("PROCEDURE"))="" D Q
. S PXAERR(9)="CPT CODE"
. S PXAERR(12)="You are missing a CPT code"
. D ERRSET
;
;Save the code or pointer.
S PXAERR(11)=$G(PXAA("PROCEDURE"))
;
N CODE,CODEIEN,CODESYS,CPTDATA,EVENTDT,SERVCAT,SOURCE,TEMP
S TEMP=^AUPNVSIT(PXAVISIT,0)
S SERVCAT=$P(TEMP,U,7)
;For historical encounters use the Date the Visit was created.
S EVENTDT=$S(SERVCAT="E":$P(TEMP,U,2),$G(PXAA("EVENT D/T"))'="":PXAA("EVENT D/T"),1:$P(TEMP,U,1))
S CPTDATA=$$CPT^ICPTCOD(PXAA("PROCEDURE"),EVENTDT)
S CODEIEN=$P(CPTDATA,U,1)
I CODEIEN'>0 D Q
. S PXAERR(9)="CPT CODE"
. S PXAERR(12)=PXAERR(11)_" is not a valid CPT code or pointer."
. D ERRSET
;
;If a code was passed store the IEN.
S PXAA("PROCEDURE")=CODEIEN
;
;If this is a deletion no further validation is required.
I $G(PXAA("DELETE"))=1 Q
;
;If Event D/T is input verify it is a valid FileMan date and not in
;the future.
;* I $G(PXAA("EVENT D/T"))'="",'$$EVENTDT^PXAIVAL(PXAA("EVENT D/T"),"T",.PXAERR) D Q
;* . D ERRSET
;
;Check that the code is active.
;* S CODE=$P(CPTDATA,U,2)
;* S SOURCE=$P(CPTDATA,U,5)
;* S CODESYS=$S(SOURCE="C":"CPT",SOURCE="H":"CPC",1:"")
;* I CODESYS="" D Q
;* . S PXAERR(9)="CODING SYSTEM"
;* . S PXAERR(12)=PXAERR(11)_" does not have a valid coding system"
;* . D ERRSET
;
;* I '$$ISCACT^PXLEX(CODESYS,CODE,EVENTDT) D Q
;* . S PXAERR(9)="CPT CODE"
;* . S PXAERR(12)=PXAERR(11)_" is not an active CPT code"
;* . D ERRSET
;
;If the number of times is missing set it to one.
I +$G(PXAA("QTY"))'>0 S PXAA("QTY")=1
;
;Check that modifiers are valid.
N MOD,MODDATA,MODIEN
S MOD=""
F S MOD=$O(PXAA("MODIFIERS",MOD)) Q:MOD=""!($G(STOP)) D
.;Try external first.
. S MODDATA=$$MODP^ICPTMOD(PXAA("PROCEDURE"),MOD,"E",EVENTDT,0)
. S MODIEN=$P(MODDATA,U,1)
. I MODIEN>0 S PXAA("MODIFIERS",MOD)=MODIEN
. E D
..;Try internal.
.. S MODDATA=$$MODP^ICPTMOD(PXAA("PROCEDURE"),MOD,"I",EVENTDT,0)
.. S MODIEN=$P(MODDATA,U,1)
.. I MODIEN>0 S PXAA("MODIFIERS",MOD)=MODIEN
. I MODIEN'>0 D
.. D ERRSET
.. S PXAERR(9)="MODIFIERS"_","_MOD
.. S PXAERR(11)=""
.. S PXAERR(12)=MOD_" is not a valid modifier for procedure "_$G(PXAA("PROCEDURE"))
.. I MODIEN=-1 S PXAERR(13)="Lexicon error: "_$P(MODDATA,U,2)
I $G(STOP)=1 Q
;
;Check that ICD diagnosis codes are valid.
N DIAGNUM,DIAGSTR,FMT,ICDDATA
F DIAGNUM=1:1:8 D Q:$G(STOP)=1
. S DIAGSTR="DIAGNOSIS"_$S(DIAGNUM>1:" "_DIAGNUM,1:"")
. I $G(PXAA(DIAGSTR))]"" D
.. S FMT=$S(PXAA(DIAGSTR)?1.N:"I",1:"E")
.. I FMT="E" S CODE=PXAA(DIAGSTR),CODEIEN=$P($$CODEN^ICDEX(CODE,80),"~",1)
.. I FMT="I" S CODEIEN=PXAA(DIAGSTR),CODE=$$CODEC^ICDEX(80,CODEIEN)
.. I CODEIEN'>0 D Q
... D ERRSET
... S PXAERR(9)="PROCEDURE DIAGNOSIS"
... S PXAERR(11)=$G(PXAA(DIAGSTR))
... S PXAERR(12)="PROCEDURE DIAGNOSIS #"_DIAGNUM_" ("_PXAERR(11)_") is not a valid pointer to the ICD Diagnosis file #80."
.. S CODESYS=$$CSI^ICDEX(80,CODEIEN)
.. I '$$ISCACT^PXLEX(CODESYS,CODE,EVENTDT) D Q
... D ERRSET
... S PXAERR(9)="PROCEDURE DIAGNOSIS"
... S PXAERR(11)=$G(PXAA(DIAGSTR))
... S PXAERR(12)="PROCEDURE DIAGNOSIS #"_DIAGNUM_" ("_PXAERR(11)_") is NOT an Active ICD code"
.. I FMT="E" S PXAA(DIAGSTR)=CODEIEN
;
;If a Provider Narrative is passed check the length.
;* I $G(PXAA("NARRATIVE"))'="",'$$TEXT^PXAIVAL("PROVIDER NARRATIVE",PXAA("NARRATIVE"),2,245,.PXAERR) D Q
;* . D ERRSET
;*Control characters are not allowed.
;*I '$$VPNARR^PXPNARR(PXAA("NARRATIVE")) D Q
;*. S PXAERR(9)="PROVIDER NARRATIVE"
;*. S PXAERR(11)=PXAA("NARRATIVE")
;*. S PXAERR(12)="Control characters are not allowed."
;*. D ERRSET
;
;If a Provider Narrative Category is passed check the length.
;* I $G(PXAA("CATEGORY"))'="",'$$TEXT^PXAIVAL("CATEGORY",PXAA("CATEGORY"),2,245,.PXAERR) D Q
;* . D ERRSET
;*Control characters are not allowed.
;*I '$$VPNARR^PXPNARR(PXAA("CATEGORY")) D Q
;*. S PXAERR(9)="PROVIDER NARRATIVE CATEGORY"
;*. S PXAERR(11)=PXAA("CATEGORY")
;*. S PXAERR(12)="Control characters are not allowed."
;*. D ERRSET
;
;If an Ordering Provider is passed verify it is valid.
;* I $G(PXAA("ORD PROVIDER"))'="",'$$PRV^PXAIVAL(PXAA("ORD PROVIDER"),"ORD",.PXAA,.PXAERR,PXAVISIT) D Q
;* . D ERRSET
;
;If an Encounter Provider is passed verify it is valid.
;* I $G(PXAA("ENC PROVIDER"))'="",'$$PRV^PXAIVAL(PXAA("ENC PROVIDER"),"ENC",.PXAA,.PXAERR,PXAVISIT) D Q
;* . D ERRSET
;
;If an Order Reference is passed verify it is valid.
;* I $G(PXAA("ORD REFERENCE"))'="",'$D(^OR(100,PXAA("ORD REFERENCE"),0)) D Q
;* . S PXAERR(9)="ORDER REFERENCE"
;* . S PXAERR(11)=PXAA("ORD REFERENCE")
;* . S PXAERR(12)=PXAA("ORD REFERENCE")_" is not a valid pointer to the Order file #100."
;* . D ERRSET
;
;If PFSS is on and Department is passed verify it is valid.
;* I $$SWSTAT^IBBAPI,$G(PXAA("DEPARTMENT"))'="",'$D(^DIC(40.7,PXAA("DEPARTMENT"),0)) D Q
;* . S PXAERR(9)="DEPARTMENT"
;* . S PXAERR(11)=PXAA("DEPARTMENT")
;* . S PXAERR(12)=PXAA("DEPARTMENT")_" is not a valid Clinic Stop."
;
;If Comment is passed check the length.
;* I $G(PXAA("COMMENT"))'="",'$$TEXT^PXAIVAL("COMMENT",PXAA("COMMENT"),1,245,.PXAERR) D Q
;* . D ERRSET
;
;If PKG is input verify it.
;* I $G(PXAA("PKG"))'="" D
;* . N PKG
;* . S PKG=$$VPKG^PXAIVAL(PXAA("PKG"),.PXAERR)
;* . I PKG=0 S PXAERR(9)="PKG" D ERRSET Q
;* . S PXAA("PKG")=PKG
;* I $G(STOP)=1 Q
;
;If SOURCE is input verify it.
;* I $G(PXAA("SOURCE"))'="" D
;* . N SRC
;* . S SRC=$$VSOURCE^PXAIVAL(PXAA("SOURCE"),.PXAERR)
;* . I SRC=0 S PXAERR(9)="SOURCE" D ERRSET Q
;* . S PXAA("SOURCE")=SRC
;* I $G(STOP)=1 Q
Q
;
VAL04 ;Setup error array for missing or invalid Provider Narrative.
S PXAERR(9)="PROVIDER NARRATIVE"
S PXAERR(11)=$G(PXAA("NARRATIVE"))
S PXAERR(12)="We are unable to retrieve a provider narrative from the PROVIDER NARRATIVE file #9999999.27"
D ERRSET
Q
;
VAL802 ;Setup error array for missing or invalid Provider Narrative Category.
;Provider Narrative Category is not required, so make this a warning.
S PXAERR(9)="PROVIDER NARRATIVE CATEGORY"
S PXAERR(11)=$G(PXAA("CATEGORY"))
S PXAERR(12)="We are unable to retrieve a provider narrative category from the PROVIDER NARRATIVE file #9999999.27"
S PXADI("DIALOG")=8390001.002
S PXAERR(7)="PROCEDURE"
S PXAERRW("CPT")=1
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPXAICPTV 6812 printed Dec 13, 2024@02:25:46 Page 2
PXAICPTV ;ISL/JVS,PKR ISA/KWP,SCK - VALIDATE PROCEDURES(CPT) ;02/04/2021
+1 ;;1.0;PCE PATIENT CARE ENCOUNTER;**15,73,74,111,121,130,168,194,199,211**;Aug 12, 1996;Build 454
+2 ;
+3 ;Reference to ICDEX supported by ICR #5747.
+4 ;
ERRSET ;Set the rest of the error data.
+1 SET STOP=1
+2 SET PXAERRF("CPT")=1
+3 SET PXADI("DIALOG")=8390001.001
+4 SET PXAERR(7)="PROCEDURE"
+5 QUIT
+6 ;
VAL ;Validate the input.
+1 IF $GET(PXAA("PROCEDURE"))=""
Begin DoDot:1
+2 SET PXAERR(9)="CPT CODE"
+3 SET PXAERR(12)="You are missing a CPT code"
+4 DO ERRSET
End DoDot:1
QUIT
+5 ;
+6 ;Save the code or pointer.
+7 SET PXAERR(11)=$GET(PXAA("PROCEDURE"))
+8 ;
+9 NEW CODE,CODEIEN,CODESYS,CPTDATA,EVENTDT,SERVCAT,SOURCE,TEMP
+10 SET TEMP=^AUPNVSIT(PXAVISIT,0)
+11 SET SERVCAT=$PIECE(TEMP,U,7)
+12 ;For historical encounters use the Date the Visit was created.
+13 SET EVENTDT=$SELECT(SERVCAT="E":$PIECE(TEMP,U,2),$GET(PXAA("EVENT D/T"))'="":PXAA("EVENT D/T"),1:$PIECE(TEMP,U,1))
+14 SET CPTDATA=$$CPT^ICPTCOD(PXAA("PROCEDURE"),EVENTDT)
+15 SET CODEIEN=$PIECE(CPTDATA,U,1)
+16 IF CODEIEN'>0
Begin DoDot:1
+17 SET PXAERR(9)="CPT CODE"
+18 SET PXAERR(12)=PXAERR(11)_" is not a valid CPT code or pointer."
+19 DO ERRSET
End DoDot:1
QUIT
+20 ;
+21 ;If a code was passed store the IEN.
+22 SET PXAA("PROCEDURE")=CODEIEN
+23 ;
+24 ;If this is a deletion no further validation is required.
+25 IF $GET(PXAA("DELETE"))=1
QUIT
+26 ;
+27 ;If Event D/T is input verify it is a valid FileMan date and not in
+28 ;the future.
+29 ;* I $G(PXAA("EVENT D/T"))'="",'$$EVENTDT^PXAIVAL(PXAA("EVENT D/T"),"T",.PXAERR) D Q
+30 ;* . D ERRSET
+31 ;
+32 ;Check that the code is active.
+33 ;* S CODE=$P(CPTDATA,U,2)
+34 ;* S SOURCE=$P(CPTDATA,U,5)
+35 ;* S CODESYS=$S(SOURCE="C":"CPT",SOURCE="H":"CPC",1:"")
+36 ;* I CODESYS="" D Q
+37 ;* . S PXAERR(9)="CODING SYSTEM"
+38 ;* . S PXAERR(12)=PXAERR(11)_" does not have a valid coding system"
+39 ;* . D ERRSET
+40 ;
+41 ;* I '$$ISCACT^PXLEX(CODESYS,CODE,EVENTDT) D Q
+42 ;* . S PXAERR(9)="CPT CODE"
+43 ;* . S PXAERR(12)=PXAERR(11)_" is not an active CPT code"
+44 ;* . D ERRSET
+45 ;
+46 ;If the number of times is missing set it to one.
+47 IF +$GET(PXAA("QTY"))'>0
SET PXAA("QTY")=1
+48 ;
+49 ;Check that modifiers are valid.
+50 NEW MOD,MODDATA,MODIEN
+51 SET MOD=""
+52 FOR
SET MOD=$ORDER(PXAA("MODIFIERS",MOD))
if MOD=""!($GET(STOP))
QUIT
Begin DoDot:1
+53 ;Try external first.
+54 SET MODDATA=$$MODP^ICPTMOD(PXAA("PROCEDURE"),MOD,"E",EVENTDT,0)
+55 SET MODIEN=$PIECE(MODDATA,U,1)
+56 IF MODIEN>0
SET PXAA("MODIFIERS",MOD)=MODIEN
+57 IF '$TEST
Begin DoDot:2
+58 ;Try internal.
+59 SET MODDATA=$$MODP^ICPTMOD(PXAA("PROCEDURE"),MOD,"I",EVENTDT,0)
+60 SET MODIEN=$PIECE(MODDATA,U,1)
+61 IF MODIEN>0
SET PXAA("MODIFIERS",MOD)=MODIEN
End DoDot:2
+62 IF MODIEN'>0
Begin DoDot:2
+63 DO ERRSET
+64 SET PXAERR(9)="MODIFIERS"_","_MOD
+65 SET PXAERR(11)=""
+66 SET PXAERR(12)=MOD_" is not a valid modifier for procedure "_$GET(PXAA("PROCEDURE"))
+67 IF MODIEN=-1
SET PXAERR(13)="Lexicon error: "_$PIECE(MODDATA,U,2)
End DoDot:2
End DoDot:1
+68 IF $GET(STOP)=1
QUIT
+69 ;
+70 ;Check that ICD diagnosis codes are valid.
+71 NEW DIAGNUM,DIAGSTR,FMT,ICDDATA
+72 FOR DIAGNUM=1:1:8
Begin DoDot:1
+73 SET DIAGSTR="DIAGNOSIS"_$SELECT(DIAGNUM>1:" "_DIAGNUM,1:"")
+74 IF $GET(PXAA(DIAGSTR))]""
Begin DoDot:2
+75 SET FMT=$SELECT(PXAA(DIAGSTR)?1.N:"I",1:"E")
+76 IF FMT="E"
SET CODE=PXAA(DIAGSTR)
SET CODEIEN=$PIECE($$CODEN^ICDEX(CODE,80),"~",1)
+77 IF FMT="I"
SET CODEIEN=PXAA(DIAGSTR)
SET CODE=$$CODEC^ICDEX(80,CODEIEN)
+78 IF CODEIEN'>0
Begin DoDot:3
+79 DO ERRSET
+80 SET PXAERR(9)="PROCEDURE DIAGNOSIS"
+81 SET PXAERR(11)=$GET(PXAA(DIAGSTR))
+82 SET PXAERR(12)="PROCEDURE DIAGNOSIS #"_DIAGNUM_" ("_PXAERR(11)_") is not a valid pointer to the ICD Diagnosis file #80."
End DoDot:3
QUIT
+83 SET CODESYS=$$CSI^ICDEX(80,CODEIEN)
+84 IF '$$ISCACT^PXLEX(CODESYS,CODE,EVENTDT)
Begin DoDot:3
+85 DO ERRSET
+86 SET PXAERR(9)="PROCEDURE DIAGNOSIS"
+87 SET PXAERR(11)=$GET(PXAA(DIAGSTR))
+88 SET PXAERR(12)="PROCEDURE DIAGNOSIS #"_DIAGNUM_" ("_PXAERR(11)_") is NOT an Active ICD code"
End DoDot:3
QUIT
+89 IF FMT="E"
SET PXAA(DIAGSTR)=CODEIEN
End DoDot:2
End DoDot:1
if $GET(STOP)=1
QUIT
+90 ;
+91 ;If a Provider Narrative is passed check the length.
+92 ;* I $G(PXAA("NARRATIVE"))'="",'$$TEXT^PXAIVAL("PROVIDER NARRATIVE",PXAA("NARRATIVE"),2,245,.PXAERR) D Q
+93 ;* . D ERRSET
+94 ;*Control characters are not allowed.
+95 ;*I '$$VPNARR^PXPNARR(PXAA("NARRATIVE")) D Q
+96 ;*. S PXAERR(9)="PROVIDER NARRATIVE"
+97 ;*. S PXAERR(11)=PXAA("NARRATIVE")
+98 ;*. S PXAERR(12)="Control characters are not allowed."
+99 ;*. D ERRSET
+100 ;
+101 ;If a Provider Narrative Category is passed check the length.
+102 ;* I $G(PXAA("CATEGORY"))'="",'$$TEXT^PXAIVAL("CATEGORY",PXAA("CATEGORY"),2,245,.PXAERR) D Q
+103 ;* . D ERRSET
+104 ;*Control characters are not allowed.
+105 ;*I '$$VPNARR^PXPNARR(PXAA("CATEGORY")) D Q
+106 ;*. S PXAERR(9)="PROVIDER NARRATIVE CATEGORY"
+107 ;*. S PXAERR(11)=PXAA("CATEGORY")
+108 ;*. S PXAERR(12)="Control characters are not allowed."
+109 ;*. D ERRSET
+110 ;
+111 ;If an Ordering Provider is passed verify it is valid.
+112 ;* I $G(PXAA("ORD PROVIDER"))'="",'$$PRV^PXAIVAL(PXAA("ORD PROVIDER"),"ORD",.PXAA,.PXAERR,PXAVISIT) D Q
+113 ;* . D ERRSET
+114 ;
+115 ;If an Encounter Provider is passed verify it is valid.
+116 ;* I $G(PXAA("ENC PROVIDER"))'="",'$$PRV^PXAIVAL(PXAA("ENC PROVIDER"),"ENC",.PXAA,.PXAERR,PXAVISIT) D Q
+117 ;* . D ERRSET
+118 ;
+119 ;If an Order Reference is passed verify it is valid.
+120 ;* I $G(PXAA("ORD REFERENCE"))'="",'$D(^OR(100,PXAA("ORD REFERENCE"),0)) D Q
+121 ;* . S PXAERR(9)="ORDER REFERENCE"
+122 ;* . S PXAERR(11)=PXAA("ORD REFERENCE")
+123 ;* . S PXAERR(12)=PXAA("ORD REFERENCE")_" is not a valid pointer to the Order file #100."
+124 ;* . D ERRSET
+125 ;
+126 ;If PFSS is on and Department is passed verify it is valid.
+127 ;* I $$SWSTAT^IBBAPI,$G(PXAA("DEPARTMENT"))'="",'$D(^DIC(40.7,PXAA("DEPARTMENT"),0)) D Q
+128 ;* . S PXAERR(9)="DEPARTMENT"
+129 ;* . S PXAERR(11)=PXAA("DEPARTMENT")
+130 ;* . S PXAERR(12)=PXAA("DEPARTMENT")_" is not a valid Clinic Stop."
+131 ;
+132 ;If Comment is passed check the length.
+133 ;* I $G(PXAA("COMMENT"))'="",'$$TEXT^PXAIVAL("COMMENT",PXAA("COMMENT"),1,245,.PXAERR) D Q
+134 ;* . D ERRSET
+135 ;
+136 ;If PKG is input verify it.
+137 ;* I $G(PXAA("PKG"))'="" D
+138 ;* . N PKG
+139 ;* . S PKG=$$VPKG^PXAIVAL(PXAA("PKG"),.PXAERR)
+140 ;* . I PKG=0 S PXAERR(9)="PKG" D ERRSET Q
+141 ;* . S PXAA("PKG")=PKG
+142 ;* I $G(STOP)=1 Q
+143 ;
+144 ;If SOURCE is input verify it.
+145 ;* I $G(PXAA("SOURCE"))'="" D
+146 ;* . N SRC
+147 ;* . S SRC=$$VSOURCE^PXAIVAL(PXAA("SOURCE"),.PXAERR)
+148 ;* . I SRC=0 S PXAERR(9)="SOURCE" D ERRSET Q
+149 ;* . S PXAA("SOURCE")=SRC
+150 ;* I $G(STOP)=1 Q
+151 QUIT
+152 ;
VAL04 ;Setup error array for missing or invalid Provider Narrative.
+1 SET PXAERR(9)="PROVIDER NARRATIVE"
+2 SET PXAERR(11)=$GET(PXAA("NARRATIVE"))
+3 SET PXAERR(12)="We are unable to retrieve a provider narrative from the PROVIDER NARRATIVE file #9999999.27"
+4 DO ERRSET
+5 QUIT
+6 ;
VAL802 ;Setup error array for missing or invalid Provider Narrative Category.
+1 ;Provider Narrative Category is not required, so make this a warning.
+2 SET PXAERR(9)="PROVIDER NARRATIVE CATEGORY"
+3 SET PXAERR(11)=$GET(PXAA("CATEGORY"))
+4 SET PXAERR(12)="We are unable to retrieve a provider narrative category from the PROVIDER NARRATIVE file #9999999.27"
+5 SET PXADI("DIALOG")=8390001.002
+6 SET PXAERR(7)="PROCEDURE"
+7 SET PXAERRW("CPT")=1
+8 QUIT
+9 ;