Add region #32
4 changed files with 18 additions and 10 deletions
|
|
@ -17,10 +17,13 @@ medicationRouter.get('/', async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
medicationRouter.get('/base/', async (req, res) => {
|
medicationRouter.post('/base/', async (req, res) => {
|
||||||
let data;
|
let data;
|
||||||
|
const body = req?.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = await databaseServices.getBaseMedications();
|
await fullMedicationInformationSchema.validate(body);
|
||||||
|
data = await databaseServices.getBaseMedications(body);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
data = { Error: err?.message };
|
data = { Error: err?.message };
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { paramyxRunQuery } from '../../paramyxConnection.js';
|
import { paramyxRunQuery } from '../../paramyxConnection.js';
|
||||||
|
|
||||||
export const medicationHelpers = {
|
export const medicationHelpers = {
|
||||||
getBaseMedications: async () => {
|
getBaseMedications: async (region) => {
|
||||||
const [medList, medRoutes] = await Promise.all([
|
const [medList, medRoutes] = await Promise.all([
|
||||||
paramyxRunQuery('SELECT * FROM medications'),
|
paramyxRunQuery('SELECT * FROM medications WHERE $1 = ANY(region)', [region]),
|
||||||
paramyxRunQuery('SELECT * FROM medication_routes')
|
paramyxRunQuery('SELECT * FROM medication_routes WHERE region = $1', [region])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const medMap = {};
|
const medMap = {};
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@ const getMedications = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getBaseMedications = async () => {
|
const getBaseMedications = async (body) => {
|
||||||
|
const { region } = body;
|
||||||
try {
|
try {
|
||||||
const dataResp = medicationHelpers.getBaseMedications();
|
const dataResp = medicationHelpers.getBaseMedications(region);
|
||||||
return dataResp;
|
return dataResp;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('GET BASE MEDICATIONS ERROR: ', err);
|
console.log('GET BASE MEDICATIONS ERROR: ', err);
|
||||||
|
|
@ -21,8 +22,8 @@ const getBaseMedications = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFullMedicationInformation = async (drug) => {
|
const getFullMedicationInformation = async (body) => {
|
||||||
const { drugId } = drug;
|
const { drugId } = body;
|
||||||
try {
|
try {
|
||||||
const dataResp = medicationHelpers.getFullMedicationInformation(drugId);
|
const dataResp = medicationHelpers.getFullMedicationInformation(drugId);
|
||||||
return dataResp;
|
return dataResp;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
|
export const baseMedicationInformationScema = Yup.object().shape({
|
||||||
|
region: Yup.string().required("region is required")
|
||||||
|
});
|
||||||
|
|
||||||
export const fullMedicationInformationSchema = Yup.object().shape({
|
export const fullMedicationInformationSchema = Yup.object().shape({
|
||||||
drugId: Yup.string().required("drugId is required"),
|
drugId: Yup.string().required("drugId is required")
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue