"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchPatient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const utils_1 = require("../../utils");
exports.searchPatient = {
    key: 'searchPatient',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Search patient',
    description: 'Search for patients in Medplum using parameters',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        var _a, _b;
        const { fields: input, medplumSdk } = await (0, utils_1.validateAndCreateSdkClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const searchParams = {};
        searchParams[input.parameter] = input.value;
        const bundle = await medplumSdk.search('Patient', searchParams);
        const patient = ((_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.resource) || null;
        await onComplete({
            data_points: {
                patientData: JSON.stringify(patient),
                searchResults: JSON.stringify(bundle),
            },
        });
    },
};
//# sourceMappingURL=searchPatient.js.map