From 2249234aa4ab1347ce48c40e662b72bd89286d7e Mon Sep 17 00:00:00 2001 From: Matt DiMeglio Date: Wed, 4 Mar 2026 00:17:38 -0500 Subject: [PATCH 1/3] Add region --- api/services/medications/index.js | 7 +++++-- api/services/operations/helpers/medications.js | 6 +++--- api/services/operations/medications.js | 9 +++++---- api/services/validations/medications.js | 6 +++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/api/services/medications/index.js b/api/services/medications/index.js index 80f526f..bc35ee0 100644 --- a/api/services/medications/index.js +++ b/api/services/medications/index.js @@ -17,10 +17,13 @@ medicationRouter.get('/', async (req, res) => { } }); -medicationRouter.get('/base/', async (req, res) => { +medicationRouter.post('/base/', async (req, res) => { let data; + const body = req?.body; + try { - data = await databaseServices.getBaseMedications(); + await fullMedicationInformationSchema.validate(body); + data = await databaseServices.getBaseMedications(body); res.status(200); } catch (err) { data = { Error: err?.message }; diff --git a/api/services/operations/helpers/medications.js b/api/services/operations/helpers/medications.js index 3edf033..13062ea 100644 --- a/api/services/operations/helpers/medications.js +++ b/api/services/operations/helpers/medications.js @@ -1,10 +1,10 @@ import { paramyxRunQuery } from '../../paramyxConnection.js'; export const medicationHelpers = { - getBaseMedications: async () => { + getBaseMedications: async (region) => { const [medList, medRoutes] = await Promise.all([ - paramyxRunQuery('SELECT * FROM medications'), - paramyxRunQuery('SELECT * FROM medication_routes') + paramyxRunQuery('SELECT * FROM medications WHERE $1 = ANY(region)', [region]), + paramyxRunQuery('SELECT * FROM medication_routes WHERE region = $1', [region]) ]); const medMap = {}; diff --git a/api/services/operations/medications.js b/api/services/operations/medications.js index b55455a..2a6f84a 100644 --- a/api/services/operations/medications.js +++ b/api/services/operations/medications.js @@ -11,9 +11,10 @@ const getMedications = async () => { } }; -const getBaseMedications = async () => { +const getBaseMedications = async (body) => { + const { region } = body; try { - const dataResp = medicationHelpers.getBaseMedications(); + const dataResp = medicationHelpers.getBaseMedications(region); return dataResp; } catch (err) { console.log('GET BASE MEDICATIONS ERROR: ', err); @@ -21,8 +22,8 @@ const getBaseMedications = async () => { } } -const getFullMedicationInformation = async (drug) => { - const { drugId } = drug; +const getFullMedicationInformation = async (body) => { + const { drugId } = body; try { const dataResp = medicationHelpers.getFullMedicationInformation(drugId); return dataResp; diff --git a/api/services/validations/medications.js b/api/services/validations/medications.js index 844cc15..28e75a8 100644 --- a/api/services/validations/medications.js +++ b/api/services/validations/medications.js @@ -1,5 +1,9 @@ import * as Yup from 'yup'; +export const baseMedicationInformationScema = Yup.object().shape({ + region: Yup.string().required("region is required") +}); + export const fullMedicationInformationSchema = Yup.object().shape({ - drugId: Yup.string().required("drugId is required"), + drugId: Yup.string().required("drugId is required") }); \ No newline at end of file -- 2.45.2 From 658bd83275b455d0b2dbe8b4c576180344eed96f Mon Sep 17 00:00:00 2001 From: Matt DiMeglio Date: Wed, 4 Mar 2026 00:26:37 -0500 Subject: [PATCH 2/3] edit full to base --- api/services/medications/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/services/medications/index.js b/api/services/medications/index.js index bc35ee0..0a25731 100644 --- a/api/services/medications/index.js +++ b/api/services/medications/index.js @@ -1,6 +1,6 @@ import express from 'express'; import { databaseServices } from '../index.js'; -import { fullMedicationInformationSchema } from '../validations/medications.js'; +import { baseMedicationInformationSchema, fullMedicationInformationSchema } from '../validations/medications.js'; export const medicationRouter = express.Router(); @@ -22,7 +22,7 @@ medicationRouter.post('/base/', async (req, res) => { const body = req?.body; try { - await fullMedicationInformationSchema.validate(body); + await baseMedicationInformationSchema.validate(body); data = await databaseServices.getBaseMedications(body); res.status(200); } catch (err) { -- 2.45.2 From b3bced8c62813fd3c5970be1db96e5fd05e28256 Mon Sep 17 00:00:00 2001 From: Matt DiMeglio Date: Wed, 4 Mar 2026 00:33:45 -0500 Subject: [PATCH 3/3] Fix spelling --- api/services/validations/medications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/services/validations/medications.js b/api/services/validations/medications.js index 28e75a8..4c041a6 100644 --- a/api/services/validations/medications.js +++ b/api/services/validations/medications.js @@ -1,6 +1,6 @@ import * as Yup from 'yup'; -export const baseMedicationInformationScema = Yup.object().shape({ +export const baseMedicationInformationSchema = Yup.object().shape({ region: Yup.string().required("region is required") }); -- 2.45.2