"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTask = 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.createTask = {
    key: 'createTask',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create task',
    description: 'Create a Task in Medplum',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        var _a;
        const { fields: input, medplumSdk, activity, } = await (0, utils_1.validateAndCreateSdkClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const res = await medplumSdk.createResource({
            resourceType: 'Task',
            code: {
                text: input.taskTitle,
            },
            description: input.description,
            status: input.status,
            intent: input.intent,
            priority: input.priority,
            for: {
                reference: `Patient/${(_a = (0, extractResourceId_1.extractResourceId)(input.patientId, 'Patient')) !== null && _a !== void 0 ? _a : 'undefined'}`,
            },
            executionPeriod: {
                end: input.dueDate,
            },
            performerType: [
                {
                    text: input.performerType,
                },
            ],
            requester: {
                identifier: {
                    system: 'https://awellhealth.com/activities/',
                    value: activity.id,
                },
                display: 'Awell',
            },
        });
        await onComplete({
            data_points: {
                // @ts-expect-error id is not included in the response type?
                taskId: res.id,
            },
        });
    },
};
//# sourceMappingURL=createTask.js.map