"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getReferralOrder = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const client_1 = require("../../client");
const config_1 = require("./config");
exports.getReferralOrder = {
    key: 'getReferralOrder',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get referral order',
    description: 'Retrieve a referral order from Elation.',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete, onError }) => {
        var _a, _b;
        const { referralOrderId } = config_1.FieldsValidationSchema.parse(payload.fields);
        const api = (0, client_1.makeAPIClient)(payload.settings);
        const res = await api.getReferralOrder(referralOrderId);
        await onComplete({
            data_points: {
                letterId: String(res.letter),
                patientId: String(res.patient),
                consultantName: res.consultant_name,
                practice: String(res.practice),
                diagnosisCodes: JSON.stringify((_a = res.icd10_codes) === null || _a === void 0 ? void 0 : _a.map((code) => code.code)),
                diagnosisLabels: JSON.stringify((_b = res.icd10_codes) === null || _b === void 0 ? void 0 : _b.map((code) => code.description)),
            },
        });
    },
};
//# sourceMappingURL=getReferralOrder.js.map