2026-01-18 03:39:32 +00:00
|
|
|
import express from 'express';
|
|
|
|
|
import { databaseServices } from '../index.js';
|
2026-01-23 05:33:18 +00:00
|
|
|
import { fullMedicationInformationSchema } from '../validations/medications.js';
|
2026-01-18 03:39:32 +00:00
|
|
|
|
|
|
|
|
export const medicationRouter = express.Router();
|
|
|
|
|
|
|
|
|
|
medicationRouter.get('/', async (req, res) => {
|
|
|
|
|
let data;
|
|
|
|
|
try {
|
|
|
|
|
data = await databaseServices.getMedications();
|
|
|
|
|
res.status(200);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
data = { Error: err?.message };
|
|
|
|
|
res.status(500);
|
|
|
|
|
} finally {
|
|
|
|
|
res.send(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
medicationRouter.get('/base/', async (req, res) => {
|
|
|
|
|
let data;
|
|
|
|
|
try {
|
|
|
|
|
data = await databaseServices.getBaseMedications();
|
|
|
|
|
res.status(200);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
data = { Error: err?.message };
|
|
|
|
|
res.status(500);
|
|
|
|
|
} finally {
|
|
|
|
|
res.send(data);
|
|
|
|
|
}
|
2026-01-23 05:33:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
medicationRouter.post('/full/', async (req, res) => {
|
|
|
|
|
let data;
|
|
|
|
|
const body = req?.body;
|
|
|
|
|
try {
|
|
|
|
|
await fullMedicationInformationSchema.validate(body);
|
2026-01-23 05:58:06 +00:00
|
|
|
data = await databaseServices.getFullMedicationInformation(JSON.parse(body));
|
2026-01-23 05:33:18 +00:00
|
|
|
res.status(200);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
data = { Error: err?.message };
|
|
|
|
|
res.status(500);
|
|
|
|
|
} finally {
|
|
|
|
|
res.send(data);
|
|
|
|
|
}
|
2026-01-18 03:39:32 +00:00
|
|
|
});
|