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

BQIPTPR.m

Go to the documentation of this file.
BQIPTPR ;PRXM/HC/BWF-Patient Provider Utilities ; 15 Nov 2005  3:17 PM
 ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
 ;
 ; This is a utility program containing special function calls
 ; needed for provider data.
 Q
 ;
PTPROV(DATA,DFN,ALL) ;EP -- BQI PATIENT PROVIDERS
 ; BQI PATIENT PROVIDERS
 ; Input
 ;  DFN  - Patient IEN
 ;  DATA - Passed by reference
 ;  ALL  - 1 if all provider categories are wanted
 ; Output
 ;  DATA - Set in this routine
 ;  
 ; Variables
 ;  BDPIEN     - Ien from ^BDPRECN
 ;  LCPROV     - Last Current Provider
 ;  
 N BDPIEN,UID,BQII,X,PROVLST,LCPROV,LCPROVNM,PROVCAT,PROV,BDPINST,BDPCAT
 N LSTUP,LSTUPU,BQPRV
 NEW LCPRVI
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIPTPR",UID))
 K @DATA
 S ALL=$G(ALL,0)
 ;
 S BQII=0
 ;
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTPR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 D HDR
 ;
 ; Drive through all entries in the BDPRECN global for each patient.
 ; BDPRECN is part of the DSPM package
 ;
 ; Check to see if DSPM is being used. If DSPM is not being used, get roles from
 ; file/fields listed in the DSPM provider categories.
 S BDPINST=$$VERSION^XPDUTL("BDP")
 I BDPINST="" D GETPROVS(DFN,.BQII) Q
 ;
 ; Loop through DSPM provider categories (if DSPM is in use).
 K BQPRV
 S BDPCAT=0
 F  S BDPCAT=$O(^BDPRECN("AA",DFN,BDPCAT)) Q:'BDPCAT  D
 .S BDPIEN=0
 .F  S BDPIEN=$O(^BDPRECN("AA",DFN,BDPCAT,BDPIEN)) Q:'BDPIEN  D
 ..S LCPROV=$$GET1^DIQ(90360.1,BDPIEN,.03,"I")      ;Last Current Provider
 ..I LCPROV="" Q
 ..S LCPROVNM=$$GET1^DIQ(90360.1,BDPIEN,.03,"E")
 ..S LCPRVI=$$GET1^DIQ(90360.1,BDPIEN,.03,"I")
 ..S PROVCAT=$$GET1^DIQ(90360.3,BDPCAT,.01,"E")     ;Prov Category Name
 ..S SRCAT=$S(PROVCAT="DESIGNATED PRIMARY PROVIDER":"aDESIGNATED PRIMARY PROVIDER",1:PROVCAT)
 ..I ALL S BQPRV(BDPCAT)=BDPIEN
 ..S PROVLST(DFN,SRCAT,LCPROV)=PROVCAT_U_LCPRVI_$C(28)_LCPROVNM_U_U
 ..D PROVST(SRCAT,LCPROV)
 ..S LSTUP=$$GET1^DIQ(90360.1,BDPIEN,.05,"I") I LSTUP S LSTUP=$$FMTE^BQIUL1(LSTUP)
 ..S LSTUPU=$$GET1^DIQ(90360.1,BDPIEN,.04,"E")
 ..S $P(PROVLST(DFN,SRCAT,LCPROV),U,6,7)=LSTUP_U_LSTUPU
 I ALL D
 . NEW N,CAT
 . S N=0
 . F  S N=$O(^BDPTCAT(N)) Q:'N  I '$D(BQPRV(N)) S CAT=$P(^BDPTCAT(N,0),U,1),PROVLST(DFN,$S(CAT="DESIGNATED PRIMARY PROVIDER":"a"_CAT,1:CAT),"~")=CAT_U_U_U_U_U_U
 D LOOP(.BQII)
 Q
 ;
PROVST(SRCAT,LCPROV) ;EP
 ;Loop through visits, and find the most recent visit that is associated with the current provider.
 N LSTVST,FOUND,VSTIEN,VPRVIEN,VSPROV,EXTVST,NXTVST,CLINIC,PROV,STATUS
 S LSTVST=0,FOUND=0
 F  S LSTVST=$O(^AUPNVSIT("AA",DFN,LSTVST)) Q:'LSTVST  D  Q:FOUND
 .S VSTIEN=0
 .F  S VSTIEN=$O(^AUPNVSIT("AA",DFN,LSTVST,VSTIEN)) Q:VSTIEN=""!(FOUND)  D
 ..I $$GET1^DIQ(9000010,VSTIEN,.11,"I")=1 Q
 ..S VPRVIEN=0
 ..F  S VPRVIEN=$O(^AUPNVPRV("AD",VSTIEN,VPRVIEN)) Q:'VPRVIEN!(FOUND)  D
 ...S VSPROV=$$GET1^DIQ(9000010.06,VPRVIEN,.01,"I")
 ...I VSPROV=LCPROV D  Q
 ....S EXTVST=9999999-$P(LSTVST,".")
 ....S EXTVST=$$FMTE^BQIUL1(EXTVST)
 ....S $P(PROVLST(DFN,SRCAT,LCPROV),U,3)=$$FMTE^BQIUL1(EXTVST),FOUND=1
 ....S $P(PROVLST(DFN,SRCAT,LCPROV),U,5)=VSTIEN
 ;
 ; Loop through patient appts and find out if prov is primary for appt clinic.
 ; S NXTVST=DT,FOUND=0
 ; Start date for appointment search should be 'NOW' to be consistent with PEND^BSDU
 S NXTVST=$$NOW^XLFDT,FOUND=0
 F  S NXTVST=$O(^DPT(DFN,"S",NXTVST)) Q:NXTVST=""!(FOUND)  D
 .S CLINIC=$$GET1^DIQ(2.98,NXTVST_","_DFN_",",.01,"I")
 .S STATUS=$$GET1^DIQ(2.98,NXTVST_","_DFN_",",.02,"I")
 .I CLINIC="" Q
 .I STATUS="C"!(STATUS="PC") Q
 .N TPRI
 .S TPRI=0
 .F  S TPRI=$O(^SC(CLINIC,"PR",TPRI)) Q:'TPRI!(FOUND)  D
 ..I +$G(^SC(CLINIC,"PR",TPRI,0))=LCPROV S $P(PROVLST(DFN,SRCAT,LCPROV),U,4)=$$FMTE^BQIUL1(NXTVST),FOUND=1
 Q
 ;
LOOP(BQII) ;EP
 NEW PCAT,LOOP
 S PCAT=$O(PROVLST(DFN,"Z"))
 I PCAT'="" D
 . S LOOP=""
 . F  S LOOP=$O(PROVLST(DFN,PCAT,LOOP)) Q:LOOP=""  D
 .. S BQII=BQII+1,@DATA@(BQII)=PROVLST(DFN,PCAT,LOOP)_$C(30)
 .. K PROVLST(DFN,PCAT)
 S PCAT=""
 F  S PCAT=$O(PROVLST(DFN,PCAT)) Q:PCAT=""  D
 . S LOOP=""
 . F  S LOOP=$O(PROVLST(DFN,PCAT,LOOP)) Q:LOOP=""  D
 .. S BQII=BQII+1,@DATA@(BQII)=PROVLST(DFN,PCAT,LOOP)_$C(30)
 S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
GETPROVS(DFN,BQII) ;EP
 N DPCP,DPCPI,MHPROV,MHPROVI,SSPROV,SSPROVI,CDPROV,CDPROVI
 NEW WHPROV,WHPROVI,TEXT,TIEN
 S DPCP=$$GET1^DIQ(9000001,DFN,.14,"E") I DPCP'="" D
 . S DPCPI=$$GET1^DIQ(9000001,DFN,.14,"I")
 . S TEXT="DESIGNATED PRIMARY PROVIDER",SRCAT="a"_TEXT
 . S TIEN=$$FIND1^DIC(90360.3,,"X",TEXT)
 . S PROVLST(DFN,SRCAT,TIEN)=TEXT_U_DPCPI_$C(28)_DPCP_U_U
 . D PROVST(SRCAT,TIEN)
 ;
 S MHPROV=$$GET1^DIQ(9002011.55,DFN,.02,"E") I MHPROV'="" D
 . S MHPROVI=$$GET1^DIQ(9002011.55,DFN,.02,"I")
 . S TEXT="MENTAL HEALTH",SRCAT=TEXT
 . S TIEN=$$FIND1^DIC(90360.3,,"X",TEXT)
 . S PROVLST(DFN,SRCAT,TIEN)=TEXT_U_MHPROVI_$C(28)_MHPROV_U_U
 . D PROVST(SRCAT,TIEN)
 ;
 S SSPROV=$$GET1^DIQ(9002011.55,DFN,.03,"E") I SSPROV'="" D
 . S SSPROVI=$$GET1^DIQ(9002011.55,DFN,.03,"I")
 . S TEXT="SOCIAL SERVICES",SRCAT=TEXT
 . S TIEN=$$FIND1^DIC(90360.3,,"X",TEXT)
 . S PROVLST(DFN,SSPROVI,TIEN)=TEXT_U_SSPROVI_$C(28)_SSPROV_U_U
 . D PROVST(SRCAT,TIEN)
 ;
 S CDPROV=$$GET1^DIQ(9002011.55,DFN,.04,"E") I CDPROV'="" D
 . S CDPROVI=$$GET1^DIQ(9002011.55,DFN,.04,"I")
 . S TEXT="CHEMICAL DEPENDENCY",SRCAT=TEXT
 . S TIEN=$$FIND1^DIC(90360.3,,"X",TEXT)
 . S PROVLST(DFN,CDPROVI,TIEN)=TEXT_U_CDPROVI_$C(28)_CDPROV_U_U
 . D PROVST(SRCAT,TIEN)
 ;
 S WHPROV=$$GET1^DIQ(9002086,DFN,.1,"E") I WHPROV'="" D
 . S WHPROVI=$$GET1^DIQ(9002086,DFN,.1,"I")
 . S TEXT="WOMENS HEALTH",SRCAT=TEXT
 . S TIEN=$$FIND1^DIC(90360.3,,"X",TEXT)
 . S PROVLST(DFN,SRCAT,TIEN)=TEXT_U_WHPROVI_$C(28)_WHPROV_U_U
 . D PROVST(SRCAT,TIEN)
 ;
 D LOOP(.BQII)
 Q
 ;
HDR ;
 ;S @DATA@(BQII)="T00045BQIPROLE^T00055BQIPROV^D00020BQILVDT^D00020BQINVDT^I00010VIEN"_$C(30)
 S @DATA@(BQII)="T00045BQIPROLE^T00055BQIPROV^D00020BQILVDT^D00020BQINVDT^I00010VIEN^D00020BQIUPDT^T00035BQIUPDUS"_$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