UNPKG

cql-execution

Version:

An execution framework for the Clinical Quality Language (CQL)

253 lines (214 loc) 6.77 kB
// Generated by CoffeeScript 1.9.3 (function() { var DT, FHIR, Patient, PatientSource, Record, toDate, typeIsArray; DT = require('./datatypes/datatypes'); FHIR = require('./fhir/models'); typeIsArray = require('./util/util').typeIsArray; toDate = function(str) { if (typeof str === 'string') { return new Date(str); } else { return null; } }; Record = (function() { function Record(json1) { this.json = json1; } 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 base, i, len, name, r, ref, ref1; 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 ((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 === 'patient-qicore-qicore-patient') { return [this]; } else { return (ref = this.records[profile]) != null ? ref : []; } }; return Patient; })(); FHIR.Patient.prototype.records = function() { var base, i, len, name, r, ref, ref1; this._records = {}; ref1 = (ref = this.json.records) != null ? ref : []; for (i = 0, len = ref1.length; i < len; i++) { r = ref1[i]; if ((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 === 'patient-qicore-qicore-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, i, len, r, 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("patient-qicore-qicore-patient") : void 0; }; return PatientSource; })(); module.exports.Patient = Patient; module.exports.PatientSource = PatientSource; }).call(this); //# sourceMappingURL=cql-patient.js.map