CRHD1 ; CAIRO/CLC - ADDED TO WORK WITH HAND OFF TEAM SECTION ;04-Mar-2008 16:00;CLC
 ;;1.0;CRHD;****;Jan 28, 2008;Build 19
 ;=================================================================
DELENTS(CRHDRTN,CRHDTM,CRHDTY,CRHDP) ;
 ;delete a Hand off patient, provider, or team
 
DA,DIK
 
CRHDRTN
 
CRHDRTN=0
 
CRHDPIEN,CRHDN
 
CRHDN=$S(CRHDTY="P":1,1:2)
 
CRHDPIEN=$O(^CRHD(183.3,+CRHDTM,+CRHDN,"B",+CRHDP,0))
 
CRHDPIEN DIK="^CRHD(183.3,"_+CRHDTM_","_+CRHDN_",",DA(1)=+CRHDTM,DA=CRHDPIEN ^DIK CRHDRTN=1
 
Q
HOTMMGR(CRHDRTN,DUZ) ;
 
CRHDKN,CRHDKEYS,CRHDOUT
 
CRHDRTN=0
 
CRHDKN=$$FIND1^DIC(19.1,"","X","CRHD HOT TEAM MGR","","","OUT")
 
GETS^DIQ(200,DUZ_",","51*","I","CRHDOUT")
 
CRHDKN>0 CRHDRTN=$D(CRHDOUT(200.051,+CRHDKN_","_DUZ_","))
 
Q
HOTMMEM(CRHDRTN,CRHDTM,CRHDFRM,CRHDDIR,CRHDPFG) ;
 ;Return a set of providers from the HOT Team list.
 ;CRHDPFG - only return providers who have patients assigned to them
 
CRHDPLST,CRHDN,CRHDMAX,CRHDORI,CRHDTL,CRHDPATS
 
CRHDRTN
 
CRHDRTN=""
 
'$G(CRHDDIRCRHDDIR=1
 
CRHDORI=0,CRHDMAX=44
 
I $G(CRHDPFGPP NX
 
HODLIST^CRHD9(.CRHDPLST,CRHDTM)
 
I $D(CRHDPLSTD
 
.CRHDN=0
 .
F  S CRHDN=$O(CRHDPLST(CRHDN)) Q:'CRHDN  D
 
..CRHDTL($P(CRHDPLST(CRHDN),"^",2))=CRHDPLST(CRHDN)
NX CRHDFRM'="",$D(CRHDTL(CRHDFRM)) CRHDFRM=$E(CRHDFRM,1,$L(CRHDFRM)-1)
 
CRHDN=CRHDFRM
 
F  Q:CRHDORI'<CRHDMAX  CRHDN=$O(CRHDTL(CRHDN),CRHDDIRQ:CRHDN=""  D
 
.CRHDORI=CRHDORI+1,CRHDRTN(CRHDORI)=CRHDTL(CRHDN)
 
Q
PP ;
 
CRHDPATS,CRHDX
 
CRHDPATS HOTPRVPT(.CRHDPATS,CRHDTM,"")
 
I $D(CRHDPATSD
 
.CRHDX=0
 .
F  S CRHDX=$O(CRHDPATS(CRHDX)) Q:'CRHDX  D
 
..S:'$D(CRHDTL($P(CRHDPATS(CRHDX),"^",1))) CRHDTL($P(CRHDPATS(CRHDX),"^",1))=$P(CRHDPATS(CRHDX),"^",2)_"^"_$P(CRHDPATS(CRHDX),"^",1)
 
Q
HOTMMEMS(CRHDRTN,CRHDTM,CRHDFRM,CRHDDIR,CRHDCLAS) ;
 ;Return a subset of HO Team list
 ;CRHDCLAS
 ;    ATTN:ATTENDING
 ;    RES:RESIDENT
 ;    INTERN:INTERN
 ;    FELLOW:FELLOW
 ;    STUD:MED STUDENT
 
CRHDPLST,CRHDN,CRHDMAX,CRHDORI,CRHDTL
 
CRHDRTN
 
'$G(CRHDDIRCRHDDIR=1
 
CRHDORI=0,CRHDMAX=44
 
HOTMMEM(.CRHDPLST,CRHDTM,CRHDFRM,CRHDDIR)
 
I $D(CRHDPLSTD
 
.CRHDN=0
 .
F  S CRHDN=$O(CRHDPLST(CRHDN)) Q:'CRHDN  D
 
..I $G(CRHDCLAS)'="" I $P(CRHDPLST(CRHDN),"^",3)=CRHDCLAS CRHDTL($P(CRHDPLST(CRHDN),"^",2))=CRHDPLST(CRHDN)
 ..
I $G(CRHDCLAS)="" CRHDTL($P(CRHDPLST(CRHDN),"^",2))=CRHDPLST(CRHDN)
 
F  Q:CRHDORI'<CRHDMAX  CRHDN=$O(CRHDTL(CRHDN),CRHDDIRQ:CRHDN=""  D
 
.CRHDORI=CRHDORI+1,CRHDRTN(CRHDORI)=CRHDTL(CRHDN)
 
Q
HOTPRVPT(CRHDRTN,CRHDTM,CRHDPRV) ;
 ;return list of patients from the HO team list provider
 
CRHDRTN
 
CRHDPLST,CRHDORI,CRHDMAX,CRHDP,CRHDTMPL,CRHDCT,CRHDI,CRHDN,CRHDNN,CRHDNNN
 
CRHDORI=0,CRHDMAX=44
 
HOPLIST^CRHD9(.CRHDPLST,CRHDTM)
 
I $D(CRHDPLSTD
 
.CRHDN=0,CRHDCT=0
 .
F  S CRHDN=$O(CRHDPLST(CRHDN)) Q:'CRHDN  D
 
..CRHDP=$P(CRHDPLST(CRHDN),"*",2)
 ..
CRHDI=2:1:$L(CRHDP,";"+$P(CRHDP,";",CRHDID
 
...+CRHDPRV +CRHDPRV=+$P(CRHDP,";",CRHDICRHDCT=CRHDCT+1,CRHDTMPL($P($P(CRHDP,";",CRHDI),"^",2),+$P(CRHDP,";",CRHDI),CRHDCT)=$P(CRHDPLST(CRHDN),"*",1) Q
 
...'CRHDPRV CRHDCT=CRHDCT+1,CRHDTMPL($P($P(CRHDP,";",CRHDI),"^",2),+$P(CRHDP,";",CRHDI),CRHDCT)=$P(CRHDPLST(CRHDN),"*",1)
 
I $D(CRHDTMPLD
 
.CRHDN=""
 
.F  Q:CRHDORI'<CRHDMAX  CRHDN=$O(CRHDTMPL(CRHDN)) Q:CRHDN=""  D
 
..CRHDNN=0
 ..
F  S CRHDNN=$O(CRHDTMPL(CRHDN,CRHDNN)) Q:'CRHDNN  D
 
...CRHDNNN=0
 ...
F  S CRHDNNN=$O(CRHDTMPL(CRHDN,CRHDNN,CRHDNNN)) Q:'CRHDNNN  D
 
....CRHDORI=CRHDORI+1,CRHDRTN(CRHDORI)=CRHDN_"^"_CRHDNN_"^"_CRHDTMPL(CRHDN,CRHDNN,CRHDNNN)
 
Q