UNPKG

cql-execution

Version:

An execution framework for the Clinical Quality Language (CQL)

256 lines (215 loc) 6.88 kB
// Generated by CoffeeScript 1.4.0 (function() { var DT, FHIR, Patient, PatientSource, Record, toDate, typeIsArray; DT = require('./cql-datatypes'); FHIR = require('./fhir/models'); typeIsArray = Array.isArray || function(value) { return {}.toString.call(value) === '[object Array]'; }; toDate = function(str) { if (typeof str === 'string') { return new Date(str); } else { return null; } }; Record = (function() { function Record(json) { this.json = json; } Record.prototype.get = function(field) { return this.json[field]; }; Record.prototype.getDate = function(field) { var val; val = this.get(field); if (val != null) { return DT.DateTime.parse(val); } else { return null; } }; Record.prototype.getInterval = function(field) { var end, start, val; val = this.get(field); if ((val != null) && typeof val === 'object') { start = val.start != null ? DT.DateTime.parse(val.start) : null; end = val.end != null ? DT.DateTime.parse(val.end) : null; return new DT.Interval(start, end); } }; Record.prototype.getDateOrInterval = function(field) { var val; val = this.get(field); if ((val != null) && typeof val === 'object') { return this.getInterval(field); } else { return this.getDate(field); } }; Record.prototype.getCode = function(field) { var val; val = this.get(field); if ((val != null) && typeof val === 'object') { return new DT.Code(val.code, val.system, val.version); } }; return Record; })(); Patient = (function() { function Patient(json) { var r, _base, _i, _len, _name, _ref, _ref1, _ref2; this.identifier = json.identifier; this.name = json.name; this.gender = json.gender; this.birthDate = json.birthDate != null ? DT.DateTime.parse(json.birthDate) : void 0; this.records = {}; _ref1 = (_ref = json.records) != null ? _ref : []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { r = _ref1[_i]; if ((_ref2 = (_base = this.records)[_name = r.profile]) == null) { _base[_name] = []; } this.records[r.profile].push(new Record(r)); } } Patient.prototype.findRecords = function(profile) { var _ref; if (profile === 'cqf-patient') { return [this]; } else { return (_ref = this.records[profile]) != null ? _ref : []; } }; return Patient; })(); FHIR.Patient.prototype.records = function() { var r, _base, _i, _len, _name, _ref, _ref1, _ref2; this._records = {}; _ref1 = (_ref = this.json.records) != null ? _ref : []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { r = _ref1[_i]; if ((_ref2 = (_base = this._records)[_name = r.profile]) == null) { _base[_name] = []; } this._records[r.profile].push(new Record(r)); } return this._records; }; FHIR.Patient.prototype.findRecords = function(profile) { var _ref, _ref1; if (profile === 'cqf-patient') { return [this]; } else { return (_ref = (_ref1 = this._bundle) != null ? _ref1.findRecords(profile) : void 0) != null ? _ref : []; } }; FHIR.Bundle.prototype.findRecords = function(profile) { var e, filtered, r, _i, _len, _results; filtered = this.entry().filter(function(e) { var _ref, _ref1, _ref2; return ((_ref = e.resource()) != null ? (_ref1 = _ref.meta()) != null ? (_ref2 = _ref1.profile()) != null ? _ref2.indexOf(profile) : void 0 : void 0 : void 0) > -1; }); _results = []; for (_i = 0, _len = filtered.length; _i < _len; _i++) { e = filtered[_i]; r = e.resource(); r._bundle = this; _results.push(r); } return _results; }; FHIR.Bundle.prototype.findRecord = function(profile) { return this.findRecords(profile)[0]; }; FHIR.Base.prototype.get = function(field) { var _ref; return (_ref = this[field]) != null ? _ref.call(this) : void 0; }; FHIR.Base.prototype.getDate = function(field) { var val; val = this.get(field); if (val instanceof DT.DateTime) { return val; } else if (typeof val === "string") { return DT.DateTime.parse(val); } }; FHIR.Base.prototype.getInterval = function(field) { var val; val = this.get(field); if (val(instannceOf(FHIR.Period))) { return this.periodToInterval(val); } }; FHIR.Base.prototype.getDateOrInterval = function(field) { var val; val = this.get(field); if (val instanceof FHIR.Period) { return this.periodToInterval(val); } else if (typeof val === "string") { return DT.DateTime.parse(val); } else if (val instanceof DT.DateTime) { return val; } }; FHIR.Base.prototype.getCode = function(field) { var val; val = this.get(field); return this.toCode(val); }; FHIR.Base.prototype.toCode = function(val) { var c, _i, _len, _results; if (typeIsArray(val)) { _results = []; for (_i = 0, _len = val.length; _i < _len; _i++) { c = val[_i]; _results.push(this.toCode(c)); } return _results; } else if (val instanceof FHIR.CodeableConcept) { return this.codableConceptToCodes(val); } else if (val instanceof FHIR.Coding) { return this.codingToCode(val); } }; FHIR.Base.prototype.codableConceptToCodes = function(cc) { var c, _i, _len, _ref, _results; _ref = cc.coding(); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { c = _ref[_i]; _results.push(this.codingToCode(c)); } return _results; }; FHIR.Base.prototype.codingToCode = function(coding) { return new DT.Code(coding.code(), coding.system(), coding.version()); }; FHIR.Base.prototype.periodToInterval = function(val) { var end, start; if (val instanceof FHIR.Period) { start = val.getDate("start"); end = val.getDate("end"); return new DT.Interval(start, end); } }; PatientSource = (function() { function PatientSource(patients) { this.patients = patients; this.nextPatient(); } PatientSource.prototype.currentPatient = function() { return this.current_patient; }; PatientSource.prototype.nextPatient = function() { var _ref; this.current = this.patients.shift(); this.current_bundle = this.current ? new FHIR.Bundle(this.current) : void 0; return this.current_patient = (_ref = this.current_bundle) != null ? _ref.findRecord("cqf-patient") : void 0; }; return PatientSource; })(); module.exports.Patient = Patient; module.exports.PatientSource = PatientSource; }).call(this);