Skip to content

Commit

Permalink
added in micrograms (with warning) and disclaimer
Browse files Browse the repository at this point in the history
  • Loading branch information
timrobinson33 committed Apr 6, 2021
1 parent f33f547 commit 222a92e
Showing 1 changed file with 106 additions and 66 deletions.
172 changes: 106 additions & 66 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,114 @@ import _ from 'lodash'
const divide = '\u00f7'

const medicines = [
{ drugName: "" },
{
drugName: "",
units: "mg"
},
{
drugName: "Morphine 1st Line",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 10, ml: 1 },
{ mg: 15, ml: 1 },
{ mg: 20, ml: 1 },
{ mg: 30, ml: 1 },
{ mg: 10, ml: 2 },
{ mg: 15, ml: 2 },
{ mg: 20, ml: 2 },
{ mg: 30, ml: 2 },
{ amount: 0 },
{ amount: 10, volume: 1 },
{ amount: 15, volume: 1 },
{ amount: 20, volume: 1 },
{ amount: 30, volume: 1 },
{ amount: 10, volume: 2 },
{ amount: 15, volume: 2 },
{ amount: 20, volume: 2 },
{ amount: 30, volume: 2 },
]
},
{
drugName: "Diamorphine",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 10, ml: 1 },
{ mg: 15, ml: 1 },
{ mg: 30, ml: 1 },
{ mg: 100, ml: 1 },
{ mg: 10, ml: 2 },
{ mg: 15, ml: 2 },
{ mg: 30, ml: 2 },
{ mg: 100, ml: 2 },
{ amount: 0 },
{ amount: 10, volume: 1 },
{ amount: 15, volume: 1 },
{ amount: 30, volume: 1 },
{ amount: 100, volume: 1 },
{ amount: 10, volume: 2 },
{ amount: 15, volume: 2 },
{ amount: 30, volume: 2 },
{ amount: 100, volume: 2 },
]
},
{
drugName: "Oxycodone",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 10, ml: 1 },
{ mg: 20, ml: 2 },
{ mg: 50, ml: 1 },
{ amount: 0 },
{ amount: 10, volume: 1 },
{ amount: 20, volume: 2 },
{ amount: 50, volume: 1 },
]
},
{
drugName: "Fentanyl",
units: "mcg",
strengths: [
{ mg: 0 },
{ mg: 0.05, ml: 1 },
{ mg: 0.1, ml: 2 },
{ mg: 0.5, ml: 5 },
{ amount: 0 },
{ amount: 50, volume: 1 },
{ amount: 100, volume: 2 },
{ amount: 500, volume: 5 },
]
},
{
drugName: "Haloperidol",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 5, ml: 1 },
{ amount: 0 },
{ amount: 5, volume: 1 },
]
},
{
drugName: "Metoclopramide",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 10, ml: 2 },
{ amount: 0 },
{ amount: 10, volume: 2 },
]
},
{
drugName: "Cyclizine",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 50, ml: 1 },
{ amount: 0 },
{ amount: 50, volume: 1 },
]
},
{
drugName: "Levomepromazine",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 25, ml: 1 },
{ amount: 0 },
{ amount: 25, volume: 1 },
]
},
{
drugName: "Midazolam",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 10, ml: 2 },
{ amount: 0 },
{ amount: 10, volume: 2 },
]
},
{
drugName: "Hyoscine Butylbromide",
units: "mg",
strengths: [
{ mg: 0 },
{ mg: 20, ml: 1 },
{ amount: 0 },
{ amount: 20, volume: 1 },
]
},
{
drugName: "Hyoscine Hydrobromide",
units: "mcg",
strengths: [
{ mg: 0 },
{ mg: 0.4, ml: 1 },
{ amount: 0 },
{ amount: 400, volume: 1 },
]
},
]
Expand All @@ -108,29 +122,32 @@ function formatNumber(n) {
}

function Results({ drugIdx, strengthIdx, prescribedDose, numStatDoses, statDoseStrength }) {
const units = medicines[drugIdx].units
const drugStrength = medicines[drugIdx].strengths[strengthIdx]
const totalDoseMg = prescribedDose + numStatDoses * statDoseStrength
const totalDoseMl = totalDoseMg / drugStrength.mg * drugStrength.ml
const numVials = _.ceil(totalDoseMl / drugStrength.ml)
const wasteMl = numVials * drugStrength.ml - totalDoseMl
const wasteMg = numVials * drugStrength.mg - totalDoseMg
return <>
<div>
<span>Total dose (mg): {prescribedDose} + ({numStatDoses} x {statDoseStrength}) = {totalDoseMg}mg</span>
</div>
<div>
<span>Total dose (ml): {totalDoseMg} {divide} {drugStrength.mg} x {drugStrength.ml} = {formatNumber(totalDoseMl)}ml</span>
</div>
<div>
<span>Number of vials: {numVials}</span>
</div>
<div>
<span>Waste: {formatNumber(wasteMg)}mg (= {formatNumber(wasteMl)}ml)</span>
</div>
</>
const totalDose = prescribedDose + numStatDoses * statDoseStrength
const totalDoseMl = totalDose / drugStrength.amount * drugStrength.volume
const numVials = _.ceil(totalDoseMl / drugStrength.volume)
const waste = numVials * drugStrength.amount - totalDose
const wasteMl = numVials * drugStrength.volume - totalDoseMl
return (
<>
<div>
<span>Total dose ({units}): {prescribedDose} + ({numStatDoses} x {statDoseStrength}) = {totalDose}{units}</span>
</div>
<div>
<span>Total dose (ml): {totalDose} {divide} {drugStrength.amount} x {drugStrength.volume} = {formatNumber(totalDoseMl)}ml</span>
</div>
<div>
<span>Number of vials: {numVials}</span>
</div>
<div>
<span>Waste: {formatNumber(waste)}{units} (= {formatNumber(wasteMl)}ml)</span>
</div>
</>
)
}

export default function App() {
function MainView() {
const [drugIdx, setDrugIdx] = useState(0)
const [strengthIdx, setStrengthIdx] = useState(0)
const [prescribedDoseStr, setPrescribedDoseStr] = useState("")
Expand All @@ -140,9 +157,13 @@ export default function App() {

const prescribedDose = Number(prescribedDoseStr)
const statDoseStrength = Number(statDoseStrengthStr)
const units = medicines[drugIdx].units
const showCalc = !showResults && !!(prescribedDose || (statDoseStrength && numStatDoses))

function selectDrug(i) {
if (medicines[i].units !== "mg") {
alert(`NOTE: ${medicines[i].drugName} is measured in micrograms (mcg or μg), not milligrams (mg).\nThere are 1000mcg in 1mg`)
}
setDrugIdx(i)
selectStrength(0)
}
Expand Down Expand Up @@ -172,14 +193,14 @@ export default function App() {
{!!drugIdx && <div>
<span>Strength: </span>
<select value={strengthIdx} disabled={showResults} onChange={e => selectStrength(parseInt(e.target.value))}>
{medicines[drugIdx].strengths.map((x, i) => <option key={i} value={i}>{x.mg ? `${x.mg}mg/${x.ml}ml` : ""}</option>)}
{medicines[drugIdx].strengths.map((x, i) => <option key={i} value={i}>{x.amount ? `${x.amount}${units}/${x.volume}ml` : ""}</option>)}
</select>
</div>}
{!!strengthIdx && <>
<div>
<span>Prescribed dose: </span>
<input type="number" disabled={showResults} min={0} value={prescribedDoseStr} onChange={e => setPrescribedDoseStr(e.target.value)} />
<span> mg</span>
<span> {units}</span>
</div>
<div>
<span>Stat/PRN doses: </span>
Expand All @@ -188,15 +209,34 @@ export default function App() {
</select>
<span> x </span>
<input type="number" min={0} disabled={showResults || (!numStatDoses)} value={statDoseStrengthStr} onChange={e => setStatDoseStrengthStr(e.target.value)} />
<span> mg</span>
<span> {units}</span>
</div>
{showCalc && <div>
<button onClick={() => { setShowResults(true) }}>Calculate</button>
</div>}
{showResults &&
<Results drugIdx={drugIdx} strengthIdx={strengthIdx} prescribedDose={prescribedDose} numStatDoses={numStatDoses} statDoseStrength={statDoseStrength} />}
<button onClick={() => { selectDrug(0) }}>Clear</button>
<button onClick={() => { selectDrug(0) }}>Reset</button>
</>}
</div>
);
)
}

function Disclaimer({ callback }) {
return (
<div>
<h1>Disclaimer</h1>
<p>This application is intended to be used only to cross-check manual drug calculations.</p>
<p>It is not approved by NHS or any other healthcare body and you should not rely on it to perform drug calculations.</p>
<p>The authors accept no liability for any errors in the application.</p>
<button onClick={callback}>OK</button>
</div>
)
}

export default function App() {
const [disclaimerAgreed, setDisclaimerAgreed] = useState(false)
return disclaimerAgreed
? <MainView />
: <Disclaimer callback={() => setDisclaimerAgreed(true)} />
}

0 comments on commit 222a92e

Please sign in to comment.