"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePatient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const client_1 = require("../../client");
const errorHandler_1 = require("../../shared/errorHandler");
const fields_1 = require("./fields");
const generic_zod_1 = require("../../validation/generic.zod");
const validation_1 = require("./validation");
const create_1 = require("./create");
exports.updatePatient = {
    key: 'updatePatient',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Update Patient',
    description: 'Updates the specified Patient.',
    fields: fields_1.updateFields,
    previewable: true,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const patient = validation_1.patientUpdateSchema.parse(payload.fields);
            const facilityId = generic_zod_1.stringId.parse(payload.fields.facilityId);
            const metriportPatient = (0, create_1.convertToMetriportPatient)(patient);
            const api = (0, client_1.createMetriportApi)(payload.settings);
            await api.updatePatient({ id: patient.id, ...metriportPatient }, facilityId);
            await onComplete();
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=update.js.map