-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
330 lines (309 loc) · 14.5 KB
/
index.html
File metadata and controls
330 lines (309 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Akrami Lab — Dosing Calculator</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
crossorigin="anonymous">
<style>
body{background:#ffffff;color:#212529}
.wrap{max-width:920px;margin:30px auto;padding:0 16px}
.pill{display:inline-block;padding:2px 8px;border-radius:999px;background:#f1f3f5;border:1px solid #e9ecef;color:#6c757d;font-size:12px}
.grid{display:grid;grid-template-columns:1fr;gap:12px}
@media(min-width:820px){ .grid{grid-template-columns:1fr 1fr} }
.sep{height:1px;background:#e9ecef;margin:10px 0}
@media print{ .noprint{display:none !important} }
.table-responsive{overflow-x:auto;-webkit-overflow-scrolling:touch}
.table th, .table td{white-space:nowrap;min-width:80px}
.table th:first-child, .table td:first-child{min-width:120px}
.table th:last-child, .table td:last-child{white-space:normal;min-width:150px}
@media(max-width:768px){
.edit-inputs{flex-direction:column;gap:4px}
.edit-inputs .form-control{max-width:100% !important}
.edit-inputs .text-muted{font-size:10px;margin:2px 0}
}
</style>
<!-- JavaScript libraries -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"
integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="wrap">
<h1 class="h4">Akrami Lab — Dosing Calculator <span class="pill">offline</span></h1>
<div class="card p-3">
<div class="d-flex flex-wrap align-items-center" style="gap:12px">
<label for="weight" class="mb-0">Weight (g)</label>
<input type="number" id="weight" min="1" step="1" value="590" class="form-control" style="max-width:120px" />
<button class="btn btn-primary" id="addAll">Select all</button>
<span class="text-muted">Volumes rounded to 0.01 mL</span>
</div>
<div class="sep"></div>
<div id="drugList" class="grid"><!-- checkboxes injected --></div>
</div>
<div class="card p-3 mt-3">
<h2 class="h6 mb-2">Calculated Volumes</h2>
<div class="table-responsive">
<table id="resultTable" class="table table-sm">
<thead>
<tr>
<th>Drug</th><th>Route</th><th class="text-right">Dose/Range</th><th class="text-right">Stock</th><th class="text-right">mL</th><th>Notes</th>
</tr>
</thead>
<tbody><!-- rows injected --></tbody>
<tfoot>
<tr>
<td colspan="4" class="text-right">Total (sum)</td>
<td class="text-right" id="totalMl">0.00</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="card p-3 mt-3">
<div class="d-flex align-items-center" style="gap:8px">
<h2 class="h6 mb-0">Defaults (SOP values used in calculation)</h2>
<button class="btn btn-sm btn-outline-secondary noprint" id="editToggle">Edit</button>
<button class="btn btn-sm btn-warning noprint d-none" id="saveDefaults">Save</button>
<button class="btn btn-sm btn-danger noprint d-none" id="resetDefaults">Reset to lab defaults</button>
</div>
<div class="table-responsive">
<table id="defaultsTable" class="table table-sm mt-2">
<thead>
<tr>
<th>Drug</th><th>Generic</th><th>Route</th><th class="text-right">Dose (mg/kg)</th><th class="text-right">Stock (mg/mL)</th><th class="text-right">max mL/kg</th><th>Notes</th>
</tr>
</thead>
<tbody><!-- defaults injected --></tbody>
</table>
</div>
<div class="text-muted small">These values are displayed and used in the calculation. Edit them here if your SOP changes. Saved to your browser (localStorage) on this machine.</div>
</div>
<div class="text-muted small mt-2">
⚠️ This tool performs arithmetic only. You are responsible for the correctness of inputs and clinical judgement.
</div>
</div>
</div>
<script>
/* ===== Lab defaults (EDIT HERE if you prefer static defaults) =====
NOTE: These are placeholders. Update to Akrami Lab SOP. */
const LAB_DEFAULTS = [
{ name:"Vetergesic", generic:"buprenorphine", volume_min_ml_per_100g:0.003, volume_max_ml_per_100g:0.017, route:"SC", max_ml_per_kg:2, notes:"analgesic", active:true },
{ name:"Metacam", generic:"meloxicam", volume_min_ml_per_100g:0.02, volume_max_ml_per_100g:0.02, route:"SC", max_ml_per_kg:2, notes:"NSAID", active:true },
{ name:"Bupivacaine", generic:"bupivacaine", volume_min_ml_per_100g:0.2, volume_max_ml_per_100g:0.2, route:"Local",max_ml_per_kg:3, notes:"0.25% = 2.5 mg/mL; wound infiltration", active:true },
{ name:"Dexadreson", generic:"dexamethasone", volume_min_ml_per_100g:0.05, volume_max_ml_per_100g:0.05, route:"SC", max_ml_per_kg:1, notes:"corticosteroid", active:true }
];
const ROUND_PLACES = 2;
const STORE_KEY = "akrami_dose_defaults_v1";
function loadDefaults(){
try{
const raw = localStorage.getItem(STORE_KEY);
if(!raw) return LAB_DEFAULTS.map(d=>({...d}));
const arr = JSON.parse(raw);
// Merge to ensure any new fields appear
return LAB_DEFAULTS.map((base) => {
const found = arr.find(x => x.name===base.name) || {};
return Object.assign({}, base, found);
});
}catch(e){ return LAB_DEFAULTS.map(d=>({...d})); }
}
function saveDefaults(arr){
localStorage.setItem(STORE_KEY, JSON.stringify(arr));
}
function resetDefaults(){
localStorage.removeItem(STORE_KEY);
state.defaults = loadDefaults();
}
const state = {
defaults: loadDefaults(),
editMode: false
};
const el = (sel) => document.querySelector(sel);
function roundMl(x){ const p = Math.pow(10, ROUND_PLACES); return Math.round((x + Number.EPSILON)*p)/p; }
function getDoseForCalc(drug){
const hasRange = drug.dose_min_mg_per_kg != null && drug.dose_max_mg_per_kg != null && drug.dose_min_mg_per_kg !== "" && drug.dose_max_mg_per_kg !== "";
if(hasRange){
const min = Number(drug.dose_min_mg_per_kg);
const max = Number(drug.dose_max_mg_per_kg);
if(min >= 0 && max > 0) return (min + max) / 2;
}
return Number(drug.dose_mg_per_kg||0);
}
function formatDoseText(drug){
const hasMgRange = drug.dose_min_mg_per_kg != null && drug.dose_max_mg_per_kg != null && drug.dose_min_mg_per_kg !== "" && drug.dose_max_mg_per_kg !== "";
if(hasMgRange){
const min = Number(drug.dose_min_mg_per_kg);
const max = Number(drug.dose_max_mg_per_kg);
const mid = ((min + max) / 2).toFixed(2);
return `${min}–${max} (${mid})`;
}
if(drug.volume_min_ml_per_100g != null && drug.volume_max_ml_per_100g != null && drug.volume_min_ml_per_100g !== "" && drug.volume_max_ml_per_100g !== ""){
const vmin = Number(drug.volume_min_ml_per_100g);
const vmax = Number(drug.volume_max_ml_per_100g);
return `${vmin}–${vmax} mL/100g`;
}
return `${Number(drug.dose_mg_per_kg||0)}`;
}
function computeVolume(drug, weight_g){
const kg = Number(weight_g||0) / 1000;
if(!kg || kg<=0) return {ml:0, warn:null};
let ml = 0;
// Prefer fixed volume per 100g if provided
const hasVolRange = drug.volume_min_ml_per_100g != null && drug.volume_max_ml_per_100g != null && drug.volume_min_ml_per_100g !== "" && drug.volume_max_ml_per_100g !== "";
if(hasVolRange){
const vmin = Number(drug.volume_min_ml_per_100g);
const vmax = Number(drug.volume_max_ml_per_100g);
const mid = (vmin + vmax) / 2;
ml = roundMl((mid * weight_g) / 100); // mL per 100g scaled by grams
} else {
const dose = getDoseForCalc(drug);
const stock = Number(drug.stock_mg_per_ml||0);
if(stock<=0) return {ml:0, warn:"Stock concentration is zero/invalid"};
ml = roundMl((dose * kg) / stock);
}
let warn=null;
if(drug.max_ml_per_kg){
const cap = roundMl(Number(drug.max_ml_per_kg)*kg);
if(ml>cap) warn = `Exceeds ${cap} mL cap`;
}
return {ml, warn};
}
function renderDrugCheckboxes(){
const box = el("#drugList");
box.innerHTML = "";
state.defaults.forEach((d, idx)=>{
const id = "drug_"+idx;
const item = document.createElement("div");
item.className="card";
item.style.margin="0";
item.innerHTML = `
<div class="card-block py-2 px-3">
<label class="mb-0" style="font-weight:600"><input class="mr-2" type="checkbox" data-idx="${idx}" ${d.active?"checked":""}/> ${d.name}</label>
<div class="text-muted small mt-1">${d.generic || ""} • ${d.route || ""} • ${formatDoseText(d)} mg/kg • ${d.stock_mg_per_ml} mg/mL ${d.max_ml_per_kg?`• max ${d.max_ml_per_kg} mL/kg`:""}</div>
</div>
`;
item.querySelector("input").addEventListener("change", (e)=>{
state.defaults[idx].active = e.target.checked;
updateResults();
});
box.appendChild(item);
});
}
function updateResults(){
const w = Number(el("#weight").value || 0);
const tbody = el("#resultTable tbody");
tbody.innerHTML = "";
let total = 0;
state.defaults.forEach((d)=>{
if(!d.active) return;
const {ml, warn} = computeVolume(d, w);
total += ml;
const tr = document.createElement("tr");
tr.innerHTML = `
<td>${d.name}</td>
<td>${d.route||""}</td>
<td class="text-right">${formatDoseText(d)}</td>
<td class="text-right">${d.stock_mg_per_ml || "—"}</td>
<td class="text-right"><strong>${ml.toFixed(ROUND_PLACES)}</strong></td>
<td>${warn ? `<span class="text-danger font-weight-bold">⚠ ${warn}</span>` : `<span class="text-muted">${d.notes||""}</span>`}</td>
`;
tbody.appendChild(tr);
});
el("#totalMl").textContent = total.toFixed(ROUND_PLACES);
}
function renderDefaultsTable(){
const tbody = el("#defaultsTable tbody");
tbody.innerHTML = "";
state.defaults.forEach((d, i)=>{
const editing = state.editMode;
const row = document.createElement("tr");
row.innerHTML = `
<td>${editing ? `<input type="text" data-f="name" data-i="${i}" value="${d.name}">` : d.name}</td>
<td>${editing ? `<input type="text" data-f="generic" data-i="${i}" value="${d.generic||""}">` : (d.generic||"")}</td>
<td>${editing ? `<input type="text" data-f="route" data-i="${i}" value="${d.route||""}">` : (d.route||"")}</td>
<td class="text-right">
${editing ? `
<div class="edit-inputs d-flex align-items-center justify-content-end" style="gap:6px">
<input type="number" step="0.01" min="0" class="form-control form-control-sm" style="max-width:90px" placeholder="dose mg/kg" data-f="dose_mg_per_kg" data-i="${i}" value="${d.dose_mg_per_kg ?? ""}">
<span class="text-muted small">or mg/kg range</span>
<input type="number" step="0.01" min="0" class="form-control form-control-sm" style="max-width:90px" placeholder="min" data-f="dose_min_mg_per_kg" data-i="${i}" value="${d.dose_min_mg_per_kg ?? ""}">
<input type="number" step="0.01" min="0" class="form-control form-control-sm" style="max-width:90px" placeholder="max" data-f="dose_max_mg_per_kg" data-i="${i}" value="${d.dose_max_mg_per_kg ?? ""}">
</div>
<div class="edit-inputs d-flex align-items-center justify-content-end mt-1" style="gap:6px">
<span class="text-muted small">or mL/100g range</span>
<input type="number" step="0.001" min="0" class="form-control form-control-sm" style="max-width:90px" placeholder="min" data-f="volume_min_ml_per_100g" data-i="${i}" value="${d.volume_min_ml_per_100g ?? ""}">
<input type="number" step="0.001" min="0" class="form-control form-control-sm" style="max-width:90px" placeholder="max" data-f="volume_max_ml_per_100g" data-i="${i}" value="${d.volume_max_ml_per_100g ?? ""}">
</div>
` : formatDoseText(d)}
</td>
<td class="text-right">${editing ? `<input type="number" step="0.01" min="0" data-f="stock_mg_per_ml" data-i="${i}" value="${d.stock_mg_per_ml}">` : d.stock_mg_per_ml}</td>
<td class="text-right">${editing ? `<input type="number" step="0.01" min="0" data-f="max_ml_per_kg" data-i="${i}" value="${d.max_ml_per_kg||""}">` : (d.max_ml_per_kg??"")}</td>
<td>${editing ? `<input type="text" data-f="notes" data-i="${i}" value="${d.notes||""}">` : (d.notes||"")}</td>
`;
tbody.appendChild(row);
});
// hook inputs
if(state.editMode){
tbody.querySelectorAll("input").forEach(inp=>{
inp.addEventListener("input", (e)=>{
const i = Number(e.target.dataset.i);
const f = e.target.dataset.f;
let v = e.target.value;
if(["dose_mg_per_kg","stock_mg_per_ml","max_ml_per_kg","dose_min_mg_per_kg","dose_max_mg_per_kg","volume_min_ml_per_100g","volume_max_ml_per_100g"].includes(f)){
v = v==="" ? "" : Number(v);
}
state.defaults[i][f] = v;
});
});
}
// toggle edit/save/reset buttons
el("#saveDefaults").classList.toggle("d-none", !state.editMode);
el("#resetDefaults").classList.toggle("d-none", !state.editMode);
}
/* Events */
document.addEventListener("DOMContentLoaded", ()=>{
renderDrugCheckboxes();
renderDefaultsTable();
updateResults();
el("#weight").addEventListener("input", updateResults);
el("#addAll").addEventListener("click", ()=>{
state.defaults.forEach(d=>d.active=true); renderDrugCheckboxes(); updateResults();
});
// Recalculate button removed; results update live on weight input
// copy/print removed per request
el("#editToggle").addEventListener("click", ()=>{
state.editMode = !state.editMode;
renderDefaultsTable();
});
el("#saveDefaults").addEventListener("click", ()=>{
saveDefaults(state.defaults);
state.editMode = false;
renderDefaultsTable();
renderDrugCheckboxes();
updateResults();
});
el("#resetDefaults").addEventListener("click", ()=>{
if(confirm("Reset to lab defaults and discard local changes?")){
resetDefaults();
state.editMode = false;
renderDefaultsTable();
renderDrugCheckboxes();
updateResults();
}
});
});
</script>
</body>
</html>