BQIPTVS ;PRXM/HC/BWF-Patient Visit Utilities ; 15 Nov 2005 3:17 PM
;;2.3;ICARE MANAGEMENT SYSTEM;**1**;Apr 18, 2012;Build 43
;
;
; This is a utility program containing special function calls
; needed for patient visit data.
Q
;
PNLVST(DATA,DFN,DRANGE) ; EP -- BQI PATIENT RECENT VISITS
;
; Description:
; Function used to gather visit information for a patient for a relative date range.
; Gathers provider name ICD narrative, POV narrative, and clinic.
; This function will gather 1.) A list of visit related information based on a date range
; 2.) If no date is provided, all visits will be reported.
;
; Use date range to drive through visits.
;
; Input
; DFN (Required) - Patient IEN
; DRANGE - Date to pull past appointments from (to the present).
;
; Output
; Global array containing information for patients.
; ^TMP("BQIPTVS",UID,BQII)=VISIT DATE_^_CLINIC_^_PROVIDER NAME_^_ICD NARRATIVE_^_POV NARRATIVE
;
; Variables
; DFN - Patient Identifier
; VSTDT - Visit Date
; VSTIEN - Visit IEN
;
N VSTIEN,VSTDT,RDRANGE,BQII,UID,X
;
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQIPTVS",UID))
K @DATA
S BQII=0
;
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTVS D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
;
D HDR
;
S DRANGE=$$DATE^BQIUL1($G(DRANGE))
S RDRANGE=9999999-DRANGE+1 ; Add one day to include visits on that day.
; ; Otherwise, they will not be included.
S VSTDT=""
F S VSTDT=$O(^AUPNVSIT("AA",DFN,VSTDT)) Q:(VSTDT="")!(VSTDT>RDRANGE) D
.S VSTIEN=0
.F S VSTIEN=$O(^AUPNVSIT("AA",DFN,VSTDT,VSTIEN)) Q:VSTIEN="" D
..D VSTDATA(VSTIEN,.BQII)
;
; DROP DOWN TO DONE
;
DONE ;
S BQII=BQII+1,@DATA@(BQII)=$C(31)
Q
;
VSTDATA(VSTIEN,BQII) ;EP
;Gather visit date, visit provider, clinic, ICD narrative, POV code narrative,
; and provider narrative for each patient and set into global array ^TMP("BQIPTVS",UID).
;
; Input
; VSTIEN - Visit IEN
; BQII - Increment variable for output.
;
; Output
; Global array containing information for patients.
; ^TMP("BQIPTVS",UID,BQII)=VISIT IEN^VISIT DATE_^_CLINIC_^_PROVIDER NAME_^_ICD NARRATIVE_^_POV NARRATIVE
;
; Variables
; VSTDT - Visit Date
; VPRVIEN - Provider IEN(s) for last visit
; VPOVIEN - V POV file IEN
;
N CLINIC,VPRVIEN,VSTDT,PRIMPROV,ICDNAR,ICDNSTR,POVNAR,POVNSTR,VPOVIEN,CLN,CSTCD
S VSTDT=$$GET1^DIQ(9000010,VSTIEN,.01,"I")
; If visit has been deleted, don't include
I $$GET1^DIQ(9000010,VSTIEN_",",.11,"I")=1 Q
S CLN=$$GET1^DIQ(9000010,VSTIEN,.08,"I"),CSTCD=""
I CLN'="" S CSTCD=$$GET1^DIQ(40.7,CLN_",",1,"E")
S CLINIC=$$GET1^DIQ(9000010,VSTIEN,.08,"E")_" "_CSTCD
;
; Loop through providers. Only primary providers will be returned.
S VPRVIEN=0,PRIMPROV=""
F S VPRVIEN=$O(^AUPNVPRV("AD",VSTIEN,VPRVIEN)) Q:VPRVIEN="" D
.I $$GET1^DIQ(9000010.06,VPRVIEN,.04,"I")'="P" Q
.S PRIMPROV=$$GET1^DIQ(9000010.06,VPRVIEN,.01,"E")
S BQII=BQII+1,@DATA@(BQII)=VSTIEN_U_$$FMTE^BQIUL1(VSTDT)_U_CLINIC_U_PRIMPROV
;
; Gather all ICD narratives, separated by a LF/CR.
S VPOVIEN=0,ICDNSTR=""
F S VPOVIEN=$O(^AUPNVPOV("AD",VSTIEN,VPOVIEN)) Q:VPOVIEN="" D
.S ICDNAR=$$GET1^DIQ(9000010.07,VPOVIEN,".019","E")
.S ICDNST=$$GET1^DIQ(9000010.07,VPOVIEN,".01","E")
.I ICDNAR'="" S ICDNSTR=ICDNSTR_ICDNST_" "_ICDNAR_$C(13)_$C(10)
;
; Gather all POV narratives, separated by a LF/CR.
S VPOVIEN=0,POVNSTR=""
F S VPOVIEN=$O(^AUPNVPOV("AD",VSTIEN,VPOVIEN)) Q:VPOVIEN="" D
.S POVNAR=$$GET1^DIQ(9000010.07,VPOVIEN,".04","E")
.I POVNAR'="" S POVNSTR=$S(POVNSTR'="":POVNSTR_$C(13)_$C(10)_POVNAR,1:POVNAR)
;
S @DATA@(BQII)=@DATA@(BQII)_U_ICDNSTR_U_POVNSTR_$C(30)
Q
;
HDR ;
S @DATA@(BQII)="I00010VST_IEN^D00015VST_DT^T00050VST_CLIN^T00050VST_PROV^T01000VST_ICD^T01000VST_POV"_$C(30)
Q
;
ERR ;
D ^%ZTER
NEW Y,ERRDTM
S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
S BMXSEC="Recording that an error occurred at "_ERRDTM
I $D(BQII),$D(DATA) S BQII=BQII+1,@DATA@(BQII)=$C(31)
Q
BQIPTVS ;PRXM/HC/BWF-Patient Visit Utilities ; 15 Nov 2005 3:17 PM
+1 ;;2.3;ICARE MANAGEMENT SYSTEM;**1**;Apr 18, 2012;Build 43
+2 ;
+3 ;
+4 ; This is a utility program containing special function calls
+5 ; needed for patient visit data.
+6 QUIT
+7 ;
PNLVST(DATA,DFN,DRANGE) ; EP -- BQI PATIENT RECENT VISITS
+1 ;
+2 ; Description:
+3 ; Function used to gather visit information for a patient for a relative date range.
+4 ; Gathers provider name ICD narrative, POV narrative, and clinic.
+5 ; This function will gather 1.) A list of visit related information based on a date range
+6 ; 2.) If no date is provided, all visits will be reported.
+7 ;
+8 ; Use date range to drive through visits.
+9 ;
+10 ; Input
+11 ; DFN (Required) - Patient IEN
+12 ; DRANGE - Date to pull past appointments from (to the present).
+13 ;
+14 ; Output
+15 ; Global array containing information for patients.
+16 ; ^TMP("BQIPTVS",UID,BQII)=VISIT DATE_^_CLINIC_^_PROVIDER NAME_^_ICD NARRATIVE_^_POV NARRATIVE
+17 ;
+18 ; Variables
+19 ; DFN - Patient Identifier
+20 ; VSTDT - Visit Date
+21 ; VSTIEN - Visit IEN
+22 ;
+23 NEW VSTIEN,VSTDT,RDRANGE,BQII,UID,X
+24 ;
+25 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+26 SET DATA=$NAME(^TMP("BQIPTVS",UID))
+27 KILL @DATA
+28 SET BQII=0
+29 ;
+30 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQIPTVS D UNWIND^%ZTER"
+31 ;
+32 DO HDR
+33 ;
+34 SET DRANGE=$$DATE^BQIUL1($GET(DRANGE))
+35 ; Add one day to include visits on that day.
SET RDRANGE=9999999-DRANGE+1
+36 ; ; Otherwise, they will not be included.
+37 SET VSTDT=""
+38 FOR
SET VSTDT=$ORDER(^AUPNVSIT("AA",DFN,VSTDT))
IF (VSTDT="")!(VSTDT>RDRANGE)
QUIT
Begin DoDot:1
+39 SET VSTIEN=0
+40 FOR
SET VSTIEN=$ORDER(^AUPNVSIT("AA",DFN,VSTDT,VSTIEN))
IF VSTIEN=""
QUIT
Begin DoDot:2
+41 DO VSTDATA(VSTIEN,.BQII)
End DoDot:2
End DoDot:1
+42 ;
+43 ; DROP DOWN TO DONE
+44 ;
DONE ;
+1 SET BQII=BQII+1
SET @DATA@(BQII)=$CHAR(31)
+2 QUIT
+3 ;
VSTDATA(VSTIEN,BQII) ;EP
+1 ;Gather visit date, visit provider, clinic, ICD narrative, POV code narrative,
+2 ; and provider narrative for each patient and set into global array ^TMP("BQIPTVS",UID).
+3 ;
+4 ; Input
+5 ; VSTIEN - Visit IEN
+6 ; BQII - Increment variable for output.
+7 ;
+8 ; Output
+9 ; Global array containing information for patients.
+10 ; ^TMP("BQIPTVS",UID,BQII)=VISIT IEN^VISIT DATE_^_CLINIC_^_PROVIDER NAME_^_ICD NARRATIVE_^_POV NARRATIVE
+11 ;
+12 ; Variables
+13 ; VSTDT - Visit Date
+14 ; VPRVIEN - Provider IEN(s) for last visit
+15 ; VPOVIEN - V POV file IEN
+16 ;
+17 NEW CLINIC,VPRVIEN,VSTDT,PRIMPROV,ICDNAR,ICDNSTR,POVNAR,POVNSTR,VPOVIEN,CLN,CSTCD
+18 SET VSTDT=$$GET1^DIQ(9000010,VSTIEN,.01,"I")
+19 ; If visit has been deleted, don't include
+20 IF $$GET1^DIQ(9000010,VSTIEN_",",.11,"I")=1
QUIT
+21 SET CLN=$$GET1^DIQ(9000010,VSTIEN,.08,"I")
SET CSTCD=""
+22 IF CLN'=""
SET CSTCD=$$GET1^DIQ(40.7,CLN_",",1,"E")
+23 SET CLINIC=$$GET1^DIQ(9000010,VSTIEN,.08,"E")_" "_CSTCD
+24 ;
+25 ; Loop through providers. Only primary providers will be returned.
+26 SET VPRVIEN=0
SET PRIMPROV=""
+27 FOR
SET VPRVIEN=$ORDER(^AUPNVPRV("AD",VSTIEN,VPRVIEN))
IF VPRVIEN=""
QUIT
Begin DoDot:1
+28 IF $$GET1^DIQ(9000010.06,VPRVIEN,.04,"I")'="P"
QUIT
+29 SET PRIMPROV=$$GET1^DIQ(9000010.06,VPRVIEN,.01,"E")
End DoDot:1
+30 SET BQII=BQII+1
SET @DATA@(BQII)=VSTIEN_U_$$FMTE^BQIUL1(VSTDT)_U_CLINIC_U_PRIMPROV
+31 ;
+32 ; Gather all ICD narratives, separated by a LF/CR.
+33 SET VPOVIEN=0
SET ICDNSTR=""
+34 FOR
SET VPOVIEN=$ORDER(^AUPNVPOV("AD",VSTIEN,VPOVIEN))
IF VPOVIEN=""
QUIT
Begin DoDot:1
+35 SET ICDNAR=$$GET1^DIQ(9000010.07,VPOVIEN,".019","E")
+36 SET ICDNST=$$GET1^DIQ(9000010.07,VPOVIEN,".01","E")
+37 IF ICDNAR'=""
SET ICDNSTR=ICDNSTR_ICDNST_" "_ICDNAR_$CHAR(13)_$CHAR(10)
End DoDot:1
+38 ;
+39 ; Gather all POV narratives, separated by a LF/CR.
+40 SET VPOVIEN=0
SET POVNSTR=""
+41 FOR
SET VPOVIEN=$ORDER(^AUPNVPOV("AD",VSTIEN,VPOVIEN))
IF VPOVIEN=""
QUIT
Begin DoDot:1
+42 SET POVNAR=$$GET1^DIQ(9000010.07,VPOVIEN,".04","E")
+43 IF POVNAR'=""
SET POVNSTR=$SELECT(POVNSTR'="":POVNSTR_$CHAR(13)_$CHAR(10)_POVNAR,1:POVNAR)
End DoDot:1
+44 ;
+45 SET @DATA@(BQII)=@DATA@(BQII)_U_ICDNSTR_U_POVNSTR_$CHAR(30)
+46 QUIT
+47 ;
HDR ;
+1 SET @DATA@(BQII)="I00010VST_IEN^D00015VST_DT^T00050VST_CLIN^T00050VST_PROV^T01000VST_ICD^T01000VST_POV"_$CHAR(30)
+2 QUIT
+3 ;
ERR ;
+1 DO ^%ZTER
+2 NEW Y,ERRDTM
+3 SET Y=$$NOW^XLFDT()
XECUTE ^DD("DD")
SET ERRDTM=Y
+4 SET BMXSEC="Recording that an error occurred at "_ERRDTM
+5 IF $DATA(BQII)
IF $DATA(DATA)
SET BQII=BQII+1
SET @DATA@(BQII)=$CHAR(31)
+6 QUIT