"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConsolidatedQueryStatus = 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 dataPoints_1 = require("./dataPoints");
const zod_1 = require("zod");
const getConsolidatedQueryStatusSchema = zod_1.z.object({
    patientId: zod_1.z
        .string({ errorMap: () => ({ message: 'Missing patientId' }) })
        .min(1),
});
exports.getConsolidatedQueryStatus = {
    key: 'getConsolidatedQueryStatus',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get Consolidated Data Query Status',
    description: "Gets the status of a consolidated data query for a Patient. Use after starting a consolidated query to check if results are ready.",
    fields: fields_1.getConsolidatedQueryStatusFields,
    previewable: true,
    dataPoints: dataPoints_1.consolidatedQueryStatusDataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const { patientId } = getConsolidatedQueryStatusSchema.parse(payload.fields);
            const api = (0, client_1.createMetriportApi)(payload.settings);
            const resp = await api.getConsolidatedQueryStatus(patientId);
            await onComplete({
                data_points: {
                    status: resp.status,
                    queries: JSON.stringify(resp.queries),
                },
            });
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=getConsolidatedQueryStatus.js.map