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

MDWORSR.m

Go to the documentation of this file.
  1. MDWORSR ; HOIFO/NCA - Daily Schedule Studies;Apr 4, 2018@11:53 ; 2/11/19 10:35am
  1. ;;1.0;CLINICAL PROCEDURES;**14,11,21,20,54,69**;Apr 01,2004;Build 2
  1. ; Reference IA# 2263 [Supported] XPAR calls
  1. ; 3067 [Private] Read fields in Consult file (#123) w/FM
  1. ; 3468 [Subscription] Call GMRCCP
  1. ; 3869 [Subscription] SDAMA202 calls
  1. ; 10035 [Supported] Patient File Access
  1. ; 10103 [Supported] XLFDT calls
  1. ;
  1. EN1 ; Entry Point to process scheduled studies
  1. N MDACL,MDCON,MDCV,MDERR,MDFDA,MDHOLD,MDKK,MDL,MDL1,MDLSP,MDMAXD,MDNOW,MDSTAT,MDV,MDX,MDXY
  1. S MDMAXD=DT+.24 K ^TMP("MDACLN",$J)
  1. D GETLST^XPAR(.MDLSP,"SYS","MD CLINIC ASSOCIATION")
  1. F MDKK=0:0 S MDKK=$O(MDLSP(MDKK)) Q:MDKK<1 S MDV=$P($G(MDLSP(MDKK)),"^",2) I +$P(MDV,";",2)>0 S MDACL=+MDV D
  1. .S ^TMP("MDACLN",$J,+MDACL,+$P(MDV,";",2))=+$P(MDV,";",2)
  1. S MDL=DT F S MDL=$O(^MDD(702,"ASD",MDL)) Q:MDL<1!(MDL>MDMAXD) F MDL1=0:0 S MDL1=$O(^MDD(702,"ASD",MDL,MDL1)) Q:MDL1<1 S MDX=$G(^MDD(702,MDL1,0)) D
  1. .K MDFDA
  1. .S MDCON=+$P(MDX,"^",5) Q:'MDCON
  1. .S MDSTAT=$$GET1^DIQ(123,MDCON_",",8,"E")
  1. .Q:MDSTAT="DISCONTINUED"!(MDSTAT="CANCELLED")
  1. .Q:+$P(MDX,"^",9)>0
  1. .S MDIENS=MDL1_",",MDXY=+$P(MDX,"^",4),MDHOLD="" I MDXY D
  1. ..S MDHOLD=$P($G(^MDD(702,+MDL1,0)),"^",7),MDNOW=$$NOW^XLFDT()
  1. ..S $P(^MDD(702,+MDL1,0),"^",7)=MDHOLD
  1. .S MDCV=$P(MDHOLD,";",3)
  1. .I +MDXY&(+MDCV) Q:$G(^TMP("MDACLN",$J,+MDCV,+MDXY))=""
  1. .S MDHL7=$$SUB^MDHL7B(MDL1)
  1. .I +MDHL7=-1 S MDFDA(702,MDIENS,.09)=2,MDFDA(702,MDIENS,.08)=$P(MDHL7,U,2)
  1. .I +MDHL7=1 S MDFDA(702,MDIENS,.02)=$$NOW^XLFDT(),MDFDA(702,MDIENS,.09)=5,MDFDA(702,MDIENS,.08)=""
  1. .D:$D(MDFDA) FILE^DIE("","MDFDA","MDERR")
  1. .S MDXY=+$P(MDX,"^",4) Q:'MDXY
  1. .I $P(^MDS(702.01,MDXY,0),U,6)=2 D Q ; Renal Check-In
  1. ..D CP^MDKUTL(+MDIENS)
  1. ..S:$G(MDHOLD)'="" MDFDA(702,MDIENS,.07)=MDHOLD
  1. ..S MDFDA(702,MDIENS,.09)=5
  1. ..D FILE^DIE("","MDFDA","MDERR")
  1. K ^TMP("MDACLN",$J)
  1. Q
  1. CLINICPT ; Check-in CP study with multiple results
  1. N MD,MDCDT,MDCL,MDCOM,MDCON,MDDT,MDDX,MDEND,MDERR,MDFDA,MDHEMO,MDHL7,MDIEN,MDIENS,MDK,MDLP,MDLST,MDMULT,MDNODE,MDNUM,MDPT,MDRET,MDSCHD,MDVSTR,MDY,MDY1,MDYR,X,X1,X2
  1. N MDATYP,MDHOLD,MDLST1,MDLST2,MDNEW,MDT,MDY3,MDY4 S MDDT=DT\1,MDEND=DT+.24 N MDINP K ^TMP($J,"SDAMA202","GETPLIST"),^TMP("MDSTATUS",$J) S MDCOM=0,MDHOLD=""
  1. K ^TMP("MDMULT",$J),^TMP("MDCLINIC",$J),^TMP("MDLST",$J)
  1. S MDNUM=$$GET^XPAR("SYS","MD COMPL PROC DISPLAY DAYS",1)
  1. I +MDNUM>0 S X1=DT,X2=-MDNUM D C^%DTC S MDCOM=X
  1. D GETLST^XPAR(.MDLST,"SYS","MD CLINIC ASSOCIATION")
  1. F MDLP=0:0 S MDLP=$O(^MDD(702,"AS",0,MDLP)) Q:MDLP<1 D
  1. .S MDY=$G(^MDD(702,MDLP,0)) Q:+$P(MDY,"^",9)>0
  1. .Q:$P(MDY,"^",7)'=""
  1. .Q:'+$P(MDY,"^",5)!($P(MDY,"^",6)'="")
  1. .Q:'+MDY
  1. .I '+$G(^TMP("MDSTATUS",$J,+MDY,+$P(MDY,"^",4))) S ^TMP("MDSTATUS",$J,+MDY,+$P(MDY,"^",4))=+MDLP
  1. .Q
  1. ; Combine clinics with multiple procedures to regular clinics
  1. S MDLST2=$S(+MDLST>0:MDLST,1:0)
  1. ; Match new studies with 0 status to appointments
  1. N MDXX K MDY F MDK=0:0 S MDK=$O(MDLST(MDK)) Q:MDK<1 S MDY=$P($G(MDLST(MDK)),"^",2) I +$P(MDY,";",2)>0 S MDCL=+MDY D
  1. .S:$G(^TMP("MDCLINIC",$J,+MDCL))="" ^TMP("MDCLINIC",$J,+MDCL)=+MDCL
  1. .S ^TMP("MDLST",$J,+MDCL,+$P(MDY,";",2))=+$P(MDY,";",2)
  1. .S MDMULT=+$$GET1^DIQ(702.01,+$P(MDY,";",2)_",",.12,"I")
  1. .S MDHEMO=+$$GET1^DIQ(702.01,+$P(MDY,";",2)_",",.06,"I")
  1. .Q:MDMULT'=1&(MDHEMO<2)
  1. .S ^TMP("MDMULT",$J,+MDK)=+MDCL_";"_+$P(MDY,";",2)
  1. .Q
  1. K MDLST,MDY F MDK=0:0 S MDK=$O(^TMP("MDCLINIC",$J,MDK)) Q:MDK<1 S MDY=MDK D
  1. .K ^TMP($J,"SDAMA202","GETPLIST") S MDCL=+MDY
  1. .D GETPLIST^SDAMA202(+MDY,"1;4;3","R",MDDT,MDEND,.MDRET,"")
  1. .F MD=0:0 S MD=$O(^TMP($J,"SDAMA202","GETPLIST",MD)) Q:'MD D
  1. ..S MDY1=+$G(^TMP($J,"SDAMA202","GETPLIST",MD,4)) Q:MDY1<1
  1. ..S MDSCHD=+$G(^TMP($J,"SDAMA202","GETPLIST",MD,1))
  1. ..S MDATYP=$G(^TMP($J,"SDAMA202","GETPLIST",MD,3)) Q:MDATYP=""
  1. ..Q:"RINT"'[MDATYP
  1. ..S MDT=MDK,MDDX=+$$MATCH(+MDY1,MDT) Q:'MDDX
  1. ..S MDMULT=+$$GET1^DIQ(702,+MDDX,".04:.12","I")
  1. ..S MDHEMO=+$$GET1^DIQ(702,+MDDX,".04:.06","I"),MDIENS=+MDDX_","
  1. ..S MDFDA(702,MDIENS,.02)=$$NOW^XLFDT()
  1. ..S MDFDA(702,MDIENS,.07)="A;"_MDSCHD_";"_MDCL
  1. ..S MDFDA(702,MDIENS,.14)=MDSCHD
  1. ..D:$D(MDFDA) FILE^DIE("","MDFDA","MDERR") K MDFDA
  1. ..I MDHEMO=2 S MDHOLD=$P($G(^MDD(702,+MDIENS,0)),"^",7),MDNEW=$$NOW^XLFDT(),$P(^MDD(702,+MDIENS,0),"^",7)=MDSCHD
  1. ..S MDHL7=$$SUB^MDHL7B(+MDIENS)
  1. ..I +MDHL7=-1 S MDFDA(702,MDIENS,.09)=2,MDFDA(702,MDIENS,.08)=$P(MDHL7,U,2)
  1. ..I +MDHL7=1 S MDFDA(702,MDIENS,.09)=5,MDFDA(702,MDIENS,.08)=""
  1. ..D:$D(MDFDA) FILE^DIE("","MDFDA","MDERR")
  1. ..Q:'+$G(MDIENS)
  1. ..I MDHEMO=2 D CP^MDKUTL(+MDIENS) S:$G(MDHOLD)'="" MDFDA(702,+MDIENS_",",.07)=MDHOLD S MDFDA(702,+MDIENS_",",.09)=5 D FILE^DIE("","MDFDA","MDERR") K MDFDA
  1. ..Q
  1. .Q
  1. ; Match the rest of appointments with previous studies
  1. N MDGET,MDINST S X1=DT,X2=-365 D C^%DTC S MDCDT=X
  1. K MDY F MDK=0:0 S MDK=$O(^TMP("MDMULT",$J,MDK)) Q:MDK<1 S MDY=$G(^(MDK)) I +$P(MDY,";",2)>0 S MDCL=+MDY D
  1. .K ^TMP($J,"SDAMA202","GETPLIST")
  1. .D GETPLIST^SDAMA202(+MDY,"1;4;3","R",MDDT,MDEND,.MDRET,"")
  1. .F MD=0:0 S MD=$O(^TMP($J,"SDAMA202","GETPLIST",MD)) Q:'MD D
  1. ..S MDINP=0
  1. ..S MDY1=+$G(^TMP($J,"SDAMA202","GETPLIST",MD,4)) Q:MDY1<1
  1. ..S MDSCHD=+$G(^TMP($J,"SDAMA202","GETPLIST",MD,1))
  1. ..S MDATYP=$G(^TMP($J,"SDAMA202","GETPLIST",MD,3))
  1. ..Q:"RINT"'[MDATYP
  1. ..S MDPT=MDY1 Q:+$$GSTUDY(MDPT,MDSCHD)
  1. ..S MDDX=$$GETC(MDPT,+$P(MDY,";",2)) Q:'+MDDX
  1. ..S MDNODE=$G(^MDD(702,+MDDX,0))
  1. ..S:$G(^DPT(MDY1,.105))'="" MDINP=1
  1. ..S MDCON=$P(MDNODE,"^",5) Q:'MDCON
  1. ..S MDVSTR=$P(MDNODE,"^",7) Q:MDVSTR=""
  1. ..S MDMULT=+$$GET1^DIQ(702,+MDDX,".04:.12","I")
  1. ..S MDHEMO=+$$GET1^DIQ(702,+MDDX,".04:.06","I")
  1. ..S MDYR=$S(MDMULT<1:MDCOM,1:MDCDT)
  1. ..Q:$P(MDNODE,"^",2)<MDYR
  1. ..Q:'$P(MDNODE,"^",9)
  1. ..Q:$P(MDNODE,"^",9)>3
  1. ..Q:$P(MDVSTR,";",2)=MDSCHD
  1. ..S MDINST=+$$GINST(+$P(MDNODE,"^",4)) Q:'MDINST
  1. ..K MDFDA,MDERR,MDIEN
  1. ..S MDFDA(702,"+1,",.01)=MDY1
  1. ..S MDFDA(702,"+1,",.02)=$$NOW^XLFDT()
  1. ..S MDFDA(702,"+1,",.03)=$P(MDNODE,"^",3)
  1. ..S MDFDA(702,"+1,",.04)=$P(MDNODE,"^",4)
  1. ..S MDFDA(702,"+1,",.05)=MDCON
  1. ..S MDFDA(702,"+1,",.07)="A;"_MDSCHD_";"_MDCL
  1. ..S MDFDA(702,"+1,",.11)=+MDINST
  1. ..S MDFDA(702,"+1,",.14)=MDSCHD
  1. ..D UPDATE^DIE("","MDFDA","MDIEN","MDERR") Q:$D(MDERR) K MDFDA
  1. ..S MDIENS=MDIEN(1)_"," I MDHEMO=2 S MDHOLD=$P($G(^MDD(702,MDIEN(1),0)),"^",7),MDNOW=$$NOW^XLFDT(),$P(^MDD(702,MDIEN(1),0),"^",7)=MDSCHD
  1. ..S MDHL7=$$SUB^MDHL7B(MDIEN(1))
  1. ..I +MDHL7=-1 S MDFDA(702,MDIENS,.09)=2,MDFDA(702,MDIENS,.08)=$P(MDHL7,U,2)
  1. ..I +MDHL7=1 S MDFDA(702,MDIENS,.09)=5,MDFDA(702,MDIENS,.08)=""
  1. ..D:$D(MDFDA) FILE^DIE("","MDFDA","MDERR")
  1. ..Q:'+$G(MDIENS)
  1. ..I MDHEMO=2 D CP^MDKUTL(+MDIENS) K MDFDA S:$G(MDHOLD)'="" MDFDA(702,+MDIENS_",",.07)=MDHOLD S MDFDA(702,+MDIENS_",",.09)=5 D FILE^DIE("","MDFDA","MDERR")
  1. K ^TMP($J,"SDAMA202","GETPLIST"),^TMP("MDSTATUS",$J),MDFDA
  1. K ^TMP("MDCLINIC",$J),^TMP("MDMULT",$J),^TMP("MDLST",$J)
  1. Q
  1. GETC(MDPAT,MDDA) ; Get consult date
  1. N MDX,MDCF S MDCF=0 K ^TMP("MDTMP",$J) D CPLIST^GMRCCP(MDPAT,+MDDA,$NA(^TMP("MDTMP",$J)))
  1. S MDX=$O(^TMP("MDTMP",$J,""),-1) Q:'+MDX 0
  1. I "saprc"'[$P($G(^TMP("MDTMP",$J,MDX)),U,4) S MDX=$O(^TMP("MDTMP",$J,MDX),-1) Q:'+MDX 0
  1. I "saprc"[$P($G(^TMP("MDTMP",$J,MDX)),U,4) S MDCF=$P($G(^TMP("MDTMP",$J,MDX)),U,5)_"^"_$P($G(^TMP("MDTMP",$J,MDX)),U,1)
  1. K ^TMP("MDTMP",$J)
  1. Q $S(+MDCF:+$O(^MDD(702,"ACON",+MDCF,""),-1)_"^"_$P(MDCF,"^",2)_"^"_+MDCF_"^"_$P(MDCF,"^",6),1:0)
  1. GINST(MDDA) ; Get instrument from CP Definition
  1. N MDIN,MDINT,Y1 S (MDINT,Y1)=0
  1. F MDIN=0:0 S MDIN=$O(^MDS(702.01,+MDDA,.1,MDIN)) Q:MDIN<1!(+Y1) S MDINT=+$G(^(MDIN,0)) I +$$GET1^DIQ(702.09,MDINT,".13","I") S Y1=MDINT
  1. Q Y1
  1. GSTUDY(MDPAT,MDDA) ;Get study for scheduled date/time
  1. N MDIN,Y1 S Y1=0
  1. F MDIN=0:0 S MDIN=$O(^MDD(702,"ASD",MDDA,MDIN)) Q:MDIN<1!(Y1>0) D
  1. .S:$P($G(^MDD(702,MDIN,0)),"^")=MDPAT Y1=1
  1. Q Y1
  1. GPRO(MDPAT,MDCLIN) ; Get procedure for study
  1. N MDX,MDCF,MDCFX S MDCF="" K ^TMP("MDTMP",$J) D CPLIST^GMRCCP(MDPAT,,$NA(^TMP("MDTMP",$J)))
  1. S MDX=0 F S MDX=$O(^TMP("MDTMP",$J,MDX)) Q:'MDX!(MDCF'="") D:"sap"[$P(^(MDX),U,4)
  1. .S MDCFX=$G(^TMP("MDTMP",$J,MDX)) Q:'+$G(^TMP("MDLST",$J,MDCLIN,+$P(MDCFX,"^",6)))
  1. .Q:+$O(^MDD(702,"ACON",+$P(MDCFX,"^",5),0)) S MDCF=MDCFX Q
  1. K ^TMP("MDTMP",$J)
  1. Q $S(MDCF'="":MDCF,1:0)
  1. MATCH(MDPAT,MDCLIN) ; Match study to appointment
  1. N MDI,MDY2 S MDY2=0
  1. F MDI=0:0 S MDI=$O(^TMP("MDSTATUS",$J,MDPAT,MDI)) Q:MDI<1!(+MDY2) D
  1. .I +$G(^TMP("MDLST",$J,MDCLIN,MDI)) S MDY2=+$G(^TMP("MDSTATUS",$J,MDPAT,MDI))
  1. Q MDY2
  1. ADD(MDPAT,MDY3,MDY4,MDCLIN,MDSC) ; Add study, if none exist
  1. N MDFDA,MDERR,MDIENS,MDP,MDPS
  1. Q:'MDY3
  1. K MDFDA,MDERR,MDIENN
  1. S MDP=$O(^MDD(702,"B",MDPAT,0)),MDPS=$G(^MDD(702,+MDP,0))
  1. S MDFDA(702,"+1,",.01)=MDPAT
  1. S MDFDA(702,"+1,",.02)=$$NOW^XLFDT()
  1. S MDFDA(702,"+1,",.03)=$S(+$P(MDPS,"^",3):$P(MDPS,"^",3),1:DUZ)
  1. S MDFDA(702,"+1,",.04)=+MDY3
  1. S MDFDA(702,"+1,",.05)=+MDY4
  1. S MDFDA(702,"+1,",.07)="A;"_MDSC_";"_MDCLIN
  1. S MDFDA(702,"+1,",.11)=+$$GINST(+MDY3)
  1. D UPDATE^DIE("","MDFDA","MDIENN","MDERR") Q:$D(MDERR) 0
  1. K MDFDA
  1. Q MDIENN(1)