global labs_line, ws, master_tbl, item_no, glu_fd, nutrition_fd, rest_fd, labs_fd, health_fd, health_num_fd, bms_fd, health_num_fd_dbg, DJDDBG, have_glu, have_nutrition, have_rest, have_labs, have_bms, master_tbl, dat, dat_year, dat_mo, oldest, newest, digits, valid, valid_cnt ####################### record health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bm_angle,bm_sz) procedure main() init() process_glu() process_nutrition() process_labs() process_rest() process_bms() write_it_out() finish() 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].wgt_cnt," ", master_tbl[health_key].glu_avg," ", master_tbl[health_key].glu_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].minutes_lamp," ", master_tbl[health_key].min_yoga," ", master_tbl[health_key].neck_perc," ", master_tbl[health_key].stretch_perc," ", master_tbl[health_key].jg," ", master_tbl[health_key].massheat," ", master_tbl[health_key].massvib," ", master_tbl[health_key].bed_time," ", master_tbl[health_key].chronotype," ", 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, " ", master_tbl[health_key].bms, " ", master_tbl[health_key].bm_angle, " ", master_tbl[health_key].bm_sz) 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].wgt_cnt)," ", cvt_num(master_tbl[health_key].glu_avg)," ", cvt_num(master_tbl[health_key].glu_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].minutes_lamp)," ", 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].jg)," ", cvt_num(master_tbl[health_key].massheat)," ", cvt_num(master_tbl[health_key].massvib)," ", cvt_num(master_tbl[health_key].bed_time)," ", cvt_num(master_tbl[health_key].chronotype)," ", 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)," ", cvt_num(master_tbl[health_key].bms), " ", cvt_num(master_tbl[health_key].bm_angle), " ", cvt_num(master_tbl[health_key].bm_sz), " ", cvt_num((master_tbl[health_key].yr - 1951) * 12) + cvt_num(master_tbl[health_key].mo)) 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].wgt_cnt),"*5* ", cvt_num(master_tbl[health_key].glu_avg),"*6* ", cvt_num(master_tbl[health_key].glu_cnt),"*7* ", cvt_num(master_tbl[health_key].glu_02),"*8* ", cvt_num(master_tbl[health_key].cnt_02),"*9* ", cvt_num(master_tbl[health_key].glu_04),"*10* ", cvt_num(master_tbl[health_key].cnt_04),"*11* ", cvt_num(master_tbl[health_key].glu_06),"*12* ", cvt_num(master_tbl[health_key].cnt_06),"*13* ", cvt_num(master_tbl[health_key].glu_08),"*14* ", cvt_num(master_tbl[health_key].cnt_08),"*15* ", cvt_num(master_tbl[health_key].glu_10),"*16* ", cvt_num(master_tbl[health_key].cnt_10),"*17* ", cvt_num(master_tbl[health_key].glu_12),"*18* ", cvt_num(master_tbl[health_key].cnt_12),"*19* ", cvt_num(master_tbl[health_key].glu_other),"*20* ", cvt_num(master_tbl[health_key].cnt_other),"*21* ", cvt_num(master_tbl[health_key].sys),"*22* ", cvt_num(master_tbl[health_key].dia),"*23* ", cvt_num(master_tbl[health_key].pul),"*24* ", cvt_num(master_tbl[health_key].cnt_bp),"*25* ", cvt_num(master_tbl[health_key].bf),"*26* ", cvt_num(master_tbl[health_key].h2o),"*27* ", cvt_num(master_tbl[health_key].bone),"*28* ", cvt_num(master_tbl[health_key].bmi),"*29* ", cvt_num(master_tbl[health_key].cnt_bmi),"*30* ", cvt_num(master_tbl[health_key].cal),"*31* ", cvt_num(master_tbl[health_key].fat),"*32* ", cvt_num(master_tbl[health_key].sat),"*33* ", cvt_num(master_tbl[health_key].poly),"*34* ", cvt_num(master_tbl[health_key].mono),"*35* ", cvt_num(master_tbl[health_key].chol),"*36* ", cvt_num(master_tbl[health_key].sod),"*37* ", cvt_num(master_tbl[health_key].pot),"*38* ", cvt_num(master_tbl[health_key].carb),"*39* ", cvt_num(master_tbl[health_key].fib),"*40* ", cvt_num(master_tbl[health_key].sugar),"*41* ", cvt_num(master_tbl[health_key].prot),"*42* ", cvt_num(master_tbl[health_key].water),"*43* ", cvt_num(master_tbl[health_key].first_sleep),"*44* ", cvt_num(master_tbl[health_key].second_sleep),"*45* ", cvt_num(master_tbl[health_key].second_occurs),"*46* ", cvt_num(master_tbl[health_key].total_sleep),"*47* ", cvt_num(master_tbl[health_key].days),"*48* ", cvt_num(master_tbl[health_key].days_extra),"*49* ", cvt_num(master_tbl[health_key].days_none),"*50* ", cvt_num(master_tbl[health_key].miles_walk),"*51* ", cvt_num(master_tbl[health_key].minutes_lamp),"*52* ", cvt_num(master_tbl[health_key].min_yoga),"*53* ", cvt_num(master_tbl[health_key].neck_perc),"*54* ", cvt_num(master_tbl[health_key].stretch_perc),"*55* ", cvt_num(master_tbl[health_key].jg),"*56* ", cvt_num(master_tbl[health_key].massheat),"*57* ", cvt_num(master_tbl[health_key].massvib),"*58* ", cvt_num(master_tbl[health_key].bed_time),"*59* ", cvt_num(master_tbl[health_key].chronotype),"*60* ", cvt_num(master_tbl[health_key].fast),"*61* ", cvt_num(master_tbl[health_key].a1c),"*62* ", cvt_num(master_tbl[health_key].sodium),"*63* ", cvt_num(master_tbl[health_key].potassium),"*64* ", cvt_num(master_tbl[health_key].chloride),"*65* ", cvt_num(master_tbl[health_key].carbon_dioxide),"*66* ", cvt_num(master_tbl[health_key].bun),"*67* ", cvt_num(master_tbl[health_key].creatnine),"*68* ", cvt_num(master_tbl[health_key].gfr),"*69* ", cvt_num(master_tbl[health_key].ast),"*70* ", cvt_num(master_tbl[health_key].alt),"*71* ", cvt_num(master_tbl[health_key].bilirubin_tot),"*72* ", cvt_num(master_tbl[health_key].alk_phosphatase),"*73* ", cvt_num(master_tbl[health_key].protein_total),"*74* ", cvt_num(master_tbl[health_key].albumin),"*75* ", cvt_num(master_tbl[health_key].calcium),"*76* ", cvt_num(master_tbl[health_key].glucose),"*77* ", cvt_num(master_tbl[health_key].triglycerides),"*78* ", cvt_num(master_tbl[health_key].cholesterol),"*79* ", cvt_num(master_tbl[health_key].hdl),"*80* ", cvt_num(master_tbl[health_key].ldl),"*81* ", cvt_num(master_tbl[health_key].ldl_hdl_ratio),"*82* ", cvt_num(master_tbl[health_key].chol_hdl_ratio),"*83* ", cvt_num(master_tbl[health_key].alb_creat_ratio),"*84* ", cvt_num(master_tbl[health_key].psa),"*85* ", cvt_num(master_tbl[health_key].ammonia), "*86* ", cvt_num(master_tbl[health_key].agap), "*87*", cvt_num_bm(master_tbl[health_key].bms), "*88*", cvt_num_bm(master_tbl[health_key].bm_angle), "*89 ", cvt_num_bm(master_tbl[health_key].bm_sz, "*90*")) } end procedure fix_it(it) ret := trim(it, ws) ret := reverse(ret) ret := trim(ret, ws) ret := reverse(ret) if ret == "" then ret := "NA" ret := map(ret," ","*") return ret end procedure cvt_num(it) if (ret := numeric(it)) then { return(ret) } if \it & (it ? ((tab(many('('))) & (ret := tab(many('1234567890.'))) & tab(many(')')))) then { if ret ~== "" then { return(ret) } } if \it & (it ? ((ret := tab(many('1234567890.'))) & tab(many('*') & tab(many(&lcase ++ &ucase))))) then { if ret ~== "" then { return(ret) } else { return(-9999.0) } } return(-9999.0) end procedure cvt_num_bm(it) if \it & it ~== 0 then return(it) else { return(-9999.0) } end procedure init() # &trace := -1 digits := '1234567890' valid := digits ++ '-.NAna' valid_cnt := digits ++ '()' ws := " " in_path := "./" glu_fname := in_path || "glucout2.txt" nutrition_fname := in_path || "nutrition.txt" rest_fname := in_path || "restout.txt" labs_fname := in_path || "labs.html" bms_fname := in_path || "bm_info.txt" 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(&errout, "Open Failed" || glu_fname) fail } nutrition_fd := open(nutrition_fname,"r") | { write(&errout, "Open Failed" || nutrition_fname) fail } rest_fd := open(rest_fname,"r") | { write(&errout, "Open Failed" || rest_fname) fail } labs_fd := open(labs_fname,"r") | { write(&errout, "Open Failed" || labs_fname) fail } bms_fd := open(bms_fname,"r") | { write(&errout, "Open Failed" || bms_fname) fail } health_fd := open(health_fname,"w") | { write(&errout, "Open Failed" || health_fname) fail } health_num_fd := open(health_fname_num,"w") | { write("Open Failed" || health_fname_num) fail } health_num_fd_dbg := open(health_fname_num_dbg,"w") | { write("Open Failed" || health_fname_num_dbg) fail } DJDDBG := open("DJD_DBG.tmp","w") | { write(&errout, "Open Failed" || DJD_DBG.tmp) fail } have_glu := table(0) have_nutrition := table(0) have_rest := table(0) have_labs := table(0) have_bms := 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 return 0 end procedure process_glu() line := read(glu_fd) line := read(glu_fd) count := 2 while line := read(glu_fd) do { 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_cnt)) & wgt_cnt := tab(many(valid_cnt)) & tab(upto(valid)) & glu_avg := tab(many(valid)) & tab(upto(valid_cnt)) & glu_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 write(&errout, "FOUND GLU date = ", chron) if chron < 199601 then { write(&errout, "Error oldest = ",oldest," in glu") fail } if chron > 206012 then { write(&errout, "Error newest = ",newest," in glu") fail } 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 #NUTRITION 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" #REST first_sleep := "NA" second_sleep := "NA" second_occurs := "NA" total_sleep := "NA" days := "NA" days_extra := "NA" days_none := "NA" miles_walk := "NA" minutes_lamp := "NA" min_yoga := "NA" neck_perc := "NA" stretch_perc := "NA" jg := "NA" massheat := "NA" massvib := "NA" bed_time := "NA" chronotype := "NA" #LABS 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" #BMS bms := "NA" bm_angle := "NA" bm_sz := "NA" master_tbl[glu_key] := health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bm_angle,bm_sz) count +:= 1 } else { write("Match fails in Glucose line number = ", count) write("Match fails line = ", line) } } return 0 end procedure process_nutrition() # 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 { 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(&errout, "Error oldest = ",oldest," in nutrition") fail } if chron > 206012 then { write(&errout, "Error newest = ",newest," in nutrition") fail } } else { if *line > 0 then { write("Match fails in Nutrition line number = ", count2) write("Match fails in Nutrition line = ", line) } } if chron < oldest then oldest := chron if chron > newest then newest := chron if *mo = 1 then mo := "0" || mo have_nutrition[nutrition_key] := 1 # started measuring peanut butter & brumel & brown June 2018 nutrition_key := yr || "/" || mo if have_glu[nutrition_key] = 0 then { wgt := "NA" wgt_cnt := "NA" glu_avg := "NA" glu_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" # REST first_sleep := "NA" second_sleep := "NA" second_occurs := "NA" total_sleep := "NA" days := "NA" days_extra := "NA" days_none := "NA" miles_walk := "NA" minutes_lamp := "NA" min_yoga := "NA" neck_perc := "NA" stretch_perc := "NA" jg := "NA" massheat := "NA" massvib := "NA" bed_time := "NA" chronotype := "NA" # LABS 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" #BMS bms := "NA" bm_angle := "NA" bm_sz := "NA" master_tbl[nutrition_key] := health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bm_angle,bm_sz) } 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 } return 0 end procedure process_rest() line := read(rest_fd) line := read(rest_fd) count3 := 2 while line := read(rest_fd) do { 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)) & minutes_lamp := 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)) & jg := tab(many(valid)) & tab(upto(valid)) & massheat := tab(many(valid)) & tab(upto(valid)) & massvib := tab(many(valid)) & tab(upto(valid)) & bed_time := tab(many(valid)) & tab(upto(valid)) & chronotype := tab(many(valid)))) then { chron := 100 * yr + mo if chron < 199601 then { write(&errout, "Error oldest = ",oldest," in rest") fail } if chron > 206012 then { write(&errout, "Error newest = ",newest," in rest") fail } 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 { #GLU 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" # NUTRITION 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" #LABS 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" #BMS bms := "NA" bm_angle := "NA" bm_sz := "NA" master_tbl[nutrition_key] := health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bm_angle,bm_sz) } 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].minutes_lamp := minutes_lamp 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].jg := jg master_tbl[rest_key].massheat := massheat master_tbl[rest_key].massvib := massvib master_tbl[rest_key].bed_time := bed_time master_tbl[rest_key].chronotype := chronotype } count3 +:= 1 } else { if *line > 0 then { write("Match fails in Rest line number = ", count3) write("Match fails in Rest line = ", line) } else write("Match fails in Rest line number = ", count3) } } return 0 end procedure process_labs() ########################################################################### check := "start" count4 := 0 line := read(labs_fd) while count4 < 2 do { if line ? tab(match("")) then count4 +:= 1 line := read(labs_fd) } line := read(labs_fd) count4 := 2 check := date := get_next_data() while check ~== "" do { fast := get_next_data() a1c := get_next_data() sodium := get_next_data() potassium := get_next_data() chloride := get_next_data() carbon_dioxide := get_next_data() bun := get_next_data() creatnine := get_next_data() gfr := get_next_data() ast := get_next_data() alt := get_next_data() bilirubin := get_next_data() alk_phosphatase := get_next_data() protein_total := get_next_data() albumin := get_next_data() calcium := get_next_data() glucose := get_next_data() triglycerides := get_next_data() cholesterol := get_next_data() hdl := get_next_data() ldl := get_next_data() ldl_hdl_ratio := get_next_data() chol_hdl_ratio := get_next_data() alb_creat_ratio := get_next_data() psa := get_next_data() ammonia := get_next_data() agap := get_next_data() 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) 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(&errout, "Error oldest = ",oldest," in labs") fail } if chron > 206012 then { write(&errout, "Error newest = ",newest," in labs") } if chron < oldest then oldest := chron if chron > newest then newest := chron if *mo = 1 then mo := "0" || mo labs_key := yr || "/" || mo have_labs[labs_key] := 1 if (have_glu[labs_key] = 0 & have_nutrition[labs_key] = 0 & have_rest[labs_key] = 0) then { #GLU 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" #NUTRITION 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" #REST first_sleep := "NA" second_sleep := "NA" second_occurs := "NA" total_sleep := "NA" days := "NA" days_extra := "NA" days_none := "NA" miles_walk := "NA" minutes_lamp := "NA" min_yoga := "NA" neck_perc := "NA" stretch_perc := "NA" jg := "NA" massheat := "NA" massvib := "NA" bed_time := "NA" chronotype := "NA" #BMS bms := "NA" bm_angle := "NA" bm_sz := "NA" bms := "NA" bm_angle := "NA" bm_sz := "NA" master_tbl[labs_key] := health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bms_angle,bm_sz) } else { master_tbl[labs_key].yr := yr master_tbl[labs_key].mo := mo 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 } check := date := get_next_data() count4 +:= 1 } return 0 ########################################################################## end ############################################### procedure process_bms() line := read(bms_fd) count5 := 1 while line := read(bms_fd) do { if (line ? (tab(upto(digits)) & mo := tab(upto('/')) & tab(upto(digits)) & yr := tab(many(digits)) & tab(upto(valid)) & bms := tab(many(valid)) & tab(upto(valid)) & bm_angle := tab(many(valid)) & tab(upto(valid)) & bm_sz := tab(many(valid)))) then { chron := 100 * yr + mo if chron < 199601 then { write(&errout, "Error oldest = ",oldest," in rest") fail } if chron > 206012 then { write(&errout, "Error newest = ",newest," in rest") fail } if chron < oldest then oldest := chron if chron > newest then newest := chron if *mo = 1 then mo := "0" || mo bms_key := yr || "/" || mo have_bms[bms_key] := 1 if have_glu[bms_key] = 0 & have_nutrition[bms_key] = 0 & have_labs[bms_key] = 0 & have_rest[bm_key] = 0 then { # GLU 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" #REST first_sleep := "NA" second_sleep := "NA" second_occurs := "NA" total_sleep := "NA" days := "NA" days_extra := "NA" days_none := "NA" miles_walk := "NA" minutes_lamp := "NA" min_yoga := "NA" neck_perc := "NA" stretch_perc := "NA" jg := "NA" massheat := "NA" massvib := "NA" bed_time := "NA" chronotype := "NA" #LABS 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" #NUTRITION 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" master_tbl[nutrition_key] := health_row(yr,mo,wgt,wgt_cnt,glu_avg,glu_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,minutes_lamp,min_yoga,neck_perc,stretch_perc,jg,massheat,massvib,bed_time,chronotype,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,bms,bm_angle,bm_sz) } else { master_tbl[bms_key].bms := bms master_tbl[bms_key].bm_angle := bm_angle master_tbl[bms_key].bm_sz := bm_sz } count5 +:= 1 } else { write("Match fails in BMS line number = ", count5) } } return 0 end ############################### procedure write_it_out() 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 } } end procedure finish() close(glu_fd) close(nutrition_fd) close(rest_fd) close(health_fd) close(health_num_fd) close(health_num_fd_dbg) end procedure get_next_data() local it static initial_state := 0 static expect_tr := 1 static expect_td := 2 static expect_data_end_td := 3 static expect_end_tr := 4 static done := 0 static item_count := 0 static state := 0 static total_items := 28 static line_labs if done = 1 then return("") if state = initial_state then { line_labs := next_line() state := expect_tr } line_labs ?:= { tab(many(' \t')) & tab(0) } if *line_labs == 0 then line_labs := next_line() while state ~= expect_data_end_td do { line_labs ?:= { tab(many(' \t')) & tab(0) } if *line_labs == 0 then line_labs := next_line() if line_labs ? match("") then { done := 1 return("") } else if state == expect_td then if (line_labs ? (upto('<') & tab(match("")) & rem := tab(0))) then { state := expect_data_end_td line_labs := rem break } else { write(&errout, "Expected line = ", line_labs) write(&errout, "item_count = ", item_count) exit(0) } else if state = expect_end_tr then if (line_labs ? (tab(match("")) & rem := tab(0))) then { state := expect_tr line_labs := rem } else { write(&errout, "Expected line = ", line_labs) exit(0) } else if state == expect_tr then if (line_labs ? (tab(match("")) & rem := tab(0))) then { state := expect_td line_labs := rem } else { write(&errout, "Expected line = ", line_labs) exit(0) } } if (line_labs ? (thing := tab(upto('<')) & tab(match("")) & rest := tab(0) )) then { item_count +:= 1 line_labs := rest if item_count = total_items then { state := expect_end_tr item_count := 0 } else state := expect_td } else { write(&errout, "expected data line = ", line_labs) state := expect_td } return thing end procedure next_line() static count_it := 0 line_lab := "" while (*line_lab = 0) do { line_lab := trim(read(labs_fd)) line_lab ?:= { tab(many(' \t')) & tab(0) } } count_it +:= 1 return line_lab end #######################################