"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBIM = isBIM;
exports.patientIsBIM = patientIsBIM;
exports.isPatientPaymentByIo = isPatientPaymentByIo;
exports.getMembership = getMembership;
exports.getInsurability = getInsurability;
exports.isPatientHospitalized = isPatientHospitalized;
function isBIM(ct1, ct2) {
    //BIM if ct1 ood and ct2 ood
    return +ct1 % 2 !== 0 && +ct2 % 2 !== 0;
}
function patientIsBIM(patient) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    // FIXME this doesn't check the date of the insurability. It is related to the idea of having only on insurability at a time.
    return isBIM((_d = (_c = (_b = (_a = patient === null || patient === void 0 ? void 0 : patient.insurabilities) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.parameters) === null || _c === void 0 ? void 0 : _c.tc1) !== null && _d !== void 0 ? _d : '000', (_h = (_g = (_f = (_e = patient === null || patient === void 0 ? void 0 : patient.insurabilities) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.parameters) === null || _g === void 0 ? void 0 : _g.tc2) !== null && _h !== void 0 ? _h : '000');
}
function isPatientPaymentByIo(patient) {
    var _a, _b, _c;
    const paymentByIo = (_c = (_b = (_a = patient === null || patient === void 0 ? void 0 : patient.insurabilities) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.parameters) === null || _c === void 0 ? void 0 : _c.paymentByIo;
    return paymentByIo === 'true';
}
/**
 * Returns the titulary id from patient insurability
 * @throws error if the patient has no insurability data
 * @param patient The patient
 */
function getMembership(patient) {
    var _a, _b;
    const ioCode = (_b = (_a = patient === null || patient === void 0 ? void 0 : patient.insurabilities) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.identificationNumber;
    if (ioCode === undefined) {
        // TODO translate
        throw new Error("Le patient n'a pas de données d'assurabilité");
    }
    return ioCode;
}
/**
 * Returns the insurability from patient
 * @throws error if the patient has no insurability data
 * @param patient The patient
 */
function getInsurability(patient) {
    var _a;
    const insurability = (_a = patient === null || patient === void 0 ? void 0 : patient.insurabilities) === null || _a === void 0 ? void 0 : _a[0];
    if (insurability === undefined) {
        // TODO translate
        throw new Error("Le patient n'a pas de données d'assurabilité");
    }
    return insurability;
}
/**
 * Returns the insurability from patient
 * @throws error if the patient has no insurability data
 * @param patient
 */
function isPatientHospitalized(patient) {
    return getInsurability(patient).hospitalisation || false;
}
//# sourceMappingURL=insurability-util.js.map