SCMCMHTC ;BP/DMR - PCMM/MH API; 4 JAN 11
;;5.3;PIMS;**1016**;JUN 30, 2012;Build 20
;
;This API provides the Mental Health Treatment Coordinator
;from PCMM for display in CPRS, or used as a stand alone API.
;
;Input - DFN
;Output - IEN^MHTC^Team Position^Role^Team
;
START(DFN) ; Get patient MHTC info.
Q:'$G(DFN)
N ACT,IEN,PNAM,PRO,TIEM,TPUR,TEAM
N TP,TPR,TPRIEN,ADATE,UDATE,SAVE,NP,TNAM
S MHTC="",SAVE=""
;
S IEN="" F S IEN=$O(^SCPT(404.42,"B",DFN,IEN)) Q:IEN=""!(SAVE=1) D
.S TIEM="" S TIEM=$P($G(^SCPT(404.42,IEN,0)),"^",3) Q:TIEM=""
.Q:$$GET1^DIQ(404.51,TIEM,.03)'="MENTAL HEALTH TREATMENT"
.S TPIEN="" F S TPIEN=$O(^SCPT(404.43,"B",IEN,TPIEN)) Q:TPIEN=""!(SAVE=1) D
..S TPRIEN="",TPRIEN=$$GET1^DIQ(404.43,TPIEN,.02,"I") Q:TPRIEN=""
..S TPR="",TPR=$$GET1^DIQ(404.57,TPRIEN,.03) Q:TPR=""
..Q:TPR'["(MHTC)" S TP="",TP=$$GET1^DIQ(404.57,TPRIEN,.01) Q:TP=""
..S PRO="",PRO=$O(^SCTM(404.52,"B",TPRIEN,PRO),-1) Q:PRO=""
..S ACT="",ACT=$$GET1^DIQ(404.52,PRO,.04,"I") Q:ACT'=1
..S PNAM="",PNAM=$$GET1^DIQ(404.52,PRO,.03) Q:PNAM=""
..S ADATE="",ADATE=$$GET1^DIQ(404.43,TPIEN,.03,"I")
..S UDATE="",UDATE=$$GET1^DIQ(404.43,TPIEN,.04,"I")
..Q:ADATE>DT Q:UDATE>ADATE&(UDATE<DT) Q:UDATE=ADATE&(UDATE<DT) D SAVE
I $G(CPRSGUI) D PRINT Q
Q MHTC
;
SAVE ;Save MHTC info.
;
S MHTC="",SAVE="",NP="",TNAM=""
S NP=$$GET1^DIQ(404.52,PRO,.03,"I")
S TNAM=$$GET1^DIQ(404.51,TIEM,.01)
S $P(MHTC,"^",1)=NP
S $P(MHTC,"^",2)=PNAM
S $P(MHTC,"^",3)=TP
S $P(MHTC,"^",4)=TPR
S $P(MHTC,"^",5)=TNAM
S SAVE=1
Q
;
PRINT ;Display in CPRS Patient Inquiry.
;
Q:'$G(CPRSGUI)
N PH,PAG,DPAG
Q:'+$G(NP)
Q:PNAM=""
Q:TP=""
S PH=$$GET1^DIQ(200,NP,.132),PAG=$$GET1^DIQ(200,NP,.137),DPAG=$$GET1^DIQ(200,NP,.138)
W !!," MH Treatment Team: ",TNAM
W !,"MH Treatment Coord: ",$E(PNAM,1,28),?52,"Position: ",$E(TP,1,18)
W !," Analog Pager: ",PAG,?55,"Phone: ",PH
W !," Digital Pager: ",DPAG
Q
;
LIST ;List of all active MHTC's from PCMM to CPRS.
;
;Output Fields - PIEN^MHTC^Role^Team Position^Team
;Output Global - ^TMP("MHTC",$J,MHTC,CC)
;
S MHTC="",PIEN="",IEN="",ROLE="",PAIEN="",TPIEN="",TP="",TEAM="",CC=""
K ^TMP("MHTC")
;
S IEN="" F S IEN=$O(^SCTM(404.52,"B",IEN)) Q:IEN="" D
.S PAIEN="" F S PAIEN=$O(^SCTM(404.52,"B",IEN,PAIEN)) Q:PAIEN="" D
..Q:$$GET1^DIQ(404.52,PAIEN,.04,"I")'=1
..S TPIEN="",TPIEN=$$GET1^DIQ(404.52,PAIEN,.01,"I") Q:TPIEN=""
..S ROLE="",ROLE=$$GET1^DIQ(404.57,TPIEN,.03) Q:ROLE'["(MHTC)"
..S MHTC="",MHTC=$$GET1^DIQ(404.52,PAIEN,.03) Q:MHTC=""
..S PIEN="",PIEN=$$GET1^DIQ(404.52,PAIEN,.03,"I")
..S TP="",TP=$$GET1^DIQ(404.57,TPIEN,.01)
..S TEAM="",TEAM=$$GET1^DIQ(404.57,TPIEN,.02)
..S CC=CC+1 S ^TMP("MHTC",$J,MHTC,CC)=PIEN_"^"_MHTC_"^"_ROLE_"^"_TP_"^"_TEAM
..Q
D EXIT
Q
;
EXIT ;
K PIEN,ROLE,PAIEN,TP,TEAM,CC,MHTC,IEN,TPIEN
Q
SCMCMHTC ;BP/DMR - PCMM/MH API; 4 JAN 11
+1 ;;5.3;PIMS;**1016**;JUN 30, 2012;Build 20
+2 ;
+3 ;This API provides the Mental Health Treatment Coordinator
+4 ;from PCMM for display in CPRS, or used as a stand alone API.
+5 ;
+6 ;Input - DFN
+7 ;Output - IEN^MHTC^Team Position^Role^Team
+8 ;
START(DFN) ; Get patient MHTC info.
+1 IF '$GET(DFN)
QUIT
+2 NEW ACT,IEN,PNAM,PRO,TIEM,TPUR,TEAM
+3 NEW TP,TPR,TPRIEN,ADATE,UDATE,SAVE,NP,TNAM
+4 SET MHTC=""
SET SAVE=""
+5 ;
+6 SET IEN=""
FOR
SET IEN=$ORDER(^SCPT(404.42,"B",DFN,IEN))
IF IEN=""!(SAVE=1)
QUIT
Begin DoDot:1
+7 SET TIEM=""
SET TIEM=$PIECE($GET(^SCPT(404.42,IEN,0)),"^",3)
IF TIEM=""
QUIT
+8 IF $$GET1^DIQ(404.51,TIEM,.03)'="MENTAL HEALTH TREATMENT"
QUIT
+9 SET TPIEN=""
FOR
SET TPIEN=$ORDER(^SCPT(404.43,"B",IEN,TPIEN))
IF TPIEN=""!(SAVE=1)
QUIT
Begin DoDot:2
+10 SET TPRIEN=""
SET TPRIEN=$$GET1^DIQ(404.43,TPIEN,.02,"I")
IF TPRIEN=""
QUIT
+11 SET TPR=""
SET TPR=$$GET1^DIQ(404.57,TPRIEN,.03)
IF TPR=""
QUIT
+12 IF TPR'["(MHTC)"
QUIT
SET TP=""
SET TP=$$GET1^DIQ(404.57,TPRIEN,.01)
IF TP=""
QUIT
+13 SET PRO=""
SET PRO=$ORDER(^SCTM(404.52,"B",TPRIEN,PRO),-1)
IF PRO=""
QUIT
+14 SET ACT=""
SET ACT=$$GET1^DIQ(404.52,PRO,.04,"I")
IF ACT'=1
QUIT
+15 SET PNAM=""
SET PNAM=$$GET1^DIQ(404.52,PRO,.03)
IF PNAM=""
QUIT
+16 SET ADATE=""
SET ADATE=$$GET1^DIQ(404.43,TPIEN,.03,"I")
+17 SET UDATE=""
SET UDATE=$$GET1^DIQ(404.43,TPIEN,.04,"I")
+18 IF ADATE>DT
QUIT
IF UDATE>ADATE&(UDATE<DT)
QUIT
IF UDATE=ADATE&(UDATE<DT)
QUIT
DO SAVE
End DoDot:2
End DoDot:1
+19 IF $GET(CPRSGUI)
DO PRINT
QUIT
+20 QUIT MHTC
+21 ;
SAVE ;Save MHTC info.
+1 ;
+2 SET MHTC=""
SET SAVE=""
SET NP=""
SET TNAM=""
+3 SET NP=$$GET1^DIQ(404.52,PRO,.03,"I")
+4 SET TNAM=$$GET1^DIQ(404.51,TIEM,.01)
+5 SET $PIECE(MHTC,"^",1)=NP
+6 SET $PIECE(MHTC,"^",2)=PNAM
+7 SET $PIECE(MHTC,"^",3)=TP
+8 SET $PIECE(MHTC,"^",4)=TPR
+9 SET $PIECE(MHTC,"^",5)=TNAM
+10 SET SAVE=1
+11 QUIT
+12 ;
PRINT ;Display in CPRS Patient Inquiry.
+1 ;
+2 IF '$GET(CPRSGUI)
QUIT
+3 NEW PH,PAG,DPAG
+4 IF '+$GET(NP)
QUIT
+5 IF PNAM=""
QUIT
+6 IF TP=""
QUIT
+7 SET PH=$$GET1^DIQ(200,NP,.132)
SET PAG=$$GET1^DIQ(200,NP,.137)
SET DPAG=$$GET1^DIQ(200,NP,.138)
+8 WRITE !!," MH Treatment Team: ",TNAM
+9 WRITE !,"MH Treatment Coord: ",$EXTRACT(PNAM,1,28),?52,"Position: ",$EXTRACT(TP,1,18)
+10 WRITE !," Analog Pager: ",PAG,?55,"Phone: ",PH
+11 WRITE !," Digital Pager: ",DPAG
+12 QUIT
+13 ;
LIST ;List of all active MHTC's from PCMM to CPRS.
+1 ;
+2 ;Output Fields - PIEN^MHTC^Role^Team Position^Team
+3 ;Output Global - ^TMP("MHTC",$J,MHTC,CC)
+4 ;
+5 SET MHTC=""
SET PIEN=""
SET IEN=""
SET ROLE=""
SET PAIEN=""
SET TPIEN=""
SET TP=""
SET TEAM=""
SET CC=""
+6 KILL ^TMP("MHTC")
+7 ;
+8 SET IEN=""
FOR
SET IEN=$ORDER(^SCTM(404.52,"B",IEN))
IF IEN=""
QUIT
Begin DoDot:1
+9 SET PAIEN=""
FOR
SET PAIEN=$ORDER(^SCTM(404.52,"B",IEN,PAIEN))
IF PAIEN=""
QUIT
Begin DoDot:2
+10 IF $$GET1^DIQ(404.52,PAIEN,.04,"I")'=1
QUIT
+11 SET TPIEN=""
SET TPIEN=$$GET1^DIQ(404.52,PAIEN,.01,"I")
IF TPIEN=""
QUIT
+12 SET ROLE=""
SET ROLE=$$GET1^DIQ(404.57,TPIEN,.03)
IF ROLE'["(MHTC)"
QUIT
+13 SET MHTC=""
SET MHTC=$$GET1^DIQ(404.52,PAIEN,.03)
IF MHTC=""
QUIT
+14 SET PIEN=""
SET PIEN=$$GET1^DIQ(404.52,PAIEN,.03,"I")
+15 SET TP=""
SET TP=$$GET1^DIQ(404.57,TPIEN,.01)
+16 SET TEAM=""
SET TEAM=$$GET1^DIQ(404.57,TPIEN,.02)
+17 SET CC=CC+1
SET ^TMP("MHTC",$JOB,MHTC,CC)=PIEN_"^"_MHTC_"^"_ROLE_"^"_TP_"^"_TEAM
+18 QUIT
End DoDot:2
End DoDot:1
+19 DO EXIT
+20 QUIT
+21 ;
EXIT ;
+1 KILL PIEN,ROLE,PAIEN,TP,TEAM,CC,MHTC,IEN,TPIEN
+2 QUIT