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

129 lines
4.3 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;
},
getFullMedicationInformation: async (drugId) => {
const [medInformation, medRoutes] = await Promise.all([
paramyxRunQuery(
`select
m.id,
m.generic,
m.trade,
m.system,
mi.class,
mi.indications,
mi.contraindications,
mi.precautions,
mi.adverse,
mi.onset,
mi.duration,
mi.tip,
mi.action
from medications m inner join medication_information mi on m.id = mi.id where m.id = $1;`,
[drugId]
),
paramyxRunQuery(`select * from medication_routes mr where medication_id = $1;`, [drugId])
]);
const fullMedicationInformation = {
...medInformation[0]
};
medRoutes?.forEach((row) => {
if (row?.is_adult) {
fullMedicationInformation.adult = {
totalMax: row.total_max,
iv: row.intravenous,
io: row.intraosseous,
im: row.intramuscular,
in: row.intranasal,
po: row.oral,
sl: row.sublingual,
pr: row.rectal,
neb: row.nebulizer,
et: row.endotracheal,
sga: row.supraglottic
}
} else {
fullMedicationInformation.pediatric = {
totalMax: row.total_max,
iv: row.intravenous,
io: row.intraosseous,
im: row.intramuscular,
in: row.intranasal,
po: row.oral,
sl: row.sublingual,
pr: row.rectal,
neb: row.nebulizer,
et: row.endotracheal,
sga: row.supraglottic
}
}
});
return fullMedicationInformation;
}
};