"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get createLabTestTypes () {
        return createLabTestTypes;
    },
    get randomLabRequest () {
        return randomLabRequest;
    },
    get randomSensitiveLabRequest () {
        return randomSensitiveLabRequest;
    }
});
const _chance = /*#__PURE__*/ _interop_require_default(require("chance"));
const _patients = require("./patients");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const chance = new _chance.default();
function randomLabTestCategory(overrides = {}) {
    const name = chance.word();
    return {
        name,
        code: name,
        type: 'labTestCategory',
        availableFacilities: null,
        ...overrides
    };
}
function randomLabTestTypeFields(overrides = {}) {
    const name = chance.word();
    return {
        code: name,
        name,
        unit: chance.pickone([
            'mmol/L',
            'umol/L',
            'IU'
        ]),
        isSensitive: false,
        externalCode: chance.word(),
        availableFacilities: null,
        ...overrides
    };
}
const randomLabRequest = async (models, overrides)=>{
    const categoryId = overrides?.categoryId || await (0, _patients.randomReferenceId)(models, 'labTestCategory');
    const labTestTypes = await createLabTestTypes(models, categoryId);
    return {
        categoryId,
        labTestTypeIds: labTestTypes.map((t)=>t.id),
        displayId: 'TESTID',
        ...overrides
    };
};
const randomSensitiveLabRequest = async (models, overrides)=>{
    // Always create a new category. A category should have either sensitive or non sensitive tests
    const { id: sensitiveCategoryId } = await models.ReferenceData.create(randomLabTestCategory({
        type: 'labTestCategory'
    }));
    const labTestTypes = await createLabTestTypes(models, sensitiveCategoryId, {
        isSensitive: true
    });
    return {
        categoryId: sensitiveCategoryId,
        labTestTypeIds: labTestTypes.map((t)=>t.id),
        displayId: 'TESTID',
        ...overrides
    };
};
const createLabTestTypes = async (models, categoryId, overrides)=>{
    const labTestCategoryId = categoryId || await (0, _patients.randomReferenceId)(models, 'labTestCategory');
    const { LabTestType } = models;
    const labTestTypes = Array(2).fill().map(()=>({
            ...randomLabTestTypeFields(),
            labTestCategoryId,
            ...overrides
        }));
    const createdLabTestTypes = await Promise.all(labTestTypes.map((t)=>LabTestType.create(t)));
    return createdLabTestTypes;
};

//# sourceMappingURL=labRequests.js.map