@ai-ecom/medusa-plugin-patient-record
Version:
A plugin for patient record
53 lines (52 loc) • 2.85 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.ReferenceRepository = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _typeorm = require("typeorm");
var _reference = require("../models/reference");
var _database = require("@medusajs/medusa/dist/loaders/database");
var ReferenceRepository = exports.ReferenceRepository = _database.dataSource.getRepository(_reference.Reference).extend({
findReferenceByCustom: function findReferenceByCustom(_ref) {
var _this = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var examinationResultTitleId, gender, type, conditions, reference;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
examinationResultTitleId = _ref.examination_result_title_id, gender = _ref.gender, type = _ref.type, conditions = _ref.conditions;
reference = _this.createQueryBuilder("reference").leftJoinAndSelect("reference.conditions", "conditions").select(["reference.*", "STRING_AGG(conditions.title, ', ') AS conditions"]).where(function (qb) {
qb.where({
examination_result_title_id: examinationResultTitleId,
gender: gender !== null && gender !== void 0 ? gender : (0, _typeorm.IsNull)(),
type: type !== null && type !== void 0 ? type : (0, _typeorm.IsNull)(),
deleted_at: (0, _typeorm.IsNull)()
});
if (conditions !== null && conditions !== void 0 && conditions.length && conditions.length > 0) {
qb.andWhere("conditions.title IN (:...conditions)", {
conditions: conditions
});
qb.having("COUNT(DISTINCT conditions.title) = :conditionCount", {
conditionCount: conditions.length
});
} else {
qb.andWhere("conditions.id IS NULL"); // Ensure there are no associated conditions
}
qb.andWhere("conditions.deleted_at IS NULL");
}).groupBy("reference.id"); // console.log(conditions, gender, type, reference.getQueryAndParameters());
_context.next = 4;
return reference.getRawMany();
case 4:
return _context.abrupt("return", _context.sent);
case 5:
case "end":
return _context.stop();
}
}, _callee);
}))();
}
});
var _default = exports["default"] = ReferenceRepository;