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

VENPCC1H.m

Go to the documentation of this file.
VENPCC1H ; IHS/OIT/GIS - MORE ENCOUNTER FORM DATA MINING ;
 ;;2.6;PCC+;;NOV 12, 2007
 ; PATCHED BY GIS 12/9/04 TO ADD RX PROVIDER. CLEANED UP RX CODE
 ;
 ; PROCESS PROBLEMS AND MED FOR VER 2.5
 ; 
DX(PRV,DFN) ; EP-GET PREFERRED DIAGNOSES
 NEW DIEN,GENERIC,ICD,IIEN,NAME,PTYPE,TOT,VAR,VAR1,X,%,INDX
 S PTYPE=$$CLASS(DFN) I PTYPE="" S STOP=1 Q
 S INDX=PRV_"."_PTYPE
 I '$D(^VEN(7.1,"AG",INDX)) S INDX=$$CP^VENPCCU(+$G(DEPTIEN))_"."_PTYPE
 I '$D(^VEN(7.1,"AG",INDX)) S INDX=$$GP^VENPCCU_"."_PTYPE
 S DIEN=0 F TOT=1:1:60 S DIEN=$O(^VEN(7.1,"AG",INDX,DIEN)) Q:'DIEN  D
 . S X=$G(^VEN(7.1,DIEN,0)),ICD=$P(X,U,2),NAME=$P(X,U,3) I '$L(NAME) Q
 . S NAME=$TR(NAME,$C(34),""),NAME=$E(NAME,1,27)
 . S VAR="d"_TOT,VAR1=VAR_"c"
 . S @TMP@(1,VAR)=NAME,@TMP@(1,VAR1)=ICD
 . Q
 K @TMP@(0)
 Q
 ;
PROB(DFN) ; EP-GET ACTIVE PROBLEMS
 I $G(DEFEF),$G(DEPTIEN),$P($G(^VEN(7.41,DEFEF,5)),U,17),$L($T(PROB^VENPCC1K)) D PROB^VENPCC1K(DFN,DEPTIEN) Q  ; ALTERNATE PROBLEM LOOKUP
 NEW %,ICD,ICD9,IIEN,NARR,NIEN,PIEN,STAT,STOP,TOT,TYPE,VAR,VAR1,X,FVFLAG,MAXNARR,MAX
 S TOT=0,PIEN=999999999,MAXNARR=$$MAXNARR^VENPCCU(+$G(DEFEF))
 S MAX=$P($G(^VEN(7.41,DEFEF,1)),U) I 'MAX S MAX=20 ; MAX # PROBS DISPLAYED ; PATCHED BY GIS/OIT 10/15/05 ; PCC+ 2.5 PATCH 1
 F  S PIEN=$O(^AUPNPROB("AC",DFN,PIEN),-1) Q:'PIEN  D  I $G(STOP) Q
 . S X=$G(^AUPNPROB(PIEN,0)),NIEN=$P(X,U,5),IIEN=+X,STAT=$P(X,U,12),TYPE=$P(X,4,U)
 . I NIEN,IIEN,STAT="A",TYPE=""
 . E  Q
 . S NARR=$G(^AUTNPOV(NIEN,0)),ICD=$P($G(^ICD9(IIEN,0)),U),ICD9(IIEN)="" ; MARK THE ICD
 . S %="" I $P($G(^VEN(7.41,DEFEF,2)),U,12) S %=$P($G(^AUPNPROB(PIEN,0)),U,13) ; DATE OF ONSET REQUESTED
 . I % S NARR=NARR_" (Onset: "_$$FMTE^XLFDT(%,"1D")_")" ; APPEND DATE OF ONSET  
 . S TOT=TOT+1 I TOT=MAX S STOP=1
 . S VAR="p"_TOT,VAR1=VAR_"c"
 . S @TMP@(1,VAR)=$E(NARR,1,MAXNARR),@TMP@(1,VAR1)=ICD
 . Q
 I $P($G(^VEN(7.41,DEFEF,2)),U,13) Q  ; OPTION TO DISPLAY ONLY PROBLEMS - NO POVS
POV ; ADD POVS TO THE LIST
 I TOT>(MAX-3) Q
 S TOT=TOT+1,%="",$P(%,"-",15)="",%=%_"POVs"_%
 S @TMP@(1,("p"_TOT))=$E(%,1,40),@TMP@(1,"p"_TOT_"c")=$E(%,1,8) ; INSERT THE POV DIVIDER LINE
 F  S PIEN=$O(^AUPNVPOV("AC",DFN,PIEN),-1) Q:'PIEN  D  I $G(STOP) Q  ; GET MOST RECENT POVS UP TO MAX #
 . S X=$G(^AUPNVPOV(PIEN,0)),NIEN=$P(X,U,4),IIEN=+X
 . I $D(ICD9(IIEN)) Q  ; DONT ADD POV IF ITS ALREADY IN THE LIST!
 . S ICD9(IIEN)=""
 . S NARR=$G(^AUTNPOV(+$G(NIEN),0))
 . S ICD=$$FVICD^VENPCCU(PIEN) ; GET ICD CODE OR BLOCK ICD CODE OF A "FOREIGN" VISIT
 . I '$L(NARR) S NARR=$P($G(^ICD9(IIEN,0)),U,3) I '$L(NARR) S NARR="<missing narrative>"
 . S TOT=TOT+1 I TOT=MAX S STOP=1
 . S VAR="p"_TOT,VAR1=VAR_"c"
 . S @TMP@(1,VAR)=$E(NARR,1,MAXNARR),@TMP@(1,VAR1)=ICD
 . Q
 I '$G(HDR25) Q  ; CHECK TO SEE IF EXTENDED HEADER FILE IS IN USE
 D POV^VENPCC1K(DFN) ; GET 30 MOST RECENT POVS
 D CSPOV^VENPCC1K(DFN,DEPTIEN) ; GET 30 MOST RECENT CLINIC-SPECIFIC POVS
 D MH^VENPCC1K(DFN) ; GER 15 MOST RECENT MENTAL HEALTH POVS
 Q
 ;
MED(PRV,DFN) ; EP-GET RECENT MEDS
 N DATE,DAYS,DCD,EXT,MED,MIEN,QTY,RIEN,SIG,STOP,TOT,VAR,VIEN,SCAT,NTRX
 N X,X1,X2,REM,IDT,MAX,PER,STAT,REF,RED,EXP,CHM,Y,Z0,Z1
 N MAXNAME,MAXSIG,MAXREM,MAXRX,RXHDR,%,RXIEN,CHMFLG,SORT,CNT,STG,PASS1,RXSORT,CKCM
 K @TMP@(0)
RXVAR ; SET GLOBAL RX VARIABLES
 S (IDT,TOT)=0
 S CFIGIEN=$$CFG^VENPCCU
 S MAX=$P($G(^VEN(7.41,+$G(DEFEF),2)),U,4) I 'MAX S MAX=15 ; MAX # OF RXS ALLOWED (UP TO 60) ; PATCHED BY GIS/OIT 10/15/05 ; PCC+ 2.5 PATCH 1
 S X=$G(^VEN(7.41,DEFEF,14))
 S MAXRX=$P(X,U) I 'MAXRX S MAXRX=150 ; MAX LENGTH OF COMPLETE RX
 S MAXNAME=$P(X,U,2) I 'MAXNAME S MAXNAME=30 ; MAX LENGTH OF DRUG NAME
 S MAXSIG=$P(X,U,3) I 'MAXSIG S MAXSIG=30 ; MAX LENGTH OF SIG
 S MAXREM=$P(X,U,4) I 'MAXREM S MAXREM=49 ; MAX LENGTH OF REMARK
 S RXSORT=+$P($G(^VEN(7.41,DEFEF,14)),U,5) ; SHOULD THE Rx LIST BE SORTED?
 S RXHDR="PRESCRIPTIONS" ; DYNAMIC RX HEADER FLAG
 S CKCM=0,X=$P($G(^VEN(7.41,DEFEF,2)),U,7)
 I X S CKCM=1 ; FORM-SPECIFIC CHRONIC MED FILTER IS ACTIVE
 I $P($G(^VEN(7.41,DEFEF,2)),U,7)="",$P($G(^VEN(7.5,CFIGIEN,0)),U,16),X'=0 S CKCM=1 ; GLOBAL CHRONIC MED FLAG ; PATCHED BY GIS/OIT 6/5/05 ; PCC+ 2.5 PATCH 5
 I CKCM S RXHDR=RXHDR_" (Chronic meds only)",RXSORT=0 ; NO SORTING NECESSARY
 I $P(X,U,8) S RXHDR="ACTIVE "_RXHDR
 I $G(HDR25) S @TMP@(1,"mh")=RXHDR
MLOOP K STOP F  Q:$G(STOP)  S IDT=$O(^AUPNVMED("AA",DFN,IDT)) Q:'IDT  S MIEN=0 F  Q:$G(STOP)  S MIEN=$O(^AUPNVMED("AA",DFN,IDT,MIEN)) Q:'MIEN  D  ; PATCHED 2/12/07 BY GIS FOR PCC+2.6
 . S X=$G(^AUPNVMED(MIEN,0)),RIEN=+X,NTRX=$P(X,U,4)
 . I $P($G(^VEN(7.41,+$G(DEFEF),2)),U,9),$D(@TMP@(0,RIEN)) Q  ; REDUNDANT MED CHECKS
 . S DCD=$P(X,U,8) I DCD Q  ; QUIT IF MED HAS BEEN DICONTINUED
 . S VIEN=$P(X,U,3),SIG=$P(X,U,5),QTY=$P(X,U,6),DAYS=$P(X,U,7),REM=""
 . S %=$G(^AUPNVSIT(+VIEN,0)) I '$L(%) Q
 . S DATE=$P(%,U) I 'DATE Q
 . S SCAT=$P(%,U,7)
 . S MED=$P($G(^PSDRUG(+RIEN,0)),U)
 . I $L(NTRX) S MED=NTRX ; NON-TABLE NAME OF DRUG
 . I '$L(MED) Q
 . I SCAT="E" S MED=MED_" (ORx)" ; OUTSIDE RX
 . I DATE,$L(MED) S Y=DATE\1 X ^DD("DD") S EXT=Y
 . I '$L($G(EXT)) Q  ; EXT DATE MUST EXIST
 . ; AT THIS POINT EXT,MED,QTY,SIG AND REM HAVE BEEN SET
 . I DAYS S PER=75,%=$P($G(^VEN(7.41,+$G(DEFEF),2)),U,6) S:% PER=% S X1=DT,X2=DATE\1 D ^%DTC I X>(DAYS+PER) Q  ; ELIMINATE EXPIRED MEDS
 . I 'DAYS S X1=DT,X2=-180 D C^%DTC I X>DATE Q  ; IF DAYS ARE NOT SPECIFIED, DONT SHOW RX IF OVER 180 DAYS OLD
 . I $P($G(^VEN(7.5,CFIGIEN,0)),U,19),$L($T(SIG^PSOHELP)) S SIG=$$SIG(SIG) I 1 ; EXPANDED SIG
 . E  I $D(^DD(52,10,9.2))  S X=SIG X ^DD(52,10,9.2) I $G(SIG)="" S SIG=X ; BKWRD COMPAT
 . S CHMFLG=0 ; SETS CHRONIC MED STATUS TO DEFAULT VALUE OF "0"
RXCK . S RXIEN=+$O(^PSRX("APCC",MIEN,0)) ; CHECKS TO SEE IF RX FILE IS POPULATED
 . I 'RXIEN G ADD  ; IF RX FILE NOT POPULATED, BYPASS SPECIAL STUFF AND ADD RX TO THE ARRAY
 . ; PATCHED BY GIS/OIT 03/15/06 ; PCC+ 2.5 PATCH 4
 . I $P($G(^VEN(7.41,+$G(DEFEF),2)),U,8),$P($G(^PSRX(RXIEN,"STA")),U)>2 Q  ; FAILED ACTIVE MED FILTER, SO QUIT
 . I $D(^PS(55,DFN,"P","CP",RXIEN)) S CHMFLG=1 G NEWREM ; ALREADY A CRONIC MED - NO CHECK NEEDED
 . I CKCM Q  ; NOT A CHRONIC MED.  FAILED CHRONIC MED FILTER, SO QUIT
NEWREM . S REM=$$REM(RXIEN) ; GET REMARKS
 . S SIG=$$REFILL(SIG,RXIEN) ; ADD REFILL INFO TO SIG
ADD . ; ADD RX INFO TO ARRAY
 . S TOT=TOT+1
 . S @TMP@(0,RIEN)=""
 . I 'RXSORT S CHMFLG=0 ; IF NOT SORTING, LUMP EVERYTHING TOGETHER UNDER THE "0" NODE
MAXMSG . I TOT>MAX S STOP=1,PASS1(0,TOT)="More meds on Health Summary!"  Q  ; WARNING MSG THAT NOT ALL MEDS WILL BE DISPLAYED
SORT . S PASS1(CHMFLG,TOT)=$G(EXT)_"|"_$G(MED)_"|"_$G(QTY)_"|"_$G(SIG)_"|"_$G(REM)
 . Q
RXLIST ; FINAL PASS: CREATE THE (SORTED) MAIL MERGE NODES
 I RXSORT D  ; SORT HEADERS
 . I '$D(PASS1(1)),'$D(PASS1(0)) S PASS1(1,.5)=" NO CURRENT MEDICATIONS" Q
 . S PASS1(1,.5)=$S($D(PASS1(1)):"",1:"NO")_" CHRONIC MEDICATIONS"
 . S PASS1(1,999999)=$S($D(PASS1(0)):"",1:"NO")_"  INCIDENTAL MEDICATIONS" ; SORT SUB-HEADERS
 . Q
 S TOT=0
 F SORT=1,0 S CNT=0 F  S CNT=$O(PASS1(SORT,CNT)) Q:'CNT  D
 . S STG=$G(PASS1(SORT,CNT)) I '$L(STG) Q
 . S TOT=TOT+1
 . S MED=$P(STG,"|",2) S QTY=$P(STG,"|",3) S SIG=$P(STG,"|",4) S REM=$P(STG,"|",5)
 . S EXT=$P(STG,"|",1) I STG'["|" S EXT=""
 . I $P($G(^VEN(7.41,+$G(DEFEF),0)),U,11) D CLASSIC Q  ; FORMAT AS A CLASSIC MED LIST
REVLIST . ; REVISED MED LIST USED IN VER 2 AND LATER
 . I STG'["|" S %=STG
 . E  S %=EXT_" "_$E(MED,1,MAXNAME)_" "_$S(QTY:"#",1:"")_QTY_"  "_$E(SIG,1,MAXSIG)_"  "_$E(REM,1,MAXREM)
 . S @TMP@(1,("md"_TOT))=% ; NEW Rx LIST FORMATTING: STORE ENTIRE Rx IN md NODE
 . S @TMP@(1,("mm"_TOT))="",@TMP@(1,("mq"_TOT))="",@TMP@(1,("ms"_TOT))="",@TMP@(1,("mr"_TOT))=""
 . Q
 K @TMP@(0)
 Q
 ; 
CLASSIC ; EP-LEGACY Rx LIST FORMATTING
 I STG'["|" S SIG=STG
 S @TMP@(1,("md"_TOT))=EXT
 S @TMP@(1,("mm"_TOT))=$E(MED,1,MAXNAME)
 S @TMP@(1,("mq"_TOT))=$S(QTY:"#",1:"")_QTY
 S @TMP@(1,("ms"_TOT))=$E(SIG,1,MAXSIG)
 S @TMP@(1,("mr"_TOT))=$E(REM,1,MAXREM)
 Q
 ;
SIG(SIG) ; EP-GET EXPANDED SIG
 N X,INS1
 I $G(SIG)="" Q ""
 S X=SIG
 D SIG^PSOHELP
 I $L($G(INS1))'>1 S INS1=SIG
 Q $G(INS1)
 ; 
REFILL(SIG,RXIEN) ; EP-APPEND REFILL INFO TO SIG
 N REF,X
 S REF=$P($G(^PSRX(RXIEN,0)),U,9) I '$L(REF) Q SIG
 S X=0 F  S X=$O(^PSRX(RXIEN,1,X)) Q:'X  S REF=REF-1 ; COMPUTE REMAINING REFILS BASED ON RX DATA
 S SIG=SIG_" ("_REF_" refill"_$S(REF=1:"",1:"s")_" left)" ; APPEND THE SIG
 Q SIG
 ;
REM(RXIEN) ; EP-GET INFO FROM PRESCRIPTION FILE: REMARKS, ISSUE DATE AND PRESCRIBING PROVIDER
 N REM,RXP,X,TXT,MODE,ISDT,Y,DFLG
 S REM=""
 I '$P($G(^VEN(7.41,DEFEF,0)),U,12) S REM=$P($G(^PSRX(RXIEN,3)),U,7) ; GET REMINDER NOTE
 S DFLG=$P($G(^VEN(7.41,DEFEF,2)),U,11) I DFLG D  ; ISSUE DATE REQUESTED
 . S %=$P($G(^PSRX(RXIEN,0)),U,13) I '% Q
 . S ISDT=$$FMTE^XLFDT(%,2)
 . I DFLG=1 S EXT=$G(EXT)_" (Issued: "_ISDT_")" Q  ; APPEND ISSUE DATE
 . S EXT="Issued: "_ISDT
 . Q
 I $P($G(^VEN(7.41,DEFEF,14)),U,9),$P($G(^PSRX(RXIEN,"STA")),U)>2 S REM=REM_" - "_$$GET1^DIQ(52,(RXIEN_","),100)
 S MODE=$P($G(^VEN(7.41,DEFEF,0)),U,14) I 'MODE Q $E(REM,1,MAXREM) ; PROVIDER INFO NOT REQUESTED, SO QUIT NOW
 S RXP=$P($G(^PSRX(+$G(RXIEN),0)),U,4) I 'RXP Q ""
 S RXP=$$PRV^VENPCCU(RXP) I 'RXP Q "" ; COVERT FILE 6 IEN TO FILE 200 IEN IF NECESSARY
 S X=$G(^VA(200,+RXP,0)) I '$L(X) Q ""
 S TXT=$S(MODE=1:$P(X,U,2),1:$P(X,U)) ; CHOOSE BETWEEN INITIALS AND THE FULL NAME
 I '$L(TXT),MODE=1,$L($P(X,U)) S TXT=$E($P(X,",",2))_$E(X) ; CREATE INITIALS ON THE FLY
 I $L(TXT) S TXT=" ["_TXT_"]"
 S REM=$E(REM,1,(MAXREM-3)-$L(TXT))_TXT
 Q REM
 ; 
CLASS(DFN) ; EP-GIVEN A DFN, RETURN THE PATIENT CLASS FOR USER PREFERENCES
 N AGE,SEX,DOB,X,Y
 S X=$P($G(^DPT(DFN,0)),U,2,3),DOB=$P(X,U,2),SEX=$P(X,U)
 I DOB,$L(SEX)
 E  Q ""
 S AGE=(DT-DOB)\10000
 I AGE<2 Q 1
 I AGE<12 Q 2
 S Y=(SEX="F")
 I AGE<18 Q (3+Y)
 I AGE<65 Q (5+Y)
 Q (7+Y)
 ;