"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CernerR4APIClient = exports.CernerR4DataWrapper = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const cacheService_1 = require("./cacheService");
class CernerR4DataWrapper extends extensions_core_1.DataWrapper {
    async getPatient(id) {
        const result = await this.RequestRaw({
            method: 'GET',
            url: `/Patient/${id}`,
        });
        return result;
    }
    async createPatient(patient) {
        const result = await this.RequestRaw({
            method: 'POST',
            url: `/Patient`,
            data: patient,
        });
        return result;
    }
    async searchPatient(data) {
        const MRN_SYSTEM_IDENTIFIER = 'urn:oid:2.16.840.1.113883.6.1000';
        const queryParams = new URLSearchParams();
        queryParams.set('identifier', `${MRN_SYSTEM_IDENTIFIER}|${data.MRN}`);
        const result = await this.RequestRaw({
            method: 'GET',
            url: `/Patient?${queryParams.toString()}`,
        });
        return result;
    }
    async getAppointment(id) {
        const result = await this.RequestRaw({
            method: 'GET',
            url: `/Appointment/${id}`,
        });
        return result;
    }
    async createDocumentReference(data) {
        const result = await this.RequestRaw({
            method: 'POST',
            url: `/DocumentReference`,
            data,
        });
        return result;
    }
    async getEncounter(id) {
        const result = await this.RequestRaw({
            method: 'GET',
            url: `/Encounter/${id}`,
        });
        return result;
    }
    async searchEncounter(data) {
        const queryParams = new URLSearchParams();
        queryParams.set('patient', data.patientResourceId);
        const result = await this.RequestRaw({
            method: 'GET',
            url: `/Encounter?${queryParams.toString()}`,
        });
        return result;
    }
}
exports.CernerR4DataWrapper = CernerR4DataWrapper;
class CernerR4APIClient extends extensions_core_1.APIClient {
    constructor({ authUrl, requestConfig, ...opts }) {
        super({
            ...opts,
            auth: new extensions_core_1.OAuthClientCredentials({
                auth_url: authUrl,
                request_config: requestConfig,
                useHeaderInAuthorization: true,
                cacheService: cacheService_1.cernerCacheService,
            }),
        });
        this.ctor = (token, baseUrl) => new CernerR4DataWrapper(token, baseUrl);
    }
    async getPatient(id) {
        return await this.FetchData(async (dw) => await dw.getPatient(id));
    }
    async createPatient(patient) {
        return await this.FetchData(async (dw) => await dw.createPatient(patient));
    }
    async searchPatient(data) {
        return await this.FetchData(async (dw) => await dw.searchPatient(data));
    }
    async getAppointment(id) {
        return await this.FetchData(async (dw) => await dw.getAppointment(id));
    }
    async createDocumentReference(data) {
        return await this.FetchData(async (dw) => await dw.createDocumentReference(data));
    }
    async searchEncounter(data) {
        return await this.FetchData(async (dw) => await dw.searchEncounter(data));
    }
    async getEncounter(id) {
        return await this.FetchData(async (dw) => await dw.getEncounter(id));
    }
}
exports.CernerR4APIClient = CernerR4APIClient;
//# sourceMappingURL=FhirR4client.js.map