"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listDocuments = 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 validation_1 = require("./validation");
const dataPoints_1 = require("./dataPoints");
exports.listDocuments = {
    key: 'listDocs',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'List Documents',
    description: 'Queries for all available document metadata for the specified patient across HIEs.',
    fields: fields_1.listFields,
    previewable: true,
    dataPoints: dataPoints_1.documentsDataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const { patientId } = validation_1.startQuerySchema.parse(payload.fields);
            const api = (0, client_1.createMetriportApi)(payload.settings);
            const resp = await api.listDocuments(patientId);
            await onComplete({
                data_points: {
                    documents: JSON.stringify(resp.documents),
                },
            });
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=list.js.map