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

APCLSMUN.m

Go to the documentation of this file.
APCLSMUN ; IHS/CMI/LAB - NIGHTLY MY SYNDROMIC SURV EXPORT
 ;;3.0;IHS PCC REPORTS;**22,23,24,25,26,27,28,29,30**;FEB 05, 1997;Build 27
 ;
 ;
START ;
 ;MUS SYNDROMIC SURV EXPORT
 ;runs nightly and should be scheduled at 12:05am
 ;gathers all ER and URGENT CARE visits that were modified since the last export
 ;1st run goes back 24 hours
 ;
 ;
 D EN^XBVK("APCL")
 S APCLSITE=$P($G(^AUTTSITE(1,0)),U,1)
 I DUZ(2)'=APCLSITE Q  ;MUST BE SCHEDULED AS MAIN SITE
 S APCLDBID=$$GET1^DIQ(9999999.06,APCLSITE,.32)
 S APCL1ST=$P($G(^APCLILIC(1,0)),U,6)
 S APCLLAST="",APCLEXTY="R"
 ;FIND LAST LOG ENTRY
 S X=0 F  S X=$O(^APCLMUSS(X)) Q:X'=+X  I $P(^APCLMUSS(X,0),U,7)="R" S APCLLAST=X
 I 'APCLLAST D  I 1
 .S APCLBD=$$FMADD^XLFDT(DT,-1)
 .S APCLED=$$FMADD^XLFDT(DT,-1)
 E  D
 .S APCLL=$P(^APCLMUSS(APCLLAST,0),U,4)  ;LAST END
 .I APCL1ST S APCLBD=$$FMADD^XLFDT(APCLL,1)
 .I 'APCL1ST S APCLBD=$$FMADD^XLFDT(APCLL,1)
 .S APCLED=$$FMADD^XLFDT(DT,-1)	;
PROC ;EP - called from xbdbque
 K ^XTMP("APCMUSS",$J)
 ;CREATE LOG ENTRY
 S X=$$NOW^XLFDT(),DIC(0)="L",DIC("DR")=".02////"_APCLSITE_";.03////"_APCLBD_";.04////"_APCLED_";.07///"_APCLEXTY,DIC="^APCLMUSS(" K DO,D0 D FILE^DICN K DA,DIC
 I Y=-1 Q
 S APCLLOG=+Y
 ;
 S APCLVD=$$FMADD^XLFDT(APCLBD,-1)_".9999"
 F  S APCLVD=$O(^AUPNVSIT("ADLM",APCLVD)) Q:APCLVD'=+APCLVD!($P(APCLVD,".")>APCLED)  D
 .S APCLV=0 F  S APCLV=$O(^AUPNVSIT("ADLM",APCLVD,APCLV)) Q:APCLV'=+APCLV  D
 ..Q:'$D(^AUPNVSIT(APCLV,0))
 ..Q:$P(^AUPNVSIT(APCLV,0),U,11)
 ..S APCLRS=$S($D(^APCLMUSS("C",APCLV)):"M",1:"A")
 ..D PROC1
 ;NOW GO BACK THROUGH ADLM AND FIND ANY H WITH AN ER
 S APCLVD=$$FMADD^XLFDT(APCLBD,-1)_".9999"
 F  S APCLVD=$O(^AUPNVSIT("ADLM",APCLVD)) Q:APCLVD'=+APCLVD!($P(APCLVD,".")>APCLED)  D
 .S APCLV=0 F  S APCLV=$O(^AUPNVSIT("ADLM",APCLVD,APCLV)) Q:APCLV'=+APCLV  D
 ..Q:'$D(^AUPNVSIT(APCLV,0))
 ..Q:$P(^AUPNVSIT(APCLV,0),U,11)
 ..Q:$P(^AUPNVSIT(APCLV,0),U,7)'="H"
 ..S DFN=$P(^AUPNVSIT(APCLV,0),U,5)
 ..Q:DFN=""
 ..Q:'$D(^DPT(DFN,0))
 ..Q:$P(^DPT(DFN,0),U)["DEMO,PATIENT"
 ..Q:$$DEMO^APCLUTL(DFN,"E")
 ..S APCLERV=$$ERV(APCLV) I 'APCLERV Q   ;quit if no ER/UC within 2 days of the H admission date
 ..S APCLRS=$S($D(^APCLMUSS("C",APCLERV)):"M",1:"A")
 ..S ^XTMP("APCLMUSS",$J,APCLERV)=APCLRS_U_APCLV
 ..;I DUZ=2881 W !!,APCLERV,"  H: ",APCLV
 ;	
 ;NOW GO THROUGH AVDEL XREF FOR DELETES SKIP IF THIS IS A FULL EXPORT
 S APCLVD=$$FMADD^XLFDT(APCLBD,-1)_".9999"
 F  S APCLVD=$O(^AUPNVSIT("AVDEL",APCLVD)) Q:APCLVD'=+APCLVD!($P(APCLVD,".")>APCLED)  D
 .;W:'$D(ZTQUEUED) ".",$$FMTE^XLFDT(APCLSD)
 .S APCLV=0 F  S APCLV=$O(^AUPNVSIT("AVDEL",APCLVD,APCLV)) Q:APCLV'=+APCLV  D
 ..I '$D(^APCLMUSS("C",APCLV)) Q  ;never exported so no need to send delete
 ..S APCLRS="D"
 ..D PROC1
 D GENHL7
 ;UPDATE/REINDEX LOG
 S DA=APCLLOG,DIK="^APCLMUSS(" D IXALL^DIK
 S DA=APCLLOG,DIE="^APCLMUSS(",DR=".05///"_APCLVCNT_";.06///"_APCLFILE D ^DIE K DA,DIE
 D PURGE
 D EXIT
 Q
ERV(H) ;is there an ER/UC Ambulatory visit within 2 days
 NEW T,BD,ADMD,D,V,P,APCLVL,X,G
 ;T IS # of minutes in 2 days
 S G=""
 S P=$P(^AUPNVSIT(H,0),U,5)  ;PATIENT
 S ADMD=$$VDTM^APCLV(H)  ;visit date/time in fileman format
 S BD=$$FMADD^XLFDT($P(ADMD,"."),-2)
 K APCLVL
 D ALLV^APCLAPIU(P,$P(BD,"."),$P(ADMD,"."),"APCLVL")
 I '$O(APCLVL(0)) Q ""
 S X=0 F  S X=$O(APCLVL(X)) Q:X'=+X  D
 .S V=$P(APCLVL(X),U,5)
 .Q:$P(^AUPNVSIT(V,0),U,7)'="A"
 .S C=$$CLINIC^APCLV(V,"C")
 .I C'=30,C'=80 Q
 .;Q:$$VDTM^APCLV(V)<(BD
 .Q:$$VDTM^APCLV(V)>ADMD
 .S G=V
 Q G
PROC1 ;
 Q:'$D(^AUPNVSIT(APCLV,0))
 S DFN=$P(^AUPNVSIT(APCLV,0),U,5)
 Q:DFN=""
 Q:'$D(^DPT(DFN,0))
 Q:$P(^DPT(DFN,0),U)["DEMO,PATIENT"
 Q:$$DEMO^APCLUTL(DFN,"E")
 I $P(^AUPNVSIT(APCLV,0),U,7)'="A",APCLRS="A" Q  ;ONLY AMBULATORY
 I $P(^AUPNVSIT(APCLV,0),U,7)'="A",APCLRS="M" S APCLRS="D"  ;WENT BEFORE AND NOW DOESN'T MEET CRITERIA SO DELETE IT
 S APCLCLIN=$$CLINIC^APCLV(APCLV,"C")
 I APCLRS="A",APCLCLIN'=30,APCLCLIN'=80 Q  ;ONLY ER AND URGENT CARE
 I APCLRS="M",APCLCLIN'=30,APCLCLIN'=80 S APCLRS="D"  ;WENT BEFORE AND CLINIC HAS BEEN CHANGED SO SEND DELETE
 S ^XTMP("APCLMUSS",$J,APCLV)=APCLRS
 Q
 ;
GENHL7 ;
 ;LOOP THROUGH ^XTMP("APCLMUSS",$J,visitien)
 ;IF YOU EXPORT THE VISIT SET A VISIT COUNTER APCLVCNT=APCLVCNT+1
 ;S APCLFILE=filenmame used for export
 ;IF YOU EXPORT THE VISIT SET THE LOG 11 MULTIPLE D LOG^APCLSMUN(APCLLOG,VISITIEN,APCLRS)
 N APCLDA,APCLREC,APCLPAT,APCLSEVN
 N IVDT,EVDT,HVST
 S APCLVCNT=0,APCLFILE=""
 Q:'$D(^XTMP("APCLMUSS",$J))
 D HL7^APCLSMU2
 ;DO THE HL7 MSG GENERATION HERE
 Q
LOG(LOG,VISIT,STAT) ;EP - SET VISIT EXPORT MULTIPLE OF LOG
 I '$G(LOG) Q
 I '$D(^APCLMUSS(LOG,0)) Q
 S:'$D(^APCLMUSS(LOG,11,0)) ^APCLMUSS(LOG,11,0)="^9001003.421101PA"
 S ^APCLMUSS(LOG,11,VISIT,0)=VISIT_"^"_STAT
 Q
DATE(D) ;EP
 Q (1700+$E(D,1,3))_$E(D,4,5)_$E(D,6,7)
 ;
JDATE(D) ;EP - get date
 I $G(D)="" Q ""
 NEW A
 S A=$$FMTE^XLFDT(D)
 Q $E(D,6,7)_$$UP^XLFSTR($P(A," ",1))_(1700+$E(D,1,3))
 ;
UID(APCLA) ;Given DFN return unique patient record id.
 I '$G(APCLA) Q ""
 I '$D(^AUPNPAT(APCLA)) Q ""
 ;
 Q $$GET1^DIQ(9999999.06,$P(^AUTTSITE(1,0),U),.32)_$E("0000000000",1,10-$L(APCLA))_APCLA
 ;
EXIT ;clean up and exit
 D EN^XBVK("APCL")
 D ^XBFMK
 K ^XTMP("APCLMUSS",$J)
 Q
 
PURGE ;
 W:'$D(ZTQUEUED) !!,"Now cleaning up host files older than 7 DAYS"
 K APCLFILE,APCLDIR
 S APCLDIR=$P($G(^AUTTSITE(1,1)),"^",2)
 I APCLDIR="" S APCLDIR=$P($G(^XTV(8989.3,1,"DEV")),"^",1)
 I APCLDIR="" Q
 S APCLASU=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),0)),U,10)
 S APCLDT=$$FMADD^XLFDT(DT,-31)
 S APCLDT=$$DATE^APCLSILI(APCLDT)
 S APCLFLST=$$LIST^%ZISH(APCLDIR,"MU2_"_APCLASU_"*",.APCLFILE)
 Q:'$O(APCLFILE(""))
 S APCLX=0 F  S APCLX=$O(APCLFILE(APCLX)) Q:APCLX'=+APCLX  D
 .S D=$P($P(APCLFILE(APCLX),"."),"_",3)
 .I D<APCLDT S N=APCLFILE(APCLX) S APCLM=$$DEL^%ZISH(APCLDIR,N)
 Q
 ;
DATEXP ;-- ask the date range
 D EN^XBVK("APCL")
 S APCLSITE=$P($G(^AUTTSITE(1,0)),U,1)
 I DUZ(2)'=APCLSITE Q  ;MUST BE SCHEDULED AS MAIN SITE
 S APCLDBID=$$GET1^DIQ(9999999.06,APCLSITE,.32)
 S %DT="AE",%DT("A")="Begin Date: "
 D ^%DT
 I Y<0 D EXIT Q
 S APCLBD=+Y
 S %DT="AE",%DT("A")="End Date: "
 D ^%DT
 I Y<0 D EXIT Q
 S APCLED=+Y
 S APCLEXTY="D"
 G PROC
 Q
 ;