@ai-ecom/medusa-plugin-patient-record
Version:
A plugin for patient record
467 lines (466 loc) • 22.6 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _medusa = require("@medusajs/medusa");
var _medusaCoreUtils = require("medusa-core-utils");
var _excluded = ["blood_analyte_method", "unit"];
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var BloodAnalyteService = /*#__PURE__*/function (_TransactionBaseServi) {
function BloodAnalyteService(_ref) {
var _this;
var bloodAnalyteRepository = _ref.bloodAnalyteRepository,
bloodAnalyteMethodRepository = _ref.bloodAnalyteMethodRepository,
unitRepository = _ref.unitRepository,
eventBusService = _ref.eventBusService;
(0, _classCallCheck2["default"])(this, BloodAnalyteService);
// eslint-disable-next-line prefer-rest-params
_this = _callSuper(this, BloodAnalyteService, [arguments[0]]);
_this.bloodAnalyteRepository_ = bloodAnalyteRepository;
_this.bloodAnalyteMethodRepository_ = bloodAnalyteMethodRepository;
_this.unitRepository_ = unitRepository;
_this.eventBus_ = eventBusService;
return _this;
}
(0, _inherits2["default"])(BloodAnalyteService, _TransactionBaseServi);
return (0, _createClass2["default"])(BloodAnalyteService, [{
key: "list",
value: function () {
var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(selector) {
var config,
_yield$this$listAndCo,
_yield$this$listAndCo2,
bloodAnalyte,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
config = _args.length > 1 && _args[1] !== undefined ? _args[1] : {
skip: 0,
take: 50,
relations: []
};
_context.next = 3;
return this.listAndCount(selector, config);
case 3:
_yield$this$listAndCo = _context.sent;
_yield$this$listAndCo2 = (0, _slicedToArray2["default"])(_yield$this$listAndCo, 1);
bloodAnalyte = _yield$this$listAndCo2[0];
return _context.abrupt("return", bloodAnalyte);
case 7:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function list(_x) {
return _list.apply(this, arguments);
}
return list;
}()
}, {
key: "listAndCount",
value: function () {
var _listAndCount = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(selector) {
var config,
bloodAnalyteRepo,
query,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
config = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
skip: 0,
take: 50,
relations: []
};
bloodAnalyteRepo = this.activeManager_.withRepository(this.bloodAnalyteRepository_);
query = (0, _medusa.buildQuery)(selector, config);
return _context2.abrupt("return", bloodAnalyteRepo.findAndCount(query));
case 4:
case "end":
return _context2.stop();
}
}, _callee2, this);
}));
function listAndCount(_x2) {
return _listAndCount.apply(this, arguments);
}
return listAndCount;
}()
}, {
key: "listAndCountDetails",
value: function () {
var _listAndCountDetails = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(_ref2) {
var appointment_id, reference_id, bloodAnalyteRepo, queryBuilder;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
appointment_id = _ref2.appointment_id, reference_id = _ref2.reference_id;
bloodAnalyteRepo = this.activeManager_.withRepository(this.bloodAnalyteRepository_);
queryBuilder = bloodAnalyteRepo.createQueryBuilder("blood_analyte").leftJoinAndSelect("blood_analyte.examination_result", "examination_result").leftJoinAndSelect("blood_analyte.method", "blood_analyte_method").leftJoinAndSelect("blood_analyte.unit", "unit").leftJoinAndSelect("unit.nominator", "nominator").leftJoinAndSelect("unit.denominator", "denominator").leftJoinAndSelect("examination_result.title", "examination_result_title").leftJoinAndSelect("examination_result.customer", "customer")
// .leftJoinAndSelect("examination_result_title.examinations", "examination")
.leftJoinAndSelect("examination_result_title.nature", "nature").leftJoinAndSelect("examination_result_title.references", "references").leftJoinAndSelect("references.values", "references_values").leftJoinAndSelect("references.conditions", "references_conditions").leftJoinAndSelect("references.unit", "references_unit").leftJoinAndSelect("references_unit.nominator", "references_unit_nominator").leftJoinAndSelect("references_unit.denominator", "references_unit_denominator"); // .leftJoinAndSelect(
// "reference.ethnicities_have_references",
// "ethnicities_have_references",
// )
// .leftJoinAndSelect("ethnicities_have_references.ethnicity", "ethnicity")
// .where("ethnicity.id = customer.ethnicity_id")
// .andWhere("reference.gender = customer.gender");
if (appointment_id) {
queryBuilder.andWhere("examination_result.appointment_id = :id", {
id: appointment_id
});
}
if (reference_id) {
queryBuilder.andWhere("examination_result.reference_id = :id", {
id: reference_id
});
}
_context3.next = 7;
return queryBuilder.skip(0).take(10000).getManyAndCount();
case 7:
return _context3.abrupt("return", _context3.sent);
case 8:
case "end":
return _context3.stop();
}
}, _callee3, this);
}));
function listAndCountDetails(_x3) {
return _listAndCountDetails.apply(this, arguments);
}
return listAndCountDetails;
}()
}, {
key: "retrieve",
value: function () {
var _retrieve = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(bloodAnalyteId, config) {
var bloodAnalyte;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return this.retrieve_({
id: bloodAnalyteId
}, config);
case 2:
bloodAnalyte = _context4.sent;
if (bloodAnalyte) {
_context4.next = 5;
break;
}
throw new _medusaCoreUtils.MedusaError(_medusaCoreUtils.MedusaError.Types.NOT_FOUND, "BloodAnalyte with ".concat(bloodAnalyteId, " was not found"));
case 5:
return _context4.abrupt("return", bloodAnalyte);
case 6:
case "end":
return _context4.stop();
}
}, _callee4, this);
}));
function retrieve(_x4, _x5) {
return _retrieve.apply(this, arguments);
}
return retrieve;
}()
}, {
key: "retrieveByExaminationResultId",
value: function () {
var _retrieveByExaminationResultId = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(examinationResultId, config) {
var bloodAnalyte;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.retrieve_({
examination_result_id: examinationResultId
}, config);
case 2:
bloodAnalyte = _context5.sent;
if (bloodAnalyte) {
_context5.next = 5;
break;
}
throw new _medusaCoreUtils.MedusaError(_medusaCoreUtils.MedusaError.Types.NOT_FOUND, "BloodAnalyte with examination_result_id ".concat(examinationResultId, " was not found"));
case 5:
return _context5.abrupt("return", bloodAnalyte);
case 6:
case "end":
return _context5.stop();
}
}, _callee5, this);
}));
function retrieveByExaminationResultId(_x6, _x7) {
return _retrieveByExaminationResultId.apply(this, arguments);
}
return retrieveByExaminationResultId;
}()
}, {
key: "retrieve_",
value: function () {
var _retrieve_ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(selector, config) {
var bloodAnalyteRepo, query, bloodAnalyte;
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
bloodAnalyteRepo = this.activeManager_.withRepository(this.bloodAnalyteRepository_);
query = (0, _medusa.buildQuery)(selector, config);
_context6.next = 4;
return bloodAnalyteRepo.findOne(query);
case 4:
bloodAnalyte = _context6.sent;
return _context6.abrupt("return", bloodAnalyte);
case 6:
case "end":
return _context6.stop();
}
}, _callee6, this);
}));
function retrieve_(_x8, _x9) {
return _retrieve_.apply(this, arguments);
}
return retrieve_;
}()
}, {
key: "create",
value: function () {
var _create = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(bloodAnalyteObject) {
var _this2 = this;
var emitTransaction,
_args8 = arguments;
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
emitTransaction = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : true;
_context8.next = 3;
return this.atomicPhase_( /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(manager) {
var bloodAnalyteRepo, bloodAnalyteMethodRepo, unitRepo, bloodAnalyteMethod, unit, rest, bloodAnalyte, result;
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
bloodAnalyteRepo = manager.withRepository(_this2.bloodAnalyteRepository_);
bloodAnalyteMethodRepo = manager.withRepository(_this2.bloodAnalyteMethodRepository_);
unitRepo = manager.withRepository(_this2.unitRepository_);
bloodAnalyteMethod = bloodAnalyteObject.blood_analyte_method, unit = bloodAnalyteObject.unit, rest = (0, _objectWithoutProperties2["default"])(bloodAnalyteObject, _excluded);
_context7.prev = 4;
bloodAnalyte = bloodAnalyteRepo.create(rest);
if (!bloodAnalyteMethod) {
_context7.next = 10;
break;
}
_context7.next = 9;
return bloodAnalyteMethodRepo.upsertBloodAnalyteMethod(bloodAnalyteMethod);
case 9:
bloodAnalyte.method = _context7.sent;
case 10:
if (!unit) {
_context7.next = 14;
break;
}
_context7.next = 13;
return unitRepo.upsertUnit({
nominator_id: unit.nominator,
denominator_id: unit.denominator
});
case 13:
bloodAnalyte.unit = _context7.sent;
case 14:
_context7.next = 16;
return bloodAnalyteRepo.save(bloodAnalyte);
case 16:
bloodAnalyte = _context7.sent;
_context7.next = 19;
return _this2.retrieve(bloodAnalyte.id, {
relations: ["method", "unit", "unit.nominator", "unit.denominator"]
});
case 19:
result = _context7.sent;
if (!emitTransaction) {
_context7.next = 23;
break;
}
_context7.next = 23;
return _this2.eventBus_.withTransaction(manager).emit(BloodAnalyteService.Events.CREATED, {
id: result.id
});
case 23:
return _context7.abrupt("return", result);
case 26:
_context7.prev = 26;
_context7.t0 = _context7["catch"](4);
throw (0, _medusa.formatException)(_context7.t0);
case 29:
case "end":
return _context7.stop();
}
}, _callee7, null, [[4, 26]]);
}));
return function (_x11) {
return _ref3.apply(this, arguments);
};
}());
case 3:
return _context8.abrupt("return", _context8.sent);
case 4:
case "end":
return _context8.stop();
}
}, _callee8, this);
}));
function create(_x10) {
return _create.apply(this, arguments);
}
return create;
}()
}, {
key: "delete",
value: function () {
var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(bloodAnalyteId) {
var _this3 = this;
return _regenerator["default"].wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return this.atomicPhase_( /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(manager) {
var bloodAnalyteRepo, bloodAnalyte;
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
bloodAnalyteRepo = manager.withRepository(_this3.bloodAnalyteRepository_);
_context9.next = 3;
return bloodAnalyteRepo.findOne({
where: {
id: bloodAnalyteId
},
relations: []
});
case 3:
bloodAnalyte = _context9.sent;
if (bloodAnalyte) {
_context9.next = 6;
break;
}
return _context9.abrupt("return");
case 6:
_context9.next = 8;
return bloodAnalyteRepo.softRemove(bloodAnalyte);
case 8:
_context9.next = 10;
return _this3.eventBus_.withTransaction(manager).emit(BloodAnalyteService.Events.DELETED, {
id: bloodAnalyteId
});
case 10:
return _context9.abrupt("return", Promise.resolve());
case 11:
case "end":
return _context9.stop();
}
}, _callee9);
}));
return function (_x13) {
return _ref4.apply(this, arguments);
};
}());
case 2:
return _context10.abrupt("return", _context10.sent);
case 3:
case "end":
return _context10.stop();
}
}, _callee10, this);
}));
function _delete(_x12) {
return _delete2.apply(this, arguments);
}
return _delete;
}()
}, {
key: "update",
value: function () {
var _update2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(bloodAnalyteId, _update) {
var _this4 = this;
return _regenerator["default"].wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return this.atomicPhase_( /*#__PURE__*/function () {
var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(manager) {
var bloodAnalyteRepo, bloodAnalyte, rest, _i, _Object$entries, _Object$entries$_i, key, value, result;
return _regenerator["default"].wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
bloodAnalyteRepo = manager.withRepository(_this4.bloodAnalyteRepository_);
_context11.next = 3;
return _this4.retrieve(bloodAnalyteId, {});
case 3:
bloodAnalyte = _context11.sent;
rest = (0, _extends2["default"])({}, ((0, _objectDestructuringEmpty2["default"])(_update), _update));
for (_i = 0, _Object$entries = Object.entries(rest); _i < _Object$entries.length; _i++) {
_Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
if ((0, _typeof2["default"])(value) !== "undefined") {
bloodAnalyte[key] = value;
}
}
_context11.next = 8;
return bloodAnalyteRepo.save(bloodAnalyte);
case 8:
result = _context11.sent;
_context11.next = 11;
return _this4.eventBus_.withTransaction(manager).emit(BloodAnalyteService.Events.UPDATED, {
id: result.id,
fields: Object.keys(_update)
});
case 11:
return _context11.abrupt("return", result);
case 12:
case "end":
return _context11.stop();
}
}, _callee11);
}));
return function (_x16) {
return _ref5.apply(this, arguments);
};
}());
case 2:
return _context12.abrupt("return", _context12.sent);
case 3:
case "end":
return _context12.stop();
}
}, _callee12, this);
}));
function update(_x14, _x15) {
return _update2.apply(this, arguments);
}
return update;
}()
}]);
}(_medusa.TransactionBaseService);
// eslint-disable-next-line max-len
(0, _defineProperty2["default"])(BloodAnalyteService, "IndexName", "blood-analytes");
(0, _defineProperty2["default"])(BloodAnalyteService, "Events", {
UPDATED: "blood-analyte.updated",
CREATED: "blood-analyte.created",
DELETED: "blood-analyte.deleted"
});
var _default = exports["default"] = BloodAnalyteService;