From 1c6341e0fba65c17d0f513c251ec1e46076b7f0f Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:33:13 +0300 Subject: [PATCH] Pulling blood pressure values for trends --- routes/processes/nishauri_new.js | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/routes/processes/nishauri_new.js b/routes/processes/nishauri_new.js index 7ad80c0..e0873a1 100644 --- a/routes/processes/nishauri_new.js +++ b/routes/processes/nishauri_new.js @@ -4677,5 +4677,53 @@ router.post( } } ); + +router.get( + "/get_blood_pressure", + passport.authenticate("jwt", { session: false }), + async (req, res) => { + try { + let user_id = req.query.user_id; + + let blood_pressure = await NBloodPressure.findAll({ + attributes: ["systolic", "diastolic", "pulse_rate", "notes", "created_at"], + where: { + user_id: base64.decode(user_id) + } + }); + + if (blood_pressure && blood_pressure.length > 0) { + let transformedData = blood_pressure.map(bp => { + return { + systolic: bp.systolic, + diastolic: bp.diastolic, + pulse_rate: bp.pulse_rate, + notes: bp.notes, + date_time: moment(bp.created_at).format('YYYY-MM-DD HH:mm:ss') + }; + }); + + return res.status(200).json({ + success: true, + message: "User blood pressure logs retrieved successfully", + data: { + blood_pressure: transformedData, + user_id: user_id + } + }); + } else { + return res.status(404).json({ + success: false, + message: "No blood pressure data found for this User" + }); + } + } catch (error) { + return res.status(500).json({ + success: false, + message: "Internal Server Error" + }); + } + } +); module.exports = router; //module.exports = { router, users };