Adding drug dose calculator (Atorvastatin), GRACE(Discharge) score

This commit is contained in:
2026-04-06 08:59:10 +05:30
parent 4c36ad570c
commit dfe1f52545
9 changed files with 505 additions and 41 deletions

View File

@@ -0,0 +1,146 @@
import { Calculator, Drug, Input, Interpretation, Values, inputOptions } from "../types"
import { DrugRegistry } from "./drugs/drug_registry"
function generateDrugList():inputOptions[] {
const drugs:inputOptions[] = DrugRegistry.map(e => {
console.log(e.name);
const drug:inputOptions = {
label:e.name,
value:e.id
}
return drug;
});
console.log(drugs);
return drugs;
}
const parameters:Input[] = [
{
id:"drug",
name:"Drug name",
placeholder:"Select the drug by searching its name below",
type:"search",
inputOptions:generateDrugList()
},
{
id:"weight",
name:"Weight",
placeholder:"Enter the weight of the patient",
type:"number"
},
{
id:"ckd",
name:"CKD Stage",
placeholder:"Whether the patient has CKD, if yes, select the stage",
type:"select",
inputOptions:[
{
label:"None",
value:"none"
},
{
label:"CKD stage 3a",
value:"3A"
},
{
label:"CKD Stage 3B",
value:"3B"
},
{
label:"CKD Stage 4",
value:"4"
},
{
label:"CKD Stage 5 / ESRD",
value:"5"
}
]
},
{
id:"cld",
name:"CLD Stage (Child Pugh)",
placeholder:"Whether the patient has CLD, if yes, select the Child Pugh Stage",
type:"select",
inputOptions:[
{
label:"None",
value:"none"
},
{
label:"Child Pugh A",
value:"A"
},
{
label:"Child Pugh B",
value:"B"
},
{
label:"Child Pugh C",
value:"C"
}
]
}
]
export const Adult_Drug_Calculator:Calculator = {
id:"adult_drug_calculator",
name:"Adult Dose Calculator",
desc:"Adult Dose Calculator can be used to calculate the drug dosing of different dose which also accounts for different comorbidities like CKD and CLD",
inputs:parameters,
calc_func:(values : Values) : string | number => {
const drugID = values.drug as string;
const weight = values.weight as number;
const ckd = values.ckd as "none" | "3A" | "3B" | "4" | "5";
const cld = values.cld as "none" | "A" | "B" | "C";
const drug = DrugRegistry.find(e => e.id === drugID);
if(drug){
if(typeof drug.cld_dosing !== "undefined" && typeof drug.ckd_dosing !== "undefined" && ckd !== "none" && cld == "none"){
const dosingObj = drug.cld_dosing.find(e => e.stage === cld);
if(drug.isWeightBased){
return `${Math.floor(dosingObj?.dosing * weight)} ${drug.unit}`;
}else{
return `${Math.floor(dosingObj?.dosing)} ${drug.unit}` || 0;
}
}else if(typeof drug.cld_dosing !== "undefined" && cld !== "none"){
const dosingObj = drug.cld_dosing.find(e => e.stage === cld);
if(drug.isWeightBased){
return `${Math.floor(dosingObj?.dosing * weight)} ${drug.unit}`;
}else{
return `${Math.floor(dosingObj?.dosing)} ${drug.unit}` || 0;
}
}else if(typeof drug.ckd_dosing !== "undefined" && ckd !== "none"){
const dosingObj = drug.ckd_dosing.find(e => e.stage === ckd);
if(drug.isWeightBased){
return `${Math.floor(dosingObj?.dosing * weight)} ${drug.unit}`;
}else{
return `${Math.floor(dosingObj?.dosing)} ${drug.unit}` || 0;
}
}else{
if(drug.isWeightBased){
return `${Math.floor(drug.adult_dosing * weight)} ${drug.unit}`;
}else{
return `${drug.adult_dosing} ${drug.unit}`;
}
}
}else{
return -1;
}
},
interpret_func:(dosing:number | string):Interpretation => {
if(dosing === 0){
return {
level:"severe",
message:"Drug is to be avoided in patient"
}
}else if(dosing === -1){
return {
level:"none",
message:"Drug not found"
}
}else{
return {
level:"low",
message:`Calculated dosing for the drug is ${dosing ? dosing : null}`
}
}
}
}

View File

@@ -0,0 +1,24 @@
import { Drug } from "../../../types";
export const Atorvastatin:Drug = {
id:"atorvastatin",
name:"Atorvastatin",
adult_dosing:"10mg to 20mg",
pediatric_dosing:"10mg to 20mg",
isWeightBased:false,
max_dose:"80mg",
max_dose_pediatric:"20mg",
unit:"mg",
cld_dosing:[
{
stage:"B",
to_be_given:true,
dosing:"5-10mg OD",
max_dose:"20mg"
},
{
stage:"C",
to_be_given:false
}
]
};

View File

@@ -0,0 +1,23 @@
import { Drug } from "../../../types";
export const metoprolol:Drug = {
id:"metoprolol",
name:"Metoprolol",
adult_dosing:1.5,
max_dose:"200mg",
isWeightBased:true,
unit:"mg",
pediatric_dosing:0.5,
cld_dosing:[
{
stage:"B",
to_be_given:true,
dosing:0.5
},
{
stage:"C",
to_be_given:true,
dosing:0.25
}
]
}

View File

@@ -0,0 +1,8 @@
import { Drugs } from "../../types";
import { Atorvastatin } from "./Cardiology/atorvastatin";
import { metoprolol } from "./Cardiology/metoprolol";
export const DrugRegistry:Drugs = [
Atorvastatin,
metoprolol
];