"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServiceRequest = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const utils_1 = require("../../utils");
exports.createServiceRequest = {
    key: 'createServiceRequest',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create service request',
    description: 'Create a service request in Medplum',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields: input, medplumSdk, activity, } = await (0, utils_1.validateAndCreateSdkClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const res = await medplumSdk.createResource({
            resourceType: 'ServiceRequest',
            status: input.status,
            intent: input.intent,
            priority: input.priority,
            subject: {
                reference: `Patient/${input.patientId}`,
            },
            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?
                serviceRequestId: res.id,
            },
        });
    },
};
//# sourceMappingURL=createServiceRequest.js.map