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

PXVRPC7A.m

Go to the documentation of this file.
PXVRPC7A ;BPFO/LMT - PCE RPCs for V Immunization - Continued ;06/23/16  11:50
 ;;1.0;PCE PATIENT CARE ENCOUNTER;**216**;Aug 12, 1996;Build 11
 ;
 ;
 ; Reference to ^DIA(9000010.11 supported by ICR #2602
 ; Reference to NPI^XUSNPI supported by ICR #4532
 ;
 ;
DEM(PXPATARR,DFN) ; get patient demographics data
 ;
 N PXI,VADM
 ;
 S PXPATARR("DFN")=DFN
 S PXPATARR("ICN")=""
 I '$$IFLOCAL^MPIF001(DFN) S PXPATARR("ICN")=$$GETICN^MPIF001(DFN)
 I +PXPATARR("ICN")=-1 S PXPATARR("ICN")=""
 ;
 D DEM^VADPT
 S PXPATARR("NAME")=VADM(1)
 S PXPATARR("DOB")=+$P($P(VADM(3),U),".")
 S PXPATARR("SEX")=$P(VADM(5),U)
 S PXPATARR("DATE OF DEATH")=$P($P(VADM(6),U),".")
 ;
 S PXI=0
 F  S PXI=$O(VADM(11,PXI)) Q:'PXI  D
 . S PXPATARR("ETHNICITY",PXI,0)=$$PTR2CODE^DGUTL4(+VADM(11,PXI),2,2)_U_$P(VADM(11,PXI),U,2)  ;icr 3799
 ;
 S PXI=0
 F  S PXI=$O(VADM(12,PXI)) Q:'PXI  D
 . S PXPATARR("RACE",PXI,0)=$$PTR2CODE^DGUTL4(+VADM(12,PXI),1,2)_U_$P(VADM(12,PXI),U,2)  ;icr 3799
 ;
 D DEMADD(.PXPATARR,.DFN)
 D DEMSUP(.PXPATARR,.DFN)
 D DEMOTHER(.PXPATARR,.DFN)
 D DEMFAC(.PXPATARR,.DFN)
 ;
 D KVA^VADPT
 Q
 ;
DEMADD(PXPATARR,DFN) ;
 ;
 N PXI,VAPA
 ;
 S VAPA("P")="" ;permanent address
 D ADD^VADPT
 S PXPATARR("ADDRESS")=""
 F PXI=1:1:4 S PXPATARR("ADDRESS")=PXPATARR("ADDRESS")_VAPA(PXI)_U
 S PXPATARR("ADDRESS")=PXPATARR("ADDRESS")_$P(VAPA(5),U,2)_U_$P(VAPA(11),U,2)
 S PXPATARR("PHONE")=VAPA(8)
 ;
 D KVA^VADPT
 Q
 ;
DEMSUP(PXPATARR,DFN) ;
 ;
 N PXA,PXCNT,PXI,PXTYPE,PXX,VAOA
 ;
 S PXCNT=0
 F PXA="",1 D
 . K VAOA
 . I PXA S VAOA("A")=PXA
 . D OAD^VADPT
 . I $G(VAOA(9))="" Q
 . S PXCNT=PXCNT+1
 . S PXTYPE=$S(PXA=1:"ECON",1:"NOK")
 . S PXX=""
 . F PXI=1:1:4 S PXX=PXX_VAOA(PXI)_U
 . S PXX=PXX_$P(VAOA(5),U,2)_U_$P(VAOA(11),U,2)
 . S PXPATARR("SUPPORT",PXCNT,0)=PXTYPE_U_VAOA(9)_U_VAOA(10)_U_VAOA(8)_U_PXX
 ;
 D KVA^VADPT
 Q
 ;
DEMOTHER(PXPATARR,DFN) ;
 N VAPD
 D OPD^VADPT
 S PXPATARR("PLACE OF BIRTH")=VAPD(1)_U_$P(VAPD(2),U,2)
 S PXPATARR("MOTHER MAIDEN NAME")=VAPD(5)
 ;
 D KVA^VADPT
 Q
 ;
DEMFAC(PXPATARR,DFN) ;
 ;
 N PXAGENCY,PXCNT,PXEARLIESTDT,PXERR,PXFAC,PXFACIEN,PXI,PXTF,PXTFL,PXTRDATE
 ;
 S PXEARLIESTDT=($E(DT,1,3)-1)_$E(DT,4,7)  ; 1 year ago
 S PXCNT=0
 S PXERR=1
 I $G(PXPATARR("ICN"))>0 S PXERR=$$QUERYTF^VAFCTFU1($P(PXPATARR("ICN"),"V"),"PXTFL","")  ;icr 2990
 I $P(PXERR,U)=1 K PXTFL
 S PXI=0
 F  S PXI=$O(PXTFL(PXI)) Q:'PXI  D
 . S PXTF=$G(PXTFL(PXI))
 . S PXFACIEN=$P(PXTF,U,1)
 . I 'PXFACIEN Q
 . S PXAGENCY=$$GET1^DIQ(4,PXFACIEN_",",95,"I")  ;icr 10090
 . I PXAGENCY'="V" Q
 . S PXTRDATE=$P(PXTF,U,2)
 . I PXTRDATE<PXEARLIESTDT Q  ;only inlcude last 1 year
 . S PXFAC=$$NS^XUAF4(PXFACIEN)
 . I $P(PXFAC,U,2)="" Q
 . I +$P(PXFAC,U,2)?1(1"776",1"200") Q  ;non-VA
 . S PXCNT=PXCNT+1
 . S PXPATARR("FACILITY",PXCNT,0)=PXFAC
 ;
 Q
 ;
VIMM(PXVIMMARR,PXVIMM,PXFILE,PXDATE) ; get immunization data
 ;
 N DFN,PXFLD,PXNPI
 ;
 S PXDATE=$G(PXDATE)
 I PXFILE=9000010.11,PXDATE'>0 D VIMM^PXPXRM(PXVIMM,.PXVIMMARR)
 I PXFILE=9000010.11,PXDATE>0 D VIMMED(.PXVIMMARR,PXVIMM,PXDATE)
 I PXFILE=9000080.11 D VIMMDEL(.PXVIMMARR,PXVIMM,PXDATE)
 K PXVIMMARR("VALUE")
 K PXVIMMARR("REMARKS")
 S PXVIMMARR("ID")=PXVIMM_$S(PXFILE=9000080.11:"D",1:"")
 S DFN=$S(PXFILE=9000010.11:$P($G(^AUPNVIMM(PXVIMM,0)),U,2),1:$P($G(^AUPDVIMM(PXVIMM,0)),U,2))
 S PXVIMMARR("PATIENT")=DFN_U_$P($G(^DPT(+DFN,0)),U,1)
 S PXVIMMARR("ADMINISTERED DATE TIME")=$G(PXVIMMARR("EVENT DATE TIME"))
 I PXVIMMARR("ADMINISTERED DATE TIME")="" D
 . S PXVIMMARR("ADMINISTERED DATE TIME")=$P($G(^AUPNVSIT(+$G(PXVIMMARR("VISIT")),0)),U,1)
 K PXVIMMARR("EVENT DATE TIME")
 I PXVIMMARR("SERIES")'="" D
 . S PXVIMMARR("SERIES")=$$EXTERNAL^DILFD(9000010.11,.04,"",PXVIMMARR("SERIES"))
 I PXVIMMARR("REACTION")'="" D
 . S PXVIMMARR("REACTION")=$$EXTERNAL^DILFD(9000010.11,.06,"",PXVIMMARR("REACTION"))
 I PXVIMMARR("MANUFACTURER") D
 . S $P(PXVIMMARR("MANUFACTURER"),U,3)=$P($G(^AUTTIMAN(+PXVIMMARR("MANUFACTURER"),0)),U,2)
 F PXFLD="ORDERING PROVIDER","ENCOUNTER PROVIDER","DOCUMENTER" D
 . I PXVIMMARR(PXFLD) D
 . . S PXNPI=$P($$NPI^XUSNPI("Individual_ID",+PXVIMMARR(PXFLD),DT),U,1) ;ICR 4532
 . . I PXNPI'=0,PXNPI'=-1,PXNPI'="" S $P(PXVIMMARR(PXFLD),U,3)=$P(PXNPI,U,1)
 . . S $P(PXVIMMARR(PXFLD),U,4)=$$VPID^XUPS(+PXVIMMARR(PXFLD)) ; 4574
 S PXVIMMARR("COMPLETION STATUS")="COMPLETE"
 S PXVIMMARR("FACILITY")=$P($G(PXVIMMARR("FACILITY")),U,2,3)
 Q
 ;
VIMMDEL(PXVIMMARR,PXVIMM,PXDATE) ;pull record from V Immunization file
 ;
 N PXEDITS,PXFLDLOC,PXFLDNUM,PXNODE,PXPIECE,PXTMP
 ;
 I '$G(PXVIMM) Q
 I '$D(^AUPDVIMM(PXVIMM)) Q
 S PXDATE=$G(PXDATE)
 ;
 K ^TMP("PXVIMM",$J)
 M ^TMP("PXVIMM",$J,PXVIMM)=^AUPDVIMM(PXVIMM)
 ;
 I PXDATE D
 . D GETEDITS(.PXEDITS,PXVIMM,PXDATE)
 . ; make sure the record in the audits is referring to the same record in the deleted file
 . S PXTMP=$G(^TMP("PXVIMM",$J,PXVIMM,0))
 . I $P($G(PXEDITS(.01)),U,1)'=$P(PXTMP,U,1) Q
 . I $P($G(PXEDITS(.02)),U,1)'=$P(PXTMP,U,2) Q
 . I $P($G(PXEDITS(.03)),U,1)'=$P(PXTMP,U,3) Q
 . ;
 . S PXFLDNUM=0
 . F  S PXFLDNUM=$O(PXEDITS(PXFLDNUM)) Q:PXFLDNUM'>0  D
 . . S PXFLDLOC=$$GET1^DID(9000010.11,PXFLDNUM,"","GLOBAL SUBSCRIPT LOCATION")
 . . S PXNODE=$P(PXFLDLOC,";",1)
 . . S PXPIECE=+$P(PXFLDLOC,";",2)
 . . I (PXNODE="")!('PXPIECE) Q
 . . S $P(^TMP("PXVIMM",$J,PXVIMM,PXNODE),U,PXPIECE)=$P(PXEDITS(PXFLDNUM),U,1)
 ;
 D VIMM2^PXPXRM(PXVIMM,.PXVIMMARR)
 ;
 K ^TMP("PXVIMM",$J)
 ;
 Q
 ;
VIMMED(PXVIMMARR,PXVIMM,PXDATE) ;pull editted record it existed on PXDATE
 ;
 N PXEDITS,PXFLDLOC,PXFLDNUM,PXNODE,PXPIECE
 ;
 I '$G(PXVIMM) Q
 I '$D(^AUPNVIMM(PXVIMM)) Q
 ;
 K ^TMP("PXVIMM",$J)
 M ^TMP("PXVIMM",$J,PXVIMM)=^AUPNVIMM(PXVIMM)
 ;
 D GETEDITS(.PXEDITS,PXVIMM,PXDATE)
 S PXFLDNUM=0
 F  S PXFLDNUM=$O(PXEDITS(PXFLDNUM)) Q:PXFLDNUM'>0  D
 . S PXFLDLOC=$$GET1^DID(9000010.11,PXFLDNUM,"","GLOBAL SUBSCRIPT LOCATION")
 . S PXNODE=$P(PXFLDLOC,";",1)
 . S PXPIECE=+$P(PXFLDLOC,";",2)
 . I (PXNODE="")!('PXPIECE) Q
 . S $P(^TMP("PXVIMM",$J,PXVIMM,PXNODE),U,PXPIECE)=$P(PXEDITS(PXFLDNUM),U,1)
 ;
 D VIMM2^PXPXRM(PXVIMM,.PXVIMMARR)
 ;
 K ^TMP("PXVIMM",$J)
 ;
 Q
 ;
GETEDITS(PXBEFORE,PXVIMM,PXDATE) ;get fields that changed since PXDATE
 ;
 N PXADDDT,PXAUDIEN,PXAUDTMP,PXEDITDT,PXEXTVAL,PXFILE,PXFLDNUM,PXINTVAL,PXLASTEDIT
 ;
 S PXFILE=9000010.11
 S PXADDDT=0
 S PXAUDIEN=0
 F  S PXAUDIEN=$O(^DIA(PXFILE,"B",PXVIMM,PXAUDIEN)) Q:('PXAUDIEN)!(PXADDDT>PXDATE)  D  ; ICR 2602
 . S PXAUDTMP=$G(^DIA(PXFILE,PXAUDIEN,0))  ; ICR 2602
 . S PXEDITDT=$P(PXAUDTMP,U,2)
 . I PXEDITDT<PXDATE Q
 . S PXFLDNUM=$P(PXAUDTMP,U,3)
 . I PXFLDNUM'>0 Q
 . I $P(PXAUDTMP,U,5)="A" S PXADDDT=PXEDITDT
 . S PXLASTEDIT=$P($G(PXBEFORE(PXFLDNUM)),U,2)
 . I PXLASTEDIT,PXLASTEDIT<PXEDITDT Q  ;if it was editted multiple times, get the 1st edit
 . S PXINTVAL=$P($G(^DIA(PXFILE,PXAUDIEN,2.1)),U,1)  ; ICR 2602
 . S PXEXTVAL=$G(^DIA(PXFILE,PXAUDIEN,2))  ; ICR 2602
 . I PXINTVAL="",PXEXTVAL'="" D  I PXINTVAL=U Q
 . . D CHK^DIE(9000010.11,PXFLDNUM,"",PXEXTVAL,.PXINTVAL)
 . S PXBEFORE(PXFLDNUM)=PXINTVAL_U_PXEDITDT
 ;
 I PXADDDT>PXDATE K PXBEFORE Q
 ;
 Q