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

BIAGE.m

Go to the documentation of this file.
  1. BIAGE ;IHS/CMI/MWR - PROCESS AGE RANGES, PROMPTS ; MAY 10, 2010
  1. ;;8.5;IMMUNIZATION;;SEP 01,2011
  1. ;;* MICHAEL REMILLARD, DDS * CIMARRON MEDICAL INFORMATICS, FOR IHS *
  1. ;; UTILITY TO PROMPT AND PROCESS AGE RANGES.
  1. ;
  1. ;
  1. ;----------
  1. AGERNG(BIAGRG,BIPOP,BIDFLT,BIDMODE) ;EP
  1. ;---> Ask age range.
  1. ;---> Parameters:
  1. ; 1 - BIAGRG (ret) Age Range^Mode (Mode is in Months or Years).
  1. ; Mode="" or 0, is Months (default).
  1. ; Mode=1, is Years.
  1. ; Or BIAGRG="ALL"
  1. ; Examples: "6-24"="6 to 24 Months"
  1. ; "50-64^1"="50 to 64 Years"
  1. ; "ALL"
  1. ; 2 - BIPOP (ret) =1 if quit
  1. ; 3 - BIDFLT (opt) Default Age Range
  1. ; 4 - BIDMODE (opt) Default Mode: 1=Years, 0/""=Months(default)
  1. ;
  1. ;
  1. ASKRNG ;EP
  1. N DIR,DIRUT,Y S BIPOP=0,BIAGRG=""
  1. D
  1. .;---> Set default=previous entry.
  1. .I $D(^BIAGRG(DUZ,0)) D Q
  1. ..S DIR("B")=$P(^BIAGRG(DUZ,0),U,2)
  1. ..S BIMODE=+$P(^BIAGRG(DUZ,0),U,3)
  1. .;
  1. .;---> If no previous user default, then use passed default.
  1. .S:$G(BIDFLT)]"" DIR("B")=BIDFLT
  1. .S BIMODE=+$G(BIDMODE)
  1. ;
  1. ASKRNG1 ;GO EP
  1. ;
  1. D FULL^VALM1,TITLE^BIUTL5("SELECT AGE RANGE")
  1. D
  1. .I BIMODE D TEXT2 Q
  1. .D TEXT1
  1. ;
  1. S DIR(0)="FOA"
  1. S DIR("?")=" Enter a number"
  1. S DIR("A")=" Enter Age Range in "
  1. S DIR("A")=DIR("A")_$S(BIMODE:"Years: ",1:"Months: ")
  1. D ^DIR
  1. I $D(DIRUT)!(Y="") S BIPOP=1 Q
  1. ;
  1. I "ALLAllall"[Y S BIAGRG="ALL" Q
  1. ;
  1. I "YyMm"[Y D G ASKRNG1
  1. .S BIMODE=$S("Yy"[Y:1,1:0) K DIR
  1. ;
  1. ;---> If not a valid range, begin again.
  1. I $$CHECK(.Y) D ERRCD^BIUTL2(660,,1) G ASKRNG
  1. ;
  1. ;---> If Age Range was given in Years, concat 1.
  1. S:BIMODE Y=Y_U_1
  1. S BIAGRG=Y
  1. ;
  1. ;---> Now store user's Age Range for future default.
  1. Q:Y=""
  1. Q:DUZ=0
  1. ;---> Clear any previous Date-Loc Line for this user.
  1. K ^BIAGRG(DUZ),^BIAGRG("B",DUZ)
  1. ;---> Store this Age Range for this user.
  1. S ^BIAGRG(DUZ,0)=DUZ_U_Y,^BIAGRG("B",DUZ,DUZ)=""
  1. Q
  1. ;
  1. ;
  1. ;----------
  1. TEXT1 ;EP
  1. ;;Enter the patient Age Range IN MONTHS in the form of: 6-24
  1. ;;Use a dash "-" to separate the limits of the range. You may also
  1. ;;enter a single age, such as 12, to select for only 12-month-old
  1. ;;patients.
  1. ;;
  1. ;;Enter "ALL" if you wish to simply include patients of ALL ages.
  1. ;;
  1. ;;Or, if you wish to select a range in YEARS, enter "Y" (no quotes).
  1. ;;
  1. ;;NOTE: The Age Range will include patients whose ages span from the
  1. ;;minimum age all the way up to ONE DAY LESS THAN a month after the
  1. ;;maximum age. For example, 6-24 will include patients 6 months of
  1. ;;age and older, up to 24 months and approximately 30 days.
  1. ;;
  1. ;;
  1. D PRINTX("TEXT1")
  1. Q
  1. ;
  1. ;
  1. ;----------
  1. TEXT2 ;EP
  1. ;;Enter the patient Age Range IN YEARS in the form of: 65-99
  1. ;;Use a dash "-" to separate the limits of the range. You may also
  1. ;;enter a single age, such as 65, to select for only 65-year-old
  1. ;;patients.
  1. ;;
  1. ;;Enter "ALL" if you wish to simply include patients of ALL ages.
  1. ;;
  1. ;;Or, if you wish to select a range in MONTHS, enter "M" (no quotes).
  1. ;;
  1. ;;NOTE: The Age Range will include patients whose ages span from the
  1. ;;minimum age all the way up to ONE DAY LESS THAN a year after the
  1. ;;maximum age. For example, 65-99 will include patients 65 years of
  1. ;;age and older, up to 99 years and 364 days.
  1. ;;
  1. ;;
  1. D PRINTX("TEXT2")
  1. Q
  1. ;
  1. ;
  1. ;----------
  1. CHECK(X) ;EP
  1. ;---> Check syntax of age range string.
  1. ;---> Also, convert to years if appropriate.
  1. ;---> Parameters:
  1. ; 1 - X (req) Age Range.
  1. ;
  1. ;---> If only one age selected, quit.
  1. Q:X?1N.N 0
  1. N V,Y,Z S V="-"
  1. S Y=$P(X,V),Z=$P(X,V,2)
  1. ;---> Each end of the range should be a number.
  1. I (Y'?1N.N)!(Z'?1N.N) K X Q 1
  1. ;---> The lower number should be first.
  1. I Z<Y K X Q 1
  1. Q 0
  1. ;
  1. ;
  1. ;----------
  1. AGEDATE(BIAGRG,BISVDT,BIBEGDT,BIENDDT,BIERR) ;EP
  1. ;---> Given an Age Range in months or years and a Survey Date,
  1. ;---> return the beginning and ending dates in Fileman format.
  1. ;---> Use to search patients by DOB.
  1. ;---> Parameters:
  1. ; 1 - BIAGRG (req) Age Range^Mth/Yr (e.g.,50-64^1)
  1. ; (See description at linelable AGERNG above.)
  1. ; 2 - BISVDT (req) Survey/Forecast Date (date from which to
  1. ; calculate age).
  1. ; 3 - BIBEGDT (ret) Beginning Date.
  1. ; 4 - BIENDDT (ret) Ending Date.
  1. ; 5 - BIERR (ret) Error.
  1. ;
  1. ;---> Set begin and end dates for search through PATIENT File.
  1. I "ALL"[$G(BIAGRG) S BIBEGDT=0,BIENDDT=9999999 Q
  1. I '$G(BISVDT) S BISVDT=$G(DT)
  1. ;I '$G(BISVDT) S BIBEGDT=0,BIENDDT=9999999 Q
  1. ;S:BISVDT>DT BISVDT=DT
  1. ;
  1. ;---> If X=one age only, set it in the form X-X and quit.
  1. ;---> If Age Range is passed in years, convert to months.
  1. D
  1. .N Y S Y=$P(BIAGRG,U)
  1. .;---> If Y=one age only, set it in the form Y-Y.
  1. .I Y?1N.N S Y=Y_"-"_Y
  1. .I '$P(BIAGRG,U,2) S BIAGRG=Y Q
  1. .S BIAGRG=(12*$P(Y,"-"))_"-"_(12*$P(Y,"-",2)+11)
  1. ;
  1. N BIAGRG1,BIAGRG2
  1. S BIAGRG1=+$P(BIAGRG,"-",1),BIAGRG2=+$P(BIAGRG,"-",2)
  1. I (BIAGRG1'?1N.N)!(BIAGRG2'?1N.N) D ERRCD^BIUTL2(676,.BIERR) Q
  1. ;
  1. ;D PASTMTH(BISVDT,($P(BIAGRG,"-",2)+1),.BIBEGDT)
  1. D PASTMTH(BISVDT,(BIAGRG2+1),.BIBEGDT)
  1. ;
  1. ;---> Now, set Beginning Day to be one day AFTER the patient would
  1. ;---> be too old and out of the selected Age Range.
  1. ;---> In other words, come forward one day to include only patients
  1. ;---> whose age is ONE DAY LESS THAN a month (or year) after the
  1. ;---> maximum limit of the selected Age Range.
  1. ;---> For example, Age Range=24-36 includes patients whose age
  1. ;---> is between [24months] and [37months-1day].
  1. N X,X1,X2 S X1=BIBEGDT,X2=1 D C^%DTC S BIBEGDT=X
  1. ;
  1. ;D PASTMTH(BISVDT,$P(BIAGRG,"-",1),.BIENDDT)
  1. D PASTMTH(BISVDT,BIAGRG1,.BIENDDT)
  1. Q
  1. ;
  1. ;
  1. ;----------
  1. PASTMTH(BIDTI,BIMTHS,BIDTO,BIYR) ;EP
  1. ;---> Return the date BIMTHS months/years prior the input date.
  1. ;---> Parameters:
  1. ; 1 - BIDTI (req) Date in.
  1. ; 2 - BIMTHS (req) Number of months in the past to calculate.
  1. ; 3 - BIDTO (ret) Date out (BIMTHS prior to BIDTI).
  1. ; 4 - BIYR (opt) If BIYR=1, input is in years; multiply BIMTHSx12.
  1. ;
  1. Q:'$G(BIDTI)
  1. I '$G(BIMTHS) S BIDTO=BIDTI Q
  1. I $G(BIYR)=1 S BIMTHS=(BIMTHS*12)
  1. N YYY,MM,DD
  1. S YYY=$E(BIDTI,1,3),MM=+$E(BIDTI,4,5),DD=+$E(BIDTI,6,7)
  1. D
  1. .I MM>BIMTHS S MM=MM-BIMTHS Q
  1. .N I,Q S Q=0
  1. .F I=12:12 D Q:Q
  1. ..I BIMTHS-MM<I S MM=I-(BIMTHS-MM),YYY=YYY-(I/12),Q=1
  1. ;
  1. S:MM<10 MM="0"_MM
  1. S:DD<10 DD="0"_DD
  1. S BIDTO=YYY_MM_DD
  1. Q
  1. ;
  1. ;
  1. ;----------
  1. MTHYR(BIAG,BIS) ;EP
  1. ;---> Return Age Range for display in either months or years
  1. ;---> as appropriate, formatted: "24-36 Months" or "65-99 Years".
  1. ;---> Parameters:
  1. ; 1 - BIAG (req) Age Range^Mth/Yr
  1. ; (See description at linelable AGERNG above.)
  1. ; 2 - BIS (opt) If BIS=1 return "Mths" instead of "Months" or
  1. ; "Yrs" instead of "Years".
  1. ;
  1. Q:$G(BIAG)="" "NO RANGE"
  1. N V,W,X,Y,Z S V="-"
  1. ;
  1. ;---> Z=""/0: Range is in Months; Z=1: Range is in Years.
  1. S W=$P(BIAG,U),X=$P(W,V),Y=$P(W,V,2),Z=$P(BIAG,U,2)
  1. S:'X X=0
  1. S:W=0 W="<1"
  1. Q:$G(Z) W_$S($G(BIS):" Yr",1:" Year")_$S((Y!(X>1)):"s",1:"")
  1. Q W_$S($G(BIS):" Mth",1:" Month")_$S((Y!(X>1)):"s",1:"")
  1. ;
  1. ;
  1. ;----------
  1. PRINTX(BILINL,BITAB) ;EP
  1. Q:$G(BILINL)=""
  1. N I,T,X S T="" S:'$D(BITAB) BITAB=5 F I=1:1:BITAB S T=T_" "
  1. F I=1:1 S X=$T(@BILINL+I) Q:X'[";;" W !,T,$P(X,";;",2)
  1. Q