"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.patientCreated = void 0;
const lodash_1 = require("lodash");
const types_1 = require("../lib/types");
const helpers_1 = require("../lib/helpers");
const dataPoints = {
    patientId: {
        key: 'patientId',
        valueType: 'string',
    },
};
exports.patientCreated = {
    key: 'patientCreated',
    dataPoints,
    onWebhookReceived: async ({ payload, settings }, onSuccess, onError) => {
        const validatedPayload = helpers_1.webhookPayloadSchema.parse(payload);
        const patientId = validatedPayload.resource_id.toString();
        if ((0, lodash_1.isNil)(patientId)) {
            await onError({
            // We should automatically send a 400 here, so no need to provide info
            });
        }
        else {
            await onSuccess({
                data_points: {
                    patientId,
                },
                patient_identifier: {
                    system: types_1.HEALTHIE_IDENTIFIER,
                    value: patientId,
                },
            });
        }
    },
};
//# sourceMappingURL=patientCreated.js.map