@peopl-health/nexus 5.58.4 → 5.58.5
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.
|
@@ -6,13 +6,19 @@ const { ensureWhatsAppFormat } = require('../helpers/twilioHelper');
|
|
|
6
6
|
|
|
7
7
|
const { addLinkedRecord } = require('../services/airtableService');
|
|
8
8
|
|
|
9
|
+
const RECORD_ID_RX = /^rec[A-Za-z0-9]{14}$/;
|
|
10
|
+
|
|
11
|
+
// physicianId links the receta to a physicians row; the Airtable automation picks the PDF template from that physician's specialty.
|
|
9
12
|
const createPrescriptionController = async (req, res) => {
|
|
10
|
-
const { prescription, triggeredBy, creationSource = 'other' } = req.body;
|
|
13
|
+
const { prescription, triggeredBy, creationSource = 'other', physicianId } = req.body;
|
|
11
14
|
let code = req.body.code;
|
|
12
15
|
|
|
13
16
|
if (!code) return res.status(400).json({ success: false, error: 'Code is required' });
|
|
14
17
|
if (!prescription) return res.status(400).json({ success: false, error: 'Prescription is required' });
|
|
15
18
|
if (!triggeredBy) return res.status(400).json({ success: false, error: 'triggeredBy is required' });
|
|
19
|
+
if (physicianId !== undefined && (typeof physicianId !== 'string' || !RECORD_ID_RX.test(physicianId))) {
|
|
20
|
+
return res.status(400).json({ success: false, error: 'physicianId must be an Airtable record id' });
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
try {
|
|
18
24
|
code = ensureWhatsAppFormat(code);
|
|
@@ -24,7 +30,8 @@ const createPrescriptionController = async (req, res) => {
|
|
|
24
30
|
prescription,
|
|
25
31
|
author_email: triggeredBy,
|
|
26
32
|
creation_source: creationSource,
|
|
27
|
-
created: new Date().toISOString()
|
|
33
|
+
created: new Date().toISOString(),
|
|
34
|
+
...(physicianId && { physician: [physicianId] })
|
|
28
35
|
},
|
|
29
36
|
{
|
|
30
37
|
referenceTable: 'estado_general',
|
|
@@ -34,7 +41,7 @@ const createPrescriptionController = async (req, res) => {
|
|
|
34
41
|
code
|
|
35
42
|
);
|
|
36
43
|
|
|
37
|
-
logger.info('[PrescriptionController] Prescription created', { code });
|
|
44
|
+
logger.info('[PrescriptionController] Prescription created', { code, physicianId });
|
|
38
45
|
res.status(201).json({ success: true, message: 'Prescription created', recordId: record?.id || null });
|
|
39
46
|
} catch (error) {
|
|
40
47
|
logger.error('[PrescriptionController] Error creating prescription', { error: error.message, code });
|