"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPatient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const utils_1 = require("../../utils");
const extractResourceId_1 = require("../../utils/extractResourceId/extractResourceId");
exports.getPatient = {
    key: 'getPatient',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get patient',
    description: 'Retrieve patient details from Medplum',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        var _a, _b, _c, _d, _e, _f;
        const { fields: input, medplumSdk } = await (0, utils_1.validateAndCreateSdkClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const resourceId = (_a = (0, extractResourceId_1.extractResourceId)(input.patientId, 'Patient')) !== null && _a !== void 0 ? _a : '';
        const res = await medplumSdk.readResource('Patient', resourceId);
        const patientFirstName = (_d = (_c = (_b = res === null || res === void 0 ? void 0 : res.name) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.given) === null || _d === void 0 ? void 0 : _d[0];
        const patientLastName = (_f = (_e = res === null || res === void 0 ? void 0 : res.name) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.family;
        const patientDob = res === null || res === void 0 ? void 0 : res.birthDate;
        const patientGender = res === null || res === void 0 ? void 0 : res.gender;
        await onComplete({
            data_points: {
                patientData: JSON.stringify(res),
                patientFirstName,
                patientLastName,
                patientDob,
                patientGender,
            },
        });
    },
};
//# sourceMappingURL=getPatient.js.map