diff --git a/.gitignore b/.gitignore index 366dd8c..721604b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ dist-ssr *.ntvs* *.njsproj *.sln -*.sw? \ No newline at end of file +*.sw? + +api/package-lock.json +web/package-lock.json \ No newline at end of file diff --git a/api/services/medications/index.js b/api/services/medications/index.js index a69a4b0..80f526f 100644 --- a/api/services/medications/index.js +++ b/api/services/medications/index.js @@ -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); + } }); \ No newline at end of file diff --git a/api/services/operations/helpers/medications.js b/api/services/operations/helpers/medications.js index 14624c1..3edf033 100644 --- a/api/services/operations/helpers/medications.js +++ b/api/services/operations/helpers/medications.js @@ -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; } }; \ No newline at end of file diff --git a/api/services/operations/medications.js b/api/services/operations/medications.js index a225df5..b55455a 100644 --- a/api/services/operations/medications.js +++ b/api/services/operations/medications.js @@ -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 } \ No newline at end of file diff --git a/api/services/validations/medications.js b/api/services/validations/medications.js new file mode 100644 index 0000000..844cc15 --- /dev/null +++ b/api/services/validations/medications.js @@ -0,0 +1,5 @@ +import * as Yup from 'yup'; + +export const fullMedicationInformationSchema = Yup.object().shape({ + drugId: Yup.string().required("drugId is required"), +}); \ No newline at end of file