PXAIVAL ;ISL/PKR - Validation for V-file input. ;05/31/2022
;;1.0;PCE PATIENT CARE ENCOUNTER;**211,217**;Aug 12, 1996;Build 134
;
;Some fields are the same for all the V-files, the same validation
;routine can be used for all of them.
;
;====================
DATETIME(FIELDNAM,PXDT,%DT,PXAERR) ;Validate a date and time.
I PXDT="@" Q 1
;Verify it is a valid FileMan date.
I $$VFMDATE^PXDATE(PXDT,%DT)=-1 D Q 0
. S PXAERR(9)=FIELDNAM
. S PXAERR(11)=PXDT
. S PXAERR(12)=PXDT_" is not a valid internal FileMan date."
. I %DT'["R",%DT'["T" S PXAERR(13)="Time is not allowed for this date."
;
;Verify it is not a future date.
I $$FUTURE^PXDATE(PXDT) D Q 0
. S PXAERR(9)=FIELDNAM
. S PXAERR(11)=PXDT
. S PXAERR(12)=PXDT_" is a future date."
Q 1
;
;====================
EVENTDT(EVENTDT,%DT,PXAERR) ;Validate EVENT D/T.
I EVENTDT="@" Q 1
;Verify it is a valid FileMan date.
I $$VFMDATE^PXDATE(EVENTDT,%DT)=-1 D Q 0
. S PXAERR(9)="EVENT D/T"
. S PXAERR(11)=EVENTDT
. S PXAERR(12)=EVENTDT_" is not a valid FileMan date."
;
;Verify it is not a future date.
I $$FUTURE^PXDATE(EVENTDT) D Q 0
. S PXAERR(9)="EVENT D/T"
. S PXAERR(11)=EVENTDT
. S PXAERR(12)=EVENTDT_" is a future date."
Q 1
;
;====================
MAG(MAG,MPARAMS,PXAERR) ;If a measurement is being input verify that the
;magnitude is in the allowed range.
I MAG="@" D Q 0
. S PXAERR(9)="MAGNITUDE"
. S PXAERR(11)=MAG
. S PXAERR(12)="Measurements cannot be deleted, they can be edited."
I MAG="" D Q 0
. S PXAERR(9)="MAGNITUDE"
. S PXAERR(11)="NULL"
. S PXAERR(12)="Magnitude cannot be NULL."
;
N UCUMCHECK,UCUMCODE,UCUMERROR,UCUMIEN,UCUMSPECIAL
S (UCUMERROR,UCUMSPECIAL)=0
S UCUMIEN=$P(MPARAMS,U,4)
I UCUMIEN="" D Q 0
. S PXAERR(9)="UCUM CODE"
. S PXAERR(11)="NULL"
. S PXAERR(12)="UCUM CODE cannot be NULL."
;
S UCUMCODE=$$UCUMCODE^LEXMUCUM(UCUMIEN)
I $P(UCUMCODE,U,1)="{unit not defined}" D Q 0
. S PXAERR(9)="UCUM CODE"
. S PXAERR(11)="Unit not defined"
. S PXAERR(12)=$P(UCUMCODE,U,2)
;
;There are two UCUM CODES where MAGNITUDE is not a
;number: {mm/dd/yyyy} and {clock_time}. These require
;special validation.
S (UCUMERROR,UCUMSPECIAL)=0
I UCUMCODE="{mm/dd/yyyy}" D
. S UCUMSPECIAL=1
. I MAG'?2N1"/"2N1"/"4N D
.. S PXAERR(9)="UCUM month-day-year"
.. S PXAERR(11)=MAG
.. S PXAERR(12)=MAG_" does not follow the format mm/dd/yyyy."
.. S UCUMERROR=1
. I UCUMERROR=1 Q
. N %DT,X,Y
. S %DT="N",X=MAG
. D ^%DT
. I Y=-1 D
.. S PXAERR(9)="UCUM month-day-year"
.. S PXAERR(11)=MAG
.. S PXAERR(12)=MAG_" is not a vaild date."
.. S UCUMERROR=1
I UCUMERROR=1 Q 0
;
I UCUMCODE="{clock_time}" D
. S UCUMSPECIAL=1
. I MAG'?1.2N1":"2N1(1"AM",1"PM") D
.. S PXAERR(9)="UCUM clock time e.g 12:30PM"
.. S PXAERR(11)=MAG
.. S PXAERR(12)=MAG_" does not follow the format HH:MMAM or HH:MMPM."
.. S UCUMERROR=1
. I UCUMERROR=1 Q
. N HH,MM
. S HH=$P(MAG,":",1)
. I (HH<1)!(HH>12) D
.. S PXAERR(9)="UCUM clock time e.g 12:30PM"
.. S PXAERR(11)=MAG
.. S PXAERR(12)=HH_" is not a valid hour."
.. S UCUMERROR=1
. I UCUMERROR=1 Q
. S MM=$P(MAG,":",2),MM=$E(MM,1,2)
. I (MM<1)!(MM>59) D
.. S PXAERR(9)="UCUM clock time e.g 12:30PM"
.. S PXAERR(11)=MAG
.. S PXAERR(12)=MM_" is not valid for minutes."
.. S UCUMERROR=1
I UCUMERROR=1 Q 0
I UCUMSPECIAL=1 Q 1
;
;Check for a valid magnitude, a positive or negative number,
;up to 14 digits and 9 decimal places.
I MAG'?0.1(0.1"-",0.1"+")0.14N0.1(1"."0.9N) D Q 0
. S PXAERR(9)="MAGNITUDE"
. S PXAERR(11)=MAG
. S PXAERR(12)="Magnitude "_MAG_", is not a number in the acceptable range."
N MAX,MAXDEC,MIN,NUM,NUMDEC
S MIN=$P(MPARAMS,U,1),MAX=$P(MPARAMS,U,2),MAXDEC=$P(MPARAMS,U,3)
S NUM=+PXAA("MAGNITUDE")
I (MIN>NUM)!(MAX<NUM) D Q 0
. S PXAERR(9)="MAGNITUDE"
. S PXAERR(11)=MAG
. S PXAERR(12)="Magnitude "_MAG_" is outside the range "_MIN_" to "_MAX
S NUMDEC=$L($P(NUM,".",2))
I NUMDEC>MAXDEC D Q 0
. S PXAERR(9)="MAGNITUDE"
. S PXAERR(11)=MAG
. S PXAERR(12)="The maximum number of decimals is "_MAXDEC_", the input contains "_NUMDEC_"."
;If magnitude is a fraction does not start with 0 add it.
Q 1
;
;====================
PRV(PXDUZ,PRVTYPE,PXAA,PXAERR,PXAVISIT) ;Validate a provider.
;PRVTYP can be "ENC PROVIDER" or "ORD PROVIDER".
I '$$VPRV^PXAIPRVV(PXDUZ,.PXAA,.PXAERR,PXAVISIT) D Q 0
. S PXAERR(9)=PRVTYPE_" PROVIDER"
. S PXAERR(11)=PXDUZ
Q 1
;
;====================
SET(FILENUM,FIELDNAM,FIELDNUM,VALUE,PXAERR) ;Validate Set of Codes input.
I VALUE="@" Q 1
N EXTERNAL,MSG
S EXTERNAL=$$EXTERNAL^DILFD(FILENUM,FIELDNUM,"",VALUE,"MSG")
I (EXTERNAL=""),$D(MSG) D Q 0
. S PXAERR(9)=FIELDNAM
. S PXAERR(11)=VALUE
. S PXAERR(12)=MSG("DIERR",1,"TEXT",1)
. S PXAERR(13)=MSG("DIERR",1,"TEXT",2)
Q 1
;
;====================
TEXT(FIELDNAM,TEXT,MIN,MAX,PXAERR) ;Validate a free text field.
I TEXT="@" Q 1
I (($L(TEXT)<MIN)!($L(TEXT)>MAX)) D Q 0
. S PXAERR(9)=FIELDNAM
. S PXAERR(11)=TEXT
. S PXAERR(12)="The length of "_FIELDNAM_" is less than "_MIN_" or greater than "_MAX_"."
Q 1
;
;====================
VPKG(PKG,PXAERR) ;Is the Package parameter valid?
N FLAGS,IEN,MSG
S FLAGS=$S(+PKG=PKG:"A",1:"M")
S IEN=+$$FIND1^DIC(9.4,"",FLAGS,PKG,"","","MSG")
I IEN=0 D Q 0
. S PXAERR(9)="PKG"
. S PXAERR(11)="The value is: "_PKG
. I FLAGS="A" S PXAERR(12)=PKG_" is not a valid pointer to the Package file #9.4"
. I FLAGS="M" S PXAERR(12)=$G(MSG("DIERR",1,"TEXT",1))
Q IEN
;
;====================
VSOURCE(SOURCE,PXAERR) ;Is the Data Source valid?
I +SOURCE=SOURCE,($D(^PX(839.7,SOURCE,0))) Q SOURCE
I +SOURCE=SOURCE,('$D(^PX(839.7,SOURCE,0))) D Q Q
. S PXAERR(7)="ENCOUNTER"
. S PXAERR(9)="DATA2PCE parameter SOURCE"
. S PXAERR(11)="The value is: "_SOURCE
. S PXAERR(12)=SOURCE_" is not a valid pointer to the PCE Data Source file #839.7"
;
I ($L(SOURCE)<3)!($L(SOURCE)>64) D Q 0
. S PXAERR(7)="ENCOUNTER"
. S PXAERR(9)="DATA2PCE parameter SOURCE"
. S PXAERR(11)="The value is: "_SOURCE
. S PXAERR(12)="The length of SOURCE is less than 3 or greater than 64."
Q $$SOURCE^PXAPIUTL(SOURCE)
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPXAIVAL 6234 printed Dec 13, 2024@02:26:06 Page 2
PXAIVAL ;ISL/PKR - Validation for V-file input. ;05/31/2022
+1 ;;1.0;PCE PATIENT CARE ENCOUNTER;**211,217**;Aug 12, 1996;Build 134
+2 ;
+3 ;Some fields are the same for all the V-files, the same validation
+4 ;routine can be used for all of them.
+5 ;
+6 ;====================
DATETIME(FIELDNAM,PXDT,%DT,PXAERR) ;Validate a date and time.
+1 IF PXDT="@"
QUIT 1
+2 ;Verify it is a valid FileMan date.
+3 IF $$VFMDATE^PXDATE(PXDT,%DT)=-1
Begin DoDot:1
+4 SET PXAERR(9)=FIELDNAM
+5 SET PXAERR(11)=PXDT
+6 SET PXAERR(12)=PXDT_" is not a valid internal FileMan date."
+7 IF %DT'["R"
IF %DT'["T"
SET PXAERR(13)="Time is not allowed for this date."
End DoDot:1
QUIT 0
+8 ;
+9 ;Verify it is not a future date.
+10 IF $$FUTURE^PXDATE(PXDT)
Begin DoDot:1
+11 SET PXAERR(9)=FIELDNAM
+12 SET PXAERR(11)=PXDT
+13 SET PXAERR(12)=PXDT_" is a future date."
End DoDot:1
QUIT 0
+14 QUIT 1
+15 ;
+16 ;====================
EVENTDT(EVENTDT,%DT,PXAERR) ;Validate EVENT D/T.
+1 IF EVENTDT="@"
QUIT 1
+2 ;Verify it is a valid FileMan date.
+3 IF $$VFMDATE^PXDATE(EVENTDT,%DT)=-1
Begin DoDot:1
+4 SET PXAERR(9)="EVENT D/T"
+5 SET PXAERR(11)=EVENTDT
+6 SET PXAERR(12)=EVENTDT_" is not a valid FileMan date."
End DoDot:1
QUIT 0
+7 ;
+8 ;Verify it is not a future date.
+9 IF $$FUTURE^PXDATE(EVENTDT)
Begin DoDot:1
+10 SET PXAERR(9)="EVENT D/T"
+11 SET PXAERR(11)=EVENTDT
+12 SET PXAERR(12)=EVENTDT_" is a future date."
End DoDot:1
QUIT 0
+13 QUIT 1
+14 ;
+15 ;====================
MAG(MAG,MPARAMS,PXAERR) ;If a measurement is being input verify that the
+1 ;magnitude is in the allowed range.
+2 IF MAG="@"
Begin DoDot:1
+3 SET PXAERR(9)="MAGNITUDE"
+4 SET PXAERR(11)=MAG
+5 SET PXAERR(12)="Measurements cannot be deleted, they can be edited."
End DoDot:1
QUIT 0
+6 IF MAG=""
Begin DoDot:1
+7 SET PXAERR(9)="MAGNITUDE"
+8 SET PXAERR(11)="NULL"
+9 SET PXAERR(12)="Magnitude cannot be NULL."
End DoDot:1
QUIT 0
+10 ;
+11 NEW UCUMCHECK,UCUMCODE,UCUMERROR,UCUMIEN,UCUMSPECIAL
+12 SET (UCUMERROR,UCUMSPECIAL)=0
+13 SET UCUMIEN=$PIECE(MPARAMS,U,4)
+14 IF UCUMIEN=""
Begin DoDot:1
+15 SET PXAERR(9)="UCUM CODE"
+16 SET PXAERR(11)="NULL"
+17 SET PXAERR(12)="UCUM CODE cannot be NULL."
End DoDot:1
QUIT 0
+18 ;
+19 SET UCUMCODE=$$UCUMCODE^LEXMUCUM(UCUMIEN)
+20 IF $PIECE(UCUMCODE,U,1)="{unit not defined}"
Begin DoDot:1
+21 SET PXAERR(9)="UCUM CODE"
+22 SET PXAERR(11)="Unit not defined"
+23 SET PXAERR(12)=$PIECE(UCUMCODE,U,2)
End DoDot:1
QUIT 0
+24 ;
+25 ;There are two UCUM CODES where MAGNITUDE is not a
+26 ;number: {mm/dd/yyyy} and {clock_time}. These require
+27 ;special validation.
+28 SET (UCUMERROR,UCUMSPECIAL)=0
+29 IF UCUMCODE="{mm/dd/yyyy}"
Begin DoDot:1
+30 SET UCUMSPECIAL=1
+31 IF MAG'?2N1"/"2N1"/"4N
Begin DoDot:2
+32 SET PXAERR(9)="UCUM month-day-year"
+33 SET PXAERR(11)=MAG
+34 SET PXAERR(12)=MAG_" does not follow the format mm/dd/yyyy."
+35 SET UCUMERROR=1
End DoDot:2
+36 IF UCUMERROR=1
QUIT
+37 NEW %DT,X,Y
+38 SET %DT="N"
SET X=MAG
+39 DO ^%DT
+40 IF Y=-1
Begin DoDot:2
+41 SET PXAERR(9)="UCUM month-day-year"
+42 SET PXAERR(11)=MAG
+43 SET PXAERR(12)=MAG_" is not a vaild date."
+44 SET UCUMERROR=1
End DoDot:2
End DoDot:1
+45 IF UCUMERROR=1
QUIT 0
+46 ;
+47 IF UCUMCODE="{clock_time}"
Begin DoDot:1
+48 SET UCUMSPECIAL=1
+49 IF MAG'?1.2N1":"2N1(1"AM",1"PM")
Begin DoDot:2
+50 SET PXAERR(9)="UCUM clock time e.g 12:30PM"
+51 SET PXAERR(11)=MAG
+52 SET PXAERR(12)=MAG_" does not follow the format HH:MMAM or HH:MMPM."
+53 SET UCUMERROR=1
End DoDot:2
+54 IF UCUMERROR=1
QUIT
+55 NEW HH,MM
+56 SET HH=$PIECE(MAG,":",1)
+57 IF (HH<1)!(HH>12)
Begin DoDot:2
+58 SET PXAERR(9)="UCUM clock time e.g 12:30PM"
+59 SET PXAERR(11)=MAG
+60 SET PXAERR(12)=HH_" is not a valid hour."
+61 SET UCUMERROR=1
End DoDot:2
+62 IF UCUMERROR=1
QUIT
+63 SET MM=$PIECE(MAG,":",2)
SET MM=$EXTRACT(MM,1,2)
+64 IF (MM<1)!(MM>59)
Begin DoDot:2
+65 SET PXAERR(9)="UCUM clock time e.g 12:30PM"
+66 SET PXAERR(11)=MAG
+67 SET PXAERR(12)=MM_" is not valid for minutes."
+68 SET UCUMERROR=1
End DoDot:2
End DoDot:1
+69 IF UCUMERROR=1
QUIT 0
+70 IF UCUMSPECIAL=1
QUIT 1
+71 ;
+72 ;Check for a valid magnitude, a positive or negative number,
+73 ;up to 14 digits and 9 decimal places.
+74 IF MAG'?0.1(0.1"-",0.1"+")0.14N0.1(1"."0.9N)
Begin DoDot:1
+75 SET PXAERR(9)="MAGNITUDE"
+76 SET PXAERR(11)=MAG
+77 SET PXAERR(12)="Magnitude "_MAG_", is not a number in the acceptable range."
End DoDot:1
QUIT 0
+78 NEW MAX,MAXDEC,MIN,NUM,NUMDEC
+79 SET MIN=$PIECE(MPARAMS,U,1)
SET MAX=$PIECE(MPARAMS,U,2)
SET MAXDEC=$PIECE(MPARAMS,U,3)
+80 SET NUM=+PXAA("MAGNITUDE")
+81 IF (MIN>NUM)!(MAX<NUM)
Begin DoDot:1
+82 SET PXAERR(9)="MAGNITUDE"
+83 SET PXAERR(11)=MAG
+84 SET PXAERR(12)="Magnitude "_MAG_" is outside the range "_MIN_" to "_MAX
End DoDot:1
QUIT 0
+85 SET NUMDEC=$LENGTH($PIECE(NUM,".",2))
+86 IF NUMDEC>MAXDEC
Begin DoDot:1
+87 SET PXAERR(9)="MAGNITUDE"
+88 SET PXAERR(11)=MAG
+89 SET PXAERR(12)="The maximum number of decimals is "_MAXDEC_", the input contains "_NUMDEC_"."
End DoDot:1
QUIT 0
+90 ;If magnitude is a fraction does not start with 0 add it.
+91 QUIT 1
+92 ;
+93 ;====================
PRV(PXDUZ,PRVTYPE,PXAA,PXAERR,PXAVISIT) ;Validate a provider.
+1 ;PRVTYP can be "ENC PROVIDER" or "ORD PROVIDER".
+2 IF '$$VPRV^PXAIPRVV(PXDUZ,.PXAA,.PXAERR,PXAVISIT)
Begin DoDot:1
+3 SET PXAERR(9)=PRVTYPE_" PROVIDER"
+4 SET PXAERR(11)=PXDUZ
End DoDot:1
QUIT 0
+5 QUIT 1
+6 ;
+7 ;====================
SET(FILENUM,FIELDNAM,FIELDNUM,VALUE,PXAERR) ;Validate Set of Codes input.
+1 IF VALUE="@"
QUIT 1
+2 NEW EXTERNAL,MSG
+3 SET EXTERNAL=$$EXTERNAL^DILFD(FILENUM,FIELDNUM,"",VALUE,"MSG")
+4 IF (EXTERNAL="")
IF $DATA(MSG)
Begin DoDot:1
+5 SET PXAERR(9)=FIELDNAM
+6 SET PXAERR(11)=VALUE
+7 SET PXAERR(12)=MSG("DIERR",1,"TEXT",1)
+8 SET PXAERR(13)=MSG("DIERR",1,"TEXT",2)
End DoDot:1
QUIT 0
+9 QUIT 1
+10 ;
+11 ;====================
TEXT(FIELDNAM,TEXT,MIN,MAX,PXAERR) ;Validate a free text field.
+1 IF TEXT="@"
QUIT 1
+2 IF (($LENGTH(TEXT)<MIN)!($LENGTH(TEXT)>MAX))
Begin DoDot:1
+3 SET PXAERR(9)=FIELDNAM
+4 SET PXAERR(11)=TEXT
+5 SET PXAERR(12)="The length of "_FIELDNAM_" is less than "_MIN_" or greater than "_MAX_"."
End DoDot:1
QUIT 0
+6 QUIT 1
+7 ;
+8 ;====================
VPKG(PKG,PXAERR) ;Is the Package parameter valid?
+1 NEW FLAGS,IEN,MSG
+2 SET FLAGS=$SELECT(+PKG=PKG:"A",1:"M")
+3 SET IEN=+$$FIND1^DIC(9.4,"",FLAGS,PKG,"","","MSG")
+4 IF IEN=0
Begin DoDot:1
+5 SET PXAERR(9)="PKG"
+6 SET PXAERR(11)="The value is: "_PKG
+7 IF FLAGS="A"
SET PXAERR(12)=PKG_" is not a valid pointer to the Package file #9.4"
+8 IF FLAGS="M"
SET PXAERR(12)=$GET(MSG("DIERR",1,"TEXT",1))
End DoDot:1
QUIT 0
+9 QUIT IEN
+10 ;
+11 ;====================
VSOURCE(SOURCE,PXAERR) ;Is the Data Source valid?
+1 IF +SOURCE=SOURCE
IF ($DATA(^PX(839.7,SOURCE,0)))
QUIT SOURCE
+2 IF +SOURCE=SOURCE
IF ('$DATA(^PX(839.7,SOURCE,0)))
Begin DoDot:1
+3 SET PXAERR(7)="ENCOUNTER"
+4 SET PXAERR(9)="DATA2PCE parameter SOURCE"
+5 SET PXAERR(11)="The value is: "_SOURCE
+6 SET PXAERR(12)=SOURCE_" is not a valid pointer to the PCE Data Source file #839.7"
End DoDot:1
QUIT
QUIT
+7 ;
+8 IF ($LENGTH(SOURCE)<3)!($LENGTH(SOURCE)>64)
Begin DoDot:1
+9 SET PXAERR(7)="ENCOUNTER"
+10 SET PXAERR(9)="DATA2PCE parameter SOURCE"
+11 SET PXAERR(11)="The value is: "_SOURCE
+12 SET PXAERR(12)="The length of SOURCE is less than 3 or greater than 64."
End DoDot:1
QUIT 0
+13 QUIT $$SOURCE^PXAPIUTL(SOURCE)
+14 ;