global labs_line,ws,master_tbl,item_no
record health_row(yr,mo,wgt,glu_avg,cnt,glu_02,cnt_02,glu_04,cnt_04,glu_06,cnt_06,glu_08,cnt_08,glu_10,cnt_10,glu_12,cnt_12,glu_other,cnt_other,sys,dia,pul,cnt_bp,bf,h2o,bone,bmi,cnt_bmi,cal,fat,sat,poly,mono,chol,sod,pot,carb,fib,sugar,prot,water,first_sleep,second_sleep,second_occurs,total_sleep,days,days_extra,days_none,miles_walk,miles_bike,min_yoga,neck_perc,stretch_perc,bed_time,chronotype,dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia,agap)
#dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia)
procedure main()
ws := " "
# in_path := "/home/dennis/dennisdarland/html/health3/"
in_path := "c:\\users\\dennis\\documents\\dennisdarland\\html\\health3\\"
glu_fname := in_path || "glucout2.txt"
nutrition_fname := in_path || "nutrition.txt"
rest_fname := in_path || "restout.txt"
labs_fname := in_path || "labs.html"
health_fname := in_path || "healthout2.txt"
health_fname_num := in_path || "healthoutnum2.txt"
health_fname_num_dbg := in_path || "healthoutnum2dbg.txt"
# sugar_fname_num := in_path || "sugaroutnum2.txt"
# glu_avg_fname_num := in_path || "glu_avg_outnum2.txt"
glu_fd := open(glu_fname,"r") | {
write("Open Failed")
fail
}
nutrition_fd := open(nutrition_fname,"r") | {
write("Open Failed")
fail
}
rest_fd := open(rest_fname,"r") | {
write("Open Failed")
fail
}
labs_fd := open(labs_fname,"r") | {
write("Open Failed")
fail
}
health_fd := open(health_fname,"w") | {
write("Open Failed")
fail
}
health_num_fd := open(health_fname_num,"w") | {
write("Open Failed")
fail
}
health_num_fd_dbg := open(health_fname_num_dbg,"w") | {
write("Open Failed")
fail
}
# sugar_num_fd := open(sugar_fname_num,"w") | {
# write("Open Failed")
# fail
# }
# glu_avg_num_fd := open(glu_avg_fname_num,"w") | {
# write("Open Failed")
# fail
# }
have_glu := table(0)
have_nutrition := table(0)
have_rest := table(0)
have_labs := table(0)
master_tbl := table()
# ignore 1st two lines
dat := &date
dat_year := dat[1:5]
dat_mo := dat[6:8]
oldest := dat_year || dat_mo
newest := 199701
line := read(glu_fd)
line := read(glu_fd)
digits := '1234567890'
valid := digits ++ '-.NAna'
valid_cnt := digits ++ '()'
count := 2
while line := read(glu_fd) do {
write("glu line count = ",count)
if (line ? (tab(upto(digits)) & mo := tab(upto('/')) &
tab(upto(digits)) & yr := tab(many(digits)) &
tab(upto(valid)) & wgt := tab(many(valid)) &
tab(upto(valid)) & glu_avg := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_02 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_02 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_04 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_04 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_06 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_06 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_08 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_08 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_10 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_10 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_12 := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_12 := tab(many(valid_cnt)) &
tab(upto(valid)) & glu_other := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_other := tab(many(valid_cnt)) &
tab(upto(valid)) & sys := tab(many(valid)) &
tab(upto(valid)) & dia := tab(many(valid)) &
tab(upto(valid)) & pul := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_bp := tab(many(valid_cnt)) &
tab(upto(valid)) & bf := tab(many(valid)) &
tab(upto(valid)) & h2o := tab(many(valid)) &
tab(upto(valid)) & bone := tab(many(valid)) &
tab(upto(valid)) & bmi := tab(many(valid)) &
tab(upto(valid_cnt)) & cnt_bmi := tab(many(valid_cnt)))) then {
chron := 100 * yr + mo
if chron < 199601 then write("Error oldest = ",oldest," in glu")
if chron > 202012 then write("Error newest = ",newest," in glu")
if chron < oldest then oldest := chron
if chron > newest then newest := chron
if *mo = 1 then mo := "0" || mo
glu_key := yr || "/" || mo
have_glu[glu_key] := 1
write("glu_key = ",glu_key)
cal := "NA"
fat := "NA"
sat := "NA"
poly := "NA"
mono := "NA"
chol := "NA"
sod := "NA"
pot := "NA"
carb := "NA"
fib := "NA"
sugar := "NA"
prot := "NA"
water := "NA"
first_sleep := "NA"
second_sleep := "NA"
second_occurs := "NA"
total_sleep := "NA"
days := "NA"
days_extra := "NA"
days_none := "NA"
miles_walk := "NA"
miles_bike := "NA"
min_yoga := "NA"
neck_perc := "NA"
stretch_perc := "NA"
bed_time := "NA"
chronotype := "NA"
dom := "NA"
fast := "NA"
a1c := "NA"
sodium := "NA"
potassium := "NA"
chloride := "NA"
carbon_dioxide := "NA"
bun := "NA"
creatnine := "NA"
gfr := "NA"
ast := "NA"
alt := "NA"
bilirubin_tot := "NA"
alk_phosphatase := "NA"
protein_total := "NA"
albumin := "NA"
calcium := "NA"
glucose := "NA"
triglycerides := "NA"
cholesterol := "NA"
hdl := "NA"
ldl := "NA"
ldl_hdl_ratio := "NA"
chol_hdl_ratio := "NA"
alb_creat_ratio := "NA"
psa := "NA"
ammonia := "NA"
agap := "NA"
master_tbl[glu_key] := health_row(yr,mo,wgt,glu_avg,cnt,glu_02,cnt_02,glu_04,cnt_04,glu_06,cnt_06,glu_08,cnt_08,glu_10,cnt_10,glu_12,cnt_12,glu_other,cnt_other,sys,dia,pul,cnt_bp,bf,h2o,bone,bmi,cnt_bmi,cal,fat,sat,poly,mono,chol,sod,pot,carb,fib,sugar,prot,water,first_sleep,second_sleep,second_occurs,total_sleep,days,days_extra,days_none,miles_walk,miles_bike,min_yoga,neck_perc,stretch_perc,bed_time,chronotype,dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia,agap)
count +:= 1
}
}
# ignore 1st 4 lines
line := read(nutrition_fd)
line := read(nutrition_fd)
line := read(nutrition_fd)
line := read(nutrition_fd)
count2 := 4
while line := read(nutrition_fd) do {
write("nutrition line count2 = ",count2)
if (line ? (tab(upto(digits)) & mo := tab(upto('/')) &
tab(upto(digits)) & yr := tab(many(digits)) &
tab(upto(valid)) & cal := tab(many(valid)) &
tab(upto(valid)) & fat := tab(many(valid)) &
tab(upto(valid)) & sat := tab(many(valid)) &
tab(upto(valid)) & poly := tab(many(valid)) &
tab(upto(valid)) & mono := tab(many(valid)) &
tab(upto(valid)) & chol := tab(many(valid)) &
tab(upto(valid)) & sod := tab(many(valid)) &
tab(upto(valid)) & pot := tab(many(valid)) &
tab(upto(valid)) & carb := tab(many(valid)) &
tab(upto(valid)) & fib := tab(many(valid)) &
tab(upto(valid)) & sugar := tab(many(valid)) &
tab(upto(valid)) & prot := tab(many(valid)) &
tab(upto(valid)) & water := tab(many(valid)))) then {
chron := 100 * yr + mo
if chron < 199601 then write("Error oldest = ",oldest," in nutrition")
if chron > 202012 then write("Error newest = ",newest," in nutrition")
if chron < oldest then oldest := chron
if chron > newest then newest := chron
if *mo = 1 then mo := "0" || mo
have_nutrition[nutrition_key] := 1
nutrition_key := yr || "/" || mo
if have_glu[nutrition_key] = 0 then {
wgt := "NA"
glu_avg := "NA"
cnt := "NA"
glu_02 := "NA"
cnt_02 := "NA"
glu_04 := "NA"
cnt_04 := "NA"
glu_06 := "NA"
cnt_06 := "NA"
glu_08 := "NA"
cnt_08 := "NA"
glu_10 := "NA"
cnt_10 := "NA"
glu_12 := "NA"
cnt_12 := "NA"
glu_other := "NA"
cnt_other := "NA"
sys := "NA"
dia := "NA"
pul := "NA"
cnt_bp := "NA"
bf := "NA"
h2o := "NA"
bone := "NA"
bmi := "NA"
cnt_bmi := "NA"
first_sleep := "NA"
second_sleep := "NA"
second_occurs := "NA"
total_sleep := "NA"
days := "NA"
days_extra := "NA"
days_none := "NA"
miles_walk := "NA"
miles_bike := "NA"
min_yoga := "NA"
neck_perc := "NA"
stretch_perc := "NA"
bed_time := "NA"
chronotype := "NA"
dom := "NA"
fast := "NA"
a1c := "NA"
sodium := "NA"
potassium := "NA"
chloride := "NA"
carbon_dioxide := "NA"
bun := "NA"
creatnine := "NA"
gfr := "NA"
ast := "NA"
alt := "NA"
bilirubin_tot := "NA"
alk_phosphatase := "NA"
protein_total := "NA"
albumin := "NA"
calcium := "NA"
glucose := "NA"
triglycerides := "NA"
cholesterol := "NA"
hdl := "NA"
ldl := "NA"
ldl_hdl_ratio := "NA"
chol_hdl_ratio := "NA"
alb_creat_ratio := "NA"
psa := "NA"
ammonia := "NA"
agap := "NA"
master_tbl[nutrition_key] := health_row(yr,mo,wgt,glu_avg,cnt,glu_02,cnt_02,glu_04,cnt_04,glu_06,cnt_06,glu_08,cnt_08,glu_10,cnt_10,glu_12,cnt_12,glu_other,cnt_other,sys,dia,pul,cnt_bp,bf,h2o,bone,bmi,cnt_bmi,cal,fat,sat,poly,mono,chol,sod,pot,carb,fib,sugar,prot,water,first_sleep,second_sleep,second_occurs,total_sleep,days,days_extra,days_none,miles_walk,miles_bike,min_yoga,neck_perc,stretch_perc,bed_time,chronotype,dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia,agap)
}
else {
master_tbl[nutrition_key].yr := yr
master_tbl[nutrition_key].mo := mo
master_tbl[nutrition_key].cal := cal
master_tbl[nutrition_key].fat := fat
master_tbl[nutrition_key].cal := cal
master_tbl[nutrition_key].fat := fat
master_tbl[nutrition_key].sat := sat
master_tbl[nutrition_key].poly := poly
master_tbl[nutrition_key].mono := mono
master_tbl[nutrition_key].chol := chol
master_tbl[nutrition_key].sod := sod
master_tbl[nutrition_key].pot := pot
master_tbl[nutrition_key].carb := carb
master_tbl[nutrition_key].fib := fib
master_tbl[nutrition_key].sugar := sugar
master_tbl[nutrition_key].prot := prot
master_tbl[nutrition_key].water := water
}
count2 +:= 1
}
}
line := read(rest_fd)
line := read(rest_fd)
count3 := 2
while line := read(rest_fd) do {
write("rest line count3 = ",count3)
if (line ? (tab(upto(digits)) & mo := tab(upto('/')) &
tab(upto(digits)) & yr := tab(many(digits)) &
tab(upto(valid)) & first_sleep := tab(many(valid)) &
tab(upto(valid)) & second_sleep := tab(many(valid)) &
tab(upto(valid)) & second_occurs := tab(many(valid)) &
tab(upto(valid)) & total_sleep := tab(many(valid)) &
tab(upto(valid)) & days := tab(many(valid)) &
tab(upto(valid)) & days_extra := tab(many(valid)) &
tab(upto(valid)) & days_none := tab(many(valid)) &
tab(upto(valid)) & miles_walk := tab(many(valid)) &
tab(upto(valid)) & miles_bike := tab(many(valid)) &
tab(upto(valid)) & min_yoga := tab(many(valid)) &
tab(upto(valid)) & neck_perc := tab(many(valid)) &
tab(upto(valid)) & stretch_perc := tab(many(valid)) &
tab(upto(valid)) & bed_time := tab(many(valid)) &
tab(upto(valid)) & chronotype := tab(many(valid)) &
tab(upto(valid)) & show := tab(many(valid)) &
tab(upto(valid)) & bath := tab(many(valid)) &
tab(upto(valid)) & sham := tab(many(valid)) &
tab(upto(valid)) & epso := tab(many(valid)))) then {
chron := 100 * yr + mo
if chron < 199601 then write("Error oldest = ",oldest," in rest")
if chron > 202012 then write("Error newest = ",newest," in rest")
if chron < oldest then oldest := chron
if chron > newest then newest := chron
if *mo = 1 then mo := "0" || mo
rest_key := yr || "/" || mo
have_rest[rest_key] := 1
if have_glu[rest_key] = 0 & have_nutrition[rest_key] = 0 then {
wgt := "NA"
glu_avg := "NA"
cnt := "NA"
glu_02 := "NA"
cnt_02 := "NA"
glu_04 := "NA"
cnt_04 := "NA"
glu_06 := "NA"
cnt_06 := "NA"
glu_08 := "NA"
cnt_08 := "NA"
glu_10 := "NA"
cnt_10 := "NA"
glu_12 := "NA"
cnt_12 := "NA"
glu_other := "NA"
cnt_other := "NA"
sys := "NA"
dia := "NA"
pul := "NA"
cnt_bp := "NA"
bf := "NA"
h2o := "NA"
bone := "NA"
bmi := "NA"
cnt_bmi := "NA"
first_sleep := "NA"
second_sleep := "NA"
second_occurs := "NA"
total_sleep := "NA"
days := "NA"
days_extra := "NA"
days_none := "NA"
miles_walk := "NA"
miles_bike := "NA"
min_yoga := "NA"
neck_perc := "NA"
stretch_perc := "NA"
bed_time := "NA"
chronotype := "NA"
dom := "NA"
fast := "NA"
a1c := "NA"
sodium := "NA"
potassium := "NA"
chloride := "NA"
carbon_dioxide := "NA"
bun := "NA"
creatnine := "NA"
gfr := "NA"
ast := "NA"
alt := "NA"
bilirubin_tot := "NA"
alk_phosphatase := "NA"
protein_total := "NA"
albumin := "NA"
calcium := "NA"
glucose := "NA"
triglycerides := "NA"
cholesterol := "NA"
hdl := "NA"
ldl := "NA"
ldl_hdl_ratio := "NA"
chol_hdl_ratio := "NA"
alb_creat_ratio := "NA"
psa := "NA"
ammonia := "NA"
agap := "NA"
master_tbl[nutrition_key] := health_row(yr,mo,wgt,glu_avg,cnt,glu_02,cnt_02,glu_04,cnt_04,glu_06,cnt_06,glu_08,cnt_08,glu_10,cnt_10,glu_12,cnt_12,glu_other,cnt_other,sys,dia,pul,cnt_bp,bf,h2o,bone,bmi,cnt_bmi,cal,fat,sat,poly,mono,chol,sod,pot,carb,fib,sugar,prot,water,first_sleep,second_sleep,second_occurs,total_sleep,days,days_extra,days_none,miles_walk,miles_bike,min_yoga,neck_perc,stretch_perc,bed_time,chronotype,dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia,agap)
}
else {
master_tbl[rest_key].yr := yr
master_tbl[rest_key].mo := mo
master_tbl[rest_key].first_sleep := first_sleep
master_tbl[rest_key].second_sleep := second_sleep
master_tbl[rest_key].second_occurs := second_occurs
master_tbl[rest_key].total_sleep := total_sleep
master_tbl[rest_key].days := days
master_tbl[rest_key].days_extra := days_extra
master_tbl[rest_key].days_none := days_none
master_tbl[rest_key].miles_walk := miles_walk
master_tbl[rest_key].miles_bike := miles_bike
master_tbl[rest_key].min_yoga := min_yoga
master_tbl[rest_key].neck_perc := neck_perc
master_tbl[rest_key].stretch_perc := stretch_perc
master_tbl[rest_key].bed_time := bed_time
master_tbl[rest_key].chronotype := chronotype
}
count3 +:= 1
}
}
###########################################################################
line := read(labs_fd)
line := read(labs_fd)
count4 := 2
while line := read(labs_fd) do {
write("line count4 AAA = ",count4)
write(line)
if (line ? ((tab(upto('<')) & tab(match("
")) & date := tab(upto('<')) & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & fast := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & a1c := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & sodium := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & potassium := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & chloride := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & carbon_dioxide := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & bun := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & creatnine := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & gfr := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & ast := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & alt := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & bilirubin := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & alk_phosphatase := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & protein_total := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & albumin := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & calcium := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & glucose := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & triglycerides := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & cholesterol := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & hdl := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & ldl := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & ldl_hdl_ratio := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & chol_hdl_ratio := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & alb_creat_ratio := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & psa := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & ammonia := (tab(upto('<')) | "") & tab(match(" | "))) &
(tab(upto('<')) & tab(match("")) & agap := (tab(upto('<')) | "") & tab(match(" | "))))) then {
write("line count4 BBB = ",count4)
date := fix_it(date)
fast := fix_it(fast)
a1c := fix_it(a1c)
sodium := fix_it(sodium)
potassium := fix_it(potassium)
chloride := fix_it(chloride)
carbon_dioxide := fix_it(carbon_dioxide)
bun := fix_it(bun)
creatnine := fix_it(creatnine)
gfr := fix_it(gfr)
ast := fix_it(ast)
alt := fix_it(alt)
bilirubin_tot := fix_it(bilirubin)
alk_phosphatase := fix_it(alk_phosphatase)
protein_total := fix_it(protein_total)
albumin := fix_it(albumin)
calcium := fix_it(calcium)
glucose := fix_it(glucose)
triglycerides := fix_it(triglycerides)
cholesterol := fix_it(cholesterol)
hdl := fix_it(hdl)
ldl := fix_it(ldl)
ldl_hdl_ratio := fix_it(ldl_hdl_ratio)
chol_hdl_ratio := fix_it(chol_hdl_ratio)
alb_creat_ratio := fix_it(alb_creat_ratio)
psa := fix_it(psa)
ammonia := fix_it(ammonia)
agap := fix_it(agap)
write("line count4 CCC = ",count4," date = ",date)
date ? (mo := tab(many(digits)) & tab(match("/")) &
dom := tab(many(digits)) & tab(match("/")) &
yr := tab(many(digits)))
chron := 100 * yr + mo
if chron < 199601 then write("Error oldest = ",oldest," in rest")
if chron > 202012 then write("Error newest = ",newest," in rest")
if chron < oldest then oldest := chron
if chron > newest then newest := chron
if *mo = 1 then mo := "0" || mo
labs_key := yr || "/" || mo
write("labs_key = ", labs_key)
have_labs[labs_key] := 1
if (have_glu[labs_key] = 0 & have_nutrition[labs_key] = 0 &
have_rest[labs_key] = 0) then {
write("line count4 DDD = ",count4)
write("adding labs_key = ", labs_key)
wgt := "NA"
glu_avg := "NA"
cnt := "NA"
glu_02 := "NA"
cnt_02 := "NA"
glu_04 := "NA"
cnt_04 := "NA"
glu_06 := "NA"
cnt_06 := "NA"
glu_08 := "NA"
cnt_08 := "NA"
glu_10 := "NA"
cnt_10 := "NA"
glu_12 := "NA"
cnt_12 := "NA"
glu_other := "NA"
cnt_other := "NA"
sys := "NA"
dia := "NA"
pul := "NA"
cnt_bp := "NA"
bf := "NA"
h2o := "NA"
bone := "NA"
bmi := "NA"
cnt_bmi := "NA"
first_sleep := "NA"
second_sleep := "NA"
second_occurs := "NA"
total_sleep := "NA"
days := "NA"
days_extra := "NA"
days_none := "NA"
miles_walk := "NA"
miles_bike := "NA"
min_yoga := "NA"
neck_perc := "NA"
stretch_perc := "NA"
bed_time := "NA"
chronotype := "NA"
cal := "NA"
fat := "NA"
sat := "NA"
poly := "NA"
mono := "NA"
chol := "NA"
sod := "NA"
pot := "NA"
carb := "NA"
fib := "NA"
sugar := "NA"
prot := "NA"
water := "NA"
write("line count4 EEE = ",count4," key = ", labs_key)
master_tbl[labs_key] := health_row(yr,mo,wgt,glu_avg,cnt,glu_02,cnt_02,glu_04,cnt_04,glu_06,cnt_06,glu_08,cnt_08,glu_10,cnt_10,glu_12,cnt_12,glu_other,cnt_other,sys,dia,pul,cnt_bp,bf,h2o,bone,bmi,cnt_bmi,cal,fat,sat,poly,mono,chol,sod,pot,carb,fib,sugar,prot,water,first_sleep,second_sleep,second_occurs,total_sleep,days,days_extra,days_none,miles_walk,miles_bike,min_yoga,neck_perc,stretch_perc,bed_time,chronotype,dom,fast,a1c,sodium,potassium,chloride,carbon_dioxide,bun,creatnine,gfr,ast,alt,bilirubin_tot,alk_phosphatase,protein_total,albumin,calcium,glucose,triglycerides,cholesterol,hdl,ldl,ldl_hdl_ratio,chol_hdl_ratio,alb_creat_ratio,psa,ammonia,agap)
write("line count4 FFF = ",count4," glucose = ",master_tbl[labs_key].glucose)
}
else {
write("line count4 GGG = ",count4)
master_tbl[labs_key].yr := yr
master_tbl[labs_key].mo := mo
master_tbl[labs_key].dom := dom
master_tbl[labs_key].fast := fast
master_tbl[labs_key].a1c := a1c
master_tbl[labs_key].sodium := sodium
master_tbl[labs_key].potassium := potassium
master_tbl[labs_key].chloride := chlodide
master_tbl[labs_key].carbon_dioxide := carbon_dioxide
master_tbl[labs_key].bun ;= bun
master_tbl[labs_key].creatnine := creatine
master_tbl[labs_key].gfr := gfr
master_tbl[labs_key].ast := ast
master_tbl[labs_key].alt := alt
master_tbl[labs_key].bilirubin_tot := bilirubin
master_tbl[labs_key].alk_phosphatase := alk_phosphatase
master_tbl[labs_key].protein_total := protein_total
master_tbl[labs_key].albumin := albumin
master_tbl[labs_key].calcium := calcium
master_tbl[labs_key].glucose := glucose
master_tbl[labs_key].triglycerides := triglycerides
master_tbl[labs_key].cholesterol := cholesterol
master_tbl[labs_key].hdl := hdl
master_tbl[labs_key].ldl := ldl
master_tbl[labs_key].ldl_hdl_ratio := ldl_hdl_ratio
master_tbl[labs_key].chol_hdl_ratio := chol_hdl_ratio
master_tbl[labs_key].alb_creat_ratio := alb_creat_ratio
master_tbl[labs_key].psa := psa
master_tbl[labs_key].ammonia := ammonia
master_tbl[labs_key].agap := agap
write("line count4 HHH = ",count4)
}
write("line count4 III = ",count4)
count4 +:= 1
}
write("line count4 JJJ = ",count4)
}
write("line count4 KKK = ",count4)
##########################################################################
oldestyr := oldest /100
oldestmo := oldest % 100
newestyr := newest / 100
newestmo := newest % 100
yr := oldestyr
mo := oldestmo
# this would not work right if oldestyr = newestyr - but not a problem for me
if oldestyr = newestyr then {
while mo < newestmo do {
export_health_rec(yr,mo,health_fd,health_num_fd,health_num_fd_dbg)
mo +:= 1
}
} else {
while yr <= newestyr do {
if yr < newestyr then {
if yr > oldestyr then mo := 1
while mo <= 12 do {
export_health_rec(yr,mo,health_fd,health_num_fd,health_num_fd_dbg)
mo +:= 1
}
}
else {
mo := 1
while mo <= newestmo do {
export_health_rec(yr,mo,health_fd,health_num_fd,health_num_fd_dbg)
mo +:= 1
}
}
yr +:= 1
}
}
close(glu_fd)
close(nutrition_fd)
close(rest_fd)
close(health_fd)
close(health_num_fd)
close(health_num_fd_dbg)
end
procedure export_health_rec(yr,mo,health_fd,health_num_fd,health_num_fd_dbg)
if *mo = 1 then mo := "0" || mo
health_key := yr || "/" || mo
if \master_tbl[health_key] then {
write(health_fd,health_key," ",
master_tbl[health_key].yr," ",
master_tbl[health_key].mo," ",
master_tbl[health_key].wgt," ",
master_tbl[health_key].glu_avg," ",
master_tbl[health_key].cnt," ",
master_tbl[health_key].glu_02," ",
master_tbl[health_key].cnt_02," ",
master_tbl[health_key].glu_04," ",
master_tbl[health_key].cnt_04," ",
master_tbl[health_key].glu_06," ",
master_tbl[health_key].cnt_06," ",
master_tbl[health_key].glu_08," ",
master_tbl[health_key].cnt_08," ",
master_tbl[health_key].glu_10," ",
master_tbl[health_key].cnt_10," ",
master_tbl[health_key].glu_12," ",
master_tbl[health_key].cnt_12," ",
master_tbl[health_key].glu_other," ",
master_tbl[health_key].cnt_other," ",
master_tbl[health_key].sys," ",
master_tbl[health_key].dia," ",
master_tbl[health_key].pul," ",
master_tbl[health_key].cnt_bp," ",
master_tbl[health_key].bf," ",
master_tbl[health_key].h2o," ",
master_tbl[health_key].bone," ",
master_tbl[health_key].bmi," ",
master_tbl[health_key].cnt_bmi," ",
master_tbl[health_key].cal," ",
master_tbl[health_key].fat," ",
master_tbl[health_key].sat," ",
master_tbl[health_key].poly," ",
master_tbl[health_key].mono," ",
master_tbl[health_key].chol," ",
master_tbl[health_key].sod," ",
master_tbl[health_key].pot," ",
master_tbl[health_key].carb," ",
master_tbl[health_key].fib," ",
master_tbl[health_key].sugar," ",
master_tbl[health_key].prot," ",
master_tbl[health_key].water," ",
master_tbl[health_key].first_sleep," ",
master_tbl[health_key].second_sleep," ",
master_tbl[health_key].second_occurs," ",
master_tbl[health_key].total_sleep," ",
master_tbl[health_key].days," ",
master_tbl[health_key].days_extra," ",
master_tbl[health_key].days_none," ",
master_tbl[health_key].miles_walk," ",
master_tbl[health_key].miles_bike," ",
master_tbl[health_key].min_yoga," ",
master_tbl[health_key].neck_perc," ",
master_tbl[health_key].stretch_perc," ",
master_tbl[health_key].bed_time," ",
master_tbl[health_key].chronotype," ",
master_tbl[health_key].dom," ",
master_tbl[health_key].fast," ",
master_tbl[health_key].a1c," ",
master_tbl[health_key].sodium," ",
master_tbl[health_key].potassium," ",
master_tbl[health_key].chloride," ",
master_tbl[health_key].carbon_dioxide," ",
master_tbl[health_key].bun," ",
master_tbl[health_key].creatnine," ",
master_tbl[health_key].gfr," ",
master_tbl[health_key].ast," ",
master_tbl[health_key].alt," ",
master_tbl[health_key].bilirubin_tot," ",
master_tbl[health_key].alk_phosphatase," ",
master_tbl[health_key].protein_total," ",
master_tbl[health_key].albumin," ",
master_tbl[health_key].calcium," ",
master_tbl[health_key].glucose," ",
master_tbl[health_key].triglycerides," ",
master_tbl[health_key].cholesterol," ",
master_tbl[health_key].hdl," ",
master_tbl[health_key].ldl," ",
master_tbl[health_key].ldl_hdl_ratio," ",
master_tbl[health_key].chol_hdl_ratio," ",
master_tbl[health_key].alb_creat_ratio," ",
master_tbl[health_key].psa," ",
master_tbl[health_key].ammonia, " ",
master_tbl[health_key].agap)
write(health_num_fd,
cvt_num(master_tbl[health_key].yr)," ",
cvt_num(master_tbl[health_key].mo)," ",
cvt_num(master_tbl[health_key].wgt)," ",
cvt_num(master_tbl[health_key].glu_avg)," ",
cvt_num(master_tbl[health_key].cnt)," ",
cvt_num(master_tbl[health_key].glu_02)," ",
cvt_num(master_tbl[health_key].cnt_02)," ",
cvt_num(master_tbl[health_key].glu_04)," ",
cvt_num(master_tbl[health_key].cnt_04)," ",
cvt_num(master_tbl[health_key].glu_06)," ",
cvt_num(master_tbl[health_key].cnt_06)," ",
cvt_num(master_tbl[health_key].glu_08)," ",
cvt_num(master_tbl[health_key].cnt_08)," ",
cvt_num(master_tbl[health_key].glu_10)," ",
cvt_num(master_tbl[health_key].cnt_10)," ",
cvt_num(master_tbl[health_key].glu_12)," ",
cvt_num(master_tbl[health_key].cnt_12)," ",
cvt_num(master_tbl[health_key].glu_other)," ",
cvt_num(master_tbl[health_key].cnt_other)," ",
cvt_num(master_tbl[health_key].sys)," ",
cvt_num(master_tbl[health_key].dia)," ",
cvt_num(master_tbl[health_key].pul)," ",
cvt_num(master_tbl[health_key].cnt_bp)," ",
cvt_num(master_tbl[health_key].bf)," ",
cvt_num(master_tbl[health_key].h2o)," ",
cvt_num(master_tbl[health_key].bone)," ",
cvt_num(master_tbl[health_key].bmi)," ",
cvt_num(master_tbl[health_key].cnt_bmi)," ",
cvt_num(master_tbl[health_key].cal)," ",
cvt_num(master_tbl[health_key].fat)," ",
cvt_num(master_tbl[health_key].sat)," ",
cvt_num(master_tbl[health_key].poly)," ",
cvt_num(master_tbl[health_key].mono)," ",
cvt_num(master_tbl[health_key].chol)," ",
cvt_num(master_tbl[health_key].sod)," ",
cvt_num(master_tbl[health_key].pot)," ",
cvt_num(master_tbl[health_key].carb)," ",
cvt_num(master_tbl[health_key].fib)," ",
cvt_num(master_tbl[health_key].sugar)," ",
cvt_num(master_tbl[health_key].prot)," ",
cvt_num(master_tbl[health_key].water)," ",
cvt_num(master_tbl[health_key].first_sleep)," ",
cvt_num(master_tbl[health_key].second_sleep)," ",
cvt_num(master_tbl[health_key].second_occurs)," ",
cvt_num(master_tbl[health_key].total_sleep)," ",
cvt_num(master_tbl[health_key].days)," ",
cvt_num(master_tbl[health_key].days_extra)," ",
cvt_num(master_tbl[health_key].days_none)," ",
cvt_num(master_tbl[health_key].miles_walk)," ",
cvt_num(master_tbl[health_key].miles_bike)," ",
cvt_num(master_tbl[health_key].min_yoga)," ",
cvt_num(master_tbl[health_key].neck_perc)," ",
cvt_num(master_tbl[health_key].stretch_perc)," ",
cvt_num(master_tbl[health_key].bed_time)," ",
cvt_num(master_tbl[health_key].chronotype)," ",
cvt_num(master_tbl[health_key].dom)," ",
cvt_num(master_tbl[health_key].fast)," ",
cvt_num(master_tbl[health_key].a1c)," ",
cvt_num(master_tbl[health_key].sodium)," ",
cvt_num(master_tbl[health_key].potassium)," ",
cvt_num(master_tbl[health_key].chloride)," ",
cvt_num(master_tbl[health_key].carbon_dioxide)," ",
cvt_num(master_tbl[health_key].bun)," ",
cvt_num(master_tbl[health_key].creatnine)," ",
cvt_num(master_tbl[health_key].gfr)," ",
cvt_num(master_tbl[health_key].ast)," ",
cvt_num(master_tbl[health_key].alt)," ",
cvt_num(master_tbl[health_key].bilirubin_tot)," ",
cvt_num(master_tbl[health_key].alk_phosphatase)," ",
cvt_num(master_tbl[health_key].protein_total)," ",
cvt_num(master_tbl[health_key].albumin)," ",
cvt_num(master_tbl[health_key].calcium)," ",
cvt_num(master_tbl[health_key].glucose)," ",
cvt_num(master_tbl[health_key].triglycerides)," ",
cvt_num(master_tbl[health_key].cholesterol)," ",
cvt_num(master_tbl[health_key].hdl)," ",
cvt_num(master_tbl[health_key].ldl)," ",
cvt_num(master_tbl[health_key].ldl_hdl_ratio)," ",
cvt_num(master_tbl[health_key].chol_hdl_ratio)," ",
cvt_num(master_tbl[health_key].alb_creat_ratio)," ",
cvt_num(master_tbl[health_key].psa)," ",
cvt_num(master_tbl[health_key].ammonia)," ",
cvt_num(master_tbl[health_key].agap))
write(health_num_fd_dbg,"*1* ",
cvt_num(master_tbl[health_key].yr),"*2* ",
cvt_num(master_tbl[health_key].mo),"*3* ",
cvt_num(master_tbl[health_key].wgt),"*4* ",
cvt_num(master_tbl[health_key].glu_avg),"*5* ",
cvt_num(master_tbl[health_key].cnt),"*6* ",
cvt_num(master_tbl[health_key].glu_02),"*7* ",
cvt_num(master_tbl[health_key].cnt_02),"*8* ",
cvt_num(master_tbl[health_key].glu_04),"*9* ",
cvt_num(master_tbl[health_key].cnt_04),"*10* ",
cvt_num(master_tbl[health_key].glu_06),"*11* ",
cvt_num(master_tbl[health_key].cnt_06),"*12* ",
cvt_num(master_tbl[health_key].glu_08),"*13* ",
cvt_num(master_tbl[health_key].cnt_08),"*14* ",
cvt_num(master_tbl[health_key].glu_10),"*15* ",
cvt_num(master_tbl[health_key].cnt_10),"*16* ",
cvt_num(master_tbl[health_key].glu_12),"*17* ",
cvt_num(master_tbl[health_key].cnt_12),"*18* ",
cvt_num(master_tbl[health_key].glu_other),"*19* ",
cvt_num(master_tbl[health_key].cnt_other),"*20* ",
cvt_num(master_tbl[health_key].sys),"*21* ",
cvt_num(master_tbl[health_key].dia),"*22* ",
cvt_num(master_tbl[health_key].pul),"*23* ",
cvt_num(master_tbl[health_key].cnt_bp),"*24* ",
cvt_num(master_tbl[health_key].bf),"*25* ",
cvt_num(master_tbl[health_key].h2o),"*26* ",
cvt_num(master_tbl[health_key].bone),"*27* ",
cvt_num(master_tbl[health_key].bmi),"*28* ",
cvt_num(master_tbl[health_key].cnt_bmi),"*29* ",
cvt_num(master_tbl[health_key].cal),"*30* ",
cvt_num(master_tbl[health_key].fat),"*31* ",
cvt_num(master_tbl[health_key].sat),"*32* ",
cvt_num(master_tbl[health_key].poly),"*33* ",
cvt_num(master_tbl[health_key].mono),"*34* ",
cvt_num(master_tbl[health_key].chol),"*35* ",
cvt_num(master_tbl[health_key].sod),"*36* ",
cvt_num(master_tbl[health_key].pot),"*37* ",
cvt_num(master_tbl[health_key].carb),"*38* ",
cvt_num(master_tbl[health_key].fib),"*39* ",
cvt_num(master_tbl[health_key].sugar),"*40* ",
cvt_num(master_tbl[health_key].prot),"*41* ",
cvt_num(master_tbl[health_key].water),"*42* ",
cvt_num(master_tbl[health_key].first_sleep),"*43* ",
cvt_num(master_tbl[health_key].second_sleep),"*44* ",
cvt_num(master_tbl[health_key].second_occurs),"*45* ",
cvt_num(master_tbl[health_key].total_sleep),"*46* ",
cvt_num(master_tbl[health_key].days),"*47* ",
cvt_num(master_tbl[health_key].days_extra),"*48* ",
cvt_num(master_tbl[health_key].days_none),"*49* ",
cvt_num(master_tbl[health_key].miles_walk),"*50* ",
cvt_num(master_tbl[health_key].miles_bike),"*51* ",
cvt_num(master_tbl[health_key].min_yoga),"*52* ",
cvt_num(master_tbl[health_key].neck_perc),"*53* ",
cvt_num(master_tbl[health_key].stretch_perc),"*54* ",
cvt_num(master_tbl[health_key].bed_time),"*55* ",
cvt_num(master_tbl[health_key].chronotype),"*56* ",
cvt_num(master_tbl[health_key].dom),"*57* ",
cvt_num(master_tbl[health_key].fast),"*58* ",
cvt_num(master_tbl[health_key].a1c),"*59* ",
cvt_num(master_tbl[health_key].sodium),"*60* ",
cvt_num(master_tbl[health_key].potassium),"*61* ",
cvt_num(master_tbl[health_key].chloride),"*62* ",
cvt_num(master_tbl[health_key].carbon_dioxide),"*63* ",
cvt_num(master_tbl[health_key].bun),"*64* ",
cvt_num(master_tbl[health_key].creatnine),"*65* ",
cvt_num(master_tbl[health_key].gfr),"*66* ",
cvt_num(master_tbl[health_key].ast),"*67* ",
cvt_num(master_tbl[health_key].alt),"*68* ",
cvt_num(master_tbl[health_key].bilirubin_tot),"*69* ",
cvt_num(master_tbl[health_key].alk_phosphatase),"*70* ",
cvt_num(master_tbl[health_key].protein_total),"*71* ",
cvt_num(master_tbl[health_key].albumin),"*72* ",
cvt_num(master_tbl[health_key].calcium),"*73* ",
cvt_num(master_tbl[health_key].glucose),"*74* ",
cvt_num(master_tbl[health_key].triglycerides),"*75* ",
cvt_num(master_tbl[health_key].cholesterol),"*76* ",
cvt_num(master_tbl[health_key].hdl),"*77* ",
cvt_num(master_tbl[health_key].ldl),"*78* ",
cvt_num(master_tbl[health_key].ldl_hdl_ratio),"*79* ",
cvt_num(master_tbl[health_key].chol_hdl_ratio),"*80* ",
cvt_num(master_tbl[health_key].alb_creat_ratio),"*81* ",
cvt_num(master_tbl[health_key].psa),"*82* ",
cvt_num(master_tbl[health_key].ammonia), "*83* ",
cvt_num(master_tbl[health_key].agap))
# if ((cvt_num(master_tbl[health_key].glu_avg) > 0.0 &
# cvt_num(master_tbl[health_key].sugar) > 0.0)) then {
# write(glu_avg_num_fd,cvt_num(master_tbl[health_key].glu_avg),","
#)
# write(sugar_num_fd,cvt_num(master_tbl[health_key].sugar),",")
# }
}
end
procedure fix_it(it)
ret := trim(it,ws)
ret := reverse(ret)
ret := trim(ret,ws)
ret := reverse(ret)
if ret == "" then ret := "NA"
write("ret = ",ret)
ret := map(ret," ","*")
return ret
end
procedure cvt_num(it)
if (ret := numeric(it)) then {
write(ret)
return(ret)
}
if \it & (it ? ((tab(many('('))) & (ret := tab(many('1234567890.'))) & tab(many(')')))) then {
if ret ~== "" then {
write(ret)
return(ret)
}
}
if \it & (it ? ((ret := tab(many('1234567890.'))) & tab(many('*') & tab(many(&lcase ++ &ucase))))) then {
if ret ~== "" then {
write(ret)
return(ret)
}
else {
return(-9999.0)
}
}
return(-9999.0)
end