Adding the calculator base with types and the first calculator (CockCroft Gault Equation)
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { Calculator, Input, Interpretation } from "../types";
|
||||
|
||||
const parameters:Input[] = [
|
||||
{
|
||||
id:"gender",
|
||||
type:"radio",
|
||||
inputOptions:[
|
||||
{
|
||||
label:"Male",
|
||||
value:"male"
|
||||
},
|
||||
{
|
||||
label:"Female",
|
||||
value:"female"
|
||||
}
|
||||
],
|
||||
required:true
|
||||
},
|
||||
{
|
||||
id:"age",
|
||||
type:"number",
|
||||
min:18,
|
||||
max:95,
|
||||
required:true
|
||||
},
|
||||
{
|
||||
id:"creatinine",
|
||||
type:"number",
|
||||
min:0.2,
|
||||
max:20,
|
||||
required:true
|
||||
},
|
||||
{
|
||||
id:"weight",
|
||||
type:"number",
|
||||
min:0,
|
||||
required:true
|
||||
}
|
||||
];
|
||||
function calc_func(gender:"male" | "female", age:number, creatinine:number, weight:number):number{
|
||||
return gender === "male"
|
||||
? ((140 - age) * weight)/(72 * creatinine)
|
||||
: (((140 - age) * weight)/(72 * creatinine)) * 0.85;
|
||||
}
|
||||
function interpret_func(gfr:number):Interpretation{
|
||||
if(gfr >= 90){
|
||||
return {
|
||||
level:"none",
|
||||
message:"Glomerular Filtration Rate (GFR) is normal or on the higher side, To be correlated with other clinical clues",
|
||||
diagnosis:"CKD Stage 1"
|
||||
}
|
||||
}else if(gfr < 90 && gfr >= 60){
|
||||
return {
|
||||
level:"low",
|
||||
message:"Glomerular Filtration Rate (GFR) is slightly reduced, To be correlated with other clinical clues",
|
||||
diagnosis:"CKD Stage 2"
|
||||
}
|
||||
}else if(gfr < 60 && gfr >= 45){
|
||||
return{
|
||||
level:"moderate",
|
||||
message:"Glomerular Filtration Rate (GFR) is moderately reduced",
|
||||
advice:"Consult a Nephrologist",
|
||||
diagnosis:"CKD Stage 3A"
|
||||
}
|
||||
}else if(gfr < 45 && gfr >= 30){
|
||||
return{
|
||||
level:"high",
|
||||
message:"Glomerular Filtration Rate (GFR) is significantly reduced",
|
||||
advice:"Consult a Nephrologist urgently",
|
||||
diagnosis:"CKD Stage 3B"
|
||||
}
|
||||
}else if(gfr < 30 && gfr >= 15){
|
||||
return{
|
||||
level:"high",
|
||||
message:"Glomerular Filtration Rate (GFR) is largely reduced",
|
||||
advice:"Consult a Nephrologist urgently",
|
||||
diagnosis:"CKD Stage 4"
|
||||
}
|
||||
}else{
|
||||
return{
|
||||
level:"severe",
|
||||
message:"Glomerular Filtration Rate (GFR) is severely reduced",
|
||||
advice:"Consult a Nephrologist urgently to consider dialysis",
|
||||
diagnosis:"CKD Stage 5 / ESRD (End Stage Renal Disease)"
|
||||
}
|
||||
}
|
||||
}
|
||||
export const cockcroftGault: Calculator = {
|
||||
id:"cockcroft-gault",
|
||||
name:"Cockcroft Gault Equation",
|
||||
desc:"The CockCroft Gault equation is a formula which is used to find the CrCl (Creatinine Clearance) of an individual on the basis of Age, Weight, Gender and Creatinine",
|
||||
unit:"mL/min",
|
||||
inputs:parameters,
|
||||
calc_func:calc_func,
|
||||
interpret_func:interpret_func
|
||||
}
|
||||
14
src/app/utils/calculators/registry.ts
Normal file
14
src/app/utils/calculators/registry.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { cockcroftGault } from "./miscellaneous/cockcroft-gault-eq";
|
||||
import { Section } from "./types";
|
||||
|
||||
export const CalculatorRegistry : Record<string, Section> = {
|
||||
miscellaneous:{
|
||||
id:"miscellaneous",
|
||||
displayName:"Miscellaneous",
|
||||
textColor:"#ccc",
|
||||
svg:"",
|
||||
calculators:[
|
||||
cockcroftGault
|
||||
]
|
||||
}
|
||||
}
|
||||
37
src/app/utils/calculators/types.ts
Normal file
37
src/app/utils/calculators/types.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export interface Calculator {
|
||||
id:string,
|
||||
name:string,
|
||||
desc:string,
|
||||
unit?:string,
|
||||
inputs:Input[],
|
||||
calc_func:Function,
|
||||
interpret_func:Function
|
||||
}
|
||||
interface inputOptions {
|
||||
label:string,
|
||||
value:string | number | Date;
|
||||
}
|
||||
export interface Input{
|
||||
id:string,
|
||||
type: "number" | "text" | "radio",
|
||||
inputOptions?:inputOptions[],
|
||||
min?:number,
|
||||
max?:number,
|
||||
required?:boolean,
|
||||
defaultUnit?:string,
|
||||
unitOptions?:string[]
|
||||
}
|
||||
|
||||
export interface Interpretation{
|
||||
level?: "none" | "low" | "moderate" | "high" | "severe",
|
||||
diagnosis?:string,
|
||||
message:string,
|
||||
advice?:string
|
||||
}
|
||||
export interface Section {
|
||||
id:string,
|
||||
displayName:string,
|
||||
textColor:string,
|
||||
svg:string,
|
||||
calculators:Calculator[]
|
||||
}
|
||||
Reference in New Issue
Block a user