"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSideEffect = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const utils_1 = require("../../utils");
exports.addSideEffect = {
    key: 'addSideEffect',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Add side effect',
    description: 'Add side effect to Medication Request',
    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 annotation = {
            text: input.sideEffect,
            authorReference: {
                identifier: {
                    system: 'https://awellhealth.com/activities/',
                    value: activity.id,
                },
                display: 'Awell',
            },
        };
        const currentMedicationRequest = await medplumSdk.readResource('MedicationRequest', input.medicationRequestId);
        const currentAnnotations = currentMedicationRequest.note;
        await medplumSdk.patchResource('MedicationRequest', input.medicationRequestId, [
            {
                op: 'add',
                path: '/note',
                value: [...(currentAnnotations !== null && currentAnnotations !== void 0 ? currentAnnotations : []), annotation],
            },
        ]);
        await onComplete();
    },
};
//# sourceMappingURL=addSideEffect.js.map