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

MMRSCRE2.m

Go to the documentation of this file.
MMRSCRE2 ;TCK - Print CRE Report Cont. (Contains functions to collect patient movements) ; 3/3/17 10:37am
 ;;1.0;MDRO PROGRAM TOOLS;**4,5**;Jun 01, 2016;Build 146
 ;
GETMOVE ;Collects ward movements for patients that were admitted or discharged in date range.
 N DUPLOC,MMRSLOC2
 D GETADM(LOC)
 ;
GETADM(LOC) ;
 N TT,MOVDT,MOVIFN,TRANTYPE,INWARD,INDATE,INIFN,INTT,OUTDATE,OUTIFN,OUTTT,NEXTIEN,LOCNAME,VAIP,INLOC
 N OUTWARD,PREVWARD
 F TT=1,2 S MOVDT=STRTDT-.0000001 F  S MOVDT=$O(^DGPM("ATT"_TT,MOVDT)) Q:(MOVDT>ENDDT)!('MOVDT)  D
 .S MOVIFN="" F  S MOVIFN=$O(^DGPM("ATT"_TT,MOVDT,MOVIFN)) Q:'MOVIFN  D
 ..D KVA^VADPT S DFN=$P($G(^DGPM(MOVIFN,0)),"^",3),VAIP("E")=MOVIFN D IN5^VADPT
 ..S TRANTYPE=$$TRANTYPE(+VAIP(4),+VAIP(2),VAIP(1),DFN)
 ..S PREVWARD=$P(TRANTYPE,U,2)
 ..I PREVWARD="" S PREVWARD=+VAIP(15,4)
 ..S TRANTYPE=$P(TRANTYPE,U,1)
 ..I TRANTYPE<1!(TRANTYPE=3) Q
 ..S INWARD=+VAIP(5),WARD=$$GET1^DIQ(42,INWARD,.01,"E")
 ..I $G(INWARD)>0 D
 ...S HSPLC=$$GET1^DIQ(42,INWARD,44,"I")
 ...S DIV=$$GET1^DIQ(44,HSPLC,3.5,"E")
 ...S DIVS=$$GET1^DIQ(44,HSPLC,3.5,"I")
 ...S DIVID=$$GET1^DIQ(40.8,DIVS,1,"I"),LOC=$$GET1^DIQ(40.8,DIVS,.01,"I")
 ..;IS THIS WARD EXCLUDED FROM THIS REPORT
 ..Q:DIV'=LOC
 ..S LOCNAME=LOC
 ..S WRDLOC(INWARD)=""
 ..I TRANTYPE=2,'$$CNGWARD(LOC,PREVWARD,INWARD) Q
 ..;SET GLOBAL
 ..S INDATE=+VAIP(3)
 ..S INIFN=MOVIFN
 ..S INTT=TRANTYPE
 ..S ADT=$$GET1^DIQ(405,MOVIFN,.04,"E")
 ..S (OUTDATE,OUTIFN,OUTTT)=""
 ..F  Q:(VAIP(16)="")!(OUTIFN)  D
 ...S TRANTYPE=$$TRANTYPE(+VAIP(16,3),+VAIP(16,2),VAIP(16),DFN)
 ...S OUTWARD=$P(TRANTYPE,U,2)
 ...S NEXTIEN=$P(TRANTYPE,U,3)
 ...S TRANTYPE=$P(TRANTYPE,U,1)
 ...I OUTWARD="" S OUTWARD=+VAIP(16,4)
 ...I TRANTYPE=3 S OUTDATE=+VAIP(16,1),OUTIFN=VAIP(16),OUTTT=3
 ...;I TRANTYPE=2,$$CNGWARD(LOC,INWARD,OUTWARD) S OUTDATE=+VAIP(16,1),OUTIFN=VAIP(16),OUTTT=2
 ...Q:OUTIFN
 ...I NEXTIEN="" S NEXTIEN=VAIP(16)
 ...D KVA^VADPT
 ...S VAIP("E")=NEXTIEN
 ...D IN5^VADPT
 ..S INLOC=$G(INWARD)
 ..S PATNM=$$GET1^DIQ(2,DFN,.01,"E")
 ..S SSN=$$GET1^DIQ(2,DFN,.09,"E"),LAST4=$E(SSN,6,9)
 ..S MASMOV=$$GET1^DIQ(405.1,TRANTYPE,.04,"E")
 ..S ^TMP($J,"MMRSCRE","D",LOCNAME,DFN,INDATE)=INLOC_U_DFN_U_INDATE_U_INIFN_U_INTT_U_WARD_U_PATNM_U_LAST4_U_INDATE_U_OUTDATE
 ..;S ^TMP($J,"MMRSCRE","DETAIL",LOCNAME,INDATE)=WARD_U_PATNM_U_LAST4_U_INDATE
 D KVA^VADPT
 Q
CNGWARD(LOC,WARD1,WARD2) ;Did patient change wards?
 I +$G(LOC)=0 S LOC=$$GETLOC(WARD1,.MMRSLOC2)
 I $D(^MMRS(104.3,LOC,1,"B",WARD1)),$D(^MMRS(104.3,LOC,1,"B",WARD2)) Q 0
 Q 1
EXCWARD(LOC,WARD) ;Is this ward excluded from the reports?
 I +$G(LOC)=0 S LOC=$$GETLOC(WARD,.MMRSLOC2)
 I LOC=0 Q 1
 I $D(^MMRS(104.3,LOC,1,"B",WARD)) Q 0
 Q 1
DUPLOC(LOC,LCTNS) ;
 N RSLT,WARD,LOC2
 S RSLT=0
 S WARD=0 F  S WARD=$O(^MMRS(104.3,LOC,1,"B",WARD)) Q:'WARD  D
 .S LOC2=0 F  S LOC2=$O(LCTNS(LOC2)) Q:'LOC2  D
 ..Q:LOC2=LOC
 ..I $D(^MMRS(104.3,LOC2,1,"B",WARD)) S RSLT=1
 Q RSLT
GETLOC(WARD,LCTNS) ;
 N RSLT,LOC
 S RSLT=0
 S LOC=0 F  S LOC=$O(LCTNS(LOC)) Q:'LOC!(RSLT)  D
 .I $D(^MMRS(104.3,LOC,1,"B",WARD)) S RSLT=LOC
 Q RSLT
TRANTYPE(MOVTYPE,TRANTYPE,MOVIEN,DFN) ;
 I MOVTYPE=46!(MOVTYPE=5)!(MOVTYPE=6)!(MOVTYPE=7)!(MOVTYPE=47)!(MOVTYPE=27)!(MOVTYPE=33)!(MOVTYPE=3)!(MOVTYPE=22) Q -1 ;MIA/LMT - Removed MOVTYPE 29 ;4/15/10
 I MOVTYPE=42!(MOVTYPE=20)!(MOVTYPE=1)!(MOVTYPE=45)!(MOVTYPE=23)!(MOVTYPE=25)!(MOVTYPE=26) Q -1
 I MOVTYPE=2!(MOVTYPE=43)!(MOVTYPE=13) Q 3
 I MOVTYPE=14!(MOVTYPE=24)!(MOVTYPE=44) Q 1
 S TRANTYPE=$$CHKOBS^MMRSIPC2(DFN,MOVIEN,TRANTYPE)
 Q TRANTYPE
 ;
END ;
 K ADT,DIV,DIVID,DIVS,ENDDT,HLPLC,LAST4,MASMOV,PATNM,SSN
 K STRTDT,WRDLOC,HSPLC
 Q
 ;