ShiftSync/api/services/operations/helpers/medications.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

import { paramyxRunQuery } from '../../paramyxConnection.js';
export const medicationHelpers = {
getBaseMedications: async () => {
const [medList, medRoutes] = await Promise.all([
paramyxRunQuery('SELECT * FROM medications'),
paramyxRunQuery('SELECT * FROM medication_routes')
]);
const medMap = {};
medList.forEach((med) => {
medMap[med.id] = {
id: med.id,
generic: med.generic,
trade: med.trade,
system: med.system,
adult: {
hasIV: false,
hasIO: false,
hasIM: false,
hasIN: false,
hasPO: false,
hasSL: false,
hasPR: false,
hasNEB: false,
hasET: false,
hasSGA: false
},
pediatric: {
hasIV: false,
hasIO: false,
hasIM: false,
hasIN: false,
hasPO: false,
hasSL: false,
hasPR: false,
hasNEB: false,
hasET: false,
hasSGA: false
}
};
});
medRoutes.forEach((route) => {
const medId = route.medication_id;
if (medMap[medId]) {
const target = route.is_adult ? medMap[medId].adult : medMap[medId].pediatric;
target.hasIV = !!route.intravenous;
target.hasIO = !!route.intraosseous;
target.hasIM = !!route.intramuscular;
target.hasIN = !!route.intranasal;
target.hasPO = !!route.oral;
target.hasSL = !!route.sublingual;
target.hasPR = !!route.rectal;
target.hasNEB = !!route.nebulizer;
target.hasET = !!route.endotracheal;
target.hasSGA = !!route.supraglottic;
}
});
const fullMedList = Object.values(medMap);
return fullMedList;
}
};