-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpregnancy-api-server.js
More file actions
104 lines (90 loc) · 3.2 KB
/
Copy pathpregnancy-api-server.js
File metadata and controls
104 lines (90 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Pregnancy Safety API Server
* Simple Express server to handle pregnancy medication safety checks
*/
const express = require('express');
const path = require('path');
const MedicationTracker = require('./medication-tracker');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json());
app.use(express.static('docs')); // Serve the HTML UI
// Initialize medication tracker
const tracker = new MedicationTracker();
/**
* Pregnancy safety check endpoint
* POST /api/check-pregnancy-safety
*/
app.post('/api/check-pregnancy-safety', async (req, res) => {
try {
const { medicationName, weekOfPregnancy, patientId } = req.body;
// Validate input
if (!medicationName || !weekOfPregnancy) {
return res.status(400).json({
error: 'Missing required fields: medicationName and weekOfPregnancy'
});
}
if (weekOfPregnancy < 1 || weekOfPregnancy > 42) {
return res.status(400).json({
error: 'Invalid pregnancy week. Must be between 1 and 42.'
});
}
// Check pregnancy safety using Bumpie_Meds
const safetyResult = await tracker.checkPregnancySafety(
medicationName,
weekOfPregnancy,
{
patientId,
sessionId: req.headers['x-session-id'] || null
}
);
res.json(safetyResult);
} catch (error) {
console.error('Pregnancy safety check error:', error);
res.status(500).json({
error: 'Internal server error',
message: error.message,
safe: false,
recommendation: 'Unable to assess safety. Please consult your healthcare provider.'
});
}
});
/**
* Health check endpoint
*/
app.get('/api/health', (req, res) => {
res.json({
status: 'ok',
service: 'MindTrackAI Pregnancy Safety API',
timestamp: new Date().toISOString()
});
});
/**
* Serve main UI
*/
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'docs', 'index.html'));
});
// Start server
if (require.main === module) {
app.listen(PORT, () => {
console.log(`
╔═══════════════════════════════════════════════════════════╗
║ 🤰 MindTrackAI Pregnancy Safety API Server ║
║ ║
║ Status: ✅ Running ║
║ Port: ${PORT} ║
║ URL: http://localhost:${PORT} ║
║ ║
║ Endpoints: ║
║ • GET / ║
║ • GET /api/health ║
║ • POST /api/check-pregnancy-safety ║
║ ║
║ 🔒 Powered by Bumpie_Meds - FDA Compliant ║
╚═══════════════════════════════════════════════════════════╝
`);
});
}
module.exports = app;