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

BTPWPCHT.m

Go to the documentation of this file.
BTPWPCHT ;VNGT/HS/ALA-Chart Review Creation ; 20 Apr 2010  9:33 AM
 ;;1.1;CARE MANAGEMENT EVENT TRACKING;**2**;Apr 01, 2015;Build 17
 ;
 ;
EN(NOT,DFN,MORE) ; EP - Create a chart review visit
 ; Input
 ;   NOT = Notification Type
 ;
 NEW APCDAUTO,NCLN,CLN,CNAM,APCDCAT,APCDDATE,CLIN,VTYP
 S NCLN=$P(^BTPW(90622,NOT,0),U,4),MORE=$G(MORE,"")
 S CLN=""
 F  S CLN=$O(^DIC(40.7,"C",NCLN,CLN)) Q:CLN=""  S CLIN=CLN
 S CNAM=$P(^DIC(40.7,CLIN,0),U,1)
 ;
 S APCDHL=$S(NCLN=51:$P(^BQICARE(DUZ,0),U,20),NCLN=53:$P(^BQICARE(DUZ,0),U,19),1:$P(^BQICARE(DUZ,0),U,18))
 D DEF(CLIN,CNAM,DFN,$G(APCDLOC),$G(APCDHL))
 ;
 ;  Create visit and then update other Vfiles
 D EN^APCDALV
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S VISIT=$G(APCDALVR("APCDVSIT"))
 I $G(APCDALVR("APCDAFLG"))=2!($G(APCDALVR("APCDAFLG"))=1) S VISIT=-1
 Q VISIT
 ;
ADD(APCDPAT,APCDVSIT,APCDALVR) ; EP 
 ; Create V files
 D EN^APCDALVR
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S RESULT=1
 I $G(APCDALVR("APCDAFLG"))=2 S RESULT=-1
 ; Cleanup
 K APCDALVR
 Q RESULT
 ;
DEF(CLN,CNAM,DFN,APCDLOC,APCDHL) ; Set variables
 S APCDALVR("APCDCLN")=CLN
 S APCDALVR("APCDHL")=APCDHL
 S APCDDATE=$$NOW^XLFDT(),APCDALVR("APCDDATE")=APCDDATE
 ; Get default Visit Type
 S VTYP=$P($G(^APCDSITE(DUZ(2),0)),U,11) I VTYP="" S VTYP="I"
 S APCDALVR("APCDTYPE")=VTYP
 S APCDCAT=$S(CNAM["TELEPHONE":"T",1:"C")
 S APCDALVR("APCDCAT")=APCDCAT
 S APCDLOC=DUZ(2),APCDALVR("APCDLOC")=APCDLOC
 S APCDALVR("APCDPAT")=DFN,APCDPAT=DFN
 S APCDALVR("APCDOPT")=$$FIND1^DIC(19,"","BX","BTPWRPC","","","ERROR")
 ;S APCDADD=1
 I $G(MORE)'="" S APCDALVR("APCDAUTO")=1,APCDAUTO=1
 S APCDALVR("APCDANE")="",APCDALVR("AUPNTALK")=""
 Q
 ;
RPC(DATA,DFN,PARMS) ; EP -- BTPW CREATE CHART REVIEW
 ; Input
 ;   DFN   - Patient IEN
 ;   PARMS - Parms string
 ;
 NEW UID,II,BTWIEN,APCDAUTO,APCDDATE,MORE,APCDALVR,NAME,PDATA,PFIEN,PTYP,VALUE,CHIEN,BQ,CNAM
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BTPWCHRT",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWEVNT D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010VISIT_IEN"_$C(30)
 S BTWIEN=$$FIND1^DIC(90506.3,"","BX","Chart Review","","","ERROR")
 I BTWIEN=0 D  Q
 . S II=II+1,@DATA@(II)="-1^RPC Failed: Passed in window name "_DEF_" not found^"_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 S FILE=$P(^BQI(90506.3,BTWIEN,0),U,2)
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 . K LIST
 ;
 K APCDALVR
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . S PFIEN=$O(^BQI(90506.3,BTWIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S PTYP=$P($G(^BQI(90506.3,BTWIEN,10,PFIEN,1)),U,1)
 . I PTYP="D" S VALUE=$$DATE^BQIUL1(VALUE)
 . I PTYP="C"!(PTYP="K") D
 .. I VALUE="" Q
 .. S CHIEN=$O(^BQI(90506.3,BTWIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^BQI(90506.3,BTWIEN,10,PFIEN,5,CHIEN,0),U,2)
 . I PTYP="W" K BTPWP D  Q
 .. F BTI=1:1  S BTJ=$P(VALUE,$C(10),BTI) Q:BTJ=""  D
 ... S BTWP(BTI,0)=BTJ
 . S @NAME=VALUE
 . S APCDALVR(NAME)=VALUE
 ;
 I $G(BTPWVIEN)'="" D  Q
 . S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010VISIT_IEN"_$C(30)
 . I $G(TIUDA)'="" S VISIT=BTPWVIEN D NOT
 . S II=II+1,@DATA@(II)="1^^"_BTPWVIEN_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 . D CLNUP(BTWIEN)
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1)
 . S PFIEN=$O(^BQI(90506.3,BTWIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S FIELD=$P($G(^BQI(90506.3,BTWIEN,10,PFIEN,3)),U,1)
 . S EXEC=$G(^BQI(90506.3,BTWIEN,10,PFIEN,7))
 . I EXEC'="" X EXEC Q
 . I FIELD="" Q
 S MORE=1
 S APCDDATE=$$NOW^XLFDT(),APCDALVR("APCDDATE")=APCDDATE
 S APCDALVR("APCDPAT")=DFN,APCDPAT=DFN
 S APCDALVR("APCDANE")="",APCDALVR("AUPNTALK")=""
 S APCDALVR("APCDLOC")=$S($G(APCDALVR("APCDLOC"))'="":APCDALVR("APCDLOC"),1:DUZ(2))
 S APCDALVR("APCDTYPE")=$G(APCDALVR("APCDTYPE"),"I")
 S CLN=APCDALVR("APCDCLN")
 S APCDHL=$S(CLN=51:$P(^BQICARE(DUZ,0),U,20),CLN=53:$P(^BQICARE(DUZ,0),U,19),1:$P(^BQICARE(DUZ,0),U,18))
 S APCDALVR("APCDHL")=APCDHL
 S CLN=$O(^DIC(40.7,"C",CLN,"")),APCDALVR("APCDCLN")=CLN
 S CNAM=$P(^DIC(40.7,CLN,0),U,1)
 S APCDALVR("APCDOPT")=$$FIND1^DIC(19,"","BX","BTPWRPC","","","ERROR")
 S APCDALVR("APCDCAT")=$S(CNAM["TELEPHONE":"T",1:"C")
 I $G(MORE)'="" S APCDALVR("APCDAUTO")=1
 ;
 ;  Create visit and then update other Vfiles
 D EN^APCDALV
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S VISIT=$G(APCDALVR("APCDVSIT"))
 I $G(APCDALVR("APCDAFLG"))=2 S VISIT=-1,MSG="Unable to create chart review"
 I $G(APCDALVR("APCDAFLG"))=1 S VISIT=-1,MSG="Chart review already exists"
 I VISIT=-1 D  Q
 . S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010VISIT_IEN"_$C(30)
 . S II=II+1,@DATA@(II)="-1^"_MSG_"^"_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 ; Set the Chart Review with provider
 K APCDALVR
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.06 (ADD)]"
 S APCDALVR("APCDTPS")="PRIMARY",APCDALVR("APCDTPRO")=$P(^VA(200,DUZ,0),U,1)
 S APCDALVR("APCDPAT")=DFN,APCDALVR("APCDVSIT")=VISIT
 S RESULT=$$ADD(DFN,VISIT,.APCDALVR)
 ;
 ; Note
 I $G(TIUDA)'="" D NOT
 ;
 ;POV
 K APCDALVR
 NEW APCDCAT,IEN
 S APCDCAT=$P(^AUPNVSIT(VISIT,0),"^",7)
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.07 (ADD)]"
 S APCDALVR("APCDTPOV")=$S($G(APCDCAT)="T":"Z71.9",1:$$CRPOV^BTPWPBTH())
 S APCDALVR("APCDTPS")="PRIMARY"
 S APCDALVR("APCDTNQ")=$S($G(APCDCAT)="T":"iCare Telephone Note|185317003",1:"iCare Chart Review|107728002")
 S APCDALVR("APCDPAT")=DFN,APCDALVR("APCDVSIT")=VISIT
 S RESULT=$$ADD(DFN,VISIT,.APCDALVR)
 S IEN=$O(^AUPNVPOV("AD",VISIT,""))
 S BQIUPD(9000010.07,IEN_",",1101)=$S($G(APCDCAT)="T":185317003,1:107728002)
 S BQIUPD(9000010.07,IEN_",",1102)=$S($G(APCDCAT)="T":285327012,1:202356017)
 D FILE^DIE("","BQIUPD","ERROR")
 ;
 S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010VISIT_IEN"_$C(30)
 S II=II+1,@DATA@(II)="1^^"_VISIT_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 D CLNUP(BTWIEN)
 Q
 ;
NOT ;Note
 K APCDALVR
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.28 (ADD)]"
 S APCDALVR("APCDTDOC")=TIUDA
 S APCDALVR("APCDPAT")=DFN,APCDALVR("APCDVSIT")=VISIT
 S RESULT=$$ADD(DFN,VISIT,.APCDALVR)
 Q
 ;
TRIG(DATA,APCDCLN) ;EP -- BTPW CHART REVIEW TRIGGER
 NEW UID,II,VALUE,SOURCE,TYPE,ABLE,CLEAR,CLFLG
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BTPWCHTR",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWBTTR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="T00008SOURCE^T00001CODE_TYPE^T00001ABLE_FLAG^T00001CLEAR_FLAG^T00060CLEAR_FIELDS^T01024PARMS"_$C(30)
 I APCDCLN=51 S VALUE="T"_$C(28)_"TELEPHONE"
 I APCDCLN'=51 S VALUE="C"_$C(28)_"CHART REVIEW"
 S SOURCE="APCDCAT",TYPE="C",ABLE="Y",CLEAR="",CLFLG="N" D UP
 S VALUE=""
 I APCDCLN=51 S VALUE=$P(^BQICARE(DUZ,0),U,20) I VALUE'="" S VALUE=VALUE_$C(28)_$P(^SC(VALUE,0),U,1)
 I APCDCLN=52 S VALUE=$P(^BQICARE(DUZ,0),U,18) I VALUE'="" S VALUE=VALUE_$C(28)_$P(^SC(VALUE,0),U,1)
 I APCDCLN=53 S VALUE=$P(^BQICARE(DUZ,0),U,19) I VALUE'="" S VALUE=VALUE_$C(28)_$P(^SC(VALUE,0),U,1)
 S SOURCE="APCDHL",TYPE="T",ABLE="Y",CLEAR="" D UP
 I APCDCLN=51 S VALUE="iCare Telephone Note"
 I APCDCLN'=51 S VALUE="iCare Chart Review"
 S SOURCE="APCDTNQ",TYPE="T",ABLE="Y",CLEAR="" D UP
 Q
 ;
UP ; Update
 S II=II+1,@DATA@(II)=SOURCE_U_TYPE_U_$G(ABLE)_U_CLFLG_U_$G(CLEAR)_U_VALUE_$C(30)
 Q
 ;
DEL(DATA,VISIT) ;EP -- BTPW DELETE CHART REVIEW
 NEW UID,II,APCDVDLT,USER,TO,FROM,DIK,DA,RESULT,DUSR
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BTPWDCHRT",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWEVNT D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010VISIT_IEN"_$C(30)
 S RESULT="1^^"
 I $O(^TIU(8925,"V",VISIT,""))'="" S RESULT="-1^TIU Document points to this visit. Cannot be deleted.^" G DONE
 X ^BTPW(90628,1,3)
 X DUSR X TO
 S DIK="^AUPNVPOV(",DA=$O(^AUPNVPOV("AD",VISIT,"")) I DA'="" D ^DIK
 S DIK="^AUPNVPRV(",DA=$O(^AUPNVPRV("AD",VISIT,"")) I DA'="" D ^DIK
 S DIK="^AUPNVNOT(",DA=$O(^AUPNVNOT("AD",VISIT,"")) I DA'="" D ^DIK
 S DIK="^AUPNVSIT(",DA=VISIT D ^DIK
 X FROM
 ;
DONE ;
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
CLNUP(VFIEN) ; Clean up variables
 NEW NAME
 S NAME=""
 F  S NAME=$O(^BQI(90506.3,VFIEN,10,"AC",NAME)) Q:NAME=""  K @NAME
 Q