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

SDMHNS1.m

Go to the documentation of this file.
SDMHNS1 ;MAF/ALB - MENTAL HEALTH NO SHOW REPORT (BGJ CONT.); SEPTEMBER 9, 2010
 ;;5.3;PIMS;**1016**;JUN 30, 2012;Build 20
DATA ; 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
 S (SDXDFN,SDXREM,SDCOUNT)=0
 I $D(^TMP(NAMSPC1,$J)) D TOTAL^SDMHNS
 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']""!(SDUP)  D
 ...S SDXNM=""
 ...F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM)) Q:SDXNM']""!(SDUP)  I SDXNM]"" D
 ....S SDXSTOP=0
 ....F  S SDXSTOP=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP)) Q:'SDXSTOP!(SDUP)  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP("SDNS",$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP,SDATE)) Q:'SDATE!(SDUP)  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXCLIN,SDXNM,SDXSTOP,SDATE)) D PRT
 .I SDTL="STOP" D
 ..S SDXSTOP=0
 ..F  S SDXSTOP=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP)) Q:SDXSTOP']""!(SDUP)  D
 ...S SDXNM=""
 ...F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM)) Q:SDXNM']""!(SDUP)  I SDXNM]""  D
 ....S SDXCLIN=""
 ....F  S SDXCLIN=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN)) Q:SDXCLIN']""!(SDUP)  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN,SDATE)) Q:SDATE=""!(SDUP)  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXSTOP,SDXNM,SDXCLIN,SDATE)) D PRT
 .I SDTL="MEN" D
 ..S SDXREM=""
 ..F  S SDXREM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM)) Q:SDXREM']""!(SDUP)  D
 ...S SDXNM=""
 ...F  S SDXNM=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXNM)) Q:SDXNM']""!(SDUP)  I SDXNM]""  D
 ....S SDXCLIN=""
 ....F  S SDXCLIN=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXNM,SDXCLIN)) Q:SDXCLIN']""!(SDUP)  D
 .....S SDATE=0
 .....F  S SDATE=$O(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXNM,SDXCLIN,SDATE)) Q:SDATE=""!(SDUP)  D
 ......I $D(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXNM,SDXCLIN,SDATE)) S SDXSTOP=$P(^TMP(NAMSPC1,$J,SDXDIV,SDXREM,SDXNM,SDXCLIN,SDATE),"^",6) D PRT
 Q
 ;
 ;
PRT ;Print  report
 N SDX
 D COUNT^SDMHNS
 I '$D(SDXFLG(SDXDIV)) D HEAD^SDMHNS  S SDXFLG(SDXDIV)=1,SDXFLG(SDXDIV,SDXCLIN)=1
 I $D(SDXFLG(SDXDIV)),'$D(SDXFLG(SDXDIV,SDXCLIN)) S SDX=$$SETSTR("",X,1,80) D SET1(SDX) D HEAD1^SDMHNS S SDXFLG(SDXDIV,SDXCLIN)=1
 N SDXNODE,SDXID,SDXDT,SDXSTAT,SDXSORT1,SDXSORT2,SDXCLIEN,SDX,SDDSS
 S SDXSORT1=$S(SDTL="MEN":SDXREM,SDTL="STOP":SDXSTOP,1:SDXCLIN)
 S SDXSORT2=$S(SDTL="CLIN":SDXSTOP,1:SDXCLIN)
 S SDXNODE=$G(^TMP(NAMSPC1,$J,SDXDIV,SDXSORT1,SDXNM,SDXSORT2,SDATE))
 S SDXDFN=$P(SDXNODE,"^",1) Q:SDXDFN']""
 S SDXID=$P(SDXNODE,"^",4)
 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)
 I '$D(SDXFLG(SDXDIV,SDXCLIN)) D HEAD1^SDMHNS  S SDXFLG(SDXDIV,SDXCLIN)=1
 S SDXDT=$$FMTE^XLFDT(SDXDT,"5P")
 D SET
 S SDX=$$SETSTR(SDCOUNT,X,1,2)_$$SETSTR($P(^DPT(SDXDFN,0),"^",1),X,4,20)_$$SETSTR(SDXID,X,2,4)_$$SETSTR(SDXDT,X,6,20)_$$SETSTR(SDXCLIN,X,2,15)_$$SETSTR("*"_SDXSTAT,X,2,4) D SET1(SDX) I SDCOUNT=$P($G(TOTAL(SDXDIV,SDXCLIN)),"^",1) S SDCOUNT=0
 ;D PATINFO
 ;D NOK
 ;D EC
 ;D PROV
 ;D MHTC
 D FUT
 ;D RESULTS
 Q
 ;
 ;
SETSTR(W,X,Y,Z) ;SET UP THE STRING
 ;W= String 
 ;X= Variable to set it into
 ;Y= column to set it into
 ;Z= length of the strubg
 S X=$$SETSTR^SDUL1(W,X,Y,Z)
 Q X
SET1(X) ;Sets the XMTEXT global
 S SDLN=SDLN+1,^TMP("SDNS1",$J,SDLN,0)=X Q
SET ;
 S X="" S SDLN=SDLN+1,^TMP("SDNS1",$J,SDLN,0)=X
 Q
 ;
PATINFO ;Patients home, cell and office phones
 N SDPHON,SDX,VAROOT,SDEC6,SDEC5
 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")]"" S SDX=$$SETSTR("Home:  ",X,4,7)_$$HLPHONE^HLFNC(SDPHON("HOME"),,) D SET1(SDX)
 I $D(SDPHON("WORK")),SDPHON("WORK")]"" S SDX=$$SETSTR("Work:  ",X,4,7)_$$HLPHONE^HLFNC(SDPHON("WORK"),,) D SET1(SDX)
 I $D(SDPHON("CELL")),SDPHON("CELL")]"" S SDX=$$SETSTR("Cell:  ",X,4,7)_$$HLPHONE^HLFNC(SDPHON("CELL"),,) D SET1(SDX)
 Q
 ;
 ;
NOK ; Next of Kin information
 N SDNOK,SDNOK2,SDNOKNM,SDNOKNM2,SDNOKR,SDNOKR2,SDNOKPH,SDNOKPH2,SDNOKPO,SDNOKPO2,SDNOKFL,SDX,SDSET,VAOA,VAROOT,SDEC3,SDEC4,X,SDPHON
 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"))
 S SDNOKFL=0
 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")
 S X="",SDX="",SDSET=0
 I $D(SDNOKNM),SDNOKNM]"" D:'SDNOKFL NOKFL S SDX=$$SETSTR("NOK: "_SDNOKNM,X,6,20) S SDSET=1
 I $D(SDNOKNM2),SDNOKNM2]"" D:'SDNOKFL NOKFL S SDX=SDX_$$SETSTR("NOK2: "_SDNOKNM2,X,20,20) S SDSET=1
 I SDSET D SET1(SDX)
 S X="",SDX="",SDSET=0
 I $D(SDNOKR),SDNOKR]"" D:'SDNOKFL NOKFL S SDX=$$SETSTR("Relation: "_SDNOKR,X,6,20) S SDSET=1
 I $D(SDNOKR2),SDNOKR2]""  D:'SDNOKFL NOKFL S SDX=SDX_$$SETSTR("Relation: "_SDNOKR2,X,20,20) S SDSET=1
 I SDSET D SET1(SDX)
 S X="",SDX="",SDSET=0
 I $D(SDNOKPH),SDNOKPH]"" D:'SDNOKFL NOKFL S SDX=$$SETSTR("     Phone: ",X,6,12)_$$SETSTR($$HLPHONE^HLFNC(SDNOKPH,,),X,1,15) S SDSET=1
 I $D(SDNOKPH2),SDNOKPH2]"" D:'SDNOKFL NOKFL S SDX=SDX_$$SETSTR("     Phone: ",X,13,12)_$$SETSTR($$HLPHONE^HLFNC(SDNOKPH2,,),X,1,15) S SDSET=1
 I SDSET D SET1(SDX)
 S X="",SDX="",SDSET=0
 I $D(SDNOKPO),SDNOKPO]"" D:'SDNOKFL NOKFL S SDX=$$SETSTR("Office Phone: ",X,6,14)_$$SETSTR($$HLPHONE^HLFNC(SDNOKPO,,),X,1,13) S SDSET=1
 I $D(SDNOKPO2),SDNOKPO2]"" D:'SDNOKFL NOKFL S SDX=SDX_$$SETSTR("Office Phone: ",X,13,14)_$$SETSTR($$HLPHONE^HLFNC(SDNOKPO2,,),X,1,15) S SDSET=1
 I SDSET D SET1(SDX)
 Q
 ;
 ;
NOKFL S SDX=$$SETSTR("   Next of Kin: ",X,1,16) D SET1(SDX) S SDNOKFL=1,SDX=""
 Q
 ;
 ;
EC ;display emergency contact information
 N SDEC1,SDEC2,SDX,DFN,X,SDPHON,VAROOT,VAOA
 Q:'$G(SDXDFN)
 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
 .S X=""
 . I $D(SDEC1)!($D(SDEC2)) S SDX=$$SETSTR("   Emergency Contact: ",X,1,50) D SET1(SDX)
 . ;Contacts name and realtionship
 . S SDX=""
 . I SDEC1(9)]"" S SDX=$$SETSTR("E-Cont.: ",X,6,10)_$E(SDEC1(9),1,20)
 . I SDEC2(9)]"" S SDX=SDX_$$SETSTR("E2-Cont.: ",X,20,10)_$E(SDEC2(9),1,20)
 . I SDX]"" D SET1(SDX)
 . S SDX=""
 . I SDEC1(10)]"" S SDX=$$SETSTR("Relation: ",X,6,10)_SDEC1(10)
 . I SDEC2(10)]"" S SDX=SDX_$$SETSTR("Relation: ",X,25,10)_SDEC2(10)
 . I SDX]"" D SET1(SDX)
 . ;ECs address lines 1, 2 and 3
 . S SDX=""
 . I SDEC1(1)]"" S SDX=$$SETSTR(SDEC1(1),X,15,20)
 . I SDEC2(1)]"" S SDX=SDX_$$SETSTR(SDEC2(1),X,20,20)
 . I SDX]"" D SET1(SDX)
 . S SDX=""
 . I SDEC1(2)]"" S SDX=$$SETSTR(SDEC1(2),X,15,20)
 . I SDEC2(2)]"" S SDX=SDX_$$SETSTR(SDEC2(2),X,20,20)
 . I SDX]"" D SET1(SDX)
 . S SDX=""
 . I SDEC1(3)]"" S SDX=$$SETSTR(SDEC1(3),X,15,20)
 . I SDEC2(3)]"" S SDX=SDX_$$SETSTR(SDEC2(3),X,20,20)
 . I SDX]"" D SET1(SDX)
 . S SDX=""
 . ;Emergency Contact 1 City, State an Zip+4
 . I SDEC1(4)]"" D
 . . S SDX=""
 . . N SDZ
 . . S SDZ=$L(SDEC1(4))
 . . S SDX=$$SETSTR(SDEC1(4),X,15,SDZ)
 . . I SDEC1(5)]"" S SDX=SDX_", "_$$GET1^DIQ(5,+SDEC1(5),1)
 . . S SDX=SDX_"  "_$P(SDEC1(11),"^",2)
 . ;Emergency Contact 2 City State and Zip+4
 . I SDEC2(4)]"" D
 . . S SDZ=$L(SDEC2(4))
 . . S SDX=SDX_$$SETSTR(SDEC2(4),X,23,SDZ)
 . . I SDEC2(5)]"" S SDX=SDX_", "_$$GET1^DIQ(5,+SDEC2(5),1)
 . . S SDX=SDX_"  "_$P(SDEC2(11),"^",2)
 . I SDX]"" D SET1(SDX)
 . ;Home and work phones
 . S SDX=""
 . I SDEC1(8)]"" S SDX=$$SETSTR("Phone: ",X,6,8)_$$HLPHONE^HLFNC(SDEC1(8),,)
 . I SDEC2(8)]"" S SDX=SDX_$$SETSTR("Phone: ",X,20,8)_$$HLPHONE^HLFNC(SDEC2(8),,)
 . I SDX]"" D SET1(SDX)
 . S SDX=""
 . I SDPHON("E-WORK")]"" S SDX=$$SETSTR("Work Phone: ",X,6,11)_$$HLPHONE^HLFNC(SDPHON("E-WORK"),,)
 . I SDPHON("E2-WORK")]"" S SDX=SDX_$$SETSTR("Work Phone: ",X,17,12)_$$HLPHONE^HLFNC(SDPHON("E2-WORK"),,)
 .I SDX]"" D SET1(SDX)
 D KVAR^VADPT
 Q
 ;
 ;
PROV ;Clinic Default Provider
 N SDPNUM,SDPNODE,SDX
 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 SDX=""
 .S SDX=$$SETSTR("Provider:  ",X,4,11)_($P(^VA(200,$P(SDPNODE,"^",1),0),"^",1))
 .D SET1(SDX)
 Q
 ;
 ;
MHTC ;Mental Health Treatment Coordinator
 S SDX=""
 S SDX=$$SETSTR("MHTC:  ",X,4,11)
 D SET1(SDX)
 Q
 ;
 ;
FUT ; FUTURE SCHEDULED APPTS.
 N SDARRAY,SDCOUNT,SDX,X1,X2,X
 ;Find Scheduled apointments witin 30 days using scheduling API
 S X1=DT,X2=14 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
 . S SDX="",X=""
 . S SDX=$$SETSTR("         Future Scheduled Appointments:  ",X,1,40) D SET1(SDX)
 . N SDFA,SDFNODE,SDFUTDT  ;,SDFUTCNT
 . ;S SDFUTCNT=0  ;List up to 6 future appts for one patient
 . S SDFA=0 F  S SDFA=$O(^TMP($J,"SDAMA301",SDXDFN,SDFA)) Q:SDFA=""  D
 ..S (SDX,X)=""
 ..S SDFUTDT=$$FMTE^XLFDT(SDFA,"5P") S SDFNODE=^TMP($J,"SDAMA301",SDXDFN,SDFA)
 ..S SDX=$$SETSTR(SDFUTDT,X,10,20)_$$SETSTR($P($P(SDFNODE,"^",2),";",2),X,7,30)
 ..D SET1(SDX)
 .Q
 I SDCOUNT'>0 D
 .S (SDX,X)=""
 .S SDX=$$SETSTR("     Future Scheduled Appointments: NO APPOINTMENTS SCHEDULED WITHIN 30 DAYS",X,1,80) D SET1(SDX)
 K ^TMP($J,"SDAMA301")
 Q
 ;
 ;
RESULTS ;Reminder information
 N SDX
 S (SDX,X)=""
 S SDX=$$SETSTR("Results: ",X,4,9) D SET1(SDX)
 Q
 ;
 ;
PID(DFN) ; Return PID
 ; INPUT  - DFN
 ; OUTPUT - PID or 'UNKNOWN'
 D PID^VADPT6
 Q $S(VA("BID")]"":VA("BID"),1:"UNKNOWN")
 ;