"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPatient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const helpers_1 = require("../../helpers");
exports.createPatient = {
    key: 'createPatient',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create patient',
    description: 'Create a patient in athena',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete, onError, helpers }) => {
        helpers.log({ fields: payload.fields }, 'Processing createPatient');
        try {
            const { fields: input, client, settings: { practiceId }, } = await (0, helpers_1.validatePayloadAndCreateClient)({
                fieldsSchema: config_1.FieldsValidationSchema,
                payload,
            });
            const res = await client.createPatient({
                practiceId,
                data: input,
            });
            await onComplete({
                data_points: {
                    createdPatientId: res.patientid,
                },
            });
        }
        catch (err) {
            helpers.log({ err }, 'error', err);
            const error = err;
            await onError({
                events: [
                    {
                        date: new Date().toISOString(),
                        text: { en: error.message },
                        error: {
                            category: 'SERVER_ERROR',
                            message: error.message,
                        },
                    },
                ],
            });
        }
    },
};
//# sourceMappingURL=createPatient.js.map