Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Nutrihelp-api
Submodule Nutrihelp-api deleted from 1313c9
78 changes: 74 additions & 4 deletions controller/appointmentController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {addAppointment, addAppointmentV2} = require('../model/addAppointment.js');
const {getAllAppointments, getAllAppointmentsV2} = require('../model/getAppointments.js');
const {addAppointment, addAppointmentModelV2, updateAppointmentModel, deleteAppointmentById} = require('../model/appointmentModel.js');
const {getAllAppointments, getAllAppointmentsV2 } = require('../model/getAppointments.js');
const { validationResult } = require('express-validator');
const { appointmentValidation } = require('../validators/appointmentValidator.js');


// Function to handle saving appointment data
const saveAppointment = async (req, res) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ const saveAppointmentV2 = async (req, res) => {
} = req.body;

try {
const appointment = await addAppointmentV2({
const appointment = await addAppointmentModelV2({
userId,
title,
doctor,
Expand All @@ -70,6 +70,74 @@ const saveAppointmentV2 = async (req, res) => {
}
};

const updateAppointment = async (req,res)=>{
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}

const { id } = req.params;

const {
title,
doctor,
type,
date,
time,
location,
address,
phone,
notes,
reminder,
} = req.body;

try {
const updatedAppointment = await updateAppointmentModel(id, {
title,
doctor,
type,
date,
time,
location,
address,
phone,
notes,
reminder,
});

if (!updatedAppointment) {
return res.status(404).json({ message: 'Appointment not found' });
}

res.status(200).json({
message: 'Appointment updated successfully',
appointment: updatedAppointment,
});
} catch (error) {
console.error('Error updating appointment:', error);
res.status(500).json({ error: 'Internal server error' });
}
}

const delAppointment = async (req,res)=>{
const { id } = req.params;

try {
const deleted = await deleteAppointmentById(id);

if (!deleted) {
return res.status(404).json({ message: 'Appointment not found' });
}

res.status(200).json({
message: 'Appointment deleted successfully',
});
} catch (error) {
console.error('Error deleting appointment:', error);
res.status(500).json({ error: 'Internal server error' });
}
}

// Function to handle retrieving all appointment data
const getAppointments = async (req, res) => {
try {
Expand Down Expand Up @@ -114,6 +182,8 @@ const getAppointmentsV2 = async (req, res) => {
module.exports = {
saveAppointment,
saveAppointmentV2,
updateAppointment,
delAppointment,
getAppointments,
getAppointmentsV2,
};
32 changes: 32 additions & 0 deletions controller/healthToolsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const getBmi = async (req, res) => {
try {
const height = Number(req.query.height);
const weight = Number(req.query.weight);

// Validate parameters
if (!height || !weight || height <= 0 || weight <= 0) {
return res.status(400).json({
error: "Invalid parameters. Height and weight must be positive numbers."
});
}

// Calculate BMI
const bmi = weight / (height * height);

// simple daily water intake estimation (ml)
const waterIntake = weight * 35; // 35 ml per kg

return res.status(200).json({
bmi: Number(bmi.toFixed(2)),
recommendedWaterIntakeMl: waterIntake
});

} catch (error) {
console.error(error);
return res.status(500).json({ error: "Internal server error" });
}
};

module.exports = {
getBmi
};
6 changes: 3 additions & 3 deletions controller/imageClassificationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ const predictImage = (req, res) => {
pythonProcess.stdout.on('data', (data) => {
prediction += data.toString();
});
console.log(prediction)

let stderrOutput = '';
// Handle errors
pythonProcess.stderr.on('data', (data) => {
console.error('Error executing Python script:', data.toString());
deleteFile(imagePath);
res.status(500).json({ error: 'Internal server error' });
stderrOutput += data.toString();
});

// When Python script finishes execution
Expand Down
202 changes: 199 additions & 3 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,101 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/appointments/v2/{id}:
put:
tags:
- Appointments
summary: Update an appointment (version 2)
parameters:
- in: path
name: id
required: true
schema:
type: integer
description: Appointment ID
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AppointmentUpdate'
responses:
'200':
description: Appointment updated successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Appointment updated successfully
appointment:
$ref: '#/components/schemas/AppointmentUpdate'
'400':
description: Bad request - invalid input
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Appointment not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
tags:
- Appointments
summary: Delete an appointment (version 2)
parameters:
- in: path
name: id
required: true
schema:
type: integer
description: Appointment ID
responses:
'200':
description: Appointment deleted successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Appointment deleted successfully
'404':
description: Appointment not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

# Shopping List API Endpoints
/shopping-list/ingredient-options:
Expand Down Expand Up @@ -2053,8 +2148,6 @@ paths:
get:
summary: Calculate estimated cost for a recipe
description: Returns JSON array containing total cost and corresponding ingredients price
summary: Unified Health News API
description: Comprehensive API for health news management with multiple actions and flexible filtering
parameters:
- in: path
name: recipe_id
Expand Down Expand Up @@ -2189,7 +2282,6 @@ paths:
responses:
'200':
description: Calculate cost successfully
description: Successfully retrieved requested data
content:
application/json:
schema:
Expand Down Expand Up @@ -2420,6 +2512,67 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'

/health-tools/bmi:
get:
summary: Calculate BMI and recommended daily water intake
description: >
Calculates Body Mass Index (BMI) based on height and weight,
and returns a recommended daily water intake value.
tags:
- Health Tools
parameters:
- name: height
in: query
required: true
description: Height in meters (e.g. 1.75)
schema:
type: number
format: float
example: 1.75
- name: weight
in: query
required: true
description: Weight in kilograms (e.g. 70)
schema:
type: number
format: float
example: 70
responses:
"200":
description: BMI and water intake calculated successfully
content:
application/json:
schema:
type: object
properties:
bmi:
type: number
format: float
example: 22.86
recommendedWaterIntakeMl:
type: number
example: 2450
"400":
description: Invalid query parameters
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: Invalid parameters. Height and weight must be positive numbers.
"500":
description: Internal server error
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: Internal server error

/recipe/nutritionlog:
get:
summary: Get full nutrition info for a recipe by name
Expand Down Expand Up @@ -3260,6 +3413,49 @@ components:
reminder:
type: string
example: 1-day
AppointmentUpdate:
type: object
required:
- userId
- title
- doctor
- type
- date
properties:
userId:
type: integer
example: 1
title:
type: string
example: Dr. Smith - Annual Checkup
doctor:
type: string
example: Dr. Robert Smith
type:
type: string
example: General Checkup
date:
type: string
format: date
example: "2024-12-05"
time:
type: string
example: "10:00"
location:
type: string
example: Main Street Medical Center
address:
type: string
example: 123 Main St, Suite 200
phone:
type: string
example: "(555) 123-4567"
notes:
type: string
example: Bring insurance card and list of current medications
reminder:
type: string
example: 1-day
SuccessResponse:
type: object
properties:
Expand Down
Loading
Loading