@peopl-health/nexus 3.13.13 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ const { Monitoreo_ID } = require('../config/airtableConfig');
2
+
3
+ const { logger } = require('../utils/logger');
4
+
5
+ const { ensureWhatsAppFormat } = require('../helpers/twilioHelper');
6
+
7
+ const { addLinkedRecord } = require('../services/airtableService');
8
+
9
+ const createPrescriptionController = async (req, res) => {
10
+ const { code, prescription, triggeredBy, creationSource = 'other' } = req.body;
11
+
12
+ if (!code) return res.status(400).json({ success: false, error: 'Code is required' });
13
+ if (!prescription) return res.status(400).json({ success: false, error: 'Prescription is required' });
14
+ if (!triggeredBy) return res.status(400).json({ success: false, error: 'triggeredBy is required' });
15
+
16
+ try {
17
+ const whatsappId = ensureWhatsAppFormat(code);
18
+
19
+ const record = await addLinkedRecord(
20
+ Monitoreo_ID,
21
+ 'patient_prescriptions',
22
+ {
23
+ prescription,
24
+ author_email: triggeredBy,
25
+ creation_source: creationSource,
26
+ created: new Date().toISOString()
27
+ },
28
+ {
29
+ referenceTable: 'estado_general',
30
+ referenceFilter: `{whatsapp_id}='${whatsappId}'`,
31
+ linkFieldName: 'patient_id'
32
+ }
33
+ );
34
+
35
+ logger.info('[PrescriptionController] Prescription created', { code: whatsappId });
36
+ res.status(201).json({ success: true, message: 'Prescription created', recordId: record?.id || null });
37
+ } catch (error) {
38
+ logger.error('[PrescriptionController] Error creating prescription', { error: error.message, code });
39
+ res.status(500).json({ success: false, error: 'Failed to create prescription' });
40
+ }
41
+ };
42
+
43
+ module.exports = { createPrescriptionController };
@@ -82,6 +82,10 @@ const dashboardRouteDefinitions = {
82
82
  'POST /:id': 'updateDashboardControllerById'
83
83
  };
84
84
 
85
+ const prescriptionRouteDefinitions = {
86
+ 'POST /create': 'createPrescriptionController'
87
+ };
88
+
85
89
  const presetRouteDefinitions = {
86
90
  'POST /cache/clear': 'clearPresetCacheController'
87
91
  };
@@ -117,6 +121,7 @@ const templateFlowController = require('../controllers/templateFlowController');
117
121
  const flowDataExchangeController = require('../controllers/flowDataExchangeController');
118
122
  const uploadController = require('../controllers/uploadController');
119
123
  const dashboardController = require('../controllers/dashboardController');
124
+ const prescriptionController = require('../controllers/prescriptionController');
120
125
 
121
126
  const builtInControllers = {
122
127
  // Assistant controllers
@@ -195,6 +200,9 @@ const builtInControllers = {
195
200
  updateAllReviewStatusController: conversationController.updateAllReviewStatusController,
196
201
  getReviewStatusController: conversationController.getReviewStatusController,
197
202
 
203
+ // Prescription controllers
204
+ createPrescriptionController: prescriptionController.createPrescriptionController,
205
+
198
206
  // Dashboard controllers
199
207
  getDashboardController: dashboardController.getDashboardController,
200
208
  getDashboardStatsControllerById: dashboardController.getDashboardStatsControllerById,
@@ -210,6 +218,7 @@ const setupDefaultRoutes = (app) => {
210
218
  app.use('/api/patient', createRouter(patientRouteDefinitions, builtInControllers));
211
219
  app.use('/api/preset', createRouter(presetRouteDefinitions, builtInControllers));
212
220
  app.use('/api/template', createRouter(templateRouteDefinitions, builtInControllers));
221
+ app.use('/api/prescription', createRouter(prescriptionRouteDefinitions, builtInControllers));
213
222
  app.use('/api/dashboard', createRouter(dashboardRouteDefinitions, builtInControllers));
214
223
  };
215
224
 
@@ -221,6 +230,7 @@ module.exports = {
221
230
  patientRoutes: patientRouteDefinitions,
222
231
  presetRoutes: presetRouteDefinitions,
223
232
  templateRoutes: templateRouteDefinitions,
233
+ prescriptionRoutes: prescriptionRouteDefinitions,
224
234
  dashboardRoutes: dashboardRouteDefinitions,
225
235
 
226
236
  createRouter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.13.13",
3
+ "version": "3.14.0",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",