This commit is contained in:
John Parkhurst 2026-02-07 12:02:12 -05:00
commit e3f86e85ab
5 changed files with 100 additions and 2 deletions

5
.gitignore vendored
View file

@ -23,4 +23,7 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
api/package-lock.json
web/package-lock.json

View file

@ -1,5 +1,6 @@
import express from 'express';
import { databaseServices } from '../index.js';
import { fullMedicationInformationSchema } from '../validations/medications.js';
export const medicationRouter = express.Router();
@ -27,4 +28,20 @@ medicationRouter.get('/base/', async (req, res) => {
} finally {
res.send(data);
}
});
medicationRouter.post('/full/', async (req, res) => {
let data;
const body = req?.body;
try {
await fullMedicationInformationSchema.validate(body);
data = await databaseServices.getFullMedicationInformation(body);
res.status(200);
} catch (err) {
data = { Error: err?.message };
res.status(500);
} finally {
res.send(data);
}
});

View file

@ -64,5 +64,66 @@ export const medicationHelpers = {
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;
}
};

View file

@ -21,7 +21,19 @@ const getBaseMedications = async () => {
}
}
const getFullMedicationInformation = async (drug) => {
const { drugId } = drug;
try {
const dataResp = medicationHelpers.getFullMedicationInformation(drugId);
return dataResp;
} catch (err) {
console.log('GET FULL MEDICATION INFORMATION ERROR: ', err);
throw err;
}
}
export const medicationOperations = {
getMedications,
getBaseMedications
getBaseMedications,
getFullMedicationInformation
}

View file

@ -0,0 +1,5 @@
import * as Yup from 'yup';
export const fullMedicationInformationSchema = Yup.object().shape({
drugId: Yup.string().required("drugId is required"),
});