October 1, 2016 : Approach to Allowable Blood Loss Theory
© 安岡喜晴 (JoyShine)
I went to bed in the morning and woke up around 7:30 PM.
After getting up, I continued to develop the Allowable Blood Loss Theory for the
Medical Calculator.
There were a lot of cases to handle (patient type, weight unit, HCT values), so it was a bit tedious to implement.
inline void calc_allowable_blood_loss(const double* in,
wchar_t* disp, size_t dsz,
wchar_t* pri, size_t psz,
wchar_t* det, size_t esz) {
int pt, wu;
if (!val_choice(in[0], 5, &pt) || !val_choice(in[2], 2, &wu)) {
calc_err(disp, dsz, pri, psz, det, esz,
L"Patient type must be 1-5; weight unit must be 1 (lbs) or 2 (kg).");
return;
}
if (pt == 0 || wu == 0) {
calc_err(disp, dsz, pri, psz, det, esz,
L"Patient type 0 and weight-unit 0 are reserved sentinels — pick a defined option.");
return;
}
double weight = in[1];
double hct_i = in[3], hct_l = in[4];
if (!val_pos(weight) || !val_pos(hct_i) || !val_nonneg(hct_l) || hct_l > hct_i) {
calc_err(disp, dsz, pri, psz, det, esz,
L"Weight and initial HCT must be > 0; lowest HCT must be >= 0 and not exceed initial HCT.");
return;
}
double avg_bv;
const wchar_t* pt_label;
switch (pt) {
case 1: avg_bv = 75; pt_label = L"Adult Man"; break;
case 2: avg_bv = 65; pt_label = L"Adult Woman"; break;
case 3: avg_bv = 80; pt_label = L"Infant"; break;
case 4: avg_bv = 95; pt_label = L"Premature Neonate"; break;
case 5: avg_bv = 85; pt_label = L"Full Term Neonate"; break;
default: avg_bv = 70; pt_label = L"(unknown)";
}
double w_kg = (wu == 1) ? (weight * 0.45359237) : weight;