"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AthenaAPIClient = exports.AthenaDataWrapper = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const cacheService_1 = require("./cacheService");
class AthenaDataWrapper extends extensions_core_1.DataWrapper {
    async createPatient({ practiceId, data, }) {
        const result = await this.Request({
            method: 'POST',
            url: `/v1/${practiceId}/patients`,
            headers: { 'content-type': 'application/x-www-form-urlencoded' },
            data,
        });
        return result[0];
    }
    async getPatient({ practiceId, patientId, }) {
        const result = await this.Request({
            method: 'GET',
            url: `/v1/${practiceId}/patients/${patientId}`,
        });
        return result[0];
    }
    async getAppointment({ practiceId, appointmentId, }) {
        const result = await this.Request({
            method: 'GET',
            url: `/v1/${practiceId}/appointments/${appointmentId}`,
        });
        return result[0];
    }
    async createAppointmentNote({ practiceId, appointmentId, data, }) {
        const result = await this.Request({
            method: 'POST',
            url: `/v1/${practiceId}/appointments/${appointmentId}/notes`,
            headers: { 'content-type': 'application/x-www-form-urlencoded' },
            data,
        });
        return result;
    }
    async addClinicalDocumentToPatientChart({ practiceId, patientId, data, }) {
        const formData = new FormData();
        Object.entries(data).forEach((entry) => {
            const [key, value] = entry;
            formData.append(key, String(value));
        });
        const result = await this.Request({
            method: 'POST',
            url: `/v1/${practiceId}/patients/${patientId}/documents/clinicaldocument`,
            headers: {
                'Content-Type': 'multipart/form-data',
            },
            data: formData,
        });
        return result;
    }
}
exports.AthenaDataWrapper = AthenaDataWrapper;
class AthenaAPIClient extends extensions_core_1.APIClient {
    constructor({ authUrl, requestConfig, ...opts }) {
        super({
            ...opts,
            auth: new extensions_core_1.OAuthClientCredentials({
                auth_url: authUrl,
                request_config: requestConfig,
                cacheService: cacheService_1.cacheService,
            }),
        });
        this.ctor = (token, baseUrl) => new AthenaDataWrapper(token, baseUrl);
    }
    async createPatient({ practiceId, data, }) {
        return await this.FetchData(async (dw) => await dw.createPatient({ practiceId, data }));
    }
    async getPatient({ practiceId, patientId, }) {
        return await this.FetchData(async (dw) => await dw.getPatient({ patientId, practiceId }));
    }
    async getAppointment({ practiceId, appointmentId, }) {
        return await this.FetchData(async (dw) => await dw.getAppointment({ appointmentId, practiceId }));
    }
    async createAppointmentNote({ practiceId, appointmentId, data, }) {
        return await this.FetchData(async (dw) => await dw.createAppointmentNote({ appointmentId, practiceId, data }));
    }
    async addClinicalDocumentToPatientChart({ practiceId, patientId, data, }) {
        return await this.FetchData(async (dw) => await dw.addClinicalDocumentToPatientChart({
            patientId,
            practiceId,
            data,
        }));
    }
}
exports.AthenaAPIClient = AthenaAPIClient;
//# sourceMappingURL=client.js.map