2026-04-27 04:25:52 +00:00

47 lines
1.4 KiB
JavaScript

'use strict';
const createError = require('http-errors');
const { issueVHL } = require('../services/vhlIssue');
/**
* POST /vhl/:patientId
*
* Issues a Verifiable Health Link (VHL) for a patient.
* Corresponds to Fase 1 (Emisión) in obtener_qr_vhl.mmd:
* MiArgentina → BusNación: solicita generación de VHL para [PacienteID]
* BusNación → MiArgentina: retorna VHL firmado (CWT)
*
* Path parameter:
* :patientId — FHIR Patient logical ID in the local HAPI FHIR server.
*
* Body (optional, application/json):
* { "pin": "1234" } ← citizen-configured PIN; protects the manifest.
*
* Response 201:
* { "cwt": "<base64url COSE_Sign1>" }
*
* MiArgentina then:
* - Decodes the base64url to get the CWT bytes.
* - Compresses with ZLIB and encodes as Base45 to produce the QR payload.
* - Displays the QR code to the citizen.
*/
async function issueVHLController(req, res, next) {
try {
const { patientId } = req.params;
if (!patientId) {
throw createError(400, 'Missing path parameter: patientId');
}
const pin = req.body && typeof req.body.pin === 'string'
? req.body.pin.trim() || undefined
: undefined;
const result = await issueVHL({ patientId, pin });
res.status(201).json(result);
} catch (err) {
next(err);
}
}
module.exports = { issueVHLController };