VistA-WorldVistAEHR/r/CLINICAL_MONITORING_SYSTEM-QAM/QAMTIME0.m

52 lines
2.0 KiB
Mathematica

QAMTIME0 ;HISC/DAD-CALCULATE TIME FRAME START-END FROM A DATE ;2/10/92 07:33
;;1.0;Clinical Monitoring System;;09/13/1993
; REQUIRES
; QAMD0 = MONITOR IEN QAMTODAY = DATE OF AUTO ENROLL RUN
; RETURNS
; QAMSTART & QAMEND = START & END DATES OF THE TIME FRAME
EN ;
S (QAMSTART,QAMEND)=0,QA=$S($D(^QA(743,QAMD0,1))#2:$P(^(1),"^"),1:"") Q:QA'>0 S QAMPRG=$S($D(^QA(743.92,QA,1))#2:^(1),1:"") X:QAMPRG]"" QAMPRG
K %Y,LEAPYEAR,QA,QAM,QAMDAYS,QAMONTH1,QAMONTH2,QAMONTHS,QAMPRG,QAMWEEK,X,X1,X2,Y
Q
EN1 ; *** DAILY
S (QAMSTART,QAMEND)=QAMTODAY
Q
EN2 ; *** WEEKLY
S QAMWEEK=$S($D(^QA(740,1,"QAM"))#2:+^("QAM"),1:0)
S X=QAMTODAY D H^%DTC S X1=QAMTODAY,X2=%Y-QAMWEEK S:X2>0 X2=-X2 D C^%DTC S (QAMSTART,X1)=X,X2=6 D C^%DTC S QAMEND=X
Q
EN3 ; *** MONTHLY
S (QAMONTH1,QAMONTH2)=$E(QAMTODAY,4,5) D DAYS S QAMSTART=$E(QAMTODAY,1,5)_"01",QAMEND=$E(QAMTODAY,1,5)_QAMDAYS
Q
EN4 ; *** QUARTERLY
S QAM=$E(QAMTODAY,4,5),QA=$E(QAMTODAY,1,3)
I QAM'>3 S QAMSTART=QA_"0101",QAMEND=QA_"0331" Q
I QAM'>6 S QAMSTART=QA_"0401",QAMEND=QA_"0630" Q
I QAM'>9 S QAMSTART=QA_"0701",QAMEND=QA_"0930" Q
S QAMSTART=QA_"1001",QAMEND=QA_"1231"
Q
EN5 ; *** SEMI-ANNUALLY
S QAM=$E(QAMTODAY,4,5),QA=$E(QAMTODAY,1,3)
I QAM'>6 S QAMSTART=QA_"0101",QAMEND=QA_"0630"
E S QAMSTART=QA_"0701",QAMEND=QA_"1231"
Q
EN6 ; *** ANNUALLY
S QAMSTART=$E(QAMTODAY,1,3)_"0101",QAMEND=$E(QAMTODAY,1,3)_"1231"
Q
EN7 ; *** FISCAL YEARLY
S QAM=$E(QAMTODAY,4,5),QA=$E(QAMTODAY,1,3)
I QAM'<10 S QAMSTART=QA_"1001",QAMEND=(QA+1)_"0930"
E S QAMSTART=(QA-1)_"1001",QAMEND=QA_"0930"
Q
EN8 ; *** FISCAL SEMI-ANNUALLY
S QAM=$E(QAMTODAY,4,5),QA=$E(QAMTODAY,1,3)
I QAM'<10 S QAMSTART=QA_"1001",QAMEND=(QA+1)_"0331" Q
I QAM'>3 S QAMSTART=(QA-1)_"1001",QAMEND=QA_"0331" Q
I QAM'<4 S QAMSTART=(QA-1)_"0401",QAMEND=QA_"0930"
Q
DAYS ; *** DAYS IN MONTH(S)
S QAMONTHS="31^28^31^30^31^30^31^31^30^31^30^31",QAMDAYS=0,Y=1700+$E(QAMTODAY,1,3),LEAPYEAR=(Y#4=0)&((Y#100)!(Y#400=0))
F QAM=QAMONTH1:1:QAMONTH2 S QAMDAYS=QAMDAYS+$P(QAMONTHS,"^",QAM)+$S(QAM=2:LEAPYEAR,1:0)
K LEAPYEAR,QAM,QAMONTH1,QAMONTH2,QAMONTHS,Y
Q