Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PXHFMEASREPAIR

PXHFMEASREPAIR.m

Go to the documentation of this file.
PXHFMEASREPAIR ;SLC/PKR - Repair V Health Factor entries that have corrupted measurements. ;05/03/2023
 ;;1.0;PCE PATIENT CARE ENCOUNTER;**234**;Aug 12, 1996;Build 6
 ;
 ; Reference     Field        ICR#
 ;^DPT(D0,0)    .01 NAME 0;1  10035
 ;
 ;===============================
EDITMEASUREMENT ;Let the user select V HF entries and edit the measurement.
 N COMMENTS,DA,DIC,DIE,DONE,DR,HFIEN,HFNAME,HFTEMP220,MAGNITUDE,MAX,MIN,MAXDEC
 N NUMNULL,NUMVHFDEC,NL,TEXT,UCUMCODE,UCUMIEN,VALID,VHFDEC,VHFTEMP220,VHFUCUMIEN,Y
 S (DIC,DIE)=9000010.23
 S DIC("A")="Input the internal entry number, or press ENTER to exit: "
 S DR="220;221"
 W !,"Edit the measurement for selected V HEALTH FACTOR entries."
 S DONE=0
 F  Q:DONE  D
 . S DIC(0)="AEN"
 . D ^DIC
 . I Y=-1 S DONE=1 Q
 . S DA=$P(Y,U,1)
 .;Display the HF information for the user.
 . S HFIEN=$P(^AUPNVHF(DA,0),U,1)
 . S COMMENTS=$G(^AUPNVHF(DA,811))
 . S HFNAME=$P(^AUTTHF(HFIEN,0),U,1)
 . S HFTEMP220=$G(^AUTTHF(HFIEN,220))
 . S MIN=$P(HFTEMP220,U,1),MAX=$P(HFTEMP220,U,2)
 . S MAXDEC=$P(HFTEMP220,U,3),UCUMIEN=$P(HFTEMP220,U,4)
 . S UCUMCODE=$S(UCUMIEN>0:$$UCUMFIELDS^PXUCUM(UCUMIEN,"DESCRIPTION"),1:"")
 . S NUMNULL=0
 . I MIN="" S NUMNULL=NUMNULL+1
 . I MAX="" S NUMNULL=NUMNULL+1
 . I MAXDEC="" S NUMNULL=NUMNULL+1
 . I UCUMIEN="" S NUMNULL=NUMNULL+1
 . W !!,"Health Factor: ",HFNAME
 . I NUMNULL=4 W !,"A measurement is not defined for this health factor."
 . I (NUMNULL>0),(NUMNULL<4) W !,"The measurement is not completly defined for this health factor."
 . I NUMNULL=0 D
 .. W !," MINIMUM VALUE: ",MIN
 .. W !," MAXIMUM VALUE: ",MAX
 .. W !," MAXIMUM DECIMALS: ",MAXDEC
 .. W !," UCUM DESCRIPTION: ",UCUMCODE
 . W !," COMMENTS: ",COMMENTS
 . W !
 . S VALID=0
 . F  Q:VALID  D
 .. D ^DIE
 ..;Validate the user's input.
 .. S NL=1,TEXT(NL)=""
 .. K TEXT
 .. S VALID=1
 .. S VHFTEMP220=$G(^AUPNVHF(DA,220))
 .. S MAGNITUDE=$P(VHFTEMP220,U,1)
 .. S VHFUCUMIEN=$P(VHFTEMP220,U,2)
 .. S NUMVHFDEC=$L($P(MAGNITUDE,".",2))
 .. I (MAGNITUDE=""),(VHFUCUMIEN'="") D
 ... S NL=NL+1,TEXT(NL)="MAGNITUDE is NULL, but UCUM CODE is not NULL."
 ... S VALID=0
 .. I (MAGNITUDE'=""),(VHFUCUMIEN="") D
 ... S NL=NL+1,TEXT(NL)="MAGNITUDE is not NULL, but UCUM CODE is NULL."
 ... S VALID=0
 .. I (MAGNITUDE'=""),((MAGNITUDE<MIN)!(MAGNITUDE>MAX)) D
 ... S NL=NL+1,TEXT(NL)=MAGNITUDE_" is not in the inclusive range "_MIN_" to "_MAX_"."
 ... S VALID=0
 .. I NUMVHFDEC>MAXDEC D
 ... S NL=NL+1,TEXT(NL)="The maximum number of decimals is exceeded."
 ... S VALID=0
 .. I (VHFUCUMIEN'=""),(VHFUCUMIEN'=UCUMIEN) D
 ... S NL=NL+1,TEXT(NL)="The V HEALTH FACTORS UCUM CODE does not match the HEALTH FACTORS UCUM CODE."
 ... S VALID=0
 .. I 'VALID D EN^DDIOL(.TEXT)
 Q
 ;
 ;===============================
LCSHF(HFIEN,VHFIEN,MEASDEF,NUMREPAIRED) ;Special handling for the LCS HFs, if what is stored
 ;in COMMENTS is a valid magnitude use it.
 N COMMENTS,DEC,DECLEN,MAGNITUDE,NUMBER,ORGMAG,TEMP220,UCUMIEN,VALIDNUM,VHFTEMP220
 S VHFTEMP220=$G(^AUPNVHF(VHFIEN,220))
 S (MAGNITUDE,ORGMAG)=$P(VHFTEMP220,U,1)
 S UCUMIEN=$P(VHFTEMP220,U,2)
 ;If MAGNITUDE is NULL try to get a number from COMMENTS.
 I MAGNITUDE="" D
 . S COMMENTS=$G(^AUPNVHF(VHFIEN,811))
 . I COMMENTS="" Q
 . S NUMBER=+COMMENTS
 . S VALIDNUM=$S(NUMBER=COMMENTS:1,1:0)
 . I 'VALIDNUM S VALIDNUM=$$NUMCHECK(COMMENTS)
 . I 'VALIDNUM Q
 . I (NUMBER<MEASDEF("MIN"))!(NUMBER>MEASDEF("MAX")) Q
 . S MAGNITUDE=NUMBER
 ;Could not obtain a valid MAGNITUDE, remove anything on the 220 node.
 I MAGNITUDE="" D  Q
 . K ^AUPNVHF(VHFIEN,220)
 . S ^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)="",NUMNOTREPAIRED=NUMNOTREPAIRED+1
 I (MAGNITUDE<MEASDEF("MIN"))!(MAGNITUDE>MEASDEF("MAX")) D  Q
 . S ^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)="",NUMNOTREPAIRED=NUMNOTREPAIRED+1
 ;Have a MAGNITUDE, make sure the number of decimals does not exceed MAXDEC.
 S DEC=$P(MAGNITUDE,".",2),DECLEN=$L(DEC)
 I DECLEN>MEASDEF("MAXDEC") S MAGNITUDE=$FN(MAGNITUDE,"",MEASDEF("MAXDEC"))
 ;Store the measurement using the UCUM from the health factor.
 I (MAGNITUDE'=ORGMAG)!(UCUMIEN'=MEASDEF("UCUMIEN")) D
 . S ^AUPNVHF(VHFIEN,220)=MAGNITUDE_U_MEASDEF("UCUMIEN")
 . S NUMREPAIRED=NUMREPAIRED+1
 Q
 ;
 ;===============================
NUMCHECK(COMMENTS) ;Verify all the characters in COMMENTS are numbers or ".".
 N ASCII,CHAR,DONE,IND,LEN,VALID
 S LEN=$L(COMMENTS)
 S (DONE,IND)=0,VALID=1
 F  Q:(DONE)!(IND=LEN)  D
 . S IND=IND+1
 . S CHAR=$E(COMMENTS,IND)
 . S ASCII=$A(CHAR)
 . I ASCII=46 Q
 . I (ASCII<48)!(ASCII>57) S DONE=1,VALID=0
 Q VALID
 ;
 ;===============================
REPAIR ;Repair V Health Factor entries that have corrupted measurements.
 N COMMENTS,DEC,DECLEN,HFIEN,HFTEMP220,LCSHF,LCSPACKDAY,LCSYEARSSMOKED,MAGNITUDE,MEASDEF
 N NUMBER,NUMREPAIRED,NUMNOTREPAIRED,ORGMAG,UCUMIEN,VALIDNUM,VHFIEN,VHFTEMP220
 K ^TMP("PXMEASDEF",$J),^TMP("PXNOREPAIR",$J)
 ;Get the IEN of the LCS health factors.
 S LCSPACKDAY=$O(^AUTTHF("B","LCS PACKS/DAY",""))
 S LCSYEARSSMOKED=$O(^AUTTHF("B","LCS YEARS SMOKED",""))
 S (HFIEN,NUMREPAIRED,NUMNOTREPAIRED)=0
 F  S HFIEN=+$O(^AUPNVHF("B",HFIEN)) Q:HFIEN=0  D
 . I (HFIEN=LCSPACKDAY)!(HFIEN=LCSYEARSSMOKED) S LCSHF=1
 . E  S LCSHF=0
 . S HFTEMP220=$G(^AUTTHF(HFIEN,220))
 . I HFTEMP220'="" D
 .. S MEASDEF("MIN")=$P(HFTEMP220,U,1)
 .. S MEASDEF("MAX")=$P(HFTEMP220,U,2)
 .. S MEASDEF("MAXDEC")=$P(HFTEMP220,U,3)
 .. S MEASDEF("UCUMIEN")=$P(HFTEMP220,U,4)
 .. S MEASDEF("PROMPT CAPTION")=$P(HFTEMP220,U,5)
 .. S MEASDEF("UCUM DISPLAY")=$P(HFTEMP220,U,6)
 .. I '$$VALIDMEASDEF(.MEASDEF) S ^TMP("PXMEASDEF",$J,HFIEN)=""
 . I HFTEMP220="" S (MEASDEF("MIN"),MEASDEF("MAX"),MEASDEF("MAXDEC"),MEASDEF("UCUMIEN"),MEASDEF("PROMPT CAPTION"),MEASDEF("UCUM DISPLAY"))=""
 . S MEASDEF=$S(MEASDEF("MIN")="":0,MEASDEF("MAX")="":0,1:1)
 . S VHFIEN=0
 . F  S VHFIEN=+$O(^AUPNVHF("B",HFIEN,VHFIEN)) Q:VHFIEN=0  D
 .. I LCSHF D LCSHF(HFIEN,VHFIEN,.MEASDEF,.NUMREPAIRED) Q
 .. S VHFTEMP220=$G(^AUPNVHF(VHFIEN,220))
 .. S (MAGNITUDE,ORGMAG)=$P(VHFTEMP220,U,1)
 .. S UCUMIEN=$P(VHFTEMP220,U,2)
 ..;If the HF does not have a measurement defined delete the VHF 220 node.
 ..;The 220 node could be ^.
 .. I (MEASDEF=0),((MAGNITUDE'="")!(UCUMIEN'=""))  D  Q
 ... S ^AUPNVHF(VHFIEN,220)="",NUMREPAIRED=NUMREPAIRED+1
 .. I (MAGNITUDE=""),(UCUMIEN="") Q
 ..;If the units do not match automatic repair is not posible.
 .. I UCUMIEN'=MEASDEF("UCUMIEN") S ^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)="",NUMNOTREPAIRED=NUMNOTREPAIRED+1 Q
 .. ;If MAGNITUDE is NULL try to get a number from COMMENTS.
 .. I MAGNITUDE="" D
 ... S COMMENTS=$G(^AUPNVHF(VHFIEN,811))
 ... I COMMENTS="" Q
 ... S NUMBER=+COMMENTS
 ... S VALIDNUM=$S(NUMBER=COMMENTS:1,1:0)
 ... I 'VALIDNUM S VALIDNUM=$$NUMCHECK(COMMENTS)
 ... I 'VALIDNUM Q
 ... I (NUMBER<MEASDEF("MIN"))!(NUMBER>MEASDEF("MAX")) Q
 ... S MAGNITUDE=NUMBER
 ..;Could not obtain a valid MAGNITUDE, remove anything on the 220 node.
 .. I MAGNITUDE="" D  Q
 ... K ^AUPNVHF(VHFIEN,220)
 ... S ^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)="",NUMNOTREPAIRED=NUMNOTREPAIRED+1
 .. I (MAGNITUDE<MEASDEF("MIN"))!(MAGNITUDE>MEASDEF("MAX")) D  Q
 ... S ^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)="",NUMNOTREPAIRED=NUMNOTREPAIRED+1
 .. ;Have a MAGNITUDE, make sure the number of decimals does not exceed MAXDEC.
 .. S DEC=$P(MAGNITUDE,".",2),DECLEN=$L(DEC)
 .. I DECLEN>MEASDEF("MAXDEC") S MAGNITUDE=$FN(MAGNITUDE,"",MEASDEF("MAXDEC"))
 .. I MAGNITUDE'=ORGMAG D
 ... S ^AUPNVHF(VHFIEN,220)=MAGNITUDE_U_MEASDEF("UCUMIEN")
 ... S NUMREPAIRED=NUMREPAIRED+1
 D SENDVHFMESSAGE(NUMREPAIRED,NUMNOTREPAIRED)
 I $D(^TMP("PXMEASDEF",$J)) D SENDHFMESSAGE
 K ^TMP("PXMEASDEF",$J),^TMP("PXNOREPAIR",$J)
 Q
 ;
 ;===============================
SENDHFMESSAGE ;Send a MailMan message to the PCE Management Repair mail group
 ;listing the HF entries with incomplete measurement definitions.
 N HFIEN,MGIEN,MGROUP,NAME,NL,SUBJECT,TO,VALUE
 S SUBJECT="HEALTH FACTORS WITH INCOMPLETE MEASUREMENT DEFINITION"
 S MGIEN=+$G(^PX(815,1,650))
 I MGIEN>0 D
 . S MGROUP="G."_$$GET1^DIQ(3.8,MGIEN,.01)
 . S TO(MGROUP)=""
 S TO(DUZ)=""
 K ^TMP("PXHFMSG",$J)
 S ^TMP("PXHFMSG",$J,1,0)="The following health factors have incomplete measurement definitions, they"
 S ^TMP("PXHFMSG",$J,2,0)="should be completed as soon as possible."
 S NL=2
 S HFIEN=0
 F  S HFIEN=$O(^TMP("PXMEASDEF",$J,HFIEN)) Q:HFIEN=""  D
 . S NAME=$P(^AUTTHF(HFIEN,0),U,1)
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=""
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=NAME
 . S HFTEMP220=$G(^AUTTHF(HFIEN,220))
 . S VALUE=$P(HFTEMP220,U,1)
 . I VALUE="" S VALUE="Missing"
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" MINIMUM VALUE: "_VALUE
 . S VALUE=$P(HFTEMP220,U,2)
 . I VALUE="" S VALUE="Missing"
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" MAXIMUM VALUE: "_VALUE
 . S VALUE=$P(HFTEMP220,U,3)
 . I VALUE="" S VALUE="Missing"
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" MAXIMUM DECIMALS: "_VALUE
 . S VALUE=$P(HFTEMP220,U,4)
 . S VALUE=$S(VALUE'="":$$UCUMFIELDS^PXUCUM(VALUE,"DESCRIPTION"),1:"Missing")
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" UCUM CODE: "_VALUE
 . S VALUE=$P(HFTEMP220,U,5)
 . I VALUE="" S VALUE="Missing"
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" PROMPT CAPTION: "_VALUE
 . S VALUE=$P(HFTEMP220,U,6)
 . I VALUE="" S VALUE="Missing"
 . S NL=NL+1,^TMP("PXHFMSG",$J,NL,0)=" UCUM DISPLAY: "_VALUE
 D SEND^PXMSG("PXHFMSG",SUBJECT,.TO)
 K ^TMP("PXHFMSG",$J)
 Q
 ;
 ;===============================
SENDVHFMESSAGE(NUMREPAIRED,NUMNOTREPAIRED) ;Send a MailMan message to the PCE Management Repair mail group
 ;listing the VHF entries whose measurement could not be repaired.
 N DFN,HF,HFIEN,HFTEMP220,MAGNITUDE,MAX,MAXDEC,MGIEN,MGROUP,MIN,PATIENT,NL,NOW
 N SUBJECT,TEMP,TO,UCUMCODE,UCUMIEN,VHFIEN,VHFTEMP220,VISITDT,VISITIEN
 K ^TMP("PXVHFMSG",$J)
 S SUBJECT="V HEALTH FACTORS MEASUREMENT REPAIR"
 S MGIEN=+$G(^PX(815,1,650))
 I MGIEN>0 D
 . S MGROUP="G."_$$GET1^DIQ(3.8,MGIEN,.01)
 . S TO(MGROUP)=""
 S TO(DUZ)=""
 S NOW=$$NOW^XLFDT
 S ^TMP("PXVHFMSG",$J,1,0)="V HEALTH FACTORS measurement repair completed at "_$$FMTE^XLFDT(NOW)
 S ^TMP("PXVHFMSG",$J,2,0)="Measurements were repaired for "_NUMREPAIRED_" entries."
 I '$D(^TMP("PXNOREPAIR",$J)) D  Q
 . D SEND^PXMSG("PXVHFMSG",SUBJECT,.TO)
 . K ^TMP("PXVHFMSG",$J)
 S ^TMP("PXVHFMSG",$J,3,0)="There were "_NUMNOTREPAIRED_" V HEALTH FACTORS entries that could not be automatically"
 S ^TMP("PXVHFMSG",$J,4,0)="repaired:"
 S HFIEN=0,NL=4
 F  S HFIEN=$O(^TMP("PXNOREPAIR",$J,HFIEN)) Q:HFIEN=""  D
 . S HF=$P(^AUTTHF(HFIEN,0),U,1)
 . S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=""
 . S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)="Health Factor: "_HF
 . S HFTEMP220=^AUTTHF(HFIEN,220)
 . S MIN=$P(HFTEMP220,U,1)
 . S MAX=$P(HFTEMP220,U,2)
 . S MAXDEC=$P(HFTEMP220,U,3)
 . S UCUMIEN=$P(HFTEMP220,U,4)
 . S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)="Minimum Value: "_MIN_" Maximum Value: "_MAX
 . S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)="Maximum Decimals: "_MAXDEC
 . S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)="UCUM Code: "_$$UCUMFIELDS^PXUCUM(UCUMIEN,"DESCRIPTION")
 . S VHFIEN=0
 . F  S VHFIEN=$O(^TMP("PXNOREPAIR",$J,HFIEN,VHFIEN)) Q:VHFIEN=""  D
 .. S TEMP=^AUPNVHF(VHFIEN,0)
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=""
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=" V Health Factors IEN: "_VHFIEN
 .. S DFN=$P(TEMP,U,2),PATIENT=$P(^DPT(DFN,0),U,1)
 .. S VISITIEN=$P(TEMP,U,3),VISITDT=$P(^AUPNVSIT(VISITIEN,0),U,1)
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=" Visit: "_$$FMTE^XLFDT(VISITDT)
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=" Patient: "_PATIENT
 .. S VHFTEMP220=$G(^AUPNVHF(VHFIEN,220))
 .. S MAGNITUDE=$P(VHFTEMP220,U,1)
 .. I MAGNITUDE="" S MAGNITUDE="Missing"
 .. S UCUMIEN=$P(VHFTEMP220,U,2)
 .. I UCUMIEN>0 S UCUMCODE=$$UCUMFIELDS^PXUCUM(UCUMIEN,"DESCRIPTION")
 .. E  S UCUMCODE="Missing"
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=" MAGNITUDE: "_MAGNITUDE_"; UCUM CODE: "_UCUMCODE
 .. S NL=NL+1,^TMP("PXVHFMSG",$J,NL,0)=" Comments: "_$G(^AUPNVHF(VHFIEN,811))
 D SEND^PXMSG("PXVHFMSG",SUBJECT,.TO)
 K ^TMP("PXVHFMSG",$J)
 Q
 ;
 ;===============================
TASKREPAIR ;Run REPAIR^PXHFMEASREPAIR as a TaskMan job.
 N TEXT,ZTDTH,ZTSAVE,ZTIO,ZTSK,ZTRTN,ZTDESC,ZTUCI,ZTCPU,ZTSYNC,ZTKIL
 S ZTRTN="REPAIR^PXHFMEASREPAIR"
 S ZTDESC="Repair corrupted V HEALTH FACTORS measurements"
 S ZTIO=""
 S ZTDTH=$H
 D ^%ZTLOAD
 I $G(ZTSK) D
 . S TEXT="V HEALTH FACTORS measurement repair has been queued, task number: "_ZTSK
 . D BMES^XPDUTL(.TEXT)
 I '$G(ZTSK) D
 . S TEXT="V HEALTH FACTORS measurement repair failed to queue. Please create a ticket."
 . D BMES^XPDUTL(.TEXT)
 Q
 ;
 ;===============================
VALIDMEASDEF(MEASDEF) ;Make sure a measurement is completely defined.
 N NUMNULL
 S NUMNULL=0
 I MEASDEF("MIN")="" S NUMNULL=NUMNULL+1
 I MEASDEF("MAX")="" S NUMNULL=NUMNULL+1
 I MEASDEF("MAXDEC")="" S NUMNULL=NUMNULL+1
 I MEASDEF("UCUMIEN")="" S NUMNULL=NUMNULL+1
 I MEASDEF("PROMPT CAPTION")="" S NUMNULL=NUMNULL+1
 I MEASDEF("UCUM DISPLAY")="" S NUMNULL=NUMNULL+1
 Q $S(NUMNULL=0:1,1:0)
 ;