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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-04 05:17:38 +00:00
|
|
|
medicationRouter.post('/base/', async (req, res) => {
|
2026-01-18 03:39:32 +00:00
|
|
|
let data;
|
2026-03-04 05:17:38 +00:00
|
|
|
const body = req?.body;
|
|
|
|
|
|
2026-01-18 03:39:32 +00:00
|
|
|
try {
|
2026-03-04 05:17:38 +00:00
|
|
|
await fullMedicationInformationSchema.validate(body);
|
|
|
|
|
data = await databaseServices.getBaseMedications(body);
|
2026-01-18 03:39:32 +00:00
|
|
|
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;
|
2026-01-23 06:21:47 +00:00
|
|
|
|
2026-01-23 05:33:18 +00:00
|
|
|
try {
|
|
|
|
|
await fullMedicationInformationSchema.validate(body);
|
2026-01-23 06:21:47 +00:00
|
|
|
data = await databaseServices.getFullMedicationInformation(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
|
|
|
});
|