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

SDMHAD1.m

Go to the documentation of this file.
SDMHAD1 ;MAF/ALB - MENTAL HEALTH AD HOC NO SHOW REPORT(cont.);JULY 14, 2010
 ;;5.3;Scheduling;**578,588**;Aug 13,1993;Build 53
 ;
SET ; Set up the data for the patient
 ;       piece 1 = dfn
 ;       piece 2 = Appointment Date and time
 ;       piece 3 = status N(Noshow) or NA (Noshow with auto rebook)
 ;       piece 4 = PID last 4 of SSN
 ;       piece 5 = clinic ien   ^SC(
 ;       piece 6 = stop code ien ^DIC(40.7
 ;   
 ;
EN ;PRINT OF THE ^TMP 
 N SDXDIV,SDXCLIN,SDXDFN,SDXSTOP,SDXREM,SDXNM,SDCOUNT,SDATE,SDTOTPG
 S (SDXDFN,SDXREM,SDCOUNT)=0
 S SDXDIV=""
 F  S SDXDIV=$O(^TMP(NAMSPC1,$J,SDXDIV)) Q:SDXDIV']""!(SDUP)  D
 .I SDTL="CLIN" D
 ..S SDXCLIN=""
 ..F  S SDXCLIN=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN)) Q:SDXCLIN']""!($G(SDUP))  D
 ...S SDXNM=""
 ...F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM)) Q:SDXNM']""!($G(SDUP))  D
 ....S SDXSTOP=0
 ....F  S SDXSTOP=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP)) Q:'SDXSTOP!($G(SDUP))  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP,SDATE)) Q:'SDATE!($G(SDUP))  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP,SDATE)) D PRT
 .I SDTL="STOP" N SDXSTOPN D
 ..S SDXSTOP=0
 ..F  S SDXSTOP=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP)) Q:SDXSTOP']""!($G(SDUP))  D
 ...S SDXNM=""
 ...F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM)) Q:SDXNM']""!($G(SDUP))  D
 ....S SDXCLIN=""
 ....F  S SDXCLIN=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN)) Q:SDXCLIN']""!($G(SDUP))  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN,SDATE)) Q:'SDATE!($G(SDUP))  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN,SDATE)) S SDXSTOPN=$P(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN,SDATE),"^",6) D PRT
 .I SDTL="MEN" D
 ..S SDXREM=""
 ..F  S SDXREM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM)) Q:SDXREM']""!($G(SDUP))  D
 ...S SDXCLIN=""
 ...F  S SDXCLIN=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXCLIN)) Q:SDXCLIN']""!($G(SDUP))  D
 ....S SDXNM=""
 ....F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXCLIN,SDXNM)) Q:SDXNM']""!($G(SDUP))  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXCLIN,SDXNM,SDATE)) Q:'SDATE!($G(SDUP))  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXCLIN,SDXNM,SDATE)) S SDXSTOP=$P(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXCLIN,SDXNM,SDATE),"^",6) D PRT
 Q:SDUP
 I $D(^TMP(NAMSPC1,$J)) S SDTOTPG=1 D HEAD^SDMHAD D TOTAL1^SDMHNS
 Q
 ;
 ;
PRT ;Print  report
 ;
 I '$D(SDXFLG(SDXDIV)) D HEAD^SDMHAD S SDXFLG(SDXDIV)=1 S:SDTL'="STOP" SDXFLG(SDXDIV,SDXCLIN)=1 S:SDTL="STOP" SDXFLG(SDXDIV,SDXSTOP,SDXSTOPN)=1
 I SDTL="CLIN" I $D(SDXFLG(SDXDIV)),'$D(SDXFLG(SDXDIV,SDXCLIN)) W !! D HEAD1^SDMHAD S SDXFLG(SDXDIV,SDXCLIN)=1
 I SDTL="STOP" I $D(SDXFLG(SDXDIV)),'$D(SDXFLG(SDXDIV,SDXSTOP,SDXSTOPN)) W !! D HEAD1^SDMHAD S SDXFLG(SDXDIV,SDXSTOP,SDXSTOPN)=1
 D COUNT^SDMHNS
 N SDXNODE,SDXID,SDXDT,SDXSTAT,SDXSORT1,SDXSORT2,SDXCLIEN,SDDSS,SDXRLL,SDXZERO,SDPROV
 S SDPROV=0
 S SDXSORT1=$S(SDTL="MEN":SDXREM,SDTL="STOP":SDXSTOP,1:SDXCLIN)
 S SDXSORT2=$S(SDTL="CLIN":SDXSTOP,1:SDXCLIN)
 I SDTL="MEN" S SDXNODE=$G(^TMP(NAMSPC1,$J,SDXDIV,SDXSORT1,SDXSORT2,SDXNM,SDATE))
 I SDTL'="MEN" S SDXNODE=$G(^TMP(NAMSPC1,$J,SDXDIV,SDXSORT1,SDXNM,SDXSORT2,SDATE))
 S SDXDFN=$P(SDXNODE,"^",1) Q:SDXDFN']""
 S SDXID=$E($P(SDXNODE,"^",4),1,5)
 S SDXDT=$P(SDXNODE,"^",2)
 S SDXSTAT=$P(SDXNODE,"^",3)
 S SDXCLIEN=$P(SDXNODE,"^",5)
 S SDDSS=$P($G(^DIC(40.7,+$P(SDXNODE,"^",6),0)),"^",2)
 S SDXDT=$$FMTE^XLFDT(SDXDT,"5") W !!,SDCOUNT,?4,$E($P(^DPT(SDXDFN,0),"^",1),1,20),?25,SDXID,?31,SDXDT,?49,$E(SDXCLIN,1,30)
 W !?47,$E("*"_SDXSTAT,1,5) D PROV W ?53,$E(SDPROV,1,26) D RET Q:SDUP  I SDCOUNT=$P($G(TOTAL(SDXDIV,SDXCLIN)),"^",1) S SDCOUNT=0
 D RET Q:SDUP  ;D PROV Q:SDUP
 D PATINFO Q:SDUP
 D RET Q:SDUP  D NOK Q:SDUP
 D RET Q:SDUP  D EC Q:SDUP
 ;D RET Q:SDUP  D PROV Q:SDUP
 D RET Q:SDUP  D MHTC Q:SDUP
 D RET Q:SDUP  D FUT Q:SDUP
 D RET Q:SDUP  D RESULTS Q:SDUP
 Q
 ;
 ;
PATINFO ;Patients home, cell and office phones
 N SDPHON,VAROOT,VAOA,SDEC6,SDEC5,DFN
 S DFN=SDXDFN,VAROOT="SDEC6" D ADD^VADPT
 I $D(SDEC6) D
 .S SDPHON("HOME")=SDEC6(8)
 S DFN=SDXDFN,VAOA("A")=5,VAROOT="SDEC5" D OAD^VADPT
 I $D(SDEC5) D
 .S SDPHON("WORK")=SDEC5(8)
 D GETS^DIQ(2,SDXDFN_",",".134","E","SDPHON")
 I $D(SDPHON(2,SDXDFN_",")) D
 .S SDPHON("CELL")=$G(SDPHON(2,SDXDFN_",",".134","E"))
 I $D(SDPHON("HOME")),SDPHON("HOME")]"" W !,?5,"Home: ",$$HLPHONE^HLFNC(SDPHON("HOME"),,) D RET Q:SDUP
 I $D(SDPHON("WORK")),SDPHON("WORK")]"" W !,?5,"Work: ",$$HLPHONE^HLFNC(SDPHON("WORK"),,) D RET Q:SDUP
 I $D(SDPHON("CELL")),SDPHON("CELL")]"" W !,?5,"Cell: ",$$HLPHONE^HLFNC(SDPHON("CELL"),,) D RET Q:SDUP
 Q
 ;
 ;
NOK ; Next of Kin information
 N SDNOK,SDNOK2,SDNOKNM,SDNOKNM2,SDNOKR,SDNOKR2,SDNOKPH,SDNOKPH2,SDNOKPO,SDNOKPO2,SDNOKFL,VAOA,VAROOT,SDEC3,SDEC4,SDPHON,DFN
 S DFN=SDXDFN,VAROOT="SDEC3" D OAD^VADPT
 S DFN=SDXDFN,VAOA("A")=3,VAROOT="SDEC4" D OAD^VADPT
 D GETS^DIQ(2,SDXDFN_",",".21011;.211011","E","SDPHON")
 I $D(SDPHON(2,SDXDFN_",")) D
 .S SDPHON("K-WORK")=$G(SDPHON(2,SDXDFN_",",".21011","E"))
 .S SDPHON("K2-WORK")=$G(SDPHON(2,SDXDFN_",",".211011","E"))
 I $D(SDEC3) D
 .S SDNOKNM=SDEC3(9),SDNOKR=SDEC3(10),SDNOKPH=SDEC3(8),SDNOKPO=SDPHON("K-WORK")
 I $D(SDEC4) D
 .S SDNOKNM2=SDEC4(9),SDNOKR2=SDEC4(10),SDNOKPH2=SDEC3(8),SDNOKPO2=SDPHON("K2-WORK")
 I SDNOKNM]""!(SDNOKNM2]"") D NOKFL D RET Q:SDUP
 I SDNOKNM]"" W ?7,"NOK: "_SDNOKNM D RET Q:SDUP
 I SDNOKNM2]"" W ?45,"NOK2: "_SDNOKNM2
 I SDNOKR]""!(SDNOKR2]"") D  D RET Q:SDUP
 .I '$D(SDNOKFL) D NOKFL Q
 .W !
 I SDNOKR]"" W ?7,"Relation: "_SDNOKR D RET Q:SDUP
 I SDNOKR2]"" W ?45,"Relation: "_SDNOKR2
 I SDNOKPH]""!(SDNOKPH2]"") D  D RET Q:SDUP
 .I '$D(SDNOKFL) D NOKFL Q
 .W !
 D RET Q:SDUP
 I SDNOKPH]"" W ?7,"Phone: "_$$HLPHONE^HLFNC(SDNOKPH,,)
 I SDNOKPH2]"" W ?45,"Phone: "_$$HLPHONE^HLFNC(SDNOKPH2,,)
 I SDNOKPO]""!(SDNOKPO2]"") D  D RET Q:SDUP
 .I '$D(SDNOKFL) D NOKFL Q
 .W !
 I SDNOKPO]"" W ?7,"Work Phone: "_$$HLPHONE^HLFNC(SDNOKPO,,)
 I SDNOKPO2]"" W ?45,"Work Phone: "_$$HLPHONE^HLFNC(SDNOKPO2,,)
 W ! D RET Q:SDUP
 Q
 ;
 ;
NOKFL W !!,"     Next of Kin:",! S SDNOKFL=1
 Q
 ;
 ;
EC ;display emergency contact information
 N SDEC1,SDEC2,SDPHON,VAROOT,VAOA
 Q:'$G(SDXDFN)
 N DFN
 S DFN=SDXDFN
 S VAOA("A")=1,VAROOT="SDEC1"  D OAD^VADPT ; Get Primary EC
 S VAOA("A")=4,VAROOT="SDEC2"  D OAD^VADPT ; Get Secondary EC
 D GETS^DIQ(2,SDXDFN_",",".33011;.331011","E","SDPHON")
 I $D(SDPHON(2,SDXDFN_",")) D
 .S SDPHON("E-WORK")=$G(SDPHON(2,SDXDFN_",",".33011","E"))
 .S SDPHON("E2-WORK")=$G(SDPHON(2,SDXDFN_",",".331011","E"))
 I SDEC1(9)]"" D
 . D RET Q:SDUP  I $D(SDEC1)!($D(SDEC2)) W !,?5,"Emergency Contact:" D RET Q:SDUP
 . ;Contacts name and realtionship
 . I SDEC1(9)]"" W !?7,"E-Cont.: ",SDEC1(9)
 . I SDEC2(9)]"" I SDEC2(9)]"" W ?45,"E2-Cont.: ",SDEC2(9)
 . D RET Q:SDUP  I SDEC1(10)]"" W !,?7,"Relation: ",SDEC1(10)
 . I SDEC2(10)]"" W ?45,"Relation: ",SDEC2(10)
 . ;ECs address lines 1, 2 and 3
 . D RET Q:SDUP  I SDEC1(1)]"" W !,?9,SDEC1(1)
 . I SDEC1(1)']"",SDEC2(1)]"" D RET Q:SDUP  W !
 . I SDEC2(1)]"" W ?47,SDEC2(1)
 . D RET Q:SDUP  I SDEC1(2)]"" W !,?9,SDEC1(2)
 . I SDEC1(2)']"",SDEC2(2)]"" D RET Q:SDUP  W !
 . I SDEC2(2)]"" W ?47,SDEC2(2)
 . D RET Q:SDUP  I SDEC1(3)]"" W !,?9,SDEC1(3)
 . I SDEC1(3)']"",SDEC2(3)]"" D RET Q:SDUP  W !
 . I SDEC2(3)]"" W ?47,SDEC2(3)
 . ;Emergency Contact 1 City, State an Zip+4
 . I SDEC1(4)]"" D
 . . D RET Q:SDUP  W !,?9,SDEC1(4)
 . . I SDEC1(5)]"" W ", "_$$GET1^DIQ(5,+SDEC1(5),1)
 . . W "  ",$P(SDEC1(11),"^",2)
 . ;Emergency Contact 2 City State and Zip+4
 . I SDEC2(4)]"" D
 . . D RET Q:SDUP  I SDEC1(4)']"" W !
 . . W ?47,SDEC2(4)
 . . I SDEC2(5)]"" W ", "_$$GET1^DIQ(5,+SDEC2(5),1)
 . . W "  ",$P(SDEC2(11),"^",2)
 . ;Home and work phones
 . D RET Q:SDUP  I SDEC1(8)]"" W !,?7,"Phone: "_$$HLPHONE^HLFNC(SDEC1(8),,)
 . I SDEC2(8)]"" W ?45,"Phone: "_$$HLPHONE^HLFNC(SDEC2(8),,)
 . D RET Q:SDUP  I SDPHON("E-WORK")]"" W !?7,"Work Phone: "_$$HLPHONE^HLFNC(SDPHON("E-WORK"),,)     ;,$S($P(^DPT(DFN,.33),U,11)]"":$P(^DPT(DFN,.33),U,11),1:"UNSPECIFIED")
 . I SDPHON("E2-WORK")]"" W ?45,"Work Phone: "_$$HLPHONE^HLFNC(SDPHON("E2-WORK"),,)    ;,$S($P(^DPT(DFN,.331),U,11)]"":$P(^DPT(DFN,.331),U,11),1:"UNSPECIFIED")
 D KVAR^VADPT
 Q
 ;
 ;
PROV ;Clinic Default Provider
 N SDPNUM,SDPNODE
 S SDPNUM=0
 F SDPNUM=0:0 S SDPNUM=$O(^SC(SDXCLIEN,"PR",SDPNUM)) Q:'(+SDPNUM)  I $D(^SC(SDXCLIEN,"PR",SDPNUM,0)) S SDPNODE=^SC(SDXCLIEN,"PR",SDPNUM,0) I $P(SDPNODE,"^",1)&($P(SDPNODE,"^",2)) D  Q:SDUP
 . S SDPROV=$E($P(^VA(200,$P(SDPNODE,"^",1),0),"^",1),1,25) ;D RET
 ;.W !,?5,"Provider:  "_$P(^VA(200,$P(SDPNODE,"^",1),0),"^",1) D RET
 Q
 ;
 ;
MHTC ;Mental Health Treatment Coordinator
 ;Q:'$T(START^SCMCMHTC)
 W !
 N SDMHTC,MHTC,SDMHTEAM
 S SDMHTC=$$START^SCMCMHTC(SDXDFN) S SDMHTEAM=$P($G(SDMHTC),"^",5),SDMHTC=$P($G(SDMHTC),"^",2)
 I SDMHTC]"" W !,?5,"MHTC:  "_SDMHTC_" ("_SDMHTEAM_$S(SDMHTEAM["TEAM":"",1:" TEAM")_")" D RET
 Q
 ;
 ;
FUT ; FUTURE SCHEDULED APPTS.
 W !,?5,"Future Scheduled Appointments:  "
 N SDARRAY,SDCOUNT,SDX,X1,X2,X
 S X1=DT,X2=$S($D(SDFUTNUM):SDFUTNUM,1:30) D C^%DTC S SDX=X
 S SDARRAY(1)=DT_";"_SDX
 S SDARRAY("SORT")="P"
 S SDARRAY(3)="NT;R"
 S SDARRAY(4)=SDXDFN
 S SDARRAY("FLDS")="1;2;3;4;10;13"
 S SDCOUNT=$$SDAPI^SDAMA301(.SDARRAY)
 I SDCOUNT>0 D  Q:SDUP
 .;Get info on future scheduled appointments and display it
 . N SDFA,SDFNODE,SDFUTDT  ;,SDFUTCNT
 . ;S SDFUTCNT=0  ;List up to 6 future appts. for a patient.
 . S SDFA=0 F  S SDFA=$O(^TMP($J,"SDAMA301",SDXDFN,SDFA)) Q:SDFA=""!(SDUP)  D  Q:SDUP
 .. S SDFUTDT=$$FMTE^XLFDT(SDFA,"5") S SDFNODE=^TMP($J,"SDAMA301",SDXDFN,SDFA) W !,?7,SDFUTDT,?26,$E($P($P(SDFNODE,"^",2),";",2),1,30)  ;S SDFUTCNT=SDFUTCNT+1
 ..D RET Q:SDUP
 .Q
 I SDCOUNT'>0 D  Q:SDUP
 .W "NO APPOINTMENTS SCHEDULED WITHIN "_SDFUTNUM_$S(SDFUTNUM=1:" DAY",1:" DAYS")
 K ^TMP($J,"SDAMA301")
 Q
 ;
 ;
RESULTS ;Reminder information
 W !,?5,"Results: "
 K ^TMP("PXRHM",$J),^TMP("PXRM",$J)
 N SDCR
 ;S SDCR=$O(^PXD(811.9,"B","VA-MH HIGH RISK NO-SHOW FOLLOW-UP",0))
 S SDCR=$O(^PXD(811.9,"B","VA-MH HIGH RISK NO-SHOW ADHOC RPT",0))
 ;    N DEFARR,FIEVAL
 ;    Load the definition into DEFARR.
 ;    D DEF^PXRMLDR(SDCR,.DEFARR)
 ;    D EVAL^PXRM(SDXDFN,.DEFARR,5,0,.FIEVAL,$P(SDXNODE,"^",2))
 D MAINDF^PXRM(SDXDFN,SDCR,5,$P(SDXNODE,"^",2))
 N SDTXT,SDTXTR,SDRNODE
 S (SDTXT,SDTXTR)=0
 F SDTXT=0:0 S SDTXT=$O(^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT)) Q:'SDTXT!(SDTXTR)  S SDRNODE=$G(^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT)) I SDRNODE["Resolution:"!(SDRNODE["Information:") D
 .;N SDTNODE
 .W !,?5,^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT) D RET Q:SDUP  D
 ..F SDTXT=SDTXT:0 S SDTXT=$O(^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT)) Q:'SDTXT  I $D(^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT)) D
 ...W !,?5,^TMP("PXRHM",$J,SDCR,"High Risk MH No-Show Adhoc Rpt","TXT",SDTXT)
 ...D RET Q:SDUP  Q
 ..S SDTXTR=1
 ..;K ^TMP("PXRHM",$J),^TMP("PXRM",$J) Q
 D RET Q:SDUP
 K ^TMP("PXRHM",$J),^TMP("PXRM",$J)
 Q
 ;
 ;
PID(DFN) ; Return PID
 ; INPUT  - DFN
 ; OUTPUT - PID or 'UNKNOWN'
 N VA
 D PID^VADPT6
 Q $S(VA("BID")]"":VA("BID"),1:"UNKNOWN")
 ;
 ;
RET ;
 I $E(IOST,1,2)="C-",($Y+6)>IOSL D  Q:SDUP
 . S DIR(0)="E"
 . D ^DIR K DIR
 . I 'Y S SDUP=1 Q
 . K SDXFLG(SDXDIV)
 . D HEAD^SDMHAD S SDXFLG(SDXDIV)=1,SDXFLG(SDXDIV,SDXCLIN)=1,SDXFLG(SDXDIV,SDXSTOP)=1