LDL Cholesterol calculation
- Posted by jmduro 1 month ago
- 1218 views
Here is code to calulate LDL Cholesterol by the Martin-Hopkins formula which works even with high levels of triglycerides or total cholesterol.
It has been checked with EU 4.2.0 development.
include std/console.e include std/io.e constant factor_table= { { 3.5, 3.4, 3.3, 3.3, 3.2, 3.1}, { 4 , 3.9, 3.7, 3.6, 3.6, 3.4}, { 4.3, 4.1, 4 , 3.9, 3.8, 3.6}, { 4.5, 4.3, 4.1, 4 , 3.9, 3.9}, { 4.7, 4.4, 4.3, 4.2, 4.1, 3.9}, { 4.8, 4.6, 4.4, 4.2, 4.2, 4.1}, { 4.9, 4.6, 4.5, 4.3, 4.3, 4.2}, { 5 , 4.8, 4.6, 4.4, 4.3, 4.2}, { 5.1, 4.8, 4.6, 4.5, 4.4, 4.3}, { 5.2, 4.9, 4.7, 4.6, 4.4, 4.3}, { 5.3, 5 , 4.8, 4.7, 4.5, 4.4}, { 5.4, 5.1, 4.8, 4.7, 4.5, 4.3}, { 5.5, 5.2, 5 , 4.7, 4.6, 4.5}, { 5.6, 5.3, 5 , 4.8, 4.6, 4.5}, { 5.7, 5.4, 5.1, 4.9, 4.7, 4.5}, { 5.8, 5.5, 5.2, 5 , 4.8, 4.6}, { 6 , 5.5, 5.3, 5 , 4.8, 4.6}, { 6.1, 5.7, 5.3, 5.1, 4.9, 4.7}, { 6.2, 5.8, 5.4, 5.2, 5 , 4.7}, { 6.3, 5.9, 5.6, 5.3, 5 , 4.8}, { 6.5, 6 , 5.7, 5.4, 5.1, 4.8}, { 6.7, 6.2, 5.8, 5.4, 5.2, 4.9}, { 6.8, 6.3, 5.9, 5.5, 5.3, 5 }, { 7 , 6.5, 6 , 5.7, 5.4, 5.1}, { 7.3, 6.7, 6.2, 5.8, 5.5, 5.2}, { 7.6, 6.9, 6.4, 6 , 5.6, 5.3}, { 8 , 7.2, 6.6, 6.2, 5.9, 5.4}, { 8.5, 7.6, 7 , 6.5, 6.1, 5.6}, { 9.5, 8.3, 7.5, 7 , 6.5, 5.9}, {11.9, 10 , 8.8, 8.1, 7.5, 6.7} } -- CT, TG, HDL en g/L function martin_hopkins(atom CT, atom TG, atom HDL) integer lig=0, col=0, tg=TG*100 -- tg, nonhdl en mg/dL atom factor=5.0, nonhdl=(CT-HDL)*100 if (tg<50) then lig=1 elsif (tg>=50) and (tg<57) then lig=2 elsif (tg>=57) and (tg<62) then lig=3 elsif (tg>=62) and (tg<67) then lig=4 elsif (tg>=67) and (tg<72) then lig=5 elsif (tg>=72) and (tg<76) then lig=6 elsif (tg>=76) and (tg<80) then lig=7 elsif (tg>=80) and (tg<84) then lig=8 elsif (tg>=84) and (tg<88) then lig=9 elsif (tg>=88) and (tg<93) then lig=10 elsif (tg>=93) and (tg<97) then lig=11 elsif (tg>=97) and (tg<101) then lig=12 elsif (tg>=101) and (tg<106) then lig=13 elsif (tg>=106) and (tg<111) then lig=14 elsif (tg>=111) and (tg<116) then lig=15 elsif (tg>=116) and (tg<121) then lig=16 elsif (tg>=121) and (tg<127) then lig=17 elsif (tg>=127) and (tg<133) then lig=18 elsif (tg>=133) and (tg<139) then lig=19 elsif (tg>=139) and (tg<147) then lig=20 elsif (tg>=147) and (tg<155) then lig=21 elsif (tg>=155) and (tg<164) then lig=22 elsif (tg>=164) and (tg<174) then lig=23 elsif (tg>=174) and (tg<186) then lig=24 elsif (tg>=186) and (tg<202) then lig=25 elsif (tg>=202) and (tg<221) then lig=26 elsif (tg>=221) and (tg<248) then lig=27 elsif (tg>=248) and (tg<293) then lig=28 elsif (tg>=293) and (tg<400) then lig=29 elsif (tg>=400) then lig=30 end if if (nonhdl<100) then col=1 elsif (nonhdl>=100) and (nonhdl<130) then col=2 elsif (nonhdl>=130) and (nonhdl<160) then col=3 elsif (nonhdl>=160) and (nonhdl<190) then col=4 elsif (nonhdl>=190) and (nonhdl<220) then col=5 elsif (nonhdl>=220) then col=6 end if factor = factor_table[lig][col] return CT - HDL - (TG/factor) end function atom CT = prompt_number("Total Cholesterol (g/L):\n", {}) atom TG = prompt_number("Triglycerides (g/L):\n", {}) atom HDL = prompt_number("HDL Cholesterol (g/L):\n", {}) printf(STDOUT, "LDL Cholesterol (g/L): %.3f\n", martin_hopkins(CT, TG, HDL)) maybe_any_key()
Jean-Marc