"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccContactApi = void 0;
/**
 * iCure Data Stack API Documentation
 * The iCure Data Stack Application API is the native interface to iCure. This version is obsolete, please use v2.
 *
 * OpenAPI spec version: v1
 *
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */
const XHR_1 = require("./XHR");
const Contact_1 = require("../model/Contact");
const Content_1 = require("../model/Content");
const DocIdentifier_1 = require("../model/DocIdentifier");
const IcureStub_1 = require("../model/IcureStub");
const LabelledOccurence_1 = require("../model/LabelledOccurence");
const ListOfIds_1 = require("../model/ListOfIds");
const PaginatedListContact_1 = require("../model/PaginatedListContact");
const PaginatedListService_1 = require("../model/PaginatedListService");
const Service_1 = require("../model/Service");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
const MinimalEntityBulkShareResult_1 = require("../model/requests/MinimalEntityBulkShareResult");
class IccContactApi {
    get headers() {
        return Promise.resolve(this._headers);
    }
    constructor(host, headers, authenticationProvider, fetchImpl) {
        this.host = (0, IccRestApiPath_1.iccRestApiPath)(host);
        this._headers = Object.keys(headers).map((k) => new XHR_1.XHR.Header(k, headers[k]));
        this.authenticationProvider = !!authenticationProvider ? authenticationProvider : new AuthenticationProvider_1.NoAuthenticationProvider();
        this.fetchImpl = fetchImpl;
    }
    handleError(e) {
        throw e;
    }
    /**
     * Keys must be delimited by coma
     * @summary Close contacts for Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    closeForHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byHcPartySecretForeignKeys/close` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Creates a contact with the current user and returns an instance of created contact afterward.
     * @summary Create a contact with the current user
     * @param body
     */
    createContact(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/contact` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new Contact_1.Contact(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified contacts.
     * @summary Create a batch of contacts
     * @param body
     */
    createContacts(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/contact/batch` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of contacts.
     *
     * @param contactIds a ListOfIds containing the ids of the contacts to delete.
     * @return a Promise that will resolve in an array of the DocIdentifiers of the successfully deleted contacts.
     */
    deleteContacts(contactIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', this.host + `/contact/delete/batch` + '?ts=' + new Date().getTime(), headers, contactIds, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a single contact by id.
     *
     * @param contactId the id of the contact to delete.
     */
    deleteContact(contactId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/contact/${encodeURIComponent(contactId)}` + '?ts=' + new Date().getTime(), yield this.headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    filterContactsBy(startDocumentId_1, limit_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (startDocumentId, limit, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/filter` +
                '?ts=' +
                new Date().getTime() +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(new PaginatedListContact_1.PaginatedListContact(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    filterServicesBy(startDocumentId_1, limit_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (startDocumentId, limit, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/service/filter` +
                '?ts=' +
                new Date().getTime() +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(new PaginatedListService_1.PaginatedListService(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get a list of contacts found by Healthcare Party and form's id.
     * @param hcPartyId
     * @param formId
     */
    findByHCPartyFormId(hcPartyId, formId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byHcPartyFormId` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (formId ? '&formId=' + encodeURIComponent(String(formId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get a list of contacts found by Healthcare Party and form's ids.
     * @param body
     * @param hcPartyId
     */
    findByHCPartyFormIds(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/byHcPartyFormIds` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findContactIdsByDataOwnerPatientOpeningDate} instead.
     * @summary Get a list of contacts found by Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param planOfActionsIds
     * @param skipClosedContacts
      @param body
     */
    findByHCPartyPatientSecretFKeysUsingPost(hcPartyId, planOfActionsIds, skipClosedContacts, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (planOfActionsIds ? '&planOfActionsIds=' + encodeURIComponent(String(planOfActionsIds)) : '') +
                (skipClosedContacts ? '&skipClosedContacts=' + encodeURIComponent(String(skipClosedContacts)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findContactIdsByDataOwnerPatientOpeningDate} instead.
     * @summary Get a list of contacts found by Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     * @param planOfActionsIds
     * @param skipClosedContacts
     */
    findByHCPartyPatientSecretFKeys(hcPartyId, secretFKeys, planOfActionsIds, skipClosedContacts) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '') +
                (planOfActionsIds ? '&planOfActionsIds=' + encodeURIComponent(String(planOfActionsIds)) : '') +
                (skipClosedContacts ? '&skipClosedContacts=' + encodeURIComponent(String(skipClosedContacts)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary List contacts found By Healthcare Party and service Id.
     * @param hcPartyId
     * @param serviceId
     */
    findByHCPartyServiceId(hcPartyId, serviceId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byHcPartyServiceId` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (serviceId ? '&serviceId=' + encodeURIComponent(String(serviceId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary List contacts found By externalId.
     * @param externalId
     */
    findContactsByExternalId(externalId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byExternalId` +
                '?ts=' +
                new Date().getTime() +
                (externalId ? '&externalId=' + encodeURIComponent(String(externalId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findContactIdsByDataOwnerPatientOpeningDate} instead.
     * @summary Get a list of contacts found by Healthcare Party and Patient foreign keys.
     * @param body
     * @param hcPartyId
     */
    findContactsByHCPartyPatientForeignKeys(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/byHcPartyPatientForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Retrieves the delegation stub of the Contact which ids are passed as parameter.
     * @param contactIds the ids of the contact for which the stub should be retrieved
     */
    findContactsDelegationsStubsByIds(contactIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/contact/delegations`;
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, { ids: contactIds }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findContactsDelegationsStubsByIds} instead.
     * @summary List contacts found By Healthcare Party and secret foreign keys.
     * @param body
     * @param hcPartyId
     */
    findContactsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/contact/byHcPartySecretForeignKeys/delegations` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findContactsDelegationsStubsByIds} instead.
     * @summary List contacts found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findContactsDelegationsStubsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byHcPartySecretForeignKeys/delegations` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Gets a contact based on its id
     * @summary Get a contact
     * @param contactId
     */
    getContact(contactId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/contact/${encodeURIComponent(String(contactId))}` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new Contact_1.Contact(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Gets a service based on its id
     * @summary Get a service
     * @param serviceId
     */
    getService(serviceId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/contact/service/${encodeURIComponent(String(serviceId))}` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new Service_1.Service(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Get a list of contact by ids/keys.
     * @summary Get contacts by batch
     * @param body
     */
    getContacts(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/byIds` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get an empty content
     */
    getEmptyContent() {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/contact/service/content/empty` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new Content_1.Content(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get the list of all used codes frequencies in services
     * @param codeType
     * @param minOccurences
     */
    getServiceCodesOccurences(codeType, minOccurences) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/service/codes/${encodeURIComponent(String(codeType))}/${encodeURIComponent(String(minOccurences))}` +
                '?ts=' +
                new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new LabelledOccurence_1.LabelledOccurence(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of contacts.
     * @summary List contacts bu opening date parties with(out) pagination
     * @param startKey The contact openingDate
     * @param endKey The contact max openingDate
     * @param hcpartyid hcpartyid
     * @param startDocumentId A contact party document ID
     * @param limit Number of rows
     */
    listContactsByOpeningDate(startDate, endDate, hcpartyid, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/byOpeningDate` +
                '?ts=' +
                new Date().getTime() +
                (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
                (endDate ? '&endDate=' + encodeURIComponent(String(endDate)) : '') +
                (hcpartyid ? '&hcPartyId=' + encodeURIComponent(String(hcpartyid)) : '') +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListContact_1.PaginatedListContact(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of services
     * @summary List services with provided ids
     * @param body
     */
    listServices(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/service` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Service_1.Service(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of services
     * @summary List services by related association id
     * @param associationId
     */
    listServicesByAssociationId(associationId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/service/associationId` +
                '?ts=' +
                new Date().getTime() +
                (associationId ? '&associationId=' + encodeURIComponent(String(associationId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Service_1.Service(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the list of services linked to the provided health element id
     * @summary List services linked to a health element
     * @param healthElementId
     * @param hcPartyId hcPartyId
     */
    listServicesByHealthElementId(healthElementId, hcPartyId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/contact/service/healthElementId/${encodeURIComponent(String(healthElementId))}` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Service_1.Service(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of services
     * @summary List services linked to provided ids
     * @param body
     * @param linkType The type of the link
     */
    listServicesLinkedTo(linkType, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/service/linkedTo` + '?ts=' + new Date().getTime() + (linkType ? '&linkType=' + encodeURIComponent(String(linkType)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Service_1.Service(it)))
                .catch((err) => this.handleError(err));
        });
    }
    matchContactsBy(body_1) {
        return __awaiter(this, arguments, void 0, function* (body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/match` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(doc.body.map((it) => JSON.parse(JSON.stringify(it))), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    matchServicesBy(body_1) {
        return __awaiter(this, arguments, void 0, function* (body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/service/match` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(doc.body.map((it) => JSON.parse(JSON.stringify(it))), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified contact.
     * @summary Modify a contact
     * @param body
     */
    modifyContact(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new Contact_1.Contact(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified contacts.
     * @summary Modify a batch of contacts
     * @param body
     */
    modifyContacts(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/contact/batch` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List Contact ids by data owner and a set of secret foreign key. The ids will be sorted by Contact openingDate, in ascending or descending
     * order according to the specified parameter value.
     *
     * @param dataOwnerId the data owner id.
     * @param secretFKeys an array of secret foreign keys.
     * @param startDate a timestamp in epoch milliseconds. If undefined, all the contact ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the contact ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by Contact openingDate
     * @return a promise that will resolve in an Array of Contact ids.
     */
    findContactIdsByDataOwnerPatientOpeningDate(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/contact/byDataOwnerPatientOpeningDate?ts=${new Date().getTime()}` +
                '&dataOwnerId=' +
                encodeURIComponent(dataOwnerId) +
                (!!startDate ? `&startDate=${encodeURIComponent(startDate)}` : '') +
                (!!endDate ? `&endDate=${encodeURIComponent(endDate)}` : '') +
                (!!descending ? `&descending=${descending}` : '');
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            const body = new ListOfIds_1.ListOfIds({ ids: secretFKeys });
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => JSON.parse(JSON.stringify(it))))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareContacts(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/contact/bulkSharedMetadataUpdate' + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new EntityBulkShareResult_1.EntityBulkShareResult(x, Contact_1.Contact)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareContactsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/contact/bulkSharedMetadataUpdateMinimal' + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new MinimalEntityBulkShareResult_1.MinimalEntityBulkShareResult(x)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccContactApi = IccContactApi;
//# sourceMappingURL=IccContactApi.js.map