From ced876e2006ea7a50764184260bcd7e56d28ecad Mon Sep 17 00:00:00 2001 From: Rohit Kandimalla Date: Fri, 9 Feb 2024 11:52:33 -0500 Subject: [PATCH] updating browser.js --- dist/browser.js | 113018 +++++++++++++++++++++++---------------------- 1 file changed, 56558 insertions(+), 56460 deletions(-) diff --git a/dist/browser.js b/dist/browser.js index 0629477..de6b5b7 100644 --- a/dist/browser.js +++ b/dist/browser.js @@ -3,7 +3,7 @@ window.cqm = window.cqm || {}; window.cqm.execution = require('./index'); window.cqm.models = require('cqm-models'); -},{"./index":5,"cqm-models":193}],2:[function(require,module,exports){ +},{"./index":5,"cqm-models":196}],2:[function(require,module,exports){ const moment = require('moment'); const CqmModels = require('cqm-models'); @@ -122,13 +122,13 @@ module.exports = class CalculatorHelpers { } if ('observation_values' in populationResults) { // DENOM observation will be the first of 2 observations - populationResultsHandled.observation_values[0] = 0; + populationResultsHandled.observation_values.unshift(0); } } if (populationResults.DENEX != null && !this.isValueZero('DENEX', populationResults) && populationResults.DENEX >= populationResults.DENOM) { if ('observation_values' in populationResults) { // DENOM observation will be the first of 2 observations - populationResultsHandled.observation_values[0] = 0; + populationResultsHandled.observation_values.unshift(0); } } if (this.isValueZero('NUMER', populationResults)) { @@ -317,6 +317,7 @@ module.exports = class CalculatorHelpers { }); } } + if ((observationDefs != null ? observationDefs.length : undefined) > 0) { // Handle observations using the names of the define statements that // were added to the ELM to call the observation functions. @@ -543,7 +544,7 @@ module.exports = class CalculatorHelpers { } }; -},{"cqm-models":193,"moment":225}],3:[function(require,module,exports){ +},{"cqm-models":196,"moment":225}],3:[function(require,module,exports){ const _ = require('lodash'); /** @@ -921,7 +922,7 @@ module.exports = class MeasureHelpers { } }; -},{"lodash":223}],4:[function(require,module,exports){ +},{"lodash":224}],4:[function(require,module,exports){ /* eslint-disable camelcase */ const _ = require('lodash'); const CqmModels = require('cqm-models'); @@ -1661,7 +1662,7 @@ module.exports = class ResultsHelpers { } }; -},{"./measure_helpers":3,"cqm-models":193,"lodash":223,"moment":225}],5:[function(require,module,exports){ +},{"./measure_helpers":3,"cqm-models":196,"lodash":224,"moment":225}],5:[function(require,module,exports){ module.exports.CalculatorHelpers = require('./helpers/calculator_helpers'); module.exports.MeasureHelpers = require('./helpers/measure_helpers'); module.exports.ResultsHelpers = require('./helpers/results_helpers'); @@ -1900,7 +1901,7 @@ module.exports = class Calculator { } }; -},{"../helpers/calculator_helpers":2,"../helpers/results_helpers":4,"./patient_source":7,"cqm-models":193,"lodash":223}],7:[function(require,module,exports){ +},{"../helpers/calculator_helpers":2,"../helpers/results_helpers":4,"./patient_source":7,"cqm-models":196,"lodash":224}],7:[function(require,module,exports){ // This is a wrapper class for an array of QDM Patients // This class adds functions used by the execution engine to // traverse an array of QDM Patients @@ -1923,22445 +1924,19560 @@ module.exports = class PatientSource { }; },{}],8:[function(require,module,exports){ -module.exports={"license":"The following data (prefixes and units) was generated by the UCUM LHC code from the UCUM data and selected LOINC combinations of UCUM units. The license for the UCUM LHC code (demo and library code as well as the combined units) is located at https://github.com/lhncbc/ucum-lhc/blob/LICENSE.md.","prefixes":{"config":["code_","ciCode_","name_","printSymbol_","value_","exp_"],"data":[["E","EX","exa","E",1000000000000000000,"18"],["G","GA","giga","G",1000000000,"9"],["Gi","GIB","gibi","Gi",1073741824,null],["Ki","KIB","kibi","Ki",1024,null],["M","MA","mega","M",1000000,"6"],["Mi","MIB","mebi","Mi",1048576,null],["P","PT","peta","P",1000000000000000,"15"],["T","TR","tera","T",1000000000000,"12"],["Ti","TIB","tebi","Ti",1099511627776,null],["Y","YA","yotta","Y",1e+24,"24"],["Z","ZA","zetta","Z",1e+21,"21"],["a","A","atto","a",1e-18,"-18"],["c","C","centi","c",0.01,"-2"],["d","D","deci","d",0.1,"-1"],["da","DA","deka","da",10,"1"],["f","F","femto","f",1e-15,"-15"],["h","H","hecto","h",100,"2"],["k","K","kilo","k",1000,"3"],["m","M","milli","m",0.001,"-3"],["n","N","nano","n",1e-9,"-9"],["p","P","pico","p",1e-12,"-12"],["u","U","micro","μ",0.000001,"-6"],["y","YO","yocto","y",1.0000000000000001e-24,"-24"],["z","ZO","zepto","z",1e-21,"-21"]]},"units":{"config":["isBase_","name_","csCode_","ciCode_","property_","magnitude_",["dim_","dimVec_"],"printSymbol_","class_","isMetric_","variable_","cnv_","cnvPfx_","isSpecial_","isArbitrary_","moleExp_","synonyms_","source_","loincProperty_","category_","guidance_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_"],"data":[[true,"meter","m","M","length",1,[1,0,0,0,0,0,0],"m",null,false,"L",null,1,false,false,0,"meters; metres; distance","UCUM","Len","Clinical","unit of length = 1.09361 yards",null,null,null,null,false],[true,"second - time","s","S","time",1,[0,1,0,0,0,0,0],"s",null,false,"T",null,1,false,false,0,"seconds","UCUM","Time","Clinical","",null,null,null,null,false],[true,"gram","g","G","mass",1,[0,0,1,0,0,0,0],"g",null,false,"M",null,1,false,false,0,"grams; gm","UCUM","Mass","Clinical","",null,null,null,null,false],[true,"radian","rad","RAD","plane angle",1,[0,0,0,1,0,0,0],"rad",null,false,"A",null,1,false,false,0,"radians","UCUM","Angle","Clinical","unit of angular measure where 1 radian = 1/2π turn = 57.296 degrees. ",null,null,null,null,false],[true,"degree Kelvin","K","K","temperature",1,[0,0,0,0,1,0,0],"K",null,false,"C",null,1,false,false,0,"Kelvin; degrees","UCUM","Temp","Clinical","absolute, thermodynamic temperature scale ",null,null,null,null,false],[true,"coulomb","C","C","electric charge",1,[0,0,0,0,0,1,0],"C",null,false,"Q",null,1,false,false,0,"coulombs","UCUM","","Clinical","defined as amount of 1 electron charge = 6.2415093×10^18 e, and equivalent to 1 Ampere-second",null,null,null,null,false],[true,"candela","cd","CD","luminous intensity",1,[0,0,0,0,0,0,1],"cd",null,false,"F",null,1,false,false,0,"candelas","UCUM","","Clinical","SI base unit of luminous intensity",null,null,null,null,false],[false,"the number ten for arbitrary powers","10*","10*","number",10,[0,0,0,0,0,0,0],"10","dimless",false,null,null,1,false,false,0,"10^; 10 to the arbitrary powers","UCUM","Num","Clinical","10* by itself is the same as 10, but users can add digits after the *. For example, 10*3 = 1000.","1","1","10",10,false],[false,"the number ten for arbitrary powers","10^","10^","number",10,[0,0,0,0,0,0,0],"10","dimless",false,null,null,1,false,false,0,"10*; 10 to the arbitrary power","UCUM","Num","Clinical","10* by itself is the same as 10, but users can add digits after the *. For example, 10*3 = 1000.","1","1","10",10,false],[false,"the number pi","[pi]","[PI]","number",3.141592653589793,[0,0,0,0,0,0,0],"π","dimless",false,null,null,1,false,false,0,"π","UCUM","","Constant","a mathematical constant; the ratio of a circle's circumference to its diameter ≈ 3.14159","1","1","3.1415926535897932384626433832795028841971693993751058209749445923",3.141592653589793,false],[false,"","%","%","fraction",0.01,[0,0,0,0,0,0,0],"%","dimless",false,null,null,1,false,false,0,"percents","UCUM","FR; NFR; MFR; CFR; SFR Rto; etc. ","Clinical","","10*-2","10*-2","1",1,false],[false,"parts per thousand","[ppth]","[PPTH]","fraction",0.001,[0,0,0,0,0,0,0],"ppth","dimless",false,null,null,1,false,false,0,"ppth; 10^-3","UCUM","MCnc; MCnt","Clinical","[ppth] is often used in solution concentrations as 1 g/L or 1 g/kg.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-3","10*-3","1",1,false],[false,"parts per million","[ppm]","[PPM]","fraction",0.000001,[0,0,0,0,0,0,0],"ppm","dimless",false,null,null,1,false,false,0,"ppm; 10^-6","UCUM","MCnt; MCnc; SFr","Clinical","[ppm] is often used in solution concentrations as 1 mg/L or 1 mg/kg. Also used to express mole fractions as 1 mmol/mol.\n\n[ppm] is also used in nuclear magnetic resonance (NMR) to represent chemical shift - the difference of a measured frequency in parts per million from the reference frequency.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-6","10*-6","1",1,false],[false,"parts per billion","[ppb]","[PPB]","fraction",1e-9,[0,0,0,0,0,0,0],"ppb","dimless",false,null,null,1,false,false,0,"ppb; 10^-9","UCUM","MCnt; MCnc; SFr","Clinical","[ppb] is often used in solution concentrations as 1 ug/L or 1 ug/kg. Also used to express mole fractions as 1 umol/mol.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-9","10*-9","1",1,false],[false,"parts per trillion","[pptr]","[PPTR]","fraction",1e-12,[0,0,0,0,0,0,0],"pptr","dimless",false,null,null,1,false,false,0,"pptr; 10^-12","UCUM","MCnt; MCnc; SFr","Clinical","[pptr] is often used in solution concentrations as 1 ng/L or 1 ng/kg. Also used to express mole fractions as 1 nmol/mol.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-12","10*-12","1",1,false],[false,"mole","mol","MOL","amount of substance",6.0221367e+23,[0,0,0,0,0,0,0],"mol","si",true,null,null,1,false,false,1,"moles","UCUM","Sub","Clinical","Measure the number of molecules ","10*23","10*23","6.0221367",6.0221367,false],[false,"steradian - solid angle","sr","SR","solid angle",1,[0,0,0,2,0,0,0],"sr","si",true,null,null,1,false,false,0,"square radian; rad2; rad^2","UCUM","Angle","Clinical","unit of solid angle in three-dimensional geometry analagous to radian; used in photometry which measures the perceived brightness of object by human eye (e.g. radiant intensity = watt/steradian)","rad2","RAD2","1",1,false],[false,"hertz","Hz","HZ","frequency",1,[0,-1,0,0,0,0,0],"Hz","si",true,null,null,1,false,false,0,"Herz; frequency; frequencies","UCUM","Freq; Num","Clinical","equal to one cycle per second","s-1","S-1","1",1,false],[false,"newton","N","N","force",1000,[1,-2,1,0,0,0,0],"N","si",true,null,null,1,false,false,0,"Newtons","UCUM","Force","Clinical","unit of force with base units kg.m/s2","kg.m/s2","KG.M/S2","1",1,false],[false,"pascal","Pa","PAL","pressure",1000,[-1,-2,1,0,0,0,0],"Pa","si",true,null,null,1,false,false,0,"pascals","UCUM","Pres","Clinical","standard unit of pressure equal to 1 newton per square meter (N/m2)","N/m2","N/M2","1",1,false],[false,"joule","J","J","energy",1000,[2,-2,1,0,0,0,0],"J","si",true,null,null,1,false,false,0,"joules","UCUM","Enrg","Clinical","unit of energy defined as the work required to move an object 1 m with a force of 1 N (N.m) or an electric charge of 1 C through 1 V (C.V), or to produce 1 W for 1 s (W.s) ","N.m","N.M","1",1,false],[false,"watt","W","W","power",1000,[2,-3,1,0,0,0,0],"W","si",true,null,null,1,false,false,0,"watts","UCUM","EngRat","Clinical","unit of power equal to 1 Joule per second (J/s) = kg⋅m2⋅s−3","J/s","J/S","1",1,false],[false,"Ampere","A","A","electric current",1,[0,-1,0,0,0,1,0],"A","si",true,null,null,1,false,false,0,"Amperes","UCUM","ElpotRat","Clinical","unit of electric current equal to flow rate of electrons equal to 16.2415×10^18 elementary charges moving past a boundary in one second or 1 Coulomb/second","C/s","C/S","1",1,false],[false,"volt","V","V","electric potential",1000,[2,-2,1,0,0,-1,0],"V","si",true,null,null,1,false,false,0,"volts","UCUM","Elpot","Clinical","unit of electric potential (voltage) = 1 Joule per Coulomb (J/C)","J/C","J/C","1",1,false],[false,"farad","F","F","electric capacitance",0.001,[-2,2,-1,0,0,2,0],"F","si",true,null,null,1,false,false,0,"farads; electric capacitance","UCUM","","Clinical","CGS unit of electric capacitance with base units C/V (Coulomb per Volt)","C/V","C/V","1",1,false],[false,"ohm","Ohm","OHM","electric resistance",1000,[2,-1,1,0,0,-2,0],"Ω","si",true,null,null,1,false,false,0,"Ω; resistance; ohms","UCUM","","Clinical","unit of electrical resistance with units of Volt per Ampere","V/A","V/A","1",1,false],[false,"siemens","S","SIE","electric conductance",0.001,[-2,1,-1,0,0,2,0],"S","si",true,null,null,1,false,false,0,"Reciprocal ohm; mho; Ω−1; conductance","UCUM","","Clinical","unit of electric conductance (the inverse of electrical resistance) equal to ohm^-1","Ohm-1","OHM-1","1",1,false],[false,"weber","Wb","WB","magnetic flux",1000,[2,-1,1,0,0,-1,0],"Wb","si",true,null,null,1,false,false,0,"magnetic flux; webers","UCUM","","Clinical","unit of magnetic flux equal to Volt second","V.s","V.S","1",1,false],[false,"degree Celsius","Cel","CEL","temperature",1,[0,0,0,0,1,0,0],"°C","si",true,null,"Cel",1,true,false,0,"°C; degrees","UCUM","Temp","Clinical","","K",null,null,1,false],[false,"tesla","T","T","magnetic flux density",1000,[0,-1,1,0,0,-1,0],"T","si",true,null,null,1,false,false,0,"Teslas; magnetic field","UCUM","","Clinical","SI unit of magnetic field strength for magnetic field B equal to 1 Weber/square meter = 1 kg/(s2*A)","Wb/m2","WB/M2","1",1,false],[false,"henry","H","H","inductance",1000,[2,0,1,0,0,-2,0],"H","si",true,null,null,1,false,false,0,"henries; inductance","UCUM","","Clinical","unit of electrical inductance; usually expressed in millihenrys (mH) or microhenrys (uH).","Wb/A","WB/A","1",1,false],[false,"lumen","lm","LM","luminous flux",1,[0,0,0,2,0,0,1],"lm","si",true,null,null,1,false,false,0,"luminous flux; lumens","UCUM","","Clinical","unit of luminous flux defined as 1 lm = 1 cd⋅sr (candela times sphere)","cd.sr","CD.SR","1",1,false],[false,"lux","lx","LX","illuminance",1,[-2,0,0,2,0,0,1],"lx","si",true,null,null,1,false,false,0,"illuminance; luxes","UCUM","","Clinical","unit of illuminance equal to one lumen per square meter. ","lm/m2","LM/M2","1",1,false],[false,"becquerel","Bq","BQ","radioactivity",1,[0,-1,0,0,0,0,0],"Bq","si",true,null,null,1,false,false,0,"activity; radiation; becquerels","UCUM","","Clinical","measure of the atomic radiation rate with units s^-1","s-1","S-1","1",1,false],[false,"gray","Gy","GY","energy dose",1,[2,-2,0,0,0,0,0],"Gy","si",true,null,null,1,false,false,0,"absorbed doses; ionizing radiation doses; kerma; grays","UCUM","EngCnt","Clinical","unit of ionizing radiation dose with base units of 1 joule of radiation energy per kilogram of matter","J/kg","J/KG","1",1,false],[false,"sievert","Sv","SV","dose equivalent",1,[2,-2,0,0,0,0,0],"Sv","si",true,null,null,1,false,false,0,"sieverts; radiation dose quantities; equivalent doses; effective dose; operational dose; committed dose","UCUM","","Clinical","SI unit for radiation dose equivalent equal to 1 Joule/kilogram.","J/kg","J/KG","1",1,false],[false,"degree - plane angle","deg","DEG","plane angle",0.017453292519943295,[0,0,0,1,0,0,0],"°","iso1000",false,null,null,1,false,false,0,"°; degree of arc; arc degree; arcdegree; angle","UCUM","Angle","Clinical","one degree is equivalent to π/180 radians.","[pi].rad/360","[PI].RAD/360","2",2,false],[false,"gon","gon","GON","plane angle",0.015707963267948967,[0,0,0,1,0,0,0],"□g","iso1000",false,null,null,1,false,false,0,"gon (grade); gons","UCUM","Angle","Nonclinical","unit of plane angle measurement equal to 1/400 circle","deg","DEG","0.9",0.9,false],[false,"arc minute","'","'","plane angle",0.0002908882086657216,[0,0,0,1,0,0,0],"'","iso1000",false,null,null,1,false,false,0,"arcminutes; arcmin; arc minutes; arc mins","UCUM","Angle","Clinical","equal to 1/60 degree; used in optometry and opthamology (e.g. visual acuity tests)","deg/60","DEG/60","1",1,false],[false,"arc second","''","''","plane angle",0.00000484813681109536,[0,0,0,1,0,0,0],"''","iso1000",false,null,null,1,false,false,0,"arcseconds; arcsecs","UCUM","Angle","Clinical","equal to 1/60 arcminute = 1/3600 degree; used in optometry and opthamology (e.g. visual acuity tests)","'/60","'/60","1",1,false],[false,"Liters","l","L","volume",0.001,[3,0,0,0,0,0,0],"l","iso1000",true,null,null,1,false,false,0,"cubic decimeters; decimeters cubed; decimetres; dm3; dm^3; litres; liters, LT ","UCUM","Vol","Clinical","Because lower case \"l\" can be read as the number \"1\", though this is a valid UCUM units. UCUM strongly reccomends using \"L\"","dm3","DM3","1",1,false],[false,"Liters","L","L","volume",0.001,[3,0,0,0,0,0,0],"L","iso1000",true,null,null,1,false,false,0,"cubic decimeters; decimeters cubed; decimetres; dm3; dm^3; litres; liters, LT ","UCUM","Vol","Clinical","Because lower case \"l\" can be read as the number \"1\", though this is a valid UCUM units. UCUM strongly reccomends using \"L\"","l",null,"1",1,false],[false,"are","ar","AR","area",100,[2,0,0,0,0,0,0],"a","iso1000",true,null,null,1,false,false,0,"100 m2; 100 m^2; 100 square meter; meters squared; metres","UCUM","Area","Clinical","metric base unit for area defined as 100 m^2","m2","M2","100",100,false],[false,"minute","min","MIN","time",60,[0,1,0,0,0,0,0],"min","iso1000",false,null,null,1,false,false,0,"minutes","UCUM","Time","Clinical","","s","S","60",60,false],[false,"hour","h","HR","time",3600,[0,1,0,0,0,0,0],"h","iso1000",false,null,null,1,false,false,0,"hours; hrs; age","UCUM","Time","Clinical","","min","MIN","60",60,false],[false,"day","d","D","time",86400,[0,1,0,0,0,0,0],"d","iso1000",false,null,null,1,false,false,0,"days; age; dy; 24 hours; 24 hrs","UCUM","Time","Clinical","","h","HR","24",24,false],[false,"tropical year","a_t","ANN_T","time",31556925.216,[0,1,0,0,0,0,0],"at","iso1000",false,null,null,1,false,false,0,"solar years; a tropical; years","UCUM","Time","Clinical","has an average of 365.242181 days but is constantly changing.","d","D","365.24219",365.24219,false],[false,"mean Julian year","a_j","ANN_J","time",31557600,[0,1,0,0,0,0,0],"aj","iso1000",false,null,null,1,false,false,0,"mean Julian yr; a julian; years","UCUM","Time","Clinical","has an average of 365.25 days, and in everyday use, has been replaced by the Gregorian year. However, this unit is used in astronomy to calculate light year. ","d","D","365.25",365.25,false],[false,"mean Gregorian year","a_g","ANN_G","time",31556952,[0,1,0,0,0,0,0],"ag","iso1000",false,null,null,1,false,false,0,"mean Gregorian yr; a gregorian; years","UCUM","Time","Clinical","has an average of 365.2425 days and is the most internationally used civil calendar.","d","D","365.2425",365.2425,false],[false,"year","a","ANN","time",31557600,[0,1,0,0,0,0,0],"a","iso1000",false,null,null,1,false,false,0,"years; a; yr, yrs; annum","UCUM","Time","Clinical","","a_j","ANN_J","1",1,false],[false,"week","wk","WK","time",604800,[0,1,0,0,0,0,0],"wk","iso1000",false,null,null,1,false,false,0,"weeks; wks","UCUM","Time","Clinical","","d","D","7",7,false],[false,"synodal month","mo_s","MO_S","time",2551442.976,[0,1,0,0,0,0,0],"mos","iso1000",false,null,null,1,false,false,0,"Moon; synodic month; lunar month; mo-s; mo s; months; moons","UCUM","Time","Nonclinical","has an average of 29.53 days per month, unit used in astronomy","d","D","29.53059",29.53059,false],[false,"mean Julian month","mo_j","MO_J","time",2629800,[0,1,0,0,0,0,0],"moj","iso1000",false,null,null,1,false,false,0,"mo-julian; mo Julian; months","UCUM","Time","Clinical","has an average of 30.435 days per month","a_j/12","ANN_J/12","1",1,false],[false,"mean Gregorian month","mo_g","MO_G","time",2629746,[0,1,0,0,0,0,0],"mog","iso1000",false,null,null,1,false,false,0,"months; month-gregorian; mo-gregorian","UCUM","Time","Clinical","has an average 30.436875 days per month and is from the most internationally used civil calendar.","a_g/12","ANN_G/12","1",1,false],[false,"month","mo","MO","time",2629800,[0,1,0,0,0,0,0],"mo","iso1000",false,null,null,1,false,false,0,"months; duration","UCUM","Time","Clinical","based on Julian calendar which has an average of 30.435 days per month (this unit is used in astronomy but not in everyday life - see mo_g)","mo_j","MO_J","1",1,false],[false,"metric ton","t","TNE","mass",1000000,[0,0,1,0,0,0,0],"t","iso1000",true,null,null,1,false,false,0,"tonnes; megagrams; tons","UCUM","Mass","Nonclinical","equal to 1000 kg used in the US (recognized by NIST as metric ton), and internationally (recognized as tonne)","kg","KG","1e3",1000,false],[false,"bar","bar","BAR","pressure",100000000,[-1,-2,1,0,0,0,0],"bar","iso1000",true,null,null,1,false,false,0,"bars","UCUM","Pres","Nonclinical","unit of pressure equal to 10^5 Pascals, primarily used by meteorologists and in weather forecasting","Pa","PAL","1e5",100000,false],[false,"unified atomic mass unit","u","AMU","mass",1.6605402e-24,[0,0,1,0,0,0,0],"u","iso1000",true,null,null,1,false,false,0,"unified atomic mass units; amu; Dalton; Da","UCUM","Mass","Clinical","the mass of 1/12 of an unbound Carbon-12 atom nuclide equal to 1.6606x10^-27 kg ","g","G","1.6605402e-24",1.6605402e-24,false],[false,"astronomic unit","AU","ASU","length",149597870691,[1,0,0,0,0,0,0],"AU","iso1000",false,null,null,1,false,false,0,"AU; units","UCUM","Len","Clinical","unit of length used in astronomy for measuring distance in Solar system","Mm","MAM","149597.870691",149597.870691,false],[false,"parsec","pc","PRS","length",30856780000000000,[1,0,0,0,0,0,0],"pc","iso1000",true,null,null,1,false,false,0,"parsecs","UCUM","Len","Clinical","unit of length equal to 3.26 light years, nad used to measure large distances to objects outside our Solar System","m","M","3.085678e16",30856780000000000,false],[false,"velocity of light in a vacuum","[c]","[C]","velocity",299792458,[1,-1,0,0,0,0,0],"c","const",true,null,null,1,false,false,0,"speed of light","UCUM","Vel","Constant","equal to 299792458 m/s (approximately 3 x 10^8 m/s)","m/s","M/S","299792458",299792458,false],[false,"Planck constant","[h]","[H]","action",6.6260755e-31,[2,-1,1,0,0,0,0],"h","const",true,null,null,1,false,false,0,"Planck's constant","UCUM","","Constant","constant = 6.62607004 × 10-34 m2.kg/s; defined as quantum of action","J.s","J.S","6.6260755e-34",6.6260755e-34,false],[false,"Boltzmann constant","[k]","[K]","(unclassified)",1.380658e-20,[2,-2,1,0,-1,0,0],"k","const",true,null,null,1,false,false,0,"k; kB","UCUM","","Constant","physical constant relating energy at the individual particle level with temperature = 1.38064852 ×10^−23 J/K","J/K","J/K","1.380658e-23",1.380658e-23,false],[false,"permittivity of vacuum - electric","[eps_0]","[EPS_0]","electric permittivity",8.854187817000001e-15,[-3,2,-1,0,0,2,0],"ε0","const",true,null,null,1,false,false,0,"ε0; Electric Constant; vacuum permittivity; permittivity of free space ","UCUM","","Constant","approximately equal to 8.854 × 10^−12 F/m (farads per meter)","F/m","F/M","8.854187817e-12",8.854187817e-12,false],[false,"permeability of vacuum - magnetic","[mu_0]","[MU_0]","magnetic permeability",0.0012566370614359172,[1,0,1,0,0,-2,0],"μ0","const",true,null,null,1,false,false,0,"μ0; vacuum permeability; permeability of free space; magnetic constant","UCUM","","Constant","equal to 4π×10^−7 N/A2 (Newtons per square ampere) ≈ 1.2566×10^−6 H/m (Henry per meter)","N/A2","4.[PI].10*-7.N/A2","1",0.0000012566370614359173,false],[false,"elementary charge","[e]","[E]","electric charge",1.60217733e-19,[0,0,0,0,0,1,0],"e","const",true,null,null,1,false,false,0,"e; q; electric charges","UCUM","","Constant","the magnitude of the electric charge carried by a single electron or proton ≈ 1.60217×10^-19 Coulombs","C","C","1.60217733e-19",1.60217733e-19,false],[false,"electronvolt","eV","EV","energy",1.60217733e-16,[2,-2,1,0,0,0,0],"eV","iso1000",true,null,null,1,false,false,0,"Electron Volts; electronvolts","UCUM","Eng","Clinical","unit of kinetic energy = 1 V * 1.602×10^−19 C = 1.6×10−19 Joules","[e].V","[E].V","1",1,false],[false,"electron mass","[m_e]","[M_E]","mass",9.1093897e-28,[0,0,1,0,0,0,0],"me","const",true,null,null,1,false,false,0,"electron rest mass; me","UCUM","Mass","Constant","approximately equal to 9.10938356 × 10-31 kg; defined as the mass of a stationary electron","g","g","9.1093897e-28",9.1093897e-28,false],[false,"proton mass","[m_p]","[M_P]","mass",1.6726231e-24,[0,0,1,0,0,0,0],"mp","const",true,null,null,1,false,false,0,"mp; masses","UCUM","Mass","Constant","approximately equal to 1.672622×10−27 kg","g","g","1.6726231e-24",1.6726231e-24,false],[false,"Newtonian constant of gravitation","[G]","[GC]","(unclassified)",6.67259e-14,[3,-2,-1,0,0,0,0],"G","const",true,null,null,1,false,false,0,"G; gravitational constant; Newton's constant","UCUM","","Constant","gravitational constant = 6.674×10−11 N⋅m2/kg2","m3.kg-1.s-2","M3.KG-1.S-2","6.67259e-11",6.67259e-11,false],[false,"standard acceleration of free fall","[g]","[G]","acceleration",9.80665,[1,-2,0,0,0,0,0],"gn","const",true,null,null,1,false,false,0,"standard gravity; g; ɡ0; ɡn","UCUM","Accel","Constant","defined by standard = 9.80665 m/s2","m/s2","M/S2","980665e-5",9.80665,false],[false,"Torr","Torr","Torr","pressure",133322,[-1,-2,1,0,0,0,0],"Torr","const",false,null,null,1,false,false,0,"torrs","UCUM","Pres","Clinical","1 torr = 1 mmHg; unit used to measure blood pressure","Pa","PAL","133.322",133.322,false],[false,"standard atmosphere","atm","ATM","pressure",101325000,[-1,-2,1,0,0,0,0],"atm","const",false,null,null,1,false,false,0,"reference pressure; atmos; std atmosphere","UCUM","Pres","Clinical","defined as being precisely equal to 101,325 Pa","Pa","PAL","101325",101325,false],[false,"light-year","[ly]","[LY]","length",9460730472580800,[1,0,0,0,0,0,0],"l.y.","const",true,null,null,1,false,false,0,"light years; ly","UCUM","Len","Constant","unit of astronomal distance = 5.88×10^12 mi","[c].a_j","[C].ANN_J","1",1,false],[false,"gram-force","gf","GF","force",9.80665,[1,-2,1,0,0,0,0],"gf","const",true,null,null,1,false,false,0,"Newtons; gram forces","UCUM","Force","Clinical","May be specific to unit related to cardiac output","g.[g]","G.[G]","1",1,false],[false,"Kayser","Ky","KY","lineic number",100,[-1,0,0,0,0,0,0],"K","cgs",true,null,null,1,false,false,0,"wavenumbers; kaysers","UCUM","InvLen","Clinical","unit of wavelength equal to cm^-1","cm-1","CM-1","1",1,false],[false,"Gal","Gal","GL","acceleration",0.01,[1,-2,0,0,0,0,0],"Gal","cgs",true,null,null,1,false,false,0,"galileos; Gals","UCUM","Accel","Clinical","unit of acceleration used in gravimetry; equivalent to cm/s2 ","cm/s2","CM/S2","1",1,false],[false,"dyne","dyn","DYN","force",0.01,[1,-2,1,0,0,0,0],"dyn","cgs",true,null,null,1,false,false,0,"dynes","UCUM","Force","Clinical","unit of force equal to 10^-5 Newtons","g.cm/s2","G.CM/S2","1",1,false],[false,"erg","erg","ERG","energy",0.0001,[2,-2,1,0,0,0,0],"erg","cgs",true,null,null,1,false,false,0,"10^-7 Joules, 10-7 Joules; 100 nJ; 100 nanoJoules; 1 dyne cm; 1 g.cm2/s2","UCUM","Eng","Clinical","unit of energy = 1 dyne centimeter = 10^-7 Joules","dyn.cm","DYN.CM","1",1,false],[false,"Poise","P","P","dynamic viscosity",100,[-1,-1,1,0,0,0,0],"P","cgs",true,null,null,1,false,false,0,"dynamic viscosity; poises","UCUM","Visc","Clinical","unit of dynamic viscosity where 1 Poise = 1/10 Pascal second","dyn.s/cm2","DYN.S/CM2","1",1,false],[false,"Biot","Bi","BI","electric current",10,[0,-1,0,0,0,1,0],"Bi","cgs",true,null,null,1,false,false,0,"Bi; abamperes; abA","UCUM","ElpotRat","Clinical","equal to 10 amperes","A","A","10",10,false],[false,"Stokes","St","ST","kinematic viscosity",0.0001,[2,-1,0,0,0,0,0],"St","cgs",true,null,null,1,false,false,0,"kinematic viscosity","UCUM","Visc","Clinical","unit of kimematic viscosity with units cm2/s","cm2/s","CM2/S","1",1,false],[false,"Maxwell","Mx","MX","flux of magnetic induction",0.00001,[2,-1,1,0,0,-1,0],"Mx","cgs",true,null,null,1,false,false,0,"magnetix flux; Maxwells","UCUM","","Clinical","unit of magnetic flux","Wb","WB","1e-8",1e-8,false],[false,"Gauss","G","GS","magnetic flux density",0.1,[0,-1,1,0,0,-1,0],"Gs","cgs",true,null,null,1,false,false,0,"magnetic fields; magnetic flux density; induction; B","UCUM","magnetic","Clinical","CGS unit of magnetic flux density, known as magnetic field B; defined as one maxwell unit per square centimeter (see Oersted for CGS unit for H field)","T","T","1e-4",0.0001,false],[false,"Oersted","Oe","OE","magnetic field intensity",79.57747154594767,[-1,-1,0,0,0,1,0],"Oe","cgs",true,null,null,1,false,false,0,"H magnetic B field; Oersteds","UCUM","","Clinical","CGS unit of the auxiliary magnetic field H defined as 1 dyne per unit pole = 1000/4π amperes per meter (see Gauss for CGS unit for B field)","A/m","/[PI].A/M","250",79.57747154594767,false],[false,"Gilbert","Gb","GB","magnetic tension",0.7957747154594768,[0,-1,0,0,0,1,0],"Gb","cgs",true,null,null,1,false,false,0,"Gi; magnetomotive force; Gilberts","UCUM","","Clinical","unit of magnetomotive force (magnetic potential)","Oe.cm","OE.CM","1",1,false],[false,"stilb","sb","SB","lum. intensity density",10000,[-2,0,0,0,0,0,1],"sb","cgs",true,null,null,1,false,false,0,"stilbs","UCUM","","Obsolete","unit of luminance; equal to and replaced by unit candela per square centimeter (cd/cm2)","cd/cm2","CD/CM2","1",1,false],[false,"Lambert","Lmb","LMB","brightness",3183.098861837907,[-2,0,0,0,0,0,1],"L","cgs",true,null,null,1,false,false,0,"luminance; lamberts","UCUM","","Clinical","unit of luminance defined as 1 lambert = 1/ π candela per square meter","cd/cm2/[pi]","CD/CM2/[PI]","1",1,false],[false,"phot","ph","PHT","illuminance",0.0001,[-2,0,0,2,0,0,1],"ph","cgs",true,null,null,1,false,false,0,"phots","UCUM","","Clinical","CGS photometric unit of illuminance, or luminous flux through an area equal to 10000 lumens per square meter = 10000 lux","lx","LX","1e-4",0.0001,false],[false,"Curie","Ci","CI","radioactivity",37000000000,[0,-1,0,0,0,0,0],"Ci","cgs",true,null,null,1,false,false,0,"curies","UCUM","","Obsolete","unit for measuring atomic disintegration rate; replaced by the Bequerel (Bq) unit","Bq","BQ","37e9",37000000000,false],[false,"Roentgen","R","ROE","ion dose",2.58e-7,[0,0,-1,0,0,1,0],"R","cgs",true,null,null,1,false,false,0,"röntgen; Roentgens","UCUM","","Clinical","unit of exposure of X-rays and gamma rays in air; unit used primarily in the US but strongly discouraged by NIST","C/kg","C/KG","2.58e-4",0.000258,false],[false,"radiation absorbed dose","RAD","[RAD]","energy dose",0.01,[2,-2,0,0,0,0,0],"RAD","cgs",true,null,null,1,false,false,0,"doses","UCUM","","Clinical","unit of radiation absorbed dose used primarily in the US with base units 100 ergs per gram of material. Also see the SI unit Gray (Gy).","erg/g","ERG/G","100",100,false],[false,"radiation equivalent man","REM","[REM]","dose equivalent",0.01,[2,-2,0,0,0,0,0],"REM","cgs",true,null,null,1,false,false,0,"Roentgen Equivalent in Man; rems; dose equivalents","UCUM","","Clinical","unit of equivalent dose which measures the effect of radiation on humans equal to 0.01 sievert. Used primarily in the US. Also see SI unit Sievert (Sv)","RAD","[RAD]","1",1,false],[false,"inch","[in_i]","[IN_I]","length",0.025400000000000002,[1,0,0,0,0,0,0],"in","intcust",false,null,null,1,false,false,0,"inches; in; international inch; body height","UCUM","Len","Clinical","standard unit for inch in the US and internationally","cm","CM","254e-2",2.54,false],[false,"foot","[ft_i]","[FT_I]","length",0.3048,[1,0,0,0,0,0,0],"ft","intcust",false,null,null,1,false,false,0,"ft; fts; foot; international foot; feet; international feet; height","UCUM","Len","Clinical","unit used in the US and internationally","[in_i]","[IN_I]","12",12,false],[false,"yard","[yd_i]","[YD_I]","length",0.9144000000000001,[1,0,0,0,0,0,0],"yd","intcust",false,null,null,1,false,false,0,"international yards; yds; distance","UCUM","Len","Clinical","standard unit used in the US and internationally","[ft_i]","[FT_I]","3",3,false],[false,"mile","[mi_i]","[MI_I]","length",1609.344,[1,0,0,0,0,0,0],"mi","intcust",false,null,null,1,false,false,0,"international miles; mi I; statute mile","UCUM","Len","Clinical","standard unit used in the US and internationally","[ft_i]","[FT_I]","5280",5280,false],[false,"fathom","[fth_i]","[FTH_I]","depth of water",1.8288000000000002,[1,0,0,0,0,0,0],"fth","intcust",false,null,null,1,false,false,0,"international fathoms","UCUM","Len","Nonclinical","unit used in the US and internationally to measure depth of water; same length as the US fathom","[ft_i]","[FT_I]","6",6,false],[false,"nautical mile","[nmi_i]","[NMI_I]","length",1852,[1,0,0,0,0,0,0],"n.mi","intcust",false,null,null,1,false,false,0,"nautical mile; nautical miles; international nautical mile; international nautical miles; nm; n.m.; nmi","UCUM","Len","Nonclinical","standard unit used in the US and internationally","m","M","1852",1852,false],[false,"knot","[kn_i]","[KN_I]","velocity",0.5144444444444445,[1,-1,0,0,0,0,0],"knot","intcust",false,null,null,1,false,false,0,"kn; kt; international knots","UCUM","Vel","Nonclinical","defined as equal to one nautical mile (1.852 km) per hour","[nmi_i]/h","[NMI_I]/H","1",1,false],[false,"square inch","[sin_i]","[SIN_I]","area",0.0006451600000000001,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"in2; in^2; inches squared; sq inch; inches squared; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[in_i]2","[IN_I]2","1",1,false],[false,"square foot","[sft_i]","[SFT_I]","area",0.09290304,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"ft2; ft^2; ft squared; sq ft; feet; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[ft_i]2","[FT_I]2","1",1,false],[false,"square yard","[syd_i]","[SYD_I]","area",0.8361273600000002,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"yd2; yd^2; sq. yds; yards squared; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[yd_i]2","[YD_I]2","1",1,false],[false,"cubic inch","[cin_i]","[CIN_I]","volume",0.000016387064000000003,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"in3; in^3; in*3; inches^3; inches*3; cu. in; cu in; cubic inches; inches cubed; cin","UCUM","Vol","Clinical","standard unit used in the US and internationally","[in_i]3","[IN_I]3","1",1,false],[false,"cubic foot","[cft_i]","[CFT_I]","volume",0.028316846592000004,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"ft3; ft^3; ft*3; cu. ft; cubic feet; cubed; [ft_i]3; international","UCUM","Vol","Clinical","","[ft_i]3","[FT_I]3","1",1,false],[false,"cubic yard","[cyd_i]","[CYD_I]","volume",0.7645548579840002,[3,0,0,0,0,0,0],"cu.yd","intcust",false,null,null,1,false,false,0,"cubic yards; cubic yds; cu yards; CYs; yards^3; yd^3; yds^3; yd3; yds3","UCUM","Vol","Nonclinical","standard unit used in the US and internationally","[yd_i]3","[YD_I]3","1",1,false],[false,"board foot","[bf_i]","[BF_I]","volume",0.002359737216,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"BDFT; FBM; BF; board feet; international","UCUM","Vol","Nonclinical","unit of volume used to measure lumber","[in_i]3","[IN_I]3","144",144,false],[false,"cord","[cr_i]","[CR_I]","volume",3.6245563637760005,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"crd I; international cords","UCUM","Vol","Nonclinical","unit of measure of dry volume used to measure firewood equal 128 ft3","[ft_i]3","[FT_I]3","128",128,false],[false,"mil","[mil_i]","[MIL_I]","length",0.000025400000000000004,[1,0,0,0,0,0,0],"mil","intcust",false,null,null,1,false,false,0,"thou, thousandth; mils; international","UCUM","Len","Clinical","equal to 0.001 international inch","[in_i]","[IN_I]","1e-3",0.001,false],[false,"circular mil","[cml_i]","[CML_I]","area",5.067074790974979e-10,[2,0,0,0,0,0,0],"circ.mil","intcust",false,null,null,1,false,false,0,"circular mils; cml I; international","UCUM","Area","Clinical","","[pi]/4.[mil_i]2","[PI]/4.[MIL_I]2","1",1,false],[false,"hand","[hd_i]","[HD_I]","height of horses",0.10160000000000001,[1,0,0,0,0,0,0],"hd","intcust",false,null,null,1,false,false,0,"hands; international","UCUM","Len","Nonclinical","used to measure horse height","[in_i]","[IN_I]","4",4,false],[false,"foot - US","[ft_us]","[FT_US]","length",0.3048006096012192,[1,0,0,0,0,0,0],"ftus","us-lengths",false,null,null,1,false,false,0,"US foot; foot US; us ft; ft us; height; visual distance; feet","UCUM","Len","Obsolete","Better to use [ft_i] which refers to the length used worldwide, including in the US; [ft_us] may be confused with land survey units. ","m/3937","M/3937","1200",1200,false],[false,"yard - US","[yd_us]","[YD_US]","length",0.9144018288036575,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US yards; us yds; distance","UCUM","Len; Nrat","Obsolete","Better to use [yd_i] which refers to the length used worldwide, including in the US; [yd_us] refers to unit used in land surveys in the US","[ft_us]","[FT_US]","3",3,false],[false,"inch - US","[in_us]","[IN_US]","length",0.0254000508001016,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US inches; in us; us in; inch US","UCUM","Len","Obsolete","Better to use [in_i] which refers to the length used worldwide, including in the US","[ft_us]/12","[FT_US]/12","1",1,false],[false,"rod - US","[rd_us]","[RD_US]","length",5.029210058420117,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US rod; US rods; rd US; US rd","UCUM","Len","Obsolete","","[ft_us]","[FT_US]","16.5",16.5,false],[false,"Gunter's chain - US","[ch_us]","[CH_US]","length",20.116840233680467,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"surveyor's chain; Surveyor's chain USA; Gunter’s measurement; surveyor’s measurement; Gunter's Chain USA","UCUM","Len","Obsolete","historical unit used for land survey used only in the US","[rd_us]","[RD_US]","4",4,false],[false,"link for Gunter's chain - US","[lk_us]","[LK_US]","length",0.20116840233680466,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Links for Gunter's Chain USA","UCUM","Len","Obsolete","","[ch_us]/100","[CH_US]/100","1",1,false],[false,"Ramden's chain - US","[rch_us]","[RCH_US]","length",30.480060960121918,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Ramsden's chain; engineer's chains","UCUM","Len","Obsolete","distance measuring device used for land survey","[ft_us]","[FT_US]","100",100,false],[false,"link for Ramden's chain - US","[rlk_us]","[RLK_US]","length",0.3048006096012192,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"links for Ramsden's chain","UCUM","Len","Obsolete","","[rch_us]/100","[RCH_US]/100","1",1,false],[false,"fathom - US","[fth_us]","[FTH_US]","length",1.828803657607315,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US fathoms; fathom USA; fth us","UCUM","Len","Obsolete","same length as the international fathom - better to use international fathom ([fth_i])","[ft_us]","[FT_US]","6",6,false],[false,"furlong - US","[fur_us]","[FUR_US]","length",201.16840233680466,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US furlongs; fur us","UCUM","Len","Nonclinical","distance unit in horse racing","[rd_us]","[RD_US]","40",40,false],[false,"mile - US","[mi_us]","[MI_US]","length",1609.3472186944373,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"U.S. Survey Miles; US statute miles; survey mi; US mi; distance","UCUM","Len","Nonclinical","Better to use [mi_i] which refers to the length used worldwide, including in the US","[fur_us]","[FUR_US]","8",8,false],[false,"acre - US","[acr_us]","[ACR_US]","area",4046.872609874252,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Acre USA Survey; Acre USA; survey acres","UCUM","Area","Nonclinical","an older unit based on pre 1959 US statute lengths that is still sometimes used in the US only for land survey purposes. ","[rd_us]2","[RD_US]2","160",160,false],[false,"square rod - US","[srd_us]","[SRD_US]","area",25.292953811714074,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"rod2; rod^2; sq. rod; rods squared","UCUM","Area","Nonclinical","Used only in the US to measure land area, based on US statute land survey length units","[rd_us]2","[RD_US]2","1",1,false],[false,"square mile - US","[smi_us]","[SMI_US]","area",2589998.470319521,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"mi2; mi^2; sq mi; miles squared","UCUM","Area","Nonclinical","historical unit used only in the US for land survey purposes (based on the US survey mile), not the internationally recognized [mi_i]","[mi_us]2","[MI_US]2","1",1,false],[false,"section","[sct]","[SCT]","area",2589998.470319521,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"sct; sections","UCUM","Area","Nonclinical","tract of land approximately equal to 1 mile square containing 640 acres","[mi_us]2","[MI_US]2","1",1,false],[false,"township","[twp]","[TWP]","area",93239944.93150276,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"twp; townships","UCUM","Area","Nonclinical","land measurement equal to 6 mile square","[sct]","[SCT]","36",36,false],[false,"mil - US","[mil_us]","[MIL_US]","length",0.0000254000508001016,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"thou, thousandth; mils","UCUM","Len","Obsolete","better to use [mil_i] which is based on the internationally recognized inch","[in_us]","[IN_US]","1e-3",0.001,false],[false,"inch - British","[in_br]","[IN_BR]","length",0.025399980000000003,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"imperial inches; imp in; br in; british inches","UCUM","Len","Obsolete","","cm","CM","2.539998",2.539998,false],[false,"foot - British","[ft_br]","[FT_BR]","length",0.30479976000000003,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British Foot; Imperial Foot; feet; imp fts; br fts","UCUM","Len","Obsolete","","[in_br]","[IN_BR]","12",12,false],[false,"rod - British","[rd_br]","[RD_BR]","length",5.02919604,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British rods; br rd","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","16.5",16.5,false],[false,"Gunter's chain - British","[ch_br]","[CH_BR]","length",20.11678416,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Gunter's Chain British; Gunters Chain British; Surveyor's Chain British","UCUM","Len","Obsolete","historical unit used for land survey used only in Great Britain","[rd_br]","[RD_BR]","4",4,false],[false,"link for Gunter's chain - British","[lk_br]","[LK_BR]","length",0.2011678416,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Links for Gunter's Chain British","UCUM","Len","Obsolete","","[ch_br]/100","[CH_BR]/100","1",1,false],[false,"fathom - British","[fth_br]","[FTH_BR]","length",1.82879856,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British fathoms; imperial fathoms; br fth; imp fth","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","6",6,false],[false,"pace - British","[pc_br]","[PC_BR]","length",0.7619994000000001,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British paces; br pc","UCUM","Len","Nonclinical","traditional unit of length equal to 152.4 centimeters, or 1.52 meter. ","[ft_br]","[FT_BR]","2.5",2.5,false],[false,"yard - British","[yd_br]","[YD_BR]","length",0.91439928,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British yards; Br yds; distance","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","3",3,false],[false,"mile - British","[mi_br]","[MI_BR]","length",1609.3427328000002,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"imperial miles; British miles; English statute miles; imp mi, br mi","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","5280",5280,false],[false,"nautical mile - British","[nmi_br]","[NMI_BR]","length",1853.1825408000002,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British nautical miles; Imperial nautical miles; Admiralty miles; n.m. br; imp nm","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","6080",6080,false],[false,"knot - British","[kn_br]","[KN_BR]","velocity",0.5147729280000001,[1,-1,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British knots; kn br; kt","UCUM","Vel","Obsolete","based on obsolete British nautical mile ","[nmi_br]/h","[NMI_BR]/H","1",1,false],[false,"acre","[acr_br]","[ACR_BR]","area",4046.850049400269,[2,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Imperial acres; British; a; ac; ar; acr","UCUM","Area","Nonclinical","the standard unit for acre used in the US and internationally","[yd_br]2","[YD_BR]2","4840",4840,false],[false,"gallon - US","[gal_us]","[GAL_US]","fluid volume",0.0037854117840000006,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US gallons; US liquid gallon; gal us; Queen Anne's wine gallon","UCUM","Vol","Nonclinical","only gallon unit used in the US; [gal_us] is only used in some other countries in South American and Africa to measure gasoline volume","[in_i]3","[IN_I]3","231",231,false],[false,"barrel - US","[bbl_us]","[BBL_US]","fluid volume",0.158987294928,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"bbl","UCUM","Vol","Nonclinical","[bbl_us] is the standard unit for oil barrel, which is a unit only used in the US to measure the volume oil. ","[gal_us]","[GAL_US]","42",42,false],[false,"quart - US","[qt_us]","[QT_US]","fluid volume",0.0009463529460000001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US quarts; us qts","UCUM","Vol","Clinical","Used only in the US","[gal_us]/4","[GAL_US]/4","1",1,false],[false,"pint - US","[pt_us]","[PT_US]","fluid volume",0.00047317647300000007,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US pints; pint US; liquid pint; pt us; us pt","UCUM","Vol","Clinical","Used only in the US","[qt_us]/2","[QT_US]/2","1",1,false],[false,"gill - US","[gil_us]","[GIL_US]","fluid volume",0.00011829411825000002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US gills; gil us","UCUM","Vol","Nonclinical","only used in the context of alcohol volume in the US","[pt_us]/4","[PT_US]/4","1",1,false],[false,"fluid ounce - US","[foz_us]","[FOZ_US]","fluid volume",0.000029573529562500005,[3,0,0,0,0,0,0],"oz fl","us-volumes",false,null,null,1,false,false,0,"US fluid ounces; fl ozs; FO; fl. oz.; foz us","UCUM","Vol","Clinical","unit used only in the US","[gil_us]/4","[GIL_US]/4","1",1,false],[false,"fluid dram - US","[fdr_us]","[FDR_US]","fluid volume",0.0000036966911953125006,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US fluid drams; fdr us","UCUM","Vol","Nonclinical","equal to 1/8 US fluid ounce = 3.69 mL; used informally to mean small amount of liquor, especially Scotch whiskey","[foz_us]/8","[FOZ_US]/8","1",1,false],[false,"minim - US","[min_us]","[MIN_US]","fluid volume",6.1611519921875e-8,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"min US; US min; ♏ US","UCUM","Vol","Obsolete","","[fdr_us]/60","[FDR_US]/60","1",1,false],[false,"cord - US","[crd_us]","[CRD_US]","fluid volume",3.6245563637760005,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US cord; US cords; crd us; us crd","UCUM","Vol","Nonclinical","unit of measure of dry volume used to measure firewood equal 128 ft3 (the same as international cord [cr_i])","[ft_i]3","[FT_I]3","128",128,false],[false,"bushel - US","[bu_us]","[BU_US]","dry volume",0.03523907016688001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US bushels; US bsh; US bu","UCUM","Vol","Obsolete","Historical unit of dry volume that is rarely used today","[in_i]3","[IN_I]3","2150.42",2150.42,false],[false,"gallon - historical","[gal_wi]","[GAL_WI]","dry volume",0.004404883770860001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"Corn Gallon British; Dry Gallon US; Gallons Historical; Grain Gallon British; Winchester Corn Gallon; historical winchester gallons; wi gal","UCUM","Vol","Obsolete","historical unit of dry volume no longer used","[bu_us]/8","[BU_US]/8","1",1,false],[false,"peck - US","[pk_us]","[PK_US]","dry volume",0.008809767541720002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US pecks; US pk","UCUM","Vol","Nonclinical","unit of dry volume rarely used today (can be used to measure volume of apples)","[bu_us]/4","[BU_US]/4","1",1,false],[false,"dry quart - US","[dqt_us]","[DQT_US]","dry volume",0.0011012209427150002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"dry quarts; dry quart US; US dry quart; dry qt; us dry qt; dqt; dqt us","UCUM","Vol","Nonclinical","historical unit of dry volume only in the US, but is rarely used today","[pk_us]/8","[PK_US]/8","1",1,false],[false,"dry pint - US","[dpt_us]","[DPT_US]","dry volume",0.0005506104713575001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"dry pints; dry pint US; US dry pint; dry pt; dpt; dpt us","UCUM","Vol","Nonclinical","historical unit of dry volume only in the US, but is rarely used today","[dqt_us]/2","[DQT_US]/2","1",1,false],[false,"tablespoon - US","[tbs_us]","[TBS_US]","volume",0.000014786764781250002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"Tbs; tbsp; tbs us; US tablespoons","UCUM","Vol","Clinical","unit defined as 0.5 US fluid ounces or 3 teaspoons - used only in the US. See [tbs_m] for the unit used internationally and in the US for nutrional labelling. ","[foz_us]/2","[FOZ_US]/2","1",1,false],[false,"teaspoon - US","[tsp_us]","[TSP_US]","volume",0.0000049289215937500005,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"tsp; t; US teaspoons","UCUM","Vol","Nonclinical","unit defined as 1/6 US fluid ounces - used only in the US. See [tsp_m] for the unit used internationally and in the US for nutrional labelling. ","[tbs_us]/3","[TBS_US]/3","1",1,false],[false,"cup - US customary","[cup_us]","[CUP_US]","volume",0.00023658823650000004,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"cup us; us cups","UCUM","Vol","Nonclinical","Unit defined as 1/2 US pint or 16 US tablespoons ≈ 236.59 mL, which is not the standard unit defined by the FDA of 240 mL - see [cup_m] (metric cup)","[tbs_us]","[TBS_US]","16",16,false],[false,"fluid ounce - metric","[foz_m]","[FOZ_M]","fluid volume",0.000029999999999999997,[3,0,0,0,0,0,0],"oz fl","us-volumes",false,null,null,1,false,false,0,"metric fluid ounces; fozs m; fl ozs m","UCUM","Vol","Clinical","unit used only in the US for nutritional labelling, as set by the FDA","mL","ML","30",30,false],[false,"cup - US legal","[cup_m]","[CUP_M]","volume",0.00023999999999999998,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"cup m; metric cups","UCUM","Vol","Clinical","standard unit equal to 240 mL used in the US for nutritional labelling, as defined by the FDA. Note that this is different from the US customary cup (236.59 mL) and the metric cup used in Commonwealth nations (250 mL).","mL","ML","240",240,false],[false,"teaspoon - metric","[tsp_m]","[TSP_M]","volume",0.0000049999999999999996,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"tsp; t; metric teaspoons","UCUM","Vol","Clinical","standard unit used in the US and internationally","mL","mL","5",5,false],[false,"tablespoon - metric","[tbs_m]","[TBS_M]","volume",0.000014999999999999999,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"metric tablespoons; Tbs; tbsp; T; tbs m","UCUM","Vol","Clinical","standard unit used in the US and internationally","mL","mL","15",15,false],[false,"gallon- British","[gal_br]","[GAL_BR]","volume",0.004546090000000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial gallons, UK gallons; British gallons; br gal; imp gal","UCUM","Vol","Nonclinical","Used only in Great Britain and other Commonwealth countries","l","L","4.54609",4.54609,false],[false,"peck - British","[pk_br]","[PK_BR]","volume",0.009092180000000002,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial pecks; British pecks; br pk; imp pk","UCUM","Vol","Nonclinical","unit of dry volume rarely used today (can be used to measure volume of apples)","[gal_br]","[GAL_BR]","2",2,false],[false,"bushel - British","[bu_br]","[BU_BR]","volume",0.03636872000000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British bushels; imperial; br bsh; br bu; imp","UCUM","Vol","Obsolete","Historical unit of dry volume that is rarely used today","[pk_br]","[PK_BR]","4",4,false],[false,"quart - British","[qt_br]","[QT_BR]","volume",0.0011365225000000002,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British quarts; imperial quarts; br qts","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[gal_br]/4","[GAL_BR]/4","1",1,false],[false,"pint - British","[pt_br]","[PT_BR]","volume",0.0005682612500000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British pints; imperial pints; pt br; br pt; imp pt; pt imp","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[qt_br]/2","[QT_BR]/2","1",1,false],[false,"gill - British","[gil_br]","[GIL_BR]","volume",0.00014206531250000003,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial gills; British gills; imp gill, br gill","UCUM","Vol","Nonclinical","only used in the context of alcohol volume in Great Britain","[pt_br]/4","[PT_BR]/4","1",1,false],[false,"fluid ounce - British","[foz_br]","[FOZ_BR]","volume",0.000028413062500000005,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British fluid ounces; Imperial fluid ounces; br fozs; imp fozs; br fl ozs","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[gil_br]/5","[GIL_BR]/5","1",1,false],[false,"fluid dram - British","[fdr_br]","[FDR_BR]","volume",0.0000035516328125000006,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British fluid drams; fdr br","UCUM","Vol","Nonclinical","equal to 1/8 Imperial fluid ounce = 3.55 mL; used informally to mean small amount of liquor, especially Scotch whiskey","[foz_br]/8","[FOZ_BR]/8","1",1,false],[false,"minim - British","[min_br]","[MIN_BR]","volume",5.919388020833334e-8,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"min br; br min; ♏ br","UCUM","Vol","Obsolete","","[fdr_br]/60","[FDR_BR]/60","1",1,false],[false,"grain","[gr]","[GR]","mass",0.06479891,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"gr; grains","UCUM","Mass","Nonclinical","an apothecary measure of mass rarely used today","mg","MG","64.79891",64.79891,false],[false,"pound","[lb_av]","[LB_AV]","mass",453.59237,[0,0,1,0,0,0,0],"lb","avoirdupois",false,null,null,1,false,false,0,"avoirdupois pounds, international pounds; av lbs; pounds","UCUM","Mass","Clinical","standard unit used in the US and internationally","[gr]","[GR]","7000",7000,false],[false,"pound force - US","[lbf_av]","[LBF_AV]","force",4448.2216152605,[1,-2,1,0,0,0,0],"lbf","const",false,null,null,1,false,false,0,"lbfs; US lbf; US pound forces","UCUM","Force","Clinical","only rarely needed in health care - see [lb_av] which is the more common unit to express weight","[lb_av].[g]","[LB_AV].[G]","1",1,false],[false,"ounce","[oz_av]","[OZ_AV]","mass",28.349523125,[0,0,1,0,0,0,0],"oz","avoirdupois",false,null,null,1,false,false,0,"ounces; international ounces; avoirdupois ounces; av ozs","UCUM","Mass","Clinical","standard unit used in the US and internationally","[lb_av]/16","[LB_AV]/16","1",1,false],[false,"Dram mass unit","[dr_av]","[DR_AV]","mass",1.7718451953125,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"Dram; drams avoirdupois; avoidupois dram; international dram","UCUM","Mass","Clinical","unit from the avoirdupois system, which is used in the US and internationally","[oz_av]/16","[OZ_AV]/16","1",1,false],[false,"short hundredweight","[scwt_av]","[SCWT_AV]","mass",45359.237,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"hundredweights; s cwt; scwt; avoirdupois","UCUM","Mass","Nonclinical","Used only in the US to equal 100 pounds","[lb_av]","[LB_AV]","100",100,false],[false,"long hundredweight","[lcwt_av]","[LCWT_AV]","mass",50802.345440000005,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"imperial hundredweights; imp cwt; lcwt; avoirdupois","UCUM","Mass","Obsolete","","[lb_av]","[LB_AV]","112",112,false],[false,"short ton - US","[ston_av]","[STON_AV]","mass",907184.74,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"ton; US tons; avoirdupois tons","UCUM","Mass","Clinical","Used only in the US","[scwt_av]","[SCWT_AV]","20",20,false],[false,"long ton - British","[lton_av]","[LTON_AV]","mass",1016046.9088000001,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"imperial tons; weight tons; British long tons; long ton avoirdupois","UCUM","Mass","Nonclinical","Used only in Great Britain and other Commonwealth countries","[lcwt_av]","[LCWT_AV]","20",20,false],[false,"stone - British","[stone_av]","[STONE_AV]","mass",6350.293180000001,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"British stones; avoirdupois","UCUM","Mass","Nonclinical","Used primarily in the UK and Ireland to measure body weight","[lb_av]","[LB_AV]","14",14,false],[false,"pennyweight - troy","[pwt_tr]","[PWT_TR]","mass",1.5551738400000001,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"dwt; denarius weights","UCUM","Mass","Obsolete","historical unit used to measure mass and cost of precious metals","[gr]","[GR]","24",24,false],[false,"ounce - troy","[oz_tr]","[OZ_TR]","mass",31.103476800000003,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"troy ounces; tr ozs","UCUM","Mass","Nonclinical","unit of mass for precious metals and gemstones only","[pwt_tr]","[PWT_TR]","20",20,false],[false,"pound - troy","[lb_tr]","[LB_TR]","mass",373.2417216,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"troy pounds; tr lbs","UCUM","Mass","Nonclinical","only used for weighing precious metals","[oz_tr]","[OZ_TR]","12",12,false],[false,"scruple","[sc_ap]","[SC_AP]","mass",1.2959782,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"scruples; sc ap","UCUM","Mass","Obsolete","","[gr]","[GR]","20",20,false],[false,"dram - apothecary","[dr_ap]","[DR_AP]","mass",3.8879346,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"ʒ; drachm; apothecaries drams; dr ap; dram ap","UCUM","Mass","Nonclinical","unit still used in the US occasionally to measure amount of drugs in pharmacies","[sc_ap]","[SC_AP]","3",3,false],[false,"ounce - apothecary","[oz_ap]","[OZ_AP]","mass",31.1034768,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"apothecary ounces; oz ap; ap ozs; ozs ap","UCUM","Mass","Obsolete","","[dr_ap]","[DR_AP]","8",8,false],[false,"pound - apothecary","[lb_ap]","[LB_AP]","mass",373.2417216,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"apothecary pounds; apothecaries pounds; ap lb; lb ap; ap lbs; lbs ap","UCUM","Mass","Obsolete","","[oz_ap]","[OZ_AP]","12",12,false],[false,"ounce - metric","[oz_m]","[OZ_M]","mass",28,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"metric ounces; m ozs","UCUM","Mass","Clinical","see [oz_av] (the avoirdupois ounce) for the standard ounce used internationally; [oz_m] is equal to 28 grams and is based on the apothecaries' system of mass units which is used in some US pharmacies. ","g","g","28",28,false],[false,"line","[lne]","[LNE]","length",0.002116666666666667,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"British lines; br L; L; l","UCUM","Len","Obsolete","","[in_i]/12","[IN_I]/12","1",1,false],[false,"point (typography)","[pnt]","[PNT]","length",0.0003527777777777778,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"DTP points; desktop publishing point; pt; pnt","UCUM","Len","Nonclinical","typography unit for typesetter's length","[lne]/6","[LNE]/6","1",1,false],[false,"pica (typography)","[pca]","[PCA]","length",0.004233333333333334,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"picas","UCUM","Len","Nonclinical","typography unit for typesetter's length","[pnt]","[PNT]","12",12,false],[false,"Printer's point (typography)","[pnt_pr]","[PNT_PR]","length",0.00035145980000000004,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pnt pr","UCUM","Len","Nonclinical","typography unit for typesetter's length","[in_i]","[IN_I]","0.013837",0.013837,false],[false,"Printer's pica (typography)","[pca_pr]","[PCA_PR]","length",0.004217517600000001,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pca pr; Printer's picas","UCUM","Len","Nonclinical","typography unit for typesetter's length","[pnt_pr]","[PNT_PR]","12",12,false],[false,"pied","[pied]","[PIED]","length",0.3248,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pieds du roi; Paris foot; royal; French; feet","UCUM","Len","Obsolete","","cm","CM","32.48",32.48,false],[false,"pouce","[pouce]","[POUCE]","length",0.027066666666666666,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"historical French inches; French royal inches","UCUM","Len","Obsolete","","[pied]/12","[PIED]/12","1",1,false],[false,"ligne","[ligne]","[LIGNE]","length",0.0022555555555555554,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Paris lines; lignes","UCUM","Len","Obsolete","","[pouce]/12","[POUCE]/12","1",1,false],[false,"didot","[didot]","[DIDOT]","length",0.0003759259259259259,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Didot point; dd; Didots Point; didots; points","UCUM","Len","Obsolete","typography unit for typesetter's length","[ligne]/6","[LIGNE]/6","1",1,false],[false,"cicero","[cicero]","[CICERO]","length",0.004511111111111111,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Didot's pica; ciceros; picas","UCUM","Len","Obsolete","typography unit for typesetter's length","[didot]","[DIDOT]","12",12,false],[false,"degrees Fahrenheit","[degF]","[DEGF]","temperature",0.5555555555555556,[0,0,0,0,1,0,0],"°F","heat",false,null,"degF",1,true,false,0,"°F; deg F","UCUM","Temp","Clinical","","K",null,null,0.5555555555555556,false],[false,"degrees Rankine","[degR]","[degR]","temperature",0.5555555555555556,[0,0,0,0,1,0,0],"°R","heat",false,null,null,1,false,false,0,"°R; °Ra; Rankine","UCUM","Temp","Obsolete","Replaced by Kelvin","K/9","K/9","5",5,false],[false,"degrees Réaumur","[degRe]","[degRe]","temperature",1.25,[0,0,0,0,1,0,0],"°Ré","heat",false,null,"degRe",1,true,false,0,"°Ré, °Re, °r; Réaumur; degree Reaumur; Reaumur","UCUM","Temp","Obsolete","replaced by Celsius","K",null,null,1.25,false],[false,"calorie at 15°C","cal_[15]","CAL_[15]","energy",4185.8,[2,-2,1,0,0,0,0],"cal15°C","heat",true,null,null,1,false,false,0,"calorie 15 C; cals 15 C; calories at 15 C","UCUM","Enrg","Nonclinical","equal to 4.1855 joules; calorie most often used in engineering","J","J","4.18580",4.1858,false],[false,"calorie at 20°C","cal_[20]","CAL_[20]","energy",4181.9,[2,-2,1,0,0,0,0],"cal20°C","heat",true,null,null,1,false,false,0,"calorie 20 C; cal 20 C; calories at 20 C","UCUM","Enrg","Clinical","equal to 4.18190 joules. ","J","J","4.18190",4.1819,false],[false,"mean calorie","cal_m","CAL_M","energy",4190.0199999999995,[2,-2,1,0,0,0,0],"calm","heat",true,null,null,1,false,false,0,"mean cals; mean calories","UCUM","Enrg","Clinical","equal to 4.19002 joules. ","J","J","4.19002",4.19002,false],[false,"international table calorie","cal_IT","CAL_IT","energy",4186.8,[2,-2,1,0,0,0,0],"calIT","heat",true,null,null,1,false,false,0,"calories IT; IT cals; international steam table calories","UCUM","Enrg","Nonclinical","used in engineering steam tables and defined as 1/860 international watt-hour; equal to 4.1868 joules","J","J","4.1868",4.1868,false],[false,"thermochemical calorie","cal_th","CAL_TH","energy",4184,[2,-2,1,0,0,0,0],"calth","heat",true,null,null,1,false,false,0,"thermochemical calories; th cals","UCUM","Enrg","Clinical","equal to 4.184 joules; used as the unit in medicine and biochemistry (equal to cal)","J","J","4.184",4.184,false],[false,"calorie","cal","CAL","energy",4184,[2,-2,1,0,0,0,0],"cal","heat",true,null,null,1,false,false,0,"gram calories; small calories","UCUM","Enrg","Clinical","equal to 4.184 joules (the same value as the thermochemical calorie, which is the most common calorie used in medicine and biochemistry)","cal_th","CAL_TH","1",1,false],[false,"nutrition label Calories","[Cal]","[CAL]","energy",4184000,[2,-2,1,0,0,0,0],"Cal","heat",false,null,null,1,false,false,0,"food calories; Cal; kcal","UCUM","Eng","Clinical","","kcal_th","KCAL_TH","1",1,false],[false,"British thermal unit at 39°F","[Btu_39]","[BTU_39]","energy",1059670,[2,-2,1,0,0,0,0],"Btu39°F","heat",false,null,null,1,false,false,0,"BTU 39F; BTU 39 F; B.T.U. 39 F; B.Th.U. 39 F; BThU 39 F; British thermal units","UCUM","Eng","Nonclinical","equal to 1.05967 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05967",1.05967,false],[false,"British thermal unit at 59°F","[Btu_59]","[BTU_59]","energy",1054800,[2,-2,1,0,0,0,0],"Btu59°F","heat",false,null,null,1,false,false,0,"BTU 59 F; BTU 59F; B.T.U. 59 F; B.Th.U. 59 F; BThU 59F; British thermal units","UCUM","Eng","Nonclinical","equal to 1.05480 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05480",1.0548,false],[false,"British thermal unit at 60°F","[Btu_60]","[BTU_60]","energy",1054680,[2,-2,1,0,0,0,0],"Btu60°F","heat",false,null,null,1,false,false,0,"BTU 60 F; BTU 60F; B.T.U. 60 F; B.Th.U. 60 F; BThU 60 F; British thermal units 60 F","UCUM","Eng","Nonclinical","equal to 1.05468 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05468",1.05468,false],[false,"mean British thermal unit","[Btu_m]","[BTU_M]","energy",1055870,[2,-2,1,0,0,0,0],"Btum","heat",false,null,null,1,false,false,0,"BTU mean; B.T.U. mean; B.Th.U. mean; BThU mean; British thermal units mean; ","UCUM","Eng","Nonclinical","equal to 1.05587 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05587",1.05587,false],[false,"international table British thermal unit","[Btu_IT]","[BTU_IT]","energy",1055055.85262,[2,-2,1,0,0,0,0],"BtuIT","heat",false,null,null,1,false,false,0,"BTU IT; B.T.U. IT; B.Th.U. IT; BThU IT; British thermal units IT","UCUM","Eng","Nonclinical","equal to 1.055 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05505585262",1.05505585262,false],[false,"thermochemical British thermal unit","[Btu_th]","[BTU_TH]","energy",1054350,[2,-2,1,0,0,0,0],"Btuth","heat",false,null,null,1,false,false,0,"BTU Th; B.T.U. Th; B.Th.U. Th; BThU Th; thermochemical British thermal units","UCUM","Eng","Nonclinical","equal to 1.054350 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.054350",1.05435,false],[false,"British thermal unit","[Btu]","[BTU]","energy",1054350,[2,-2,1,0,0,0,0],"btu","heat",false,null,null,1,false,false,0,"BTU; B.T.U. ; B.Th.U.; BThU; British thermal units","UCUM","Eng","Nonclinical","equal to the thermochemical British thermal unit equal to 1.054350 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","[Btu_th]","[BTU_TH]","1",1,false],[false,"horsepower - mechanical","[HP]","[HP]","power",745699.8715822703,[2,-3,1,0,0,0,0],null,"heat",false,null,null,1,false,false,0,"imperial horsepowers","UCUM","EngRat","Nonclinical","refers to mechanical horsepower, which is unit used to measure engine power primarily in the US. ","[ft_i].[lbf_av]/s","[FT_I].[LBF_AV]/S","550",550,false],[false,"tex","tex","TEX","linear mass density (of textile thread)",0.001,[-1,0,1,0,0,0,0],"tex","heat",true,null,null,1,false,false,0,"linear mass density; texes","UCUM","","Clinical","unit of linear mass density for fibers equal to gram per 1000 meters","g/km","G/KM","1",1,false],[false,"Denier (linear mass density)","[den]","[DEN]","linear mass density (of textile thread)",0.0001111111111111111,[-1,0,1,0,0,0,0],"den","heat",false,null,null,1,false,false,0,"den; deniers","UCUM","","Nonclinical","equal to the mass in grams per 9000 meters of the fiber (1 denier = 1 strand of silk)","g/9/km","G/9/KM","1",1,false],[false,"meter of water column","m[H2O]","M[H2O]","pressure",9806650,[-1,-2,1,0,0,0,0],"m HO2","clinical",true,null,null,1,false,false,0,"mH2O; m H2O; meters of water column; metres; pressure","UCUM","Pres","Clinical","","kPa","KPAL","980665e-5",9.80665,false],[false,"meter of mercury column","m[Hg]","M[HG]","pressure",133322000,[-1,-2,1,0,0,0,0],"m Hg","clinical",true,null,null,1,false,false,0,"mHg; m Hg; meters of mercury column; metres; pressure","UCUM","Pres","Clinical","","kPa","KPAL","133.3220",133.322,false],[false,"inch of water column","[in_i'H2O]","[IN_I'H2O]","pressure",249088.91000000003,[-1,-2,1,0,0,0,0],"in HO2","clinical",false,null,null,1,false,false,0,"inches WC; inAq; in H2O; inch of water gauge; iwg; pressure","UCUM","Pres","Clinical","unit of pressure, especially in respiratory and ventilation care","m[H2O].[in_i]/m","M[H2O].[IN_I]/M","1",1,false],[false,"inch of mercury column","[in_i'Hg]","[IN_I'HG]","pressure",3386378.8000000003,[-1,-2,1,0,0,0,0],"in Hg","clinical",false,null,null,1,false,false,0,"inHg; in Hg; pressure; inches","UCUM","Pres","Clinical","unit of pressure used in US to measure barometric pressure and occasionally blood pressure (see mm[Hg] for unit used internationally)","m[Hg].[in_i]/m","M[HG].[IN_I]/M","1",1,false],[false,"peripheral vascular resistance unit","[PRU]","[PRU]","fluid resistance",133322000000,[-4,-1,1,0,0,0,0],"P.R.U.","clinical",false,null,null,1,false,false,0,"peripheral vascular resistance units; peripheral resistance unit; peripheral resistance units; PRU","UCUM","FldResist","Clinical","used to assess blood flow in the capillaries; equal to 1 mmH.min/mL = 133.3 Pa·min/mL","mm[Hg].s/ml","MM[HG].S/ML","1",1,false],[false,"Wood unit","[wood'U]","[WOOD'U]","fluid resistance",7999320000,[-4,-1,1,0,0,0,0],"Wood U.","clinical",false,null,null,1,false,false,0,"hybrid reference units; HRU; mmHg.min/L; vascular resistance","UCUM","Pres","Clinical","simplified unit of measurement for for measuring pulmonary vascular resistance that uses pressure; equal to mmHg.min/L","mm[Hg].min/L","MM[HG].MIN/L","1",1,false],[false,"diopter (lens)","[diop]","[DIOP]","refraction of a lens",1,[1,0,0,0,0,0,0],"dpt","clinical",false,null,"inv",1,false,false,0,"diopters; diop; dioptre; dpt; refractive power","UCUM","InvLen","Clinical","unit of optical power of lens represented by inverse meters (m^-1)","m","/M","1",1,false],[false,"prism diopter (magnifying power)","[p'diop]","[P'DIOP]","refraction of a prism",1,[0,0,0,1,0,0,0],"PD","clinical",false,null,"tanTimes100",1,true,false,0,"diopters; dioptres; p diops; pdiop; dpt; pdptr; Δ; cm/m; centimeter per meter; centimetre; metre","UCUM","Angle","Clinical","unit for prism correction in eyeglass prescriptions","rad",null,null,1,false],[false,"percent of slope","%[slope]","%[SLOPE]","slope",0.017453292519943295,[0,0,0,1,0,0,0],"%","clinical",false,null,"100tan",1,true,false,0,"% slope; %slope; percents slopes","UCUM","VelFr; ElpotRatFr; VelRtoFr; AccelFr","Clinical","","deg",null,null,1,false],[false,"mesh","[mesh_i]","[MESH_I]","lineic number",0.025400000000000002,[1,0,0,0,0,0,0],null,"clinical",false,null,"inv",1,false,false,0,"meshes","UCUM","NLen (lineic number)","Clinical","traditional unit of length defined as the number of strands or particles per inch","[in_i]","/[IN_I]","1",1,false],[false,"French (catheter gauge) ","[Ch]","[CH]","gauge of catheters",0.0003333333333333333,[1,0,0,0,0,0,0],"Ch","clinical",false,null,null,1,false,false,0,"Charrières, French scales; French gauges; Fr, Fg, Ga, FR, Ch","UCUM","Len; Circ; Diam","Clinical","","mm/3","MM/3","1",1,false],[false,"drop - metric (1/20 mL)","[drp]","[DRP]","volume",5e-8,[3,0,0,0,0,0,0],"drp","clinical",false,null,null,1,false,false,0,"drop dosing units; metric drops; gtt","UCUM","Vol","Clinical","standard unit used in the US and internationally for clinical medicine but note that although [drp] is defined as 1/20 milliliter, in practice, drop sizes will vary due to external factors","ml/20","ML/20","1",1,false],[false,"Hounsfield unit","[hnsf'U]","[HNSF'U]","x-ray attenuation",1,[0,0,0,0,0,0,0],"HF","clinical",false,null,null,1,false,false,0,"HU; units","UCUM","","Clinical","used to measure X-ray attenuation, especially in CT scans.","1","1","1",1,false],[false,"Metabolic Equivalent of Task ","[MET]","[MET]","metabolic cost of physical activity",5.833333333333334e-11,[3,-1,-1,0,0,0,0],"MET","clinical",false,null,null,1,false,false,0,"metabolic equivalents","UCUM","RelEngRat","Clinical","unit used to measure rate of energy expenditure per power in treadmill and other functional tests","mL/min/kg","ML/MIN/KG","3.5",3.5,false],[false,"homeopathic potency of decimal series (retired)","[hp'_X]","[HP'_X]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,"hpX",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of centesimal series (retired)","[hp'_C]","[HP'_C]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,"hpC",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of millesimal series (retired)","[hp'_M]","[HP'_M]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,"hpM",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of quintamillesimal series (retired)","[hp'_Q]","[HP'_Q]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,"hpQ",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of decimal hahnemannian series","[hp_X]","[HP_X]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of centesimal hahnemannian series","[hp_C]","[HP_C]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of millesimal hahnemannian series","[hp_M]","[HP_M]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of quintamillesimal hahnemannian series","[hp_Q]","[HP_Q]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of decimal korsakovian series","[kp_X]","[KP_X]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of centesimal korsakovian series","[kp_C]","[KP_C]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of millesimal korsakovian series","[kp_M]","[KP_M]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of quintamillesimal korsakovian series","[kp_Q]","[KP_Q]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"equivalent","eq","EQ","amount of substance",6.0221367e+23,[0,0,0,0,0,0,0],"eq","chemical",true,null,null,1,false,false,1,"equivalents","UCUM","Sub","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"osmole","osm","OSM","amount of substance (dissolved particles)",6.0221367e+23,[0,0,0,0,0,0,0],"osm","chemical",true,null,null,1,false,false,1,"osmoles; osmols","UCUM","Osmol","Clinical","the number of moles of solute that contribute to the osmotic pressure of a solution","mol","MOL","1",1,false],[false,"pH","[pH]","[PH]","acidity",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"pH","chemical",false,null,"pH",1,true,false,0,"pH scale","UCUM","LogCnc","Clinical","Log concentration of H+","mol/l",null,null,1,false],[false,"gram percent","g%","G%","mass concentration",10000,[-3,0,1,0,0,0,0],"g%","chemical",true,null,null,1,false,false,0,"gram %; gram%; grams per deciliter; g/dL; gm per dL; gram percents","UCUM","MCnc","Clinical","equivalent to unit gram per deciliter (g/dL), a unit often used in medical tests to represent solution concentrations","g/dl","G/DL","1",1,false],[false,"Svedberg unit","[S]","[S]","sedimentation coefficient",1e-13,[0,1,0,0,0,0,0],"S","chemical",false,null,null,1,false,false,0,"Sv; 10^-13 seconds; 100 fs; 100 femtoseconds","UCUM","Time","Clinical","unit of time used in measuring particle's sedimentation rate, usually after centrifugation. ","s","10*-13.S","1",1e-13,false],[false,"high power field (microscope)","[HPF]","[HPF]","view area in microscope",1,[0,0,0,0,0,0,0],"HPF","chemical",false,null,null,1,false,false,0,"HPF","UCUM","Area","Clinical","area visible under the maximum magnification power of the objective in microscopy (usually 400x)\n","1","1","1",1,false],[false,"low power field (microscope)","[LPF]","[LPF]","view area in microscope",1,[0,0,0,0,0,0,0],"LPF","chemical",false,null,null,1,false,false,0,"LPF; fields","UCUM","Area","Clinical","area visible under the low magnification of the objective in microscopy (usually 100 x)\n","1","1","100",100,false],[false,"katal","kat","KAT","catalytic activity",6.0221367e+23,[0,-1,0,0,0,0,0],"kat","chemical",true,null,null,1,false,false,1,"mol/secs; moles per second; mol*sec-1; mol*s-1; mol.s-1; katals; catalytic activity; enzymatic; enzyme units; activities","UCUM","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"enzyme unit","U","U","catalytic activity",10036894500000000,[0,-1,0,0,0,0,0],"U","chemical",true,null,null,1,false,false,1,"micromoles per minute; umol/min; umol per minute; umol min-1; enzymatic activity; enzyme activity","UCUM","CAct","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"international unit - arbitrary","[iU]","[IU]","arbitrary",1,[0,0,0,0,0,0,0],"IU","chemical",true,null,null,1,false,true,0,"international units; IE; F2","UCUM","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","1","1","1",1,false],[false,"international unit - arbitrary","[IU]","[IU]","arbitrary",1,[0,0,0,0,0,0,0],"i.U.","chemical",true,null,null,1,false,true,0,"international units; IE; F2","UCUM","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"arbitary unit","[arb'U]","[ARB'U]","arbitrary",1,[0,0,0,0,0,0,0],"arb. U","chemical",false,null,null,1,false,true,0,"arbitary units; arb units; arbU","UCUM","Arb","Clinical","relative unit of measurement to show the ratio of test measurement to reference measurement","1","1","1",1,false],[false,"United States Pharmacopeia unit","[USP'U]","[USP'U]","arbitrary",1,[0,0,0,0,0,0,0],"U.S.P.","chemical",false,null,null,1,false,true,0,"USP U; USP'U","UCUM","Arb","Clinical","a dose unit to express potency of drugs and vitamins defined by the United States Pharmacopoeia; usually 1 USP = 1 IU","1","1","1",1,false],[false,"GPL unit","[GPL'U]","[GPL'U]","biologic activity of anticardiolipin IgG",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"GPL Units; GPL U; IgG anticardiolipin units; IgG Phospholipid","UCUM","ACnc; AMass","Clinical","Units for an antiphospholipid test","1","1","1",1,false],[false,"MPL unit","[MPL'U]","[MPL'U]","biologic activity of anticardiolipin IgM",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"MPL units; MPL U; MPL'U; IgM anticardiolipin units; IgM Phospholipid Units ","UCUM","ACnc","Clinical","units for antiphospholipid test","1","1","1",1,false],[false,"APL unit","[APL'U]","[APL'U]","biologic activity of anticardiolipin IgA",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"APL units; APL U; IgA anticardiolipin; IgA Phospholipid; biologic activity of","UCUM","AMass; ACnc","Clinical","Units for an anti phospholipid syndrome test","1","1","1",1,false],[false,"Bethesda unit","[beth'U]","[BETH'U]","biologic activity of factor VIII inhibitor",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"BU","UCUM","ACnc","Clinical","measures of blood coagulation inhibitior for many blood factors","1","1","1",1,false],[false,"anti factor Xa unit","[anti'Xa'U]","[ANTI'XA'U]","biologic activity of factor Xa inhibitor (heparin)",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","ACnc","Clinical","[anti'Xa'U] unit is equivalent to and can be converted to IU/mL. ","1","1","1",1,false],[false,"Todd unit","[todd'U]","[TODD'U]","biologic activity antistreptolysin O",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","InvThres; RtoThres","Clinical","the unit for the results of the testing for antistreptolysin O (ASO)","1","1","1",1,false],[false,"Dye unit","[dye'U]","[DYE'U]","biologic activity of amylase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","CCnc","Obsolete","equivalent to the Somogyi unit, which is an enzyme unit for amylase but better to use U, the standard enzyme unit for measuring catalytic activity","1","1","1",1,false],[false,"Somogyi unit","[smgy'U]","[SMGY'U]","biologic activity of amylase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"Somogyi units; smgy U","UCUM","CAct","Clinical","measures the enzymatic activity of amylase in blood serum - better to use base units mg/mL ","1","1","1",1,false],[false,"Bodansky unit","[bdsk'U]","[BDSK'U]","biologic activity of phosphatase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"","UCUM","ACnc","Obsolete","Enzyme unit specific to alkaline phosphatase - better to use standard enzyme unit of U","1","1","1",1,false],[false,"King-Armstrong unit","[ka'U]","[KA'U]","biologic activity of phosphatase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"King-Armstrong Units; King units","UCUM","AMass","Obsolete","enzyme units for acid phosphatase - better to use enzyme unit [U]","1","1","1",1,false],[false,"Kunkel unit","[knk'U]","[KNK'U]","arbitrary biologic activity",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"Mac Lagan unit","[mclg'U]","[MCLG'U]","arbitrary biologic activity",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"galactose index; galactose tolerance test; thymol turbidity test unit; mclg U; units; indexes","UCUM","ACnc","Obsolete","unit for liver tests - previously used in thymol turbidity tests for liver disease diagnoses, and now is sometimes referred to in the oral galactose tolerance test","1","1","1",1,false],[false,"tuberculin unit","[tb'U]","[TB'U]","biologic activity of tuberculin",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"TU; units","UCUM","Arb","Clinical","amount of tuberculin antigen -usually in reference to a TB skin test ","1","1","1",1,false],[false,"50% cell culture infectious dose","[CCID_50]","[CCID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"CCID50","chemical",false,null,null,1,false,true,0,"CCID50; 50% cell culture infective doses","UCUM","NumThres","Clinical","","1","1","1",1,false],[false,"50% tissue culture infectious dose","[TCID_50]","[TCID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"TCID50","chemical",false,null,null,1,false,true,0,"TCID50; 50% tissue culture infective dose","UCUM","NumThres","Clinical","","1","1","1",1,false],[false,"50% embryo infectious dose","[EID_50]","[EID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"EID50","chemical",false,null,null,1,false,true,0,"EID50; 50% embryo infective doses; EID50 Egg Infective Dosage","UCUM","thresNum","Clinical","","1","1","1",1,false],[false,"plaque forming units","[PFU]","[PFU]","amount of an infectious agent",1,[0,0,0,0,0,0,0],"PFU","chemical",false,null,null,1,false,true,0,"PFU","UCUM","ACnc","Clinical","tests usually report unit as number of PFU per unit volume","1","1","1",1,false],[false,"focus forming units (cells)","[FFU]","[FFU]","amount of an infectious agent",1,[0,0,0,0,0,0,0],"FFU","chemical",false,null,null,1,false,true,0,"FFU","UCUM","EntNum","Clinical","","1","1","1",1,false],[false,"colony forming units","[CFU]","[CFU]","amount of a proliferating organism",1,[0,0,0,0,0,0,0],"CFU","chemical",false,null,null,1,false,true,0,"CFU","UCUM","Num","Clinical","","1","1","1",1,false],[false,"index of reactivity (allergen)","[IR]","[IR]","amount of an allergen callibrated through in-vivo testing using the Stallergenes® method.",1,[0,0,0,0,0,0,0],"IR","chemical",false,null,null,1,false,true,0,"IR; indexes","UCUM","Acnc","Clinical","amount of an allergen callibrated through in-vivo testing using the Stallergenes method. Usually reported in tests as IR/mL","1","1","1",1,false],[false,"bioequivalent allergen unit","[BAU]","[BAU]","amount of an allergen callibrated through in-vivo testing based on the ID50EAL method of (intradermal dilution for 50mm sum of erythema diameters",1,[0,0,0,0,0,0,0],"BAU","chemical",false,null,null,1,false,true,0,"BAU; Bioequivalent Allergy Units; bioequivalent allergen units","UCUM","Arb","Clinical","","1","1","1",1,false],[false,"allergy unit","[AU]","[AU]","procedure defined amount of an allergen using some reference standard",1,[0,0,0,0,0,0,0],"AU","chemical",false,null,null,1,false,true,0,"allergy units; allergen units; AU","UCUM","Arb","Clinical","Most standard test allergy units are reported as [IU] or as %. ","1","1","1",1,false],[false,"allergen unit for Ambrosia artemisiifolia","[Amb'a'1'U]","[AMB'A'1'U]","procedure defined amount of the major allergen of ragweed.",1,[0,0,0,0,0,0,0],"Amb a 1 U","chemical",false,null,null,1,false,true,0,"Amb a 1 unit; Antigen E; AgE U; allergen units","UCUM","Arb","Clinical","Amb a 1 is the major allergen in short ragweed, and can be converted Bioequivalent allergen units (BAU) where 350 Amb a 1 U/mL = 100,000 BAU/mL","1","1","1",1,false],[false,"protein nitrogen unit (allergen testing)","[PNU]","[PNU]","procedure defined amount of a protein substance",1,[0,0,0,0,0,0,0],"PNU","chemical",false,null,null,1,false,true,0,"protein nitrogen units; PNU","UCUM","Mass","Clinical","defined as 0.01 ug of phosphotungstic acid-precipitable protein nitrogen. Being replaced by bioequivalent allergy units (BAU).","1","1","1",1,false],[false,"Limit of flocculation","[Lf]","[LF]","procedure defined amount of an antigen substance",1,[0,0,0,0,0,0,0],"Lf","chemical",false,null,null,1,false,true,0,"Lf doses","UCUM","Arb","Clinical","the antigen content forming 1:1 ratio against 1 unit of antitoxin","1","1","1",1,false],[false,"D-antigen unit (polio)","[D'ag'U]","[D'AG'U]","procedure defined amount of a poliomyelitis d-antigen substance",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"DAgU; units","UCUM","Acnc","Clinical","unit of potency of poliovirus vaccine used for poliomyelitis prevention reported as D antigen units/mL. The unit is poliovirus type-specific.","1","1","1",1,false],[false,"fibrinogen equivalent units","[FEU]","[FEU]","amount of fibrinogen broken down into the measured d-dimers",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"FEU","UCUM","MCnc","Clinical","Note both the FEU and DDU units are used to report D-dimer measurements. 1 DDU = 1/2 FFU","1","1","1",1,false],[false,"ELISA unit","[ELU]","[ELU]","arbitrary ELISA unit",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"Enzyme-Linked Immunosorbent Assay Units; ELU; EL. U","UCUM","ACnc","Clinical","","1","1","1",1,false],[false,"Ehrlich units (urobilinogen)","[EU]","[EU]","Ehrlich unit",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"EU/dL; mg{urobilinogen}/dL","UCUM","ACnc","Clinical","","1","1","1",1,false],[false,"neper","Np","NEP","level",1,[0,0,0,0,0,0,0],"Np","levels",true,null,"ln",1,true,false,0,"nepers","UCUM","LogRto","Clinical","logarithmic unit for ratios of measurements of physical field and power quantities, such as gain and loss of electronic signals","1",null,null,1,false],[false,"bel","B","B","level",1,[0,0,0,0,0,0,0],"B","levels",true,null,"lg",1,true,false,0,"bels","UCUM","LogRto","Clinical","Logarithm of the ratio of power- or field-type quantities; usually expressed in decibels ","1",null,null,1,false],[false,"bel sound pressure","B[SPL]","B[SPL]","pressure level",0.02,[-1,-2,1,0,0,0,0],"B(SPL)","levels",true,null,"lgTimes2",1,true,false,0,"bel SPL; B SPL; sound pressure bels","UCUM","LogRto","Clinical","used to measure sound level in acoustics","Pa",null,null,0.00002,false],[false,"bel volt","B[V]","B[V]","electric potential level",1000,[2,-2,1,0,0,-1,0],"B(V)","levels",true,null,"lgTimes2",1,true,false,0,"bel V; B V; volts bels","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","V",null,null,1,false],[false,"bel millivolt","B[mV]","B[MV]","electric potential level",1,[2,-2,1,0,0,-1,0],"B(mV)","levels",true,null,"lgTimes2",1,true,false,0,"bel mV; B mV; millivolt bels; 10^-3V bels; 10*-3V ","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","mV",null,null,1,false],[false,"bel microvolt","B[uV]","B[UV]","electric potential level",0.001,[2,-2,1,0,0,-1,0],"B(μV)","levels",true,null,"lgTimes2",1,true,false,0,"bel uV; B uV; microvolts bels; 10^-6V bel; 10*-6V bel","UCUM","LogRto","Clinical","used to express power gain in electrical circuits","uV",null,null,1,false],[false,"bel 10 nanovolt","B[10.nV]","B[10.NV]","electric potential level",0.000010000000000000003,[2,-2,1,0,0,-1,0],"B(10 nV)","levels",true,null,"lgTimes2",1,true,false,0,"bel 10 nV; B 10 nV; 10 nanovolts bels","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","nV",null,null,10,false],[false,"bel watt","B[W]","B[W]","power level",1000,[2,-3,1,0,0,0,0],"B(W)","levels",true,null,"lg",1,true,false,0,"bel W; b W; b Watt; Watts bels","UCUM","LogRto","Clinical","used to express power","W",null,null,1,false],[false,"bel kilowatt","B[kW]","B[KW]","power level",1000000,[2,-3,1,0,0,0,0],"B(kW)","levels",true,null,"lg",1,true,false,0,"bel kW; B kW; kilowatt bel; kW bel; kW B","UCUM","LogRto","Clinical","used to express power","kW",null,null,1,false],[false,"stere","st","STR","volume",1,[3,0,0,0,0,0,0],"st","misc",true,null,null,1,false,false,0,"stère; m3; cubic meter; m^3; meters cubed; metre","UCUM","Vol","Nonclinical","equal to one cubic meter, usually used for measuring firewoord","m3","M3","1",1,false],[false,"Ångström","Ao","AO","length",1.0000000000000002e-10,[1,0,0,0,0,0,0],"Å","misc",false,null,null,1,false,false,0,"Å; Angstroms; Ao; Ångströms","UCUM","Len","Clinical","equal to 10^-10 meters; used to express wave lengths and atom scaled differences ","nm","NM","0.1",0.1,false],[false,"barn","b","BRN","action area",9.999999999999999e-29,[2,0,0,0,0,0,0],"b","misc",false,null,null,1,false,false,0,"barns","UCUM","Area","Clinical","used in high-energy physics to express cross-sectional areas","fm2","FM2","100",100,false],[false,"technical atmosphere","att","ATT","pressure",98066499.99999999,[-1,-2,1,0,0,0,0],"at","misc",false,null,null,1,false,false,0,"at; tech atm; tech atmosphere; kgf/cm2; atms; atmospheres","UCUM","Pres","Obsolete","non-SI unit of pressure equal to one kilogram-force per square centimeter","kgf/cm2","KGF/CM2","1",1,false],[false,"mho","mho","MHO","electric conductance",0.001,[-2,1,-1,0,0,2,0],"mho","misc",true,null,null,1,false,false,0,"siemens; ohm reciprocals; Ω^−1; Ω-1 ","UCUM","","Obsolete","unit of electric conductance (the inverse of electrical resistance) equal to ohm^-1","S","S","1",1,false],[false,"pound per square inch","[psi]","[PSI]","pressure",6894757.293168359,[-1,-2,1,0,0,0,0],"psi","misc",false,null,null,1,false,false,0,"psi; lb/in2; lb per in2","UCUM","Pres","Clinical","","[lbf_av]/[in_i]2","[LBF_AV]/[IN_I]2","1",1,false],[false,"circle - plane angle","circ","CIRC","plane angle",6.283185307179586,[0,0,0,1,0,0,0],"circ","misc",false,null,null,1,false,false,0,"angles; circles","UCUM","Angle","Clinical","","[pi].rad","[PI].RAD","2",2,false],[false,"spere - solid angle","sph","SPH","solid angle",12.566370614359172,[0,0,0,2,0,0,0],"sph","misc",false,null,null,1,false,false,0,"speres","UCUM","Angle","Clinical","equal to the solid angle of an entire sphere = 4πsr (sr = steradian) ","[pi].sr","[PI].SR","4",4,false],[false,"metric carat","[car_m]","[CAR_M]","mass",0.2,[0,0,1,0,0,0,0],"ctm","misc",false,null,null,1,false,false,0,"carats; ct; car m","UCUM","Mass","Nonclinical","unit of mass for gemstones","g","G","2e-1",0.2,false],[false,"carat of gold alloys","[car_Au]","[CAR_AU]","mass fraction",0.041666666666666664,[0,0,0,0,0,0,0],"ctAu","misc",false,null,null,1,false,false,0,"karats; k; kt; car au; carats","UCUM","MFr","Nonclinical","unit of purity for gold alloys","/24","/24","1",1,false],[false,"Smoot","[smoot]","[SMOOT]","length",1.7018000000000002,[1,0,0,0,0,0,0],null,"misc",false,null,null,1,false,false,0,"","UCUM","Len","Nonclinical","prank unit of length from MIT","[in_i]","[IN_I]","67",67,false],[false,"meter per square seconds per square root of hertz","[m/s2/Hz^(1/2)]","[M/S2/HZ^(1/2)]","amplitude spectral density",1,[2,-3,0,0,0,0,0],null,"misc",false,null,"sqrt",1,true,false,0,"m/s2/(Hz^.5); m/s2/(Hz^(1/2)); m per s2 per Hz^1/2","UCUM","","Constant","measures amplitude spectral density, and is equal to the square root of power spectral density\n ","m2/s4/Hz",null,null,1,false],[false,"bit - logarithmic","bit_s","BIT_S","amount of information",1,[0,0,0,0,0,0,0],"bits","infotech",false,null,"ld",1,true,false,0,"bit-s; bit s; bit logarithmic","UCUM","LogA","Nonclinical","defined as the log base 2 of the number of distinct signals; cannot practically be used to express more than 1000 bits\n\nIn information theory, the definition of the amount of self-information and information entropy is often expressed with the binary logarithm (log base 2)","1",null,null,1,false],[false,"bit","bit","BIT","amount of information",1,[0,0,0,0,0,0,0],"bit","infotech",true,null,null,1,false,false,0,"bits","UCUM","","Nonclinical","dimensionless information unit of 1 used in computing and digital communications","1","1","1",1,false],[false,"byte","By","BY","amount of information",8,[0,0,0,0,0,0,0],"B","infotech",true,null,null,1,false,false,0,"bytes","UCUM","","Nonclinical","equal to 8 bits","bit","bit","8",8,false],[false,"baud","Bd","BD","signal transmission rate",1,[0,1,0,0,0,0,0],"Bd","infotech",true,null,"inv",1,false,false,0,"Bd; bauds","UCUM","Freq","Nonclinical","unit to express rate in symbols per second or pulses per second. ","s","/s","1",1,false],[false,"per twelve hour","/(12.h)","/HR","",0.000023148148148148147,[0,-1,0,0,0,0,0],"/h",null,false,null,null,1,false,false,0,"per 12 hours; 12hrs; 12 hrs; /12hrs","LOINC","Rat","Clinical","",null,null,null,null,false],[false,"per arbitrary unit","/[arb'U]","/[ARB'U]","",1,[0,0,0,0,0,0,0],"/arb/ U",null,false,null,null,1,false,true,0,"/arbU","LOINC","InvA ","Clinical","",null,null,null,null,false],[false,"per high power field","/[HPF]","/[HPF]","",1,[0,0,0,0,0,0,0],"/HPF",null,false,null,null,1,false,false,0,"/HPF; per HPF","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per international unit","/[IU]","/[IU]","",1,[0,0,0,0,0,0,0],"/i/U.",null,false,null,null,1,false,true,0,"international units; /IU; per IU","LOINC","InvA","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)",null,null,null,null,false],[false,"per low power field","/[LPF]","/[LPF]","",1,[0,0,0,0,0,0,0],"/LPF",null,false,null,null,1,false,false,0,"/LPF; per LPF","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per 10 billion ","/10*10","/10*10","",1e-10,[0,0,0,0,0,0,0],"/1010<.sup>",null,false,null,null,1,false,false,0,"/10^10; per 10*10","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per trillion ","/10*12","/10*12","",1e-12,[0,0,0,0,0,0,0],"/1012<.sup>",null,false,null,null,1,false,false,0,"/10^12; per 10*12","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per thousand","/10*3","/10*3","",0.001,[0,0,0,0,0,0,0],"/103<.sup>",null,false,null,null,1,false,false,0,"/10^3; per 10*3","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per million","/10*6","/10*6","",0.000001,[0,0,0,0,0,0,0],"/106<.sup>",null,false,null,null,1,false,false,0,"/10^6; per 10*6;","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per billion","/10*9","/10*9","",1e-9,[0,0,0,0,0,0,0],"/109<.sup>",null,false,null,null,1,false,false,0,"/10^9; per 10*9","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per 100","/100","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"per hundred; 10^2; 10*2","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per 100 cells","/100{cells}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 cells; /100cells; per hundred","LOINC","EntMass; EntNum; NFr","Clinical","",null,null,null,null,false],[false,"per 100 neutrophils","/100{neutrophils}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 neutrophils; /100neutrophils; per hundred","LOINC","EntMass; EntNum; NFr","Clinical","",null,null,null,null,false],[false,"per 100 spermatozoa","/100{spermatozoa}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 spermatozoa; /100spermatozoa; per hundred","LOINC","NFr","Clinical","",null,null,null,null,false],[false,"per 100 white blood cells","/100{WBCs}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 WBCs; /100WBCs; per hundred","LOINC","Ratio; NFr","Clinical","",null,null,null,null,false],[false,"per year","/a","/ANN","",3.168808781402895e-8,[0,-1,0,0,0,0,0],"/a",null,false,null,null,1,false,false,0,"/Years; /yrs; yearly","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per centimeter of water","/cm[H2O]","/CM[H2O]","",0.000010197162129779282,[1,2,-1,0,0,0,0],"/cm HO2<.r>",null,false,null,null,1,false,false,0,"/cmH2O; /cm H2O; centimeters; centimetres","LOINC","InvPress","Clinical","",null,null,null,null,false],[false,"per day","/d","/D","",0.000011574074074074073,[0,-1,0,0,0,0,0],"/d",null,false,null,null,1,false,false,0,"/dy; per day","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per deciliter","/dL","/DL","",10000,[-3,0,0,0,0,0,0],"/dL",null,false,null,null,1,false,false,0,"per dL; /deciliter; decilitre","LOINC","NCnc","Clinical","",null,null,null,null,false],[false,"per gram","/g","/G","",1,[0,0,-1,0,0,0,0],"/g",null,false,null,null,1,false,false,0,"/gm; /gram; per g","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per hour","/h","/HR","",0.0002777777777777778,[0,-1,0,0,0,0,0],"/h",null,false,null,null,1,false,false,0,"/hr; /hour; per hr","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per kilogram","/kg","/KG","",0.001,[0,0,-1,0,0,0,0],"/kg",null,false,null,null,1,false,false,0,"per kg; per kilogram","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per liter","/L","/L","",1000,[-3,0,0,0,0,0,0],"/L",null,false,null,null,1,false,false,0,"/liter; litre","LOINC","NCnc","Clinical","",null,null,null,null,false],[false,"per square meter","/m2","/M2","",1,[-2,0,0,0,0,0,0],"/m2<.sup>",null,false,null,null,1,false,false,0,"/m^2; /m*2; /sq. m; per square meter; meter squared; metre","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per cubic meter","/m3","/M3","",1,[-3,0,0,0,0,0,0],"/m3<.sup>",null,false,null,null,1,false,false,0,"/m^3; /m*3; /cu. m; per cubic meter; meter cubed; per m3; metre","LOINC","NCncn","Clinical","",null,null,null,null,false],[false,"per milligram","/mg","/MG","",1000,[0,0,-1,0,0,0,0],"/mg",null,false,null,null,1,false,false,0,"/milligram; per mg","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per minute","/min","/MIN","",0.016666666666666666,[0,-1,0,0,0,0,0],"/min",null,false,null,null,1,false,false,0,"/minute; per mins; breaths beats per minute","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per milliliter","/mL","/ML","",1000000,[-3,0,0,0,0,0,0],"/mL",null,false,null,null,1,false,false,0,"/milliliter; per mL; millilitre","LOINC","NCncn","Clinical","",null,null,null,null,false],[false,"per millimeter","/mm","/MM","",1000,[-1,0,0,0,0,0,0],"/mm",null,false,null,null,1,false,false,0,"/millimeter; per mm; millimetre","LOINC","InvLen","Clinical","",null,null,null,null,false],[false,"per month","/mo","/MO","",3.802570537683474e-7,[0,-1,0,0,0,0,0],"/mo",null,false,null,null,1,false,false,0,"/month; per mo; monthly; month","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per second","/s","/S","",1,[0,-1,0,0,0,0,0],"/s",null,false,null,null,1,false,false,0,"/second; /sec; per sec; frequency; Hertz; Herz; Hz; becquerels; Bq; s-1; s^-1","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per enzyme unit","/U","/U","",9.963241120049633e-17,[0,1,0,0,0,0,0],"/U",null,false,null,null,1,false,false,-1,"/enzyme units; per U","LOINC","InvC; NCat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)",null,null,null,null,false],[false,"per microliter","/uL","/UL","",999999999.9999999,[-3,0,0,0,0,0,0],"/μL",null,false,null,null,1,false,false,0,"/microliter; microlitre; /mcl; per uL","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"per week","/wk","/WK","",0.0000016534391534391535,[0,-1,0,0,0,0,0],"/wk",null,false,null,null,1,false,false,0,"/week; per wk; weekly, weeks","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"APL unit per milliliter","[APL'U]/mL","[APL'U]/ML","biologic activity of anticardiolipin IgA",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"APL/mL; APL'U/mL; APL U/mL; APL/milliliter; IgA anticardiolipin units per milliliter; IgA Phospholipid Units; millilitre; biologic activity of","LOINC","ACnc","Clinical","Units for an anti phospholipid syndrome test","1","1","1",1,false],[false,"arbitrary unit per milliliter","[arb'U]/mL","[ARB'U]/ML","arbitrary",1000000,[-3,0,0,0,0,0,0],"(arb. U)/mL","chemical",false,null,null,1,false,true,0,"arb'U/mL; arbU/mL; arb U/mL; arbitrary units per milliliter; millilitre","LOINC","ACnc","Clinical","relative unit of measurement to show the ratio of test measurement to reference measurement","1","1","1",1,false],[false,"colony forming units per liter","[CFU]/L","[CFU]/L","amount of a proliferating organism",1000,[-3,0,0,0,0,0,0],"CFU/L","chemical",false,null,null,1,false,true,0,"CFU per Liter; CFU/L","LOINC","NCnc","Clinical","","1","1","1",1,false],[false,"colony forming units per milliliter","[CFU]/mL","[CFU]/ML","amount of a proliferating organism",1000000,[-3,0,0,0,0,0,0],"CFU/mL","chemical",false,null,null,1,false,true,0,"CFU per mL; CFU/mL","LOINC","NCnc","Clinical","","1","1","1",1,false],[false,"foot per foot - US","[ft_us]/[ft_us]","[FT_US]/[FT_US]","length",1,[0,0,0,0,0,0,0],"(ftus)/(ftus)","us-lengths",false,null,null,1,false,false,0,"ft/ft; ft per ft; feet per feet; visual acuity","","LenRto","Clinical","distance ratio to measure 20:20 vision","m/3937","M/3937","1200",1200,false],[false,"GPL unit per milliliter","[GPL'U]/mL","[GPL'U]/ML","biologic activity of anticardiolipin IgG",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"GPL U/mL; GPL'U/mL; GPL/mL; GPL U per mL; IgG Phospholipid Units per milliliters; IgG anticardiolipin units; millilitres ","LOINC","ACnc; AMass","Clinical","Units for an antiphospholipid test","1","1","1",1,false],[false,"international unit per 2 hour","[IU]/(2.h)","[IU]/HR","arbitrary",0.0001388888888888889,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/2hrs; IU/2 hours; IU per 2 hrs; international units per 2 hours","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per 24 hour","[IU]/(24.h)","[IU]/HR","arbitrary",0.000011574074074074073,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/24hr; IU/24 hours; IU per 24 hrs; international units per 24 hours","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per day","[IU]/d","[IU]/D","arbitrary",0.000011574074074074073,[0,-1,0,0,0,0,0],"(i.U.)/d","chemical",true,null,null,1,false,true,0,"IU/dy; IU/days; IU per dys; international units per day","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per deciliter","[IU]/dL","[IU]/DL","arbitrary",10000,[-3,0,0,0,0,0,0],"(i.U.)/dL","chemical",true,null,null,1,false,true,0,"IU/dL; IU per dL; international units per deciliters; decilitres","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per gram","[IU]/g","[IU]/G","arbitrary",1,[0,0,-1,0,0,0,0],"(i.U.)/g","chemical",true,null,null,1,false,true,0,"IU/gm; IU/gram; IU per gm; IU per g; international units per gram","LOINC","ACnt","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per hour","[IU]/h","[IU]/HR","arbitrary",0.0002777777777777778,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/hrs; IU per hours; international units per hour","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per kilogram","[IU]/kg","[IU]/KG","arbitrary",0.001,[0,0,-1,0,0,0,0],"(i.U.)/kg","chemical",true,null,null,1,false,true,0,"IU/kg; IU/kilogram; IU per kg; units","LOINC","ACnt","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per kilogram per day","[IU]/kg/d","([IU]/KG)/D","arbitrary",1.1574074074074074e-8,[0,-1,-1,0,0,0,0],"((i.U.)/kg)/d","chemical",true,null,null,1,false,true,0,"IU/kg/dy; IU/kg/day; IU/kilogram/day; IU per kg per day; units","LOINC","ACntRat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per liter","[IU]/L","[IU]/L","arbitrary",1000,[-3,0,0,0,0,0,0],"(i.U.)/L","chemical",true,null,null,1,false,true,0,"IU/L; IU/liter; IU per liter; units; litre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per minute","[IU]/min","[IU]/MIN","arbitrary",0.016666666666666666,[0,-1,0,0,0,0,0],"(i.U.)/min","chemical",true,null,null,1,false,true,0,"IU/min; IU/minute; IU per minute; international units","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per milliliter","[IU]/mL","[IU]/ML","arbitrary",1000000,[-3,0,0,0,0,0,0],"(i.U.)/mL","chemical",true,null,null,1,false,true,0,"IU/mL; IU per mL; international units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"MPL unit per milliliter","[MPL'U]/mL","[MPL'U]/ML","biologic activity of anticardiolipin IgM",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"MPL/mL; MPL U/mL; MPL'U/mL; IgM anticardiolipin units; IgM Phospholipid Units; millilitre ","LOINC","ACnc","Clinical","units for antiphospholipid test\n","1","1","1",1,false],[false,"number per high power field","{#}/[HPF]","/[HPF]","",1,[0,0,0,0,0,0,0],"/HPF",null,false,null,null,1,false,false,0,"#/HPF; # per HPF; number/HPF; numbers per high power field","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"number per low power field","{#}/[LPF]","/[LPF]","",1,[0,0,0,0,0,0,0],"/LPF",null,false,null,null,1,false,false,0,"#/LPF; # per LPF; number/LPF; numbers per low power field","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"IgA antiphosphatidylserine unit ","{APS'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"APS Unit; Phosphatidylserine Antibody IgA Units","LOINC","ACnc","Clinical","unit for antiphospholipid test",null,null,null,null,false],[false,"EIA index","{EIA_index}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"enzyme immunoassay index","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"kaolin clotting time","{KCT'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"KCT","LOINC","Time","Clinical","sensitive test to detect lupus anticoagulants; measured in seconds",null,null,null,null,false],[false,"IgM antiphosphatidylserine unit","{MPS'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"Phosphatidylserine Antibody IgM Measurement ","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"trillion per liter","10*12/L","(10*12)/L","number",1000000000000000,[-3,0,0,0,0,0,0],"(1012)/L","dimless",false,null,null,1,false,false,0,"10^12/L; 10*12 per Liter; trillion per liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^3 (used for cell count)","10*3","10*3","number",1000,[0,0,0,0,0,0,0],"103","dimless",false,null,null,1,false,false,0,"10^3; thousand","LOINC","Num","Clinical","usually used for counting entities (e.g. blood cells) per volume","1","1","10",10,false],[false,"thousand per liter","10*3/L","(10*3)/L","number",1000000,[-3,0,0,0,0,0,0],"(103)/L","dimless",false,null,null,1,false,false,0,"10^3/L; 10*3 per liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"thousand per milliliter","10*3/mL","(10*3)/ML","number",1000000000,[-3,0,0,0,0,0,0],"(103)/mL","dimless",false,null,null,1,false,false,0,"10^3/mL; 10*3 per mL; thousand per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"thousand per microliter","10*3/uL","(10*3)/UL","number",999999999999.9999,[-3,0,0,0,0,0,0],"(103)/μL","dimless",false,null,null,1,false,false,0,"10^3/uL; 10*3 per uL; thousand per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10 thousand per microliter","10*4/uL","(10*4)/UL","number",10000000000000,[-3,0,0,0,0,0,0],"(104)/μL","dimless",false,null,null,1,false,false,0,"10^4/uL; 10*4 per uL; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^5 ","10*5","10*5","number",100000,[0,0,0,0,0,0,0],"105","dimless",false,null,null,1,false,false,0,"one hundred thousand","LOINC","Num","Clinical","","1","1","10",10,false],[false,"10^6","10*6","10*6","number",1000000,[0,0,0,0,0,0,0],"106","dimless",false,null,null,1,false,false,0,"","LOINC","Num","Clinical","","1","1","10",10,false],[false,"million colony forming unit per liter","10*6.[CFU]/L","((10*6).[CFU])/L","number",1000000000,[-3,0,0,0,0,0,0],"((106).CFU)/L","dimless",false,null,null,1,false,true,0,"10*6 CFU/L; 10^6 CFU/L; 10^6CFU; 10^6 CFU per liter; million colony forming units; litre","LOINC","ACnc","Clinical","","1","1","10",10,false],[false,"million international unit","10*6.[IU]","(10*6).[IU]","number",1000000,[0,0,0,0,0,0,0],"(106).(i.U.)","dimless",false,null,null,1,false,true,0,"10*6 IU; 10^6 IU; international units","LOINC","arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","1","1","10",10,false],[false,"million per 24 hour","10*6/(24.h)","(10*6)/HR","number",11.574074074074074,[0,-1,0,0,0,0,0],"(106)/h","dimless",false,null,null,1,false,false,0,"10*6/24hrs; 10^6/24 hrs; 10*6 per 24 hrs; 10^6 per 24 hours","LOINC","NRat","Clinical","","1","1","10",10,false],[false,"million per kilogram","10*6/kg","(10*6)/KG","number",1000,[0,0,-1,0,0,0,0],"(106)/kg","dimless",false,null,null,1,false,false,0,"10^6/kg; 10*6 per kg; 10*6 per kilogram; millions","LOINC","NCnt","Clinical","","1","1","10",10,false],[false,"million per liter","10*6/L","(10*6)/L","number",1000000000,[-3,0,0,0,0,0,0],"(106)/L","dimless",false,null,null,1,false,false,0,"10^6/L; 10*6 per Liter; 10^6 per Liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"million per milliliter","10*6/mL","(10*6)/ML","number",1000000000000,[-3,0,0,0,0,0,0],"(106)/mL","dimless",false,null,null,1,false,false,0,"10^6/mL; 10*6 per mL; 10*6 per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"million per microliter","10*6/uL","(10*6)/UL","number",1000000000000000,[-3,0,0,0,0,0,0],"(106)/μL","dimless",false,null,null,1,false,false,0,"10^6/uL; 10^6 per uL; 10^6/mcl; 10^6 per mcl; 10^6 per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^8","10*8","10*8","number",100000000,[0,0,0,0,0,0,0],"108","dimless",false,null,null,1,false,false,0,"100 million; one hundred million; 10^8","LOINC","Num","Clinical","","1","1","10",10,false],[false,"billion per liter","10*9/L","(10*9)/L","number",1000000000000,[-3,0,0,0,0,0,0],"(109)/L","dimless",false,null,null,1,false,false,0,"10^9/L; 10*9 per Liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"billion per milliliter","10*9/mL","(10*9)/ML","number",1000000000000000,[-3,0,0,0,0,0,0],"(109)/mL","dimless",false,null,null,1,false,false,0,"10^9/mL; 10*9 per mL; 10^9 per mL; 10*9 per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"billion per microliter","10*9/uL","(10*9)/UL","number",1000000000000000000,[-3,0,0,0,0,0,0],"(109)/μL","dimless",false,null,null,1,false,false,0,"10^9/uL; 10^9 per uL; 10^9/mcl; 10^9 per mcl; 10*9 per uL; 10*9 per mcl; 10*9/mcl; 10^9 per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10 liter per minute per square meter","10.L/(min.m2)","L/(MIN.M2)","",0.00016666666666666666,[1,-1,0,0,0,0,0],"L/(min.(m2))",null,false,null,null,1,false,false,0,"10 liters per minutes per square meter; 10 L per min per m2; m^2; 10 L/(min*m2); 10L/(min*m^2); litres; sq. meter; metre; meters squared","LOINC","ArVRat","Clinical","",null,null,null,null,false],[false,"10 liter per minute","10.L/min","L/MIN","",0.00016666666666666666,[3,-1,0,0,0,0,0],"L/min",null,false,null,null,1,false,false,0,"10 liters per minute; 10 L per min; 10L; 10 L/min; litre","LOINC","VRat","Clinical","",null,null,null,null,false],[false,"10 micronewton second per centimeter to the fifth power per square meter","10.uN.s/(cm5.m2)","(UN.S)/(CM5.M2)","",100000000,[-6,-1,1,0,0,0,0],"(μN.s)/(cm5).(m2)",null,false,null,null,1,false,false,0,"dyne seconds per centimeter5 and square meter; dyn.s/(cm5.m2); dyn.s/cm5/m2; cm^5; m^2","LOINC","","Clinical","unit to measure systemic vascular resistance per body surface area",null,null,null,null,false],[false,"24 hour","24.h","HR","",86400,[0,1,0,0,0,0,0],"h",null,false,null,null,1,false,false,0,"24hrs; 24 hrs; 24 hours; days; dy","LOINC","Time","Clinical","",null,null,null,null,false],[false,"ampere per meter","A/m","A/M","electric current",1,[-1,-1,0,0,0,1,0],"A/m","si",true,null,null,1,false,false,0,"A/m; amp/meter; magnetic field strength; H; B; amperes per meter; metre","LOINC","","Clinical","unit of magnetic field strength","C/s","C/S","1",1,false],[false,"centigram","cg","CG","mass",0.01,[0,0,1,0,0,0,0],"cg",null,false,"M",null,1,false,false,0,"centigrams; cg; cgm","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"centiliter","cL","CL","volume",0.00001,[3,0,0,0,0,0,0],"cL","iso1000",true,null,null,1,false,false,0,"centiliters; centilitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"centimeter","cm","CM","length",0.01,[1,0,0,0,0,0,0],"cm",null,false,"L",null,1,false,false,0,"centimeters; centimetres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"centimeter of water","cm[H2O]","CM[H2O]","pressure",98066.5,[-1,-2,1,0,0,0,0],"cm HO2","clinical",true,null,null,1,false,false,0,"cm H2O; cmH2O; centimetres; pressure","LOINC","Pres","Clinical","unit of pressure mostly applies to blood pressure","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of water per liter per second","cm[H2O]/L/s","(CM[H2O]/L)/S","pressure",98066500,[-4,-3,1,0,0,0,0],"((cm HO2)/L)/s","clinical",true,null,null,1,false,false,0,"cm[H2O]/(L/s); cm[H2O].s/L; cm H2O/L/sec; cmH2O/L/sec; cmH2O/Liter; cmH2O per L per secs; centimeters of water per liters per second; centimetres; litres; cm[H2O]/(L/s)","LOINC","PresRat","Clinical","unit used to measure mean pulmonary resistance","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of water per second per meter","cm[H2O]/s/m","(CM[H2O]/S)/M","pressure",98066.5,[-2,-3,1,0,0,0,0],"((cm HO2)/s)/m","clinical",true,null,null,1,false,false,0,"cm[H2O]/(s.m); cm H2O/s/m; cmH2O; cmH2O/sec/m; cmH2O per secs per meters; centimeters of water per seconds per meter; centimetres; metre","LOINC","PresRat","Clinical","unit used to measure pulmonary pressure time product","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of mercury","cm[Hg]","CM[HG]","pressure",1333220,[-1,-2,1,0,0,0,0],"cm Hg","clinical",true,null,null,1,false,false,0,"centimeters of mercury; centimetres; cmHg; cm Hg","LOINC","Pres","Clinical","unit of pressure where 1 cmHg = 10 torr","kPa","KPAL","133.3220",133.322,false],[false,"square centimeter","cm2","CM2","length",0.0001,[2,0,0,0,0,0,0],"cm2",null,false,"L",null,1,false,false,0,"cm^2; sq cm; centimeters squared; square centimeters; centimetre; area","LOINC","Area","Clinical","",null,null,null,null,false],[false,"square centimeter per second","cm2/s","CM2/S","length",0.0001,[2,-1,0,0,0,0,0],"(cm2)/s",null,false,"L",null,1,false,false,0,"cm^2/sec; square centimeters per second; sq cm per sec; cm2; centimeters squared; centimetres","LOINC","AreaRat","Clinical","",null,null,null,null,false],[false,"centipoise","cP","CP","dynamic viscosity",1,[-1,-1,1,0,0,0,0],"cP","cgs",true,null,null,1,false,false,0,"cps; centiposes","LOINC","Visc","Clinical","unit of dynamic viscosity in the CGS system with base units: 10^−3 Pa.s = 1 mPa·.s (1 millipascal second)","dyn.s/cm2","DYN.S/CM2","1",1,false],[false,"centistoke","cSt","CST","kinematic viscosity",0.0000010000000000000002,[2,-1,0,0,0,0,0],"cSt","cgs",true,null,null,1,false,false,0,"centistokes","LOINC","Visc","Clinical","unit for kinematic viscosity with base units of mm^2/s (square millimeter per second)","cm2/s","CM2/S","1",1,false],[false,"dekaliter per minute","daL/min","DAL/MIN","volume",0.00016666666666666666,[3,-1,0,0,0,0,0],"daL/min","iso1000",true,null,null,1,false,false,0,"dekalitres; dekaliters per minute; per min","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"dekaliter per minute per square meter","daL/min/m2","(DAL/MIN)/M2","volume",0.00016666666666666666,[1,-1,0,0,0,0,0],"(daL/min)/(m2)","iso1000",true,null,null,1,false,false,0,"daL/min/m^2; daL/minute/m2; sq. meter; dekaliters per minutes per square meter; meter squared; dekalitres; metre","LOINC","ArVRat","Clinical","The area usually is the body surface area used to normalize cardiovascular measures for patient's size","l",null,"1",1,false],[false,"decibel","dB","DB","level",1,[0,0,0,0,0,0,0],"dB","levels",true,null,"lg",0.1,true,false,0,"decibels","LOINC","LogRto","Clinical","unit most commonly used in acoustics as unit of sound pressure level. (also see B[SPL] or bel sound pressure level). ","1",null,null,1,false],[false,"degree per second","deg/s","DEG/S","plane angle",0.017453292519943295,[0,-1,0,1,0,0,0],"°/s","iso1000",false,null,null,1,false,false,0,"deg/sec; deg per sec; °/sec; twist rate; angular speed; rotational speed","LOINC","ARat","Clinical","unit of angular (rotational) speed used to express turning rate","[pi].rad/360","[PI].RAD/360","2",2,false],[false,"decigram","dg","DG","mass",0.1,[0,0,1,0,0,0,0],"dg",null,false,"M",null,1,false,false,0,"decigrams; dgm; 0.1 grams; 1/10 gm","LOINC","Mass","Clinical","equal to 1/10 gram",null,null,null,null,false],[false,"deciliter","dL","DL","volume",0.0001,[3,0,0,0,0,0,0],"dL","iso1000",true,null,null,1,false,false,0,"deciliters; decilitres; 0.1 liters; 1/10 L","LOINC","Vol","Clinical","equal to 1/10 liter","l",null,"1",1,false],[false,"decimeter","dm","DM","length",0.1,[1,0,0,0,0,0,0],"dm",null,false,"L",null,1,false,false,0,"decimeters; decimetres; 0.1 meters; 1/10 m; 10 cm; centimeters","LOINC","Len","Clinical","equal to 1/10 meter or 10 centimeters",null,null,null,null,false],[false,"square decimeter per square second","dm2/s2","DM2/S2","length",0.010000000000000002,[2,-2,0,0,0,0,0],"(dm2)/(s2)",null,false,"L",null,1,false,false,0,"dm2 per s2; dm^2/s^2; decimeters squared per second squared; sq dm; sq sec","LOINC","EngMass (massic energy)","Clinical","units for energy per unit mass or Joules per kilogram (J/kg = kg.m2/s2/kg = m2/s2) ",null,null,null,null,false],[false,"dyne second per centimeter per square meter","dyn.s/(cm.m2)","(DYN.S)/(CM.M2)","force",1,[-2,-1,1,0,0,0,0],"(dyn.s)/(cm.(m2))","cgs",true,null,null,1,false,false,0,"(dyn*s)/(cm*m2); (dyn*s)/(cm*m^2); dyn s per cm per m2; m^2; dyne seconds per centimeters per square meter; centimetres; sq. meter; squared","LOINC","","Clinical","","g.cm/s2","G.CM/S2","1",1,false],[false,"dyne second per centimeter","dyn.s/cm","(DYN.S)/CM","force",1,[0,-1,1,0,0,0,0],"(dyn.s)/cm","cgs",true,null,null,1,false,false,0,"(dyn*s)/cm; dyn sec per cm; seconds; centimetre; dyne seconds","LOINC","","Clinical","","g.cm/s2","G.CM/S2","1",1,false],[false,"equivalent per liter","eq/L","EQ/L","amount of substance",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"eq/L","chemical",true,null,null,1,false,false,1,"eq/liter; eq/litre; eqs; equivalents per liter; litre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per milliliter","eq/mL","EQ/ML","amount of substance",6.0221367e+29,[-3,0,0,0,0,0,0],"eq/mL","chemical",true,null,null,1,false,false,1,"equivalent/milliliter; equivalents per milliliter; eq per mL; millilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per millimole","eq/mmol","EQ/MMOL","amount of substance",1000,[0,0,0,0,0,0,0],"eq/mmol","chemical",true,null,null,1,false,false,0,"equivalent/millimole; equivalents per millimole; eq per mmol","LOINC","SRto","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per micromole","eq/umol","EQ/UMOL","amount of substance",1000000,[0,0,0,0,0,0,0],"eq/μmol","chemical",true,null,null,1,false,false,0,"equivalent/micromole; equivalents per micromole; eq per umol","LOINC","SRto","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"femtogram","fg","FG","mass",1e-15,[0,0,1,0,0,0,0],"fg",null,false,"M",null,1,false,false,0,"fg; fgm; femtograms; weight","LOINC","Mass","Clinical","equal to 10^-15 grams",null,null,null,null,false],[false,"femtoliter","fL","FL","volume",1e-18,[3,0,0,0,0,0,0],"fL","iso1000",true,null,null,1,false,false,0,"femtolitres; femtoliters","LOINC","Vol; EntVol","Clinical","equal to 10^-15 liters","l",null,"1",1,false],[false,"femtometer","fm","FM","length",1e-15,[1,0,0,0,0,0,0],"fm",null,false,"L",null,1,false,false,0,"femtometres; femtometers","LOINC","Len","Clinical","equal to 10^-15 meters",null,null,null,null,false],[false,"femtomole","fmol","FMOL","amount of substance",602213670,[0,0,0,0,0,0,0],"fmol","si",true,null,null,1,false,false,1,"femtomoles","LOINC","EntSub","Clinical","equal to 10^-15 moles","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per gram","fmol/g","FMOL/G","amount of substance",602213670,[0,0,-1,0,0,0,0],"fmol/g","si",true,null,null,1,false,false,1,"femtomoles; fmol/gm; fmol per gm","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per liter","fmol/L","FMOL/L","amount of substance",602213670000,[-3,0,0,0,0,0,0],"fmol/L","si",true,null,null,1,false,false,1,"femtomoles; fmol per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per milligram","fmol/mg","FMOL/MG","amount of substance",602213670000,[0,0,-1,0,0,0,0],"fmol/mg","si",true,null,null,1,false,false,1,"fmol per mg; femtomoles","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per milliliter","fmol/mL","FMOL/ML","amount of substance",602213670000000,[-3,0,0,0,0,0,0],"fmol/mL","si",true,null,null,1,false,false,1,"femtomoles; millilitre; fmol per mL; fmol per milliliter","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"gram meter","g.m","G.M","mass",1,[1,0,1,0,0,0,0],"g.m",null,false,"M",null,1,false,false,0,"g*m; gxm; meters; metres","LOINC","Enrg","Clinical","Unit for measuring stroke work (heart work)",null,null,null,null,false],[false,"gram per 100 gram","g/(100.g)","G/G","mass",0.01,[0,0,0,0,0,0,0],"g/g",null,false,"M",null,1,false,false,0,"g/100 gm; 100gm; grams per 100 grams; gm per 100 gm","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"gram per 12 hour","g/(12.h)","G/HR","mass",0.000023148148148148147,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/12hrs; 12 hrs; gm per 12 hrs; 12hrs; grams per 12 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 24 hour","g/(24.h)","G/HR","mass",0.000011574074074074073,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/24hrs; gm/24 hrs; gm per 24 hrs; 24hrs; grams per 24 hours; gm/dy; gm per dy; grams per day","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 3 days","g/(3.d)","G/D","mass",0.000003858024691358025,[0,-1,1,0,0,0,0],"g/d",null,false,"M",null,1,false,false,0,"gm/3dy; gm/3 dy; gm per 3 days; grams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 4 hour","g/(4.h)","G/HR","mass",0.00006944444444444444,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/4hrs; gm/4 hrs; gm per 4 hrs; 4hrs; grams per 4 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 48 hour","g/(48.h)","G/HR","mass",0.000005787037037037037,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/48hrs; gm/48 hrs; gm per 48 hrs; 48hrs; grams per 48 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 5 hour","g/(5.h)","G/HR","mass",0.00005555555555555556,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/5hrs; gm/5 hrs; gm per 5 hrs; 5hrs; grams per 5 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 6 hour","g/(6.h)","G/HR","mass",0.000046296296296296294,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/6hrs; gm/6 hrs; gm per 6 hrs; 6hrs; grams per 6 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 72 hour","g/(72.h)","G/HR","mass",0.000003858024691358025,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/72hrs; gm/72 hrs; gm per 72 hrs; 72hrs; grams per 72 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per cubic centimeter","g/cm3","G/CM3","mass",999999.9999999999,[-3,0,1,0,0,0,0],"g/(cm3)",null,false,"M",null,1,false,false,0,"g/cm^3; gm per cm3; g per cm^3; grams per centimeter cubed; cu. cm; centimetre; g/mL; gram per milliliter; millilitre","LOINC","MCnc","Clinical","g/cm3 = g/mL",null,null,null,null,false],[false,"gram per day","g/d","G/D","mass",0.000011574074074074073,[0,-1,1,0,0,0,0],"g/d",null,false,"M",null,1,false,false,0,"gm/dy; gm per dy; grams per day; gm/24hrs; gm/24 hrs; gm per 24 hrs; 24hrs; grams per 24 hours; serving","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per deciliter","g/dL","G/DL","mass",10000,[-3,0,1,0,0,0,0],"g/dL",null,false,"M",null,1,false,false,0,"gm/dL; gm per dL; grams per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per gram","g/g","G/G","mass",1,[0,0,0,0,0,0,0],"g/g",null,false,"M",null,1,false,false,0,"gm; grams","LOINC","MRto ","Clinical","",null,null,null,null,false],[false,"gram per hour","g/h","G/HR","mass",0.0002777777777777778,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/hr; gm per hr; grams; intake; output","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per hour per square meter","g/h/m2","(G/HR)/M2","mass",0.0002777777777777778,[-2,-1,1,0,0,0,0],"(g/h)/(m2)",null,false,"M",null,1,false,false,0,"gm/hr/m2; gm/h/m2; /m^2; sq. m; g per hr per m2; grams per hours per square meter; meter squared; metre","LOINC","ArMRat","Clinical","",null,null,null,null,false],[false,"gram per kilogram","g/kg ","G/KG","mass",0.001,[0,0,0,0,0,0,0],"g/kg",null,false,"M",null,1,false,false,0,"g per kg; gram per kilograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"gram per kilogram per 8 hour ","g/kg/(8.h)","(G/KG)/HR","mass",3.472222222222222e-8,[0,-1,0,0,0,0,0],"(g/kg)/h",null,false,"M",null,1,false,false,0,"g/(8.kg.h); gm/kg/8hrs; 8 hrs; g per kg per 8 hrs; 8hrs; grams per kilograms per 8 hours; shift","LOINC","MCntRat; RelMRat","Clinical","unit often used to describe mass in grams of protein consumed in a 8 hours, divided by the subject's body weight in kilograms. Also used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per day","g/kg/d","(G/KG)/D","mass",1.1574074074074074e-8,[0,-1,0,0,0,0,0],"(g/kg)/d",null,false,"M",null,1,false,false,0,"g/(kg.d); gm/kg/dy; gm per kg per dy; grams per kilograms per day","LOINC","RelMRat","Clinical","unit often used to describe mass in grams of protein consumed in a day, divided by the subject's body weight in kilograms. Also used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per hour","g/kg/h","(G/KG)/HR","mass",2.7777777777777776e-7,[0,-1,0,0,0,0,0],"(g/kg)/h",null,false,"M",null,1,false,false,0,"g/(kg.h); g/kg/hr; g per kg per hrs; grams per kilograms per hour","LOINC","MCntRat; RelMRat","Clinical","unit used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per minute","g/kg/min","(G/KG)/MIN","mass",0.000016666666666666667,[0,-1,0,0,0,0,0],"(g/kg)/min",null,false,"M",null,1,false,false,0,"g/(kg.min); g/kg/min; g per kg per min; grams per kilograms per minute","LOINC","MCntRat; RelMRat","Clinical","unit used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per liter","g/L","G/L","mass",1000,[-3,0,1,0,0,0,0],"g/L",null,false,"M",null,1,false,false,0,"gm per liter; g/liter; grams per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per square meter","g/m2","G/M2","mass",1,[-2,0,1,0,0,0,0],"g/(m2)",null,false,"M",null,1,false,false,0,"g/m^2; gram/square meter; g/sq m; g per m2; g per m^2; grams per square meter; meters squared; metre","LOINC","ArMass","Clinical","Tests measure myocardial mass (heart ventricle system) per body surface area; unit used to measure mass dose per body surface area",null,null,null,null,false],[false,"gram per milligram","g/mg","G/MG","mass",1000,[0,0,0,0,0,0,0],"g/mg",null,false,"M",null,1,false,false,0,"g per mg; grams per milligram","LOINC","MCnt; MRto","Clinical","",null,null,null,null,false],[false,"gram per minute","g/min","G/MIN","mass",0.016666666666666666,[0,-1,1,0,0,0,0],"g/min",null,false,"M",null,1,false,false,0,"g per min; grams per minute; gram/minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per milliliter","g/mL","G/ML","mass",1000000,[-3,0,1,0,0,0,0],"g/mL",null,false,"M",null,1,false,false,0,"g per mL; grams per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per millimole","g/mmol","G/MMOL","mass",1.6605401866749388e-21,[0,0,1,0,0,0,0],"g/mmol",null,false,"M",null,1,false,false,-1,"grams per millimole; g per mmol","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"joule per liter","J/L","J/L","energy",1000000,[-1,-2,1,0,0,0,0],"J/L","si",true,null,null,1,false,false,0,"joules per liter; litre; J per L","LOINC","EngCnc","Clinical","","N.m","N.M","1",1,false],[false,"degree Kelvin per Watt","K/W","K/W","temperature",0.001,[-2,3,-1,0,1,0,0],"K/W",null,false,"C",null,1,false,false,0,"degree Kelvin/Watt; K per W; thermal ohm; thermal resistance; degrees","LOINC","TempEngRat","Clinical","unit for absolute thermal resistance equal to the reciprocal of thermal conductance. Unit used for tests to measure work of breathing",null,null,null,null,false],[false,"kilo international unit per liter","k[IU]/L","K[IU]/L","arbitrary",1000000,[-3,0,0,0,0,0,0],"(ki.U.)/L","chemical",true,null,null,1,false,true,0,"kIU/L; kIU per L; kIU per liter; kilo international units; litre; allergens; allergy units","LOINC","ACnc","Clinical","IgE has an WHO reference standard so IgE allergen testing can be reported as k[IU]/L","[iU]","[IU]","1",1,false],[false,"kilo international unit per milliliter","k[IU]/mL","K[IU]/ML","arbitrary",1000000000,[-3,0,0,0,0,0,0],"(ki.U.)/mL","chemical",true,null,null,1,false,true,0,"kIU/mL; kIU per mL; kIU per milliliter; kilo international units; millilitre; allergens; allergy units","LOINC","ACnc","Clinical","IgE has an WHO reference standard so IgE allergen testing can be reported as k[IU]/mL","[iU]","[IU]","1",1,false],[false,"katal per kilogram","kat/kg","KAT/KG","catalytic activity",602213670000000000000,[0,-1,-1,0,0,0,0],"kat/kg","chemical",true,null,null,1,false,false,1,"kat per kg; katals per kilogram; mol/s/kg; moles per seconds per kilogram","LOINC","CCnt","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"katal per liter","kat/L","KAT/L","catalytic activity",6.0221366999999994e+26,[-3,-1,0,0,0,0,0],"kat/L","chemical",true,null,null,1,false,false,1,"kat per L; katals per liter; litre; mol/s/L; moles per seconds per liter","LOINC","CCnc","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"kilocalorie","kcal","KCAL","energy",4184000,[2,-2,1,0,0,0,0],"kcal","heat",true,null,null,1,false,false,0,"kilogram calories; large calories; food calories; kcals","LOINC","EngRat","Clinical","It is equal to 1000 calories (equal to 4.184 kJ). But in practical usage, kcal refers to food calories which excludes caloric content in fiber and other constitutes that is not digestible by humans. Also see nutrition label Calories ([Cal])","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per 24 hour","kcal/(24.h)","KCAL/HR","energy",48.425925925925924,[2,-3,1,0,0,0,0],"kcal/h","heat",true,null,null,1,false,false,0,"kcal/24hrs; kcal/24 hrs; kcal per 24hrs; kilocalories per 24 hours; kilojoules; kJ/24hr; kJ/(24.h); kJ/dy; kilojoules per days; intake; calories burned; metabolic rate; food calories","","EngRat","Clinical","","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per ounce","kcal/[oz_av]","KCAL/[OZ_AV]","energy",147586.25679704445,[2,-2,0,0,0,0,0],"kcal/oz","heat",true,null,null,1,false,false,0,"kcal/oz; kcal per ozs; large calories per ounces; food calories; servings; international","LOINC","EngCnt","Clinical","used in nutrition to represent calorie of food","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per day","kcal/d","KCAL/D","energy",48.425925925925924,[2,-3,1,0,0,0,0],"kcal/d","heat",true,null,null,1,false,false,0,"kcal/dy; kcal per day; kilocalories per days; kilojoules; kJ/dy; kilojoules per days; intake; calories burned; metabolic rate; food calories","LOINC","EngRat","Clinical","unit in nutrition for food intake (measured in calories) in a day","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per hour","kcal/h","KCAL/HR","energy",1162.2222222222222,[2,-3,1,0,0,0,0],"kcal/h","heat",true,null,null,1,false,false,0,"kcal/hrs; kcals per hr; intake; kilocalories per hours; kilojoules","LOINC","EngRat","Clinical","used in nutrition to represent caloric requirement or consumption","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per kilogram per 24 hour","kcal/kg/(24.h)","(KCAL/KG)/HR","energy",0.04842592592592593,[2,-3,0,0,0,0,0],"(kcal/kg)/h","heat",true,null,null,1,false,false,0,"kcal/kg/24hrs; 24 hrs; kcal per kg per 24hrs; kilocalories per kilograms per 24 hours; kilojoules","LOINC","EngCntRat","Clinical","used in nutrition to represent caloric requirement per day based on subject's body weight in kilograms","cal_th","CAL_TH","1",1,false],[false,"kilogram","kg","KG","mass",1000,[0,0,1,0,0,0,0],"kg",null,false,"M",null,1,false,false,0,"kilograms; kgs","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"kilogram meter per second","kg.m/s","(KG.M)/S","mass",1000,[1,-1,1,0,0,0,0],"(kg.m)/s",null,false,"M",null,1,false,false,0,"kg*m/s; kg.m per sec; kg*m per sec; p; momentum","LOINC","","Clinical","unit for momentum = mass times velocity",null,null,null,null,false],[false,"kilogram per second per square meter","kg/(s.m2)","KG/(S.M2)","mass",1000,[-2,-1,1,0,0,0,0],"kg/(s.(m2))",null,false,"M",null,1,false,false,0,"kg/(s*m2); kg/(s*m^2); kg per s per m2; per sec; per m^2; kilograms per seconds per square meter; meter squared; metre","LOINC","ArMRat","Clinical","",null,null,null,null,false],[false,"kilogram per hour","kg/h","KG/HR","mass",0.2777777777777778,[0,-1,1,0,0,0,0],"kg/h",null,false,"M",null,1,false,false,0,"kg/hr; kg per hr; kilograms per hour","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kilogram per liter","kg/L","KG/L","mass",1000000,[-3,0,1,0,0,0,0],"kg/L",null,false,"M",null,1,false,false,0,"kg per liter; litre; kilograms","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"kilogram per square meter","kg/m2","KG/M2","mass",1000,[-2,0,1,0,0,0,0],"kg/(m2)",null,false,"M",null,1,false,false,0,"kg/m^2; kg/sq. m; kg per m2; per m^2; per sq. m; kilograms; meter squared; metre; BMI","LOINC","Ratio","Clinical","units for body mass index (BMI)",null,null,null,null,false],[false,"kilogram per cubic meter","kg/m3","KG/M3","mass",1000,[-3,0,1,0,0,0,0],"kg/(m3)",null,false,"M",null,1,false,false,0,"kg/m^3; kg/cu. m; kg per m3; per m^3; per cu. m; kilograms; meters cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"kilogram per minute","kg/min","KG/MIN","mass",16.666666666666668,[0,-1,1,0,0,0,0],"kg/min",null,false,"M",null,1,false,false,0,"kilogram/minute; kg per min; kilograms per minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kilogram per mole","kg/mol","KG/MOL","mass",1.6605401866749388e-21,[0,0,1,0,0,0,0],"kg/mol",null,false,"M",null,1,false,false,-1,"kilogram/mole; kg per mol; kilograms per mole","LOINC","SCnt","Clinical","",null,null,null,null,false],[false,"kilogram per second","kg/s","KG/S","mass",1000,[0,-1,1,0,0,0,0],"kg/s",null,false,"M",null,1,false,false,0,"kg/sec; kilogram/second; kg per sec; kilograms; second","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kiloliter","kL","KL","volume",1,[3,0,0,0,0,0,0],"kL","iso1000",true,null,null,1,false,false,0,"kiloliters; kilolitres; m3; m^3; meters cubed; metre","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"kilometer","km","KM","length",1000,[1,0,0,0,0,0,0],"km",null,false,"L",null,1,false,false,0,"kilometers; kilometres; distance","LOINC","Len","Clinical","",null,null,null,null,false],[false,"kilopascal","kPa","KPAL","pressure",1000000,[-1,-2,1,0,0,0,0],"kPa","si",true,null,null,1,false,false,0,"kilopascals; pressure","LOINC","Pres; PPresDiff","Clinical","","N/m2","N/M2","1",1,false],[false,"kilosecond","ks","KS","time",1000,[0,1,0,0,0,0,0],"ks",null,false,"T",null,1,false,false,0,"kiloseconds; ksec","LOINC","Time","Clinical","",null,null,null,null,false],[false,"kilo enzyme unit","kU","KU","catalytic activity",10036894500000000000,[0,-1,0,0,0,0,0],"kU","chemical",true,null,null,1,false,false,1,"units; mmol/min; millimoles per minute","LOINC","CAct","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per gram","kU/g","KU/G","catalytic activity",10036894500000000000,[0,-1,-1,0,0,0,0],"kU/g","chemical",true,null,null,1,false,false,1,"units per grams; kU per gm","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per liter","kU/L","KU/L","catalytic activity",1.00368945e+22,[-3,-1,0,0,0,0,0],"kU/L","chemical",true,null,null,1,false,false,1,"units per liter; litre; enzymatic activity; enzyme activity per volume; activities","LOINC","ACnc; CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per milliliter","kU/mL","KU/ML","catalytic activity",1.00368945e+25,[-3,-1,0,0,0,0,0],"kU/mL","chemical",true,null,null,1,false,false,1,"kU per mL; units per milliliter; millilitre; enzymatic activity per volume; enzyme activities","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"Liters per 24 hour","L/(24.h)","L/HR","volume",1.1574074074074074e-8,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/24hrs; L/24 hrs; L per 24hrs; liters per 24 hours; day; dy; litres; volume flow rate","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per 8 hour","L/(8.h)","L/HR","volume",3.472222222222222e-8,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/8hrs; L/8 hrs; L per 8hrs; liters per 8 hours; litres; volume flow rate; shift","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per minute per square meter","L/(min.m2) ","L/(MIN.M2)","volume",0.000016666666666666667,[1,-1,0,0,0,0,0],"L/(min.(m2))","iso1000",true,null,null,1,false,false,0,"L/(min.m2); L/min/m^2; L/min/sq. meter; L per min per m2; m^2; liters per minutes per square meter; meter squared; litres; metre ","LOINC","ArVRat","Clinical","unit for tests that measure cardiac output per body surface area (cardiac index)","l",null,"1",1,false],[false,"Liters per day","L/d","L/D","volume",1.1574074074074074e-8,[3,-1,0,0,0,0,0],"L/d","iso1000",true,null,null,1,false,false,0,"L/dy; L per day; 24hrs; 24 hrs; 24 hours; liters; litres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per hour","L/h","L/HR","volume",2.7777777777777776e-7,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/hr; L per hr; litres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per kilogram","L/kg","L/KG","volume",0.000001,[3,0,-1,0,0,0,0],"L/kg","iso1000",true,null,null,1,false,false,0,"L per kg; litre","LOINC","VCnt","Clinical","","l",null,"1",1,false],[false,"Liters per liter","L/L","L/L","volume",1,[0,0,0,0,0,0,0],"L/L","iso1000",true,null,null,1,false,false,0,"L per L; liter/liter; litre","LOINC","VFr","Clinical","","l",null,"1",1,false],[false,"Liters per minute","L/min","L/MIN","volume",0.000016666666666666667,[3,-1,0,0,0,0,0],"L/min","iso1000",true,null,null,1,false,false,0,"liters per minute; litre","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per minute per square meter","L/min/m2","(L/MIN)/M2","volume",0.000016666666666666667,[1,-1,0,0,0,0,0],"(L/min)/(m2)","iso1000",true,null,null,1,false,false,0,"L/(min.m2); L/min/m^2; L/min/sq. meter; L per min per m2; m^2; liters per minutes per square meter; meter squared; litres; metre ","","ArVRat","Clinical","unit for tests that measure cardiac output per body surface area (cardiac index)","l",null,"1",1,false],[false,"Liters per second","L/s","L/S","volume",0.001,[3,-1,0,0,0,0,0],"L/s","iso1000",true,null,null,1,false,false,0,"L per sec; litres","LOINC","VRat","Clinical","unit used often to measure gas flow and peak expiratory flow","l",null,"1",1,false],[false,"Liters per second per square second","L/s/s2","(L/S)/S2","volume",0.001,[3,-3,0,0,0,0,0],"(L/s)/(s2)","iso1000",true,null,null,1,false,false,0,"L/s/s^2; L/sec/sec2; L/sec/sec^2; L/sec/sq. sec; L per s per s2; L per sec per sec2; s^2; sec^2; liters per seconds per square second; second squared; litres ","LOINC","ArVRat","Clinical","unit for tests that measure cardiac output/body surface area","l",null,"1",1,false],[false,"lumen square meter","lm.m2","LM.M2","luminous flux",1,[2,0,0,2,0,0,1],"lm.(m2)","si",true,null,null,1,false,false,0,"lm*m2; lm*m^2; lumen meters squared; lumen sq. meters; metres","LOINC","","Clinical","","cd.sr","CD.SR","1",1,false],[false,"meter per second","m/s","M/S","length",1,[1,-1,0,0,0,0,0],"m/s",null,false,"L",null,1,false,false,0,"meter/second; m per sec; meters per second; metres; velocity; speed","LOINC","Vel","Clinical","unit of velocity",null,null,null,null,false],[false,"meter per square second","m/s2","M/S2","length",1,[1,-2,0,0,0,0,0],"m/(s2)",null,false,"L",null,1,false,false,0,"m/s^2; m/sq. sec; m per s2; per s^2; meters per square second; second squared; sq second; metres; acceleration","LOINC","Accel","Clinical","unit of acceleration",null,null,null,null,false],[false,"milli international unit per liter","m[IU]/L","M[IU]/L","arbitrary",1,[-3,0,0,0,0,0,0],"(mi.U.)/L","chemical",true,null,null,1,false,true,0,"mIU/L; m IU/L; mIU per liter; units; litre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"milli international unit per milliliter","m[IU]/mL","M[IU]/ML","arbitrary",1000.0000000000001,[-3,0,0,0,0,0,0],"(mi.U.)/mL","chemical",true,null,null,1,false,true,0,"mIU/mL; m IU/mL; mIU per mL; milli international units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"square meter","m2","M2","length",1,[2,0,0,0,0,0,0],"m2",null,false,"L",null,1,false,false,0,"m^2; sq m; square meters; meters squared; metres","LOINC","Area","Clinical","unit often used to represent body surface area",null,null,null,null,false],[false,"square meter per second","m2/s","M2/S","length",1,[2,-1,0,0,0,0,0],"(m2)/s",null,false,"L",null,1,false,false,0,"m^2/sec; m2 per sec; m^2 per sec; sq m/sec; meters squared/seconds; sq m per sec; meters squared; metres","LOINC","ArRat","Clinical","",null,null,null,null,false],[false,"cubic meter per second","m3/s","M3/S","length",1,[3,-1,0,0,0,0,0],"(m3)/s",null,false,"L",null,1,false,false,0,"m^3/sec; m3 per sec; m^3 per sec; cu m/sec; cubic meters per seconds; meters cubed; metres","LOINC","VRat","Clinical","",null,null,null,null,false],[false,"milliampere","mA","MA","electric current",0.001,[0,-1,0,0,0,1,0],"mA","si",true,null,null,1,false,false,0,"mamp; milliamperes","LOINC","ElpotRat","Clinical","unit of electric current","C/s","C/S","1",1,false],[false,"millibar","mbar","MBAR","pressure",100000,[-1,-2,1,0,0,0,0],"mbar","iso1000",true,null,null,1,false,false,0,"millibars","LOINC","Pres","Clinical","unit of pressure","Pa","PAL","1e5",100000,false],[false,"millibar second per liter","mbar.s/L","(MBAR.S)/L","pressure",100000000,[-4,-1,1,0,0,0,0],"(mbar.s)/L","iso1000",true,null,null,1,false,false,0,"mbar*s/L; mbar.s per L; mbar*s per L; millibar seconds per liter; millibar second per litre","LOINC","","Clinical","unit to measure expiratory resistance","Pa","PAL","1e5",100000,false],[false,"millibar per liter per second","mbar/L/s","(MBAR/L)/S","pressure",100000000,[-4,-3,1,0,0,0,0],"(mbar/L)/s","iso1000",true,null,null,1,false,false,0,"mbar/(L.s); mbar/L/sec; mbar/liter/second; mbar per L per sec; mbar per liter per second; millibars per liters per seconds; litres","LOINC","PresCncRat","Clinical","unit to measure expiratory resistance","Pa","PAL","1e5",100000,false],[false,"milliequivalent","meq","MEQ","amount of substance",602213670000000000000,[0,0,0,0,0,0,0],"meq","chemical",true,null,null,1,false,false,1,"milliequivalents; meqs","LOINC","Sub","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 2 hour","meq/(2.h)","MEQ/HR","amount of substance",83640787500000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/2hrs; meq/2 hrs; meq per 2 hrs; milliequivalents per 2 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 24 hour","meq/(24.h)","MEQ/HR","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/24hrs; meq/24 hrs; meq per 24 hrs; milliequivalents per 24 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 8 hour","meq/(8.h)","MEQ/HR","amount of substance",20910196875000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/8hrs; meq/8 hrs; meq per 8 hrs; milliequivalents per 8 hours; shift","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per day","meq/d","MEQ/D","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"meq/d","chemical",true,null,null,1,false,false,1,"meq/dy; meq per day; milliquivalents per days; meq/24hrs; meq/24 hrs; meq per 24 hrs; milliequivalents per 24 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per deciliter","meq/dL","MEQ/DL","amount of substance",6.022136699999999e+24,[-3,0,0,0,0,0,0],"meq/dL","chemical",true,null,null,1,false,false,1,"meq per dL; milliequivalents per deciliter; decilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per gram","meq/g","MEQ/G","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"meq/g","chemical",true,null,null,1,false,false,1,"mgq/gm; meq per gm; milliequivalents per gram","LOINC","MCnt","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per hour","meq/h","MEQ/HR","amount of substance",167281575000000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/hrs; meq per hrs; milliequivalents per hour","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per kilogram","meq/kg","MEQ/KG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"meq/kg","chemical",true,null,null,1,false,false,1,"meq per kg; milliequivalents per kilogram","LOINC","SCnt","Clinical","equivalence equals moles per valence; used to measure dose per patient body mass","mol","MOL","1",1,false],[false,"milliequivalent per kilogram per hour","meq/kg/h","(MEQ/KG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(meq/kg)/h","chemical",true,null,null,1,false,false,1,"meq/(kg.h); meq/kg/hr; meq per kg per hr; milliequivalents per kilograms per hour","LOINC","SCntRat","Clinical","equivalence equals moles per valence; unit used to measure dose rate per patient body mass","mol","MOL","1",1,false],[false,"milliequivalent per liter","meq/L","MEQ/L","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"meq/L","chemical",true,null,null,1,false,false,1,"milliequivalents per liter; litre; meq per l; acidity","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per square meter","meq/m2","MEQ/M2","amount of substance",602213670000000000000,[-2,0,0,0,0,0,0],"meq/(m2)","chemical",true,null,null,1,false,false,1,"meq/m^2; meq/sq. m; milliequivalents per square meter; meter squared; metre","LOINC","ArSub","Clinical","equivalence equals moles per valence; note that the use of m2 in clinical units ofter refers to body surface area","mol","MOL","1",1,false],[false,"milliequivalent per minute","meq/min","MEQ/MIN","amount of substance",10036894500000000000,[0,-1,0,0,0,0,0],"meq/min","chemical",true,null,null,1,false,false,1,"meq per min; milliequivalents per minute","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per milliliter","meq/mL","MEQ/ML","amount of substance",6.0221367e+26,[-3,0,0,0,0,0,0],"meq/mL","chemical",true,null,null,1,false,false,1,"meq per mL; milliequivalents per milliliter; millilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milligram","mg","MG","mass",0.001,[0,0,1,0,0,0,0],"mg",null,false,"M",null,1,false,false,0,"milligrams","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"milligram per 10 hour","mg/(10.h)","MG/HR","mass",2.7777777777777777e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/10hrs; mg/10 hrs; mg per 10 hrs; milligrams per 10 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 12 hour","mg/(12.h)","MG/HR","mass",2.3148148148148148e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/12hrs; mg/12 hrs; per 12 hrs; 12hrs; milligrams per 12 hours","LOINC","MRat","Clinical","units used for tests in urine",null,null,null,null,false],[false,"milligram per 2 hour","mg/(2.h)","MG/HR","mass",1.3888888888888888e-7,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/2hrs; mg/2 hrs; mg per 2 hrs; 2hrs; milligrams per 2 hours","LOINC","MRat","Clinical","units used for tests in urine",null,null,null,null,false],[false,"milligram per 24 hour","mg/(24.h)","MG/HR","mass",1.1574074074074074e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/24hrs; mg/24 hrs; milligrams per 24 hours; mg/kg/dy; mg per kg per day; milligrams per kilograms per days","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 6 hour","mg/(6.h)","MG/HR","mass",4.6296296296296295e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/6hrs; mg/6 hrs; mg per 6 hrs; 6hrs; milligrams per 6 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 72 hour","mg/(72.h)","MG/HR","mass",3.858024691358025e-9,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/72hrs; mg/72 hrs; 72 hrs; 72hrs; milligrams per 72 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 8 hour","mg/(8.h)","MG/HR","mass",3.472222222222222e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/8hrs; mg/8 hrs; milligrams per 8 hours; shift","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per day","mg/d","MG/D","mass",1.1574074074074074e-8,[0,-1,1,0,0,0,0],"mg/d",null,false,"M",null,1,false,false,0,"mg/24hrs; mg/24 hrs; milligrams per 24 hours; mg/dy; mg per day; milligrams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per deciliter","mg/dL","MG/DL","mass",10,[-3,0,1,0,0,0,0],"mg/dL",null,false,"M",null,1,false,false,0,"mg per dL; milligrams per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per gram","mg/g","MG/G","mass",0.001,[0,0,0,0,0,0,0],"mg/g",null,false,"M",null,1,false,false,0,"mg per gm; milligrams per gram","LOINC","MCnt; MRto","Clinical","",null,null,null,null,false],[false,"milligram per hour","mg/h","MG/HR","mass",2.7777777777777776e-7,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/hr; mg per hr; milligrams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per kilogram","mg/kg","MG/KG","mass",0.000001,[0,0,0,0,0,0,0],"mg/kg",null,false,"M",null,1,false,false,0,"mg per kg; milligrams per kilograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"milligram per kilogram per 8 hour","mg/kg/(8.h)","(MG/KG)/HR","mass",3.472222222222222e-11,[0,-1,0,0,0,0,0],"(mg/kg)/h",null,false,"M",null,1,false,false,0,"mg/(8.h.kg); mg/kg/8hrs; mg/kg/8 hrs; mg per kg per 8hrs; 8 hrs; milligrams per kilograms per 8 hours; shift","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per day","mg/kg/d","(MG/KG)/D","mass",1.1574074074074074e-11,[0,-1,0,0,0,0,0],"(mg/kg)/d",null,false,"M",null,1,false,false,0,"mg/(kg.d); mg/(kg.24.h)mg/kg/dy; mg per kg per day; milligrams per kilograms per days; mg/kg/(24.h); mg/kg/24hrs; 24 hrs; 24 hours","LOINC","RelMRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per hour","mg/kg/h","(MG/KG)/HR","mass",2.7777777777777777e-10,[0,-1,0,0,0,0,0],"(mg/kg)/h",null,false,"M",null,1,false,false,0,"mg/(kg.h); mg/kg/hr; mg per kg per hr; milligrams per kilograms per hour","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per minute","mg/kg/min","(MG/KG)/MIN","mass",1.6666666666666667e-8,[0,-1,0,0,0,0,0],"(mg/kg)/min",null,false,"M",null,1,false,false,0,"mg/(kg.min); mg per kg per min; milligrams per kilograms per minute","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per liter","mg/L","MG/L","mass",1,[-3,0,1,0,0,0,0],"mg/L",null,false,"M",null,1,false,false,0,"mg per l; milligrams per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per square meter","mg/m2","MG/M2","mass",0.001,[-2,0,1,0,0,0,0],"mg/(m2)",null,false,"M",null,1,false,false,0,"mg/m^2; mg/sq. m; mg per m2; mg per m^2; mg per sq. milligrams; meter squared; metre","LOINC","ArMass","Clinical","",null,null,null,null,false],[false,"milligram per cubic meter","mg/m3","MG/M3","mass",0.001,[-3,0,1,0,0,0,0],"mg/(m3)",null,false,"M",null,1,false,false,0,"mg/m^3; mg/cu. m; mg per m3; milligrams per cubic meter; meter cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per milligram","mg/mg","MG/MG","mass",1,[0,0,0,0,0,0,0],"mg/mg",null,false,"M",null,1,false,false,0,"mg per mg; milligrams; milligram/milligram","LOINC","MRto","Clinical","",null,null,null,null,false],[false,"milligram per minute","mg/min","MG/MIN","mass",0.000016666666666666667,[0,-1,1,0,0,0,0],"mg/min",null,false,"M",null,1,false,false,0,"mg per min; milligrams per minutes; milligram/minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per milliliter","mg/mL","MG/ML","mass",1000.0000000000001,[-3,0,1,0,0,0,0],"mg/mL",null,false,"M",null,1,false,false,0,"mg per mL; milligrams per milliliters; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per millimole","mg/mmol","MG/MMOL","mass",1.660540186674939e-24,[0,0,1,0,0,0,0],"mg/mmol",null,false,"M",null,1,false,false,-1,"mg per mmol; milligrams per millimole; ","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"milligram per week","mg/wk","MG/WK","mass",1.6534391534391535e-9,[0,-1,1,0,0,0,0],"mg/wk",null,false,"M",null,1,false,false,0,"mg/week; mg per wk; milligrams per weeks; milligram/week","LOINC","Mrat","Clinical","",null,null,null,null,false],[false,"milliliter","mL","ML","volume",0.000001,[3,0,0,0,0,0,0],"mL","iso1000",true,null,null,1,false,false,0,"milliliters; millilitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"milliliter per 10 hour","mL/(10.h)","ML/HR","volume",2.7777777777777777e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/10hrs; ml/10 hrs; mL per 10hrs; 10 hrs; milliliters per 10 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 12 hour","mL/(12.h)","ML/HR","volume",2.3148148148148147e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/12hrs; ml/12 hrs; mL per 12hrs; 12 hrs; milliliters per 12 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 2 hour","mL/(2.h)","ML/HR","volume",1.3888888888888888e-10,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/2hrs; ml/2 hrs; mL per 2hrs; 2 hrs; milliliters per 2 hours; millilitres ","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 24 hour","mL/(24.h)","ML/HR","volume",1.1574074074074074e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/24hrs; ml/24 hrs; mL per 24hrs; 24 hrs; milliliters per 24 hours; millilitres; ml/dy; /day; ml per dy; days; fluid outputs; fluid inputs; flow rate","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 4 hour","mL/(4.h)","ML/HR","volume",6.944444444444444e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/4hrs; ml/4 hrs; mL per 4hrs; 4 hrs; milliliters per 4 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 5 hour","mL/(5.h)","ML/HR","volume",5.5555555555555553e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/5hrs; ml/5 hrs; mL per 5hrs; 5 hrs; milliliters per 5 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 6 hour","mL/(6.h)","ML/HR","volume",4.6296296296296294e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/6hrs; ml/6 hrs; mL per 6hrs; 6 hrs; milliliters per 6 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 72 hour","mL/(72.h)","ML/HR","volume",3.8580246913580245e-12,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/72hrs; ml/72 hrs; mL per 72hrs; 72 hrs; milliliters per 72 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 8 hour","mL/(8.h)","ML/HR","volume",3.472222222222222e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/8hrs; ml/8 hrs; mL per 8hrs; 8 hrs; milliliters per 8 hours; millilitres; shift","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 8 hour per kilogram","mL/(8.h)/kg","(ML/HR)/KG","volume",3.472222222222222e-14,[3,-1,-1,0,0,0,0],"(mL/h)/kg","iso1000",true,null,null,1,false,false,0,"mL/kg/(8.h); ml/8h/kg; ml/8 h/kg; ml/8hr/kg; ml/8 hr/kgr; mL per 8h per kg; 8 h; 8hr; 8 hr; milliliters per 8 hours per kilogram; millilitres; shift","LOINC","VRatCnt","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per square inch (international)","mL/[sin_i]","ML/[SIN_I]","volume",0.0015500031000061998,[1,0,0,0,0,0,0],"mL","iso1000",true,null,null,1,false,false,0,"mL/sin; mL/in2; mL/in^2; mL per sin; in2; in^2; sq. in; milliliters per square inch; inch squared","LOINC","ArVol","Clinical","","l",null,"1",1,false],[false,"milliliter per centimeter of water","mL/cm[H2O]","ML/CM[H2O]","volume",1.0197162129779282e-11,[4,2,-1,0,0,0,0],"mL/(cm HO2)","iso1000",true,null,null,1,false,false,0,"milliliters per centimeter of water; millilitre per centimetre of water; millilitres per centimetre of water; mL/cmH2O; mL/cm H2O; mL per cmH2O; mL per cm H2O","LOINC","Compli","Clinical","unit used to measure dynamic lung compliance","l",null,"1",1,false],[false,"milliliter per day","mL/d","ML/D","volume",1.1574074074074074e-11,[3,-1,0,0,0,0,0],"mL/d","iso1000",true,null,null,1,false,false,0,"ml/day; ml per day; milliliters per day; 24 hours; 24hrs; millilitre;","LOINC","VRat","Clinical","usually used to measure fluid output or input; flow rate","l",null,"1",1,false],[false,"milliliter per deciliter","mL/dL","ML/DL","volume",0.009999999999999998,[0,0,0,0,0,0,0],"mL/dL","iso1000",true,null,null,1,false,false,0,"mL per dL; millilitres; decilitre; milliliters","LOINC","VFr; VFrDiff","Clinical","","l",null,"1",1,false],[false,"milliliter per hour","mL/h","ML/HR","volume",2.7777777777777777e-10,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"mL/hr; mL per hr; milliliters per hour; millilitres; fluid intake; fluid output","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per kilogram","mL/kg","ML/KG","volume",9.999999999999999e-10,[3,0,-1,0,0,0,0],"mL/kg","iso1000",true,null,null,1,false,false,0,"mL per kg; milliliters per kilogram; millilitres","LOINC","VCnt","Clinical","","l",null,"1",1,false],[false,"milliliter per kilogram per 8 hour","mL/kg/(8.h)","(ML/KG)/HR","volume",3.472222222222222e-14,[3,-1,-1,0,0,0,0],"(mL/kg)/h","iso1000",true,null,null,1,false,false,0,"mL/(8.h.kg); mL/kg/8hrs; mL/kg/8 hrs; mL per kg per 8hrs; 8 hrs; milliliters per kilograms per 8 hours; millilitres; shift","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per day","mL/kg/d","(ML/KG)/D","volume",1.1574074074074072e-14,[3,-1,-1,0,0,0,0],"(mL/kg)/d","iso1000",true,null,null,1,false,false,0,"mL/(kg.d); mL/kg/dy; mL per kg per day; milliliters per kilograms per day; mg/kg/24hrs; 24 hrs; per 24 hours millilitres","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per hour","mL/kg/h","(ML/KG)/HR","volume",2.7777777777777774e-13,[3,-1,-1,0,0,0,0],"(mL/kg)/h","iso1000",true,null,null,1,false,false,0,"mL/(kg.h); mL/kg/hr; mL per kg per hr; milliliters per kilograms per hour; millilitres","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per minute","mL/kg/min","(ML/KG)/MIN","volume",1.6666666666666664e-11,[3,-1,-1,0,0,0,0],"(mL/kg)/min","iso1000",true,null,null,1,false,false,0,"mL/(kg.min); mL/kg/dy; mL per kg per day; milliliters per kilograms per day; millilitres","LOINC","RelEngRat","Clinical","used for tests that measure activity metabolic rate compared to standard resting metabolic rate ","l",null,"1",1,false],[false,"milliliter per square meter","mL/m2","ML/M2","volume",0.000001,[1,0,0,0,0,0,0],"mL/(m2)","iso1000",true,null,null,1,false,false,0,"mL/m^2; mL/sq. meter; mL per m2; m^2; sq. meter; milliliters per square meter; millilitres; meter squared","LOINC","ArVol","Clinical","used for tests that relate to heart work - e.g. ventricular stroke volume; atrial volume per body surface area","l",null,"1",1,false],[false,"milliliter per millibar","mL/mbar","ML/MBAR","volume",1e-11,[4,2,-1,0,0,0,0],"mL/mbar","iso1000",true,null,null,1,false,false,0,"mL per mbar; milliliters per millibar; millilitres","LOINC","","Clinical","unit used to measure dynamic lung compliance","l",null,"1",1,false],[false,"milliliter per minute","mL/min","ML/MIN","volume",1.6666666666666667e-8,[3,-1,0,0,0,0,0],"mL/min","iso1000",true,null,null,1,false,false,0,"mL per min; milliliters; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per minute per square meter","mL/min/m2","(ML/MIN)/M2","volume",1.6666666666666667e-8,[1,-1,0,0,0,0,0],"(mL/min)/(m2)","iso1000",true,null,null,1,false,false,0,"ml/min/m^2; ml/min/sq. meter; mL per min per m2; m^2; sq. meter; milliliters per minutes per square meter; millilitres; metre; meter squared","LOINC","ArVRat","Clinical","unit used to measure volume per body surface area; oxygen consumption index","l",null,"1",1,false],[false,"milliliter per millimeter","mL/mm","ML/MM","volume",0.001,[2,0,0,0,0,0,0],"mL/mm","iso1000",true,null,null,1,false,false,0,"mL per mm; milliliters per millimeter; millilitres; millimetre","LOINC","Lineic Volume","Clinical","","l",null,"1",1,false],[false,"milliliter per second","mL/s","ML/S","volume",0.000001,[3,-1,0,0,0,0,0],"mL/s","iso1000",true,null,null,1,false,false,0,"ml/sec; mL per sec; milliliters per second; millilitres","LOINC","Vel; VelRat; VRat","Clinical","","l",null,"1",1,false],[false,"millimeter","mm","MM","length",0.001,[1,0,0,0,0,0,0],"mm",null,false,"L",null,1,false,false,0,"millimeters; millimetres; height; length; diameter; thickness; axis; curvature; size","LOINC","Len","Clinical","",null,null,null,null,false],[false,"millimeter per hour","mm/h","MM/HR","length",2.7777777777777776e-7,[1,-1,0,0,0,0,0],"mm/h",null,false,"L",null,1,false,false,0,"mm/hr; mm per hr; millimeters per hour; millimetres","LOINC","Vel","Clinical","unit to measure sedimentation rate",null,null,null,null,false],[false,"millimeter per minute","mm/min","MM/MIN","length",0.000016666666666666667,[1,-1,0,0,0,0,0],"mm/min",null,false,"L",null,1,false,false,0,"mm per min; millimeters per minute; millimetres","LOINC","Vel","Clinical","",null,null,null,null,false],[false,"millimeter of water","mm[H2O]","MM[H2O]","pressure",9806.65,[-1,-2,1,0,0,0,0],"mm HO2","clinical",true,null,null,1,false,false,0,"mmH2O; mm H2O; millimeters of water; millimetres","LOINC","Pres","Clinical","","kPa","KPAL","980665e-5",9.80665,false],[false,"millimeter of mercury","mm[Hg]","MM[HG]","pressure",133322,[-1,-2,1,0,0,0,0],"mm Hg","clinical",true,null,null,1,false,false,0,"mmHg; mm Hg; millimeters of mercury; millimetres","LOINC","Pres; PPres; Ratio","Clinical","1 mm[Hg] = 1 torr; unit to measure blood pressure","kPa","KPAL","133.3220",133.322,false],[false,"square millimeter","mm2","MM2","length",0.000001,[2,0,0,0,0,0,0],"mm2",null,false,"L",null,1,false,false,0,"mm^2; sq. mm.; sq. millimeters; millimeters squared; millimetres","LOINC","Area","Clinical","",null,null,null,null,false],[false,"millimole","mmol","MMOL","amount of substance",602213670000000000000,[0,0,0,0,0,0,0],"mmol","si",true,null,null,1,false,false,1,"millimoles","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 12 hour","mmol/(12.h)","MMOL/HR","amount of substance",13940131250000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/12hrs; mmol/12 hrs; mmol per 12 hrs; 12hrs; millimoles per 12 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 2 hour","mmol/(2.h)","MMOL/HR","amount of substance",83640787500000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/2hrs; mmol/2 hrs; mmol per 2 hrs; 2hrs; millimoles per 2 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 24 hour","mmol/(24.h)","MMOL/HR","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/24hrs; mmol/24 hrs; mmol per 24 hrs; 24hrs; millimoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 5 hour","mmol/(5.h)","MMOL/HR","amount of substance",33456315000000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/5hrs; mmol/5 hrs; mmol per 5 hrs; 5hrs; millimoles per 5 hours","LOINC","SRat","Clinical","unit for tests related to doses","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 6 hour","mmol/(6.h)","MMOL/HR","amount of substance",27880262500000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/6hrs; mmol/6 hrs; mmol per 6 hrs; 6hrs; millimoles per 6 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 8 hour","mmol/(8.h)","MMOL/HR","amount of substance",20910196875000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/8hrs; mmol/8 hrs; mmol per 8 hrs; 8hrs; millimoles per 8 hours; shift","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per day","mmol/d","MMOL/D","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"mmol/d","si",true,null,null,1,false,false,1,"mmol/24hrs; mmol/24 hrs; mmol per 24 hrs; 24hrs; millimoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per deciliter","mmol/dL","MMOL/DL","amount of substance",6.022136699999999e+24,[-3,0,0,0,0,0,0],"mmol/dL","si",true,null,null,1,false,false,1,"mmol per dL; millimoles; decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per gram","mmol/g","MMOL/G","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"mmol/g","si",true,null,null,1,false,false,1,"mmol per gram; millimoles","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per hour","mmol/h","MMOL/HR","amount of substance",167281575000000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/hr; mmol per hr; millimoles per hour","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram","mmol/kg","MMOL/KG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"mmol/kg","si",true,null,null,1,false,false,1,"mmol per kg; millimoles per kilogram","LOINC","SCnt","Clinical","unit for tests related to stool","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per 8 hour","mmol/kg/(8.h)","(MMOL/KG)/HR","amount of substance",20910196875000,[0,-1,-1,0,0,0,0],"(mmol/kg)/h","si",true,null,null,1,false,false,1,"mmol/(8.h.kg); mmol/kg/8hrs; mmol/kg/8 hrs; mmol per kg per 8hrs; 8 hrs; millimoles per kilograms per 8 hours; shift","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per day","mmol/kg/d","(MMOL/KG)/D","amount of substance",6970065625000,[0,-1,-1,0,0,0,0],"(mmol/kg)/d","si",true,null,null,1,false,false,1,"mmol/kg/dy; mmol/kg/day; mmol per kg per dy; millimoles per kilograms per day","LOINC","RelSRat","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per hour","mmol/kg/h","(MMOL/KG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(mmol/kg)/h","si",true,null,null,1,false,false,1,"mmol/kg/hr; mmol per kg per hr; millimoles per kilograms per hour","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per minute","mmol/kg/min","(MMOL/KG)/MIN","amount of substance",10036894500000000,[0,-1,-1,0,0,0,0],"(mmol/kg)/min","si",true,null,null,1,false,false,1,"mmol/(kg.min); mmol/kg/min; mmol per kg per min; millimoles per kilograms per minute","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass; note that the unit for the enzyme unit U = umol/min. mmol/kg/min = kU/kg; ","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per liter","mmol/L","MMOL/L","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"mmol/L","si",true,null,null,1,false,false,1,"mmol per L; millimoles per liter; litre","LOINC","SCnc","Clinical","unit for tests related to doses","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per square meter","mmol/m2","MMOL/M2","amount of substance",602213670000000000000,[-2,0,0,0,0,0,0],"mmol/(m2)","si",true,null,null,1,false,false,1,"mmol/m^2; mmol/sq. meter; mmol per m2; m^2; sq. meter; millimoles; meter squared; metre","LOINC","ArSub","Clinical","unit used to measure molar dose per patient body surface area","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per minute","mmol/min","MMOL/MIN","amount of substance",10036894500000000000,[0,-1,0,0,0,0,0],"mmol/min","si",true,null,null,1,false,false,1,"mmol per min; millimoles per minute","LOINC","Srat; CAct","Clinical","unit for the enzyme unit U = umol/min. mmol/min = kU","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per millimole","mmol/mmol","MMOL/MMOL","amount of substance",1,[0,0,0,0,0,0,0],"mmol/mmol","si",true,null,null,1,false,false,0,"mmol per mmol; millimoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per mole","mmol/mol","MMOL/MOL","amount of substance",0.001,[0,0,0,0,0,0,0],"mmol/mol","si",true,null,null,1,false,false,0,"mmol per mol; millimoles per mole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per second per liter","mmol/s/L","(MMOL/S)/L","amount of substance",6.0221367e+23,[-3,-1,0,0,0,0,0],"(mmol/s)/L","si",true,null,null,1,false,false,1,"mmol/sec/L; mmol per s per L; per sec; millimoles per seconds per liter; litre","LOINC","CCnc ","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per kilogram","mol/kg","MOL/KG","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"mol/kg","si",true,null,null,1,false,false,1,"mol per kg; moles; mols","LOINC","SCnt","Clinical","unit for tests related to stool","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per kilogram per second","mol/kg/s","(MOL/KG)/S","amount of substance",602213670000000000000,[0,-1,-1,0,0,0,0],"(mol/kg)/s","si",true,null,null,1,false,false,1,"mol/kg/sec; mol per kg per sec; moles per kilograms per second; mols","LOINC","CCnt","Clinical","unit of catalytic activity (mol/s) per mass (kg)","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per liter","mol/L","MOL/L","amount of substance",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"mol/L","si",true,null,null,1,false,false,1,"mol per L; moles per liter; litre; moles; mols","LOINC","SCnc","Clinical","unit often used in tests measuring oxygen content","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per cubic meter","mol/m3","MOL/M3","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"mol/(m3)","si",true,null,null,1,false,false,1,"mol/m^3; mol/cu. m; mol per m3; m^3; cu. meter; mols; moles; meters cubed; metre; mole per kiloliter; kilolitre; mol/kL","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per milliliter","mol/mL","MOL/ML","amount of substance",6.0221367e+29,[-3,0,0,0,0,0,0],"mol/mL","si",true,null,null,1,false,false,1,"mol per mL; moles; millilitre; mols","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per mole","mol/mol","MOL/MOL","amount of substance",1,[0,0,0,0,0,0,0],"mol/mol","si",true,null,null,1,false,false,0,"mol per mol; moles per mol; mols","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per second","mol/s","MOL/S","amount of substance",6.0221367e+23,[0,-1,0,0,0,0,0],"mol/s","si",true,null,null,1,false,false,1,"mol per sec; moles per second; mols","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"milliosmole","mosm","MOSM","amount of substance (dissolved particles)",602213670000000000000,[0,0,0,0,0,0,0],"mosm","chemical",true,null,null,1,false,false,1,"milliosmoles","LOINC","Osmol","Clinical","equal to 1/1000 of an osmole","mol","MOL","1",1,false],[false,"milliosmole per kilogram","mosm/kg","MOSM/KG","amount of substance (dissolved particles)",602213670000000000,[0,0,-1,0,0,0,0],"mosm/kg","chemical",true,null,null,1,false,false,1,"mosm per kg; milliosmoles per kilogram","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"milliosmole per liter","mosm/L","MOSM/L","amount of substance (dissolved particles)",6.0221367e+23,[-3,0,0,0,0,0,0],"mosm/L","chemical",true,null,null,1,false,false,1,"mosm per liter; litre; milliosmoles","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"millipascal","mPa","MPAL","pressure",1,[-1,-2,1,0,0,0,0],"mPa","si",true,null,null,1,false,false,0,"millipascals","LOINC","Pres","Clinical","unit of pressure","N/m2","N/M2","1",1,false],[false,"millipascal second","mPa.s","MPAL.S","pressure",1,[-1,-1,1,0,0,0,0],"mPa.s","si",true,null,null,1,false,false,0,"mPa*s; millipoise; mP; dynamic viscosity","LOINC","Visc","Clinical","base units for millipoise, a measurement of dynamic viscosity","N/m2","N/M2","1",1,false],[false,"megasecond","Ms","MAS","time",1000000,[0,1,0,0,0,0,0],"Ms",null,false,"T",null,1,false,false,0,"megaseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"millisecond","ms","MS","time",0.001,[0,1,0,0,0,0,0],"ms",null,false,"T",null,1,false,false,0,"milliseconds; duration","LOINC","Time","Clinical","",null,null,null,null,false],[false,"milli enzyme unit per gram","mU/g","MU/G","catalytic activity",10036894500000,[0,-1,-1,0,0,0,0],"mU/g","chemical",true,null,null,1,false,false,1,"mU per gm; milli enzyme units per gram; enzyme activity; enzymatic activity per mass","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per liter","mU/L","MU/L","catalytic activity",10036894500000000,[-3,-1,0,0,0,0,0],"mU/L","chemical",true,null,null,1,false,false,1,"mU per liter; litre; milli enzyme units enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milligram","mU/mg","MU/MG","catalytic activity",10036894500000000,[0,-1,-1,0,0,0,0],"mU/mg","chemical",true,null,null,1,false,false,1,"mU per mg; milli enzyme units per milligram","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milliliter","mU/mL","MU/ML","catalytic activity",10036894500000000000,[-3,-1,0,0,0,0,0],"mU/mL","chemical",true,null,null,1,false,false,1,"mU per mL; milli enzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milliliter per minute","mU/mL/min","(MU/ML)/MIN","catalytic activity",167281575000000000,[-3,-2,0,0,0,0,0],"(mU/mL)/min","chemical",true,null,null,1,false,false,1,"mU per mL per min; mU per milliliters per minute; millilitres; milli enzyme units; enzymatic activity; enzyme activity","LOINC","CCncRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"millivolt","mV","MV","electric potential",1,[2,-2,1,0,0,-1,0],"mV","si",true,null,null,1,false,false,0,"millivolts","LOINC","Elpot","Clinical","unit of electric potential (voltage)","J/C","J/C","1",1,false],[false,"Newton centimeter","N.cm","N.CM","force",10,[2,-2,1,0,0,0,0],"N.cm","si",true,null,null,1,false,false,0,"N*cm; Ncm; N cm; Newton*centimeters; Newton* centimetres; torque; work","LOINC","","Clinical","as a measurement of work, N.cm = 1/100 Joules;\nnote that N.m is the standard unit of measurement for torque (although dimensionally equivalent to Joule), and N.cm can also be thought of as a torqe unit","kg.m/s2","KG.M/S2","1",1,false],[false,"Newton second","N.s","N.S","force",1000,[1,-1,1,0,0,0,0],"N.s","si",true,null,null,1,false,false,0,"Newton*seconds; N*s; N s; Ns; impulse; imp","LOINC","","Clinical","standard unit of impulse","kg.m/s2","KG.M/S2","1",1,false],[false,"nanogram","ng","NG","mass",1e-9,[0,0,1,0,0,0,0],"ng",null,false,"M",null,1,false,false,0,"nanograms","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"nanogram per 24 hour","ng/(24.h)","NG/HR","mass",1.1574074074074075e-14,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/24hrs; ng/24 hrs; nanograms per 24 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per 8 hour","ng/(8.h)","NG/HR","mass",3.4722222222222224e-14,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/8hrs; ng/8 hrs; nanograms per 8 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per million","ng/10*6","NG/(10*6)","mass",1e-15,[0,0,1,0,0,0,0],"ng/(106)",null,false,"M",null,1,false,false,0,"ng/10^6; ng per 10*6; 10^6; nanograms","LOINC","MNum","Clinical","",null,null,null,null,false],[false,"nanogram per day","ng/d","NG/D","mass",1.1574074074074075e-14,[0,-1,1,0,0,0,0],"ng/d",null,false,"M",null,1,false,false,0,"ng/dy; ng per day; nanograms ","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per deciliter","ng/dL","NG/DL","mass",0.00001,[-3,0,1,0,0,0,0],"ng/dL",null,false,"M",null,1,false,false,0,"ng per dL; nanograms per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per gram","ng/g","NG/G","mass",1e-9,[0,0,0,0,0,0,0],"ng/g",null,false,"M",null,1,false,false,0,"ng/gm; ng per gm; nanograms per gram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per hour","ng/h","NG/HR","mass",2.777777777777778e-13,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/hr; ng per hr; nanograms per hour","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per kilogram","ng/kg","NG/KG","mass",1e-12,[0,0,0,0,0,0,0],"ng/kg",null,false,"M",null,1,false,false,0,"ng per kg; nanograms per kilogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per kilogram per 8 hour","ng/kg/(8.h)","(NG/KG)/HR","mass",3.472222222222222e-17,[0,-1,0,0,0,0,0],"(ng/kg)/h",null,false,"M",null,1,false,false,0,"ng/(8.h.kg); ng/kg/8hrs; ng/kg/8 hrs; ng per kg per 8hrs; 8 hrs; nanograms per kilograms per 8 hours; shift","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per kilogram per hour","ng/kg/h","(NG/KG)/HR","mass",2.7777777777777775e-16,[0,-1,0,0,0,0,0],"(ng/kg)/h",null,false,"M",null,1,false,false,0,"ng/(kg.h); ng/kg/hr; ng per kg per hr; nanograms per kilograms per hour","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per kilogram per minute","ng/kg/min","(NG/KG)/MIN","mass",1.6666666666666667e-14,[0,-1,0,0,0,0,0],"(ng/kg)/min",null,false,"M",null,1,false,false,0,"ng/(kg.min); ng per kg per min; nanograms per kilograms per minute","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per liter","ng/L","NG/L","mass",0.000001,[-3,0,1,0,0,0,0],"ng/L",null,false,"M",null,1,false,false,0,"ng per L; nanograms per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per square meter","ng/m2","NG/M2","mass",1e-9,[-2,0,1,0,0,0,0],"ng/(m2)",null,false,"M",null,1,false,false,0,"ng/m^2; ng/sq. m; ng per m2; m^2; sq. meter; nanograms; meter squared; metre","LOINC","ArMass","Clinical","unit used to measure mass dose per patient body surface area",null,null,null,null,false],[false,"nanogram per milligram","ng/mg","NG/MG","mass",0.000001,[0,0,0,0,0,0,0],"ng/mg",null,false,"M",null,1,false,false,0,"ng per mg; nanograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per milligram per hour","ng/mg/h","(NG/MG)/HR","mass",2.7777777777777777e-10,[0,-1,0,0,0,0,0],"(ng/mg)/h",null,false,"M",null,1,false,false,0,"ng/mg/hr; ng per mg per hr; nanograms per milligrams per hour","LOINC","MRtoRat ","Clinical","",null,null,null,null,false],[false,"nanogram per minute","ng/min","NG/MIN","mass",1.6666666666666667e-11,[0,-1,1,0,0,0,0],"ng/min",null,false,"M",null,1,false,false,0,"ng per min; nanograms","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per millliiter","ng/mL","NG/ML","mass",0.001,[-3,0,1,0,0,0,0],"ng/mL",null,false,"M",null,1,false,false,0,"ng per mL; nanograms; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per milliliter per hour","ng/mL/h","(NG/ML)/HR","mass",2.7777777777777776e-7,[-3,-1,1,0,0,0,0],"(ng/mL)/h",null,false,"M",null,1,false,false,0,"ng/mL/hr; ng per mL per mL; nanograms per milliliter per hour; nanogram per millilitre per hour; nanograms per millilitre per hour; enzymatic activity per volume; enzyme activity per milliliters","LOINC","CCnc","Clinical","tests that measure enzymatic activity",null,null,null,null,false],[false,"nanogram per second","ng/s","NG/S","mass",1e-9,[0,-1,1,0,0,0,0],"ng/s",null,false,"M",null,1,false,false,0,"ng/sec; ng per sec; nanograms per second","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per enzyme unit","ng/U","NG/U","mass",9.963241120049634e-26,[0,1,1,0,0,0,0],"ng/U",null,false,"M",null,1,false,false,-1,"ng per U; nanograms per enzyme unit","LOINC","CMass","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)",null,null,null,null,false],[false,"nanokatal","nkat","NKAT","catalytic activity",602213670000000,[0,-1,0,0,0,0,0],"nkat","chemical",true,null,null,1,false,false,1,"nanokatals","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"nanoliter","nL","NL","volume",1.0000000000000002e-12,[3,0,0,0,0,0,0],"nL","iso1000",true,null,null,1,false,false,0,"nanoliters; nanolitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"nanometer","nm","NM","length",1e-9,[1,0,0,0,0,0,0],"nm",null,false,"L",null,1,false,false,0,"nanometers; nanometres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"nanometer per second per liter","nm/s/L","(NM/S)/L","length",0.000001,[-2,-1,0,0,0,0,0],"(nm/s)/L",null,false,"L",null,1,false,false,0,"nm/sec/liter; nm/sec/litre; nm per s per l; nm per sec per l; nanometers per second per liter; nanometre per second per litre; nanometres per second per litre","LOINC","VelCnc","Clinical","",null,null,null,null,false],[false,"nanomole","nmol","NMOL","amount of substance",602213670000000,[0,0,0,0,0,0,0],"nmol","si",true,null,null,1,false,false,1,"nanomoles","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per 24 hour","nmol/(24.h)","NMOL/HR","amount of substance",6970065625,[0,-1,0,0,0,0,0],"nmol/h","si",true,null,null,1,false,false,1,"nmol/24hr; nmol/24 hr; nanomoles per 24 hours; nmol/day; nanomoles per day; nmol per day; nanomole/day; nanomol/day","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per day","nmol/d","NMOL/D","amount of substance",6970065625,[0,-1,0,0,0,0,0],"nmol/d","si",true,null,null,1,false,false,1,"nmol/day; nanomoles per day; nmol per day; nanomole/day; nanomol/day; nmol/24hr; nmol/24 hr; nanomoles per 24 hours; ","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per deciliter","nmol/dL","NMOL/DL","amount of substance",6022136700000000000,[-3,0,0,0,0,0,0],"nmol/dL","si",true,null,null,1,false,false,1,"nmol per dL; nanomoles per deciliter; nanomole per decilitre; nanomoles per decilitre; nanomole/deciliter; nanomole/decilitre; nanomol/deciliter; nanomol/decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per gram","nmol/g","NMOL/G","amount of substance",602213670000000,[0,0,-1,0,0,0,0],"nmol/g","si",true,null,null,1,false,false,1,"nmol per gram; nanomoles per gram; nanomole/gram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per hour per liter","nmol/h/L","(NMOL/HR)/L","amount of substance",167281575000000,[-3,-1,0,0,0,0,0],"(nmol/h)/L","si",true,null,null,1,false,false,1,"nmol/hrs/L; nmol per hrs per L; nanomoles per hours per liter; litre; enzymatic activity per volume; enzyme activities","LOINC","CCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per liter","nmol/L","NMOL/L","amount of substance",602213670000000000,[-3,0,0,0,0,0,0],"nmol/L","si",true,null,null,1,false,false,1,"nmol per L; nanomoles per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram","nmol/mg","NMOL/MG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"nmol/mg","si",true,null,null,1,false,false,1,"nmol per mg; nanomoles per milligram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram per hour","nmol/mg/h","(NMOL/MG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(nmol/mg)/h","si",true,null,null,1,false,false,1,"nmol/mg/hr; nmol per mg per hr; nanomoles per milligrams per hour","LOINC","SCntRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram of protein","nmol/mg{prot}","NMOL/MG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"nmol/mg","si",true,null,null,1,false,false,1,"nanomoles; nmol/mg prot; nmol per mg prot","LOINC","Ratio; CCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per minute","nmol/min","NMOL/MIN","amount of substance",10036894500000,[0,-1,0,0,0,0,0],"nmol/min","si",true,null,null,1,false,false,1,"nmol per min; nanomoles per minute; milli enzyme units; enzyme activity per volume; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/min = mU (milli enzyme unit)","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per minute per milliliter","nmol/min/mL","(NMOL/MIN)/ML","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(nmol/min)/mL","si",true,null,null,1,false,false,1,"nmol per min per mL; nanomoles per minutes per milliliter; millilitre; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/mL/min = mU/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter","nmol/mL","NMOL/ML","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"nmol/mL","si",true,null,null,1,false,false,1,"nmol per mL; nanomoles per milliliter; millilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter per hour","nmol/mL/h","(NMOL/ML)/HR","amount of substance",167281575000000000,[-3,-1,0,0,0,0,0],"(nmol/mL)/h","si",true,null,null,1,false,false,1,"nmol/mL/hr; nmol per mL per hr; nanomoles per milliliters per hour; millilitres; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter per minute","nmol/mL/min","(NMOL/ML)/MIN","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(nmol/mL)/min","si",true,null,null,1,false,false,1,"nmol per mL per min; nanomoles per milliliters per min; millilitres; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/mL/min = mU/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per millimole","nmol/mmol","NMOL/MMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"nmol/mmol","si",true,null,null,1,false,false,0,"nmol per mmol; nanomoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per millimole of creatinine","nmol/mmol{creat}","NMOL/MMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"nmol/mmol","si",true,null,null,1,false,false,0,"nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per mole","nmol/mol","NMOL/MOL","amount of substance",1e-9,[0,0,0,0,0,0,0],"nmol/mol","si",true,null,null,1,false,false,0,"nmol per mole; nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per nanomole","nmol/nmol","NMOL/NMOL","amount of substance",1,[0,0,0,0,0,0,0],"nmol/nmol","si",true,null,null,1,false,false,0,"nmol per nmol; nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per second","nmol/s","NMOL/S","amount of substance",602213670000000,[0,-1,0,0,0,0,0],"nmol/s","si",true,null,null,1,false,false,1,"nmol/sec; nmol per sec; nanomoles per sercond; milli enzyme units; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per second per liter","nmol/s/L","(NMOL/S)/L","amount of substance",602213670000000000,[-3,-1,0,0,0,0,0],"(nmol/s)/L","si",true,null,null,1,false,false,1,"nmol/sec/L; nmol per s per L; nmol per sec per L; nanomoles per seconds per liter; litre; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanosecond","ns","NS","time",1e-9,[0,1,0,0,0,0,0],"ns",null,false,"T",null,1,false,false,0,"nanoseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"nanoenzyme unit per milliliter","nU/mL","NU/ML","catalytic activity",10036894500000,[-3,-1,0,0,0,0,0],"nU/mL","chemical",true,null,null,1,false,false,1,"nU per mL; nanoenzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 fU = pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"Ohm meter","Ohm.m","OHM.M","electric resistance",1000,[3,-1,1,0,0,-2,0],"Ω.m","si",true,null,null,1,false,false,0,"electric resistivity; meters; metres","LOINC","","Clinical","unit of electric resistivity","V/A","V/A","1",1,false],[false,"osmole per kilogram","osm/kg","OSM/KG","amount of substance (dissolved particles)",602213670000000000000,[0,0,-1,0,0,0,0],"osm/kg","chemical",true,null,null,1,false,false,1,"osm per kg; osmoles per kilogram; osmols","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"osmole per liter","osm/L","OSM/L","amount of substance (dissolved particles)",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"osm/L","chemical",true,null,null,1,false,false,1,"osm per L; osmoles per liter; litre; osmols","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"picoampere","pA","PA","electric current",1e-12,[0,-1,0,0,0,1,0],"pA","si",true,null,null,1,false,false,0,"picoamperes","LOINC","","Clinical","equal to 10^-12 amperes","C/s","C/S","1",1,false],[false,"picogram","pg","PG","mass",1e-12,[0,0,1,0,0,0,0],"pg",null,false,"M",null,1,false,false,0,"picograms","LOINC","Mass; EntMass","Clinical","",null,null,null,null,false],[false,"picogram per deciliter","pg/dL","PG/DL","mass",9.999999999999999e-9,[-3,0,1,0,0,0,0],"pg/dL",null,false,"M",null,1,false,false,0,"pg per dL; picograms; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per liter","pg/L","PG/L","mass",1e-9,[-3,0,1,0,0,0,0],"pg/L",null,false,"M",null,1,false,false,0,"pg per L; picograms; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per milligram","pg/mg","PG/MG","mass",1e-9,[0,0,0,0,0,0,0],"pg/mg",null,false,"M",null,1,false,false,0,"pg per mg; picograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"picogram per milliliter","pg/mL","PG/ML","mass",0.000001,[-3,0,1,0,0,0,0],"pg/mL",null,false,"M",null,1,false,false,0,"pg per mL; picograms per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per millimeter","pg/mm","PG/MM","mass",1e-9,[-1,0,1,0,0,0,0],"pg/mm",null,false,"M",null,1,false,false,0,"pg per mm; picogram/millimeter; picogram/millimetre; picograms per millimeter; millimetre","LOINC","Lineic Mass","Clinical","",null,null,null,null,false],[false,"picokatal","pkat","PKAT","catalytic activity",602213670000,[0,-1,0,0,0,0,0],"pkat","chemical",true,null,null,1,false,false,1,"pkats; picokatals","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"picoliter","pL","PL","volume",1e-15,[3,0,0,0,0,0,0],"pL","iso1000",true,null,null,1,false,false,0,"picoliters; picolitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"picometer","pm","PM","length",1e-12,[1,0,0,0,0,0,0],"pm",null,false,"L",null,1,false,false,0,"picometers; picometres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"picomole","pmol","PMOL","amount of substance",602213670000,[0,0,0,0,0,0,0],"pmol","si",true,null,null,1,false,false,1,"picomoles; pmols","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per 24 hour","pmol/(24.h)","PMOL/HR","amount of substance",6970065.625,[0,-1,0,0,0,0,0],"pmol/h","si",true,null,null,1,false,false,1,"pmol/24hrs; pmol/24 hrs; pmol per 24 hrs; 24hrs; days; dy; picomoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per day","pmol/d","PMOL/D","amount of substance",6970065.625,[0,-1,0,0,0,0,0],"pmol/d","si",true,null,null,1,false,false,1,"pmol/dy; pmol per day; 24 hours; 24hrs; 24 hrs; picomoles","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per deciliter","pmol/dL","PMOL/DL","amount of substance",6022136700000000,[-3,0,0,0,0,0,0],"pmol/dL","si",true,null,null,1,false,false,1,"pmol per dL; picomoles per deciliter; decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per gram","pmol/g","PMOL/G","amount of substance",602213670000,[0,0,-1,0,0,0,0],"pmol/g","si",true,null,null,1,false,false,1,"pmol per gm; picomoles per gram; picomole/gram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per hour per milliliter ","pmol/h/mL","(PMOL/HR)/ML","amount of substance",167281575000000,[-3,-1,0,0,0,0,0],"(pmol/h)/mL","si",true,null,null,1,false,false,1,"pmol/hrs/mL; pmol per hrs per mL; picomoles per hour per milliliter; millilitre; micro enzyme units per volume; enzymatic activity; enzyme activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. ","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per liter","pmol/L","PMOL/L","amount of substance",602213670000000,[-3,0,0,0,0,0,0],"pmol/L","si",true,null,null,1,false,false,1,"picomole/liter; pmol per L; picomoles; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per minute","pmol/min","PMOL/MIN","amount of substance",10036894500,[0,-1,0,0,0,0,0],"pmol/min","si",true,null,null,1,false,false,1,"picomole/minute; pmol per min; picomoles per minute; micro enzyme units; enzymatic activity; enzyme activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. pmol/min = uU (micro enzyme unit)","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per milliliter","pmol/mL","PMOL/ML","amount of substance",602213670000000000,[-3,0,0,0,0,0,0],"pmol/mL","si",true,null,null,1,false,false,1,"picomole/milliliter; picomole/millilitre; pmol per mL; picomoles; millilitre; picomols; pmols","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per micromole","pmol/umol","PMOL/UMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"pmol/μmol","si",true,null,null,1,false,false,0,"pmol/mcgmol; picomole/micromole; pmol per umol; pmol per mcgmol; picomoles ","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picosecond","ps","PS","time",1e-12,[0,1,0,0,0,0,0],"ps",null,false,"T",null,1,false,false,0,"picoseconds; psec","LOINC","Time","Clinical","",null,null,null,null,false],[false,"picotesla","pT","PT","magnetic flux density",1e-9,[0,-1,1,0,0,-1,0],"pT","si",true,null,null,1,false,false,0,"picoteslas","LOINC","","Clinical","SI unit of magnetic field strength for magnetic field B","Wb/m2","WB/M2","1",1,false],[false,"enzyme unit per 12 hour","U/(12.h)","U/HR","catalytic activity",232335520833.33334,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/12hrs; U/ 12hrs; U per 12 hrs; 12hrs; enzyme units per 12 hours; enzyme activity; enzymatic activity per time; umol per min per 12 hours; micromoles per minute per 12 hours; umol/min/12hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 2 hour","U/(2.h)","U/HR","catalytic activity",1394013125000,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/2hrs; U/ 2hrs; U per 2 hrs; 2hrs; enzyme units per 2 hours; enzyme activity; enzymatic activity per time; umol per minute per 2 hours; micromoles per minute; umol/min/2hr; umol per min per 2hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 24 hour","U/(24.h)","U/HR","catalytic activity",116167760416.66667,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/24hrs; U/ 24hrs; U per 24 hrs; 24hrs; enzyme units per 24 hours; enzyme activity; enzymatic activity per time; micromoles per minute per 24 hours; umol/min/24hr; umol per min per 24hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 10","U/10","U","catalytic activity",1003689450000000,[0,-1,0,0,0,0,0],"U","chemical",true,null,null,1,false,false,1,"enzyme unit/10; U per 10; enzyme units per 10; enzymatic activity; enzyme activity; micromoles per minute; umol/min/10","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 10 billion","U/10*10","U/(10*10)","catalytic activity",1003689.45,[0,-1,0,0,0,0,0],"U/(1010)","chemical",true,null,null,1,false,false,1,"U per 10*10; enzyme units per 10*10; U per 10 billion; enzyme units; enzymatic activity; micromoles per minute per 10 billion; umol/min/10*10","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per trillion","U/10*12","U/(10*12)","catalytic activity",10036.8945,[0,-1,0,0,0,0,0],"U/(1012)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*12; U per 10*12; enzyme units per 10*12; enzyme units per trillion; enzymatic activity; micromoles per minute per trillion; umol/min/10*12; umol per min per 10*12","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per million","U/10*6","U/(10*6)","catalytic activity",10036894500,[0,-1,0,0,0,0,0],"U/(106)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*6; U per 10*6; enzyme units per 10*6; enzyme units; enzymatic activity per volume; micromoles per minute per million; umol/min/10*6; umol per min per 10*6","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per billion","U/10*9","U/(10*9)","catalytic activity",10036894.5,[0,-1,0,0,0,0,0],"U/(109)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*9; U per 10*9; enzyme units per 10*9; enzymatic activity per volume; micromoles per minute per billion; umol/min/10*9; umol per min per 10*9","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per day","U/d","U/D","catalytic activity",116167760416.66667,[0,-2,0,0,0,0,0],"U/d","chemical",true,null,null,1,false,false,1,"U/dy; enzyme units per day; enzyme units; enzyme activity; enzymatic activity per time; micromoles per minute per day; umol/min/day; umol per min per day","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per deciliter","U/dL","U/DL","catalytic activity",100368945000000000000,[-3,-1,0,0,0,0,0],"U/dL","chemical",true,null,null,1,false,false,1,"U per dL; enzyme units per deciliter; decilitre; micromoles per minute per deciliter; umol/min/dL; umol per min per dL","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per gram","U/g","U/G","catalytic activity",10036894500000000,[0,-1,-1,0,0,0,0],"U/g","chemical",true,null,null,1,false,false,1,"U/gm; U per gm; enzyme units per gram; micromoles per minute per gram; umol/min/g; umol per min per g","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per hour","U/h","U/HR","catalytic activity",2788026250000,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/hr; U per hr; enzyme units per hour; micromoles per minute per hour; umol/min/hr; umol per min per hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per liter","U/L","U/L","catalytic activity",10036894500000000000,[-3,-1,0,0,0,0,0],"U/L","chemical",true,null,null,1,false,false,1,"enzyme unit/liter; enzyme unit/litre; U per L; enzyme units per liter; enzyme unit per litre; micromoles per minute per liter; umol/min/L; umol per min per L","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per minute","U/min","U/MIN","catalytic activity",167281575000000,[0,-2,0,0,0,0,0],"U/min","chemical",true,null,null,1,false,false,1,"enzyme unit/minute; U per min; enzyme units; umol/min/min; micromoles per minute per minute; micromoles per min per min; umol","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per milliliter","U/mL","U/ML","catalytic activity",1.00368945e+22,[-3,-1,0,0,0,0,0],"U/mL","chemical",true,null,null,1,false,false,1,"U per mL; enzyme units per milliliter; millilitre; micromoles per minute per milliliter; umol/min/mL; umol per min per mL","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per second","U/s","U/S","catalytic activity",10036894500000000,[0,-2,0,0,0,0,0],"U/s","chemical",true,null,null,1,false,false,1,"U/sec; U per second; enzyme units per second; micromoles per minute per second; umol/min/sec; umol per min per sec","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"micro international unit","u[IU]","U[IU]","arbitrary",0.000001,[0,0,0,0,0,0,0],"μi.U.","chemical",true,null,null,1,false,true,0,"uIU; u IU; microinternational units","LOINC","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"micro international unit per liter","u[IU]/L","U[IU]/L","arbitrary",0.001,[-3,0,0,0,0,0,0],"(μi.U.)/L","chemical",true,null,null,1,false,true,0,"uIU/L; u IU/L; uIU per L; microinternational units per liter; litre; ","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"micro international unit per milliliter","u[IU]/mL","U[IU]/ML","arbitrary",1,[-3,0,0,0,0,0,0],"(μi.U.)/mL","chemical",true,null,null,1,false,true,0,"uIU/mL; u IU/mL; uIU per mL; microinternational units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"microequivalent","ueq","UEQ","amount of substance",602213670000000000,[0,0,0,0,0,0,0],"μeq","chemical",true,null,null,1,false,false,1,"microequivalents; 10^-6 equivalents; 10-6 equivalents","LOINC","Sub","Clinical","","mol","MOL","1",1,false],[false,"microequivalent per liter","ueq/L","UEQ/L","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"μeq/L","chemical",true,null,null,1,false,false,1,"ueq per liter; litre; microequivalents","LOINC","MCnc","Clinical","","mol","MOL","1",1,false],[false,"microequivalent per milliliter","ueq/mL","UEQ/ML","amount of substance",6.0221367000000003e+23,[-3,0,0,0,0,0,0],"μeq/mL","chemical",true,null,null,1,false,false,1,"ueq per milliliter; millilitre; microequivalents","LOINC","MCnc","Clinical","","mol","MOL","1",1,false],[false,"microgram","ug","UG","mass",0.000001,[0,0,1,0,0,0,0],"μg",null,false,"M",null,1,false,false,0,"mcg; micrograms; 10^-6 grams; 10-6 grams","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"microgram per 100 gram","ug/(100.g)","UG/G","mass",1e-8,[0,0,0,0,0,0,0],"μg/g",null,false,"M",null,1,false,false,0,"ug/100gm; ug/100 gm; mcg; ug per 100g; 100 gm; mcg per 100g; micrograms per 100 grams","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per 24 hour","ug/(24.h)","UG/HR","mass",1.1574074074074074e-11,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/24hrs; ug/24 hrs; mcg/24hrs; ug per 24hrs; mcg per 24hrs; 24 hrs; micrograms per 24 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per 8 hour","ug/(8.h)","UG/HR","mass",3.472222222222222e-11,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/8hrs; ug/8 hrs; mcg/8hrs; ug per 8hrs; mcg per 8hrs; 8 hrs; micrograms per 8 hours; shift","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per square foot (international)","ug/[sft_i]","UG/[SFT_I]","mass",0.000010763910416709721,[-2,0,1,0,0,0,0],"μg",null,false,"M",null,1,false,false,0,"ug/sft; ug/ft2; ug/ft^2; ug/sq. ft; micrograms; sq. foot; foot squared","LOINC","ArMass","Clinical","",null,null,null,null,false],[false,"microgram per day","ug/d","UG/D","mass",1.1574074074074074e-11,[0,-1,1,0,0,0,0],"μg/d",null,false,"M",null,1,false,false,0,"ug/dy; mcg/dy; ug per day; mcg; micrograms per day","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per deciliter","ug/dL","UG/DL","mass",0.009999999999999998,[-3,0,1,0,0,0,0],"μg/dL",null,false,"M",null,1,false,false,0,"ug per dL; mcg/dl; mcg per dl; micrograms per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per gram","ug/g","UG/G","mass",0.000001,[0,0,0,0,0,0,0],"μg/g",null,false,"M",null,1,false,false,0,"ug per gm; mcg/gm; mcg per g; micrograms per gram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per hour","ug/h","UG/HR","mass",2.7777777777777777e-10,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/hr; mcg/hr; mcg per hr; ug per hr; ug per hour; micrograms","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per kilogram","ug/kg","UG/KG","mass",9.999999999999999e-10,[0,0,0,0,0,0,0],"μg/kg",null,false,"M",null,1,false,false,0,"ug per kg; mcg/kg; mcg per kg; micrograms per kilogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per kilogram per 8 hour","ug/kg/(8.h)","(UG/KG)/HR","mass",3.472222222222222e-14,[0,-1,0,0,0,0,0],"(μg/kg)/h",null,false,"M",null,1,false,false,0,"ug/kg/8hrs; mcg/kg/8hrs; ug/kg/8 hrs; mcg/kg/8 hrs; ug per kg per 8hrs; 8 hrs; mcg per kg per 8hrs; micrograms per kilograms per 8 hours; shift","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per day","ug/kg/d","(UG/KG)/D","mass",1.1574074074074072e-14,[0,-1,0,0,0,0,0],"(μg/kg)/d",null,false,"M",null,1,false,false,0,"ug/(kg.d); ug/kg/dy; mcg/kg/day; ug per kg per dy; 24 hours; 24hrs; mcg; kilograms; microgram per kilogram and day","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per hour","ug/kg/h","(UG/KG)/HR","mass",2.7777777777777774e-13,[0,-1,0,0,0,0,0],"(μg/kg)/h",null,false,"M",null,1,false,false,0,"ug/(kg.h); ug/kg/hr; mcg/kg/hr; ug per kg per hr; mcg per kg per hr; kilograms","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per minute","ug/kg/min","(UG/KG)/MIN","mass",1.6666666666666664e-11,[0,-1,0,0,0,0,0],"(μg/kg)/min",null,false,"M",null,1,false,false,0,"ug/kg/min; ug/kg/min; mcg/kg/min; ug per kg per min; mcg; micrograms per kilograms per minute ","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per liter","ug/L","UG/L","mass",0.001,[-3,0,1,0,0,0,0],"μg/L",null,false,"M",null,1,false,false,0,"mcg/L; ug per L; mcg; micrograms per liter; litre ","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per liter per 24 hour","ug/L/(24.h)","(UG/L)/HR","mass",1.1574074074074074e-8,[-3,-1,1,0,0,0,0],"(μg/L)/h",null,false,"M",null,1,false,false,0,"ug/L/24hrs; ug/L/24 hrs; mcg/L/24hrs; ug per L per 24hrs; 24 hrs; day; dy mcg; micrograms per liters per 24 hours; litres","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per square meter","ug/m2","UG/M2","mass",0.000001,[-2,0,1,0,0,0,0],"μg/(m2)",null,false,"M",null,1,false,false,0,"ug/m^2; ug/sq. m; mcg/m2; mcg/m^2; mcg/sq. m; ug per m2; m^2; sq. meter; mcg; micrograms per square meter; meter squared; metre","LOINC","ArMass","Clinical","unit used to measure mass dose per patient body surface area",null,null,null,null,false],[false,"microgram per cubic meter","ug/m3","UG/M3","mass",0.000001,[-3,0,1,0,0,0,0],"μg/(m3)",null,false,"M",null,1,false,false,0,"ug/m^3; ug/cu. m; mcg/m3; mcg/m^3; mcg/cu. m; ug per m3; ug per m^3; ug per cu. m; mcg; micrograms per cubic meter; meter cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per milligram","ug/mg","UG/MG","mass",0.001,[0,0,0,0,0,0,0],"μg/mg",null,false,"M",null,1,false,false,0,"ug per mg; mcg/mg; mcg per mg; micromilligrams per milligram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per minute","ug/min","UG/MIN","mass",1.6666666666666667e-8,[0,-1,1,0,0,0,0],"μg/min",null,false,"M",null,1,false,false,0,"ug per min; mcg/min; mcg per min; microminutes per minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per milliliter","ug/mL","UG/ML","mass",1,[-3,0,1,0,0,0,0],"μg/mL",null,false,"M",null,1,false,false,0,"ug per mL; mcg/mL; mcg per mL; micrograms per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per millimole","ug/mmol","UG/MMOL","mass",1.660540186674939e-27,[0,0,1,0,0,0,0],"μg/mmol",null,false,"M",null,1,false,false,-1,"ug per mmol; mcg/mmol; mcg per mmol; micrograms per millimole","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"microgram per nanogram","ug/ng","UG/NG","mass",999.9999999999999,[0,0,0,0,0,0,0],"μg/ng",null,false,"M",null,1,false,false,0,"ug per ng; mcg/ng; mcg per ng; micrograms per nanogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microkatal","ukat","UKAT","catalytic activity",602213670000000000,[0,-1,0,0,0,0,0],"μkat","chemical",true,null,null,1,false,false,1,"microkatals; ukats","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"microliter","uL","UL","volume",1e-9,[3,0,0,0,0,0,0],"μL","iso1000",true,null,null,1,false,false,0,"microliters; microlitres; mcl","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"microliter per 2 hour","uL/(2.h)","UL/HR","volume",1.388888888888889e-13,[3,-1,0,0,0,0,0],"μL/h","iso1000",true,null,null,1,false,false,0,"uL/2hrs; uL/2 hrs; mcg/2hr; mcg per 2hr; uL per 2hr; uL per 2 hrs; microliters per 2 hours; microlitres ","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"microliter per hour","uL/h","UL/HR","volume",2.777777777777778e-13,[3,-1,0,0,0,0,0],"μL/h","iso1000",true,null,null,1,false,false,0,"uL/hr; mcg/hr; mcg per hr; uL per hr; microliters per hour; microlitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"micrometer","um","UM","length",0.000001,[1,0,0,0,0,0,0],"μm",null,false,"L",null,1,false,false,0,"micrometers; micrometres; μm; microns","LOINC","Len","Clinical","Unit of length that is usually used in tests related to the eye",null,null,null,null,false],[false,"microns per second","um/s","UM/S","length",0.000001,[1,-1,0,0,0,0,0],"μm/s",null,false,"L",null,1,false,false,0,"um/sec; micron/second; microns/second; um per sec; micrometers per second; micrometres","LOINC","Vel","Clinical","",null,null,null,null,false],[false,"micromole","umol","UMOL","amount of substance",602213670000000000,[0,0,0,0,0,0,0],"μmol","si",true,null,null,1,false,false,1,"micromoles; umols","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 2 hour","umol/(2.h)","UMOL/HR","amount of substance",83640787500000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/2hrs; umol/2 hrs; umol per 2 hrs; 2hrs; micromoles per 2 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 24 hour","umol/(24.h)","UMOL/HR","amount of substance",6970065625000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/24hrs; umol/24 hrs; umol per 24 hrs; per 24hrs; micromoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 8 hour","umol/(8.h)","UMOL/HR","amount of substance",20910196875000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/8hr; umol/8 hr; umol per 8 hr; umol per 8hr; umols per 8hr; umol per 8 hours; micromoles per 8 hours; shift","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per day","umol/d","UMOL/D","amount of substance",6970065625000,[0,-1,0,0,0,0,0],"μmol/d","si",true,null,null,1,false,false,1,"umol/day; umol per day; umols per day; umol per days; micromoles per days; umol/24hr; umol/24 hr; umol per 24 hr; umol per 24hr; umols per 24hr; umol per 24 hours; micromoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per deciliter","umol/dL","UMOL/DL","amount of substance",6.0221367e+21,[-3,0,0,0,0,0,0],"μmol/dL","si",true,null,null,1,false,false,1,"micromole/deciliter; micromole/decilitre; umol per dL; micromoles per deciliters; micromole per decilitres","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per gram","umol/g","UMOL/G","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"μmol/g","si",true,null,null,1,false,false,1,"micromole/gram; umol per g; micromoles per gram","LOINC","SCnt; Ratio","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per hour","umol/h","UMOL/HR","amount of substance",167281575000000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/hr; umol per hr; umol per hour; micromoles per hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per kilogram","umol/kg","UMOL/KG","amount of substance",602213670000000,[0,0,-1,0,0,0,0],"μmol/kg","si",true,null,null,1,false,false,1,"umol per kg; micromoles per kilogram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per liter","umol/L","UMOL/L","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"μmol/L","si",true,null,null,1,false,false,1,"micromole/liter; micromole/litre; umol per liter; micromoles per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per liter per hour","umol/L/h","(UMOL/L)/HR","amount of substance",167281575000000000,[-3,-1,0,0,0,0,0],"(μmol/L)/h","si",true,null,null,1,false,false,1,"umol/liter/hr; umol/litre/hr; umol per L per hr; umol per liter per hour; micromoles per liters per hour; litre","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min; umol/L/h is a derived unit of enzyme units","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milligram","umol/mg","UMOL/MG","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"μmol/mg","si",true,null,null,1,false,false,1,"micromole/milligram; umol per mg; micromoles per milligram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute","umol/min","UMOL/MIN","amount of substance",10036894500000000,[0,-1,0,0,0,0,0],"μmol/min","si",true,null,null,1,false,false,1,"micromole/minute; umol per min; micromoles per minute; enzyme units","LOINC","CAct","Clinical","unit for the enzyme unit U = umol/min","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute per gram","umol/min/g","(UMOL/MIN)/G","amount of substance",10036894500000000,[0,-1,-1,0,0,0,0],"(μmol/min)/g","si",true,null,null,1,false,false,1,"umol/min/gm; umol per min per gm; micromoles per minutes per gram; U/g; enzyme units","LOINC","CCnt","Clinical","unit for the enzyme unit U = umol/min. umol/min/g = U/g","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute per liter","umol/min/L","(UMOL/MIN)/L","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(μmol/min)/L","si",true,null,null,1,false,false,1,"umol/min/liter; umol/minute/liter; micromoles per minutes per liter; litre; enzyme units; U/L","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. umol/min/L = U/L","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milliliter","umol/mL","UMOL/ML","amount of substance",6.0221367000000003e+23,[-3,0,0,0,0,0,0],"μmol/mL","si",true,null,null,1,false,false,1,"umol per mL; micromoles per milliliter; millilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milliliter per minute","umol/mL/min","(UMOL/ML)/MIN","amount of substance",1.00368945e+22,[-3,-1,0,0,0,0,0],"(μmol/mL)/min","si",true,null,null,1,false,false,1,"umol per mL per min; micromoles per milliliters per minute; millilitres","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. umol/mL/min = U/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per millimole","umol/mmol","UMOL/MMOL","amount of substance",0.001,[0,0,0,0,0,0,0],"μmol/mmol","si",true,null,null,1,false,false,0,"umol per mmol; micromoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per mole","umol/mol","UMOL/MOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"μmol/mol","si",true,null,null,1,false,false,0,"umol per mol; micromoles per mole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per micromole","umol/umol","UMOL/UMOL","amount of substance",1,[0,0,0,0,0,0,0],"μmol/μmol","si",true,null,null,1,false,false,0,"umol per umol; micromoles per micromole","LOINC","Srto; SFr; EntSRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"microOhm","uOhm","UOHM","electric resistance",0.001,[2,-1,1,0,0,-2,0],"μΩ","si",true,null,null,1,false,false,0,"microOhms; µΩ","LOINC","","Clinical","unit of electric resistance","V/A","V/A","1",1,false],[false,"microsecond","us","US","time",0.000001,[0,1,0,0,0,0,0],"μs",null,false,"T",null,1,false,false,0,"microseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"micro enzyme unit per gram","uU/g","UU/G","catalytic activity",10036894500,[0,-1,-1,0,0,0,0],"μU/g","chemical",true,null,null,1,false,false,1,"uU per gm; micro enzyme units per gram; micro enzymatic activity per mass; enzyme activity","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"micro enzyme unit per liter","uU/L","UU/L","catalytic activity",10036894500000,[-3,-1,0,0,0,0,0],"μU/L","chemical",true,null,null,1,false,false,1,"uU per L; micro enzyme units per liter; litre; enzymatic activity per volume; enzyme activity ","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"micro enzyme unit per milliliter","uU/mL","UU/ML","catalytic activity",10036894500000000,[-3,-1,0,0,0,0,0],"μU/mL","chemical",true,null,null,1,false,false,1,"uU per mL; micro enzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"microvolt","uV","UV","electric potential",0.001,[2,-2,1,0,0,-1,0],"μV","si",true,null,null,1,false,false,0,"microvolts","LOINC","Elpot","Clinical","unit of electric potential (voltage)","J/C","J/C","1",1,false]]}} +(function (global){(function (){ +'use strict'; -},{}],9:[function(require,module,exports){ -"use strict"; +var objectAssign = require('object-assign'); -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Ucum = void 0; +// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js +// original notice: -/* - * This defines the namespace for the UCUM classes and provides - * a place for the definition of global variables and constants. +/*! + * The buffer module from node.js, for the browser. * - * The javascript for this UCUM implementation uses syntax as - * defined by the ECMAScript 6 standard + * @author Feross Aboukhadijeh + * @license MIT */ -var Ucum = { - /** - * Flag indicating whether or not we're using case sensitive labels - * I don't think we need this. I think we're just going with - * case sensitive, per Clem. Gunther's code has this flag, but I - * am removing it, at least for now. lm, 6/2016 - */ - //caseSensitive_: true , - - /** - * The number of elements in a Dimension array. Currently this - * is set as a configuration variable, but when we get to the point - * of loading the unit definitions from a file, this value will be - * set from that. - */ - dimLen_: 7, +function compare(a, b) { + if (a === b) { + return 0; + } - /** - * The characters used as valid operators in a UCUM unit expression, - * where '.' is for multiplication and '/' is for division. - */ - validOps_: ['.', '/'], + var x = a.length; + var y = b.length; - /** - * The string used to separate a unit code and unit name when they - * are displayed together - */ - codeSep_: ': ', - // Message text variations for validation methods and conversion methods - valMsgStart_: 'Did you mean ', - valMsgEnd_: '?', - cnvMsgStart_: 'We assumed you meant ', - cnvMsgEnd_: '.', + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } - /** - * Default opening string used to emphasize portions of error messages. - * Used when NOT displaying messages on a web site, i.e., for output - * from the library methods or to a file. - */ - openEmph_: ' ->', + if (x < y) { + return -1; + } + if (y < x) { + return 1; + } + return 0; +} +function isBuffer(b) { + if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { + return global.Buffer.isBuffer(b); + } + return !!(b != null && b._isBuffer); +} - /** - * Default closing string used to emphasize portions of error messages. - * Used when NOT displaying messages on a web site, i.e., for output - * from the library methods or to a file. - */ - closeEmph_: '<- ', +// based on node assert, original notice: +// NB: The URL to the CommonJS spec is kept just for tradition. +// node-assert has evolved a lot since then, both in API and behavior. - /** - * Opening HTML used to emphasize portions of error messages. Used when - * displaying messages on a web site; should be blank when output is - * to a file. - */ - openEmphHTML_: '', +// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 +// +// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! +// +// Originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the 'Software'), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - /** - * Closing HTML used to emphasize portions of error messages. Used when - * displaying messages on a web site; should be blank when output is - * to a file. - */ - closeEmphHTML_: '', +var util = require('util/'); +var hasOwn = Object.prototype.hasOwnProperty; +var pSlice = Array.prototype.slice; +var functionsHaveNames = (function () { + return function foo() {}.name === 'foo'; +}()); +function pToString (obj) { + return Object.prototype.toString.call(obj); +} +function isView(arrbuf) { + if (isBuffer(arrbuf)) { + return false; + } + if (typeof global.ArrayBuffer !== 'function') { + return false; + } + if (typeof ArrayBuffer.isView === 'function') { + return ArrayBuffer.isView(arrbuf); + } + if (!arrbuf) { + return false; + } + if (arrbuf instanceof DataView) { + return true; + } + if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { + return true; + } + return false; +} +// 1. The assert module provides functions that throw +// AssertionError's when particular conditions are not met. The +// assert module must conform to the following interface. - /** - * Message that is displayed when annotations are included in a unit - * string, to let the user know how they are interpreted. - */ - bracesMsg_: 'FYI - annotations (text in curly braces {}) are ignored, ' + 'except that an annotation without a leading symbol implies ' + 'the default unit 1 (the unity).', +var assert = module.exports = ok; - /** - * Message that is displayed or returned when a conversion is requested - * for two units where (only) a mass<->moles conversion is appropriate - * but no molecular weight was specified. - */ - needMoleWeightMsg_: 'Did you wish to convert between mass and moles? The ' + 'molecular weight of the substance represented by the ' + 'units is required to perform the conversion.', +// 2. The AssertionError is defined in assert. +// new assert.AssertionError({ message: message, +// actual: actual, +// expected: expected }) - /** - * Hash that matches unit column names to names used in the csv file - * that is submitted to the data updater. - */ - csvCols_: { - 'case-sensitive code': 'csCode_', - 'LOINC property': 'loincProperty_', - 'name (display)': 'name_', - 'synonyms': 'synonyms_', - 'source': 'source_', - 'category': 'category_', - 'Guidance': 'guidance_' - }, +var regex = /\s*function\s+([^\(\s]*)\s*/; +// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js +function getName(func) { + if (!util.isFunction(func)) { + return; + } + if (functionsHaveNames) { + return func.name; + } + var str = func.toString(); + var match = str.match(regex); + return match && match[1]; +} +assert.AssertionError = function AssertionError(options) { + this.name = 'AssertionError'; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + if (options.message) { + this.message = options.message; + this.generatedMessage = false; + } else { + this.message = getMessage(this); + this.generatedMessage = true; + } + var stackStartFunction = options.stackStartFunction || fail; + if (Error.captureStackTrace) { + Error.captureStackTrace(this, stackStartFunction); + } else { + // non v8 browsers so we can have a stacktrace + var err = new Error(); + if (err.stack) { + var out = err.stack; - /** - * Name of the column in the csv file that serves as the key - */ - inputKey_: 'case-sensitive code', + // try to strip useless frames + var fn_name = getName(stackStartFunction); + var idx = out.indexOf('\n' + fn_name); + if (idx >= 0) { + // once we have located the function frame + // we need to strip out everything before it (and its line) + var next_line = out.indexOf('\n', idx + 1); + out = out.substring(next_line + 1); + } - /** - * Special codes that contain operators within brackets. The operator - * within these codes causes them to parse incorrectly if they are preceded - * by a prefix, because the parsing algorithm splits them up on the operator. - * So we use this object to identify them and substitute placeholders to - * avoid that. - */ - specUnits_: { - 'B[10.nV]': 'specialUnitOne', - '[m/s2/Hz^(1/2)]': 'specialUnitTwo' + this.stack = out; + } } }; -exports.Ucum = Ucum; +// assert.AssertionError instanceof Error +util.inherits(assert.AssertionError, Error); -},{}],10:[function(require,module,exports){ -"use strict"; +function truncate(s, n) { + if (typeof s === 'string') { + return s.length < n ? s : s.slice(0, n); + } else { + return s; + } +} +function inspect(something) { + if (functionsHaveNames || !util.isFunction(something)) { + return util.inspect(something); + } + var rawname = getName(something); + var name = rawname ? ': ' + rawname : ''; + return '[Function' + name + ']'; +} +function getMessage(self) { + return truncate(inspect(self.actual), 128) + ' ' + + self.operator + ' ' + + truncate(inspect(self.expected), 128); +} -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Dimension = void 0; +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. -/** - * This class implements an object containing the vector of exponents for - * a unit and its operations for addition, subtraction, and multiplication - * with a scalar. - * - * This object should exist for each unit that can be expressed as a - * vector of numbers. This excludes arbitrary units, e.g., (10*23), and - * units that are not numbers but are an expression based solely on numbers, - * e.g., mol (mole) which is based on 10*23. - * - * @author Lee Mericle, based on java version by Gunther Schadow - */ -var UC = require('./config.js'); +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. -var isInteger = require("is-integer"); +function fail(actual, expected, message, operator, stackStartFunction) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator, + stackStartFunction: stackStartFunction + }); +} -class Dimension { - /** - * Constructor. - * - * @param dimSetting an optional parameter that may be: - * null, which means that the dimVec_ attribute for this object will be null; or - * an array, which must be the length defined by Ucum.dimLen_, and - * whose contents will be copied to this new object's vector; or - * an integer, which must be between 0 and 1 less than the vector length - * defined by Ucum.dimLen_. This new object's vector will be - * initialized to zero for all elements except the one whose index - * matches the number passed in. That element will be set to one. - * @throws an error if the dimSetting parameter does not meet the types - * listed above. - * An error will also be thrown if Ucum.dimLen_ has not been set yet, - * i.e., is still zero. Currently that won't happen, because the - * value is set in the config.js file. But further down the road - * the setting will come from a definitions input file, so we check - * here anyway. - * - */ - constructor(dimSetting) { - if (UC.Ucum.dimLen_ === 0) { - throw new Error('Dimension.setDimensionLen must be called before ' + 'Dimension constructor'); - } +// EXTENSION! allows for well behaved errors defined elsewhere. +assert.fail = fail; - if (dimSetting === undefined || dimSetting === null) { - this.assignZero(); - } else if (dimSetting instanceof Array) { - if (dimSetting.length !== UC.Ucum.dimLen_) { - throw new Error('Parameter error, incorrect length of vector passed to ' + `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`); - } +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, !!guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. - this.dimVec_ = []; +function ok(value, message) { + if (!value) fail(value, true, message, '==', assert.ok); +} +assert.ok = ok; - for (let d = 0; d < UC.Ucum.dimLen_; d++) this.dimVec_.push(dimSetting[d]); - } // In es6 this should be Number.isInteger(dimSetting). But Babel - // doesn't transpile that correctly, so we need to use the isInteger - // module. :0 - else if (isInteger(dimSetting)) { - if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) { - throw new Error('Parameter error, invalid element number specified for ' + 'Dimension constructor'); - } +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); - this.assignZero(); - this.dimVec_[dimSetting] = 1; - } - } // end constructor +assert.equal = function equal(actual, expected, message) { + if (actual != expected) fail(actual, expected, message, '==', assert.equal); +}; - /** - * Sets the element at the specified position to a specified value. The - * default value is 1. If the dimension vector is null when this is called - * a zero-filled vector is created and then the indicated position is set. - * - * @param indexPos the index of the element to be set - * @param value the value to assign to the specified element; optional, - * default value is 1 - * @throws an exception if the specified position is invalid, i.e., not a - * number or is less than 0 or greater than Ucum.dimLen_ - **/ +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); +assert.notEqual = function notEqual(actual, expected, message) { + if (actual == expected) { + fail(actual, expected, message, '!=', assert.notEqual); + } +}; - setElementAt(indexPos, value) { - if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) { - throw new Error(`Dimension.setElementAt called with an invalid index ` + `position (${indexPos})`); - } +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); - if (!this.dimVec_) { - this.assignZero(); - } +assert.deepEqual = function deepEqual(actual, expected, message) { + if (!_deepEqual(actual, expected, false)) { + fail(actual, expected, message, 'deepEqual', assert.deepEqual); + } +}; - if (value === undefined || value === null) value = 1; - this.dimVec_[indexPos] = value; +assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { + if (!_deepEqual(actual, expected, true)) { + fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); } - /** - * Gets the value of the element at the specified position - * - * @param indexPos the index of the element whose value is to be returned - * @return the value of the element at indexPos, or null if the dimension - * vector is null - * @throws an exception if the specified position is invalid, i.e., not a - * number or is less than 0 or greater than Ucum.dimLen_ - **/ +}; +function _deepEqual(actual, expected, strict, memos) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + } else if (isBuffer(actual) && isBuffer(expected)) { + return compare(actual, expected) === 0; - getElementAt(indexPos) { - if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) { - throw new Error(`Dimension.getElementAt called with an invalid index ` + `position (${indexPos})`); - } + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (util.isDate(actual) && util.isDate(expected)) { + return actual.getTime() === expected.getTime(); - let ret = null; - if (this.dimVec_) ret = this.dimVec_[indexPos]; - return ret; - } - /** - * This returns the value of the property named by the parameter - * passed in. Although we currently only have one property, dimVec_, - * that this will get, it's possible that we'll have additional - * properties. If we don't this could just be replaced by a - * getVector function. - * - * @param propertyName name of the property to be returned, with - * or without the trailing underscore. - * @return the requested property, if found for this Dimension - * @throws an error if the property is not found for this Dimension - */ + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (util.isRegExp(actual) && util.isRegExp(expected)) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + // 7.4. Other pairs that do not both pass typeof value == 'object', + // equivalence is determined by ==. + } else if ((actual === null || typeof actual !== 'object') && + (expected === null || typeof expected !== 'object')) { + return strict ? actual === expected : actual == expected; - getProperty(propertyName) { - let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_'; - return this[uProp]; - } // end getProperty + // If both values are instances of typed arrays, wrap their underlying + // ArrayBuffers in a Buffer each to increase performance + // This optimization requires the arrays to have the same type as checked by + // Object.prototype.toString (aka pToString). Never perform binary + // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their + // bit patterns are not identical. + } else if (isView(actual) && isView(expected) && + pToString(actual) === pToString(expected) && + !(actual instanceof Float32Array || + actual instanceof Float64Array)) { + return compare(new Uint8Array(actual.buffer), + new Uint8Array(expected.buffer)) === 0; - /** - * Return a string that represents the dimension vector. Returns null if - * the dimension vector is null. - * - * @return the string that represents the dimension vector. The - * values are enclosed in square brackets, each separated - * by a comma and a space - **/ + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + } else if (isBuffer(actual) !== isBuffer(expected)) { + return false; + } else { + memos = memos || {actual: [], expected: []}; + + var actualIndex = memos.actual.indexOf(actual); + if (actualIndex !== -1) { + if (actualIndex === memos.expected.indexOf(expected)) { + return true; + } + } + memos.actual.push(actual); + memos.expected.push(expected); - toString() { - let ret = null; - if (this.dimVec_) ret = '[' + this.dimVec_.join(', ') + ']'; - return ret; + return objEquiv(actual, expected, strict, memos); } - /** - * Adds the vector of the dimension object passed in to this - * dimension object's vector. This object's vector is changed. - * If either dimension vector is null, no changes are made to this object. - * - * - * @param dim2 the dimension whose vector is to be added to this one - * @return this object - * @throws an exception if dim2 is not a Dimension object - **/ - - - add(dim2) { - if (!dim2 instanceof Dimension) { - throw new Error(`Dimension.add called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); - } +} - if (this.dimVec_ && dim2.dimVec_) { - for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] += dim2.dimVec_[i]; - } +function isArguments(object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; +} - return this; +function objEquiv(a, b, strict, actualVisitedObjects) { + if (a === null || a === undefined || b === null || b === undefined) + return false; + // if one is a primitive, the other must be same + if (util.isPrimitive(a) || util.isPrimitive(b)) + return a === b; + if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) + return false; + var aIsArgs = isArguments(a); + var bIsArgs = isArguments(b); + if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) + return false; + if (aIsArgs) { + a = pSlice.call(a); + b = pSlice.call(b); + return _deepEqual(a, b, strict); } - /** - * Subtracts the vector of the dimension object passed in from this - * dimension object's vector. This object's vector is changed. - * If either dimension vector is null, no changes are made to this object. - * - * @param dim2 the dimension whose vector is to be subtracted from this one - * @return this object - * @throws an exception if dim2 is not a Dimension object - **/ - - - sub(dim2) { - if (!dim2 instanceof Dimension) { - throw new Error(`Dimension.sub called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); - } - - if (this.dimVec_ && dim2.dimVec_) { - for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] -= dim2.dimVec_[i]; - } - - return this; + var ka = objectKeys(a); + var kb = objectKeys(b); + var key, i; + // having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length !== kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] !== kb[i]) + return false; } - /** - * Inverts this dimension object's vector (by multiplying each element - * by negative 1). This object's vector is changed - unless it is null, - * in which case it stays that way. - * - * @return this object - **/ - - - minus() { - if (this.dimVec_) { - for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] = -this.dimVec_[i]; - } - - return this; + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) + return false; } - /** - * Multiplies this dimension object's vector with a scalar. This is used - * when a unit is raised to a power. This object's vector is changed unless - * the vector is null, in which case it stays that way. - * - * @param s the scalar to use - * @return this object - * @throws an exception if s is not a number - */ - - - mul(s) { - if (!isInteger(s)) { - throw new Error(`Dimension.sub called with an invalid parameter - ` + `${typeof dim2} instead of a number`); - } + return true; +} - if (this.dimVec_) { - for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] *= s; - } +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); - return this; +assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (_deepEqual(actual, expected, false)) { + fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); } - /** - * Tests for equality of this dimension object's vector and that of - * the dimension object passed in. If the dimension vector for one of - * the objects is null, the dimension vector for the other object must - * also be null for the two to be equal. (I know - duh. still) - * - * @param dim2 the dimension object whose vector is to be compared to this one - * @return true if the two vectors are equal; false otherwise. - * @throws an exception if dim2 is not a Dimension object - */ - - - equals(dim2) { - if (!dim2 instanceof Dimension) { - throw new Error(`Dimension.equals called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); - } - - let isEqual = true; - let dimVec2 = dim2.dimVec_; - - if (this.dimVec_ && dimVec2) { - for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++) isEqual = this.dimVec_[i] === dimVec2[i]; - } else { - isEqual = this.dimVec_ === null && dimVec2 === null; - } +}; - return isEqual; +assert.notDeepStrictEqual = notDeepStrictEqual; +function notDeepStrictEqual(actual, expected, message) { + if (_deepEqual(actual, expected, true)) { + fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); } - /** - * Assigns the contents of the vector belonging to the dimension object - * passed in to this dimension's vector. If this dimension vector is null - * and the other is not, this one will get the contents of the other. If - * this dimension vector is not null but the one passed in is null, this - * one will be set to null. - * - * @param dim2 the dimension object with the vector whose contents are - * to be assigned to this dimension's vector - * @return this object (not sure why) - * @throws an exception if dim2 is not a Dimension object - */ - +} - assignDim(dim2) { - if (!dim2 instanceof Dimension) { - throw new Error(`Dimension.assignDim called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); - } - if (dim2.dimVec_ === null) this.dimVec_ = null;else { - if (this.dimVec_ === null) { - this.dimVec_ = []; - } +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); - for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] = dim2.dimVec_[i]; - } - return this; +assert.strictEqual = function strictEqual(actual, expected, message) { + if (actual !== expected) { + fail(actual, expected, message, '===', assert.strictEqual); } - /** - * Sets all elements of this dimension object's vector to zero. - * If this object's vector is null, it is created as a zero-filled vector. - * - * @return this object (not sure why) - */ - - - assignZero() { - if (this.dimVec_ === null || this.dimVec_ === undefined) this.dimVec_ = []; +}; - for (let i = 0; i < UC.Ucum.dimLen_; i++) { - this.dimVec_.push(0); - } +// 10. The strict non-equality assertion tests for strict inequality, as +// determined by !==. assert.notStrictEqual(actual, expected, message_opt); - return this; +assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (actual === expected) { + fail(actual, expected, message, '!==', assert.notStrictEqual); } - /** - * Tests for a dimension vector set to all zeroes. - * - * @return true if exponents (elements) of this dimension's vector are all - * zero; false otherwise (including if the current vector is null). - * - */ +}; +function expectedException(actual, expected) { + if (!actual || !expected) { + return false; + } - isZero() { - let allZero = this.dimVec_ !== null; + if (Object.prototype.toString.call(expected) == '[object RegExp]') { + return expected.test(actual); + } - if (this.dimVec_) { - for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++) allZero = this.dimVec_[i] === 0; + try { + if (actual instanceof expected) { + return true; } + } catch (e) { + // Ignore. The instanceof check doesn't work for arrow functions. + } - return allZero; + if (Error.isPrototypeOf(expected)) { + return false; } - /** - * Tests for a Dimension object with no dimension vector (dimVec_ is null). - * - * @return true the dimension vector is null; false if it is not - * - */ + return expected.call({}, actual) === true; +} - isNull() { - return this.dimVec_ === null; +function _tryBlock(block) { + var error; + try { + block(); + } catch (e) { + error = e; } - /** - * Creates and returns a clone of this Dimension object - * - * @return the clone - */ + return error; +} +function _throws(shouldThrow, block, expected, message) { + var actual; - clone() { - let that = new Dimension(); - that.assignDim(this); - return that; + if (typeof block !== 'function') { + throw new TypeError('"block" argument must be a function'); } -} // end Dimension class - + if (typeof expected === 'string') { + message = expected; + expected = null; + } -exports.Dimension = Dimension; + actual = _tryBlock(block); + message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + + (message ? ' ' + message : '.'); -},{"./config.js":9,"is-integer":221}],11:[function(require,module,exports){ -"use strict"; + if (shouldThrow && !actual) { + fail(actual, expected, 'Missing expected exception' + message); + } -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.packArray = packArray; -exports.unpackArray = unpackArray; + var userProvidedMessage = typeof message === 'string'; + var isUnwantedException = !shouldThrow && util.isError(actual); + var isUnexpectedException = !shouldThrow && actual && !expected; -/** - * This file provides functions to reduce the size of an array of objects of the same structure in JSON. - */ -const pushFn = Array.prototype.push; + if ((isUnwantedException && + userProvidedMessage && + expectedException(actual, expected)) || + isUnexpectedException) { + fail(actual, expected, 'Got unwanted exception' + message); + } -function isObject(value) { - return Object.prototype.toString.call(value) === '[object Object]'; + if ((shouldThrow && actual && expected && + !expectedException(actual, expected)) || (!shouldThrow && actual)) { + throw actual; + } } -/** - * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data. - * @param {Object} refObj - reference item of array of objects of the same structure - * @returns {Array} - */ +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); -function createConfig(refObj) { - return Object.keys(refObj).reduce((config, key) => { - if (isObject(refObj[key])) { - pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)])); - } else { - config.push(key); - } +assert.throws = function(block, /*optional*/error, /*optional*/message) { + _throws(true, block, error, message); +}; - return config; - }, []); -} -/** - * Prepares config created with createConfig function to use in packItem/unpackItem functions. - * @param {Array} config - * @returns {Array} - */ +// EXTENSION! This is annoying to write outside this module. +assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { + _throws(false, block, error, message); +}; +assert.ifError = function(err) { if (err) throw err; }; -function prepareConfig(config) { - return config.map(key => Array.isArray(key) ? key : [key]); +// Expose a strict only variant of assert +function strict(value, message) { + if (!value) fail(value, true, message, '==', strict); } -/** - * Converts an object to an array of values in the order of keys from configuration array. - * @param {Array} config - configuration array - * @param {Object} item - input object - * @returns {Array} - */ - +assert.strict = objectAssign(strict, assert, { + equal: assert.strictEqual, + deepEqual: assert.deepStrictEqual, + notEqual: assert.notStrictEqual, + notDeepEqual: assert.notDeepStrictEqual +}); +assert.strict.strict = assert.strict; -function packItem(config, item) { - if (config.join() !== prepareConfig(createConfig(item)).join()) { - throw new Error('Object of unusual structure'); +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + if (hasOwn.call(obj, key)) keys.push(key); } + return keys; +}; - return config.map(keyArr => { - let place = item; - keyArr.forEach(key => { - place = place[key]; - - if (place === undefined) { - throw new Error('Object of unusual structure'); +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"object-assign":368,"util/":11}],9:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true } }); - return place; - }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } } -/** - * Performs the reverse of packItem function. - * @param {Array} config - configuration array - * @param {Array} item - input object - * @returns {Object} - */ - - -function unpackItem(config, item) { - let result = {}; - config.forEach((keyArr, i) => { - let place = result; - - for (let i = 0; i < keyArr.length - 1; i++) { - place = place[keyArr[i]] = place[keyArr[i]] || {}; - } - place[keyArr[keyArr.length - 1]] = item[i]; - }); - return result; +},{}],10:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; } -/** - * Reduces size of an array of objects of the same structure before serialize it to JSON - * @param {Array} arr - * @returns {Object} - */ - - -function packArray(arr) { - if (arr && arr.length) { - const config = createConfig(arr[0]), - _config = prepareConfig(config); +},{}],11:[function(require,module,exports){ +(function (process,global){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - if (config.length) { - return { - config: config, - data: arr.map(packItem.bind(null, _config)) - }; +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); } + return objects.join(' '); } - return { - config: [], - data: arr - }; -} -/** - * Restores an array of objects of the same structure after deserializing this object from JSON - * @param {Object} obj - * @returns {Array} - */ - - -function unpackArray(obj) { - const config = obj && obj.config; - - if (config) { - if (config.length && obj.data) { - const _config = prepareConfig(config); - - return obj.data.map(unpackItem.bind(null, _config)); + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; } else { - return obj.data; + str += ' ' + inspect(x); } } + return str; +}; - return obj; -} +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } -},{}],12:[function(require,module,exports){ -"use strict"; + if (process.noDeprecation === true) { + return fn; + } -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Prefix = void 0; + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; -/** - * Prefix objects are defined in this file. - */ /** - * This class implements the prefix object. Prefixes are used as multipliers - * for units, e.g., km for kilometers - * - * @author Lee Mericle, based on java version by Gunther Schadow + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. */ -var Ucum = require('./config.js'); +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; -class Prefix { - /** - * Creates a single prefix object. - * - * @param attrs a hash of the values to use in creating the prefix object. - * They should be: - * code_ - which is the case-sensitive code used for the prefix, - * e.g., k for kilo - * ciCode_ - which is the case-insensitive code used for the prefix, - * e.g., K for kilo - * name_ - which is the name of the prefix, e.g., kilo - * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo - * value_ - which is teh value to use in multiplying the magnitude of - * a unit, e.g., for a prefix of c the value will be .01. - * exp_ - which is the exponent used to get the value. For decimal based - * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a - * prefix of c, the exponent will be -2. For prefixes that are not - * decimal based, this will be null (but must not be undefined). - * - * @throws an error if the not all required parameters are provided - */ - constructor(attrs) { - if (attrs['code_'] === undefined || attrs['code_'] === null || attrs['name_'] === undefined || attrs['name_'] === null || attrs['value_'] === undefined || attrs['value_'] === null || attrs['exp_'] === undefined) { - throw new Error('Prefix constructor called missing one or more parameters. ' + 'Prefix codes (cs or ci), name, value and exponent must all be specified ' + 'and all but the exponent must not be null.'); - } - /** - * The prefix code, e.g., k for kilo. This should be the case-sensitive - * code. Since there's no way to check to see if it's the case-sensitive - * one as opposed to the case-insensitive one (because although - * case-insensitive codes all seem to be uppercase, some case-sensitive - * codes are also all uppercase), we'll just have to believe that the - * right one was passed in. - */ +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; + +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; - this.code_ = attrs['code_']; - /** - * The case-insensitive code, e.g., K for kilo - */ - this.ciCode_ = attrs['ciCode_']; - /** - * The prefix name, e.g., kilo - */ +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; - this.name_ = attrs['name_']; - /** - * The printSymbol for the prefix, e.g., k for kilo - */ + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} - this.printSymbol_ = attrs['printSymbol_']; - /** - * The value to use in multiplying the magnitude of a unit - */ - if (typeof attrs['value_'] === 'string') this.value_ = parseFloat(attrs['value_']);else this.value_ = attrs['value_']; - /** - * The exponent used to create the value from 10. For prefixes that are - * not based on 10, this will be null. - */ +function stylizeNoColor(str, styleType) { + return str; +} - this.exp_ = attrs['exp_']; - } // end constructor - /** - * Returns the value for the current prefix object - * @return the value for the prefix object with the specified code - * */ +function arrayToHash(array) { + var hash = {}; + array.forEach(function(val, idx) { + hash[val] = true; + }); - getValue() { - return this.value_; - } - /** - * Returns the prefix code for the current prefix object - * @return the code for the current prefix object - */ + return hash; +} - getCode() { - return this.code_; +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; } - /** - * Returns the case-insensitive code for the current prefix object - * @return the case_insensitive code for the current prefix object - */ - - getCiCode() { - return this.ciCode_; + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; } - /** - * Returns the prefix name for the current prefix object - * @return the name for the current prefix object - */ + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); - getName() { - return this.name_; + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); } - /** - * Returns the print symbol for the current prefix object - * @return the print symbol for the current prefix object - */ + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } - getPrintSymbol() { - return this.printSymbol_; + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } } - /** - * Returns the exponent for the current prefix object - * @return the exponent for the current prefix object - */ + var base = '', array = false, braces = ['{', '}']; - getExp() { - return this.exp_; + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; } - /** - * Provides way to tell if one prefix equals another. The second prefix - * must match all attribute values. - * - * @param prefix2 prefix object to check for a match - * @return true for a match; false if one or more attributes don't match - */ + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } - equals(prefix2) { - return this.code_ === prefix2.code_ && this.ciCode_ === prefix2.ciCode_ && this.name_ === prefix2.name_ && this.printSymbol_ === prefix2.printSymbol_ && this.value_ === prefix2.value_ && this.exp_ === prefix2.exp_; + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); } -} // end Prefix class + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } -exports.Prefix = Prefix; + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } -},{"./config.js":9}],13:[function(require,module,exports){ -"use strict"; + ctx.seen.push(value); -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.PrefixTables = exports.PrefixTablesFactory = void 0; + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } -/** - * The tables of defined prefixes is defined in this file. - */ + ctx.seen.pop(); -/** - * This class implements the table of multiplier prefixes. - * - * @author Lee Mericle, based on java version by Gunther Schadow - * - */ -class PrefixTablesFactory { - /** - * Constructor. This creates the empty PrefixTable hashes once. - * There is one hash whose key is the prefix code and one whose - * key is the prefix value. - * - * Implementation of this as a singleton is based on the UnitTables - * implementation. See that class for details. - */ - constructor() { - this.byCode_ = {}; - this.byValue_ = {}; - } - /** - * Provides the number of prefix objects in each table - * @returns count of the number of prefix objects in each table - */ + return reduceToSingleString(output, base, braces); +} - prefixCount() { - return Object.keys(this.byCode_).length; +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); } - /** - * This is used to get all prefix objects by value. Currently it is used - * to create a csv file with all prefixes and units. - * @returns csv string containing all prefix objects, ordered by value. - */ + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} - allPrefixesByValue() { - let prefixBuff = ''; - let pList = Object.keys(this.byValue_); //pList.sort() ; +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} - let pLen = pList.length; - for (let p = 0; p < pLen; p++) { - let pfx = this.getPrefixByValue(pList[p]); - prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\r\n'; +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); } - - return prefixBuff; } - /** - * This is used to get all prefix objects. Currently it is used - * to get the objects to write to the json ucum definitions file - * that is used to provide prefix and unit definition objects for - * conversions and validations. - * - * @returns an array containing all prefix objects, ordered by code. - */ - + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} - allPrefixesByCode() { - let prefixList = []; - let pList = Object.keys(this.byCode_); - pList.sort(); - let pLen = pList.length; - for (let p = 0; p < pLen; p++) { - prefixList.push(this.getPrefixByCode(pList[p])); +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); } - - return prefixList; } - /** - * Adds a prefix object to the tables - * - * @param prefixObj the object to be added to the tables - */ - - - add(prefixObj) { - this.byCode_[prefixObj.getCode()] = prefixObj; - this.byValue_[prefixObj.getValue()] = prefixObj; + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; } - /** - * Tests whether a prefix object is found for a specified code. This - * is used to determine whether or not a prefix object has been created - * for the code. - * - * @param code the code to be used to find the prefix object - * @return boolean indicating whether or not a prefix object was found - * for the specified code - */ - - - isDefined(code) { - return this.byCode_[code] !== null && this.byCode_[code] !== undefined; + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } } - /** - * Obtains a prefix object for a specified code. - * - * @param code the code to be used to find the prefix object - * @return the prefix object found, or null if nothing was found - */ + return name + ': ' + str; +} - getPrefixByCode(code) { - return this.byCode_[code]; - } - /** - * Obtains a prefix object for a specified value. - * - * @param value the value to be used to find the prefix object - * @return the prefix object found, or null if nothing was found - */ - - - getPrefixByValue(value) { - return this.byValue_[value]; - } - -} // end PrefixTablesFactory class -// Create a singleton instance and (to preserve the existing API) an object that -// provides that instance via getInstance(). +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); -exports.PrefixTablesFactory = PrefixTablesFactory; -var prefixTablesInstance = new PrefixTablesFactory(); -const PrefixTables = { - getInstance: function () { - return prefixTablesInstance; + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; } -}; -exports.PrefixTables = PrefixTables; - - -},{}],14:[function(require,module,exports){ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -/* - * This class manages the special functions used by some units. - * - * @author Lee Mericle, based on java version by Gunther Schadow - * - */ -class UcumFunctions { - /** - * Constructor - * - * Creates the singleton object that contains the list of functions used - * to convert special units. - */ - constructor() { - // Create the hash containing the function pairs - this.funcs = {}; // Celsius - convert to Celsius from kelvin and from Celsius to kelvin - // where kelvin is the base unit for temperature - - this.funcs['cel'] = { - cnvTo: function (x) { - return x - 273.15; - }, - cnvFrom: function (x) { - return x + 273.15; - } - }; // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to - // kelvin - which is the base unit for temperature - - this.funcs['degf'] = { - cnvTo: function (x) { - return x - 459.67; - }, - cnvFrom: function (x) { - return x + 459.67; - } - }; // Reaumur - convert between Reaumur and Kelvin. Because of the way the - // calling code in the Units class is set up (in the convertFrom method), - // what is given here as the convertTo function is actually the convert - // from method and vice versa. - //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;}, - // cnvFrom : function(x){return x - 273.15;}}; - this.funcs['degre'] = { - cnvTo: function (x) { - return x - 273.15; - }, - cnvFrom: function (x) { - return x + 273.15; - } - }; // pH - convert to pH from moles per liter and from moles per liter to pH - // where a mole is an amount of a substance (a count of particles) + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} - this.funcs['ph'] = { - cnvTo: function (x) { - return -Math.log(x) / Math.LN10; - }, - cnvFrom: function (x) { - return Math.pow(10, -x); - } - }; // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom) - // and 2ln - two times the natural logarithm - this.funcs['ln'] = { - cnvTo: function (x) { - return Math.log(x); - }, - cnvFrom: function (x) { - return Math.exp(x); - } - }; - this.funcs['2ln'] = { - cnvTo: function (x) { - return 2 * Math.log(x); - }, - cnvFrom: function (x) { - return Math.exp(x / 2); - } - }; // lg - the decadic logarithm (base 10) +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; - this.funcs['lg'] = { - cnvTo: function (x) { - return Math.log(x) / Math.LN10; - }, - cnvFrom: function (x) { - return Math.pow(10, x); - } - }; - this.funcs['10lg'] = { - cnvTo: function (x) { - return 10 * Math.log(x) / Math.LN10; - }, - cnvFrom: function (x) { - return Math.pow(10, x / 10); - } - }; - this.funcs['20lg'] = { - cnvTo: function (x) { - return 20 * Math.log(x) / Math.LN10; - }, - cnvFrom: function (x) { - return Math.pow(10, x / 20); - } - }; // The plain text ucum units file uses '2lg' +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; - this.funcs['2lg'] = { - cnvTo: function (x) { - return 2 * Math.log(x) / Math.LN10; - }, - cnvFrom: function (x) { - return Math.pow(10, x / 2); - } - }; // The xml essence ucum file uses lgTimes2 +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; - this.funcs['lgtimes2'] = this.funcs['2lg']; // ld - dual logarithm (base 2) +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; - this.funcs['ld'] = { - cnvTo: function (x) { - return Math.log(x) / Math.LN2; - }, - cnvFrom: function (x) { - return Math.pow(2, x); - } - }; // tan - tangent +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; - this.funcs['100tan'] = { - cnvTo: function (x) { - return Math.tan(x) * 100; - }, - cnvFrom: function (x) { - return Math.atan(x / 100); - } - }; // the xml essence ucum file uses both 100tan and tanTimes100 +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; - this.funcs['tanTimes100'] = this.funcs['100tan']; // sqrt - square root +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; - this.funcs['sqrt'] = { - cnvTo: function (x) { - return Math.sqrt(x); - }, - cnvFrom: function (x) { - return x * x; - } - }; // inv - inverse +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; - this.funcs['inv'] = { - cnvTo: function (x) { - return 1.0 / x; - }, - cnvFrom: function (x) { - return 1.0 / x; - } - }; // homeopathic potency functions +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; - this.funcs['hpX'] = { - cnvTo: function (x) { - return -this.funcs['lg'](x); - }, - cnvFrom: function (x) { - return Math.pow(10, -x); - } - }; - this.funcs['hpC'] = { - cnvTo: function (x) { - return -this.func['ln'](x) / this.funcs['ln'](100); - }, - cnvFrom: function (x) { - return Math.pow(100, -x); - } - }; - this.funcs['hpM'] = { - cnvTo: function (x) { - return -this.funcs['ln'](x) / this.funcs['ln'](1000); - }, - cnvFrom: function (x) { - return Math.pow(1000, -x); - } - }; - this.funcs['hpQ'] = { - cnvTo: function (x) { - return -this.funcs['ln'](x) / this.funcs['ln'](50000); - }, - cnvFrom: function (x) { - return Math.pow(50000, -x); - } - }; - } // end of constructor +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; - /** - * Returns the function with the name specified - * - * @param fname name of the function to be returned - * @return the function with the specified name - * @throws an error message if the function is not found - */ +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; - forName(fname) { - fname = fname.toLowerCase(); - let f = this.funcs[fname]; - if (f === null) throw new Error(`Requested function ${fname} is not defined`); - return f; - } - /** - * Returns a flag indicating whether or not the function has been - * defined. - * - * @param fname name of the function in question - * @return true if it has been defined; false if not - */ +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; - isDefined(fname) { - fname = fname.toLowerCase(); - return this.funcs[fname] !== null; - } +exports.isBuffer = require('./support/isBuffer'); -} // end of UcumFunctions class +function objectToString(o) { + return Object.prototype.toString.call(o); +} -var _default = new UcumFunctions(); // one singleton instance +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} -exports.default = _default; +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} -},{}],15:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.isNumericString = isNumericString; -exports.isIntegerUnit = isIntegerUnit; -exports.getSynonyms = getSynonyms; +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; -/** - * Internal utilities used by multiple UCUM classes. For example, - * isNumericString is used by both the UnitString and UcumLhcUtils - * classes. If it's in the UnitString class the UcumLhcUtils class - * needs to require the UnitString class. But the checkSynonyms - * class is used by the UnitString class - but was in the UcumLhcUtils - * class. Requiring the UcumLhcUtils class from the UnitString class - * made everything break (cyclical requires). - * - * So now they're here. - */ /** - * This module implements internal ucum utilities. - * - * @author Lee Mericle, based on java version by Gunther Schadow + * Inherit the prototype methods from one constructor into another. * - */ -var UnitTables = require('./unitTables.js').UnitTables; -/** - * This function tests a string to see if it contains only numbers (digits, - * a period, leading - or +). This code was taken from a stackoverflow - * solution: - * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340 + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). * - * @params theString - * @returns true if the string contains only numbers; false otherwise + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. */ +exports.inherits = require('inherits'); +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; -function isNumericString(theString) { - let num = "" + theString; //coerce num to be a string - - return !isNaN(num) && !isNaN(parseFloat(num)); -} // end isNumericString - -/** - * Checks whether a string qualifies as an integer unit. Section 2.2.8 ("integer - * numbers", says, "A positive integer number may appear in place of a simple - * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is - * interpreted as a number." - * Note: This leaves open the question of whether "0" is a valid unit, since - * it is positive, but you can't measure anything in units of zero. - * @param str the string to check - */ - + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; -function isIntegerUnit(str) { - return /^\d+$/.test(str); +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); } -/** - * This method accepts a term and looks for units that include it as - * a synonym - or that include the term in its name. - * - * @param theSyn the term to search for. This is assumed to be - * a string and not undefined. The calling method should do any - * necessary checking before calling this. - * @returns a hash with up to three elements: - * 'status' contains the status of the request, which can be 'error', - * 'failed' or succeeded'; - * 'msg' which contains a message for an error or if no units were found; and - * 'units' which is an array that contains one array for each unit found: - * the unit's csCode_, the unit's name_, and the unit's guidance_ - * - */ +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":10,"_process":369,"inherits":9}],12:[function(require,module,exports){ +(function (global){(function (){ +'use strict'; -function getSynonyms(theSyn) { - let retObj = {}; - let utab = UnitTables.getInstance(); - let resp = {}; - resp = utab.getUnitBySynonym(theSyn); // If we didn't get any units, transfer the status and message +var possibleNames = [ + 'BigInt64Array', + 'BigUint64Array', + 'Float32Array', + 'Float64Array', + 'Int16Array', + 'Int32Array', + 'Int8Array', + 'Uint16Array', + 'Uint32Array', + 'Uint8Array', + 'Uint8ClampedArray' +]; - if (!resp['units']) { - retObj['status'] = resp['status']; - retObj['msg'] = resp['msg']; - } else { - retObj['status'] = 'succeeded'; - let aLen = resp['units'].length; - retObj['units'] = []; +var g = typeof globalThis === 'undefined' ? global : globalThis; - for (let a = 0; a < aLen; a++) { - let theUnit = resp['units'][a]; - retObj['units'][a] = { - 'code': theUnit.csCode_, - 'name': theUnit.name_, - 'guidance': theUnit.guidance_ - }; - } // end do for all units returned +module.exports = function availableTypedArrays() { + var out = []; + for (var i = 0; i < possibleNames.length; i++) { + if (typeof g[possibleNames[i]] === 'function') { + out[out.length] = possibleNames[i]; + } + } + return out; +}; - } // end if we got a units list +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],13:[function(require,module,exports){ +'use strict' +exports.byteLength = byteLength +exports.toByteArray = toByteArray +exports.fromByteArray = fromByteArray - return retObj; -} // end getSynonyms +var lookup = [] +var revLookup = [] +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' +for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i] + revLookup[code.charCodeAt(i)] = i +} -},{"./unitTables.js":21}],16:[function(require,module,exports){ -"use strict"; +// Support decoding URL-safe base64 strings, as Node.js does. +// See: https://en.wikipedia.org/wiki/Base64#URL_applications +revLookup['-'.charCodeAt(0)] = 62 +revLookup['_'.charCodeAt(0)] = 63 -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.ucumJsonDefs = exports.UcumJsonDefs = void 0; +function getLens (b64) { + var len = b64.length -/** - * This class handles opening, reading and loading the JSON file of ucum - * definitions (prefixes, base units, and unit atoms). - * - * @author Lee Mericle - * - */ -var Pfx = require("./prefix.js"); + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } -var PfxT = require("./prefixTables.js"); + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('=') + if (validLen === -1) validLen = len -var Un = require("./unit.js"); + var placeHoldersLen = validLen === len + ? 0 + : 4 - (validLen % 4) -var Utab = require('./unitTables.js'); + return [validLen, placeHoldersLen] +} -var unpackArray = require('./jsonArrayPack.js').unpackArray; - -class UcumJsonDefs { - /** - * This method loads the JSON prefix and unit objects into the prefix and - * unit tables. - * - * @returns nothing - */ - loadJsonDefs() { - // requiring the file will take care of opening it for use - const jsonDefs = require('../data/ucumDefs.min.json'); - - jsonDefs.prefixes = unpackArray(jsonDefs.prefixes); - jsonDefs.units = unpackArray(jsonDefs.units); - - if (Utab.UnitTables.getInstance().unitsCount() === 0) { - let pTab = PfxT.PrefixTables.getInstance(); - let prefixes = jsonDefs["prefixes"]; - let plen = prefixes.length; +// base64 is 4/3 + up to two characters of the original data +function byteLength (b64) { + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} - for (let p = 0; p < plen; p++) { - let newPref = new Pfx.Prefix(prefixes[p]); - pTab.add(newPref); - } +function _byteLength (b64, validLen, placeHoldersLen) { + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} - let uTab = Utab.UnitTables.getInstance(); - let units = jsonDefs["units"]; - let ulen = units.length; +function toByteArray (b64) { + var tmp + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] - for (let u = 0; u < ulen; u++) { - let newUnit = new Un.Unit(units[u]); - uTab.addUnit(newUnit); - } - } // end if the data has not already been loaded + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) - } // end loadJsonDefs + var curByte = 0 + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 + ? validLen - 4 + : validLen -} // end UcumJsonDefs class + var i + for (i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)] + arr[curByte++] = (tmp >> 16) & 0xFF + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[curByte++] = tmp & 0xFF + } -exports.UcumJsonDefs = UcumJsonDefs; -var ucumJsonDefs = new UcumJsonDefs(); -exports.ucumJsonDefs = ucumJsonDefs; + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } + return arr +} -},{"../data/ucumDefs.min.json":8,"./jsonArrayPack.js":11,"./prefix.js":12,"./prefixTables.js":13,"./unit.js":19,"./unitTables.js":21}],17:[function(require,module,exports){ -"use strict"; +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + + lookup[num >> 12 & 0x3F] + + lookup[num >> 6 & 0x3F] + + lookup[num & 0x3F] +} -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UcumLhcUtils = void 0; +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = + ((uint8[i] << 16) & 0xFF0000) + + ((uint8[i + 1] << 8) & 0xFF00) + + (uint8[i + 2] & 0xFF) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} -var _ucumJsonDefs = require("./ucumJsonDefs.js"); +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 -var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + } -function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + parts.push( + lookup[tmp >> 2] + + lookup[(tmp << 4) & 0x3F] + + '==' + ) + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1] + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3F] + + lookup[(tmp << 2) & 0x3F] + + '=' + ) + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } + return parts.join('') +} -/** - * This class provides a single point of access to the LHC UCUM utilities - * - * @author Lee Mericle - * +},{}],14:[function(require,module,exports){ +(function (process,global,setImmediate){(function (){ +/* @preserve + * The MIT License (MIT) + * + * Copyright (c) 2013-2017 Petka Antonov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * */ -var Ucum = require('./config.js').Ucum; - -var UnitTables = require('./unitTables.js').UnitTables; +/** + * bluebird build version 3.5.1 + * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each +*/ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o 0) { + var fn = queue.shift(); + if (typeof fn !== "function") { + fn._settlePromises(); + continue; + } + var receiver = queue.shift(); + var arg = queue.shift(); + fn.call(receiver, arg); } +}; - if (toUnitCode) { - toUnitCode = toUnitCode.trim(); - } +Async.prototype._drainQueues = function () { + this._drainQueue(this._normalQueue); + this._reset(); + this._haveDrainedQueues = true; + this._drainQueue(this._lateQueue); +}; - if (!toUnitCode || toUnitCode == '') { - returnObj['status'] = 'error'; - returnObj['msg'].push('No "to" unit expression specified.'); +Async.prototype._queueTick = function () { + if (!this._isTickUsed) { + this._isTickUsed = true; + this._schedule(this.drainQueues); } +}; - if (returnObj['status'] !== 'error') { - try { - let fromUnit = null; - let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest); - fromUnit = parseResp['unit']; - if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']); +Async.prototype._reset = function () { + this._isTickUsed = false; +}; - if (parseResp['suggestions']) { - returnObj['suggestions'] = {}; - returnObj['suggestions']['from'] = parseResp['suggestions']; - } +module.exports = Async; +module.exports.firstLineError = firstLineError; - if (!fromUnit) { - returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` + `so no conversion could be performed.`); - } +},{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) { +var calledBind = false; +var rejectThis = function(_, e) { + this._reject(e); +}; - let toUnit = null; - parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest); - toUnit = parseResp['unit']; - if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']); +var targetRejected = function(e, context) { + context.promiseRejectionQueued = true; + context.bindingPromise._then(rejectThis, rejectThis, null, this, e); +}; - if (parseResp['suggestions']) { - if (!returnObj['suggestions']) returnObj['suggestions'] = {}; - returnObj['suggestions']['to'] = parseResp['suggestions']; - } +var bindingResolved = function(thisArg, context) { + if (((this._bitField & 50397184) === 0)) { + this._resolveCallback(context.target); + } +}; - if (!toUnit) { - returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` + `so no conversion could be performed.`); - } +var bindingRejected = function(e, context) { + if (!context.promiseRejectionQueued) this._reject(e); +}; - if (fromUnit && toUnit) { - try { - // if no molecular weight was specified perform a normal conversion - if (!molecularWeight) { - returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit); - } else { - if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) { - throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed for two ' + 'mole-based units. No conversion was attempted.'); - } +Promise.prototype.bind = function (thisArg) { + if (!calledBind) { + calledBind = true; + Promise.prototype._propagateFrom = debug.propagateFromFunction(); + Promise.prototype._boundValue = debug.boundValueFunction(); + } + var maybePromise = tryConvertToPromise(thisArg); + var ret = new Promise(INTERNAL); + ret._propagateFrom(this, 1); + var target = this._target(); + ret._setBoundTo(maybePromise); + if (maybePromise instanceof Promise) { + var context = { + promiseRejectionQueued: false, + promise: ret, + target: target, + bindingPromise: maybePromise + }; + target._then(INTERNAL, targetRejected, undefined, ret, context); + maybePromise._then( + bindingResolved, bindingRejected, undefined, ret, context); + ret._setOnCancel(maybePromise); + } else { + ret._resolveCallback(target); + } + return ret; +}; - if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) { - throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed when ' + 'neither unit is mole-based. No conversion was attempted.'); - } +Promise.prototype._setBoundTo = function (obj) { + if (obj !== undefined) { + this._bitField = this._bitField | 2097152; + this._boundTo = obj; + } else { + this._bitField = this._bitField & (~2097152); + } +}; - if (!fromUnit.isMoleMassCommensurable(toUnit)) { - throw new Error(`Sorry. ${fromUnitCode} cannot be ` + `converted to ${toUnitCode}.`); - } // if the "from" unit is a mole-based unit, assume a mole to mass - // request +Promise.prototype._isBound = function () { + return (this._bitField & 2097152) === 2097152; +}; +Promise.bind = function (thisArg, value) { + return Promise.resolve(value).bind(thisArg); +}; +}; - if (fromUnit.moleExp_ !== 0) { - returnObj['toVal'] = fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight); - } // else the "to" unit must be the mole-based unit, so assume a - // mass to mole request - else { - returnObj['toVal'] = fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight); - } - } // end if a molecular weight was specified - // if an error hasn't been thrown - either from convertFrom or here, - // set the return object to show success +},{}],4:[function(_dereq_,module,exports){ +"use strict"; +var old; +if (typeof Promise !== "undefined") old = Promise; +function noConflict() { + try { if (Promise === bluebird) Promise = old; } + catch (e) {} + return bluebird; +} +var bluebird = _dereq_("./promise")(); +bluebird.noConflict = noConflict; +module.exports = bluebird; +},{"./promise":22}],5:[function(_dereq_,module,exports){ +"use strict"; +var cr = Object.create; +if (cr) { + var callerCache = cr(null); + var getterCache = cr(null); + callerCache[" size"] = getterCache[" size"] = 0; +} - returnObj['status'] = 'succeeded'; - returnObj['fromUnit'] = fromUnit; - returnObj['toUnit'] = toUnit; - } catch (err) { - returnObj['status'] = 'failed'; - returnObj['msg'].push(err.message); - } - } // end if we have the from and to units +module.exports = function(Promise) { +var util = _dereq_("./util"); +var canEvaluate = util.canEvaluate; +var isIdentifier = util.isIdentifier; - } catch (err) { - if (err.message == Ucum.needMoleWeightMsg_) returnObj['status'] = 'failed';else returnObj['status'] = 'error'; - returnObj['msg'].push(err.message); - } +var getMethodCaller; +var getGetter; +if (!true) { +var makeMethodCaller = function (methodName) { + return new Function("ensureMethod", " \n\ + return function(obj) { \n\ + 'use strict' \n\ + var len = this.length; \n\ + ensureMethod(obj, 'methodName'); \n\ + switch(len) { \n\ + case 1: return obj.methodName(this[0]); \n\ + case 2: return obj.methodName(this[0], this[1]); \n\ + case 3: return obj.methodName(this[0], this[1], this[2]); \n\ + case 0: return obj.methodName(); \n\ + default: \n\ + return obj.methodName.apply(obj, this); \n\ + } \n\ + }; \n\ + ".replace(/methodName/g, methodName))(ensureMethod); +}; + +var makeGetter = function (propertyName) { + return new Function("obj", " \n\ + 'use strict'; \n\ + return obj.propertyName; \n\ + ".replace("propertyName", propertyName)); +}; + +var getCompiled = function(name, compiler, cache) { + var ret = cache[name]; + if (typeof ret !== "function") { + if (!isIdentifier(name)) { + return null; + } + ret = compiler(name); + cache[name] = ret; + cache[" size"]++; + if (cache[" size"] > 512) { + var keys = Object.keys(cache); + for (var i = 0; i < 256; ++i) delete cache[keys[i]]; + cache[" size"] = keys.length - 256; + } } + return ret; +}; - return returnObj; - } // end convertUnitTo +getMethodCaller = function(name) { + return getCompiled(name, makeMethodCaller, callerCache); +}; - /** - * This method accepts a term and looks for units that include it as - * a synonym - or that include the term in its name. - * - * @param theSyn the term to search for - * @returns a hash with up to three elements: - * 'status' contains the status of the request, which can be 'error', - * 'failed' or succeeded'; - * 'msg' which contains a message for an error or if no units were found; and - * 'units' which is an array that contains one hash for each unit found: - * 'code' is the unit's csCode_ - * 'name' is the unit's name_ - * 'guidance' is the unit's guidance_ - * - */ +getGetter = function(name) { + return getCompiled(name, makeGetter, getterCache); +}; +} +function ensureMethod(obj, methodName) { + var fn; + if (obj != null) fn = obj[methodName]; + if (typeof fn !== "function") { + var message = "Object " + util.classString(obj) + " has no method '" + + util.toString(methodName) + "'"; + throw new Promise.TypeError(message); + } + return fn; +} - checkSynonyms(theSyn) { - let retObj = {}; +function caller(obj) { + var methodName = this.pop(); + var fn = ensureMethod(obj, methodName); + return fn.apply(obj, this); +} +Promise.prototype.call = function (methodName) { + var args = [].slice.call(arguments, 1);; + if (!true) { + if (canEvaluate) { + var maybeCaller = getMethodCaller(methodName); + if (maybeCaller !== null) { + return this._then( + maybeCaller, undefined, undefined, args, undefined); + } + } + } + args.push(methodName); + return this._then(caller, undefined, undefined, args, undefined); +}; - if (theSyn === undefined || theSyn === null) { - retObj['status'] = 'error'; - retObj['msg'] = 'No term specified for synonym search.'; +function namedGetter(obj) { + return obj[this]; +} +function indexedGetter(obj) { + var index = +this; + if (index < 0) index = Math.max(0, index + obj.length); + return obj[index]; +} +Promise.prototype.get = function (propertyName) { + var isIndex = (typeof propertyName === "number"); + var getter; + if (!isIndex) { + if (canEvaluate) { + var maybeGetter = getGetter(propertyName); + getter = maybeGetter !== null ? maybeGetter : namedGetter; + } else { + getter = namedGetter; + } } else { - retObj = intUtils_.getSynonyms(theSyn); - } // end if a search synonym was supplied - + getter = indexedGetter; + } + return this._then(getter, undefined, undefined, propertyName, undefined); +}; +}; - return retObj; - } // end checkSynonyms +},{"./util":36}],6:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, PromiseArray, apiRejection, debug) { +var util = _dereq_("./util"); +var tryCatch = util.tryCatch; +var errorObj = util.errorObj; +var async = Promise._async; - /** - * This method parses a unit string to get (or try to get) the unit - * represented by the string. It returns an error message if no string was specified - * or if any errors were encountered trying to get the unit. - * - * @param uName the expression/string representing the unit - * @param valConv indicates what type of request this is for - a request to - * validate (pass in 'validate') or a request to convert (pass in 'convert') - * @param suggest a boolean to indicate whether or not suggestions are - * requested for a string that cannot be resolved to a valid unit; - * true indicates suggestions are wanted; false indicates they are not, - * and is the default if the parameter is not specified; - * @returns a hash containing: - * 'unit' the unit object (or null if there were problems creating the - * unit); - * 'origString' the possibly updated unit string passed in; - * 'retMsg' an array of user messages (informational, error or warning) if - * any were generated (IF any were generated, otherwise will be an - * empty array); and - * 'suggestions' is an array of 1 or more hash objects. Each hash - * contains three elements: - * 'msg' which is a message indicating what unit expression the - * suggestions are for; - * 'invalidUnit' which is the unit expression the suggestions are - * for; and - * 'units' which is an array of data for each suggested unit found. - * Each array will contain the unit code, the unit name and the - * unit guidance (if any). - * The return hash will not contain a suggestions array if a valid unit - * was found or if suggestions were not requested and found. - */ +Promise.prototype["break"] = Promise.prototype.cancel = function() { + if (!debug.cancellation()) return this._warn("cancellation is disabled"); + var promise = this; + var child = promise; + while (promise._isCancellable()) { + if (!promise._cancelBy(child)) { + if (child._isFollowing()) { + child._followee().cancel(); + } else { + child._cancelBranched(); + } + break; + } - getSpecifiedUnit(uName, valConv, suggest) { - if (suggest === undefined) suggest = false; - let retObj = {}; - retObj['retMsg'] = []; + var parent = promise._cancellationParent; + if (parent == null || !parent._isCancellable()) { + if (promise._isFollowing()) { + promise._followee().cancel(); + } else { + promise._cancelBranched(); + } + break; + } else { + if (promise._isFollowing()) promise._followee().cancel(); + promise._setWillBeCancelled(); + child = promise; + promise = parent; + } + } +}; - if (!uName) { - retObj['retMsg'].push('No unit string specified.'); - } else { - let utab = UnitTables.getInstance(); - uName = uName.trim(); // go ahead and just try using the name as the code. This may or may not - // work, but if it does, it cuts out a lot of parsing. +Promise.prototype._branchHasCancelled = function() { + this._branchesRemainingToCancel--; +}; - let theUnit = utab.getUnitByCode(uName); // If we found it, set the returned unit string to what was passed in; - // otherwise try parsing as a unit string +Promise.prototype._enoughBranchesHaveCancelled = function() { + return this._branchesRemainingToCancel === undefined || + this._branchesRemainingToCancel <= 0; +}; - if (theUnit) { - retObj['unit'] = theUnit; - retObj['origString'] = uName; - } else { - try { - let resp = this.uStrParser_.parseString(uName, valConv, suggest); - retObj['unit'] = resp[0]; - retObj['origString'] = resp[1]; - if (resp[2]) retObj['retMsg'] = resp[2]; - retObj['suggestions'] = resp[3]; - } catch (err) { - console.log(`Unit requested for unit string ${uName}.` + 'request unsuccessful; error thrown = ' + err.message); - retObj['retMsg'].unshift(`${uName} is not a valid unit. ` + `${err.message}`); +Promise.prototype._cancelBy = function(canceller) { + if (canceller === this) { + this._branchesRemainingToCancel = 0; + this._invokeOnCancel(); + return true; + } else { + this._branchHasCancelled(); + if (this._enoughBranchesHaveCancelled()) { + this._invokeOnCancel(); + return true; } - } // end if the unit was not found as a unit name - - } // end if a unit expression was specified + } + return false; +}; +Promise.prototype._cancelBranched = function() { + if (this._enoughBranchesHaveCancelled()) { + this._cancel(); + } +}; - return retObj; - } // end getSpecifiedUnit +Promise.prototype._cancel = function() { + if (!this._isCancellable()) return; + this._setCancelled(); + async.invoke(this._cancelPromises, this, undefined); +}; - /** - * This method retrieves a list of units commensurable, i.e., that can be - * converted from and to, a specified unit. Returns an error if the "from" - * unit cannot be found. - * - * @param fromName the name/unit string of the "from" unit - * @returns an array containing two elements; - * first element is the list of commensurable units if any were found - * second element is an error message if the "from" unit is not found - */ +Promise.prototype._cancelPromises = function() { + if (this._length() > 0) this._settlePromises(); +}; +Promise.prototype._unsetOnCancel = function() { + this._onCancelField = undefined; +}; - commensurablesList(fromName) { - let retMsg = []; - let commUnits = null; - let parseResp = this.getSpecifiedUnit(fromName, 'validate', false); - let fromUnit = parseResp['unit']; - if (parseResp['retMsg'].length > 0) retMsg = parseResp['retMsg']; +Promise.prototype._isCancellable = function() { + return this.isPending() && !this._isCancelled(); +}; - if (!fromUnit) { - retMsg.push(`Could not find unit ${fromName}.`); - } else { - let dimVec = null; - let fromDim = fromUnit.getProperty('dim_'); +Promise.prototype.isCancellable = function() { + return this.isPending() && !this.isCancelled(); +}; - if (!fromDim) { - retMsg.push('No commensurable units were found for ' + fromName); - } else { - try { - dimVec = fromDim.getProperty('dimVec_'); - } catch (err) { - retMsg.push(err.message); - if (err.message === "Dimension does not have requested property(dimVec_)") dimVec = null; +Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) { + if (util.isArray(onCancelCallback)) { + for (var i = 0; i < onCancelCallback.length; ++i) { + this._doInvokeOnCancel(onCancelCallback[i], internalOnly); } - - if (dimVec) { - let utab = UnitTables.getInstance(); - commUnits = utab.getUnitsByDimension(dimVec); + } else if (onCancelCallback !== undefined) { + if (typeof onCancelCallback === "function") { + if (!internalOnly) { + var e = tryCatch(onCancelCallback).call(this._boundValue()); + if (e === errorObj) { + this._attachExtraTrace(e.e); + async.throwLater(e.e); + } + } + } else { + onCancelCallback._resultCancelled(this); } - } // end if the from unit has a dimension vector - - } // end if we found a "from" unit + } +}; +Promise.prototype._invokeOnCancel = function() { + var onCancelCallback = this._onCancel(); + this._unsetOnCancel(); + async.invoke(this._doInvokeOnCancel, this, onCancelCallback); +}; - return [commUnits, retMsg]; - } // end commensurablesList +Promise.prototype._invokeInternalOnCancel = function() { + if (this._isCancellable()) { + this._doInvokeOnCancel(this._onCancel(), true); + this._unsetOnCancel(); + } +}; +Promise.prototype._resultCancelled = function() { + this.cancel(); +}; -} // end UcumLhcUtils class +}; -/** - * This function exists ONLY until the original UcumLhcUtils constructor - * is called for the first time. It's defined here in case getInstance - * is called before the constructor. This calls the constructor. - * - * The constructor redefines the getInstance function to return the - * singleton UcumLhcUtils object. This is based on the UnitTables singleton - * implementation; see more detail in the UnitTables constructor description. - * - * NO LONGER TRUE - not implemented as a singleton. This method retained to - * avoid problems with calls to it that exist throughout the code. - * - * @return the (formerly singleton) UcumLhcUtils object. - */ +},{"./util":36}],7:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(NEXT_FILTER) { +var util = _dereq_("./util"); +var getKeys = _dereq_("./es5").keys; +var tryCatch = util.tryCatch; +var errorObj = util.errorObj; +function catchFilter(instances, cb, promise) { + return function(e) { + var boundTo = promise._boundValue(); + predicateLoop: for (var i = 0; i < instances.length; ++i) { + var item = instances[i]; -exports.UcumLhcUtils = UcumLhcUtils; + if (item === Error || + (item != null && item.prototype instanceof Error)) { + if (e instanceof item) { + return tryCatch(cb).call(boundTo, e); + } + } else if (typeof item === "function") { + var matchesPredicate = tryCatch(item).call(boundTo, e); + if (matchesPredicate === errorObj) { + return matchesPredicate; + } else if (matchesPredicate) { + return tryCatch(cb).call(boundTo, e); + } + } else if (util.isObject(e)) { + var keys = getKeys(item); + for (var j = 0; j < keys.length; ++j) { + var key = keys[j]; + if (item[key] != e[key]) { + continue predicateLoop; + } + } + return tryCatch(cb).call(boundTo, e); + } + } + return NEXT_FILTER; + }; +} -UcumLhcUtils.getInstance = function () { - return new UcumLhcUtils(); +return catchFilter; }; - -},{"./config.js":9,"./ucumInternalUtils.js":15,"./ucumJsonDefs.js":16,"./unitString.js":20,"./unitTables.js":21}],18:[function(require,module,exports){ +},{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){ "use strict"; +module.exports = function(Promise) { +var longStackTraces = false; +var contextStack = []; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UnitTables = exports.UcumLhcUtils = exports.Ucum = void 0; - -/** - * This exports definitions for ucum classes that need references to them - * available to the demo code. The actual code will be in the ucumPkg - * library found in the dist directory. This file provides the hooks to - * those classes within the library. - */ -var Ucum = require("./config.js").Ucum; - -exports.Ucum = Ucum; - -var UcumLhcUtils = require("./ucumLhcUtils.js").UcumLhcUtils; +Promise.prototype._promiseCreated = function() {}; +Promise.prototype._pushContext = function() {}; +Promise.prototype._popContext = function() {return null;}; +Promise._peekContext = Promise.prototype._peekContext = function() {}; -exports.UcumLhcUtils = UcumLhcUtils; +function Context() { + this._trace = new Context.CapturedTrace(peekContext()); +} +Context.prototype._pushContext = function () { + if (this._trace !== undefined) { + this._trace._promiseCreated = null; + contextStack.push(this._trace); + } +}; -var UnitTables = require("./unitTables.js").UnitTables; +Context.prototype._popContext = function () { + if (this._trace !== undefined) { + var trace = contextStack.pop(); + var ret = trace._promiseCreated; + trace._promiseCreated = null; + return ret; + } + return null; +}; -exports.UnitTables = UnitTables; +function createContext() { + if (longStackTraces) return new Context(); +} +function peekContext() { + var lastIndex = contextStack.length - 1; + if (lastIndex >= 0) { + return contextStack[lastIndex]; + } + return undefined; +} +Context.CapturedTrace = null; +Context.create = createContext; +Context.deactivateLongStackTraces = function() {}; +Context.activateLongStackTraces = function() { + var Promise_pushContext = Promise.prototype._pushContext; + var Promise_popContext = Promise.prototype._popContext; + var Promise_PeekContext = Promise._peekContext; + var Promise_peekContext = Promise.prototype._peekContext; + var Promise_promiseCreated = Promise.prototype._promiseCreated; + Context.deactivateLongStackTraces = function() { + Promise.prototype._pushContext = Promise_pushContext; + Promise.prototype._popContext = Promise_popContext; + Promise._peekContext = Promise_PeekContext; + Promise.prototype._peekContext = Promise_peekContext; + Promise.prototype._promiseCreated = Promise_promiseCreated; + longStackTraces = false; + }; + longStackTraces = true; + Promise.prototype._pushContext = Context.prototype._pushContext; + Promise.prototype._popContext = Context.prototype._popContext; + Promise._peekContext = Promise.prototype._peekContext = peekContext; + Promise.prototype._promiseCreated = function() { + var ctx = this._peekContext(); + if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this; + }; +}; +return Context; +}; -},{"./config.js":9,"./ucumLhcUtils.js":17,"./unitTables.js":21}],19:[function(require,module,exports){ +},{}],9:[function(_dereq_,module,exports){ "use strict"; +module.exports = function(Promise, Context) { +var getDomain = Promise._getDomain; +var async = Promise._async; +var Warning = _dereq_("./errors").Warning; +var util = _dereq_("./util"); +var canAttachTrace = util.canAttachTrace; +var unhandledRejectionHandled; +var possiblyUnhandledRejection; +var bluebirdFramePattern = + /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/; +var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/; +var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/; +var stackFramePattern = null; +var formatStack = null; +var indentStackFrames = false; +var printWarning; +var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 && + (true || + util.env("BLUEBIRD_DEBUG") || + util.env("NODE_ENV") === "development")); -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Unit = void 0; +var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 && + (debugging || util.env("BLUEBIRD_WARNINGS"))); -var _ucumFunctions = _interopRequireDefault(require("./ucumFunctions.js")); +var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 && + (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES"))); -var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); +var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 && + (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN")); -function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } +Promise.prototype.suppressUnhandledRejections = function() { + var target = this._target(); + target._bitField = ((target._bitField & (~1048576)) | + 524288); +}; -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +Promise.prototype._ensurePossibleRejectionHandled = function () { + if ((this._bitField & 524288) !== 0) return; + this._setRejectionIsUnhandled(); + var self = this; + setTimeout(function() { + self._notifyUnhandledRejection(); + }, 1); +}; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +Promise.prototype._notifyUnhandledRejectionIsHandled = function () { + fireRejectionEvent("rejectionHandled", + unhandledRejectionHandled, undefined, this); +}; -/** - * This class represents one unit of measure. It includes - * functions to cover constructor, accessor, and assignment tasks as - * well as operators to calculate multiplication, division and raising - * to a power. - * - * @author Lee Mericle, based on java version by Gunther Schadow - * - */ -var Ucum = require('./config.js').Ucum; +Promise.prototype._setReturnedNonUndefined = function() { + this._bitField = this._bitField | 268435456; +}; -var Dimension = require('./dimension.js').Dimension; +Promise.prototype._returnedNonUndefined = function() { + return (this._bitField & 268435456) !== 0; +}; -var UnitTables; +Promise.prototype._notifyUnhandledRejection = function () { + if (this._isRejectionUnhandled()) { + var reason = this._settledValue(); + this._setUnhandledRejectionIsNotified(); + fireRejectionEvent("unhandledRejection", + possiblyUnhandledRejection, reason, this); + } +}; -var isInteger = require("is-integer"); +Promise.prototype._setUnhandledRejectionIsNotified = function () { + this._bitField = this._bitField | 262144; +}; -class Unit { - /** - * Constructor. - * - * @param attrs an optional parameter that may be: - * a string, which is parsed by the unit parser, which creates - * the unit from the parsed string; or - * a hash containing all or some values for the attributes of - * the unit, where the keys are the attribute names, without a - * trailing underscore, e.g., name instead of name_; or - * null, in which case an empty hash is created and used to - * set the values forthe attributes. - * If a hash (empty or not) is used, attributes for which no value - * is specified are assigned a default value. - * - */ - constructor(attrs = {}) { - // Process the attrs hash passed in, which may be empty. - // Create and assign values (from the attrs hash or defaults) to all - // attributes. From Class Declarations in Understanding ECMAScript, - // https://leanpub.com/understandinges6/read/#leanpub-auto-class-declarations, - // "Own properties, properties that occur on the instance rather than the - // prototype, can only be created inside of a class constructor or method. - // It's recommended to create all possible own properties inside of the - // constructor function so there's a single place that's responsible for - // all of them." +Promise.prototype._unsetUnhandledRejectionIsNotified = function () { + this._bitField = this._bitField & (~262144); +}; - /* - * Flag indicating whether or not this is a base unit - */ - this.isBase_ = attrs['isBase_'] || false; - /* - * The unit name, e.g., meter - */ +Promise.prototype._isUnhandledRejectionNotified = function () { + return (this._bitField & 262144) > 0; +}; - this.name_ = attrs['name_'] || ''; - /* - * The unit's case-sensitive code, e.g., m - */ +Promise.prototype._setRejectionIsUnhandled = function () { + this._bitField = this._bitField | 1048576; +}; - this.csCode_ = attrs['csCode_'] || ''; - /* - * The unit's case-insensitive code, e.g., M - */ +Promise.prototype._unsetRejectionIsUnhandled = function () { + this._bitField = this._bitField & (~1048576); + if (this._isUnhandledRejectionNotified()) { + this._unsetUnhandledRejectionIsNotified(); + this._notifyUnhandledRejectionIsHandled(); + } +}; - this.ciCode_ = attrs['ciCode_'] || ''; - /* - * The unit's property, e.g., length - */ +Promise.prototype._isRejectionUnhandled = function () { + return (this._bitField & 1048576) > 0; +}; - this.property_ = attrs['property_'] || ''; - /* - * The magnitude of the unit, e.g., 3600/3937 for a yard, - * where a yard - 3600/3973 * m(eter). The Dimension - * property specifies the meter - which is the unit on which - * a yard is based, and this magnitude specifies how to figure - * this unit based on the base unit. - */ +Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) { + return warn(message, shouldUseOwnTrace, promise || this); +}; - this.magnitude_ = attrs['magnitude_'] || 1; - /* - * The Dimension object of the unit - */ +Promise.onPossiblyUnhandledRejection = function (fn) { + var domain = getDomain(); + possiblyUnhandledRejection = + typeof fn === "function" ? (domain === null ? + fn : util.domainBind(domain, fn)) + : undefined; +}; - if (attrs['dim_'] === undefined || attrs['dim_'] === null) { - this.dim_ = new Dimension(); - } // When the unit data stored in json format is reloaded, the dimension data - // is recognized as a a hash, not as a Dimension object. - else if (attrs['dim_']['dimVec_'] !== undefined) { - this.dim_ = new Dimension(attrs['dim_']['dimVec_']); - } else if (attrs['dim_'] instanceof Dimension) { - this.dim_ = attrs['dim_']; - } else if (attrs['dim_'] instanceof Array || isInteger(attrs['dim_'])) { - this.dim_ = new Dimension(attrs['dim_']); - } else { - this.dim_ = new Dimension(); - } - /* - * The print symbol of the unit, e.g., m - */ +Promise.onUnhandledRejectionHandled = function (fn) { + var domain = getDomain(); + unhandledRejectionHandled = + typeof fn === "function" ? (domain === null ? + fn : util.domainBind(domain, fn)) + : undefined; +}; +var disableLongStackTraces = function() {}; +Promise.longStackTraces = function () { + if (async.haveItemsQueued() && !config.longStackTraces) { + throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + if (!config.longStackTraces && longStackTracesIsSupported()) { + var Promise_captureStackTrace = Promise.prototype._captureStackTrace; + var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace; + config.longStackTraces = true; + disableLongStackTraces = function() { + if (async.haveItemsQueued() && !config.longStackTraces) { + throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + Promise.prototype._captureStackTrace = Promise_captureStackTrace; + Promise.prototype._attachExtraTrace = Promise_attachExtraTrace; + Context.deactivateLongStackTraces(); + async.enableTrampoline(); + config.longStackTraces = false; + }; + Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace; + Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace; + Context.activateLongStackTraces(); + async.disableTrampolineIfNecessary(); + } +}; - this.printSymbol_ = attrs['printSymbol_'] || null; - /* - * The class of the unit, where given, e.g., dimless - */ +Promise.hasLongStackTraces = function () { + return config.longStackTraces && longStackTracesIsSupported(); +}; - this.class_ = attrs['class_'] || null; - /* - * A flag indicating whether or not the unit is metric - */ +var fireDomEvent = (function() { + try { + if (typeof CustomEvent === "function") { + var event = new CustomEvent("CustomEvent"); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = new CustomEvent(name.toLowerCase(), { + detail: event, + cancelable: true + }); + return !util.global.dispatchEvent(domEvent); + }; + } else if (typeof Event === "function") { + var event = new Event("CustomEvent"); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = new Event(name.toLowerCase(), { + cancelable: true + }); + domEvent.detail = event; + return !util.global.dispatchEvent(domEvent); + }; + } else { + var event = document.createEvent("CustomEvent"); + event.initCustomEvent("testingtheevent", false, true, {}); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = document.createEvent("CustomEvent"); + domEvent.initCustomEvent(name.toLowerCase(), false, true, + event); + return !util.global.dispatchEvent(domEvent); + }; + } + } catch (e) {} + return function() { + return false; + }; +})(); - this.isMetric_ = attrs['isMetric_'] || false; - /* - * The "variable" - which I think is used only for base units - * The symbol for the variable as used in equations, e.g., s for distance - */ +var fireGlobalEvent = (function() { + if (util.isNode) { + return function() { + return process.emit.apply(process, arguments); + }; + } else { + if (!util.global) { + return function() { + return false; + }; + } + return function(name) { + var methodName = "on" + name.toLowerCase(); + var method = util.global[methodName]; + if (!method) return false; + method.apply(util.global, [].slice.call(arguments, 1)); + return true; + }; + } +})(); - this.variable_ = attrs['variable_'] || null; // comes from 'dim' in XML +function generatePromiseLifecycleEventObject(name, promise) { + return {promise: promise}; +} - /* - * The conversion function - */ +var eventToObjectGenerator = { + promiseCreated: generatePromiseLifecycleEventObject, + promiseFulfilled: generatePromiseLifecycleEventObject, + promiseRejected: generatePromiseLifecycleEventObject, + promiseResolved: generatePromiseLifecycleEventObject, + promiseCancelled: generatePromiseLifecycleEventObject, + promiseChained: function(name, promise, child) { + return {promise: promise, child: child}; + }, + warning: function(name, warning) { + return {warning: warning}; + }, + unhandledRejection: function (name, reason, promise) { + return {reason: reason, promise: promise}; + }, + rejectionHandled: generatePromiseLifecycleEventObject +}; - this.cnv_ = attrs['cnv_'] || null; - /* - * The conversion prefix - */ +var activeFireEvent = function (name) { + var globalEventFired = false; + try { + globalEventFired = fireGlobalEvent.apply(null, arguments); + } catch (e) { + async.throwLater(e); + globalEventFired = true; + } - this.cnvPfx_ = attrs['cnvPfx_'] || 1; - /* - * Flag indicating whether or not this is a "special" unit, i.e., is - * constructed using a function specific to the measurement, e.g., - * fahrenheit and celsius - */ + var domEventFired = false; + try { + domEventFired = fireDomEvent(name, + eventToObjectGenerator[name].apply(null, arguments)); + } catch (e) { + async.throwLater(e); + domEventFired = true; + } - this.isSpecial_ = attrs['isSpecial_'] || false; - /* - * Flag indicating whether or not this is an arbitrary unit - */ + return domEventFired || globalEventFired; +}; - this.isArbitrary_ = attrs['isArbitrary_'] || false; - /* - * Integer indicating what level of exponent applies to a mole-based portion - * of the unit. So, for the unit "mol", this will be 1. For "mol2" this - * will be 2. For "1/mol" this will be -1. Any unit that does not include - * a mole will have a 0 in this field. This is used to determine - * commensurability for mole<->mass conversions. - */ +Promise.config = function(opts) { + opts = Object(opts); + if ("longStackTraces" in opts) { + if (opts.longStackTraces) { + Promise.longStackTraces(); + } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) { + disableLongStackTraces(); + } + } + if ("warnings" in opts) { + var warningsOption = opts.warnings; + config.warnings = !!warningsOption; + wForgottenReturn = config.warnings; - this.moleExp_ = attrs['moleExp_'] || 0; - /* - * Added when added LOINC list of units - * synonyms are used by the autocompleter to enhance lookup capabilities - * while source says where the unit first shows up. Current sources are - * UCUM - which are units from the unitsofmeasure.org list and LOINC - - * which are units from the LOINC data. - */ - - this.synonyms_ = attrs['synonyms_'] || null; - this.source_ = attrs['source_'] || null; - this.loincProperty_ = attrs['loincProperty_'] || null; - this.category_ = attrs['category_'] || null; - this.guidance_ = attrs['guidance_'] || null; - /* - * Used to compute dimension; storing for now until I complete - * unit definition parsing - */ - - /* - * Case sensitive (cs) and case insensitive (ci) base unit strings, - * includes exponent and prefix if applicable - specified in - * nnn -- the unit part -- - * in the ucum-essence.xml file, and may be specified by a user - * when requesting conversion or validation of a unit string. The - * magnitude (base factor) is used with this to determine the new unit. - * For example, a Newton (unit code N) is created from the string - * kg.m/s2, and the value of 1 (base factor defined below). An hour - * (unit code h) is created from the unit min (minute) with a value - * of 60. - */ - - this.csUnitString_ = attrs['csUnitString_'] || null; - this.ciUnitString_ = attrs['ciUnitString_'] || null; - /* - * String and numeric versions of factor applied to unit specified in - * nnn -- the value part - */ - - this.baseFactorStr_ = attrs['baseFactorStr_'] || null; - this.baseFactor_ = attrs['baseFactor_'] || null; - /* - * Flag used to indicate units where the definition process failed - * when parsing units from the official units definitions file - * (currently using the ucum-essence.xml file). We keep these - * so that we can use them to at least validate them as valid - * units, but we don't try to convert them. This is temporary - * and only to account for instances where the code does not - * take into account various special cases in the xml file. - * - * This is NOT used when trying to validate a unit string - * submitted during a conversion or validation attempt. - */ - - this.defError_ = attrs['defError_'] || false; - } // end constructor - - /** - * Assign the unity (= dimensionless unit 1) to this unit. - * - * @return this unit - */ - - - assignUnity() { - this.name_ = ""; - this.magnitude_ = 1; - if (!this.dim_) this.dim_ = new Dimension(); - this.dim_.assignZero(); - this.cnv_ = null; - this.cnvPfx_ = 1; - return this; - } // end assignUnity - - /** - * This assigns one or more values, as provided in the hash passed in, - * to this unit. - * - * @param vals hash of values to be assigned to the attributes - * specified by the key(s), which should be the attribute - * name without the trailing underscore, e.g., name instead - * of name_. - * @return nothing - */ - - - assignVals(vals) { - for (let key in vals) { - let uKey = !key.charAt(key.length - 1) === '_' ? key + '_' : key; - if (this.hasOwnProperty(uKey)) this[uKey] = vals[key];else throw new Error(`Parameter error; ${key} is not a property of a Unit`); + if (util.isObject(warningsOption)) { + if ("wForgottenReturn" in warningsOption) { + wForgottenReturn = !!warningsOption.wForgottenReturn; + } + } } - } // end assignVals + if ("cancellation" in opts && opts.cancellation && !config.cancellation) { + if (async.haveItemsQueued()) { + throw new Error( + "cannot enable cancellation after promises are in use"); + } + Promise.prototype._clearCancellationData = + cancellationClearCancellationData; + Promise.prototype._propagateFrom = cancellationPropagateFrom; + Promise.prototype._onCancel = cancellationOnCancel; + Promise.prototype._setOnCancel = cancellationSetOnCancel; + Promise.prototype._attachCancellationCallback = + cancellationAttachCancellationCallback; + Promise.prototype._execute = cancellationExecute; + propagateFromFunction = cancellationPropagateFrom; + config.cancellation = true; + } + if ("monitoring" in opts) { + if (opts.monitoring && !config.monitoring) { + config.monitoring = true; + Promise.prototype._fireEvent = activeFireEvent; + } else if (!opts.monitoring && config.monitoring) { + config.monitoring = false; + Promise.prototype._fireEvent = defaultFireEvent; + } + } + return Promise; +}; - /** - * This creates a clone of this unit. - * - * @return the clone - */ +function defaultFireEvent() { return false; } +Promise.prototype._fireEvent = defaultFireEvent; +Promise.prototype._execute = function(executor, resolve, reject) { + try { + executor(resolve, reject); + } catch (e) { + return e; + } +}; +Promise.prototype._onCancel = function () {}; +Promise.prototype._setOnCancel = function (handler) { ; }; +Promise.prototype._attachCancellationCallback = function(onCancel) { + ; +}; +Promise.prototype._captureStackTrace = function () {}; +Promise.prototype._attachExtraTrace = function () {}; +Promise.prototype._clearCancellationData = function() {}; +Promise.prototype._propagateFrom = function (parent, flags) { + ; + ; +}; - clone() { - let retUnit = new Unit(); - Object.getOwnPropertyNames(this).forEach(val => { - if (val === 'dim_') { - if (this['dim_']) retUnit['dim_'] = this['dim_'].clone();else retUnit['dim_'] = null; - } else retUnit[val] = this[val]; - }); - return retUnit; - } // end clone +function cancellationExecute(executor, resolve, reject) { + var promise = this; + try { + executor(resolve, reject, function(onCancel) { + if (typeof onCancel !== "function") { + throw new TypeError("onCancel must be a function, got: " + + util.toString(onCancel)); + } + promise._attachCancellationCallback(onCancel); + }); + } catch (e) { + return e; + } +} - /** - * This assigns all properties of a unit passed to it to this unit. - * - * @param unit2 the unit whose properties are to be assigned to this one. - * @return nothing; this unit is updated - */ +function cancellationAttachCancellationCallback(onCancel) { + if (!this._isCancellable()) return this; + var previousOnCancel = this._onCancel(); + if (previousOnCancel !== undefined) { + if (util.isArray(previousOnCancel)) { + previousOnCancel.push(onCancel); + } else { + this._setOnCancel([previousOnCancel, onCancel]); + } + } else { + this._setOnCancel(onCancel); + } +} - assign(unit2) { - Object.getOwnPropertyNames(unit2).forEach(val => { - if (val === 'dim_') { - if (unit2['dim_']) this['dim_'] = unit2['dim_'].clone();else this['dim_'] = null; - } else { - this[val] = unit2[val]; - } - }); - } // end assign +function cancellationOnCancel() { + return this._onCancelField; +} - /** - * This determines whether or not object properties of the unit - * passed in are equal to the corresponding properties in this unit. - * The following properties are the only ones checked: - * magnitude_, dim_, cnv_ and cnvPfx_ - * - * @param unit2 the unit whose properties are to be checked. - * @return boolean indicating whether or not they match - */ +function cancellationSetOnCancel(onCancel) { + this._onCancelField = onCancel; +} +function cancellationClearCancellationData() { + this._cancellationParent = undefined; + this._onCancelField = undefined; +} - equals(unit2) { - return this.magnitude_ === unit2.magnitude_ && this.cnv_ === unit2.cnv_ && this.cnvPfx_ === unit2.cnvPfx_ && (this.dim_ === null && unit2.dim_ === null || this.dim_.equals(unit2.dim_)); - } // end equals +function cancellationPropagateFrom(parent, flags) { + if ((flags & 1) !== 0) { + this._cancellationParent = parent; + var branchesRemainingToCancel = parent._branchesRemainingToCancel; + if (branchesRemainingToCancel === undefined) { + branchesRemainingToCancel = 0; + } + parent._branchesRemainingToCancel = branchesRemainingToCancel + 1; + } + if ((flags & 2) !== 0 && parent._isBound()) { + this._setBoundTo(parent._boundTo); + } +} - /** - * This method compares every attribute of two objects to determine - * if they all match. - * - * @param unit2 the unit that is to be compared to this unit - * @return boolean indicating whether or not every attribute matches - */ +function bindingPropagateFrom(parent, flags) { + if ((flags & 2) !== 0 && parent._isBound()) { + this._setBoundTo(parent._boundTo); + } +} +var propagateFromFunction = bindingPropagateFrom; +function boundValueFunction() { + var ret = this._boundTo; + if (ret !== undefined) { + if (ret instanceof Promise) { + if (ret.isFulfilled()) { + return ret.value(); + } else { + return undefined; + } + } + } + return ret; +} - fullEquals(unit2) { - let thisAttr = Object.keys(this).sort(); - let u2Attr = Object.keys(unit2).sort(); - let keyLen = thisAttr.length; - let match = keyLen === u2Attr.length; // check each attribute. Dimension objects have to checked using - // the equals function of the Dimension class. +function longStackTracesCaptureStackTrace() { + this._trace = new CapturedTrace(this._peekContext()); +} - for (let k = 0; k < keyLen && match; k++) { - if (thisAttr[k] === u2Attr[k]) { - if (thisAttr[k] === 'dim_') match = this.dim_.equals(unit2.dim_);else match = this[thisAttr[k]] === unit2[thisAttr[k]]; - } else match = false; - } // end do for each key and attribute +function longStackTracesAttachExtraTrace(error, ignoreSelf) { + if (canAttachTrace(error)) { + var trace = this._trace; + if (trace !== undefined) { + if (ignoreSelf) trace = trace._parent; + } + if (trace !== undefined) { + trace.attachExtraTrace(error); + } else if (!error.__stackCleaned__) { + var parsed = parseStackAndMessage(error); + util.notEnumerableProp(error, "stack", + parsed.message + "\n" + parsed.stack.join("\n")); + util.notEnumerableProp(error, "__stackCleaned__", true); + } + } +} +function checkForgottenReturns(returnValue, promiseCreated, name, promise, + parent) { + if (returnValue === undefined && promiseCreated !== null && + wForgottenReturn) { + if (parent !== undefined && parent._returnedNonUndefined()) return; + if ((promise._bitField & 65535) === 0) return; - return match; - } // end of fullEquals + if (name) name = name + " "; + var handlerLine = ""; + var creatorLine = ""; + if (promiseCreated._trace) { + var traceLines = promiseCreated._trace.stack.split("\n"); + var stack = cleanStack(traceLines); + for (var i = stack.length - 1; i >= 0; --i) { + var line = stack[i]; + if (!nodeFramePattern.test(line)) { + var lineMatches = line.match(parseLinePattern); + if (lineMatches) { + handlerLine = "at " + lineMatches[1] + + ":" + lineMatches[2] + ":" + lineMatches[3] + " "; + } + break; + } + } - /** - * This returns the value of the property named by the parameter - * passed in. - * - * @param propertyName name of the property to be returned, with - * or without the trailing underscore. - * @return the requested property, if found for this unit - * @throws an error if the property is not found for this unit - */ + if (stack.length > 0) { + var firstUserLine = stack[0]; + for (var i = 0; i < traceLines.length; ++i) { + if (traceLines[i] === firstUserLine) { + if (i > 0) { + creatorLine = "\n" + traceLines[i - 1]; + } + break; + } + } - getProperty(propertyName) { - let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_'; - return this[uProp]; - } // end getProperty + } + } + var msg = "a promise was created in a " + name + + "handler " + handlerLine + "but was not returned from it, " + + "see http://goo.gl/rRqMUw" + + creatorLine; + promise._warn(msg, true, promiseCreated); + } +} - /** - * Takes a measurement consisting of a number of units and a unit and returns - * the equivalent number of this unit. So, 15 mL would translate - * to 1 tablespoon if this object is a tablespoon. - * - * Note that the number returned may not be what is normally expected. - * For example, converting 10 Celsius units to Fahrenheit would "normally" - * return a value of 50. But in this case you'll get back something like - * 49.99999999999994. - * - * If either unit is an arbitrary unit an exception is raised. - * - * @param num the magnitude for the unit to be translated (e.g. 15 for 15 mL) - * @param fromUnit the unit to be translated to one of this type (e.g. a mL unit) - * - * @return the number of converted units (e.g. 1 for 1 tablespoon) - * @throws an error if the dimension of the fromUnit differs from this unit's - * dimension - */ +function deprecated(name, replacement) { + var message = name + + " is deprecated and will be removed in a future version."; + if (replacement) message += " Use " + replacement + " instead."; + return warn(message); +} +function warn(message, shouldUseOwnTrace, promise) { + if (!config.warnings) return; + var warning = new Warning(message); + var ctx; + if (shouldUseOwnTrace) { + promise._attachExtraTrace(warning); + } else if (config.longStackTraces && (ctx = Promise._peekContext())) { + ctx.attachExtraTrace(warning); + } else { + var parsed = parseStackAndMessage(warning); + warning.stack = parsed.message + "\n" + parsed.stack.join("\n"); + } - convertFrom(num, fromUnit) { - let newNum = 0.0; - if (this.isArbitrary_) throw new Error(`Attempt to convert arbitrary unit ${this.name_}`); - if (fromUnit.isArbitrary_) throw new Error(`Attempt to convert to arbitrary unit ${fromUnit.name_}`); // reject request if both units have dimensions that are not equal + if (!activeFireEvent("warning", warning)) { + formatAndLogError(warning, "", true); + } +} - if (fromUnit.dim_ && this.dim_ && !fromUnit.dim_.equals(this.dim_)) { - // check first to see if a mole<->mass conversion is appropriate - if (this.isMoleMassCommensurable(fromUnit)) { - throw new Error(Ucum.needMoleWeightMsg_); - } else { - throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); - } - } // reject request if there is a "from" dimension but no "to" dimension +function reconstructStack(message, stacks) { + for (var i = 0; i < stacks.length - 1; ++i) { + stacks[i].push("From previous event:"); + stacks[i] = stacks[i].join("\n"); + } + if (i < stacks.length) { + stacks[i] = stacks[i].join("\n"); + } + return message + "\n" + stacks.join("\n"); +} +function removeDuplicateOrEmptyJumps(stacks) { + for (var i = 0; i < stacks.length; ++i) { + if (stacks[i].length === 0 || + ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) { + stacks.splice(i, 1); + i--; + } + } +} - if (fromUnit.dim_ && (!this.dim_ || this.dim_.isNull())) { - throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); - } // reject request if there is a "to" dimension but no "from" dimension +function removeCommonRoots(stacks) { + var current = stacks[0]; + for (var i = 1; i < stacks.length; ++i) { + var prev = stacks[i]; + var currentLastIndex = current.length - 1; + var currentLastLine = current[currentLastIndex]; + var commonRootMeetPoint = -1; + for (var j = prev.length - 1; j >= 0; --j) { + if (prev[j] === currentLastLine) { + commonRootMeetPoint = j; + break; + } + } - if (this.dim_ && (!fromUnit.dim_ || fromUnit.dim_.isNull())) { - throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); + for (var j = commonRootMeetPoint; j >= 0; --j) { + var line = prev[j]; + if (current[currentLastIndex] === line) { + current.pop(); + currentLastIndex--; + } else { + break; + } + } + current = prev; } +} - let fromCnv = fromUnit.cnv_; - let fromMag = fromUnit.magnitude_; // If the same conversion function is specified for both units, which - // includes neither unit having a conversion function, multiply the - // "from" unit's magnitude by the number passed in and then divide - // that result by this unit's magnitude. Do this for units with - // and without dimension vectors. PROBLEM with 2 non-commensurable - // units with no dimension vector or function, e.g., byte to mol - - if (fromCnv === this.cnv_) { - newNum = num * fromMag / this.magnitude_; - } // else use a function to get the number to be returned - else { - let x = 0.0; - - if (fromCnv != null) { - // turn num * fromUnit.magnitude into its ratio scale equivalent, - // e.g., convert Celsius to Kelvin - let fromFunc = _ucumFunctions.default.forName(fromCnv); +function cleanStack(stack) { + var ret = []; + for (var i = 0; i < stack.length; ++i) { + var line = stack[i]; + var isTraceLine = " (No stack trace)" === line || + stackFramePattern.test(line); + var isInternalFrame = isTraceLine && shouldIgnore(line); + if (isTraceLine && !isInternalFrame) { + if (indentStackFrames && line.charAt(0) !== " ") { + line = " " + line; + } + ret.push(line); + } + } + return ret; +} - x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag; //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_; - } else { - x = num * fromMag; +function stackFramesAsArray(error) { + var stack = error.stack.replace(/\s+$/g, "").split("\n"); + for (var i = 0; i < stack.length; ++i) { + var line = stack[i]; + if (" (No stack trace)" === line || stackFramePattern.test(line)) { + break; } + } + if (i > 0 && error.name != "SyntaxError") { + stack = stack.slice(i); + } + return stack; +} - if (this.cnv_ != null) { - // turn mag * origUnit on ratio scale into a non-ratio unit, - // e.g. convert Kelvin to Fahrenheit - let toFunc = _ucumFunctions.default.forName(this.cnv_); +function parseStackAndMessage(error) { + var stack = error.stack; + var message = error.toString(); + stack = typeof stack === "string" && stack.length > 0 + ? stackFramesAsArray(error) : [" (No stack trace)"]; + return { + message: message, + stack: error.name == "SyntaxError" ? stack : cleanStack(stack) + }; +} - newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_; +function formatAndLogError(error, title, isSoft) { + if (typeof console !== "undefined") { + var message; + if (util.isObject(error)) { + var stack = error.stack; + message = title + formatStack(stack, error); } else { - newNum = x / this.magnitude_; + message = title + String(error); + } + if (typeof printWarning === "function") { + printWarning(message, isSoft); + } else if (typeof console.log === "function" || + typeof console.log === "object") { + console.log(message); } - } // end if either unit has a conversion function + } +} +function fireRejectionEvent(name, localHandler, reason, promise) { + var localEventFired = false; + try { + if (typeof localHandler === "function") { + localEventFired = true; + if (name === "rejectionHandled") { + localHandler(promise); + } else { + localHandler(reason, promise); + } + } + } catch (e) { + async.throwLater(e); + } - return newNum; - } // end convertFrom + if (name === "unhandledRejection") { + if (!activeFireEvent(name, reason, promise) && !localEventFired) { + formatAndLogError(reason, "Unhandled rejection "); + } + } else { + activeFireEvent(name, promise); + } +} - /** - * Takes a number and a target unit and returns the number for a measurement - * of this unit that corresponds to the number of the target unit passed in. - * So, 1 tablespoon (where this unit represents a tablespoon) would translate - * to 15 mL. - * - * See the note on convertFrom about return values. - * - * @param mag the magnitude for this unit (e.g. 1 for 1 tablespoon) - * @param toUnit the unit to which this unit is to be translated - * (e.g. an mL unit) - * - * @return the converted number value (e.g. 15 mL) - * @throws an error if the dimension of the toUnit differs from this unit's - * dimension - */ +function formatNonError(obj) { + var str; + if (typeof obj === "function") { + str = "[function " + + (obj.name || "anonymous") + + "]"; + } else { + str = obj && typeof obj.toString === "function" + ? obj.toString() : util.toString(obj); + var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; + if (ruselessToString.test(str)) { + try { + var newStr = JSON.stringify(obj); + str = newStr; + } + catch(e) { + } + } + if (str.length === 0) { + str = "(empty array)"; + } + } + return ("(<" + snip(str) + ">, no stack trace)"); +} - convertTo(num, toUnit) { - return toUnit.convertFrom(num, this); - } // end convertTo +function snip(str) { + var maxChars = 41; + if (str.length < maxChars) { + return str; + } + return str.substr(0, maxChars - 3) + "..."; +} - /** - * Takes a given number of this unit returns the number of this unit - * if it is converted into a coherent unit. Does not change this unit. - * - * If this is a coherent unit already, just gives back the number - * passed in. - * - * @param num the number for the coherent version of this unit - * @return the number for the coherent version of this unit - */ +function longStackTracesIsSupported() { + return typeof captureStackTrace === "function"; +} +var shouldIgnore = function() { return false; }; +var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/; +function parseLineInfo(line) { + var matches = line.match(parseLineInfoRegex); + if (matches) { + return { + fileName: matches[1], + line: parseInt(matches[2], 10) + }; + } +} - convertCoherent(num) { - // convert mag' * u' into canonical number * u on ratio scale - if (this.cnv_ !== null) num = this.cnv_.f_from(num / this.cnvPfx_) * this.magnitude_; - return num; - } // end convertCoherent +function setBounds(firstLineError, lastLineError) { + if (!longStackTracesIsSupported()) return; + var firstStackLines = firstLineError.stack.split("\n"); + var lastStackLines = lastLineError.stack.split("\n"); + var firstIndex = -1; + var lastIndex = -1; + var firstFileName; + var lastFileName; + for (var i = 0; i < firstStackLines.length; ++i) { + var result = parseLineInfo(firstStackLines[i]); + if (result) { + firstFileName = result.fileName; + firstIndex = result.line; + break; + } + } + for (var i = 0; i < lastStackLines.length; ++i) { + var result = parseLineInfo(lastStackLines[i]); + if (result) { + lastFileName = result.fileName; + lastIndex = result.line; + break; + } + } + if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName || + firstFileName !== lastFileName || firstIndex >= lastIndex) { + return; + } - /** - * Mutates this unit into a coherent unit and converts a given number of - * units to the appropriate value for this unit as a coherent unit - * - * @param num the number for this unit before conversion - * @return the number of this unit after conversion - * @throws an error if the dimensions differ - */ + shouldIgnore = function(line) { + if (bluebirdFramePattern.test(line)) return true; + var info = parseLineInfo(line); + if (info) { + if (info.fileName === firstFileName && + (firstIndex <= info.line && info.line <= lastIndex)) { + return true; + } + } + return false; + }; +} +function CapturedTrace(parent) { + this._parent = parent; + this._promisesCreated = 0; + var length = this._length = 1 + (parent === undefined ? 0 : parent._length); + captureStackTrace(this, CapturedTrace); + if (length > 32) this.uncycle(); +} +util.inherits(CapturedTrace, Error); +Context.CapturedTrace = CapturedTrace; - mutateCoherent(num) { - // convert mu' * u' into canonical mu * u on ratio scale - num = this.convertCoherent(num); // mutate to coherent unit +CapturedTrace.prototype.uncycle = function() { + var length = this._length; + if (length < 2) return; + var nodes = []; + var stackToIndex = {}; - this.magnitude_ = 1; - this.cnv_ = null; - this.cnvPfx_ = 1; - this.name_ = ""; // build a name as a term of coherent base units - // This is probably ALL WRONG and a HORRIBLE MISTAKE - // but until we figure out what the heck the name being - // built here really is, it will have to stay. + for (var i = 0, node = this; node !== undefined; ++i) { + nodes.push(node); + node = node._parent; + } + length = this._length = i; + for (var i = length - 1; i >= 0; --i) { + var stack = nodes[i].stack; + if (stackToIndex[stack] === undefined) { + stackToIndex[stack] = i; + } + } + for (var i = 0; i < length; ++i) { + var currentStack = nodes[i].stack; + var index = stackToIndex[currentStack]; + if (index !== undefined && index !== i) { + if (index > 0) { + nodes[index - 1]._parent = undefined; + nodes[index - 1]._length = 1; + } + nodes[i]._parent = undefined; + nodes[i]._length = 1; + var cycleEdgeNode = i > 0 ? nodes[i - 1] : this; - for (let i = 0, max = Dimension.getMax(); i < max; i++) { - let elem = this.dim_.getElementAt(i); + if (index < length - 1) { + cycleEdgeNode._parent = nodes[index + 1]; + cycleEdgeNode._parent.uncycle(); + cycleEdgeNode._length = + cycleEdgeNode._parent._length + 1; + } else { + cycleEdgeNode._parent = undefined; + cycleEdgeNode._length = 1; + } + var currentChildLength = cycleEdgeNode._length + 1; + for (var j = i - 2; j >= 0; --j) { + nodes[j]._length = currentChildLength; + currentChildLength++; + } + return; + } + } +}; - let tabs = this._getUnitTables(); +CapturedTrace.prototype.attachExtraTrace = function(error) { + if (error.__stackCleaned__) return; + this.uncycle(); + var parsed = parseStackAndMessage(error); + var message = parsed.message; + var stacks = [parsed.stack]; - let uA = tabs.getUnitsByDimension(new Dimension(i)); - if (uA == null) throw new Error(`Can't find base unit for dimension ${i}`); - this.name_ = uA.name + elem; + var trace = this; + while (trace !== undefined) { + stacks.push(cleanStack(trace.stack.split("\n"))); + trace = trace._parent; } + removeCommonRoots(stacks); + removeDuplicateOrEmptyJumps(stacks); + util.notEnumerableProp(error, "stack", reconstructStack(message, stacks)); + util.notEnumerableProp(error, "__stackCleaned__", true); +}; - return num; - } // end mutateCoherent +var captureStackTrace = (function stackDetection() { + var v8stackFramePattern = /^\s*at\s*/; + var v8stackFormatter = function(stack, error) { + if (typeof stack === "string") return stack; - /** - * Calculates the number of units that would result from converting a unit - * expressed in mass/grams to a unit expressed in moles. The "this" unit is - * the unit expressed in some form of mass (g, mg, mmg, kg, whatever) and the - * target or "to" unit - the molUnit parameter - is a unit expressed in moles - * - mol, umol, mmol, etc. The unit expressions surrounding the moles and - * mass must be convertible. No validation of this requirement is performed. - * - * @param amt the quantity of this unit to be converted - * @param molUnit the target/to unit for which the converted # is wanted - * @param molecularWeight the molecular weight of the substance for which the - * conversion is being made - * @return the equivalent amount in molUnit - */ + if (error.name !== undefined && + error.message !== undefined) { + return error.toString(); + } + return formatNonError(error); + }; + if (typeof Error.stackTraceLimit === "number" && + typeof Error.captureStackTrace === "function") { + Error.stackTraceLimit += 6; + stackFramePattern = v8stackFramePattern; + formatStack = v8stackFormatter; + var captureStackTrace = Error.captureStackTrace; - convertMassToMol(amt, molUnit, molecularWeight) { - // The prefix values that have been applied to this unit, which is the mass - // (grams) unit, are reflected in the magnitude. So the number of moles - // represented by this unit equals the number of grams -- amount * magnitude - // divided by the molecular Weight - let molAmt = this.magnitude_ * amt / molecularWeight; // The molUnit's basic magnitude, before prefixes are applied, - // is avogadro's number, get that and divide it out of the current magnitude. + shouldIgnore = function(line) { + return bluebirdFramePattern.test(line); + }; + return function(receiver, ignoreUntil) { + Error.stackTraceLimit += 6; + captureStackTrace(receiver, ignoreUntil); + Error.stackTraceLimit -= 6; + }; + } + var err = new Error(); - let tabs = this._getUnitTables(); + if (typeof err.stack === "string" && + err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) { + stackFramePattern = /@/; + formatStack = v8stackFormatter; + indentStackFrames = true; + return function captureStackTrace(o) { + o.stack = new Error().stack; + }; + } - let avoNum = tabs.getUnitByCode('mol').magnitude_; - let molesFactor = molUnit.magnitude_ / avoNum; // return the molAmt divided by the molesFactor as the number of moles - // for the molUnit + var hasStackAfterThrow; + try { throw new Error(); } + catch(e) { + hasStackAfterThrow = ("stack" in e); + } + if (!("stack" in err) && hasStackAfterThrow && + typeof Error.stackTraceLimit === "number") { + stackFramePattern = v8stackFramePattern; + formatStack = v8stackFormatter; + return function captureStackTrace(o) { + Error.stackTraceLimit += 6; + try { throw new Error(); } + catch(e) { o.stack = e.stack; } + Error.stackTraceLimit -= 6; + }; + } - return molAmt / molesFactor; - } - /** - * Calculates the number of units that would result from converting a unit - * expressed in moles to a unit expressed in mass (grams). The "this" unit - * is the unit expressed in some form of moles, e.g., mol, umol, mmol, etc., - * and the target or "to" unit is a unit expressed in some form of mass, e.g., - * g, mg, mmg, kg, etc. Any unit expressions surrounding the moles and mass - * must be convertible. No validation of this requirement is performed. - * - * @param amt the quantity of this unit to be converted - * @param massUnit the target/to unit for which the converted # is wanted - * @param molecularWeight the molecular weight of the substance for which the - * conversion is being made - * @return the equivalent amount in massUnit - */ + formatStack = function(stack, error) { + if (typeof stack === "string") return stack; + if ((typeof error === "object" || + typeof error === "function") && + error.name !== undefined && + error.message !== undefined) { + return error.toString(); + } + return formatNonError(error); + }; - convertMolToMass(amt, massUnit, molecularWeight) { - // A simple mole unit has a magnitude of avogadro's number. Get that - // number now (since not everyone agrees on what it is, and what is - // being used in this system might change). - let tabs = this._getUnitTables(); + return null; - let avoNum = tabs.getUnitByCode('mol').magnitude_; // Determine what prefix values (mg or mg/dL, etc.) have been applied to - // this unit by dividing the simple mole unit magnitude out of the - // current mole unit magnitude. +})([]); - let molesFactor = this.magnitude_ / avoNum; // The number of grams (mass) is equal to the number of moles (amt) - // times the molecular weight. We also multiply that by the prefix values - // applied to the current unit (molesFactor) to get the grams for this - // particular unit. +if (typeof console !== "undefined" && typeof console.warn !== "undefined") { + printWarning = function (message) { + console.warn(message); + }; + if (util.isNode && process.stderr.isTTY) { + printWarning = function(message, isSoft) { + var color = isSoft ? "\u001b[33m" : "\u001b[31m"; + console.warn(color + message + "\u001b[0m\n"); + }; + } else if (!util.isNode && typeof (new Error().stack) === "string") { + printWarning = function(message, isSoft) { + console.warn("%c" + message, + isSoft ? "color: darkorange" : "color: red"); + }; + } +} - let massAmt = molesFactor * amt * molecularWeight; // Finally, we return the mass amount/grams for this particular unit - // divided by any effects of prefixes applied to the "to" unit, which - // is assumed to be some form of a gram unit +var config = { + warnings: warnings, + longStackTraces: false, + cancellation: false, + monitoring: false +}; - return massAmt / massUnit.magnitude_; - } - /** - * Mutates this unit into a unit on a ratio scale and converts a specified - * number of units to an appropriate value for this converted unit - * - * @param num the number of this unit before it's converted - * @return the magnitude of this unit after it's converted - * @throw an error if the dimensions differ - */ +if (longStackTraces) Promise.longStackTraces(); +return { + longStackTraces: function() { + return config.longStackTraces; + }, + warnings: function() { + return config.warnings; + }, + cancellation: function() { + return config.cancellation; + }, + monitoring: function() { + return config.monitoring; + }, + propagateFromFunction: function() { + return propagateFromFunction; + }, + boundValueFunction: function() { + return boundValueFunction; + }, + checkForgottenReturns: checkForgottenReturns, + setBounds: setBounds, + warn: warn, + deprecated: deprecated, + CapturedTrace: CapturedTrace, + fireDomEvent: fireDomEvent, + fireGlobalEvent: fireGlobalEvent +}; +}; - mutateRatio(num) { - if (this.cnv_ == null) return this.mutateCoherent(num);else return num; - } // end mutateRatio +},{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise) { +function returner() { + return this.value; +} +function thrower() { + throw this.reason; +} - /** - * Multiplies this unit with a scalar. Special meaning for - * special units so that (0.1*B) is 1 dB. - * - * This function DOES NOT modify this unit. - * - * @param s the value by which this unit is to be multiplied - * @return a copy this unit multiplied by s - * */ +Promise.prototype["return"] = +Promise.prototype.thenReturn = function (value) { + if (value instanceof Promise) value.suppressUnhandledRejections(); + return this._then( + returner, undefined, undefined, {value: value}, undefined); +}; +Promise.prototype["throw"] = +Promise.prototype.thenThrow = function (reason) { + return this._then( + thrower, undefined, undefined, {reason: reason}, undefined); +}; - multiplyThis(s) { - let retUnit = this.clone(); - if (retUnit.cnv_ != null) retUnit.cnvPfx_ *= s;else retUnit.magnitude_ *= s; - let mulVal = s.toString(); - retUnit.name_ = this._concatStrs(mulVal, '*', this.name_, '[', ']'); - retUnit.csCode_ = this._concatStrs(mulVal, '.', this.csCode_, '(', ')'); - retUnit.ciCode_ = this._concatStrs(mulVal, '.', this.ciCode_, '(', ')'); - retUnit.printSymbol_ = this._concatStrs(mulVal, '.', this.printSymbol_, '(', ')'); - return retUnit; - } // end multiplyThis +Promise.prototype.catchThrow = function (reason) { + if (arguments.length <= 1) { + return this._then( + undefined, thrower, undefined, {reason: reason}, undefined); + } else { + var _reason = arguments[1]; + var handler = function() {throw _reason;}; + return this.caught(reason, handler); + } +}; - /** - * Multiplies this unit with another unit. If one of the - * units is a non-ratio unit the other must be dimensionless or - * else an exception is thrown. - * - * This function does NOT modify this unit - * @param unit2 the unit to be multiplied with this one - * @return this unit after it is multiplied - * @throws an error if one of the units is not on a ratio-scale - * and the other is not dimensionless. - */ +Promise.prototype.catchReturn = function (value) { + if (arguments.length <= 1) { + if (value instanceof Promise) value.suppressUnhandledRejections(); + return this._then( + undefined, returner, undefined, {value: value}, undefined); + } else { + var _value = arguments[1]; + if (_value instanceof Promise) _value.suppressUnhandledRejections(); + var handler = function() {return _value;}; + return this.caught(value, handler); + } +}; +}; +},{}],11:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL) { +var PromiseReduce = Promise.reduce; +var PromiseAll = Promise.all; - multiplyThese(unit2) { - var retUnit = this.clone(); +function promiseAllThis() { + return PromiseAll(this); +} - if (retUnit.cnv_ != null) { - if (unit2.cnv_ == null && (!unit2.dim_ || unit2.dim_.isZero())) retUnit.cnvPfx_ *= unit2.magnitude_;else throw new Error(`Attempt to multiply non-ratio unit ${retUnit.name_} ` + 'failed.'); - } // end if this unit has a conversion function - else if (unit2.cnv_ != null) { - if (!retUnit.dim_ || retUnit.dim_.isZero()) { - retUnit.cnvPfx_ = unit2.cnvPfx_ * retUnit.magnitude_; - retUnit.cnv_ = unit2.cnv_; - } else throw new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`); - } // end if unit2 has a conversion function - // else neither unit has a conversion function - else { - retUnit.magnitude_ *= unit2.magnitude_; - } // end if unit2 does not have a conversion function - // If this.dim_ isn't there, clone the dimension in unit2 - if dimVec_ - // is a dimension in unit2.dim_; else just transfer it to this dimension +function PromiseMapSeries(promises, fn) { + return PromiseReduce(promises, fn, INTERNAL, INTERNAL); +} +Promise.prototype.each = function (fn) { + return PromiseReduce(this, fn, INTERNAL, 0) + ._then(promiseAllThis, undefined, undefined, this, undefined); +}; - if (!retUnit.dim_ || retUnit.dim_ && !retUnit.dim_.dimVec_) { - if (unit2.dim_) retUnit.dim_ = unit2.dim_.clone();else retUnit.dim_ = unit2.dim_; - } // Else this.dim_ is there. If there is a dimension for unit2, - // add it to this one. - else if (unit2.dim_ && unit2.dim_ instanceof Dimension) { - retUnit.dim_.add(unit2.dim_); - } // Concatenate the unit info (name, code, etc) for all cases - // where the multiplication was performed (an error wasn't thrown) - - - retUnit.name_ = this._concatStrs(retUnit.name_, '*', unit2.name_, '[', ']'); - retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '.', unit2.csCode_, '(', ')'); - if (retUnit.ciCode_ && unit2.ciCode_) retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '.', unit2.ciCode_, '(', ')');else if (unit2.ciCode_) retUnit.ciCode_ = unit2.ciCode_; - retUnit.resetFieldsForDerivedUnit(); - if (retUnit.printSymbol_ && unit2.printSymbol_) retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.', unit2.printSymbol_, '(', ')');else if (unit2.printSymbol_) retUnit.printSymbol_ = unit2.printSymbol_; // Update the mole exponent count by adding the count for unit2 to the - // count for this unit. +Promise.prototype.mapSeries = function (fn) { + return PromiseReduce(this, fn, INTERNAL, INTERNAL); +}; - retUnit.moleExp_ = retUnit.moleExp_ + unit2.moleExp_; // A unit that has the arbitrary attribute taints any unit created from it - // via an arithmetic operation. Taint accordingly - // if (!retUnit.isMole_) - // retUnit.isMole_ = unit2.isMole_ ; +Promise.each = function (promises, fn) { + return PromiseReduce(promises, fn, INTERNAL, 0) + ._then(promiseAllThis, undefined, undefined, promises, undefined); +}; - if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_; - return retUnit; - } // end multiplyThese +Promise.mapSeries = PromiseMapSeries; +}; - /** - * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned - * from a known unit but it being used to construct a derived unit. - */ +},{}],12:[function(_dereq_,module,exports){ +"use strict"; +var es5 = _dereq_("./es5"); +var Objectfreeze = es5.freeze; +var util = _dereq_("./util"); +var inherits = util.inherits; +var notEnumerableProp = util.notEnumerableProp; - resetFieldsForDerivedUnit() { - this.guidance_ = ''; - this.synonyms_ = null; - this.isBase_ = false; - } - /** - * Divides this unit by another unit. If this unit is not on a ratio - * scale an exception is raised. Mutating to a ratio scale unit - * is not possible for a unit, only for a measurement. - * - * This unit is NOT modified by this function. - * @param unit2 the unit by which to divide this one - * @return this unit after it is divided by unit2 - * @throws an error if either of the units is not on a ratio scale. - * */ +function subError(nameProperty, defaultMessage) { + function SubError(message) { + if (!(this instanceof SubError)) return new SubError(message); + notEnumerableProp(this, "message", + typeof message === "string" ? message : defaultMessage); + notEnumerableProp(this, "name", nameProperty); + if (Error.captureStackTrace) { + Error.captureStackTrace(this, this.constructor); + } else { + Error.call(this); + } + } + inherits(SubError, Error); + return SubError; +} +var _TypeError, _RangeError; +var Warning = subError("Warning", "warning"); +var CancellationError = subError("CancellationError", "cancellation error"); +var TimeoutError = subError("TimeoutError", "timeout error"); +var AggregateError = subError("AggregateError", "aggregate error"); +try { + _TypeError = TypeError; + _RangeError = RangeError; +} catch(e) { + _TypeError = subError("TypeError", "type error"); + _RangeError = subError("RangeError", "range error"); +} - divide(unit2) { - var retUnit = this.clone(); - if (retUnit.cnv_ != null) throw new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`); - if (unit2.cnv_ != null) throw new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`); - if (retUnit.name_ && unit2.name_) retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');else if (unit2.name_) retUnit.name_ = unit2.invertString(unit2.name_); - retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_, '(', ')'); - if (retUnit.ciCode_ && unit2.ciCode_) retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_, '(', ')');else if (unit2.ciCode_) retUnit.ciCode_ = unit2.invertString(unit2.ciCode_); - retUnit.resetFieldsForDerivedUnit(); - retUnit.magnitude_ /= unit2.magnitude_; - if (retUnit.printSymbol_ && unit2.printSymbol_) retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/', unit2.printSymbol_, '(', ')');else if (unit2.printSymbol_) retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_); // Continue if unit2 has a dimension object. - // If this object has a dimension object, subtract unit2's dim_ object from - // this one. The sub method will take care of cases where the dimVec_ arrays - // are missing on one or both dim_ objects. +var methods = ("join pop push shift unshift slice filter forEach some " + + "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); - if (unit2.dim_) { - if (retUnit.dim_) { - if (retUnit.dim_.isNull()) retUnit.dim_.assignZero(); - retUnit.dim_ = retUnit.dim_.sub(unit2.dim_); - } // end if this.dim_ exists - // Else if this dim_ object is missing, clone unit2's dim_ object - // and give the inverted clone to this unit. - else retUnit.dim_ = unit2.dim_.clone().minus(); - } // end if unit2 has a dimension object - // Update the mole exponent count by subtracting the count for unit2 from - // the // count for this unit. +for (var i = 0; i < methods.length; ++i) { + if (typeof Array.prototype[methods[i]] === "function") { + AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; + } +} +es5.defineProperty(AggregateError.prototype, "length", { + value: 0, + configurable: false, + writable: true, + enumerable: true +}); +AggregateError.prototype["isOperational"] = true; +var level = 0; +AggregateError.prototype.toString = function() { + var indent = Array(level * 4 + 1).join(" "); + var ret = "\n" + indent + "AggregateError of:" + "\n"; + level++; + indent = Array(level * 4 + 1).join(" "); + for (var i = 0; i < this.length; ++i) { + var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; + var lines = str.split("\n"); + for (var j = 0; j < lines.length; ++j) { + lines[j] = indent + lines[j]; + } + str = lines.join("\n"); + ret += str + "\n"; + } + level--; + return ret; +}; - retUnit.moleExp_ = retUnit.moleExp_ - unit2.moleExp_; // A unit that has the arbitrary attribute taints any unit created from - // it via an arithmetic operation. Taint accordingly - // if (!retUnit.isMole_) - // retUnit.isMole_ = unit2.isMole_ ; +function OperationalError(message) { + if (!(this instanceof OperationalError)) + return new OperationalError(message); + notEnumerableProp(this, "name", "OperationalError"); + notEnumerableProp(this, "message", message); + this.cause = message; + this["isOperational"] = true; - if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_; - return retUnit; - } // end divide + if (message instanceof Error) { + notEnumerableProp(this, "message", message.message); + notEnumerableProp(this, "stack", message.stack); + } else if (Error.captureStackTrace) { + Error.captureStackTrace(this, this.constructor); + } - /** - * Invert this unit with respect to multiplication. If this unit is not - * on a ratio scale an exception is thrown. Mutating to a ratio scale unit - * is not possible for a unit, only for a measurement (the magnitude and - * dimension). - * - * This unit is modified by this function. - * @return this unit after being inverted - * @throws and error if this unit is not on a ratio scale - */ +} +inherits(OperationalError, Error); +var errorTypes = Error["__BluebirdErrorTypes__"]; +if (!errorTypes) { + errorTypes = Objectfreeze({ + CancellationError: CancellationError, + TimeoutError: TimeoutError, + OperationalError: OperationalError, + RejectionError: OperationalError, + AggregateError: AggregateError + }); + es5.defineProperty(Error, "__BluebirdErrorTypes__", { + value: errorTypes, + writable: false, + enumerable: false, + configurable: false + }); +} - invert() { - if (this.cnv_ != null) throw new Error(`Attempt to invert a non-ratio unit - ${this.name_}`); - this.name_ = this.invertString(this.name_); - this.magnitude_ = 1 / this.magnitude_; - this.dim_.minus(); - return this; - } // end invert +module.exports = { + Error: Error, + TypeError: _TypeError, + RangeError: _RangeError, + CancellationError: errorTypes.CancellationError, + OperationalError: errorTypes.OperationalError, + TimeoutError: errorTypes.TimeoutError, + AggregateError: errorTypes.AggregateError, + Warning: Warning +}; - /** - * Inverts a string, where the string is assumed to be a code or a name - * of a division operation where the string is the divisor and the dividend - * is blank. - * - * @param the string to be inverted - * @return the inverted string - */ +},{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){ +var isES5 = (function(){ + "use strict"; + return this === undefined; +})(); +if (isES5) { + module.exports = { + freeze: Object.freeze, + defineProperty: Object.defineProperty, + getDescriptor: Object.getOwnPropertyDescriptor, + keys: Object.keys, + names: Object.getOwnPropertyNames, + getPrototypeOf: Object.getPrototypeOf, + isArray: Array.isArray, + isES5: isES5, + propertyIsWritable: function(obj, prop) { + var descriptor = Object.getOwnPropertyDescriptor(obj, prop); + return !!(!descriptor || descriptor.writable || descriptor.set); + } + }; +} else { + var has = {}.hasOwnProperty; + var str = {}.toString; + var proto = {}.constructor.prototype; - invertString(theString) { - if (theString.length > 0) { - let stringRep = theString.replace('/', "!").replace('.', '/').replace("!", '.'); + var ObjectKeys = function (o) { + var ret = []; + for (var key in o) { + if (has.call(o, key)) { + ret.push(key); + } + } + return ret; + }; - switch (stringRep.charAt(0)) { - case '.': - theString = stringRep.substr(1); - break; + var ObjectGetDescriptor = function(o, key) { + return {value: o[key]}; + }; - case '/': - theString = stringRep; - break; + var ObjectDefineProperty = function (o, key, desc) { + o[key] = desc.value; + return o; + }; - default: - theString = "/" + stringRep; - } - } + var ObjectFreeze = function (obj) { + return obj; + }; - return theString; - } // end invertString + var ObjectGetPrototypeOf = function (obj) { + try { + return Object(obj).constructor.prototype; + } + catch (e) { + return proto; + } + }; - /** - * This function handles concatenation of two strings and an operator. - * It's called to build unit data, e.g., unit name, unit code, etc., from - * two different units, joined by the specified operator. - * - * @param str1 the first string to appear in the result - * @param operator the operator ('*', '.' or '/') to appear between the strings - * @param str2 the second string to appear in the result - * @param startChar the starting character to be used, when needed, to - * enclose a string - * @param endChar the ending character to be used, when needed, to enclose - * a string - * @returns the built string - */ + var ArrayIsArray = function (obj) { + try { + return str.call(obj) === "[object Array]"; + } + catch(e) { + return false; + } + }; + module.exports = { + isArray: ArrayIsArray, + keys: ObjectKeys, + names: ObjectKeys, + defineProperty: ObjectDefineProperty, + getDescriptor: ObjectGetDescriptor, + freeze: ObjectFreeze, + getPrototypeOf: ObjectGetPrototypeOf, + isES5: isES5, + propertyIsWritable: function() { + return true; + } + }; +} - _concatStrs(str1, operator, str2, startChar, endChar) { - return this._buildOneString(str1, startChar, endChar) + operator + this._buildOneString(str2, startChar, endChar); - } - /** - * This function handles creation of one string to be included in a - * concatenated string. Basically it checks to see if the string - * needs to be enclosed either in parentheses or square brackets. - * - * The string is enclosed if it is not a number, is not already enclosed in a pair of - * parentheses or square brackets, and includes a period, and asterisk, - * a slash or a blank space. - * - * @param str the string - * @param startChar starting enclosing character - * @param endChar ending enclosing character - * @returns the string - */ +},{}],14:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL) { +var PromiseMap = Promise.map; +Promise.prototype.filter = function (fn, options) { + return PromiseMap(this, fn, options, INTERNAL); +}; - _buildOneString(str, startChar, endChar) { - let ret = ''; +Promise.filter = function (promises, fn, options) { + return PromiseMap(promises, fn, options, INTERNAL); +}; +}; - if (intUtils_.isNumericString(str)) { - ret = str; - } else { - if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) { - ret = str; - } else if (/[./* ]/.test(str)) { - ret = startChar + str + endChar; - } else { - ret = str; - } - } +},{}],15:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) { +var util = _dereq_("./util"); +var CancellationError = Promise.CancellationError; +var errorObj = util.errorObj; +var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); - return ret; - } - /** - * Raises the unit to a power. For example - * kg.m/s2 raised to the -2 power would be kg-2.m-2/s-4 - * - * If this unit is not on a ratio scale an error is thrown. Mutating - * to a ratio scale unit is not possible for a unit, only for a - * measurement (magnitude and dimension). - * - * This is based on the pow method in Gunter Schadow's java version, - * although it uses javascript capabilities to simplify the processing. - * - * This unit is modified by this function - * - * @param p the power to with this unit is to be raise - * @return this unit after it is raised - * @throws an error if this unit is not on a ratio scale. - */ +function PassThroughHandlerContext(promise, type, handler) { + this.promise = promise; + this.type = type; + this.handler = handler; + this.called = false; + this.cancelPromise = null; +} +PassThroughHandlerContext.prototype.isFinallyHandler = function() { + return this.type === 0; +}; - power(p) { - if (this.cnv_ != null) throw new Error(`Attempt to raise a non-ratio unit, ${this.name_}, ` + 'to a power.'); //this.name_ = UnitString.pow(this.name_, p); - // the above line is replaced with the code below, as the pow method - // never actually existing in the UnitString class. (Tried to use - // Schadow java code but this way ended up being a lot easier). +function FinallyHandlerCancelReaction(finallyHandler) { + this.finallyHandler = finallyHandler; +} - let uStr = this.csCode_; - let uArray = uStr.match(/([./]|[^./]+)/g); - let arLen = uArray.length; +FinallyHandlerCancelReaction.prototype._resultCancelled = function() { + checkCancel(this.finallyHandler); +}; - for (let i = 0; i < arLen; i++) { - let un = uArray[i]; +function checkCancel(ctx, reason) { + if (ctx.cancelPromise != null) { + if (arguments.length > 1) { + ctx.cancelPromise._reject(reason); + } else { + ctx.cancelPromise._cancel(); + } + ctx.cancelPromise = null; + return true; + } + return false; +} - if (un !== '/' && un !== '.') { - let nun = parseInt(un); - if (isInteger(nun)) uArray[i] = Math.pow(nun, p).toString();else { - let uLen = un.length; +function succeed() { + return finallyHandler.call(this, this.promise._target()._settledValue()); +} +function fail(reason) { + if (checkCancel(this, reason)) return; + errorObj.e = reason; + return errorObj; +} +function finallyHandler(reasonOrValue) { + var promise = this.promise; + var handler = this.handler; - for (let u = uLen - 1; u >= 0; u--) { - let uChar = parseInt(un[u]); + if (!this.called) { + this.called = true; + var ret = this.isFinallyHandler() + ? handler.call(promise._boundValue()) + : handler.call(promise._boundValue(), reasonOrValue); + if (ret === NEXT_FILTER) { + return ret; + } else if (ret !== undefined) { + promise._setReturnedNonUndefined(); + var maybePromise = tryConvertToPromise(ret, promise); + if (maybePromise instanceof Promise) { + if (this.cancelPromise != null) { + if (maybePromise._isCancelled()) { + var reason = + new CancellationError("late cancellation observer"); + promise._attachExtraTrace(reason); + errorObj.e = reason; + return errorObj; + } else if (maybePromise.isPending()) { + maybePromise._attachCancellationCallback( + new FinallyHandlerCancelReaction(this)); + } + } + return maybePromise._then( + succeed, fail, undefined, this, undefined); + } + } + } - if (!isInteger(uChar)) { - if (un[u] === '-' || un[u] === '+') { - u--; - } + if (promise.isRejected()) { + checkCancel(this); + errorObj.e = reasonOrValue; + return errorObj; + } else { + checkCancel(this); + return reasonOrValue; + } +} - if (u < uLen - 1) { - let exp = parseInt(un.substr(u)); - exp = Math.pow(exp, p); - uArray[i] = un.substr(0, u) + exp.toString(); - u = -1; - } else { - uArray[i] += p.toString(); - u = -1; - } // end if there are/aren't some numbers at the end +Promise.prototype._passThrough = function(handler, type, success, fail) { + if (typeof handler !== "function") return this.then(); + return this._then(success, + fail, + undefined, + new PassThroughHandlerContext(this, type, handler), + undefined); +}; +Promise.prototype.lastly = +Promise.prototype["finally"] = function (handler) { + return this._passThrough(handler, + 0, + finallyHandler, + finallyHandler); +}; - u = -1; - } // end if this character is not a number - } // end searching backwards for start of exponent +Promise.prototype.tap = function (handler) { + return this._passThrough(handler, 1, finallyHandler); +}; - } // end if this element is not a number - } // end if the current element is not an operator +Promise.prototype.tapCatch = function (handlerOrPredicate) { + var len = arguments.length; + if(len === 1) { + return this._passThrough(handlerOrPredicate, + 1, + undefined, + finallyHandler); + } else { + var catchInstances = new Array(len - 1), + j = 0, i; + for (i = 0; i < len - 1; ++i) { + var item = arguments[i]; + if (util.isObject(item)) { + catchInstances[j++] = item; + } else { + return Promise.reject(new TypeError( + "tapCatch statement predicate: " + + "expecting an object but got " + util.classString(item) + )); + } + } + catchInstances.length = j; + var handler = arguments[i]; + return this._passThrough(catchFilter(catchInstances, handler, this), + 1, + undefined, + finallyHandler); + } - } // end do for each element of the units array - // reassemble the updated units array to a string +}; +return PassThroughHandlerContext; +}; - this.csCode_ = uArray.join(''); - this.magnitude_ = Math.pow(this.magnitude_, p); +},{"./catch_filter":7,"./util":36}],16:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, + apiRejection, + INTERNAL, + tryConvertToPromise, + Proxyable, + debug) { +var errors = _dereq_("./errors"); +var TypeError = errors.TypeError; +var util = _dereq_("./util"); +var errorObj = util.errorObj; +var tryCatch = util.tryCatch; +var yieldHandlers = []; - if (this.dim_) { - this.dim_.mul(p); +function promiseFromYieldHandler(value, yieldHandlers, traceParent) { + for (var i = 0; i < yieldHandlers.length; ++i) { + traceParent._pushContext(); + var result = tryCatch(yieldHandlers[i])(value); + traceParent._popContext(); + if (result === errorObj) { + traceParent._pushContext(); + var ret = Promise.reject(errorObj.e); + traceParent._popContext(); + return ret; + } + var maybePromise = tryConvertToPromise(result, traceParent); + if (maybePromise instanceof Promise) return maybePromise; } + return null; +} - return this; - } // end power - - /* - * This function tests this unit against the unit passed in to see if the - * two are mole to mass commensurable. It assumes that one of the units - * is a mole-based unit and the other is a mass-based unit. It also assumes - * that the mole-based unit has a single mole unit in the numerator and that - * the mass-based unit has a single mass unit in the numerator. It does NOT - * check to validate those assumptions. - * - * The check is made by setting the dimension vector element corresponding - * to the base mass unit (gram) in the mole unit, and then comparing the - * two dimension vectors. If they match, the units are commensurable. - * Otherwise they are not. - * - * @param unit2 the unit to be compared to this one - * @returns boolean indicating commensurability - */ +function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) { + if (debug.cancellation()) { + var internal = new Promise(INTERNAL); + var _finallyPromise = this._finallyPromise = new Promise(INTERNAL); + this._promise = internal.lastly(function() { + return _finallyPromise; + }); + internal._captureStackTrace(); + internal._setOnCancel(this); + } else { + var promise = this._promise = new Promise(INTERNAL); + promise._captureStackTrace(); + } + this._stack = stack; + this._generatorFunction = generatorFunction; + this._receiver = receiver; + this._generator = undefined; + this._yieldHandlers = typeof yieldHandler === "function" + ? [yieldHandler].concat(yieldHandlers) + : yieldHandlers; + this._yieldedPromise = null; + this._cancellationPhase = false; +} +util.inherits(PromiseSpawn, Proxyable); +PromiseSpawn.prototype._isResolved = function() { + return this._promise === null; +}; - isMoleMassCommensurable(unit2) { - let tabs = this._getUnitTables(); +PromiseSpawn.prototype._cleanup = function() { + this._promise = this._generator = null; + if (debug.cancellation() && this._finallyPromise !== null) { + this._finallyPromise._fulfill(); + this._finallyPromise = null; + } +}; - let d = tabs.getMassDimensionIndex(); - let commensurable = false; +PromiseSpawn.prototype._promiseCancelled = function() { + if (this._isResolved()) return; + var implementsReturn = typeof this._generator["return"] !== "undefined"; - if (this.moleExp_ === 1 && unit2.moleExp_ === 0) { - let testDim = this.dim_.clone(); - let curVal = testDim.getElementAt(d); - testDim.setElementAt(d, curVal + this.moleExp_); - commensurable = testDim.equals(unit2.dim_); - } else if (unit2.moleExp_ === 1 && this.moleExp_ === 0) { - let testDim = unit2.dim_.clone(); - let curVal = testDim.getElementAt(d); - testDim.setElementAt(d, curVal + unit2.moleExp_); - commensurable = testDim.equals(this.dim_); + var result; + if (!implementsReturn) { + var reason = new Promise.CancellationError( + "generator .return() sentinel"); + Promise.coroutine.returnSentinel = reason; + this._promise._attachExtraTrace(reason); + this._promise._pushContext(); + result = tryCatch(this._generator["throw"]).call(this._generator, + reason); + this._promise._popContext(); + } else { + this._promise._pushContext(); + result = tryCatch(this._generator["return"]).call(this._generator, + undefined); + this._promise._popContext(); } + this._cancellationPhase = true; + this._yieldedPromise = null; + this._continue(result); +}; - return commensurable; - } - /** - * This returns the UnitTables singleton object. Including the require - * statement included here causes a circular dependency condition that - * resulted in the UnitTables object not being defined for the Unit object. - * sigh. Thanks, Paul, for figuring this out. - * - * @private - */ - +PromiseSpawn.prototype._promiseFulfilled = function(value) { + this._yieldedPromise = null; + this._promise._pushContext(); + var result = tryCatch(this._generator.next).call(this._generator, value); + this._promise._popContext(); + this._continue(result); +}; - _getUnitTables() { - if (!UnitTables) UnitTables = require('./unitTables.js').UnitTables; - return UnitTables.getInstance(); - } +PromiseSpawn.prototype._promiseRejected = function(reason) { + this._yieldedPromise = null; + this._promise._attachExtraTrace(reason); + this._promise._pushContext(); + var result = tryCatch(this._generator["throw"]) + .call(this._generator, reason); + this._promise._popContext(); + this._continue(result); +}; -} // end Unit class +PromiseSpawn.prototype._resultCancelled = function() { + if (this._yieldedPromise instanceof Promise) { + var promise = this._yieldedPromise; + this._yieldedPromise = null; + promise.cancel(); + } +}; +PromiseSpawn.prototype.promise = function () { + return this._promise; +}; -exports.Unit = Unit; +PromiseSpawn.prototype._run = function () { + this._generator = this._generatorFunction.call(this._receiver); + this._receiver = + this._generatorFunction = undefined; + this._promiseFulfilled(undefined); +}; +PromiseSpawn.prototype._continue = function (result) { + var promise = this._promise; + if (result === errorObj) { + this._cleanup(); + if (this._cancellationPhase) { + return promise.cancel(); + } else { + return promise._rejectCallback(result.e, false); + } + } -},{"./config.js":9,"./dimension.js":10,"./ucumFunctions.js":14,"./ucumInternalUtils.js":15,"./unitTables.js":21,"is-integer":221}],20:[function(require,module,exports){ -"use strict"; + var value = result.value; + if (result.done === true) { + this._cleanup(); + if (this._cancellationPhase) { + return promise.cancel(); + } else { + return promise._resolveCallback(value); + } + } else { + var maybePromise = tryConvertToPromise(value, this._promise); + if (!(maybePromise instanceof Promise)) { + maybePromise = + promiseFromYieldHandler(maybePromise, + this._yieldHandlers, + this._promise); + if (maybePromise === null) { + this._promiseRejected( + new TypeError( + "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", String(value)) + + "From coroutine:\u000a" + + this._stack.split("\n").slice(1, -7).join("\n") + ) + ); + return; + } + } + maybePromise = maybePromise._target(); + var bitField = maybePromise._bitField; + ; + if (((bitField & 50397184) === 0)) { + this._yieldedPromise = maybePromise; + maybePromise._proxy(this, null); + } else if (((bitField & 33554432) !== 0)) { + Promise._async.invoke( + this._promiseFulfilled, this, maybePromise._value() + ); + } else if (((bitField & 16777216) !== 0)) { + Promise._async.invoke( + this._promiseRejected, this, maybePromise._reason() + ); + } else { + this._promiseCancelled(); + } + } +}; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UnitString = void 0; +Promise.coroutine = function (generatorFunction, options) { + if (typeof generatorFunction !== "function") { + throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + var yieldHandler = Object(options).yieldHandler; + var PromiseSpawn$ = PromiseSpawn; + var stack = new Error().stack; + return function () { + var generator = generatorFunction.apply(this, arguments); + var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler, + stack); + var ret = spawn.promise(); + spawn._generator = generator; + spawn._promiseFulfilled(undefined); + return ret; + }; +}; -var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); +Promise.coroutine.addYieldHandler = function(fn) { + if (typeof fn !== "function") { + throw new TypeError("expecting a function but got " + util.classString(fn)); + } + yieldHandlers.push(fn); +}; -function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } +Promise.spawn = function (generatorFunction) { + debug.deprecated("Promise.spawn()", "Promise.coroutine()"); + if (typeof generatorFunction !== "function") { + return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + var spawn = new PromiseSpawn(generatorFunction, this); + var ret = spawn.promise(); + spawn._run(Promise.spawn); + return ret; +}; +}; -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +},{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){ +"use strict"; +module.exports = +function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, + getDomain) { +var util = _dereq_("./util"); +var canEvaluate = util.canEvaluate; +var tryCatch = util.tryCatch; +var errorObj = util.errorObj; +var reject; -/** - * This class handles the parsing of a unit string into a unit object - */ -var Ucum = require('./config.js').Ucum; +if (!true) { +if (canEvaluate) { + var thenCallback = function(i) { + return new Function("value", "holder", " \n\ + 'use strict'; \n\ + holder.pIndex = value; \n\ + holder.checkFulfillment(this); \n\ + ".replace(/Index/g, i)); + }; -var Unit = require('./unit.js').Unit; + var promiseSetter = function(i) { + return new Function("promise", "holder", " \n\ + 'use strict'; \n\ + holder.pIndex = promise; \n\ + ".replace(/Index/g, i)); + }; -var UnitTables = require('./unitTables.js').UnitTables; + var generateHolderClass = function(total) { + var props = new Array(total); + for (var i = 0; i < props.length; ++i) { + props[i] = "this.p" + (i+1); + } + var assignment = props.join(" = ") + " = null;"; + var cancellationCode= "var promise;\n" + props.map(function(prop) { + return " \n\ + promise = " + prop + "; \n\ + if (promise instanceof Promise) { \n\ + promise.cancel(); \n\ + } \n\ + "; + }).join("\n"); + var passedArguments = props.join(", "); + var name = "Holder$" + total; -var PrefixTables = require('./prefixTables.js').PrefixTables; -class UnitString { - /** - * Constructor - */ - constructor() { - // Get instances of the unit and prefix tables and the utilities - this.utabs_ = UnitTables.getInstance(); - this.pfxTabs_ = PrefixTables.getInstance(); // Set emphasis characters to defaults. These are used to emphasize - // certain characters or strings in user messages. They can be reset in - // the useHTMLInMessages method. + var code = "return function(tryCatch, errorObj, Promise, async) { \n\ + 'use strict'; \n\ + function [TheName](fn) { \n\ + [TheProperties] \n\ + this.fn = fn; \n\ + this.asyncNeeded = true; \n\ + this.now = 0; \n\ + } \n\ + \n\ + [TheName].prototype._callFunction = function(promise) { \n\ + promise._pushContext(); \n\ + var ret = tryCatch(this.fn)([ThePassedArguments]); \n\ + promise._popContext(); \n\ + if (ret === errorObj) { \n\ + promise._rejectCallback(ret.e, false); \n\ + } else { \n\ + promise._resolveCallback(ret); \n\ + } \n\ + }; \n\ + \n\ + [TheName].prototype.checkFulfillment = function(promise) { \n\ + var now = ++this.now; \n\ + if (now === [TheTotal]) { \n\ + if (this.asyncNeeded) { \n\ + async.invoke(this._callFunction, this, promise); \n\ + } else { \n\ + this._callFunction(promise); \n\ + } \n\ + \n\ + } \n\ + }; \n\ + \n\ + [TheName].prototype._resultCancelled = function() { \n\ + [CancellationCode] \n\ + }; \n\ + \n\ + return [TheName]; \n\ + }(tryCatch, errorObj, Promise, async); \n\ + "; - this.openEmph_ = Ucum.openEmph_; - this.closeEmph_ = Ucum.closeEmph_; // Set the braces message to blank. This message is displayed for each - // validation request on the web page, but is included separately as - // a note on the validation spreadsheet. The useBraceMsgForEachString - // method should be used to set the message to be displayed for each - // unit string. + code = code.replace(/\[TheName\]/g, name) + .replace(/\[TheTotal\]/g, total) + .replace(/\[ThePassedArguments\]/g, passedArguments) + .replace(/\[TheProperties\]/g, assignment) + .replace(/\[CancellationCode\]/g, cancellationCode); - this.bracesMsg_ = ''; // Set the flags used, with indices, as place holders in unit strings - // for parenthetical strings and strings within braces. + return new Function("tryCatch", "errorObj", "Promise", "async", code) + (tryCatch, errorObj, Promise, async); + }; - this.parensFlag_ = "parens_placeholder"; // in lieu of Jehoshaphat + var holderClasses = []; + var thenCallbacks = []; + var promiseSetters = []; - this.pFlagLen_ = this.parensFlag_.length; - this.braceFlag_ = "braces_placeholder"; // in lieu of Nebuchadnezzar + for (var i = 0; i < 8; ++i) { + holderClasses.push(generateHolderClass(i + 1)); + thenCallbacks.push(thenCallback(i + 1)); + promiseSetters.push(promiseSetter(i + 1)); + } - this.bFlagLen_ = this.braceFlag_.length; // Initialize the message start/end strings, which will be set when - // parseString is called. + reject = function (reason) { + this._reject(reason); + }; +}} - this.vcMsgStart_ = null; - this.vcMsgEnd_ = null; // Arrays used by multiple methods within this class to hold persistent - // data. Just gets too bulky to pass these guys around. - // Messages to be returned to the calling function +Promise.join = function () { + var last = arguments.length - 1; + var fn; + if (last > 0 && typeof arguments[last] === "function") { + fn = arguments[last]; + if (!true) { + if (last <= 8 && canEvaluate) { + var ret = new Promise(INTERNAL); + ret._captureStackTrace(); + var HolderClass = holderClasses[last - 1]; + var holder = new HolderClass(fn); + var callbacks = thenCallbacks; - this.retMsg_ = []; // Units for parenthetical unit strings + for (var i = 0; i < last; ++i) { + var maybePromise = tryConvertToPromise(arguments[i], ret); + if (maybePromise instanceof Promise) { + maybePromise = maybePromise._target(); + var bitField = maybePromise._bitField; + ; + if (((bitField & 50397184) === 0)) { + maybePromise._then(callbacks[i], reject, + undefined, ret, holder); + promiseSetters[i](maybePromise, holder); + holder.asyncNeeded = false; + } else if (((bitField & 33554432) !== 0)) { + callbacks[i].call(ret, + maybePromise._value(), holder); + } else if (((bitField & 16777216) !== 0)) { + ret._reject(maybePromise._reason()); + } else { + ret._cancel(); + } + } else { + callbacks[i].call(ret, maybePromise, holder); + } + } - this.parensUnits_ = []; // annotation text for annotations found in unit strings + if (!ret._isFateSealed()) { + if (holder.asyncNeeded) { + var domain = getDomain(); + if (domain !== null) { + holder.fn = util.domainBind(domain, holder.fn); + } + } + ret._setAsyncGuaranteed(); + ret._setOnCancel(holder); + } + return ret; + } + } + } + var args = [].slice.call(arguments);; + if (fn) args.pop(); + var ret = new PromiseArray(args).promise(); + return fn !== undefined ? ret.spread(fn) : ret; +}; - this.annotations_ = []; // suggestions for unit strings that for which no unit was found +}; - this.suggestions = []; - } // end constructor +},{"./util":36}],18:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, + PromiseArray, + apiRejection, + tryConvertToPromise, + INTERNAL, + debug) { +var getDomain = Promise._getDomain; +var util = _dereq_("./util"); +var tryCatch = util.tryCatch; +var errorObj = util.errorObj; +var async = Promise._async; - /** - * Sets the emphasis strings to the HTML used in the webpage display - or - * blanks them out, depending on the use parameter. - * - * @param use flag indicating whether or not to use the html message format; - * defaults to true - */ - - - useHTMLInMessages(use) { - if (use === undefined || use) { - this.openEmph_ = Ucum.openEmphHTML_; - this.closeEmph_ = Ucum.closeEmphHTML_; - } else { - this.openEmph_ = Ucum.openEmph_; - this.closeEmph_ = Ucum.closeEmph_; - } - } // end useHTMLInMessages +function MappingPromiseArray(promises, fn, limit, _filter) { + this.constructor$(promises); + this._promise._captureStackTrace(); + var domain = getDomain(); + this._callback = domain === null ? fn : util.domainBind(domain, fn); + this._preservedValues = _filter === INTERNAL + ? new Array(this.length()) + : null; + this._limit = limit; + this._inFlight = 0; + this._queue = []; + async.invoke(this._asyncInit, this, undefined); +} +util.inherits(MappingPromiseArray, PromiseArray); - /** - * Sets the braces message to be displayed for each unit string validation - * requested, as appropriate. - * - * @param use flag indicating whether or not to use the braces message; - * defaults to true - */ +MappingPromiseArray.prototype._asyncInit = function() { + this._init$(undefined, -2); +}; +MappingPromiseArray.prototype._init = function () {}; - useBraceMsgForEachString(use) { - if (use === undefined || use) this.bracesMsg_ = Ucum.bracesMsg_;else this.bracesMsg_ = ''; - } - /** - * Parses a unit string, returns a unit, a possibly updated version of - * the string passed in, and messages and suggestions where appropriate. - * - * The string returned may be updated if the input string contained unit - * names, e.g., "pound". The unit code ([lb_av] for pound) is placed in - * the string returned, a the returned messages array includes a note - * explaining the substitution. - * - * @param uStr the string defining the unit - * @param valConv indicates what type of request this is for - a request to - * validate (pass in 'validate') or a request to convert (pass in 'convert'); - * optional, defaults to 'validate' - * @param suggest a boolean to indicate whether or not suggestions are - * requested for a string that cannot be resolved to a valid unit; - * true indicates suggestions are wanted; false indicates they are not, - * and is the default if the parameter is not specified; - * @returns an array containing: - * the unit object or null if a unit could not be created. In cases where - * a fix was found for a problem string, .e.g., 2.mg for 2mg, a unit will - * be returned but an error message will also be returned, describing - * the substitution; - * the possibly updated unit string passed in; - * an array of any user messages (informational, error or warning) - * generated (or an empty array); and - * a suggestions array of hash objects (1 or more). Each hash contains - * three elements: - * 'msg' which is a message indicating what unit expression the - * suggestions are for; - * 'invalidUnit' which is the unit expression the suggestions are - * for; and - * 'units' which is an array of data for each suggested unit found. - * Each array will contain the unit code, the unit name and the - * unit guidance (if any). - * The return array will not contain a suggestions array if a valid unit - * was found or if suggestions were not requested. - * @throws an error if nothing was specified. - */ +MappingPromiseArray.prototype._promiseFulfilled = function (value, index) { + var values = this._values; + var length = this.length(); + var preservedValues = this._preservedValues; + var limit = this._limit; + if (index < 0) { + index = (index * -1) - 1; + values[index] = value; + if (limit >= 1) { + this._inFlight--; + this._drainQueue(); + if (this._isResolved()) return true; + } + } else { + if (limit >= 1 && this._inFlight >= limit) { + values[index] = value; + this._queue.push(index); + return false; + } + if (preservedValues !== null) preservedValues[index] = value; - parseString(uStr, valConv, suggest) { - uStr = uStr.trim(); // Make sure we have something to work with + var promise = this._promise; + var callback = this._callback; + var receiver = promise._boundValue(); + promise._pushContext(); + var ret = tryCatch(callback).call(receiver, value, index, length); + var promiseCreated = promise._popContext(); + debug.checkForgottenReturns( + ret, + promiseCreated, + preservedValues !== null ? "Promise.filter" : "Promise.map", + promise + ); + if (ret === errorObj) { + this._reject(ret.e); + return true; + } - if (uStr === '' || uStr === null) { - throw new Error('Please specify a unit expression to be validated.'); + var maybePromise = tryConvertToPromise(ret, this._promise); + if (maybePromise instanceof Promise) { + maybePromise = maybePromise._target(); + var bitField = maybePromise._bitField; + ; + if (((bitField & 50397184) === 0)) { + if (limit >= 1) this._inFlight++; + values[index] = maybePromise; + maybePromise._proxy(this, (index + 1) * -1); + return false; + } else if (((bitField & 33554432) !== 0)) { + ret = maybePromise._value(); + } else if (((bitField & 16777216) !== 0)) { + this._reject(maybePromise._reason()); + return true; + } else { + this._cancel(); + return true; + } + } + values[index] = ret; } - - if (valConv === 'validate') { - this.vcMsgStart_ = Ucum.valMsgStart_; - this.vcMsgEnd_ = Ucum.valMsgEnd_; - } else { - this.vcMsgStart_ = Ucum.cnvMsgStart_; - this.vcMsgEnd_ = Ucum.cnvMsgEnd_; + var totalResolved = ++this._totalResolved; + if (totalResolved >= length) { + if (preservedValues !== null) { + this._filter(values, preservedValues); + } else { + this._resolve(values); + } + return true; } + return false; +}; - if (suggest === undefined || suggest === false) { - this.suggestions_ = null; - } else { - this.suggestions_ = []; +MappingPromiseArray.prototype._drainQueue = function () { + var queue = this._queue; + var limit = this._limit; + var values = this._values; + while (queue.length > 0 && this._inFlight < limit) { + if (this._isResolved()) return; + var index = queue.pop(); + this._promiseFulfilled(values[index], index); } +}; - this.retMsg_ = []; - this.parensUnits_ = []; - this.annotations_ = []; - let origString = uStr; - let retObj = []; // Extract any annotations, i.e., text enclosed in braces ({}) from the - // string before further processing. Store each one in this.annotations_ - // array and put a placeholder in the string for the annotation. Do - // this before other processing in case an annotation contains characters - // that will be interpreted as parenthetical markers or operators in - // subsequent processing. - - uStr = this._getAnnotations(uStr); - - if (this.retMsg_.length > 0) { - retObj[0] = null; - retObj[1] = null; - } else { - // Flag used to block further processing on an unrecoverable error - let endProcessing = this.retMsg_.length > 0; // First check for one of the "special" units. If it's one of those, put - // in a substitution phrase for it to avoid having it separated on its - // embedded operator. This will only happen, by the way, if it is - // preceded by a prefix or followed by an operator and another unit. - - let sUnit = null; +MappingPromiseArray.prototype._filter = function (booleans, values) { + var len = values.length; + var ret = new Array(len); + var j = 0; + for (var i = 0; i < len; ++i) { + if (booleans[i]) ret[j++] = values[i]; + } + ret.length = j; + this._resolve(ret); +}; - for (sUnit in Ucum.specUnits_) { - while (uStr.indexOf(sUnit) !== -1) uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]); - } // Check for spaces and throw an error if any are found. The spec - // explicitly forbids spaces except in annotations, which is why any - // annotations are extracted before this check is made. +MappingPromiseArray.prototype.preservedValues = function () { + return this._preservedValues; +}; +function map(promises, fn, options, _filter) { + if (typeof fn !== "function") { + return apiRejection("expecting a function but got " + util.classString(fn)); + } - if (uStr.indexOf(' ') > -1) { - throw new Error('Blank spaces are not allowed in unit expressions.'); - } // end if blanks were found in the string - // assign the array returned to retObj. It will contain 2 elements: - // the unit returned in position 0; and the origString (possibly - // modified) in position 1. The origString in position 1 will not - // be changed by subsequent processing. + var limit = 0; + if (options !== undefined) { + if (typeof options === "object" && options !== null) { + if (typeof options.concurrency !== "number") { + return Promise.reject( + new TypeError("'concurrency' must be a number but it is " + + util.classString(options.concurrency))); + } + limit = options.concurrency; + } else { + return Promise.reject(new TypeError( + "options argument must be an object but it is " + + util.classString(options))); + } + } + limit = typeof limit === "number" && + isFinite(limit) && limit >= 1 ? limit : 0; + return new MappingPromiseArray(promises, fn, limit, _filter).promise(); +} +Promise.prototype.map = function (fn, options) { + return map(this, fn, options, null); +}; - retObj = this._parseTheString(uStr, origString); - let finalUnit = retObj[0]; // Do a final check to make sure that finalUnit is a unit and not - // just a number. Something like "8/{HCP}" will return a "unit" of 8 - // - which is not a unit. Hm - evidently it is. So just create a unit - // object for it. +Promise.map = function (promises, fn, options, _filter) { + return map(promises, fn, options, _filter); +}; - if (intUtils_.isIntegerUnit(finalUnit) || typeof finalUnit === 'number') { - finalUnit = new Unit({ - 'csCode_': origString, - 'magnitude_': finalUnit, - 'name_': origString - }); - retObj[0] = finalUnit; - } // end final check - } // end if no annotation errors were found +}; +},{"./util":36}],19:[function(_dereq_,module,exports){ +"use strict"; +module.exports = +function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) { +var util = _dereq_("./util"); +var tryCatch = util.tryCatch; - retObj[2] = this.retMsg_; - if (this.suggestions_ && this.suggestions_.length > 0) retObj[3] = this.suggestions_; - return retObj; - } // end parseString +Promise.method = function (fn) { + if (typeof fn !== "function") { + throw new Promise.TypeError("expecting a function but got " + util.classString(fn)); + } + return function () { + var ret = new Promise(INTERNAL); + ret._captureStackTrace(); + ret._pushContext(); + var value = tryCatch(fn).apply(this, arguments); + var promiseCreated = ret._popContext(); + debug.checkForgottenReturns( + value, promiseCreated, "Promise.method", ret); + ret._resolveFromSyncValue(value); + return ret; + }; +}; - /** - * Parses a unit string, returns a unit, a possibly updated version of - * the string passed in, and messages where appropriate. This should - * only be called from within this class (or by test code). - * - * The string returned may be updated if the input string contained unit - * names, e.g., "pound". The unit code ([lb_av] for pound) is placed in - * the string returned, a the returned messages array includes a note - * explaining the substitution. - * - * @param uStr the string defining the unit - * @param origString the original unit string passed in - * - * @returns - * an array containing: - * the unit object (or null if there were problems creating the unit); and - * the possibly updated unit string passed in. - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * the this.parensUnits_ array is referenced and possibly populated by - * methods called within this one - * the this.annotations_ array is referenced by methods called within - * this one - * the this.suggestions_ array may be populated by methods called within - * this one - */ +Promise.attempt = Promise["try"] = function (fn) { + if (typeof fn !== "function") { + return apiRejection("expecting a function but got " + util.classString(fn)); + } + var ret = new Promise(INTERNAL); + ret._captureStackTrace(); + ret._pushContext(); + var value; + if (arguments.length > 1) { + debug.deprecated("calling Promise.try with more than 1 argument"); + var arg = arguments[1]; + var ctx = arguments[2]; + value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg) + : tryCatch(fn).call(ctx, arg); + } else { + value = tryCatch(fn)(); + } + var promiseCreated = ret._popContext(); + debug.checkForgottenReturns( + value, promiseCreated, "Promise.try", ret); + ret._resolveFromSyncValue(value); + return ret; +}; +Promise.prototype._resolveFromSyncValue = function (value) { + if (value === util.errorObj) { + this._rejectCallback(value.e, false); + } else { + this._resolveCallback(value, true); + } +}; +}; - _parseTheString(uStr, origString) { - // Unit to be returned - let finalUnit = null; // Flag used to block further processing on an unrecoverable error +},{"./util":36}],20:[function(_dereq_,module,exports){ +"use strict"; +var util = _dereq_("./util"); +var maybeWrapAsError = util.maybeWrapAsError; +var errors = _dereq_("./errors"); +var OperationalError = errors.OperationalError; +var es5 = _dereq_("./es5"); - let endProcessing = this.retMsg_.length > 0; // Call _processParens to search for and process any/all parenthetical - // strings in uStr. Units created for parenthetical strings will be - // stored in the this.parensUnits_ array. +function isUntypedError(obj) { + return obj instanceof Error && + es5.getPrototypeOf(obj) === Error.prototype; +} - let parensResp = this._processParens(uStr, origString); +var rErrorKey = /^(?:name|message|stack|cause)$/; +function wrapAsOperationalError(obj) { + var ret; + if (isUntypedError(obj)) { + ret = new OperationalError(obj); + ret.name = obj.name; + ret.message = obj.message; + ret.stack = obj.stack; + var keys = es5.keys(obj); + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + if (!rErrorKey.test(key)) { + ret[key] = obj[key]; + } + } + return ret; + } + util.markAsOriginatingFromRejection(obj); + return obj; +} - endProcessing = parensResp[2]; // The array used to hold the units and their operators. +function nodebackForPromise(promise, multiArgs) { + return function(err, value) { + if (promise === null) return; + if (err) { + var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); + promise._attachExtraTrace(wrapped); + promise._reject(wrapped); + } else if (!multiArgs) { + promise._fulfill(value); + } else { + var args = [].slice.call(arguments, 1);; + promise._fulfill(args); + } + promise = null; + }; +} - let uArray = []; // Continue if we didn't hit a problem +module.exports = nodebackForPromise; - if (!endProcessing) { - uStr = parensResp[0]; - origString = parensResp[1]; // Call _makeUnitsArray to convert the string to an array of unit - // descriptors with operators. +},{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise) { +var util = _dereq_("./util"); +var async = Promise._async; +var tryCatch = util.tryCatch; +var errorObj = util.errorObj; - let mkUArray = this._makeUnitsArray(uStr, origString); +function spreadAdapter(val, nodeback) { + var promise = this; + if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback); + var ret = + tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val)); + if (ret === errorObj) { + async.throwLater(ret.e); + } +} - endProcessing = mkUArray[2]; +function successAdapter(val, nodeback) { + var promise = this; + var receiver = promise._boundValue(); + var ret = val === undefined + ? tryCatch(nodeback).call(receiver, null) + : tryCatch(nodeback).call(receiver, null, val); + if (ret === errorObj) { + async.throwLater(ret.e); + } +} +function errorAdapter(reason, nodeback) { + var promise = this; + if (!reason) { + var newReason = new Error(reason + ""); + newReason.cause = reason; + reason = newReason; + } + var ret = tryCatch(nodeback).call(promise._boundValue(), reason); + if (ret === errorObj) { + async.throwLater(ret.e); + } +} - if (!endProcessing) { - uArray = mkUArray[0]; - origString = mkUArray[1]; // Create a unit object out of each un element +Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback, + options) { + if (typeof nodeback == "function") { + var adapter = successAdapter; + if (options !== undefined && Object(options).spread) { + adapter = spreadAdapter; + } + this._then( + adapter, + errorAdapter, + undefined, + this, + nodeback + ); + } + return this; +}; +}; - let uLen = uArray.length; +},{"./util":36}],22:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function() { +var makeSelfResolutionError = function () { + return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a"); +}; +var reflectHandler = function() { + return new Promise.PromiseInspection(this._target()); +}; +var apiRejection = function(msg) { + return Promise.reject(new TypeError(msg)); +}; +function Proxyable() {} +var UNDEFINED_BINDING = {}; +var util = _dereq_("./util"); - for (let u1 = 0; u1 < uLen; u1++) { - //for (let u1 = 0; u1 < uLen && !endProcessing; u1++) { - let curCode = uArray[u1]['un']; // Determine the type of the "un" attribute of the current array element - // Check to see if it's a number. If so write the number version of - // the number back to the "un" attribute and move on +var getDomain; +if (util.isNode) { + getDomain = function() { + var ret = process.domain; + if (ret === undefined) ret = null; + return ret; + }; +} else { + getDomain = function() { + return null; + }; +} +util.notEnumerableProp(Promise, "_getDomain", getDomain); - if (intUtils_.isIntegerUnit(curCode)) { - uArray[u1]['un'] = Number(curCode); - } else { - // The current unit array element is a string. Check now to see - // if it is or contains a parenthesized unit from this.parensUnits_. - // If so, call _getParens to process the string and get the unit. - if (curCode.indexOf(this.parensFlag_) >= 0) { - let parenUnit = this._getParensUnit(curCode, origString); // if we couldn't process the string, set the end flag and bypass - // further processing. - - - if (!endProcessing) endProcessing = parenUnit[1]; // If we're good, put the unit in the uArray and replace the - // curCode, which contains the parentheses placeholders, etc., - // with the unit's code - including any substitutions. - - if (!endProcessing) { - uArray[u1]['un'] = parenUnit[0]; - } - } // end if the curCode contains a parenthesized unit - // Else it's not a parenthetical unit and not a number. Call - // _makeUnit to create a unit for it. - else { - let uRet = this._makeUnit(curCode, origString); // If we didn't get a unit, set the endProcessing flag. +var es5 = _dereq_("./es5"); +var Async = _dereq_("./async"); +var async = new Async(); +es5.defineProperty(Promise, "_async", {value: async}); +var errors = _dereq_("./errors"); +var TypeError = Promise.TypeError = errors.TypeError; +Promise.RangeError = errors.RangeError; +var CancellationError = Promise.CancellationError = errors.CancellationError; +Promise.TimeoutError = errors.TimeoutError; +Promise.OperationalError = errors.OperationalError; +Promise.RejectionError = errors.OperationalError; +Promise.AggregateError = errors.AggregateError; +var INTERNAL = function(){}; +var APPLY = {}; +var NEXT_FILTER = {}; +var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL); +var PromiseArray = + _dereq_("./promise_array")(Promise, INTERNAL, + tryConvertToPromise, apiRejection, Proxyable); +var Context = _dereq_("./context")(Promise); + /*jshint unused:false*/ +var createContext = Context.create; +var debug = _dereq_("./debuggability")(Promise, Context); +var CapturedTrace = debug.CapturedTrace; +var PassThroughHandlerContext = + _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER); +var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); +var nodebackForPromise = _dereq_("./nodeback"); +var errorObj = util.errorObj; +var tryCatch = util.tryCatch; +function check(self, executor) { + if (self == null || self.constructor !== Promise) { + throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + if (typeof executor !== "function") { + throw new TypeError("expecting a function but got " + util.classString(executor)); + } +} - if (uRet[0] === null) { - endProcessing = true; - } else { - uArray[u1]['un'] = uRet[0]; - origString = uRet[1]; - } - } // end if the curCode is not a parenthetical expression +function Promise(executor) { + if (executor !== INTERNAL) { + check(this, executor); + } + this._bitField = 0; + this._fulfillmentHandler0 = undefined; + this._rejectionHandler0 = undefined; + this._promise0 = undefined; + this._receiver0 = undefined; + this._resolveFromExecutor(executor); + this._promiseCreated(); + this._fireEvent("promiseCreated", this); +} - } // end if the "un" array is a not a number +Promise.prototype.toString = function () { + return "[object Promise]"; +}; - } // end do for each element in the units array +Promise.prototype.caught = Promise.prototype["catch"] = function (fn) { + var len = arguments.length; + if (len > 1) { + var catchInstances = new Array(len - 1), + j = 0, i; + for (i = 0; i < len - 1; ++i) { + var item = arguments[i]; + if (util.isObject(item)) { + catchInstances[j++] = item; + } else { + return apiRejection("Catch statement predicate: " + + "expecting an object but got " + util.classString(item)); + } + } + catchInstances.length = j; + fn = arguments[i]; + return this.then(undefined, catchFilter(catchInstances, fn, this)); + } + return this.then(undefined, fn); +}; - } // end if _makeUnitsArray did not return an error +Promise.prototype.reflect = function () { + return this._then(reflectHandler, + reflectHandler, undefined, this, undefined); +}; - } // end if _processParens did not find an error that causes a stop - // If we're still good, continue +Promise.prototype.then = function (didFulfill, didReject) { + if (debug.warnings() && arguments.length > 0 && + typeof didFulfill !== "function" && + typeof didReject !== "function") { + var msg = ".then() only accepts functions but was passed: " + + util.classString(didFulfill); + if (arguments.length > 1) { + msg += ", " + util.classString(didReject); + } + this._warn(msg); + } + return this._then(didFulfill, didReject, undefined, undefined, undefined); +}; +Promise.prototype.done = function (didFulfill, didReject) { + var promise = + this._then(didFulfill, didReject, undefined, undefined, undefined); + promise._setIsFinal(); +}; - if (!endProcessing) { - // Process the units (and numbers) to create one final unit object - if ((uArray[0] === null || uArray[0] === ' ' || uArray[0]['un'] === undefined || uArray[0]['un'] === null) && this.retMsg_.length === 0) { - // not sure what this might be, but this is a safeguard - this.retMsg_.push(`Unit string (${origString}) did not contain ` + `anything that could be used to create a unit, or else something ` + `that is not handled yet by this package. Sorry`); - endProcessing = true; - } +Promise.prototype.spread = function (fn) { + if (typeof fn !== "function") { + return apiRejection("expecting a function but got " + util.classString(fn)); } + return this.all()._then(fn, undefined, undefined, APPLY, undefined); +}; - if (!endProcessing) { - finalUnit = this._performUnitArithmetic(uArray, origString); +Promise.prototype.toJSON = function () { + var ret = { + isFulfilled: false, + isRejected: false, + fulfillmentValue: undefined, + rejectionReason: undefined + }; + if (this.isFulfilled()) { + ret.fulfillmentValue = this.value(); + ret.isFulfilled = true; + } else if (this.isRejected()) { + ret.rejectionReason = this.reason(); + ret.isRejected = true; } + return ret; +}; - return [finalUnit, origString]; - } // end _parseTheString +Promise.prototype.all = function () { + if (arguments.length > 0) { + this._warn(".all() was passed arguments but it does not take any"); + } + return new PromiseArray(this).promise(); +}; - /** - * Extracts all annotations from a unit string, replacing them with - * placeholders for later evaluation. The annotations are stored in the - * this.annotations_ array. This should only be called from within this - * class (or by test code). - * - * @param uString the unit string being parsed - * @returns the string after the annotations are replaced with placeholders - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * the this.annotations_ array is populated by this method - */ +Promise.prototype.error = function (fn) { + return this.caught(util.originatesFromRejection, fn); +}; +Promise.getNewLibraryCopy = module.exports; - _getAnnotations(uString) { - let openBrace = uString.indexOf('{'); +Promise.is = function (val) { + return val instanceof Promise; +}; - while (openBrace >= 0) { - let closeBrace = uString.indexOf('}'); +Promise.fromNode = Promise.fromCallback = function(fn) { + var ret = new Promise(INTERNAL); + ret._captureStackTrace(); + var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs + : false; + var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs)); + if (result === errorObj) { + ret._rejectCallback(result.e, true); + } + if (!ret._isFateSealed()) ret._setAsyncGuaranteed(); + return ret; +}; - if (closeBrace < 0) { - this.retMsg_.push('Missing closing brace for annotation starting at ' + this.openEmph_ + uString.substr(openBrace) + this.closeEmph_); - openBrace = -1; - } else { - let braceStr = uString.substring(openBrace, closeBrace + 1); - let aIdx = this.annotations_.length.toString(); - uString = uString.replace(braceStr, this.braceFlag_ + aIdx + this.braceFlag_); - this.annotations_.push(braceStr); - openBrace = uString.indexOf('{'); - } - } // end do while we have an opening brace - // check for a stray/unmatched closing brace +Promise.all = function (promises) { + return new PromiseArray(promises).promise(); +}; +Promise.cast = function (obj) { + var ret = tryConvertToPromise(obj); + if (!(ret instanceof Promise)) { + ret = new Promise(INTERNAL); + ret._captureStackTrace(); + ret._setFulfilled(); + ret._rejectionHandler0 = obj; + } + return ret; +}; - let closeBrace = uString.indexOf('}'); - if (closeBrace >= 0) this.retMsg_.push('Missing opening brace for closing brace found at ' + this.openEmph_ + uString.substring(0, closeBrace + 1) + this.closeEmph_); - return uString; - } // end _getAnnotations +Promise.resolve = Promise.fulfilled = Promise.cast; - /** - * Finds and processes any/all parenthesized unit strings. This should only - * be called from within this class (or by test code). - * - * Nested parenthesized strings are processed from the inside out. The - * parseString function is called from within this one for each parenthesized - * unit string, and the resulting unit object is stored in this.parensUnits_, - * to be processed after all strings are translated to units. - * - * A placeholder is placed in the unit string returned to indicate that the - * unit object should be obtained from the this.parensUnits_ array. The - * placeholder consists of the parenthesis flag (this.parensFlag_) followed - * by the index of the unit in this.parensUnits_ followed by this.parensFlag_. - * - * @param uString the unit string being parsed, where this will be the full - * string the first time this is called and parenthesized strings on any - * subsequent calls - * @param origString the original string first passed in to parseString - * @returns - * an array containing: - * the string after the parentheses are replaced; - * the original string; and - * a boolean flag indicating whether or not an error occurred that - * should stop processing. - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * this this.parensUnits_ array will be populated with units found for - * parenthetical unit strings - */ +Promise.reject = Promise.rejected = function (reason) { + var ret = new Promise(INTERNAL); + ret._captureStackTrace(); + ret._rejectCallback(reason, true); + return ret; +}; +Promise.setScheduler = function(fn) { + if (typeof fn !== "function") { + throw new TypeError("expecting a function but got " + util.classString(fn)); + } + return async.setScheduler(fn); +}; - _processParens(uString, origString) { - // Unit strings array and index - let uStrArray = []; - let uStrAryPos = 0; - let stopProcessing = false; - let pu = this.parensUnits_.length; // Count of characters trimmed off the beginning of the unit string (uString) - // as units are removed from it; used for error messages to provide - // context. +Promise.prototype._then = function ( + didFulfill, + didReject, + _, receiver, + internalData +) { + var haveInternalData = internalData !== undefined; + var promise = haveInternalData ? internalData : new Promise(INTERNAL); + var target = this._target(); + var bitField = target._bitField; - let trimmedCt = 0; // Break the unit string into pieces that consist of text outside of - // parenthetical strings and placeholders for the parenthetical units. - // This method is called recursively for parenthetical strings and the units - // returned are stored in the this.parensUnits_ array. + if (!haveInternalData) { + promise._propagateFrom(this, 3); + promise._captureStackTrace(); + if (receiver === undefined && + ((this._bitField & 2097152) !== 0)) { + if (!((bitField & 50397184) === 0)) { + receiver = this._boundValue(); + } else { + receiver = target === this ? undefined : this._boundTo; + } + } + this._fireEvent("promiseChained", this, promise); + } - while (uString !== "" && !stopProcessing) { - let openCt = 0; - let closeCt = 0; - let openPos = uString.indexOf('('); // If an opening parenthesis was not found, check for an unmatched - // close parenthesis. If one was found report the error and end - // processing. + var domain = getDomain(); + if (!((bitField & 50397184) === 0)) { + var handler, value, settler = target._settlePromiseCtx; + if (((bitField & 33554432) !== 0)) { + value = target._rejectionHandler0; + handler = didFulfill; + } else if (((bitField & 16777216) !== 0)) { + value = target._fulfillmentHandler0; + handler = didReject; + target._unsetRejectionIsUnhandled(); + } else { + settler = target._settlePromiseLateCancellationObserver; + value = new CancellationError("late cancellation observer"); + target._attachExtraTrace(value); + handler = didReject; + } - if (openPos < 0) { - let closePos = uString.indexOf(')'); + async.invoke(settler, target, { + handler: domain === null ? handler + : (typeof handler === "function" && + util.domainBind(domain, handler)), + promise: promise, + receiver: receiver, + value: value + }); + } else { + target._addCallbacks(didFulfill, didReject, promise, receiver, domain); + } - if (closePos >= 0) { - let theMsg = `Missing open parenthesis for close ` + `parenthesis at ${uString.substring(0, closePos + trimmedCt)}` + `${this.openEmph_}${uString.substr(closePos, 1)}${this.closeEmph_}`; + return promise; +}; - if (closePos < uString.length - 1) { - theMsg += `${uString.substr(closePos + 1)}`; - } +Promise.prototype._length = function () { + return this._bitField & 65535; +}; - this.retMsg_.push(theMsg); - uStrArray[uStrAryPos] = uString; - stopProcessing = true; - } // end if a close parenthesis was found - // If no parentheses were found in the current unit string, transfer - // it to the units array and blank out the string, which will end - // the search for parenthetical units. - else { - uStrArray[uStrAryPos] = uString; - uString = ""; - } // end if no close parenthesis was found +Promise.prototype._isFateSealed = function () { + return (this._bitField & 117506048) !== 0; +}; - } // end if no open parenthesis was found - // Otherwise an open parenthesis was found. Process the string that - // includes the parenthetical group - else { - openCt += 1; // Write the text before the parentheses (if any) to the unit strings array +Promise.prototype._isFollowing = function () { + return (this._bitField & 67108864) === 67108864; +}; - let uLen = uString.length; +Promise.prototype._setLength = function (len) { + this._bitField = (this._bitField & -65536) | + (len & 65535); +}; - if (openPos > 0) { - uStrArray[uStrAryPos++] = uString.substr(0, openPos); - } // Find the matching closePos, i.e., the one that closes the - // parenthetical group that this one opens. Look also for - // another open parenthesis, in case this includes nested parenthetical - // strings. This continues until it finds the same number of close - // parentheses as open parentheses, or runs out of string to check. - // In the case of nested parentheses this will identify the outer set - // of parentheses. +Promise.prototype._setFulfilled = function () { + this._bitField = this._bitField | 33554432; + this._fireEvent("promiseFulfilled", this); +}; +Promise.prototype._setRejected = function () { + this._bitField = this._bitField | 16777216; + this._fireEvent("promiseRejected", this); +}; - let closePos = 0; - let c = openPos + 1; +Promise.prototype._setFollowing = function () { + this._bitField = this._bitField | 67108864; + this._fireEvent("promiseResolved", this); +}; - for (; c < uLen && openCt != closeCt; c++) { - if (uString[c] === '(') openCt += 1;else if (uString[c] === ')') closeCt += 1; - } // Put a placeholder for the group in the unit strings array and recursively - // call this method for the parenthetical group. Put the unit returned - // in this.parensUnits_. Set the unit string to whatever follows - // the position of the closing parenthesis for this group, to be - // processed by the next iteration of this loop. If there's nothing - // left uString is set to "". +Promise.prototype._setIsFinal = function () { + this._bitField = this._bitField | 4194304; +}; +Promise.prototype._isFinal = function () { + return (this._bitField & 4194304) > 0; +}; - if (openCt === closeCt) { - closePos = c; - uStrArray[uStrAryPos++] = this.parensFlag_ + pu.toString() + this.parensFlag_; +Promise.prototype._unsetCancelled = function() { + this._bitField = this._bitField & (~65536); +}; - let parseResp = this._parseTheString(uString.substring(openPos + 1, closePos - 1), origString); +Promise.prototype._setCancelled = function() { + this._bitField = this._bitField | 65536; + this._fireEvent("promiseCancelled", this); +}; - if (parseResp[0] === null) stopProcessing = true;else { - origString = parseResp[1]; - this.parensUnits_[pu++] = parseResp[0]; - uString = uString.substr(closePos); - trimmedCt = closePos; - } - } // end if the number of open and close parentheses matched - // If the number of open and close parentheses doesn't match, indicate - // an error. - else { - uStrArray.push(origString.substr(openPos)); - this.retMsg_.push(`Missing close parenthesis for open parenthesis at ` + `${origString.substring(0, openPos + trimmedCt)}` + `${this.openEmph_}${origString.substr(openPos, 1)}` + `${this.closeEmph_}${origString.substr(openPos + 1)}`); - stopProcessing = true; - } - } // end if an open parenthesis was found +Promise.prototype._setWillBeCancelled = function() { + this._bitField = this._bitField | 8388608; +}; - } // end do while the input string is not empty +Promise.prototype._setAsyncGuaranteed = function() { + if (async.hasCustomScheduler()) return; + this._bitField = this._bitField | 134217728; +}; +Promise.prototype._receiverAt = function (index) { + var ret = index === 0 ? this._receiver0 : this[ + index * 4 - 4 + 3]; + if (ret === UNDEFINED_BINDING) { + return undefined; + } else if (ret === undefined && this._isBound()) { + return this._boundValue(); + } + return ret; +}; - if (stopProcessing) this.parensUnits_ = []; - return [uStrArray.join(''), origString, stopProcessing]; - } // end _processParens +Promise.prototype._promiseAt = function (index) { + return this[ + index * 4 - 4 + 2]; +}; - /** - * Breaks the unit string into an array of unit descriptors and operators. - * If a unit descriptor consists of a number preceding a unit code, with - * no multiplication operator, e.g., 2mg instead of 2.mg, it is handled - * as if it were a parenthetical expression. - * - * This should only be called from within this class (or by test code). - * - * @param uStr the unit string being parsed - * @param origString the original string passed to parseString - * @returns - * an array containing: - * the array representing the unit string; - * the original string passed in, possibly updated with corrections; and - * and a flag indicating whether or not processing can continue. - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - */ +Promise.prototype._fulfillmentHandlerAt = function (index) { + return this[ + index * 4 - 4 + 0]; +}; +Promise.prototype._rejectionHandlerAt = function (index) { + return this[ + index * 4 - 4 + 1]; +}; - _makeUnitsArray(uStr, origString) { - // Separate the string into pieces based on delimiters / (division) and . - // (multiplication). The idea is to get an array of units on which we - // can then perform any operations (prefixes, multiplication, division). - let uArray1 = uStr.match(/([./]|[^./]+)/g); - let endProcessing = false; - let uArray = []; - let startNumCheck = /(^[0-9]+)(\[?[a-zA-Z\_0-9a-zA-Z\_]+\]?$)/; // If the first element in the array is the division operator (/), the - // string started with '/'. Add a first element containing 1 to the - // array, which will cause the correct computation to be performed (inversion). +Promise.prototype._boundValue = function() {}; - if (uArray1[0] === "/") { - uArray1.unshift("1"); - } // If the first element in the array is the multiplication operator (.) - // return an error. - else if (uArray1[0] === '.') { - this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `The multiplication operator at the beginning of the expression is ` + `not valid. A multiplication operator must appear only between ` + `two codes.`); - endProcessing = true; - } +Promise.prototype._migrateCallback0 = function (follower) { + var bitField = follower._bitField; + var fulfill = follower._fulfillmentHandler0; + var reject = follower._rejectionHandler0; + var promise = follower._promise0; + var receiver = follower._receiverAt(0); + if (receiver === undefined) receiver = UNDEFINED_BINDING; + this._addCallbacks(fulfill, reject, promise, receiver, null); +}; - if (!endProcessing) { - // Check to see if there is a number preceding a unit code, e.g., 2mg - // If so, update the first element to remove the number (2mg -> mg) and - // add two elements to the beginning of the array - the number and the - // multiplication operator. - if (!intUtils_.isNumericString(uArray1[0])) { - let numRes = uArray1[0].match(startNumCheck); - - if (numRes && numRes.length === 3 && numRes[1] !== '' && numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) { - let dispVal = numRes[2]; +Promise.prototype._migrateCallbackAt = function (follower, index) { + var fulfill = follower._fulfillmentHandlerAt(index); + var reject = follower._rejectionHandlerAt(index); + var promise = follower._promiseAt(index); + var receiver = follower._receiverAt(index); + if (receiver === undefined) receiver = UNDEFINED_BINDING; + this._addCallbacks(fulfill, reject, promise, receiver, null); +}; - if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) { - let parensback = this._getParensUnit(numRes[2], origString); +Promise.prototype._addCallbacks = function ( + fulfill, + reject, + promise, + receiver, + domain +) { + var index = this._length(); - numRes[2] = parensback[0]['csCode_']; - dispVal = `(${numRes[2]})`; - endProcessing = parensback[1]; - } + if (index >= 65535 - 4) { + index = 0; + this._setLength(0); + } - if (!endProcessing) { - this.retMsg_.push(`${numRes[1]}${dispVal} is not a valid UCUM code.` + ` ${this.vcMsgStart_}${numRes[1]}.${dispVal}${this.vcMsgEnd_}`); - origString = origString.replace(`${numRes[1]}${dispVal}`, `${numRes[1]}.${dispVal}`); - uArray1[0] = numRes[2]; - uArray1.unshift(numRes[1], '.'); - } + if (index === 0) { + this._promise0 = promise; + this._receiver0 = receiver; + if (typeof fulfill === "function") { + this._fulfillmentHandler0 = + domain === null ? fulfill : util.domainBind(domain, fulfill); } - } // end if the first element is not a number (only) - // Create an array of unit/operator objects. The unit is, for now, the - // string containing the unit code (e.g., Hz for hertz) including - // a possible prefix and exponent. The operator is the operator to be - // applied to that unit and the one preceding it. So, a.b would give - // us two objects. The first will have a unit of a, and a blank operator - // (because it's the first unit). The second would have a unit of b - // and the multiplication operator (.). - + if (typeof reject === "function") { + this._rejectionHandler0 = + domain === null ? reject : util.domainBind(domain, reject); + } + } else { + var base = index * 4 - 4; + this[base + 2] = promise; + this[base + 3] = receiver; + if (typeof fulfill === "function") { + this[base + 0] = + domain === null ? fulfill : util.domainBind(domain, fulfill); + } + if (typeof reject === "function") { + this[base + 1] = + domain === null ? reject : util.domainBind(domain, reject); + } + } + this._setLength(index + 1); + return index; +}; - if (!endProcessing) { - let u1 = uArray1.length; - uArray = [{ - op: "", - un: uArray1[0] - }]; +Promise.prototype._proxy = function (proxyable, arg) { + this._addCallbacks(undefined, undefined, arg, proxyable, null); +}; - for (let n = 1; n < u1; n++) { - // check to make sure that we don't have two operators together, e.g., - // mg./K. If so, let the user know the problem. - let theOp = uArray1[n++]; // oh wait - check to make sure something is even there, that the - // user didn't end the expression with an operator. +Promise.prototype._resolveCallback = function(value, shouldBind) { + if (((this._bitField & 117506048) !== 0)) return; + if (value === this) + return this._rejectCallback(makeSelfResolutionError(), false); + var maybePromise = tryConvertToPromise(value, this); + if (!(maybePromise instanceof Promise)) return this._fulfill(value); - if (!uArray1[n]) { - this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `It is terminated with the operator ${this.openEmph_}` + `${theOp}${this.closeEmph_}.`); - n = u1; - endProcessing = true; - } else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) { - this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `A unit code is missing between${this.openEmph_}` + `${theOp}${this.closeEmph_}and${this.openEmph_}` + `${uArray1[n]}${this.closeEmph_}in${this.openEmph_}` + `${theOp}${uArray1[n]}${this.closeEmph_}.`); - n = u1; - endProcessing = true; - } else { - // Check to see if a number precedes a unit code. - // If so, send the element to _processParens, inserting the multiplication - // operator where it belongs. Treating it as parenthetical keeps it from - // being interpreted incorrectly because of operator parentheses. For - // example, if the whole string is mg/2kJ we don't want to rewrite it as - // mg/2.kJ - because mg/2 would be performed, followed by .kJ. Instead, - // handling 2kJ as a parenthesized unit will make sure mg is divided by - // 2.kJ. - if (!intUtils_.isNumericString(uArray1[n])) { - let numRes2 = uArray1[n].match(startNumCheck); + if (shouldBind) this._propagateFrom(maybePromise, 2); - if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' && numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) { - let invalidString = numRes2[0]; + var promise = maybePromise._target(); - if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) { - let parensback = this._getParensUnit(numRes2[2], origString); + if (promise === this) { + this._reject(makeSelfResolutionError()); + return; + } - numRes2[2] = parensback[0]['csCode_']; - invalidString = `(${numRes2[2]})`; - endProcessing = parensback[1]; + var bitField = promise._bitField; + if (((bitField & 50397184) === 0)) { + var len = this._length(); + if (len > 0) promise._migrateCallback0(this); + for (var i = 1; i < len; ++i) { + promise._migrateCallbackAt(this, i); + } + this._setFollowing(); + this._setLength(0); + this._setFollowee(promise); + } else if (((bitField & 33554432) !== 0)) { + this._fulfill(promise._value()); + } else if (((bitField & 16777216) !== 0)) { + this._reject(promise._reason()); + } else { + var reason = new CancellationError("late cancellation observer"); + promise._attachExtraTrace(reason); + this._reject(reason); + } +}; - if (!endProcessing) { - this.retMsg_.push(`${numRes2[1]}${invalidString} is not a ` + `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${invalidString}` + `${this.vcMsgEnd_}`); - let parensString = `(${numRes2[1]}.${invalidString})`; - origString = origString.replace(`${numRes2[1]}${invalidString}`, parensString); +Promise.prototype._rejectCallback = +function(reason, synchronous, ignoreNonErrorWarnings) { + var trace = util.ensureErrorObject(reason); + var hasStack = trace === reason; + if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) { + var message = "a promise was rejected with a non-error: " + + util.classString(reason); + this._warn(message, true); + } + this._attachExtraTrace(trace, synchronous ? hasStack : false); + this._reject(reason); +}; - let nextParens = this._processParens(parensString, origString); +Promise.prototype._resolveFromExecutor = function (executor) { + if (executor === INTERNAL) return; + var promise = this; + this._captureStackTrace(); + this._pushContext(); + var synchronous = true; + var r = this._execute(executor, function(value) { + promise._resolveCallback(value); + }, function (reason) { + promise._rejectCallback(reason, synchronous); + }); + synchronous = false; + this._popContext(); - endProcessing = nextParens[2]; + if (r !== undefined) { + promise._rejectCallback(r, true); + } +}; - if (!endProcessing) { - uArray.push({ - op: theOp, - un: nextParens[0] - }); - } //uArray.push({op: '.', un: numRes2[2]}); +Promise.prototype._settlePromiseFromHandler = function ( + handler, receiver, value, promise +) { + var bitField = promise._bitField; + if (((bitField & 65536) !== 0)) return; + promise._pushContext(); + var x; + if (receiver === APPLY) { + if (!value || typeof value.length !== "number") { + x = errorObj; + x.e = new TypeError("cannot .spread() a non-array: " + + util.classString(value)); + } else { + x = tryCatch(handler).apply(this._boundValue(), value); + } + } else { + x = tryCatch(handler).call(receiver, value); + } + var promiseCreated = promise._popContext(); + bitField = promise._bitField; + if (((bitField & 65536) !== 0)) return; - } - } // end if the string represents a parenthesized unit - else { - let parensStr = '(' + numRes2[1] + '.' + numRes2[2] + ')'; + if (x === NEXT_FILTER) { + promise._reject(value); + } else if (x === errorObj) { + promise._rejectCallback(x.e, false); + } else { + debug.checkForgottenReturns(x, promiseCreated, "", promise, this); + promise._resolveCallback(x); + } +}; - let parensResp = this._processParens(parensStr, origString); // if a "stop processing" flag was returned, set the n index to end - // the loop and set the endProcessing flag +Promise.prototype._target = function() { + var ret = this; + while (ret._isFollowing()) ret = ret._followee(); + return ret; +}; +Promise.prototype._followee = function() { + return this._rejectionHandler0; +}; - if (parensResp[2]) { - n = u1; - endProcessing = true; - } else { - this.retMsg_.push(`${numRes2[0]} is not a ` + `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${numRes2[2]}` + `${this.vcMsgEnd_}`); - origString = origString.replace(numRes2[0], parensStr); - uArray.push({ - op: theOp, - un: parensResp[0] - }); - } // end if no error on the processParens call +Promise.prototype._setFollowee = function(promise) { + this._rejectionHandler0 = promise; +}; - } // end if the string does not represent a parenthesized unit +Promise.prototype._settlePromise = function(promise, handler, receiver, value) { + var isPromise = promise instanceof Promise; + var bitField = this._bitField; + var asyncGuaranteed = ((bitField & 134217728) !== 0); + if (((bitField & 65536) !== 0)) { + if (isPromise) promise._invokeInternalOnCancel(); - } // end if the string is a number followed by a string - else { - uArray.push({ - op: theOp, - un: uArray1[n] - }); - } + if (receiver instanceof PassThroughHandlerContext && + receiver.isFinallyHandler()) { + receiver.cancelPromise = promise; + if (tryCatch(handler).call(receiver, value) === errorObj) { + promise._reject(errorObj.e); + } + } else if (handler === reflectHandler) { + promise._fulfill(reflectHandler.call(receiver)); + } else if (receiver instanceof Proxyable) { + receiver._promiseCancelled(promise); + } else if (isPromise || promise instanceof PromiseArray) { + promise._cancel(); + } else { + receiver.cancel(); + } + } else if (typeof handler === "function") { + if (!isPromise) { + handler.call(receiver, value, promise); + } else { + if (asyncGuaranteed) promise._setAsyncGuaranteed(); + this._settlePromiseFromHandler(handler, receiver, value, promise); + } + } else if (receiver instanceof Proxyable) { + if (!receiver._isResolved()) { + if (((bitField & 33554432) !== 0)) { + receiver._promiseFulfilled(value, promise); } else { - uArray.push({ - op: theOp, - un: uArray1[n] - }); + receiver._promiseRejected(value, promise); } - } // end if there isn't a missing operator or unit code - - } // end do for each element in uArray1 - - } // end if a processing error didn't occur in getParensUnit + } + } else if (isPromise) { + if (asyncGuaranteed) promise._setAsyncGuaranteed(); + if (((bitField & 33554432) !== 0)) { + promise._fulfill(value); + } else { + promise._reject(value); + } + } +}; - } // end if the string did not begin with a '.' with no following digit +Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) { + var handler = ctx.handler; + var promise = ctx.promise; + var receiver = ctx.receiver; + var value = ctx.value; + if (typeof handler === "function") { + if (!(promise instanceof Promise)) { + handler.call(receiver, value, promise); + } else { + this._settlePromiseFromHandler(handler, receiver, value, promise); + } + } else if (promise instanceof Promise) { + promise._reject(value); + } +}; +Promise.prototype._settlePromiseCtx = function(ctx) { + this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value); +}; - return [uArray, origString, endProcessing]; - } // end _makeUnitsArray +Promise.prototype._settlePromise0 = function(handler, value, bitField) { + var promise = this._promise0; + var receiver = this._receiverAt(0); + this._promise0 = undefined; + this._receiver0 = undefined; + this._settlePromise(promise, handler, receiver, value); +}; - /** - * Takes a unit string containing parentheses flags and returns the unit they - * represent. Any text found before and/or after the parenthetical - * expression is checked to see if we can tell what the user meant and - * let them know what it should have been. For example, 2(mg), which - * would resolve to 2mg, should be 2.mg. - * - * This should only be called from within this class (or by test code). - * - * @param pStr the string being parsed - * @param origString the original unit string passed in; passed through - * to _getAnnonText if annotation flags are found in any text preceding - * or following the parenthetical unit - * @returns - * an array containing - * the unit object; and - * a flag indicating whether or not processing should be ended. - * True indicates that the string was invalid and no corrections - * (substitutions or suggestions) could be found; - * False indicates that it was either valid or substitutions/suggestions - * were made. - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * this this.parensUnits_ array contains the units that are acquired by - * this method - * @throws an error if an invalid parensUnit index was found. This is - * a processing error. - */ +Promise.prototype._clearCallbackDataAtIndex = function(index) { + var base = index * 4 - 4; + this[base + 2] = + this[base + 3] = + this[base + 0] = + this[base + 1] = undefined; +}; +Promise.prototype._fulfill = function (value) { + var bitField = this._bitField; + if (((bitField & 117506048) >>> 16)) return; + if (value === this) { + var err = makeSelfResolutionError(); + this._attachExtraTrace(err); + return this._reject(err); + } + this._setFulfilled(); + this._rejectionHandler0 = value; - _getParensUnit(pStr, origString) { - let endProcessing = false; - let retAry = []; - let retUnit = null; - let befAnnoText = null; - let aftAnnoText = null; // Get the location of the flags. We're assuming there are only two - // because _processParens takes care of nesting. By the time we get - // here we should not be looking a nested parens. Also get any text - // before and after the parentheses. Once we get the unit we update - // the input string with the unit's csCode_, which will wipe out any - // before and after text + if ((bitField & 65535) > 0) { + if (((bitField & 134217728) !== 0)) { + this._settlePromises(); + } else { + async.settlePromises(this); + } + } +}; - let psIdx = pStr.indexOf(this.parensFlag_); - let befText = null; +Promise.prototype._reject = function (reason) { + var bitField = this._bitField; + if (((bitField & 117506048) >>> 16)) return; + this._setRejected(); + this._fulfillmentHandler0 = reason; - if (psIdx > 0) { - befText = pStr.substr(0, psIdx - 1); + if (this._isFinal()) { + return async.fatalError(reason, util.isNode); } - let peIdx = pStr.lastIndexOf(this.parensFlag_); - let aftText = null; + if ((bitField & 65535) > 0) { + async.settlePromises(this); + } else { + this._ensurePossibleRejectionHandled(); + } +}; - if (peIdx + this.pFlagLen_ < pStr.length) { - aftText = pStr.substr(peIdx + this.pFlagLen_); - } // Get the text between the flags +Promise.prototype._fulfillPromises = function (len, value) { + for (var i = 1; i < len; i++) { + var handler = this._fulfillmentHandlerAt(i); + var promise = this._promiseAt(i); + var receiver = this._receiverAt(i); + this._clearCallbackDataAtIndex(i); + this._settlePromise(promise, handler, receiver, value); + } +}; +Promise.prototype._rejectPromises = function (len, reason) { + for (var i = 1; i < len; i++) { + var handler = this._rejectionHandlerAt(i); + var promise = this._promiseAt(i); + var receiver = this._receiverAt(i); + this._clearCallbackDataAtIndex(i); + this._settlePromise(promise, handler, receiver, reason); + } +}; - let pNumText = pStr.substring(psIdx + this.pFlagLen_, peIdx); // Make sure the index is a number, and if it is, get the unit from the - // this.parensUnits_ array +Promise.prototype._settlePromises = function () { + var bitField = this._bitField; + var len = (bitField & 65535); - if (intUtils_.isNumericString(pNumText)) { - retUnit = this.parensUnits_[Number(pNumText)]; + if (len > 0) { + if (((bitField & 16842752) !== 0)) { + var reason = this._fulfillmentHandler0; + this._settlePromise0(this._rejectionHandler0, reason, bitField); + this._rejectPromises(len, reason); + } else { + var value = this._rejectionHandler0; + this._settlePromise0(this._fulfillmentHandler0, value, bitField); + this._fulfillPromises(len, value); + } + this._setLength(0); + } + this._clearCancellationData(); +}; - if (!intUtils_.isIntegerUnit(retUnit)) { - pStr = retUnit.csCode_; - } else { - pStr = retUnit; - } - } // If it's not a number, it's a programming error. Throw a fit. - else { - throw new Error(`Processing error - invalid parens number ${pNumText} ` + `found in ${pStr}.`); - } // If there's something in front of the starting parentheses flag, check to - // see if it's a number or an annotation. +Promise.prototype._settledValue = function() { + var bitField = this._bitField; + if (((bitField & 33554432) !== 0)) { + return this._rejectionHandler0; + } else if (((bitField & 16777216) !== 0)) { + return this._fulfillmentHandler0; + } +}; +function deferResolve(v) {this.promise._resolveCallback(v);} +function deferReject(v) {this.promise._rejectCallback(v, false);} - if (befText) { - // If it's a number, assume that multiplication was assumed - if (intUtils_.isNumericString(befText)) { - let nMag = retUnit.getProperty('magnitude_'); - nMag *= Number(befText); - retUnit.assignVals({ - 'magnitude_': nMag - }); - pStr = `${befText}.${pStr}`; - this.retMsg_.push(`${befText}${pStr} is not a valid UCUM code.\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); - } else { - if (befText.indexOf(this.braceFlag_) >= 0) { - let annoRet = this._getAnnoText(befText, origString); // if we found not only an annotation, but text before or after - // the annotation (remembering that this is all before the - // parentheses) throw an error - because we don't know what - // to do with it. Could it be missing an operator? +Promise.defer = Promise.pending = function() { + debug.deprecated("Promise.defer", "new Promise"); + var promise = new Promise(INTERNAL); + return { + promise: promise, + resolve: deferResolve, + reject: deferReject + }; +}; +util.notEnumerableProp(Promise, + "_makeSelfResolutionError", + makeSelfResolutionError); - if (annoRet[1] || annoRet[2]) { - throw new Error(`Text found before the parentheses (` + `${befText}) included an annotation along with other text ` + `for parenthetical unit ${retUnit.csCode_}`); - } // Otherwise put the annotation after the unit string and note - // the misplacement. +_dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection, + debug); +_dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug); +_dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug); +_dereq_("./direct_resolve")(Promise); +_dereq_("./synchronous_inspection")(Promise); +_dereq_("./join")( + Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain); +Promise.Promise = Promise; +Promise.version = "3.5.1"; +_dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); +_dereq_('./call_get.js')(Promise); +_dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug); +_dereq_('./timers.js')(Promise, INTERNAL, debug); +_dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug); +_dereq_('./nodeify.js')(Promise); +_dereq_('./promisify.js')(Promise, INTERNAL); +_dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection); +_dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection); +_dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); +_dereq_('./settle.js')(Promise, PromiseArray, debug); +_dereq_('./some.js')(Promise, PromiseArray, apiRejection); +_dereq_('./filter.js')(Promise, INTERNAL); +_dereq_('./each.js')(Promise, INTERNAL); +_dereq_('./any.js')(Promise); + + util.toFastProperties(Promise); + util.toFastProperties(Promise.prototype); + function fillTypes(value) { + var p = new Promise(INTERNAL); + p._fulfillmentHandler0 = value; + p._rejectionHandler0 = value; + p._promise0 = value; + p._receiver0 = value; + } + // Complete slack tracking, opt out of field-type tracking and + // stabilize map + fillTypes({a: 1}); + fillTypes({b: 2}); + fillTypes({c: 3}); + fillTypes(1); + fillTypes(function(){}); + fillTypes(undefined); + fillTypes(false); + fillTypes(new Promise(INTERNAL)); + debug.setBounds(Async.firstLineError, util.lastLineError); + return Promise; +}; - pStr += annoRet[0]; - this.retMsg_.push(`The annotation ${annoRet[0]} before the unit ` + `code is invalid.\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); - } // else the text before the parentheses is neither a number nor - // an annotation. If suggestions were NOT requested, record an - // error. - else if (!this.suggestions_) { - this.retMsg_.push(`${befText} preceding the unit code ${pStr} ` + `is invalid. Unable to make a substitution.`); - endProcessing = true; - } // otherwise try for suggestions - else { - let suggestStat = this._getSuggestions(befText); +},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL, tryConvertToPromise, + apiRejection, Proxyable) { +var util = _dereq_("./util"); +var isArray = util.isArray; - endProcessing = suggestStat !== 'succeeded'; - } // end if a brace was found or, if not, suggestions were not or - // were requested +function toResolutionValue(val) { + switch(val) { + case -2: return []; + case -3: return {}; + case -6: return new Map(); + } +} - } // end if text preceding the parentheses was not a number +function PromiseArray(values) { + var promise = this._promise = new Promise(INTERNAL); + if (values instanceof Promise) { + promise._propagateFrom(values, 3); + } + promise._setOnCancel(this); + this._values = values; + this._length = 0; + this._totalResolved = 0; + this._init(undefined, -2); +} +util.inherits(PromiseArray, Proxyable); - } // end if there was text before the parentheses - // Process any text after the parentheses +PromiseArray.prototype.length = function () { + return this._length; +}; + +PromiseArray.prototype.promise = function () { + return this._promise; +}; +PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) { + var values = tryConvertToPromise(this._values, this._promise); + if (values instanceof Promise) { + values = values._target(); + var bitField = values._bitField; + ; + this._values = values; - if (aftText) { - // if it's an annotation, get it and add it to the pStr - if (aftText.indexOf(this.braceFlag_) >= 0) { - let annoRet = this._getAnnoText(aftText, origString); // if we found not only an annotation, but text before or after - // the annotation (remembering that this is all after the - // parentheses) throw an error - because we don't know what - // to do with it. Could it be missing an operator? + if (((bitField & 50397184) === 0)) { + this._promise._setAsyncGuaranteed(); + return values._then( + init, + this._reject, + undefined, + this, + resolveValueIfEmpty + ); + } else if (((bitField & 33554432) !== 0)) { + values = values._value(); + } else if (((bitField & 16777216) !== 0)) { + return this._reject(values._reason()); + } else { + return this._cancel(); + } + } + values = util.asArray(values); + if (values === null) { + var err = apiRejection( + "expecting an array or an iterable object but got " + util.classString(values)).reason(); + this._promise._rejectCallback(err, false); + return; + } + if (values.length === 0) { + if (resolveValueIfEmpty === -5) { + this._resolveEmptyArray(); + } + else { + this._resolve(toResolutionValue(resolveValueIfEmpty)); + } + return; + } + this._iterate(values); +}; - if (annoRet[1] || annoRet[2]) { - throw new Error(`Text found after the parentheses (` + `${aftText}) included an annotation along with other text ` + `for parenthetical unit ${retUnit.csCode_}`); - } // Otherwise put the annotation after the unit string - no message - // needed. +PromiseArray.prototype._iterate = function(values) { + var len = this.getActualLength(values.length); + this._length = len; + this._values = this.shouldCopyValues() ? new Array(len) : this._values; + var result = this._promise; + var isResolved = false; + var bitField = null; + for (var i = 0; i < len; ++i) { + var maybePromise = tryConvertToPromise(values[i], result); + if (maybePromise instanceof Promise) { + maybePromise = maybePromise._target(); + bitField = maybePromise._bitField; + } else { + bitField = null; + } - pStr += annoRet[0]; - } // Otherwise check to see if it's an exponent. If so, warn the - // user that it's not valid - but try it anyway - else { - if (intUtils_.isNumericString(aftText)) { - pStr += aftText; - retUnit = retUnit.power(Number(aftText)); - this.retMsg_.push(`An exponent (${aftText}) following a parenthesis ` + `is invalid as of revision 1.9 of the UCUM Specification.\n ` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); - } // else the text after the parentheses is neither a number nor - // an annotation. If suggestions were NOT requested, record an - // error. - else if (!this.suggestions_) { - this.retMsg_.push(`Text ${aftText} following the unit code ${pStr} ` + `is invalid. Unable to make a substitution.`); - endProcessing = true; - } // otherwise try for suggestions - else { - let suggestStat = this._getSuggestions(befText); + if (isResolved) { + if (bitField !== null) { + maybePromise.suppressUnhandledRejections(); + } + } else if (bitField !== null) { + if (((bitField & 50397184) === 0)) { + maybePromise._proxy(this, i); + this._values[i] = maybePromise; + } else if (((bitField & 33554432) !== 0)) { + isResolved = this._promiseFulfilled(maybePromise._value(), i); + } else if (((bitField & 16777216) !== 0)) { + isResolved = this._promiseRejected(maybePromise._reason(), i); + } else { + isResolved = this._promiseCancelled(i); + } + } else { + isResolved = this._promiseFulfilled(maybePromise, i); + } + } + if (!isResolved) result._setAsyncGuaranteed(); +}; - endProcessing = suggestStat !== 'succeeded'; - } // end if text following the parentheses not an exponent +PromiseArray.prototype._isResolved = function () { + return this._values === null; +}; - } // end if text following the parentheses is not an annotation +PromiseArray.prototype._resolve = function (value) { + this._values = null; + this._promise._fulfill(value); +}; - } // end if there is text following the parentheses +PromiseArray.prototype._cancel = function() { + if (this._isResolved() || !this._promise._isCancellable()) return; + this._values = null; + this._promise._cancel(); +}; +PromiseArray.prototype._reject = function (reason) { + this._values = null; + this._promise._rejectCallback(reason, false); +}; - if (!endProcessing) { - if (!retUnit) { - retUnit = new Unit({ - 'csCode_': pStr, - 'magnitude_': 1, - 'name_': pStr - }); - } else if (intUtils_.isIntegerUnit(retUnit)) { - retUnit = new Unit({ - 'csCode_': retUnit, - 'magnitude_': retUnit, - 'name_': retUnit - }); - } else { - retUnit.csCode_ = pStr; - } +PromiseArray.prototype._promiseFulfilled = function (value, index) { + this._values[index] = value; + var totalResolved = ++this._totalResolved; + if (totalResolved >= this._length) { + this._resolve(this._values); + return true; } + return false; +}; - return [retUnit, endProcessing]; - } // end _getParensUnit +PromiseArray.prototype._promiseCancelled = function() { + this._cancel(); + return true; +}; - /** - * Takes a unit string containing annotation flags and returns the - * annotation they represent. This also returns any text found before - * the annotation and any found after the annotation. - * - * This should only be called from within this class (or by test code). - * NEEDS FIX in next branch to handle string with multiple annotations. - * - * @param pStr the string being parsed - * @param origString the original string being parsed; used in error msg - * thrown for an invalid index to the annotations array - * @returns - * an array containing - * the annotation for the pStr; - * any text found before the annotation; and - * any text found after the annotation. - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * the this.annotations_ array is used as the source for the annotations text - * @throws an error if for a processing error - an invalid annotation index. - */ +PromiseArray.prototype._promiseRejected = function (reason) { + this._totalResolved++; + this._reject(reason); + return true; +}; +PromiseArray.prototype._resultCancelled = function() { + if (this._isResolved()) return; + var values = this._values; + this._cancel(); + if (values instanceof Promise) { + values.cancel(); + } else { + for (var i = 0; i < values.length; ++i) { + if (values[i] instanceof Promise) { + values[i].cancel(); + } + } + } +}; - _getAnnoText(pStr, origString) { - // if the starting braces flag is not at index 0, get the starting - // text and the adjust the pStr to omit it. - let asIdx = pStr.indexOf(this.braceFlag_); - let startText = asIdx > 0 ? pStr.substring(0, asIdx) : null; +PromiseArray.prototype.shouldCopyValues = function () { + return true; +}; - if (asIdx !== 0) { - pStr = pStr.substr(asIdx); - } // Get the location of the end flag and, if text follows it, get the text +PromiseArray.prototype.getActualLength = function (len) { + return len; +}; +return PromiseArray; +}; - let aeIdx = pStr.indexOf(this.braceFlag_, 1); - let endText = aeIdx + this.bFlagLen_ < pStr.length ? pStr.substr(aeIdx + this.bFlagLen_) : null; // Get the index of the annotation in this.annotations_. - // Check it to make sure it's valid, and if not, throw an error +},{"./util":36}],24:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL) { +var THIS = {}; +var util = _dereq_("./util"); +var nodebackForPromise = _dereq_("./nodeback"); +var withAppended = util.withAppended; +var maybeWrapAsError = util.maybeWrapAsError; +var canEvaluate = util.canEvaluate; +var TypeError = _dereq_("./errors").TypeError; +var defaultSuffix = "Async"; +var defaultPromisified = {__isPromisified__: true}; +var noCopyProps = [ + "arity", "length", + "name", + "arguments", + "caller", + "callee", + "prototype", + "__isPromisified__" +]; +var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$"); - let idx = pStr.substring(this.bFlagLen_, aeIdx); - let idxNum = Number(idx); +var defaultFilter = function(name) { + return util.isIdentifier(name) && + name.charAt(0) !== "_" && + name !== "constructor"; +}; - if (!intUtils_.isNumericString(idx) || idxNum >= this.annotations_.length) { - throw new Error(`Processing Error - invalid annotation index ${idx} found ` + `in ${pStr} that was created from ${origString}`); - } // Replace the flags and annotation index with the annotation expression +function propsFilter(key) { + return !noCopyPropsPattern.test(key); +} +function isPromisified(fn) { + try { + return fn.__isPromisified__ === true; + } + catch (e) { + return false; + } +} - pStr = this.annotations_[idxNum]; - return [pStr, startText, endText]; - } // end _getAnnoText +function hasPromisified(obj, key, suffix) { + var val = util.getDataPropertyOrDefault(obj, key + suffix, + defaultPromisified); + return val ? isPromisified(val) : false; +} +function checkValid(ret, suffix, suffixRegexp) { + for (var i = 0; i < ret.length; i += 2) { + var key = ret[i]; + if (suffixRegexp.test(key)) { + var keyWithoutAsyncSuffix = key.replace(suffixRegexp, ""); + for (var j = 0; j < ret.length; j += 2) { + if (ret[j] === keyWithoutAsyncSuffix) { + throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a" + .replace("%s", suffix)); + } + } + } + } +} - /** - * Takes a unit string and looks for suggested units. This should be - * called for unit strings that cannot be resolved to unit codes. The - * string is searched for in the synonyms table found in the UnitTables - * class. That table includes all synonyms and unit names for the units - * in the unit data table. - * - * @param pStr the string being parsed - * @returns an object that contains an element named 'status', whose - * value indicates the status of the request: - * 'succeeded' indicates that synonyms were found; - * 'failed' indicates that no synonyms were found; or - * 'error' which indicates that an error occurred - * - * the this.retMsg_ array will be updated with a message indicating whether - * or not synonyms/suggestions were found - * the this.suggestions_ array will be updated with a hash (added to the - * array if it already contains others) that contains three elements: - * 'msg' which is a message indicating what unit expression the - * suggestions are for; - * 'invalidUnit' which is the unit expression the suggestions are for; and - * 'units' which is an array of data for each suggested unit found. - * Each array will contain the unit code, the unit name and the - * unit guidance (if any). - */ +function promisifiableMethods(obj, suffix, suffixRegexp, filter) { + var keys = util.inheritedDataKeys(obj); + var ret = []; + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + var value = obj[key]; + var passesDefaultFilter = filter === defaultFilter + ? true : defaultFilter(key, value, obj); + if (typeof value === "function" && + !isPromisified(value) && + !hasPromisified(obj, key, suffix) && + filter(key, value, obj, passesDefaultFilter)) { + ret.push(key, value); + } + } + checkValid(ret, suffix, suffixRegexp); + return ret; +} +var escapeIdentRegex = function(str) { + return str.replace(/([$])/, "\\$"); +}; - _getSuggestions(pStr) { - let retObj = intUtils_.getSynonyms(pStr); +var makeNodePromisifiedEval; +if (!true) { +var switchCaseArgumentOrder = function(likelyArgumentCount) { + var ret = [likelyArgumentCount]; + var min = Math.max(0, likelyArgumentCount - 1 - 3); + for(var i = likelyArgumentCount - 1; i >= min; --i) { + ret.push(i); + } + for(var i = likelyArgumentCount + 1; i <= 3; ++i) { + ret.push(i); + } + return ret; +}; - if (retObj['status'] === 'succeeded') { - let suggSet = {}; - suggSet['msg'] = `${pStr} is not a valid UCUM code. We found possible ` + `units that might be what was meant:`; - suggSet['invalidUnit'] = pStr; - let synLen = retObj['units'].length; - suggSet['units'] = []; +var argumentSequence = function(argumentCount) { + return util.filledRange(argumentCount, "_arg", ""); +}; - for (let s = 0; s < synLen; s++) { - let unit = retObj['units'][s]; - let unitArray = [unit['code'], unit['name'], unit['guidance']]; - suggSet['units'].push(unitArray); - } +var parameterDeclaration = function(parameterCount) { + return util.filledRange( + Math.max(parameterCount, 3), "_arg", ""); +}; - this.suggestions_.push(suggSet); - } else { - this.retMsg_.push(`${pStr} is not a valid UCUM code. No alternatives ` + `were found.`); +var parameterCount = function(fn) { + if (typeof fn.length === "number") { + return Math.max(Math.min(fn.length, 1023 + 1), 0); } + return 0; +}; - return retObj['status']; - } // end getSuggestions +makeNodePromisifiedEval = +function(callback, receiver, originalName, fn, _, multiArgs) { + var newParameterCount = Math.max(0, parameterCount(fn) - 1); + var argumentOrder = switchCaseArgumentOrder(newParameterCount); + var shouldProxyThis = typeof callback === "string" || receiver === THIS; - /** - * Creates a unit object from a string defining one unit. The string - * should consist of a unit code for a unit already defined (base or - * otherwise). It may include a prefix and an exponent, e.g., cm2 - * (centimeter squared). This should only be called from within this - * class (or by test code). - * - * @params uCode the string defining the unit - * @param origString the original string to be parsed; used to provide - * context for messages - * @returns - * an array containing: - * a unit object, or null if there were problems creating the unit; and - * the origString passed in, which may be updated if a unit name was - * translated to a unit code. - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - * the this.suggestions_ array will be populated if no unit (with or without - * substitutions) could be found and suggestions were requested - */ + function generateCallForArgumentCount(count) { + var args = argumentSequence(count).join(", "); + var comma = count > 0 ? ", " : ""; + var ret; + if (shouldProxyThis) { + ret = "ret = callback.call(this, {{args}}, nodeback); break;\n"; + } else { + ret = receiver === undefined + ? "ret = callback({{args}}, nodeback); break;\n" + : "ret = callback.call(receiver, {{args}}, nodeback); break;\n"; + } + return ret.replace("{{args}}", args).replace(", ", comma); + } + function generateArgumentSwitchCase() { + var ret = ""; + for (var i = 0; i < argumentOrder.length; ++i) { + ret += "case " + argumentOrder[i] +":" + + generateCallForArgumentCount(argumentOrder[i]); + } - _makeUnit(uCode, origString) { - // First try the code just as is, without looking for annotations, - // prefixes, exponents, or elephants. - let retUnit = this.utabs_.getUnitByCode(uCode); + ret += " \n\ + default: \n\ + var args = new Array(len + 1); \n\ + var i = 0; \n\ + for (var i = 0; i < len; ++i) { \n\ + args[i] = arguments[i]; \n\ + } \n\ + args[i] = nodeback; \n\ + [CodeForCall] \n\ + break; \n\ + ".replace("[CodeForCall]", (shouldProxyThis + ? "ret = callback.apply(this, args);\n" + : "ret = callback.apply(receiver, args);\n")); + return ret; + } - if (retUnit) { - retUnit = retUnit.clone(); - } // If we found it, we're done. No need to parse for those elephants (or - // other stuff). - else if (uCode.indexOf(this.braceFlag_) >= 0) { - let getAnnoRet = this._getUnitWithAnnotation(uCode, origString); + var getFunctionCode = typeof callback === "string" + ? ("this != null ? this['"+callback+"'] : fn") + : "fn"; + var body = "'use strict'; \n\ + var ret = function (Parameters) { \n\ + 'use strict'; \n\ + var len = arguments.length; \n\ + var promise = new Promise(INTERNAL); \n\ + promise._captureStackTrace(); \n\ + var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\ + var ret; \n\ + var callback = tryCatch([GetFunctionCode]); \n\ + switch(len) { \n\ + [CodeForSwitchCase] \n\ + } \n\ + if (ret === errorObj) { \n\ + promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\ + } \n\ + if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\ + return promise; \n\ + }; \n\ + notEnumerableProp(ret, '__isPromisified__', true); \n\ + return ret; \n\ + ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase()) + .replace("[GetFunctionCode]", getFunctionCode); + body = body.replace("Parameters", parameterDeclaration(newParameterCount)); + return new Function("Promise", + "fn", + "receiver", + "withAppended", + "maybeWrapAsError", + "nodebackForPromise", + "tryCatch", + "errorObj", + "notEnumerableProp", + "INTERNAL", + body)( + Promise, + fn, + receiver, + withAppended, + maybeWrapAsError, + nodebackForPromise, + util.tryCatch, + util.errorObj, + util.notEnumerableProp, + INTERNAL); +}; +} - retUnit = getAnnoRet[0]; +function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) { + var defaultThis = (function() {return this;})(); + var method = callback; + if (typeof method === "string") { + callback = fn; + } + function promisified() { + var _receiver = receiver; + if (receiver === THIS) _receiver = this; + var promise = new Promise(INTERNAL); + promise._captureStackTrace(); + var cb = typeof method === "string" && this !== defaultThis + ? this[method] : callback; + var fn = nodebackForPromise(promise, multiArgs); + try { + cb.apply(_receiver, withAppended(arguments, fn)); + } catch(e) { + promise._rejectCallback(maybeWrapAsError(e), true, true); + } + if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); + return promise; + } + util.notEnumerableProp(promisified, "__isPromisified__", true); + return promisified; +} - if (retUnit) { - origString = getAnnoRet[1]; - } // If a unit is not found, retUnit will be returned null and - // the this.retMsg_ array will contain a message describing the problem. - // If a unit is found, of course, all is good. So ... nothing left - // to see here, move along. +var makeNodePromisified = canEvaluate + ? makeNodePromisifiedEval + : makeNodePromisifiedClosure; - } // end if the uCode includes an annotation - else { - // So we didn't find a unit for the full uCode or for one with - // annotations. Try looking for a unit that uses a carat (^) - // instead of an asterisk (*) - if (uCode.indexOf('^') > -1) { - let tryCode = uCode.replace('^', '*'); - retUnit = this.utabs_.getUnitByCode(tryCode); +function promisifyAll(obj, suffix, filter, promisifier, multiArgs) { + var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$"); + var methods = + promisifiableMethods(obj, suffix, suffixRegexp, filter); - if (retUnit) { - retUnit = retUnit.clone(); - retUnit.csCode_ = retUnit.csCode_.replace('*', '^'); - retUnit.ciCode_ = retUnit.ciCode_.replace('*', '^'); - } - } // If that didn't work, check to see if it should have brackets - // around it (uCode = degF when it should be [degF] + for (var i = 0, len = methods.length; i < len; i+= 2) { + var key = methods[i]; + var fn = methods[i+1]; + var promisifiedKey = key + suffix; + if (promisifier === makeNodePromisified) { + obj[promisifiedKey] = + makeNodePromisified(key, THIS, key, fn, suffix, multiArgs); + } else { + var promisified = promisifier(fn, function() { + return makeNodePromisified(key, THIS, key, + fn, suffix, multiArgs); + }); + util.notEnumerableProp(promisified, "__isPromisified__", true); + obj[promisifiedKey] = promisified; + } + } + util.toFastProperties(obj); + return obj; +} +function promisify(callback, receiver, multiArgs) { + return makeNodePromisified(callback, receiver, undefined, + callback, null, multiArgs); +} - if (!retUnit) { - let addBrackets = '[' + uCode + ']'; - retUnit = this.utabs_.getUnitByCode(addBrackets); +Promise.promisify = function (fn, options) { + if (typeof fn !== "function") { + throw new TypeError("expecting a function but got " + util.classString(fn)); + } + if (isPromisified(fn)) { + return fn; + } + options = Object(options); + var receiver = options.context === undefined ? THIS : options.context; + var multiArgs = !!options.multiArgs; + var ret = promisify(fn, receiver, multiArgs); + util.copyDescriptors(fn, ret, propsFilter); + return ret; +}; - if (retUnit) { - retUnit = retUnit.clone(); - origString = origString.replace(uCode, addBrackets); - this.retMsg_.push(`${uCode} is not a valid unit expression, but ` + `${addBrackets} is.\n` + this.vcMsgStart_ + `${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`); - } // end if we found the unit after adding brackets +Promise.promisifyAll = function (target, options) { + if (typeof target !== "function" && typeof target !== "object") { + throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + options = Object(options); + var multiArgs = !!options.multiArgs; + var suffix = options.suffix; + if (typeof suffix !== "string") suffix = defaultSuffix; + var filter = options.filter; + if (typeof filter !== "function") filter = defaultFilter; + var promisifier = options.promisifier; + if (typeof promisifier !== "function") promisifier = makeNodePromisified; - } // end trying to add brackets - // If we didn't find it, try it as a name + if (!util.isIdentifier(suffix)) { + throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + var keys = util.inheritedDataKeys(target); + for (var i = 0; i < keys.length; ++i) { + var value = target[keys[i]]; + if (keys[i] !== "constructor" && + util.isClass(value)) { + promisifyAll(value.prototype, suffix, filter, promisifier, + multiArgs); + promisifyAll(value, suffix, filter, promisifier, multiArgs); + } + } - if (!retUnit) { - let retUnitAry = this.utabs_.getUnitByName(uCode); + return promisifyAll(target, suffix, filter, promisifier, multiArgs); +}; +}; - if (retUnitAry && retUnitAry.length > 0) { - retUnit = retUnitAry[0].clone(); - let mString = 'The UCUM code for ' + uCode + ' is ' + retUnit.csCode_ + '.\n' + this.vcMsgStart_ + retUnit.csCode_ + this.vcMsgEnd_; - let dupMsg = false; - for (let r = 0; r < this.retMsg_.length && !dupMsg; r++) dupMsg = this.retMsg_[r] === mString; +},{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function( + Promise, PromiseArray, tryConvertToPromise, apiRejection) { +var util = _dereq_("./util"); +var isObject = util.isObject; +var es5 = _dereq_("./es5"); +var Es6Map; +if (typeof Map === "function") Es6Map = Map; - if (!dupMsg) this.retMsg_.push(mString); - let rStr = new RegExp('(^|[.\/({])(' + uCode + ')($|[.\/)}])'); - let res = origString.match(rStr); - origString = origString.replace(rStr, res[1] + retUnit.csCode_ + res[3]); - uCode = retUnit.csCode_; - } - } // If we still don't have a unit, try assuming a modifier (prefix and/or - // exponent) and look for a unit without the modifier +var mapToEntries = (function() { + var index = 0; + var size = 0; + function extractEntry(value, key) { + this[index] = value; + this[index + size] = key; + index++; + } - if (!retUnit) { - // Well, first see if it's one of the special units. If so, - // replace the placeholder text with the actual unit string, keeping - // whatever text (probably a prefix) goes with the unit string. - let sUnit = null; + return function mapToEntries(map) { + size = map.size; + index = 0; + var ret = new Array(map.size * 2); + map.forEach(extractEntry, ret); + return ret; + }; +})(); - for (sUnit in Ucum.specUnits_) { - if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1) uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit); +var entriesToMap = function(entries) { + var ret = new Es6Map(); + var length = entries.length / 2 | 0; + for (var i = 0; i < length; ++i) { + var key = entries[length + i]; + var value = entries[i]; + ret.set(key, value); + } + return ret; +}; + +function PropertiesPromiseArray(obj) { + var isMap = false; + var entries; + if (Es6Map !== undefined && obj instanceof Es6Map) { + entries = mapToEntries(obj); + isMap = true; + } else { + var keys = es5.keys(obj); + var len = keys.length; + entries = new Array(len * 2); + for (var i = 0; i < len; ++i) { + var key = keys[i]; + entries[i] = obj[key]; + entries[i + len] = key; + } + } + this.constructor$(entries); + this._isMap = isMap; + this._init$(undefined, isMap ? -6 : -3); +} +util.inherits(PropertiesPromiseArray, PromiseArray); + +PropertiesPromiseArray.prototype._init = function () {}; + +PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) { + this._values[index] = value; + var totalResolved = ++this._totalResolved; + if (totalResolved >= this._length) { + var val; + if (this._isMap) { + val = entriesToMap(this._values); + } else { + val = {}; + var keyOffset = this.length(); + for (var i = 0, len = this.length(); i < len; ++i) { + val[this._values[i + keyOffset]] = this._values[i]; } + } + this._resolve(val); + return true; + } + return false; +}; - retUnit = this.utabs_.getUnitByCode(uCode); - if (retUnit) retUnit = retUnit.clone(); - } +PropertiesPromiseArray.prototype.shouldCopyValues = function () { + return false; +}; - if (!retUnit) { - let origCode = uCode; - let origUnit = null; - let exp = null; - let pfxCode = null; - let pfxObj = null; - let pfxVal = null; - let pfxExp = null; // Look first for an exponent. If we got one, separate it out and - // try to get the unit again +PropertiesPromiseArray.prototype.getActualLength = function (len) { + return len >> 1; +}; - let codeAndExp = this._isCodeWithExponent(uCode); +function props(promises) { + var ret; + var castValue = tryConvertToPromise(promises); - if (codeAndExp) { - uCode = codeAndExp[0]; - exp = codeAndExp[1]; - origUnit = this.utabs_.getUnitByCode(uCode); - } // If we still don't have a unit, separate out the prefix, if any, - // and try without it. + if (!isObject(castValue)) { + return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } else if (castValue instanceof Promise) { + ret = castValue._then( + Promise.props, undefined, undefined, undefined, undefined); + } else { + ret = new PropertiesPromiseArray(castValue).promise(); + } + if (castValue instanceof Promise) { + ret._propagateFrom(castValue, 2); + } + return ret; +} - if (!origUnit) { - // Try for a single character prefix first. - pfxCode = uCode.charAt(0); - pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode); // if we got a prefix, get its info and remove it from the unit code +Promise.prototype.props = function () { + return props(this); +}; - if (pfxObj) { - pfxVal = pfxObj.getValue(); - pfxExp = pfxObj.getExp(); - let pCodeLen = pfxCode.length; - uCode = uCode.substr(pCodeLen); // try again for the unit +Promise.props = function (promises) { + return props(promises); +}; +}; - origUnit = this.utabs_.getUnitByCode(uCode); // If we still don't have a unit, see if the prefix could be the - // two character "da" (deka) prefix. That's the only prefix with - // two characters, and without this check it's interpreted as "d" - // (deci) and the "a" is considered part of the unit code. +},{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){ +"use strict"; +function arrayMove(src, srcIndex, dst, dstIndex, len) { + for (var j = 0; j < len; ++j) { + dst[j + dstIndex] = src[j + srcIndex]; + src[j + srcIndex] = void 0; + } +} - if (!origUnit && pfxCode == 'd' && uCode.substr(0, 1) == 'a') { - pfxCode = 'da'; - pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode); - pfxVal = pfxObj.getValue(); - uCode = uCode.substr(1); // try one more time for the unit +function Queue(capacity) { + this._capacity = capacity; + this._length = 0; + this._front = 0; +} - origUnit = this.utabs_.getUnitByCode(uCode); - } // Reject the unit we found if it might have another prefix. - // Such things are in our tables through the LOINC source_ - // (ucum.csv) which has guidance and synonyms. I think it should be - // safe to exclude anything whose source is LOINC from having a - // prefix. +Queue.prototype._willBeOverCapacity = function (size) { + return this._capacity < size; +}; +Queue.prototype._pushOne = function (arg) { + var length = this.length(); + this._checkCapacity(length + 1); + var i = (this._front + length) & (this._capacity - 1); + this[i] = arg; + this._length = length + 1; +}; - if (origUnit && origUnit.source_ == 'LOINC') origUnit = null; - } // end if we found a prefix +Queue.prototype.push = function (fn, receiver, arg) { + var length = this.length() + 3; + if (this._willBeOverCapacity(length)) { + this._pushOne(fn); + this._pushOne(receiver); + this._pushOne(arg); + return; + } + var j = this._front + length - 3; + this._checkCapacity(length); + var wrapMask = this._capacity - 1; + this[(j + 0) & wrapMask] = fn; + this[(j + 1) & wrapMask] = receiver; + this[(j + 2) & wrapMask] = arg; + this._length = length; +}; - } // end if we didn't get a unit after removing an exponent - // If we still haven't found anything, we're done looking. - // (We tried with the full unit string, with the unit string - // without the exponent, the unit string without a prefix, - // common errors, etc. That's all we can try). +Queue.prototype.shift = function () { + var front = this._front, + ret = this[front]; + this[front] = undefined; + this._front = (front + 1) & (this._capacity - 1); + this._length--; + return ret; +}; - if (!origUnit) { - retUnit = null; // BUT if the user asked for suggestions, at least look for them +Queue.prototype.length = function () { + return this._length; +}; - if (this.suggestions_) { - let suggestStat = this._getSuggestions(origCode); - } else { - this.retMsg_.push(`${origCode} is not a valid UCUM code.`); - } - } else { - // Otherwise we found a unit object. Clone it and then apply the - // prefix and exponent, if any, to it. And remove the guidance. - retUnit = origUnit.clone(); // If we are here, this is only part of the full unit string, so it is - // not a base unit, and the synonyms will mostly likely not be correct for the full - // string. +Queue.prototype._checkCapacity = function (size) { + if (this._capacity < size) { + this._resizeTo(this._capacity << 1); + } +}; - retUnit.resetFieldsForDerivedUnit(); - let theDim = retUnit.getProperty('dim_'); - let theMag = retUnit.getProperty('magnitude_'); - let theName = retUnit.getProperty('name_'); - let theCiCode = retUnit.getProperty('ciCode_'); - let thePrintSymbol = retUnit.getProperty('printSymbol_'); // If there is an exponent for the unit, apply it to the dimension - // and magnitude now +Queue.prototype._resizeTo = function (capacity) { + var oldCapacity = this._capacity; + this._capacity = capacity; + var front = this._front; + var length = this._length; + var moveItemsCount = (front + length) & (oldCapacity - 1); + arrayMove(this, 0, this, oldCapacity, moveItemsCount); +}; - if (exp) { - exp = parseInt(exp); - let expMul = exp; - if (theDim) theDim = theDim.mul(exp); - theMag = Math.pow(theMag, exp); - retUnit.assignVals({ - 'magnitude_': theMag - }); // If there is also a prefix, apply the exponent to the prefix. +module.exports = Queue; - if (pfxObj) { - // if the prefix base is 10 it will have an exponent. Multiply - // the current prefix exponent by the exponent for the unit - // we're working with. Then raise the prefix value to the level - // defined by the exponent. - if (pfxExp) { - expMul *= pfxObj.getExp(); - pfxVal = Math.pow(10, expMul); - } // If the prefix base is not 10, it won't have an exponent. - // At the moment I don't see any units using the prefixes - // that aren't base 10. But if we get one the prefix value - // will be applied to the magnitude (below) if the unit does - // not have a conversion function, and to the conversion prefix - // if it does. +},{}],27:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function( + Promise, INTERNAL, tryConvertToPromise, apiRejection) { +var util = _dereq_("./util"); - } // end if there's a prefix as well as the exponent +var raceLater = function (promise) { + return promise.then(function(array) { + return race(array, promise); + }); +}; - } // end if there's an exponent - // Now apply the prefix, if there is one, to the conversion - // prefix or the magnitude +function race(promises, parent) { + var maybePromise = tryConvertToPromise(promises); + if (maybePromise instanceof Promise) { + return raceLater(maybePromise); + } else { + promises = util.asArray(promises); + if (promises === null) + return apiRejection("expecting an array or an iterable object but got " + util.classString(promises)); + } - if (pfxObj) { - if (retUnit.cnv_) { - retUnit.assignVals({ - 'cnvPfx_': pfxVal - }); - } else { - theMag *= pfxVal; - retUnit.assignVals({ - 'magnitude_': theMag - }); - } - } // if we have a prefix and/or an exponent, add them to the unit - // attributes - name, csCode, ciCode and print symbol + var ret = new Promise(INTERNAL); + if (parent !== undefined) { + ret._propagateFrom(parent, 3); + } + var fulfill = ret._fulfill; + var reject = ret._reject; + for (var i = 0, len = promises.length; i < len; ++i) { + var val = promises[i]; + if (val === undefined && !(i in promises)) { + continue; + } - let theCode = retUnit.csCode_; + Promise.cast(val)._then(fulfill, reject, undefined, ret, null); + } + return ret; +} - if (pfxObj) { - theName = pfxObj.getName() + theName; - theCode = pfxCode + theCode; - theCiCode = pfxObj.getCiCode() + theCiCode; - thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol; - retUnit.assignVals({ - 'name_': theName, - 'csCode_': theCode, - 'ciCode_': theCiCode, - 'printSymbol_': thePrintSymbol - }); - } +Promise.race = function (promises) { + return race(promises, undefined); +}; - if (exp) { - let expStr = exp.toString(); - retUnit.assignVals({ - 'name_': theName + '' + expStr + '', - 'csCode_': theCode + expStr, - 'ciCode_': theCiCode + expStr, - 'printSymbol_': thePrintSymbol + '' + expStr + '' - }); - } - } // end if an original unit was found (without prefix and/or exponent) +Promise.prototype.race = function () { + return race(this, undefined); +}; - } // end if we didn't get a unit for the full unit code (w/out modifiers) +}; - } // end if we didn't find the unit on the first try, before parsing +},{"./util":36}],28:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, + PromiseArray, + apiRejection, + tryConvertToPromise, + INTERNAL, + debug) { +var getDomain = Promise._getDomain; +var util = _dereq_("./util"); +var tryCatch = util.tryCatch; +function ReductionPromiseArray(promises, fn, initialValue, _each) { + this.constructor$(promises); + var domain = getDomain(); + this._fn = domain === null ? fn : util.domainBind(domain, fn); + if (initialValue !== undefined) { + initialValue = Promise.resolve(initialValue); + initialValue._attachCancellationCallback(this); + } + this._initialValue = initialValue; + this._currentCancellable = null; + if(_each === INTERNAL) { + this._eachValues = Array(this._length); + } else if (_each === 0) { + this._eachValues = null; + } else { + this._eachValues = undefined; + } + this._promise._captureStackTrace(); + this._init$(undefined, -5); +} +util.inherits(ReductionPromiseArray, PromiseArray); - return [retUnit, origString]; - } // end _makeUnit +ReductionPromiseArray.prototype._gotAccum = function(accum) { + if (this._eachValues !== undefined && + this._eachValues !== null && + accum !== INTERNAL) { + this._eachValues.push(accum); + } +}; - /** - * This method handles unit creation when an annotation is included - * in the unit string. This basically isolates and retrieves the - * annotation and then calls _makeUnit to try to get a unit from - * any text that precedes or follows the annotation. - * - * @param uCode the string defining the unit - * @param origString the original full string submitted to parseString - * @returns the unit object found, or null if one could not be found - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - */ +ReductionPromiseArray.prototype._eachComplete = function(value) { + if (this._eachValues !== null) { + this._eachValues.push(value); + } + return this._eachValues; +}; +ReductionPromiseArray.prototype._init = function() {}; - _getUnitWithAnnotation(uCode, origString) { - let retUnit = null; // Get the annotation and anything that precedes or follows it. +ReductionPromiseArray.prototype._resolveEmptyArray = function() { + this._resolve(this._eachValues !== undefined ? this._eachValues + : this._initialValue); +}; - let annoRet = this._getAnnoText(uCode, origString); +ReductionPromiseArray.prototype.shouldCopyValues = function () { + return false; +}; - let annoText = annoRet[0]; - let befAnnoText = annoRet[1]; - let aftAnnoText = annoRet[2]; // Add the warning about annotations - just once. +ReductionPromiseArray.prototype._resolve = function(value) { + this._promise._resolveCallback(value); + this._values = null; +}; - if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1) this.retMsg_.push(this.bracesMsg_); // If there's no text before or after the annotation, it's probably - // something that should be interpreted as a 1, e.g., {KCT'U}. - // HOWEVER, it could also be a case where someone used braces instead - // of brackets, e.g., {degF} instead of [degF]. Check for that before - // we assume it should be a 1. +ReductionPromiseArray.prototype._resultCancelled = function(sender) { + if (sender === this._initialValue) return this._cancel(); + if (this._isResolved()) return; + this._resultCancelled$(); + if (this._currentCancellable instanceof Promise) { + this._currentCancellable.cancel(); + } + if (this._initialValue instanceof Promise) { + this._initialValue.cancel(); + } +}; - let msgLen = this.retMsg_.length; +ReductionPromiseArray.prototype._iterate = function (values) { + this._values = values; + var value; + var i; + var length = values.length; + if (this._initialValue !== undefined) { + value = this._initialValue; + i = 0; + } else { + value = Promise.resolve(values[0]); + i = 1; + } - if (!befAnnoText && !aftAnnoText) { - let tryBrackets = '[' + annoText.substring(1, annoText.length - 1) + ']'; + this._currentCancellable = value; - let mkUnitRet = this._makeUnit(tryBrackets, origString); // If we got back a unit, assign it to the returned unit, and add - // a message to advise the user that brackets should enclose the code + if (!value.isRejected()) { + for (; i < length; ++i) { + var ctx = { + accum: null, + value: values[i], + index: i, + length: length, + array: this + }; + value = value._then(gotAccum, undefined, undefined, ctx, undefined); + } + } + if (this._eachValues !== undefined) { + value = value + ._then(this._eachComplete, undefined, undefined, this, undefined); + } + value._then(completed, completed, undefined, value, this); +}; - if (mkUnitRet[0]) { - retUnit = mkUnitRet[0]; - origString = origString.replace(annoText, tryBrackets); - this.retMsg_.push(`${annoText} is not a valid unit expression, but ` + `${tryBrackets} is.\n` + this.vcMsgStart_ + `${tryBrackets} (${retUnit.name_})${this.vcMsgEnd_}`); - } // Otherwise assume that this should be interpreted as a 1 - else { - // remove error message generated for trybrackets - if (this.retMsg_.length > msgLen) { - this.retMsg_.pop(); - } +Promise.prototype.reduce = function (fn, initialValue) { + return reduce(this, fn, initialValue, null); +}; - uCode = 1; - retUnit = 1; - } - } // end if it's only an annotation - else { - // if there's text before and no text after, assume the text before - // the annotation is the unit code (with an annotation following it). - // Call _makeUnit for the text before the annotation. - if (befAnnoText && !aftAnnoText) { - // make sure that what's before the annoText is not a number, e.g., - // /100{cells}. But f it is a number, just set the return unit to - // the number. - if (intUtils_.isIntegerUnit(befAnnoText)) { - retUnit = befAnnoText; - } // Otherwise try to find a unit - else { - let mkUnitRet = this._makeUnit(befAnnoText, origString); // if a unit was returned +Promise.reduce = function (promises, fn, initialValue, _each) { + return reduce(promises, fn, initialValue, _each); +}; +function completed(valueOrReason, array) { + if (this.isFulfilled()) { + array._resolve(valueOrReason); + } else { + array._reject(valueOrReason); + } +} - if (mkUnitRet[0]) { - retUnit = mkUnitRet[0]; - retUnit.csCode_ += annoText; - origString = mkUnitRet[1]; - } // Otherwise add a not found message - else { - this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` + `precedes the annotation ${annoText}.`); - } - } - } // else if there's only text after the annotation, try for a unit - // from the after text and assume the user put the annotation in - // the wrong place (and tell them) - else if (!befAnnoText && aftAnnoText) { - // Again, test for a number and if it is a number, set the return - // unit to the number. - if (intUtils_.isIntegerUnit(aftAnnoText)) { - retUnit = aftAnnoText + annoText; - this.retMsg_.push(`The annotation ${annoText} before the ``${aftAnnoText} is invalid.\n` + this.vcMsgStart_ + retUnit + this.vcMsgEnd_); - } else { - let mkUnitRet = this._makeUnit(aftAnnoText, origString); +function reduce(promises, fn, initialValue, _each) { + if (typeof fn !== "function") { + return apiRejection("expecting a function but got " + util.classString(fn)); + } + var array = new ReductionPromiseArray(promises, fn, initialValue, _each); + return array.promise(); +} - if (mkUnitRet[0]) { - retUnit = mkUnitRet[0]; - retUnit.csCode_ += annoText; - origString = retUnit.csCode_; - this.retMsg_.push(`The annotation ${annoText} before the unit ` + `code is invalid.\n` + this.vcMsgStart_ + retUnit.csCode_ + this.vcMsgEnd_); - } // Otherwise add a not found message - else { - this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` + `follows the annotation ${annoText}.`); - } - } - } // else it's got text before AND after the annotation. Now what? - // For now this is an error. This may be a case of a missing - // operator but that is not handled yet. - else { - this.retMsg_.push(`Unable to find a unit for ${befAnnoText}${annoText}` + `${aftAnnoText}.\nWe are not sure how to interpret text both before ` + `and after the annotation. Sorry`); - } - } // else if there's text before/and or after the annotation +function gotAccum(accum) { + this.accum = accum; + this.array._gotAccum(accum); + var value = tryConvertToPromise(this.value, this.array._promise); + if (value instanceof Promise) { + this.array._currentCancellable = value; + return value._then(gotValue, undefined, undefined, this, undefined); + } else { + return gotValue.call(this, value); + } +} +function gotValue(value) { + var array = this.array; + var promise = array._promise; + var fn = tryCatch(array._fn); + promise._pushContext(); + var ret; + if (array._eachValues !== undefined) { + ret = fn.call(promise._boundValue(), value, this.index, this.length); + } else { + ret = fn.call(promise._boundValue(), + this.accum, value, this.index, this.length); + } + if (ret instanceof Promise) { + array._currentCancellable = ret; + } + var promiseCreated = promise._popContext(); + debug.checkForgottenReturns( + ret, + promiseCreated, + array._eachValues !== undefined ? "Promise.each" : "Promise.reduce", + promise + ); + return ret; +} +}; - return [retUnit, origString]; - } // end _getUnitWithAnnotations +},{"./util":36}],29:[function(_dereq_,module,exports){ +"use strict"; +var util = _dereq_("./util"); +var schedule; +var noAsyncScheduler = function() { + throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); +}; +var NativePromise = util.getNativePromise(); +if (util.isNode && typeof MutationObserver === "undefined") { + var GlobalSetImmediate = global.setImmediate; + var ProcessNextTick = process.nextTick; + schedule = util.isRecentNode + ? function(fn) { GlobalSetImmediate.call(global, fn); } + : function(fn) { ProcessNextTick.call(process, fn); }; +} else if (typeof NativePromise === "function" && + typeof NativePromise.resolve === "function") { + var nativePromise = NativePromise.resolve(); + schedule = function(fn) { + nativePromise.then(fn); + }; +} else if ((typeof MutationObserver !== "undefined") && + !(typeof window !== "undefined" && + window.navigator && + (window.navigator.standalone || window.cordova))) { + schedule = (function() { + var div = document.createElement("div"); + var opts = {attributes: true}; + var toggleScheduled = false; + var div2 = document.createElement("div"); + var o2 = new MutationObserver(function() { + div.classList.toggle("foo"); + toggleScheduled = false; + }); + o2.observe(div2, opts); - /** - * Performs unit arithmetic for the units in the units array. That array - * contains units/numbers and the operators (division or multiplication) to - * be performed on each unit/unit or unit/number pair in the array. This - * should only be called from within this class (or by test code). - * - * @params uArray the array that contains the units, numbers and operators - * derived from the unit string passed in to parseString - * @param origString the original string to be parsed; used to provide - * context for messages - * - * @returns a single unit object that is the result of the unit arithmetic - * - * the this.retMsg_ array will be updated with any user messages - * (informational, error or warning) generated by this or called methods - */ + var scheduleToggle = function() { + if (toggleScheduled) return; + toggleScheduled = true; + div2.classList.toggle("foo"); + }; + + return function schedule(fn) { + var o = new MutationObserver(function() { + o.disconnect(); + fn(); + }); + o.observe(div, opts); + scheduleToggle(); + }; + })(); +} else if (typeof setImmediate !== "undefined") { + schedule = function (fn) { + setImmediate(fn); + }; +} else if (typeof setTimeout !== "undefined") { + schedule = function (fn) { + setTimeout(fn, 0); + }; +} else { + schedule = noAsyncScheduler; +} +module.exports = schedule; +},{"./util":36}],30:[function(_dereq_,module,exports){ +"use strict"; +module.exports = + function(Promise, PromiseArray, debug) { +var PromiseInspection = Promise.PromiseInspection; +var util = _dereq_("./util"); - _performUnitArithmetic(uArray, origString) { - let finalUnit = uArray[0]['un']; +function SettledPromiseArray(values) { + this.constructor$(values); +} +util.inherits(SettledPromiseArray, PromiseArray); - if (intUtils_.isIntegerUnit(finalUnit)) { - finalUnit = new Unit({ - 'csCode_': finalUnit, - 'magnitude_': Number(finalUnit), - 'name_': finalUnit - }); +SettledPromiseArray.prototype._promiseResolved = function (index, inspection) { + this._values[index] = inspection; + var totalResolved = ++this._totalResolved; + if (totalResolved >= this._length) { + this._resolve(this._values); + return true; } + return false; +}; - let uLen = uArray.length; - let endProcessing = false; // Perform the arithmetic for the units, starting with the first 2 units. - // We only need to do the arithmetic if we have more than one unit. +SettledPromiseArray.prototype._promiseFulfilled = function (value, index) { + var ret = new PromiseInspection(); + ret._bitField = 33554432; + ret._settledValueField = value; + return this._promiseResolved(index, ret); +}; +SettledPromiseArray.prototype._promiseRejected = function (reason, index) { + var ret = new PromiseInspection(); + ret._bitField = 16777216; + ret._settledValueField = reason; + return this._promiseResolved(index, ret); +}; - for (let u2 = 1; u2 < uLen && !endProcessing; u2++) { - let nextUnit = uArray[u2]['un']; +Promise.settle = function (promises) { + debug.deprecated(".settle()", ".reflect()"); + return new SettledPromiseArray(promises).promise(); +}; - if (intUtils_.isIntegerUnit(nextUnit)) { - nextUnit = new Unit({ - 'csCode_': nextUnit, - 'magnitude_': Number(nextUnit), - 'name_': nextUnit - }); - } +Promise.prototype.settle = function () { + return Promise.settle(this); +}; +}; - if (nextUnit === null || typeof nextUnit !== 'number' && !nextUnit.getProperty) { - let msgString = `Unit string (${origString}) contains unrecognized ` + 'element'; +},{"./util":36}],31:[function(_dereq_,module,exports){ +"use strict"; +module.exports = +function(Promise, PromiseArray, apiRejection) { +var util = _dereq_("./util"); +var RangeError = _dereq_("./errors").RangeError; +var AggregateError = _dereq_("./errors").AggregateError; +var isArray = util.isArray; +var CANCELLATION = {}; - if (nextUnit) { - msgString += ` (${this.openEmph_}${nextUnit.toString()}` + `${this.closeEmph_})`; - } - msgString += '; could not parse full string. Sorry'; - this.retMsg_.push(msgString); - endProcessing = true; - } else { - try { - // Is the operation division? - let thisOp = uArray[u2]['op']; - let isDiv = thisOp === '/'; // Perform the operation. Both the finalUnit and nextUnit - // are unit objects. +function SomePromiseArray(values) { + this.constructor$(values); + this._howMany = 0; + this._unwrap = false; + this._initialized = false; +} +util.inherits(SomePromiseArray, PromiseArray); - isDiv ? finalUnit = finalUnit.divide(nextUnit) : finalUnit = finalUnit.multiplyThese(nextUnit); - } catch (err) { - this.retMsg_.unshift(err.message); - endProcessing = true; - finalUnit = null; - } - } // end if we have another valid unit/number to process +SomePromiseArray.prototype._init = function () { + if (!this._initialized) { + return; + } + if (this._howMany === 0) { + this._resolve([]); + return; + } + this._init$(undefined, -5); + var isArrayResolved = isArray(this._values); + if (!this._isResolved() && + isArrayResolved && + this._howMany > this._canPossiblyFulfill()) { + this._reject(this._getRangeError(this.length())); + } +}; - } // end do for each unit after the first one +SomePromiseArray.prototype.init = function () { + this._initialized = true; + this._init(); +}; +SomePromiseArray.prototype.setUnwrap = function () { + this._unwrap = true; +}; - return finalUnit; - } // end _performUnitArithmetic +SomePromiseArray.prototype.howMany = function () { + return this._howMany; +}; - /** - * This tests a string to see if it starts with characters and ends with - * digits. This is used to test for an exponent on a UCUM code (or what - * we think might be a UCUM code). This is broken out to a separate - * function so that the regular expression can be verified to provide the - * results we expect, in case someone changes it. (Per Paul Lynch) - * See "Test _isCodeWithExponent method" in testUnitString.spec.js - * - * This particular regex has been tweaked several times. This one - * works with the following test strings: - * "m[H2O]-21 gives ["m[H2O]-21", "m[H2O]", "-21"] - * "m[H2O]+21 gives ["m[H2O]+21", "m[H2O]", "+21"] - * "m[H2O]21 gives ["m[H2O]-21", "m[H2O]", "21"] - * "s2" gives ["s2", "s, "2"] - * "kg" gives null - * "m[H2O]" gives null - * "m[H2O]23X" gives null - * - * @params uCode the code being tested - * @returns an array containing: (1) the code without the exponent (or - * trailing number); and (2) the exponent/trailing number. Returns null - * if there is no trailing number or something follows the trailing - * number, or if the first part is not characters. - */ +SomePromiseArray.prototype.setHowMany = function (count) { + this._howMany = count; +}; +SomePromiseArray.prototype._promiseFulfilled = function (value) { + this._addFulfilled(value); + if (this._fulfilled() === this.howMany()) { + this._values.length = this.howMany(); + if (this.howMany() === 1 && this._unwrap) { + this._resolve(this._values[0]); + } else { + this._resolve(this._values); + } + return true; + } + return false; - _isCodeWithExponent(uCode) { - let ret = []; - let res = uCode.match(/(^[^\-\+]+?)([\-\+\d]+)$/); // If we got a return with an exponent, separate the exponent from the - // unit and return both (as separate values) +}; +SomePromiseArray.prototype._promiseRejected = function (reason) { + this._addRejected(reason); + return this._checkOutcome(); +}; - if (res && res[2] && res[2] !== "") { - ret.push(res[1]); - ret.push(res[2]); - } // end if we got an exponent - else { - ret = null; - } +SomePromiseArray.prototype._promiseCancelled = function () { + if (this._values instanceof Promise || this._values == null) { + return this._cancel(); + } + this._addRejected(CANCELLATION); + return this._checkOutcome(); +}; - return ret; - } // end _isCodeWithExponent +SomePromiseArray.prototype._checkOutcome = function() { + if (this.howMany() > this._canPossiblyFulfill()) { + var e = new AggregateError(); + for (var i = this.length(); i < this._values.length; ++i) { + if (this._values[i] !== CANCELLATION) { + e.push(this._values[i]); + } + } + if (e.length > 0) { + this._reject(e); + } else { + this._cancel(); + } + return true; + } + return false; +}; +SomePromiseArray.prototype._fulfilled = function () { + return this._totalResolved; +}; -} // end class UnitString +SomePromiseArray.prototype._rejected = function () { + return this._values.length - this.length(); +}; -/** - * This function exists ONLY until the original UnitString constructor - * is called for the first time. It's defined here in case getInstance - * is called before the constructor. This calls the constructor. - * - * The constructor redefines the getInstance function to return the - * singleton UnitString object. This is based on the UnitTables singleton - * implementation; see more detail in the UnitTables constructor description. - * - * @return the singleton UnitString object. - */ +SomePromiseArray.prototype._addRejected = function (reason) { + this._values.push(reason); +}; +SomePromiseArray.prototype._addFulfilled = function (value) { + this._values[this._totalResolved++] = value; +}; -exports.UnitString = UnitString; +SomePromiseArray.prototype._canPossiblyFulfill = function () { + return this.length() - this._rejected(); +}; -UnitString.getInstance = function () { - return new UnitString(); +SomePromiseArray.prototype._getRangeError = function (count) { + var message = "Input array must contain at least " + + this._howMany + " items but contains only " + count + " items"; + return new RangeError(message); }; -/* -// Perform the first request for the object, to set the getInstance method. -UnitString.getInstance(); -*/ +SomePromiseArray.prototype._resolveEmptyArray = function () { + this._reject(this._getRangeError(0)); +}; +function some(promises, howMany) { + if ((howMany | 0) !== howMany || howMany < 0) { + return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + var ret = new SomePromiseArray(promises); + var promise = ret.promise(); + ret.setHowMany(howMany); + ret.init(); + return promise; +} -},{"./config.js":9,"./prefixTables.js":13,"./ucumInternalUtils.js":15,"./unit.js":19,"./unitTables.js":21}],21:[function(require,module,exports){ -"use strict"; +Promise.some = function (promises, howMany) { + return some(promises, howMany); +}; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UnitTables = void 0; +Promise.prototype.some = function (howMany) { + return some(this, howMany); +}; -/** - * This class manages Hashtables that provide references to - * defined units. - * - * @author Lee Mericle, based on java version by Gunther Schadow - * - */ -var Ucum = require('./config.js').Ucum; +Promise._SomePromiseArray = SomePromiseArray; +}; -class UnitTablesFactory { - /** - * Constructor. This creates the empty unit tables (hashes) once. After the - * tables are created, it redefines this constructor to throw an error - * stating that the constructor is no longer available and that the - * getInstance function must be used. Here's a description of the first - * and then all subsequent calls to this constructor. - * - * First call to constructor: - * 1. creates OBJECT1 - * 2. initializes attributes of OBJECT1 - * 3. stores reference to OBJECT1.prototype in holdthis local variable - * 4. redefines OBJECT1 as a function that throws an error - * 5. defines the getInstance function (which is also defined outside of - * the class definition - see below). - * - * All subsequent calls to constructor: - * 1. throw error message referring to getInstance - * 2. call getInstance, returns this - which is OBJECT1. - */ - constructor() { - /** - * Tracks units by name - * @type hash - key is the name; - * value is an array of references to the Unit objects - * with the name. More than one unit may have the same - * name, e.g., "second", which is shared by the base unit - * with the code = "s" and the unit with code = "'". - */ - this.unitNames_ = {}; - /** - * Tracks units by code using case-sensitive version. - * - * @type hash - key is the code; - * value is the reference to the Unit object. Codes must - * be unique. - */ +},{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise) { +function PromiseInspection(promise) { + if (promise !== undefined) { + promise = promise._target(); + this._bitField = promise._bitField; + this._settledValueField = promise._isFateSealed() + ? promise._settledValue() : undefined; + } + else { + this._bitField = 0; + this._settledValueField = undefined; + } +} - this.unitCodes_ = {}; - /** - * Keeps track of the order in which units are defined. The order is - * important because unit definitions build on previous definitions. - * - * @type {Array} - */ +PromiseInspection.prototype._settledValue = function() { + return this._settledValueField; +}; - this.codeOrder_ = []; - /** - * Tracks units by unit strings, e.g., cm-1 - * - * @type hash - key is the unit string - * value is an array of unit objects with that ciUnitString. - */ +var value = PromiseInspection.prototype.value = function () { + if (!this.isFulfilled()) { + throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + return this._settledValue(); +}; - this.unitStrings_ = {}; - /** - * Tracks units by Dimension vector - * - * @type hash - key is the dimension vector (not the object, just the - * vector); - * value is an array of references to the Unit objects - * with that vector. More than one unit may have the same - * unit vector, and this can be used to provide a list - * of commensurable units. - */ +var reason = PromiseInspection.prototype.error = +PromiseInspection.prototype.reason = function () { + if (!this.isRejected()) { + throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + } + return this._settledValue(); +}; - this.unitDimensions_ = {}; - /** - * Maps synonyms to units. Not built until first requested. - * - * @type hash - key is the synonym - * value is an array of references to Unit objects that - * include that synonym. - */ +var isFulfilled = PromiseInspection.prototype.isFulfilled = function() { + return (this._bitField & 33554432) !== 0; +}; - this.unitSynonyms_ = {}; - /* - * Holds onto the index of the index of the dimension vector flag for - * the base mass unit (gram). This is set when the base unit (gram) is - * created, and is stored here so that it doesn't have to be found - * over and over again to try to determine whether or not a unit is - * mass-based (for mole<->mass conversions) - * - * @type integer - */ +var isRejected = PromiseInspection.prototype.isRejected = function () { + return (this._bitField & 16777216) !== 0; +}; - this.massDimIndex_ = 0; - } - /** - * Provides the number of unit objects written to the tables, using the - * codes table since codes must be unique. - * - * @returns count of the number of unit objects in the unitCodes_ table. - */ +var isPending = PromiseInspection.prototype.isPending = function () { + return (this._bitField & 50397184) === 0; +}; +var isResolved = PromiseInspection.prototype.isResolved = function () { + return (this._bitField & 50331648) !== 0; +}; - unitsCount() { - return Object.keys(this.unitCodes_).length; - } - /** - * Adds a Unit object to the tables. - * - * @param theUnit the unit to be added - * @returns nothing - * @throws passes on an error if one is thrown by the called functions for - * a problem with the unit code or unit name - */ +PromiseInspection.prototype.isCancelled = function() { + return (this._bitField & 8454144) !== 0; +}; +Promise.prototype.__isCancelled = function() { + return (this._bitField & 65536) === 65536; +}; - addUnit(theUnit) { - let uName = theUnit['name_']; +Promise.prototype._isCancelled = function() { + return this._target().__isCancelled(); +}; - if (uName) { - this.addUnitName(theUnit); - } +Promise.prototype.isCancelled = function() { + return (this._target()._bitField & 8454144) !== 0; +}; - this.addUnitCode(theUnit); - this.addUnitString(theUnit); +Promise.prototype.isPending = function() { + return isPending.call(this._target()); +}; - try { - if (theUnit['dim_'].getProperty('dimVec_')) this.addUnitDimension(theUnit); - } catch (err) {// do nothing - throws error if the property is null - // and that's OK here. - } - } // end addUnit +Promise.prototype.isRejected = function() { + return isRejected.call(this._target()); +}; - /** - * Adds a Unit object to the unitNames_ table. More than one unit - * can have the same name, e.g., the two units with the name "second", - * where the code for one of them is 's' and the code for the other is - * "'". Because of this, an array of unit objects is stored for the - * name. In most cases it will be an array of one object, but this - * clarifies that there may be more than one. - * - * @param theUnit the unit to be added - * @returns nothing - * @throws an error if the unit has no name - */ +Promise.prototype.isFulfilled = function() { + return isFulfilled.call(this._target()); +}; +Promise.prototype.isResolved = function() { + return isResolved.call(this._target()); +}; - addUnitName(theUnit) { - let uName = theUnit['name_']; +Promise.prototype.value = function() { + return value.call(this._target()); +}; - if (uName) { - if (this.unitNames_[uName]) this.unitNames_[uName].push(theUnit);else this.unitNames_[uName] = [theUnit]; - } else throw new Error('UnitTables.addUnitName called for a unit with no name. ' + `Unit code = ${theUnit['csCode_']}.`); - } // end addUnitName +Promise.prototype.reason = function() { + var target = this._target(); + target._unsetRejectionIsUnhandled(); + return reason.call(target); +}; - /** - * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and - * codeOrder_ tables. This also sets the mass dimension index when the - * base mass unit (gram) is read. - * - * @param theUnit the unit to be added - * @returns nothing - * @throws an error if the unitCodes_ table already contains a unit with - * the code - */ +Promise.prototype._value = function() { + return this._settledValue(); +}; +Promise.prototype._reason = function() { + this._unsetRejectionIsUnhandled(); + return this._settledValue(); +}; - addUnitCode(theUnit) { - let uCode = theUnit['csCode_']; +Promise.PromiseInspection = PromiseInspection; +}; - if (uCode) { - if (this.unitCodes_[uCode]) throw new Error(`UnitTables.addUnitCode called, already contains entry for ` + `unit with code = ${uCode}`);else { - this.unitCodes_[uCode] = theUnit; - this.codeOrder_.push(uCode); +},{}],33:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL) { +var util = _dereq_("./util"); +var errorObj = util.errorObj; +var isObject = util.isObject; - if (uCode == 'g') { - let dimVec = theUnit.dim_.dimVec_; - let d = 0; +function tryConvertToPromise(obj, context) { + if (isObject(obj)) { + if (obj instanceof Promise) return obj; + var then = getThen(obj); + if (then === errorObj) { + if (context) context._pushContext(); + var ret = Promise.reject(then.e); + if (context) context._popContext(); + return ret; + } else if (typeof then === "function") { + if (isAnyBluebirdPromise(obj)) { + var ret = new Promise(INTERNAL); + obj._then( + ret._fulfill, + ret._reject, + undefined, + ret, + null + ); + return ret; + } + return doThenable(obj, then, context); + } + } + return obj; +} - for (; d < dimVec.length && dimVec[d] < 1; d++); +function doGetThen(obj) { + return obj.then; +} - this.massDimIndex_ = d; - } - } - } else throw new Error('UnitTables.addUnitCode called for unit that has ' + 'no code.'); - } // end addUnitCode +function getThen(obj) { + try { + return doGetThen(obj); + } catch (e) { + errorObj.e = e; + return errorObj; + } +} - /** - * Adds a unit object to the unitStrings_ table. More than one unit - * can have the same string, so an array of unit objects is stored - * for the string. The unit string is the string that creates a non-base - * unit, e.g., a Newton has a unit code of N, a name of Newton, and a - * unitString of kg.m/s2. - * - * If the unit has no string, nothing is stored and no error is reported. - * - * @param theUnit the unit to be added - * @returns nothing - */ +var hasProp = {}.hasOwnProperty; +function isAnyBluebirdPromise(obj) { + try { + return hasProp.call(obj, "_promise0"); + } catch (e) { + return false; + } +} +function doThenable(x, then, context) { + var promise = new Promise(INTERNAL); + var ret = promise; + if (context) context._pushContext(); + promise._captureStackTrace(); + if (context) context._popContext(); + var synchronous = true; + var result = util.tryCatch(then).call(x, resolve, reject); + synchronous = false; - addUnitString(theUnit) { - let uString = null; - if (Ucum.caseSensitive_ == true) uString = theUnit['csUnitString_'];else uString = theUnit['ciUnitString_']; + if (promise && result === errorObj) { + promise._rejectCallback(result.e, true, true); + promise = null; + } - if (uString) { - let uEntry = { - mag: theUnit['baseFactorStr_'], - unit: theUnit - }; - if (this.unitStrings_[uString]) this.unitStrings_[uString].push(uEntry);else this.unitStrings_[uString] = [uEntry]; + function resolve(value) { + if (!promise) return; + promise._resolveCallback(value); + promise = null; } - } // end addUnitString - /** - * Adds a Unit object to the unitDimensions_ table. More than one unit - * can have the same dimension (commensurable units have the same dimension). - * Because of this, an array of unit objects is stored for the - * dimension. - * - * @param theUnit the unit to be added - * @returns nothing - * @throws an error if the unit has no dimension - */ + function reject(reason) { + if (!promise) return; + promise._rejectCallback(reason, synchronous, true); + promise = null; + } + return ret; +} +return tryConvertToPromise; +}; - addUnitDimension(theUnit) { - let uDim = theUnit['dim_'].getProperty('dimVec_'); +},{"./util":36}],34:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function(Promise, INTERNAL, debug) { +var util = _dereq_("./util"); +var TimeoutError = Promise.TimeoutError; - if (uDim) { - if (this.unitDimensions_[uDim]) this.unitDimensions_[uDim].push(theUnit);else this.unitDimensions_[uDim] = [theUnit]; - } else throw new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' + `Unit code = ${theUnit['csCode_']}.`); - } // end addUnitDimension - - /** - * Builds the unitSynonyms_ table. This is called the first time the - * getUnitsBySynonym method is called. The table/hash contains each word - * (once) from each synonym as well as each word from each unit name. - * - * Hash keys are the words. Hash values are an array of unit codes for - * each unit that has that word in its synonyms or name. - * - * @returns nothing - */ - - - buildUnitSynonyms() { - for (let code in this.unitCodes_) { - let theUnit = this.unitCodes_[code]; - let uSyns = theUnit.synonyms_; // If the current unit has synonyms, process each synonym (often multiples) +function HandleWrapper(handle) { + this.handle = handle; +} - if (uSyns) { - let synsAry = uSyns.split(';'); +HandleWrapper.prototype._resultCancelled = function() { + clearTimeout(this.handle); +}; - if (synsAry[0] !== '') { - let aLen = synsAry.length; +var afterValue = function(value) { return delay(+this).thenReturn(value); }; +var delay = Promise.delay = function (ms, value) { + var ret; + var handle; + if (value !== undefined) { + ret = Promise.resolve(value) + ._then(afterValue, null, null, ms, undefined); + if (debug.cancellation() && value instanceof Promise) { + ret._setOnCancel(value); + } + } else { + ret = new Promise(INTERNAL); + handle = setTimeout(function() { ret._fulfill(); }, +ms); + if (debug.cancellation()) { + ret._setOnCancel(new HandleWrapper(handle)); + } + ret._captureStackTrace(); + } + ret._setAsyncGuaranteed(); + return ret; +}; - for (let a = 0; a < aLen; a++) { - let theSyn = synsAry[a].trim(); // call addSynonymCodes to process each word in the - // synonym, e.g., "British fluid ounces" +Promise.prototype.delay = function (ms) { + return delay(ms, this); +}; - this.addSynonymCodes(code, theSyn); - } // end do for each synonym +var afterTimeout = function (promise, message, parent) { + var err; + if (typeof message !== "string") { + if (message instanceof Error) { + err = message; + } else { + err = new TimeoutError("operation timed out"); + } + } else { + err = new TimeoutError(message); + } + util.markAsOriginatingFromRejection(err); + promise._attachExtraTrace(err); + promise._reject(err); - } // end if the current unit has a non-null synonym attribute + if (parent != null) { + parent.cancel(); + } +}; - } // end if the unit has any synonyms - // Now call addSynonymCodes to process each word in the unit's name +function successClear(value) { + clearTimeout(this.handle); + return value; +} +function failureClear(reason) { + clearTimeout(this.handle); + throw reason; +} - this.addSynonymCodes(code, theUnit.name_); - } // end do for each unit +Promise.prototype.timeout = function (ms, message) { + ms = +ms; + var ret, parent; - } // end buildUnitSynonyms + var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() { + if (ret.isPending()) { + afterTimeout(ret, message, parent); + } + }, ms)); - /** - * Adds unit code entries to the synonyms table for a string containing - * one or more words to be considered as synonyms. - * - * @param theCode the unit code to be connected to the synonyms - * @param theSynonyms a string containing one or more words to be - * considered synonyms (and thus to be added to the unitSynonyms hash). - */ + if (debug.cancellation()) { + parent = this.then(); + ret = parent._then(successClear, failureClear, + undefined, handleWrapper, undefined); + ret._setOnCancel(handleWrapper); + } else { + ret = this._then(successClear, failureClear, + undefined, handleWrapper, undefined); + } + return ret; +}; - addSynonymCodes(theCode, theSynonyms) { - let words = theSynonyms.split(' '); - let wLen = words.length; +}; - for (let w = 0; w < wLen; w++) { - let word = words[w]; // if there is already a synonyms entry for the word, - // get the array of unit codes currently assigned to - // the word and add the code for the current word to - // the synonyms array if it's not already there. +},{"./util":36}],35:[function(_dereq_,module,exports){ +"use strict"; +module.exports = function (Promise, apiRejection, tryConvertToPromise, + createContext, INTERNAL, debug) { + var util = _dereq_("./util"); + var TypeError = _dereq_("./errors").TypeError; + var inherits = _dereq_("./util").inherits; + var errorObj = util.errorObj; + var tryCatch = util.tryCatch; + var NULL = {}; - if (this.unitSynonyms_[word]) { - let synCodes = this.unitSynonyms_[word]; + function thrower(e) { + setTimeout(function(){throw e;}, 0); + } - if (synCodes.indexOf(theCode) === -1) { - this.unitSynonyms_[word].push(theCode); + function castPreservingDisposable(thenable) { + var maybePromise = tryConvertToPromise(thenable); + if (maybePromise !== thenable && + typeof thenable._isDisposable === "function" && + typeof thenable._getDisposer === "function" && + thenable._isDisposable()) { + maybePromise._setDisposable(thenable._getDisposer()); } - } // else there are no synonyms entry for the word. Create a - // synonyms array for the word, setting it to contain the unit code. - else { - this.unitSynonyms_[word] = [theCode]; + return maybePromise; + } + function dispose(resources, inspection) { + var i = 0; + var len = resources.length; + var ret = new Promise(INTERNAL); + function iterator() { + if (i >= len) return ret._fulfill(); + var maybePromise = castPreservingDisposable(resources[i++]); + if (maybePromise instanceof Promise && + maybePromise._isDisposable()) { + try { + maybePromise = tryConvertToPromise( + maybePromise._getDisposer().tryDispose(inspection), + resources.promise); + } catch (e) { + return thrower(e); + } + if (maybePromise instanceof Promise) { + return maybePromise._then(iterator, thrower, + null, null, null); + } + } + iterator(); } - } // end do for each word in the synonyms being processed - - } // end addSynonymCodes + iterator(); + return ret; + } - /** - * Returns a unit object with a case-sensitive code matching the - * uCode parameter, or null if no unit is found with that code. - * - * @param uCode the code of the unit to be returned - * @returns the unit object or null if it is not found - */ + function Disposer(data, promise, context) { + this._data = data; + this._promise = promise; + this._context = context; + } + Disposer.prototype.data = function () { + return this._data; + }; - getUnitByCode(uCode) { - let retUnit = null; + Disposer.prototype.promise = function () { + return this._promise; + }; - if (uCode) { - retUnit = this.unitCodes_[uCode]; - } + Disposer.prototype.resource = function () { + if (this.promise().isFulfilled()) { + return this.promise().value(); + } + return NULL; + }; - return retUnit; - } - /** - * Returns a array of unit objects based on the unit's name. Usually this - * will be an array of one, but there may be more, since unit names are - * not necessarily unique. - * - * @param uName the name of the unit to be returned. If more than one - * unit has the same name and you only want one specific unit, append the - * csCode of the unit you want to the end of the name, separated by the - * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us]. - * @returns null if no unit was found for the specified name OR an array of - * unit objects with the specified name. Normally this will be an array - * of one object. - * @throws an error if no name is provided to search on - */ + Disposer.prototype.tryDispose = function(inspection) { + var resource = this.resource(); + var context = this._context; + if (context !== undefined) context._pushContext(); + var ret = resource !== NULL + ? this.doDispose(resource, inspection) : null; + if (context !== undefined) context._popContext(); + this._promise._unsetDisposable(); + this._data = null; + return ret; + }; + Disposer.isDisposer = function (d) { + return (d != null && + typeof d.resource === "function" && + typeof d.tryDispose === "function"); + }; - getUnitByName(uName) { - if (uName === null || uName === undefined) { - throw new Error('Unable to find unit by name because no name was provided.'); + function FunctionDisposer(fn, promise, context) { + this.constructor$(fn, promise, context); } + inherits(FunctionDisposer, Disposer); - let sepPos = uName.indexOf(Ucum.codeSep_); - let uCode = null; + FunctionDisposer.prototype.doDispose = function (resource, inspection) { + var fn = this.data(); + return fn.call(resource, resource, inspection); + }; - if (sepPos >= 1) { - uCode = uName.substr(sepPos + Ucum.codeSep_.length); - uName = uName.substr(0, sepPos); + function maybeUnwrapDisposer(value) { + if (Disposer.isDisposer(value)) { + this.resources[this.index]._setDisposable(value); + return value.promise(); + } + return value; } - let retUnits = this.unitNames_[uName]; - - if (retUnits) { - let uLen = retUnits.length; + function ResourceList(length) { + this.length = length; + this.promise = null; + this[length-1] = null; + } - if (uCode && uLen > 1) { - let i = 0; + ResourceList.prototype._resultCancelled = function() { + var len = this.length; + for (var i = 0; i < len; ++i) { + var item = this[i]; + if (item instanceof Promise) { + item.cancel(); + } + } + }; - for (; retUnits[i].csCode_ !== uCode && i < uLen; i++); + Promise.using = function () { + var len = arguments.length; + if (len < 2) return apiRejection( + "you must pass at least 2 arguments to Promise.using"); + var fn = arguments[len - 1]; + if (typeof fn !== "function") { + return apiRejection("expecting a function but got " + util.classString(fn)); + } + var input; + var spreadArgs = true; + if (len === 2 && Array.isArray(arguments[0])) { + input = arguments[0]; + len = input.length; + spreadArgs = false; + } else { + input = arguments; + len--; + } + var resources = new ResourceList(len); + for (var i = 0; i < len; ++i) { + var resource = input[i]; + if (Disposer.isDisposer(resource)) { + var disposer = resource; + resource = resource.promise(); + resource._setDisposable(disposer); + } else { + var maybePromise = tryConvertToPromise(resource); + if (maybePromise instanceof Promise) { + resource = + maybePromise._then(maybeUnwrapDisposer, null, null, { + resources: resources, + index: i + }, undefined); + } + } + resources[i] = resource; + } - if (i < uLen) retUnits = [retUnits[i]];else { - retUnits = null; + var reflectedResources = new Array(resources.length); + for (var i = 0; i < reflectedResources.length; ++i) { + reflectedResources[i] = Promise.resolve(resources[i]).reflect(); } - } // end if we need to find both a name and a code - } // end if we got an array of units + var resultPromise = Promise.all(reflectedResources) + .then(function(inspections) { + for (var i = 0; i < inspections.length; ++i) { + var inspection = inspections[i]; + if (inspection.isRejected()) { + errorObj.e = inspection.error(); + return errorObj; + } else if (!inspection.isFulfilled()) { + resultPromise.cancel(); + return; + } + inspections[i] = inspection.value(); + } + promise._pushContext(); + fn = tryCatch(fn); + var ret = spreadArgs + ? fn.apply(undefined, inspections) : fn(inspections); + var promiseCreated = promise._popContext(); + debug.checkForgottenReturns( + ret, promiseCreated, "Promise.using", promise); + return ret; + }); - return retUnits; - } // end getUnitByName + var promise = resultPromise.lastly(function() { + var inspection = new Promise.PromiseInspection(resultPromise); + return dispose(resources, inspection); + }); + resources.promise = promise; + promise._setOnCancel(resources); + return promise; + }; - /** - * Returns an array of unit objects with the specified unit string. - * The array may contain one or more unit reference objects. - * Or none, if no units have a matching unit string (which is not - * considered an error) - * - * @param name the name of the unit to be returned - * @returns the array of unit references or null if none were found - */ + Promise.prototype._setDisposable = function (disposer) { + this._bitField = this._bitField | 131072; + this._disposer = disposer; + }; + Promise.prototype._isDisposable = function () { + return (this._bitField & 131072) > 0; + }; - getUnitByString(uString) { - let retAry = null; + Promise.prototype._getDisposer = function () { + return this._disposer; + }; - if (uString) { - retAry = this.unitStrings_[uString]; - if (retAry === undefined) retAry = null; - } + Promise.prototype._unsetDisposable = function () { + this._bitField = this._bitField & (~131072); + this._disposer = undefined; + }; - return retAry; - } - /** - * Returns a array of unit objects based on the unit's dimension vector. - * - * @param uName the dimension vector of the units to be returned. - * - * @returns null if no unit was found for the specified vector OR an array of - * one or more unit objects with the specified vector. - * @throws an error if no vector is provided to search on - * logs an error to the console if no unit is found - */ + Promise.prototype.disposer = function (fn) { + if (typeof fn === "function") { + return new FunctionDisposer(fn, this, createContext()); + } + throw new TypeError(); + }; +}; - getUnitsByDimension(uDim) { - let unitsArray = null; +},{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){ +"use strict"; +var es5 = _dereq_("./es5"); +var canEvaluate = typeof navigator == "undefined"; - if (uDim === null || uDim === undefined) { - throw new Error('Unable to find unit by because no dimension ' + 'vector was provided.'); +var errorObj = {e: {}}; +var tryCatchTarget; +var globalObject = typeof self !== "undefined" ? self : + typeof window !== "undefined" ? window : + typeof global !== "undefined" ? global : + this !== undefined ? this : null; + +function tryCatcher() { + try { + var target = tryCatchTarget; + tryCatchTarget = null; + return target.apply(this, arguments); + } catch (e) { + errorObj.e = e; + return errorObj; } +} +function tryCatch(fn) { + tryCatchTarget = fn; + return tryCatcher; +} - unitsArray = this.unitDimensions_[uDim]; +var inherits = function(Child, Parent) { + var hasProp = {}.hasOwnProperty; - if (unitsArray === undefined || unitsArray === null) { - console.log(`Unable to find unit with dimension = ${uDim}`); + function T() { + this.constructor = Child; + this.constructor$ = Parent; + for (var propertyName in Parent.prototype) { + if (hasProp.call(Parent.prototype, propertyName) && + propertyName.charAt(propertyName.length-1) !== "$" + ) { + this[propertyName + "$"] = Parent.prototype[propertyName]; + } + } } + T.prototype = Parent.prototype; + Child.prototype = new T(); + return Child.prototype; +}; - return unitsArray; - } // end getUnitsByDimension - - /** - * Returns a array of unit objects that include the specified synonym. - * - * @param uSyn the synonym of the units to be returned. - * - * @returns an object with two of the following three elements: - * 'status' will be error, failed or succeeded - * 'msg' will be included for returns with status = error or failed and - * will explain why the request did not return any units - * 'units' any array of unit objects with the specified synonym will be - * returned for requests with status = succeeded - */ +function isPrimitive(val) { + return val == null || val === true || val === false || + typeof val === "string" || typeof val === "number"; - getUnitBySynonym(uSyn) { - let retObj = {}; - let unitsArray = []; +} - try { - if (uSyn === null || uSyn === undefined) { - retObj['status'] = 'error'; - throw new Error('Unable to find unit by synonym because no synonym ' + 'was provided.'); - } // If this is the first request for a unit by synonym, build the hash map +function isObject(value) { + return typeof value === "function" || + typeof value === "object" && value !== null; +} +function maybeWrapAsError(maybeError) { + if (!isPrimitive(maybeError)) return maybeError; - if (Object.keys(this.unitSynonyms_).length === 0) { - this.buildUnitSynonyms(); - } + return new Error(safeToString(maybeError)); +} - let foundCodes = []; - foundCodes = this.unitSynonyms_[uSyn]; +function withAppended(target, appendee) { + var len = target.length; + var ret = new Array(len + 1); + var i; + for (i = 0; i < len; ++i) { + ret[i] = target[i]; + } + ret[i] = appendee; + return ret; +} - if (foundCodes) { - retObj['status'] = 'succeeded'; - let fLen = foundCodes.length; +function getDataPropertyOrDefault(obj, key, defaultValue) { + if (es5.isES5) { + var desc = Object.getOwnPropertyDescriptor(obj, key); - for (let f = 0; f < fLen; f++) { - unitsArray.push(this.unitCodes_[foundCodes[f]]); + if (desc != null) { + return desc.get == null && desc.set == null + ? desc.value + : defaultValue; } - - retObj['units'] = unitsArray; - } - - if (unitsArray.length === 0) { - retObj['status'] = 'failed'; - retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`; - } - } catch (err) { - retObj['msg'] = err.message; + } else { + return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined; } +} - return retObj; - } // end getUnitBySynonym - - /** - * Gets a list of all unit names in the Unit tables - * - * @returns an array of the unit names - */ +function notEnumerableProp(obj, name, value) { + if (isPrimitive(obj)) return obj; + var descriptor = { + value: value, + configurable: true, + enumerable: false, + writable: true + }; + es5.defineProperty(obj, name, descriptor); + return obj; +} +function thrower(r) { + throw r; +} - getAllUnitNames() { - return Object.keys(this.unitNames_); - } // end getAllUnitNames +var inheritedDataKeys = (function() { + var excludedPrototypes = [ + Array.prototype, + Object.prototype, + Function.prototype + ]; - /** - * Gets a list of all unit names in the tables. Where more than one - * unit has the same name, the unit code, in parentheses, is appended - * to the end of the name. - * - * @returns {Array} - */ + var isExcludedProto = function(val) { + for (var i = 0; i < excludedPrototypes.length; ++i) { + if (excludedPrototypes[i] === val) { + return true; + } + } + return false; + }; + if (es5.isES5) { + var getKeys = Object.getOwnPropertyNames; + return function(obj) { + var ret = []; + var visitedKeys = Object.create(null); + while (obj != null && !isExcludedProto(obj)) { + var keys; + try { + keys = getKeys(obj); + } catch (e) { + return ret; + } + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + if (visitedKeys[key]) continue; + visitedKeys[key] = true; + var desc = Object.getOwnPropertyDescriptor(obj, key); + if (desc != null && desc.get == null && desc.set == null) { + ret.push(key); + } + } + obj = es5.getPrototypeOf(obj); + } + return ret; + }; + } else { + var hasProp = {}.hasOwnProperty; + return function(obj) { + if (isExcludedProto(obj)) return []; + var ret = []; - getUnitNamesList() { - let nameList = []; - let codes = Object.keys(this.unitCodes_); - codes.sort(this.compareCodes); - let uLen = codes.length; + /*jshint forin:false */ + enumeration: for (var key in obj) { + if (hasProp.call(obj, key)) { + ret.push(key); + } else { + for (var i = 0; i < excludedPrototypes.length; ++i) { + if (hasProp.call(excludedPrototypes[i], key)) { + continue enumeration; + } + } + ret.push(key); + } + } + return ret; + }; + } - for (let i = 0; i < uLen; i++) { - nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_; - } // end do for each code +})(); +var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/; +function isClass(fn) { + try { + if (typeof fn === "function") { + var keys = es5.names(fn.prototype); - return nameList; - } - /* - * Returns the mass dimension index - * @returns this.massDimIndex_ - */ + var hasMethods = es5.isES5 && keys.length > 1; + var hasMethodsOtherThanConstructor = keys.length > 0 && + !(keys.length === 1 && keys[0] === "constructor"); + var hasThisAssignmentAndStaticMethods = + thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0; + if (hasMethods || hasMethodsOtherThanConstructor || + hasThisAssignmentAndStaticMethods) { + return true; + } + } + return false; + } catch (e) { + return false; + } +} - getMassDimensionIndex() { - return this.massDimIndex_; - } - /** - * This provides a sort function for unit codes so that sorting ignores - * square brackets and case. - * - * @param a first value - * @param b second value - * @returns -1 if a is should fall before b; otherwise 1. - */ +function toFastProperties(obj) { + /*jshint -W027,-W055,-W031*/ + function FakeConstructor() {} + FakeConstructor.prototype = obj; + var l = 8; + while (l--) new FakeConstructor(); + return obj; + eval(obj); +} +var rident = /^[a-z$_][a-z$_0-9]*$/i; +function isIdentifier(str) { + return rident.test(str); +} - compareCodes(a, b) { - a = a.replace(/[\[\]]/g, ''); - a = a.toLowerCase(); - b = b.replace(/[\[\]]/g, ''); - b = b.toLowerCase(); - return a < b ? -1 : 1; - } - /** - * Gets a list of all unit codes in the Unit tables - * - * @returns an array of the unit names - */ +function filledRange(count, prefix, suffix) { + var ret = new Array(count); + for(var i = 0; i < count; ++i) { + ret[i] = prefix + i + suffix; + } + return ret; +} +function safeToString(obj) { + try { + return obj + ""; + } catch (e) { + return "[no string representation]"; + } +} - getAllUnitCodes() { - return Object.keys(this.unitCodes_); - } // end getAllUnitNames +function isError(obj) { + return obj instanceof Error || + (obj !== null && + typeof obj === "object" && + typeof obj.message === "string" && + typeof obj.name === "string"); +} - /** - * This is used to get all unit objects. Currently it is used - * to get the objects to write to the json ucum definitions file - * that is used to provide prefix and unit definition objects for - * conversions and validations. - * - * @returns an array containing all unit objects, ordered by definition - * order - */ +function markAsOriginatingFromRejection(e) { + try { + notEnumerableProp(e, "isOperational", true); + } + catch(ignore) {} +} +function originatesFromRejection(e) { + if (e == null) return false; + return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) || + e["isOperational"] === true); +} - allUnitsByDef() { - let unitsList = []; - let uLen = this.codeOrder_.length; +function canAttachTrace(obj) { + return isError(obj) && es5.propertyIsWritable(obj, "stack"); +} - for (let u = 0; u < uLen; u++) { - unitsList.push(this.getUnitByCode(this.codeOrder_[u])); +var ensureErrorObject = (function() { + if (!("stack" in new Error())) { + return function(value) { + if (canAttachTrace(value)) return value; + try {throw new Error(safeToString(value));} + catch(err) {return err;} + }; + } else { + return function(value) { + if (canAttachTrace(value)) return value; + return new Error(safeToString(value)); + }; } +})(); - return unitsList; - } // end allUnitsByDef - - /** - * This is used to get all unit objects, ordered by unit name. Currently it - * is used to create a csv list of all units. - * @param sep separator character (or string) to be used to separate each - * column in the output. Optional, defaults to '|' if not specified. - * (Used to use ; but the synonyms use that extensively). Don't use a - * comma or any other punctuation found in the output data. - * @returns a buffer containing all unit objects, ordered by name - * order - */ - +function classString(obj) { + return {}.toString.call(obj); +} - allUnitsByName(cols, sep) { - if (sep === undefined || sep === null) sep = '|'; - let unitBuff = ''; - let unitsList = this.getAllUnitNames(); - let uLen = unitsList.length; - let cLen = cols.length; +function copyDescriptors(from, to, filter) { + var keys = es5.names(from); + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + if (filter(key)) { + try { + es5.defineProperty(to, key, es5.getDescriptor(from, key)); + } catch (ignore) {} + } + } +} - for (let i = 0; i < uLen; i++) { - let nameRecs = this.getUnitByName(unitsList[i]); +var asArray = function(v) { + if (es5.isArray(v)) { + return v; + } + return null; +}; - for (let u = 0; u < nameRecs.length; u++) { - let rec = nameRecs[u]; +if (typeof Symbol !== "undefined" && Symbol.iterator) { + var ArrayFrom = typeof Array.from === "function" ? function(v) { + return Array.from(v); + } : function(v) { + var ret = []; + var it = v[Symbol.iterator](); + var itResult; + while (!((itResult = it.next()).done)) { + ret.push(itResult.value); + } + return ret; + }; - for (let c = 0; c < cLen; c++) { - if (c > 0) unitBuff += sep; + asArray = function(v) { + if (es5.isArray(v)) { + return v; + } else if (v != null && typeof v[Symbol.iterator] === "function") { + return ArrayFrom(v); + } + return null; + }; +} - if (cols[c] === 'dim_') { - if (rec.dim_ !== null && rec.dim_ !== undefined && rec.dim_.dimVec_ instanceof Array) unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';else unitBuff += ''; - } else { - let cbuf = rec[cols[c]]; - if (typeof cbuf === 'string') unitBuff += cbuf.replace(/[\n\r]/g, ' ');else unitBuff += cbuf; - } - } // end do for each column requested +var isNode = typeof process !== "undefined" && + classString(process).toLowerCase() === "[object process]"; +var hasEnvVariables = typeof process !== "undefined" && + typeof process.env !== "undefined"; - unitBuff += '\r\n'; - } // end do for each unit in the unit names array +function env(key) { + return hasEnvVariables ? process.env[key] : undefined; +} +function getNativePromise() { + if (typeof Promise === "function") { + try { + var promise = new Promise(function(){}); + if ({}.toString.call(promise) === "[object Promise]") { + return Promise; + } + } catch (e) {} } +} - return unitBuff; - } // end allUnitsByName +function domainBind(self, cb) { + return self.bind(cb); +} - /** - * This creates a list of all units in the tables. It uses the byCode - * table, and uses the codeOrder_ array to determine the order in which - * the units are listed. - * - * @param doLong boolean indicating how much to output. If true, all data - * from the unit objects is included. If false, only a few major values - * are included. - * @param sep separator character (or string) to be used to separate each - * column in the output. Optional, defaults to '|' if not specified. - * (Used to use ; but the synonyms use that extensively). - * @returns {string} buffer containing all the listings - */ +var ret = { + isClass: isClass, + isIdentifier: isIdentifier, + inheritedDataKeys: inheritedDataKeys, + getDataPropertyOrDefault: getDataPropertyOrDefault, + thrower: thrower, + isArray: es5.isArray, + asArray: asArray, + notEnumerableProp: notEnumerableProp, + isPrimitive: isPrimitive, + isObject: isObject, + isError: isError, + canEvaluate: canEvaluate, + errorObj: errorObj, + tryCatch: tryCatch, + inherits: inherits, + withAppended: withAppended, + maybeWrapAsError: maybeWrapAsError, + toFastProperties: toFastProperties, + filledRange: filledRange, + toString: safeToString, + canAttachTrace: canAttachTrace, + ensureErrorObject: ensureErrorObject, + originatesFromRejection: originatesFromRejection, + markAsOriginatingFromRejection: markAsOriginatingFromRejection, + classString: classString, + copyDescriptors: copyDescriptors, + hasDevTools: typeof chrome !== "undefined" && chrome && + typeof chrome.loadTimes === "function", + isNode: isNode, + hasEnvVariables: hasEnvVariables, + env: env, + global: globalObject, + getNativePromise: getNativePromise, + domainBind: domainBind +}; +ret.isRecentNode = ret.isNode && (function() { + var version = 'v16.13.0'.split(".").map(Number); + return (version[0] === 0 && version[1] > 10) || (version[0] > 0); +})(); +if (ret.isNode) ret.toFastProperties(process); - printUnits(doLong, sep) { - if (doLong === undefined) doLong = false; - if (sep === undefined) sep = '|'; - let codeList = ''; - let uLen = this.codeOrder_.length; - let unitString = 'csCode' + sep; +try {throw new Error(); } catch (e) {ret.lastLineError = e;} +module.exports = ret; - if (doLong) { - unitString += 'ciCode' + sep; - } +},{"./es5":13}]},{},[4])(4) +}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; } +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) +},{"_process":369,"timers":374}],15:[function(require,module,exports){ +(function (global){(function (){ +/** + * Module dependencies. + * @ignore + */ - unitString += 'name' + sep; - if (doLong) unitString += 'isBase' + sep; - unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep + 'value' + sep + 'function' + sep; - if (doLong) unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep + 'source' + sep + 'class' + sep + 'isMetric' + sep + 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep; - unitString += 'comment'; - codeList = unitString + '\n'; +// Test if we're in Node via presence of "global" not absence of "window" +// to support hybrid environments like Electron +if (typeof global !== 'undefined') { + var Buffer = require('buffer').Buffer; // TODO just use global Buffer +} - for (let u = 0; u < uLen; u++) { - let curUnit = this.getUnitByCode(this.codeOrder_[u]); - unitString = this.codeOrder_[u] + sep; +var utils = require('./parser/utils'); - if (doLong) { - unitString += curUnit.getProperty('ciCode_') + sep; - } +/** + * A class representation of the BSON Binary type. + * + * Sub types + * - **BSON.BSON_BINARY_SUBTYPE_DEFAULT**, default BSON type. + * - **BSON.BSON_BINARY_SUBTYPE_FUNCTION**, BSON function type. + * - **BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY**, BSON byte array type. + * - **BSON.BSON_BINARY_SUBTYPE_UUID**, BSON uuid type. + * - **BSON.BSON_BINARY_SUBTYPE_MD5**, BSON md5 type. + * - **BSON.BSON_BINARY_SUBTYPE_USER_DEFINED**, BSON user defined type. + * + * @class + * @param {Buffer} buffer a buffer object containing the binary data. + * @param {Number} [subType] the option binary type. + * @return {Binary} + */ +function Binary(buffer, subType) { + if (!(this instanceof Binary)) return new Binary(buffer, subType); - unitString += curUnit.getProperty('name_') + sep; + if ( + buffer != null && + !(typeof buffer === 'string') && + !Buffer.isBuffer(buffer) && + !(buffer instanceof Uint8Array) && + !Array.isArray(buffer) + ) { + throw new Error('only String, Buffer, Uint8Array or Array accepted'); + } - if (doLong) { - if (curUnit.getProperty('isBase_')) unitString += 'true' + sep;else unitString += 'false' + sep; - } + this._bsontype = 'Binary'; - unitString += curUnit.getProperty('magnitude_') + sep; - let curDim = curUnit.getProperty('dim_'); + if (buffer instanceof Number) { + this.sub_type = buffer; + this.position = 0; + } else { + this.sub_type = subType == null ? BSON_BINARY_SUBTYPE_DEFAULT : subType; + this.position = 0; + } - if (curDim) { - unitString += curDim.dimVec_ + sep; + if (buffer != null && !(buffer instanceof Number)) { + // Only accept Buffer, Uint8Array or Arrays + if (typeof buffer === 'string') { + // Different ways of writing the length of the string for the different types + if (typeof Buffer !== 'undefined') { + this.buffer = utils.toBuffer(buffer); + } else if ( + typeof Uint8Array !== 'undefined' || + Object.prototype.toString.call(buffer) === '[object Array]' + ) { + this.buffer = writeStringToArray(buffer); } else { - unitString += 'null' + sep; - } - - if (curUnit.csUnitString_) unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep;else unitString += 'null' + sep + 'null' + sep; - if (curUnit.cnv_) unitString += curUnit.cnv_ + sep;else unitString += 'null' + sep; - - if (doLong) { - unitString += curUnit.getProperty('property_') + sep + curUnit.getProperty('printSymbol_') + sep + curUnit.getProperty('synonyms_') + sep + curUnit.getProperty('source_') + sep + curUnit.getProperty('class_') + sep + curUnit.getProperty('isMetric_') + sep + curUnit.getProperty('variable_') + sep + curUnit.getProperty('isSpecial_') + sep + curUnit.getProperty('isArbitrary_') + sep; + throw new Error('only String, Buffer, Uint8Array or Array accepted'); } - - if (curUnit.defError_) unitString += 'problem parsing this one, deferred to later.'; - codeList += unitString + '\n'; + } else { + this.buffer = buffer; } - - return codeList; - } - -} // end UnitTablesFactory -// Create a singleton instance and (to preserve the existing API) an object that -// provides that instance via getInstance(). - - -var unitTablesInstance = new UnitTablesFactory(); -const UnitTables = { - getInstance: function () { - return unitTablesInstance; + this.position = buffer.length; + } else { + if (typeof Buffer !== 'undefined') { + this.buffer = utils.allocBuffer(Binary.BUFFER_SIZE); + } else if (typeof Uint8Array !== 'undefined') { + this.buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE)); + } else { + this.buffer = new Array(Binary.BUFFER_SIZE); + } + // Set position to start of buffer + this.position = 0; } -}; -exports.UnitTables = UnitTables; - - -},{"./config.js":9}],22:[function(require,module,exports){ -(function (global){(function (){ -'use strict'; - -var objectAssign = require('object-assign'); - -// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js -// original notice: +} -/*! - * The buffer module from node.js, for the browser. +/** + * Updates this binary with byte_value. * - * @author Feross Aboukhadijeh - * @license MIT + * @method + * @param {string} byte_value a single byte we wish to write. */ -function compare(a, b) { - if (a === b) { - return 0; - } - - var x = a.length; - var y = b.length; - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; - } - } +Binary.prototype.put = function put(byte_value) { + // If it's a string and a has more than one character throw an error + if (byte_value['length'] != null && typeof byte_value !== 'number' && byte_value.length !== 1) + throw new Error('only accepts single character String, Uint8Array or Array'); + if ((typeof byte_value !== 'number' && byte_value < 0) || byte_value > 255) + throw new Error('only accepts number in a valid unsigned byte range 0-255'); - if (x < y) { - return -1; - } - if (y < x) { - return 1; - } - return 0; -} -function isBuffer(b) { - if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { - return global.Buffer.isBuffer(b); + // Decode the byte value once + var decoded_byte = null; + if (typeof byte_value === 'string') { + decoded_byte = byte_value.charCodeAt(0); + } else if (byte_value['length'] != null) { + decoded_byte = byte_value[0]; + } else { + decoded_byte = byte_value; } - return !!(b != null && b._isBuffer); -} -// based on node assert, original notice: -// NB: The URL to the CommonJS spec is kept just for tradition. -// node-assert has evolved a lot since then, both in API and behavior. + if (this.buffer.length > this.position) { + this.buffer[this.position++] = decoded_byte; + } else { + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { + // Create additional overflow buffer + var buffer = utils.allocBuffer(Binary.BUFFER_SIZE + this.buffer.length); + // Combine the two buffers together + this.buffer.copy(buffer, 0, 0, this.buffer.length); + this.buffer = buffer; + this.buffer[this.position++] = decoded_byte; + } else { + buffer = null; + // Create a new buffer (typed or normal array) + if (Object.prototype.toString.call(this.buffer) === '[object Uint8Array]') { + buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE + this.buffer.length)); + } else { + buffer = new Array(Binary.BUFFER_SIZE + this.buffer.length); + } -// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 -// -// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! -// -// Originally from narwhal.js (http://narwhaljs.org) -// Copyright (c) 2009 Thomas Robinson <280north.com> -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + // We need to copy all the content to the new array + for (var i = 0; i < this.buffer.length; i++) { + buffer[i] = this.buffer[i]; + } -var util = require('util/'); -var hasOwn = Object.prototype.hasOwnProperty; -var pSlice = Array.prototype.slice; -var functionsHaveNames = (function () { - return function foo() {}.name === 'foo'; -}()); -function pToString (obj) { - return Object.prototype.toString.call(obj); -} -function isView(arrbuf) { - if (isBuffer(arrbuf)) { - return false; - } - if (typeof global.ArrayBuffer !== 'function') { - return false; - } - if (typeof ArrayBuffer.isView === 'function') { - return ArrayBuffer.isView(arrbuf); - } - if (!arrbuf) { - return false; - } - if (arrbuf instanceof DataView) { - return true; - } - if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { - return true; + // Reassign the buffer + this.buffer = buffer; + // Write the byte + this.buffer[this.position++] = decoded_byte; + } } - return false; -} -// 1. The assert module provides functions that throw -// AssertionError's when particular conditions are not met. The -// assert module must conform to the following interface. +}; -var assert = module.exports = ok; +/** + * Writes a buffer or string to the binary. + * + * @method + * @param {(Buffer|string)} string a string or buffer to be written to the Binary BSON object. + * @param {number} offset specify the binary of where to write the content. + * @return {null} + */ +Binary.prototype.write = function write(string, offset) { + offset = typeof offset === 'number' ? offset : this.position; -// 2. The AssertionError is defined in assert. -// new assert.AssertionError({ message: message, -// actual: actual, -// expected: expected }) + // If the buffer is to small let's extend the buffer + if (this.buffer.length < offset + string.length) { + var buffer = null; + // If we are in node.js + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { + buffer = utils.allocBuffer(this.buffer.length + string.length); + this.buffer.copy(buffer, 0, 0, this.buffer.length); + } else if (Object.prototype.toString.call(this.buffer) === '[object Uint8Array]') { + // Create a new buffer + buffer = new Uint8Array(new ArrayBuffer(this.buffer.length + string.length)); + // Copy the content + for (var i = 0; i < this.position; i++) { + buffer[i] = this.buffer[i]; + } + } -var regex = /\s*function\s+([^\(\s]*)\s*/; -// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js -function getName(func) { - if (!util.isFunction(func)) { - return; - } - if (functionsHaveNames) { - return func.name; - } - var str = func.toString(); - var match = str.match(regex); - return match && match[1]; -} -assert.AssertionError = function AssertionError(options) { - this.name = 'AssertionError'; - this.actual = options.actual; - this.expected = options.expected; - this.operator = options.operator; - if (options.message) { - this.message = options.message; - this.generatedMessage = false; - } else { - this.message = getMessage(this); - this.generatedMessage = true; + // Assign the new buffer + this.buffer = buffer; } - var stackStartFunction = options.stackStartFunction || fail; - if (Error.captureStackTrace) { - Error.captureStackTrace(this, stackStartFunction); - } else { - // non v8 browsers so we can have a stacktrace - var err = new Error(); - if (err.stack) { - var out = err.stack; - // try to strip useless frames - var fn_name = getName(stackStartFunction); - var idx = out.indexOf('\n' + fn_name); - if (idx >= 0) { - // once we have located the function frame - // we need to strip out everything before it (and its line) - var next_line = out.indexOf('\n', idx + 1); - out = out.substring(next_line + 1); - } + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(string) && Buffer.isBuffer(this.buffer)) { + string.copy(this.buffer, offset, 0, string.length); + this.position = offset + string.length > this.position ? offset + string.length : this.position; + // offset = string.length + } else if ( + typeof Buffer !== 'undefined' && + typeof string === 'string' && + Buffer.isBuffer(this.buffer) + ) { + this.buffer.write(string, offset, 'binary'); + this.position = offset + string.length > this.position ? offset + string.length : this.position; + // offset = string.length; + } else if ( + Object.prototype.toString.call(string) === '[object Uint8Array]' || + (Object.prototype.toString.call(string) === '[object Array]' && typeof string !== 'string') + ) { + for (i = 0; i < string.length; i++) { + this.buffer[offset++] = string[i]; + } - this.stack = out; + this.position = offset > this.position ? offset : this.position; + } else if (typeof string === 'string') { + for (i = 0; i < string.length; i++) { + this.buffer[offset++] = string.charCodeAt(i); } + + this.position = offset > this.position ? offset : this.position; } }; -// assert.AssertionError instanceof Error -util.inherits(assert.AssertionError, Error); +/** + * Reads **length** bytes starting at **position**. + * + * @method + * @param {number} position read from the given position in the Binary. + * @param {number} length the number of bytes to read. + * @return {Buffer} + */ +Binary.prototype.read = function read(position, length) { + length = length && length > 0 ? length : this.position; -function truncate(s, n) { - if (typeof s === 'string') { - return s.length < n ? s : s.slice(0, n); + // Let's return the data based on the type we have + if (this.buffer['slice']) { + return this.buffer.slice(position, position + length); } else { - return s; - } -} -function inspect(something) { - if (functionsHaveNames || !util.isFunction(something)) { - return util.inspect(something); + // Create a buffer to keep the result + var buffer = + typeof Uint8Array !== 'undefined' + ? new Uint8Array(new ArrayBuffer(length)) + : new Array(length); + for (var i = 0; i < length; i++) { + buffer[i] = this.buffer[position++]; + } } - var rawname = getName(something); - var name = rawname ? ': ' + rawname : ''; - return '[Function' + name + ']'; -} -function getMessage(self) { - return truncate(inspect(self.actual), 128) + ' ' + - self.operator + ' ' + - truncate(inspect(self.expected), 128); -} - -// At present only the three keys mentioned above are used and -// understood by the spec. Implementations or sub modules can pass -// other keys to the AssertionError's constructor - they will be -// ignored. - -// 3. All of the following functions must throw an AssertionError -// when a corresponding condition is not met, with a message that -// may be undefined if not provided. All assertion methods provide -// both the actual and expected values to the assertion error for -// display purposes. - -function fail(actual, expected, message, operator, stackStartFunction) { - throw new assert.AssertionError({ - message: message, - actual: actual, - expected: expected, - operator: operator, - stackStartFunction: stackStartFunction - }); -} - -// EXTENSION! allows for well behaved errors defined elsewhere. -assert.fail = fail; + // Return the buffer + return buffer; +}; -// 4. Pure assertion tests whether a value is truthy, as determined -// by !!guard. -// assert.ok(guard, message_opt); -// This statement is equivalent to assert.equal(true, !!guard, -// message_opt);. To test strictly for the value true, use -// assert.strictEqual(true, guard, message_opt);. +/** + * Returns the value of this binary as a string. + * + * @method + * @return {string} + */ +Binary.prototype.value = function value(asRaw) { + asRaw = asRaw == null ? false : asRaw; -function ok(value, message) { - if (!value) fail(value, true, message, '==', assert.ok); -} -assert.ok = ok; + // Optimize to serialize for the situation where the data == size of buffer + if ( + asRaw && + typeof Buffer !== 'undefined' && + Buffer.isBuffer(this.buffer) && + this.buffer.length === this.position + ) + return this.buffer; -// 5. The equality assertion tests shallow, coercive equality with -// ==. -// assert.equal(actual, expected, message_opt); + // If it's a node.js buffer object + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { + return asRaw + ? this.buffer.slice(0, this.position) + : this.buffer.toString('binary', 0, this.position); + } else { + if (asRaw) { + // we support the slice command use it + if (this.buffer['slice'] != null) { + return this.buffer.slice(0, this.position); + } else { + // Create a new buffer to copy content to + var newBuffer = + Object.prototype.toString.call(this.buffer) === '[object Uint8Array]' + ? new Uint8Array(new ArrayBuffer(this.position)) + : new Array(this.position); + // Copy content + for (var i = 0; i < this.position; i++) { + newBuffer[i] = this.buffer[i]; + } + // Return the buffer + return newBuffer; + } + } else { + return convertArraytoUtf8BinaryString(this.buffer, 0, this.position); + } + } +}; -assert.equal = function equal(actual, expected, message) { - if (actual != expected) fail(actual, expected, message, '==', assert.equal); +/** + * Length. + * + * @method + * @return {number} the length of the binary. + */ +Binary.prototype.length = function length() { + return this.position; }; -// 6. The non-equality assertion tests for whether two objects are not equal -// with != assert.notEqual(actual, expected, message_opt); +/** + * @ignore + */ +Binary.prototype.toJSON = function() { + return this.buffer != null ? this.buffer.toString('base64') : ''; +}; -assert.notEqual = function notEqual(actual, expected, message) { - if (actual == expected) { - fail(actual, expected, message, '!=', assert.notEqual); - } +/** + * @ignore + */ +Binary.prototype.toString = function(format) { + return this.buffer != null ? this.buffer.slice(0, this.position).toString(format) : ''; }; -// 7. The equivalence assertion tests a deep equality relation. -// assert.deepEqual(actual, expected, message_opt); +/** + * Binary default subtype + * @ignore + */ +var BSON_BINARY_SUBTYPE_DEFAULT = 0; -assert.deepEqual = function deepEqual(actual, expected, message) { - if (!_deepEqual(actual, expected, false)) { - fail(actual, expected, message, 'deepEqual', assert.deepEqual); +/** + * @ignore + */ +var writeStringToArray = function(data) { + // Create a buffer + var buffer = + typeof Uint8Array !== 'undefined' + ? new Uint8Array(new ArrayBuffer(data.length)) + : new Array(data.length); + // Write the content to the buffer + for (var i = 0; i < data.length; i++) { + buffer[i] = data.charCodeAt(i); } + // Write the string to the buffer + return buffer; }; -assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { - if (!_deepEqual(actual, expected, true)) { - fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); +/** + * Convert Array ot Uint8Array to Binary String + * + * @ignore + */ +var convertArraytoUtf8BinaryString = function(byteArray, startIndex, endIndex) { + var result = ''; + for (var i = startIndex; i < endIndex; i++) { + result = result + String.fromCharCode(byteArray[i]); } + return result; }; -function _deepEqual(actual, expected, strict, memos) { - // 7.1. All identical values are equivalent, as determined by ===. - if (actual === expected) { - return true; - } else if (isBuffer(actual) && isBuffer(expected)) { - return compare(actual, expected) === 0; +Binary.BUFFER_SIZE = 256; - // 7.2. If the expected value is a Date object, the actual value is - // equivalent if it is also a Date object that refers to the same time. - } else if (util.isDate(actual) && util.isDate(expected)) { - return actual.getTime() === expected.getTime(); +/** + * Default BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_DEFAULT = 0; +/** + * Function BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_FUNCTION = 1; +/** + * Byte Array BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_BYTE_ARRAY = 2; +/** + * OLD UUID BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_UUID_OLD = 3; +/** + * UUID BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_UUID = 4; +/** + * MD5 BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_MD5 = 5; +/** + * User BSON type + * + * @classconstant SUBTYPE_DEFAULT + **/ +Binary.SUBTYPE_USER_DEFINED = 128; - // 7.3 If the expected value is a RegExp object, the actual value is - // equivalent if it is also a RegExp object with the same source and - // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). - } else if (util.isRegExp(actual) && util.isRegExp(expected)) { - return actual.source === expected.source && - actual.global === expected.global && - actual.multiline === expected.multiline && - actual.lastIndex === expected.lastIndex && - actual.ignoreCase === expected.ignoreCase; - - // 7.4. Other pairs that do not both pass typeof value == 'object', - // equivalence is determined by ==. - } else if ((actual === null || typeof actual !== 'object') && - (expected === null || typeof expected !== 'object')) { - return strict ? actual === expected : actual == expected; +/** + * Expose. + */ +module.exports = Binary; +module.exports.Binary = Binary; - // If both values are instances of typed arrays, wrap their underlying - // ArrayBuffers in a Buffer each to increase performance - // This optimization requires the arrays to have the same type as checked by - // Object.prototype.toString (aka pToString). Never perform binary - // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their - // bit patterns are not identical. - } else if (isView(actual) && isView(expected) && - pToString(actual) === pToString(expected) && - !(actual instanceof Float32Array || - actual instanceof Float64Array)) { - return compare(new Uint8Array(actual.buffer), - new Uint8Array(expected.buffer)) === 0; +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./parser/utils":31,"buffer":35}],16:[function(require,module,exports){ +'use strict'; - // 7.5 For all other Object pairs, including Array objects, equivalence is - // determined by having the same number of owned properties (as verified - // with Object.prototype.hasOwnProperty.call), the same set of keys - // (although not necessarily the same order), equivalent values for every - // corresponding key, and an identical 'prototype' property. Note: this - // accounts for both named and indexed properties on Arrays. - } else if (isBuffer(actual) !== isBuffer(expected)) { - return false; - } else { - memos = memos || {actual: [], expected: []}; +var Map = require('./map'), + Long = require('./long'), + Double = require('./double'), + Timestamp = require('./timestamp'), + ObjectID = require('./objectid'), + BSONRegExp = require('./regexp'), + Symbol = require('./symbol'), + Int32 = require('./int_32'), + Code = require('./code'), + Decimal128 = require('./decimal128'), + MinKey = require('./min_key'), + MaxKey = require('./max_key'), + DBRef = require('./db_ref'), + Binary = require('./binary'); - var actualIndex = memos.actual.indexOf(actual); - if (actualIndex !== -1) { - if (actualIndex === memos.expected.indexOf(expected)) { - return true; - } - } +// Parts of the parser +var deserialize = require('./parser/deserializer'), + serializer = require('./parser/serializer'), + calculateObjectSize = require('./parser/calculate_size'), + utils = require('./parser/utils'); - memos.actual.push(actual); - memos.expected.push(expected); +/** + * @ignore + * @api private + */ +// Default Max Size +var MAXSIZE = 1024 * 1024 * 17; - return objEquiv(actual, expected, strict, memos); - } -} +// Current Internal Temporary Serialization Buffer +var buffer = utils.allocBuffer(MAXSIZE); -function isArguments(object) { - return Object.prototype.toString.call(object) == '[object Arguments]'; -} +var BSON = function() {}; -function objEquiv(a, b, strict, actualVisitedObjects) { - if (a === null || a === undefined || b === null || b === undefined) - return false; - // if one is a primitive, the other must be same - if (util.isPrimitive(a) || util.isPrimitive(b)) - return a === b; - if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) - return false; - var aIsArgs = isArguments(a); - var bIsArgs = isArguments(b); - if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) - return false; - if (aIsArgs) { - a = pSlice.call(a); - b = pSlice.call(b); - return _deepEqual(a, b, strict); - } - var ka = objectKeys(a); - var kb = objectKeys(b); - var key, i; - // having the same number of owned properties (keys incorporates - // hasOwnProperty) - if (ka.length !== kb.length) - return false; - //the same set of keys (although not necessarily the same order), - ka.sort(); - kb.sort(); - //~~~cheap key test - for (i = ka.length - 1; i >= 0; i--) { - if (ka[i] !== kb[i]) - return false; - } - //equivalent values for every corresponding key, and - //~~~possibly expensive deep test - for (i = ka.length - 1; i >= 0; i--) { - key = ka[i]; - if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) - return false; +/** + * Serialize a Javascript object. + * + * @param {Object} object the Javascript object to serialize. + * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. + * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. + * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. + * @param {Number} [options.minInternalBufferSize=1024*1024*17] minimum size of the internal temporary serialization buffer **(default:1024*1024*17)**. + * @return {Buffer} returns the Buffer object containing the serialized object. + * @api public + */ +BSON.prototype.serialize = function serialize(object, options) { + options = options || {}; + // Unpack the options + var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; + var serializeFunctions = + typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; + var ignoreUndefined = + typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; + var minInternalBufferSize = + typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; + + // Resize the internal serialization buffer if needed + if (buffer.length < minInternalBufferSize) { + buffer = utils.allocBuffer(minInternalBufferSize); } - return true; -} - -// 8. The non-equivalence assertion tests for any deep inequality. -// assert.notDeepEqual(actual, expected, message_opt); -assert.notDeepEqual = function notDeepEqual(actual, expected, message) { - if (_deepEqual(actual, expected, false)) { - fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); - } + // Attempt to serialize + var serializationIndex = serializer( + buffer, + object, + checkKeys, + 0, + 0, + serializeFunctions, + ignoreUndefined, + [] + ); + // Create the final buffer + var finishedBuffer = utils.allocBuffer(serializationIndex); + // Copy into the finished buffer + buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length); + // Return the buffer + return finishedBuffer; }; -assert.notDeepStrictEqual = notDeepStrictEqual; -function notDeepStrictEqual(actual, expected, message) { - if (_deepEqual(actual, expected, true)) { - fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); - } -} - +/** + * Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization. + * + * @param {Object} object the Javascript object to serialize. + * @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. + * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. + * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. + * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. + * @param {Number} [options.index] the index in the buffer where we wish to start serializing into. + * @return {Number} returns the index pointing to the last written byte in the buffer. + * @api public + */ +BSON.prototype.serializeWithBufferAndIndex = function(object, finalBuffer, options) { + options = options || {}; + // Unpack the options + var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; + var serializeFunctions = + typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; + var ignoreUndefined = + typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; + var startIndex = typeof options.index === 'number' ? options.index : 0; -// 9. The strict equality assertion tests strict equality, as determined by ===. -// assert.strictEqual(actual, expected, message_opt); + // Attempt to serialize + var serializationIndex = serializer( + finalBuffer, + object, + checkKeys, + startIndex || 0, + 0, + serializeFunctions, + ignoreUndefined + ); -assert.strictEqual = function strictEqual(actual, expected, message) { - if (actual !== expected) { - fail(actual, expected, message, '===', assert.strictEqual); - } + // Return the index + return serializationIndex - 1; }; -// 10. The strict non-equality assertion tests for strict inequality, as -// determined by !==. assert.notStrictEqual(actual, expected, message_opt); - -assert.notStrictEqual = function notStrictEqual(actual, expected, message) { - if (actual === expected) { - fail(actual, expected, message, '!==', assert.notStrictEqual); - } +/** + * Deserialize data as BSON. + * + * @param {Buffer} buffer the buffer containing the serialized set of BSON documents. + * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. + * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. + * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. + * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits + * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. + * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. + * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. + * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. + * @return {Object} returns the deserialized Javascript Object. + * @api public + */ +BSON.prototype.deserialize = function(buffer, options) { + return deserialize(buffer, options); }; -function expectedException(actual, expected) { - if (!actual || !expected) { - return false; - } - - if (Object.prototype.toString.call(expected) == '[object RegExp]') { - return expected.test(actual); - } - - try { - if (actual instanceof expected) { - return true; - } - } catch (e) { - // Ignore. The instanceof check doesn't work for arrow functions. - } +/** + * Calculate the bson size for a passed in Javascript object. + * + * @param {Object} object the Javascript object to calculate the BSON byte size for. + * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. + * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. + * @return {Number} returns the number of bytes the BSON object will take up. + * @api public + */ +BSON.prototype.calculateObjectSize = function(object, options) { + options = options || {}; - if (Error.isPrototypeOf(expected)) { - return false; - } + var serializeFunctions = + typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; + var ignoreUndefined = + typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; - return expected.call({}, actual) === true; -} + return calculateObjectSize(object, serializeFunctions, ignoreUndefined); +}; -function _tryBlock(block) { - var error; - try { - block(); - } catch (e) { - error = e; +/** + * Deserialize stream data as BSON documents. + * + * @param {Buffer} data the buffer containing the serialized set of BSON documents. + * @param {Number} startIndex the start index in the data Buffer where the deserialization is to start. + * @param {Number} numberOfDocuments number of documents to deserialize. + * @param {Array} documents an array where to store the deserialized documents. + * @param {Number} docStartIndex the index in the documents array from where to start inserting documents. + * @param {Object} [options] additional options used for the deserialization. + * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. + * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. + * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. + * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits + * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. + * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. + * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. + * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. + * @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents. + * @api public + */ +BSON.prototype.deserializeStream = function( + data, + startIndex, + numberOfDocuments, + documents, + docStartIndex, + options +) { + options = options != null ? options : {}; + var index = startIndex; + // Loop over all documents + for (var i = 0; i < numberOfDocuments; i++) { + // Find size of the document + var size = + data[index] | (data[index + 1] << 8) | (data[index + 2] << 16) | (data[index + 3] << 24); + // Update options with index + options['index'] = index; + // Parse the document at this point + documents[docStartIndex + i] = this.deserialize(data, options); + // Adjust index by the document size + index = index + size; } - return error; -} -function _throws(shouldThrow, block, expected, message) { - var actual; - - if (typeof block !== 'function') { - throw new TypeError('"block" argument must be a function'); - } + // Return object containing end index of parsing and list of documents + return index; +}; - if (typeof expected === 'string') { - message = expected; - expected = null; - } +/** + * @ignore + * @api private + */ +// BSON MAX VALUES +BSON.BSON_INT32_MAX = 0x7fffffff; +BSON.BSON_INT32_MIN = -0x80000000; - actual = _tryBlock(block); +BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; +BSON.BSON_INT64_MIN = -Math.pow(2, 63); - message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + - (message ? ' ' + message : '.'); +// JS MAX PRECISE VALUES +BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. +BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. - if (shouldThrow && !actual) { - fail(actual, expected, 'Missing expected exception' + message); - } +// Internal long versions +// var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. +// var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. - var userProvidedMessage = typeof message === 'string'; - var isUnwantedException = !shouldThrow && util.isError(actual); - var isUnexpectedException = !shouldThrow && actual && !expected; +/** + * Number BSON Type + * + * @classconstant BSON_DATA_NUMBER + **/ +BSON.BSON_DATA_NUMBER = 1; +/** + * String BSON Type + * + * @classconstant BSON_DATA_STRING + **/ +BSON.BSON_DATA_STRING = 2; +/** + * Object BSON Type + * + * @classconstant BSON_DATA_OBJECT + **/ +BSON.BSON_DATA_OBJECT = 3; +/** + * Array BSON Type + * + * @classconstant BSON_DATA_ARRAY + **/ +BSON.BSON_DATA_ARRAY = 4; +/** + * Binary BSON Type + * + * @classconstant BSON_DATA_BINARY + **/ +BSON.BSON_DATA_BINARY = 5; +/** + * ObjectID BSON Type + * + * @classconstant BSON_DATA_OID + **/ +BSON.BSON_DATA_OID = 7; +/** + * Boolean BSON Type + * + * @classconstant BSON_DATA_BOOLEAN + **/ +BSON.BSON_DATA_BOOLEAN = 8; +/** + * Date BSON Type + * + * @classconstant BSON_DATA_DATE + **/ +BSON.BSON_DATA_DATE = 9; +/** + * null BSON Type + * + * @classconstant BSON_DATA_NULL + **/ +BSON.BSON_DATA_NULL = 10; +/** + * RegExp BSON Type + * + * @classconstant BSON_DATA_REGEXP + **/ +BSON.BSON_DATA_REGEXP = 11; +/** + * Code BSON Type + * + * @classconstant BSON_DATA_CODE + **/ +BSON.BSON_DATA_CODE = 13; +/** + * Symbol BSON Type + * + * @classconstant BSON_DATA_SYMBOL + **/ +BSON.BSON_DATA_SYMBOL = 14; +/** + * Code with Scope BSON Type + * + * @classconstant BSON_DATA_CODE_W_SCOPE + **/ +BSON.BSON_DATA_CODE_W_SCOPE = 15; +/** + * 32 bit Integer BSON Type + * + * @classconstant BSON_DATA_INT + **/ +BSON.BSON_DATA_INT = 16; +/** + * Timestamp BSON Type + * + * @classconstant BSON_DATA_TIMESTAMP + **/ +BSON.BSON_DATA_TIMESTAMP = 17; +/** + * Long BSON Type + * + * @classconstant BSON_DATA_LONG + **/ +BSON.BSON_DATA_LONG = 18; +/** + * MinKey BSON Type + * + * @classconstant BSON_DATA_MIN_KEY + **/ +BSON.BSON_DATA_MIN_KEY = 0xff; +/** + * MaxKey BSON Type + * + * @classconstant BSON_DATA_MAX_KEY + **/ +BSON.BSON_DATA_MAX_KEY = 0x7f; - if ((isUnwantedException && - userProvidedMessage && - expectedException(actual, expected)) || - isUnexpectedException) { - fail(actual, expected, 'Got unwanted exception' + message); - } +/** + * Binary Default Type + * + * @classconstant BSON_BINARY_SUBTYPE_DEFAULT + **/ +BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; +/** + * Binary Function Type + * + * @classconstant BSON_BINARY_SUBTYPE_FUNCTION + **/ +BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; +/** + * Binary Byte Array Type + * + * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY + **/ +BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; +/** + * Binary UUID Type + * + * @classconstant BSON_BINARY_SUBTYPE_UUID + **/ +BSON.BSON_BINARY_SUBTYPE_UUID = 3; +/** + * Binary MD5 Type + * + * @classconstant BSON_BINARY_SUBTYPE_MD5 + **/ +BSON.BSON_BINARY_SUBTYPE_MD5 = 4; +/** + * Binary User Defined Type + * + * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED + **/ +BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; - if ((shouldThrow && actual && expected && - !expectedException(actual, expected)) || (!shouldThrow && actual)) { - throw actual; - } -} - -// 11. Expected to throw an error: -// assert.throws(block, Error_opt, message_opt); +// Return BSON +module.exports = BSON; +module.exports.Code = Code; +module.exports.Map = Map; +module.exports.Symbol = Symbol; +module.exports.BSON = BSON; +module.exports.DBRef = DBRef; +module.exports.Binary = Binary; +module.exports.ObjectID = ObjectID; +module.exports.Long = Long; +module.exports.Timestamp = Timestamp; +module.exports.Double = Double; +module.exports.Int32 = Int32; +module.exports.MinKey = MinKey; +module.exports.MaxKey = MaxKey; +module.exports.BSONRegExp = BSONRegExp; +module.exports.Decimal128 = Decimal128; -assert.throws = function(block, /*optional*/error, /*optional*/message) { - _throws(true, block, error, message); +},{"./binary":15,"./code":17,"./db_ref":18,"./decimal128":19,"./double":20,"./int_32":22,"./long":23,"./map":24,"./max_key":25,"./min_key":26,"./objectid":27,"./parser/calculate_size":28,"./parser/deserializer":29,"./parser/serializer":30,"./parser/utils":31,"./regexp":32,"./symbol":33,"./timestamp":34}],17:[function(require,module,exports){ +/** + * A class representation of the BSON Code type. + * + * @class + * @param {(string|function)} code a string or function. + * @param {Object} [scope] an optional scope for the function. + * @return {Code} + */ +var Code = function Code(code, scope) { + if (!(this instanceof Code)) return new Code(code, scope); + this._bsontype = 'Code'; + this.code = code; + this.scope = scope; }; -// EXTENSION! This is annoying to write outside this module. -assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { - _throws(false, block, error, message); +/** + * @ignore + */ +Code.prototype.toJSON = function() { + return { scope: this.scope, code: this.code }; }; -assert.ifError = function(err) { if (err) throw err; }; +module.exports = Code; +module.exports.Code = Code; -// Expose a strict only variant of assert -function strict(value, message) { - if (!value) fail(value, true, message, '==', strict); +},{}],18:[function(require,module,exports){ +/** + * A class representation of the BSON DBRef type. + * + * @class + * @param {string} namespace the collection name. + * @param {ObjectID} oid the reference ObjectID. + * @param {string} [db] optional db name, if omitted the reference is local to the current db. + * @return {DBRef} + */ +function DBRef(namespace, oid, db) { + if (!(this instanceof DBRef)) return new DBRef(namespace, oid, db); + + this._bsontype = 'DBRef'; + this.namespace = namespace; + this.oid = oid; + this.db = db; } -assert.strict = objectAssign(strict, assert, { - equal: assert.strictEqual, - deepEqual: assert.deepStrictEqual, - notEqual: assert.notStrictEqual, - notDeepEqual: assert.notDeepStrictEqual -}); -assert.strict.strict = assert.strict; -var objectKeys = Object.keys || function (obj) { - var keys = []; - for (var key in obj) { - if (hasOwn.call(obj, key)) keys.push(key); - } - return keys; +/** + * @ignore + * @api private + */ +DBRef.prototype.toJSON = function() { + return { + $ref: this.namespace, + $id: this.oid, + $db: this.db == null ? '' : this.db + }; }; -}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"object-assign":368,"util/":25}],23:[function(require,module,exports){ -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }); - }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } -} +module.exports = DBRef; +module.exports.DBRef = DBRef; -},{}],24:[function(require,module,exports){ -module.exports = function isBuffer(arg) { - return arg && typeof arg === 'object' - && typeof arg.copy === 'function' - && typeof arg.fill === 'function' - && typeof arg.readUInt8 === 'function'; -} -},{}],25:[function(require,module,exports){ -(function (process,global){(function (){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +},{}],19:[function(require,module,exports){ +'use strict'; -var formatRegExp = /%[sdj%]/g; -exports.format = function(f) { - if (!isString(f)) { - var objects = []; - for (var i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); - } - return objects.join(' '); - } +var Long = require('./long'); - var i = 1; - var args = arguments; - var len = args.length; - var str = String(f).replace(formatRegExp, function(x) { - if (x === '%%') return '%'; - if (i >= len) return x; - switch (x) { - case '%s': return String(args[i++]); - case '%d': return Number(args[i++]); - case '%j': - try { - return JSON.stringify(args[i++]); - } catch (_) { - return '[Circular]'; - } - default: - return x; - } - }); - for (var x = args[i]; i < len; x = args[++i]) { - if (isNull(x) || !isObject(x)) { - str += ' ' + x; - } else { - str += ' ' + inspect(x); - } - } - return str; -}; +var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/; +var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i; +var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i; +var EXPONENT_MAX = 6111; +var EXPONENT_MIN = -6176; +var EXPONENT_BIAS = 6176; +var MAX_DIGITS = 34; -// Mark that a method should not be used. -// Returns a modified function which warns once by default. -// If --no-deprecation is set, then it is a no-op. -exports.deprecate = function(fn, msg) { - // Allow for deprecating things in the process of starting up. - if (isUndefined(global.process)) { - return function() { - return exports.deprecate(fn, msg).apply(this, arguments); - }; - } +// Nan value bits as 32 bit values (due to lack of longs) +var NAN_BUFFER = [ + 0x7c, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 +].reverse(); +// Infinity value bits 32 bit values (due to lack of longs) +var INF_NEGATIVE_BUFFER = [ + 0xf8, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 +].reverse(); +var INF_POSITIVE_BUFFER = [ + 0x78, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 +].reverse(); - if (process.noDeprecation === true) { - return fn; - } +var EXPONENT_REGEX = /^([-+])?(\d+)?$/; - var warned = false; - function deprecated() { - if (!warned) { - if (process.throwDeprecation) { - throw new Error(msg); - } else if (process.traceDeprecation) { - console.trace(msg); - } else { - console.error(msg); - } - warned = true; - } - return fn.apply(this, arguments); - } +var utils = require('./parser/utils'); - return deprecated; +// Detect if the value is a digit +var isDigit = function(value) { + return !isNaN(parseInt(value, 10)); }; +// Divide two uint128 values +var divideu128 = function(value) { + var DIVISOR = Long.fromNumber(1000 * 1000 * 1000); + var _rem = Long.fromNumber(0); + var i = 0; -var debugs = {}; -var debugEnviron; -exports.debuglog = function(set) { - if (isUndefined(debugEnviron)) - debugEnviron = process.env.NODE_DEBUG || ''; - set = set.toUpperCase(); - if (!debugs[set]) { - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { - var pid = process.pid; - debugs[set] = function() { - var msg = exports.format.apply(exports, arguments); - console.error('%s %d: %s', set, pid, msg); - }; - } else { - debugs[set] = function() {}; - } + if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) { + return { quotient: value, rem: _rem }; } - return debugs[set]; -}; - -/** - * Echos the value of a value. Trys to print the value out - * in the best way possible given the different types. - * - * @param {Object} obj The object to print out. - * @param {Object} opts Optional options object that alters the output. - */ -/* legacy: obj, showHidden, depth, colors*/ -function inspect(obj, opts) { - // default options - var ctx = { - seen: [], - stylize: stylizeNoColor - }; - // legacy... - if (arguments.length >= 3) ctx.depth = arguments[2]; - if (arguments.length >= 4) ctx.colors = arguments[3]; - if (isBoolean(opts)) { - // legacy... - ctx.showHidden = opts; - } else if (opts) { - // got an "options" object - exports._extend(ctx, opts); + for (i = 0; i <= 3; i++) { + // Adjust remainder to match value of next dividend + _rem = _rem.shiftLeft(32); + // Add the divided to _rem + _rem = _rem.add(new Long(value.parts[i], 0)); + value.parts[i] = _rem.div(DIVISOR).low_; + _rem = _rem.modulo(DIVISOR); } - // set default options - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; - if (isUndefined(ctx.depth)) ctx.depth = 2; - if (isUndefined(ctx.colors)) ctx.colors = false; - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; - if (ctx.colors) ctx.stylize = stylizeWithColor; - return formatValue(ctx, obj, ctx.depth); -} -exports.inspect = inspect; - - -// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics -inspect.colors = { - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [30, 39], - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] -}; -// Don't use 'blue' not visible on cmd.exe -inspect.styles = { - 'special': 'cyan', - 'number': 'yellow', - 'boolean': 'yellow', - 'undefined': 'grey', - 'null': 'bold', - 'string': 'green', - 'date': 'magenta', - // "name": intentionally not styling - 'regexp': 'red' + return { quotient: value, rem: _rem }; }; - -function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; - - if (style) { - return '\u001b[' + inspect.colors[style][0] + 'm' + str + - '\u001b[' + inspect.colors[style][1] + 'm'; - } else { - return str; +// Multiply two Long values and return the 128 bit value +var multiply64x2 = function(left, right) { + if (!left && !right) { + return { high: Long.fromNumber(0), low: Long.fromNumber(0) }; } -} - -function stylizeNoColor(str, styleType) { - return str; -} + var leftHigh = left.shiftRightUnsigned(32); + var leftLow = new Long(left.getLowBits(), 0); + var rightHigh = right.shiftRightUnsigned(32); + var rightLow = new Long(right.getLowBits(), 0); + var productHigh = leftHigh.multiply(rightHigh); + var productMid = leftHigh.multiply(rightLow); + var productMid2 = leftLow.multiply(rightHigh); + var productLow = leftLow.multiply(rightLow); -function arrayToHash(array) { - var hash = {}; + productHigh = productHigh.add(productMid.shiftRightUnsigned(32)); + productMid = new Long(productMid.getLowBits(), 0) + .add(productMid2) + .add(productLow.shiftRightUnsigned(32)); - array.forEach(function(val, idx) { - hash[val] = true; - }); + productHigh = productHigh.add(productMid.shiftRightUnsigned(32)); + productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0)); - return hash; -} + // Return the 128 bit result + return { high: productHigh, low: productLow }; +}; +var lessThan = function(left, right) { + // Make values unsigned + var uhleft = left.high_ >>> 0; + var uhright = right.high_ >>> 0; -function formatValue(ctx, value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (ctx.customInspect && - value && - isFunction(value.inspect) && - // Filter out the util module, it's inspect function is special - value.inspect !== exports.inspect && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); - } - return ret; + // Compare high bits first + if (uhleft < uhright) { + return true; + } else if (uhleft === uhright) { + var ulleft = left.low_ >>> 0; + var ulright = right.low_ >>> 0; + if (ulleft < ulright) return true; } - // Primitive types cannot have properties - var primitive = formatPrimitive(ctx, value); - if (primitive) { - return primitive; - } + return false; +}; - // Look up the keys of the object. - var keys = Object.keys(value); - var visibleKeys = arrayToHash(keys); +// var longtoHex = function(value) { +// var buffer = utils.allocBuffer(8); +// var index = 0; +// // Encode the low 64 bits of the decimal +// // Encode low bits +// buffer[index++] = value.low_ & 0xff; +// buffer[index++] = (value.low_ >> 8) & 0xff; +// buffer[index++] = (value.low_ >> 16) & 0xff; +// buffer[index++] = (value.low_ >> 24) & 0xff; +// // Encode high bits +// buffer[index++] = value.high_ & 0xff; +// buffer[index++] = (value.high_ >> 8) & 0xff; +// buffer[index++] = (value.high_ >> 16) & 0xff; +// buffer[index++] = (value.high_ >> 24) & 0xff; +// return buffer.reverse().toString('hex'); +// }; - if (ctx.showHidden) { - keys = Object.getOwnPropertyNames(value); - } +// var int32toHex = function(value) { +// var buffer = utils.allocBuffer(4); +// var index = 0; +// // Encode the low 64 bits of the decimal +// // Encode low bits +// buffer[index++] = value & 0xff; +// buffer[index++] = (value >> 8) & 0xff; +// buffer[index++] = (value >> 16) & 0xff; +// buffer[index++] = (value >> 24) & 0xff; +// return buffer.reverse().toString('hex'); +// }; - // IE doesn't make error fields non-enumerable - // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx - if (isError(value) - && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { - return formatError(value); - } +/** + * A class representation of the BSON Decimal128 type. + * + * @class + * @param {Buffer} bytes a buffer containing the raw Decimal128 bytes. + * @return {Double} + */ +var Decimal128 = function(bytes) { + this._bsontype = 'Decimal128'; + this.bytes = bytes; +}; - // Some type of object without properties can be shortcutted. - if (keys.length === 0) { - if (isFunction(value)) { - var name = value.name ? ': ' + value.name : ''; - return ctx.stylize('[Function' + name + ']', 'special'); - } - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } - if (isDate(value)) { - return ctx.stylize(Date.prototype.toString.call(value), 'date'); - } - if (isError(value)) { - return formatError(value); - } - } +/** + * Create a Decimal128 instance from a string representation + * + * @method + * @param {string} string a numeric string representation. + * @return {Decimal128} returns a Decimal128 instance. + */ +Decimal128.fromString = function(string) { + // Parse state tracking + var isNegative = false; + var sawRadix = false; + var foundNonZero = false; - var base = '', array = false, braces = ['{', '}']; + // Total number of significant digits (no leading or trailing zero) + var significantDigits = 0; + // Total number of significand digits read + var nDigitsRead = 0; + // Total number of digits (no leading zeros) + var nDigits = 0; + // The number of the digits after radix + var radixPosition = 0; + // The index of the first non-zero in *str* + var firstNonZero = 0; - // Make Array say that they are Array - if (isArray(value)) { - array = true; - braces = ['[', ']']; - } + // Digits Array + var digits = [0]; + // The number of digits in digits + var nDigitsStored = 0; + // Insertion pointer for digits + var digitsInsert = 0; + // The index of the first non-zero digit + var firstDigit = 0; + // The index of the last digit + var lastDigit = 0; - // Make functions say that they are functions - if (isFunction(value)) { - var n = value.name ? ': ' + value.name : ''; - base = ' [Function' + n + ']'; - } + // Exponent + var exponent = 0; + // loop index over array + var i = 0; + // The high 17 digits of the significand + var significandHigh = [0, 0]; + // The low 17 digits of the significand + var significandLow = [0, 0]; + // The biased exponent + var biasedExponent = 0; - // Make RegExps say that they are RegExps - if (isRegExp(value)) { - base = ' ' + RegExp.prototype.toString.call(value); + // Read index + var index = 0; + + // Trim the string + string = string.trim(); + + // Naively prevent against REDOS attacks. + // TODO: implementing a custom parsing for this, or refactoring the regex would yield + // further gains. + if (string.length >= 7000) { + throw new Error('' + string + ' not a valid Decimal128 string'); } - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + Date.prototype.toUTCString.call(value); + // Results + var stringMatch = string.match(PARSE_STRING_REGEXP); + var infMatch = string.match(PARSE_INF_REGEXP); + var nanMatch = string.match(PARSE_NAN_REGEXP); + + // Validate the string + if ((!stringMatch && !infMatch && !nanMatch) || string.length === 0) { + throw new Error('' + string + ' not a valid Decimal128 string'); } - // Make error with message first say the error - if (isError(value)) { - base = ' ' + formatError(value); + // Check if we have an illegal exponent format + if (stringMatch && stringMatch[4] && stringMatch[2] === undefined) { + throw new Error('' + string + ' not a valid Decimal128 string'); } - if (keys.length === 0 && (!array || value.length == 0)) { - return braces[0] + base + braces[1]; + // Get the negative or positive sign + if (string[index] === '+' || string[index] === '-') { + isNegative = string[index++] === '-'; } - if (recurseTimes < 0) { - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } else { - return ctx.stylize('[Object]', 'special'); + // Check if user passed Infinity or NaN + if (!isDigit(string[index]) && string[index] !== '.') { + if (string[index] === 'i' || string[index] === 'I') { + return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); + } else if (string[index] === 'N') { + return new Decimal128(utils.toBuffer(NAN_BUFFER)); } } - ctx.seen.push(value); + // Read all the digits + while (isDigit(string[index]) || string[index] === '.') { + if (string[index] === '.') { + if (sawRadix) { + return new Decimal128(utils.toBuffer(NAN_BUFFER)); + } - var output; - if (array) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); - }); - } + sawRadix = true; + index = index + 1; + continue; + } - ctx.seen.pop(); + if (nDigitsStored < 34) { + if (string[index] !== '0' || foundNonZero) { + if (!foundNonZero) { + firstNonZero = nDigitsRead; + } - return reduceToSingleString(output, base, braces); -} + foundNonZero = true; + // Only store 34 digits + digits[digitsInsert++] = parseInt(string[index], 10); + nDigitsStored = nDigitsStored + 1; + } + } -function formatPrimitive(ctx, value) { - if (isUndefined(value)) - return ctx.stylize('undefined', 'undefined'); - if (isString(value)) { - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') - .replace(/'/g, "\\'") - .replace(/\\"/g, '"') + '\''; - return ctx.stylize(simple, 'string'); - } - if (isNumber(value)) - return ctx.stylize('' + value, 'number'); - if (isBoolean(value)) - return ctx.stylize('' + value, 'boolean'); - // For some reason typeof null is "object", so special case here. - if (isNull(value)) - return ctx.stylize('null', 'null'); -} + if (foundNonZero) { + nDigits = nDigits + 1; + } + + if (sawRadix) { + radixPosition = radixPosition + 1; + } + nDigitsRead = nDigitsRead + 1; + index = index + 1; + } -function formatError(value) { - return '[' + Error.prototype.toString.call(value) + ']'; -} + if (sawRadix && !nDigitsRead) { + throw new Error('' + string + ' not a valid Decimal128 string'); + } + // Read exponent if exists + if (string[index] === 'e' || string[index] === 'E') { + // Read exponent digits + var match = string.substr(++index).match(EXPONENT_REGEX); -function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { - var output = []; - for (var i = 0, l = value.length; i < l; ++i) { - if (hasOwnProperty(value, String(i))) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); - } else { - output.push(''); + // No digits read + if (!match || !match[2]) { + return new Decimal128(utils.toBuffer(NAN_BUFFER)); } + + // Get exponent + exponent = parseInt(match[0], 10); + + // Adjust the index + index = index + match[0].length; } - keys.forEach(function(key) { - if (!key.match(/^\d+$/)) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); - } - }); - return output; -} + // Return not a number + if (string[index]) { + return new Decimal128(utils.toBuffer(NAN_BUFFER)); + } -function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str, desc; - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; - if (desc.get) { - if (desc.set) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); - } + // Done reading input + // Find first non-zero digit in digits + firstDigit = 0; + + if (!nDigitsStored) { + firstDigit = 0; + lastDigit = 0; + digits[0] = 0; + nDigits = 1; + nDigitsStored = 1; + significantDigits = 0; } else { - if (desc.set) { - str = ctx.stylize('[Setter]', 'special'); + lastDigit = nDigitsStored - 1; + significantDigits = nDigits; + + if (exponent !== 0 && significantDigits !== 1) { + while (string[firstNonZero + significantDigits - 1] === '0') { + significantDigits = significantDigits - 1; + } } } - if (!hasOwnProperty(visibleKeys, key)) { - name = '[' + key + ']'; + + // Normalization of exponent + // Correct exponent based on radix position, and shift significand as needed + // to represent user input + + // Overflow prevention + if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) { + exponent = EXPONENT_MIN; + } else { + exponent = exponent - radixPosition; } - if (!str) { - if (ctx.seen.indexOf(desc.value) < 0) { - if (isNull(recurseTimes)) { - str = formatValue(ctx, desc.value, null); + + // Attempt to normalize the exponent + while (exponent > EXPONENT_MAX) { + // Shift exponent to significand and decrease + lastDigit = lastDigit + 1; + + if (lastDigit - firstDigit > MAX_DIGITS) { + // Check if we have a zero then just hard clamp, otherwise fail + var digitsString = digits.join(''); + if (digitsString.match(/^0+$/)) { + exponent = EXPONENT_MAX; + break; } else { - str = formatValue(ctx, desc.value, recurseTimes - 1); - } - if (str.indexOf('\n') > -1) { - if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); - } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); - } + return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); } - } else { - str = ctx.stylize('[Circular]', 'special'); } + + exponent = exponent - 1; } - if (isUndefined(name)) { - if (array && key.match(/^\d+$/)) { - return str; + + while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) { + // Shift last digit + if (lastDigit === 0) { + exponent = EXPONENT_MIN; + significantDigits = 0; + break; } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length - 2); - name = ctx.stylize(name, 'name'); + + if (nDigitsStored < nDigits) { + // adjust to match digits not stored + nDigits = nDigits - 1; } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = ctx.stylize(name, 'string'); + // adjust to round + lastDigit = lastDigit - 1; } - } - return name + ': ' + str; -} - - -function reduceToSingleString(output, base, braces) { - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if (cur.indexOf('\n') >= 0) numLinesEst++; - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; - }, 0); - - if (length > 60) { - return braces[0] + - (base === '' ? '' : base + '\n ') + - ' ' + - output.join(',\n ') + - ' ' + - braces[1]; + if (exponent < EXPONENT_MAX) { + exponent = exponent + 1; + } else { + // Check if we have a zero then just hard clamp, otherwise fail + digitsString = digits.join(''); + if (digitsString.match(/^0+$/)) { + exponent = EXPONENT_MAX; + break; + } else { + return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); + } + } } - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; -} + // Round + // We've normalized the exponent, but might still need to round. + if (lastDigit - firstDigit + 1 < significantDigits && string[significantDigits] !== '0') { + var endOfString = nDigitsRead; + // If we have seen a radix point, 'string' is 1 longer than we have + // documented with ndigits_read, so inc the position of the first nonzero + // digit and the position that digits are read to. + if (sawRadix && exponent === EXPONENT_MIN) { + firstNonZero = firstNonZero + 1; + endOfString = endOfString + 1; + } -// NOTE: These type checking functions intentionally don't use `instanceof` -// because it is fragile and can be easily faked with `Object.create()`. -function isArray(ar) { - return Array.isArray(ar); -} -exports.isArray = isArray; + var roundDigit = parseInt(string[firstNonZero + lastDigit + 1], 10); + var roundBit = 0; -function isBoolean(arg) { - return typeof arg === 'boolean'; -} -exports.isBoolean = isBoolean; + if (roundDigit >= 5) { + roundBit = 1; -function isNull(arg) { - return arg === null; -} -exports.isNull = isNull; + if (roundDigit === 5) { + roundBit = digits[lastDigit] % 2 === 1; -function isNullOrUndefined(arg) { - return arg == null; -} -exports.isNullOrUndefined = isNullOrUndefined; + for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) { + if (parseInt(string[i], 10)) { + roundBit = 1; + break; + } + } + } + } -function isNumber(arg) { - return typeof arg === 'number'; -} -exports.isNumber = isNumber; + if (roundBit) { + var dIdx = lastDigit; -function isString(arg) { - return typeof arg === 'string'; -} -exports.isString = isString; + for (; dIdx >= 0; dIdx--) { + if (++digits[dIdx] > 9) { + digits[dIdx] = 0; -function isSymbol(arg) { - return typeof arg === 'symbol'; -} -exports.isSymbol = isSymbol; + // overflowed most significant digit + if (dIdx === 0) { + if (exponent < EXPONENT_MAX) { + exponent = exponent + 1; + digits[dIdx] = 1; + } else { + return new Decimal128( + utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER) + ); + } + } + } else { + break; + } + } + } + } -function isUndefined(arg) { - return arg === void 0; -} -exports.isUndefined = isUndefined; + // Encode significand + // The high 17 digits of the significand + significandHigh = Long.fromNumber(0); + // The low 17 digits of the significand + significandLow = Long.fromNumber(0); -function isRegExp(re) { - return isObject(re) && objectToString(re) === '[object RegExp]'; -} -exports.isRegExp = isRegExp; + // read a zero + if (significantDigits === 0) { + significandHigh = Long.fromNumber(0); + significandLow = Long.fromNumber(0); + } else if (lastDigit - firstDigit < 17) { + dIdx = firstDigit; + significandLow = Long.fromNumber(digits[dIdx++]); + significandHigh = new Long(0, 0); -function isObject(arg) { - return typeof arg === 'object' && arg !== null; -} -exports.isObject = isObject; + for (; dIdx <= lastDigit; dIdx++) { + significandLow = significandLow.multiply(Long.fromNumber(10)); + significandLow = significandLow.add(Long.fromNumber(digits[dIdx])); + } + } else { + dIdx = firstDigit; + significandHigh = Long.fromNumber(digits[dIdx++]); -function isDate(d) { - return isObject(d) && objectToString(d) === '[object Date]'; -} -exports.isDate = isDate; + for (; dIdx <= lastDigit - 17; dIdx++) { + significandHigh = significandHigh.multiply(Long.fromNumber(10)); + significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx])); + } -function isError(e) { - return isObject(e) && - (objectToString(e) === '[object Error]' || e instanceof Error); -} -exports.isError = isError; + significandLow = Long.fromNumber(digits[dIdx++]); -function isFunction(arg) { - return typeof arg === 'function'; -} -exports.isFunction = isFunction; + for (; dIdx <= lastDigit; dIdx++) { + significandLow = significandLow.multiply(Long.fromNumber(10)); + significandLow = significandLow.add(Long.fromNumber(digits[dIdx])); + } + } -function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; -} -exports.isPrimitive = isPrimitive; + var significand = multiply64x2(significandHigh, Long.fromString('100000000000000000')); -exports.isBuffer = require('./support/isBuffer'); + significand.low = significand.low.add(significandLow); -function objectToString(o) { - return Object.prototype.toString.call(o); -} + if (lessThan(significand.low, significandLow)) { + significand.high = significand.high.add(Long.fromNumber(1)); + } + // Biased exponent + biasedExponent = exponent + EXPONENT_BIAS; + var dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) }; -function pad(n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); -} + // Encode combination, exponent, and significand. + if ( + significand.high + .shiftRightUnsigned(49) + .and(Long.fromNumber(1)) + .equals(Long.fromNumber) + ) { + // Encode '11' into bits 1 to 3 + dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61)); + dec.high = dec.high.or( + Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)) + ); + dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff))); + } else { + dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49)); + dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff))); + } + dec.low = significand.low; -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; + // Encode sign + if (isNegative) { + dec.high = dec.high.or(Long.fromString('9223372036854775808')); + } -// 26 Feb 16:19:34 -function timestamp() { - var d = new Date(); - var time = [pad(d.getHours()), - pad(d.getMinutes()), - pad(d.getSeconds())].join(':'); - return [d.getDate(), months[d.getMonth()], time].join(' '); -} + // Encode into a buffer + var buffer = utils.allocBuffer(16); + index = 0; + // Encode the low 64 bits of the decimal + // Encode low bits + buffer[index++] = dec.low.low_ & 0xff; + buffer[index++] = (dec.low.low_ >> 8) & 0xff; + buffer[index++] = (dec.low.low_ >> 16) & 0xff; + buffer[index++] = (dec.low.low_ >> 24) & 0xff; + // Encode high bits + buffer[index++] = dec.low.high_ & 0xff; + buffer[index++] = (dec.low.high_ >> 8) & 0xff; + buffer[index++] = (dec.low.high_ >> 16) & 0xff; + buffer[index++] = (dec.low.high_ >> 24) & 0xff; -// log is just a thin wrapper to console.log that prepends a timestamp -exports.log = function() { - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); + // Encode the high 64 bits of the decimal + // Encode low bits + buffer[index++] = dec.high.low_ & 0xff; + buffer[index++] = (dec.high.low_ >> 8) & 0xff; + buffer[index++] = (dec.high.low_ >> 16) & 0xff; + buffer[index++] = (dec.high.low_ >> 24) & 0xff; + // Encode high bits + buffer[index++] = dec.high.high_ & 0xff; + buffer[index++] = (dec.high.high_ >> 8) & 0xff; + buffer[index++] = (dec.high.high_ >> 16) & 0xff; + buffer[index++] = (dec.high.high_ >> 24) & 0xff; + + // Return the new Decimal128 + return new Decimal128(buffer); }; +// Extract least significant 5 bits +var COMBINATION_MASK = 0x1f; +// Extract least significant 14 bits +var EXPONENT_MASK = 0x3fff; +// Value of combination field for Inf +var COMBINATION_INFINITY = 30; +// Value of combination field for NaN +var COMBINATION_NAN = 31; +// Value of combination field for NaN +// var COMBINATION_SNAN = 32; +// decimal128 exponent bias +EXPONENT_BIAS = 6176; /** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be rewritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). + * Create a string representation of the raw Decimal128 value * - * @param {function} ctor Constructor function which needs to inherit the - * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. + * @method + * @return {string} returns a Decimal128 string representation. */ -exports.inherits = require('inherits'); - -exports._extend = function(origin, add) { - // Don't do anything if add isn't an object - if (!add || !isObject(add)) return origin; - - var keys = Object.keys(add); - var i = keys.length; - while (i--) { - origin[keys[i]] = add[keys[i]]; - } - return origin; -}; +Decimal128.prototype.toString = function() { + // Note: bits in this routine are referred to starting at 0, + // from the sign bit, towards the coefficient. -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} + // bits 0 - 31 + var high; + // bits 32 - 63 + var midh; + // bits 64 - 95 + var midl; + // bits 96 - 127 + var low; + // bits 1 - 5 + var combination; + // decoded biased exponent (14 bits) + var biased_exponent; + // the number of significand digits + var significand_digits = 0; + // the base-10 digits in the significand + var significand = new Array(36); + for (var i = 0; i < significand.length; i++) significand[i] = 0; + // read pointer into significand + var index = 0; -}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":24,"_process":369,"inherits":23}],26:[function(require,module,exports){ -(function (global){(function (){ -'use strict'; + // unbiased exponent + var exponent; + // the exponent if scientific notation is used + var scientific_exponent; -var possibleNames = [ - 'BigInt64Array', - 'BigUint64Array', - 'Float32Array', - 'Float64Array', - 'Int16Array', - 'Int32Array', - 'Int8Array', - 'Uint16Array', - 'Uint32Array', - 'Uint8Array', - 'Uint8ClampedArray' -]; + // true if the number is zero + var is_zero = false; -var g = typeof globalThis === 'undefined' ? global : globalThis; + // the most signifcant significand bits (50-46) + var significand_msb; + // temporary storage for significand decoding + var significand128 = { parts: new Array(4) }; + // indexing variables + i; + var j, k; -module.exports = function availableTypedArrays() { - var out = []; - for (var i = 0; i < possibleNames.length; i++) { - if (typeof g[possibleNames[i]] === 'function') { - out[out.length] = possibleNames[i]; - } - } - return out; -}; + // Output string + var string = []; -}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],27:[function(require,module,exports){ -'use strict' + // Unpack index + index = 0; -exports.byteLength = byteLength -exports.toByteArray = toByteArray -exports.fromByteArray = fromByteArray + // Buffer reference + var buffer = this.bytes; -var lookup = [] -var revLookup = [] -var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array + // Unpack the low 64bits into a long + low = + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); + midl = + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); -var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i] - revLookup[code.charCodeAt(i)] = i -} + // Unpack the high 64bits into a long + midh = + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); + high = + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); -// Support decoding URL-safe base64 strings, as Node.js does. -// See: https://en.wikipedia.org/wiki/Base64#URL_applications -revLookup['-'.charCodeAt(0)] = 62 -revLookup['_'.charCodeAt(0)] = 63 + // Unpack index + index = 0; -function getLens (b64) { - var len = b64.length + // Create the state of the decimal + var dec = { + low: new Long(low, midl), + high: new Long(midh, high) + }; - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') + if (dec.high.lessThan(Long.ZERO)) { + string.push('-'); } - // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - var validLen = b64.indexOf('=') - if (validLen === -1) validLen = len + // Decode combination field and exponent + combination = (high >> 26) & COMBINATION_MASK; - var placeHoldersLen = validLen === len - ? 0 - : 4 - (validLen % 4) + if (combination >> 3 === 3) { + // Check for 'special' values + if (combination === COMBINATION_INFINITY) { + return string.join('') + 'Infinity'; + } else if (combination === COMBINATION_NAN) { + return 'NaN'; + } else { + biased_exponent = (high >> 15) & EXPONENT_MASK; + significand_msb = 0x08 + ((high >> 14) & 0x01); + } + } else { + significand_msb = (high >> 14) & 0x07; + biased_exponent = (high >> 17) & EXPONENT_MASK; + } - return [validLen, placeHoldersLen] -} + exponent = biased_exponent - EXPONENT_BIAS; -// base64 is 4/3 + up to two characters of the original data -function byteLength (b64) { - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen -} + // Create string of significand digits -function _byteLength (b64, validLen, placeHoldersLen) { - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen -} + // Convert the 114-bit binary number represented by + // (significand_high, significand_low) to at most 34 decimal + // digits through modulo and division. + significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14); + significand128.parts[1] = midh; + significand128.parts[2] = midl; + significand128.parts[3] = low; -function toByteArray (b64) { - var tmp - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] + if ( + significand128.parts[0] === 0 && + significand128.parts[1] === 0 && + significand128.parts[2] === 0 && + significand128.parts[3] === 0 + ) { + is_zero = true; + } else { + for (k = 3; k >= 0; k--) { + var least_digits = 0; + // Peform the divide + var result = divideu128(significand128); + significand128 = result.quotient; + least_digits = result.rem.low_; - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) + // We now have the 9 least significant digits (in base 2). + // Convert and output to string. + if (!least_digits) continue; - var curByte = 0 + for (j = 8; j >= 0; j--) { + // significand[k * 9 + j] = Math.round(least_digits % 10); + significand[k * 9 + j] = least_digits % 10; + // least_digits = Math.round(least_digits / 10); + least_digits = Math.floor(least_digits / 10); + } + } + } - // if there are placeholders, only get up to the last complete 4 chars - var len = placeHoldersLen > 0 - ? validLen - 4 - : validLen + // Output format options: + // Scientific - [-]d.dddE(+/-)dd or [-]dE(+/-)dd + // Regular - ddd.ddd - var i - for (i = 0; i < len; i += 4) { - tmp = - (revLookup[b64.charCodeAt(i)] << 18) | - (revLookup[b64.charCodeAt(i + 1)] << 12) | - (revLookup[b64.charCodeAt(i + 2)] << 6) | - revLookup[b64.charCodeAt(i + 3)] - arr[curByte++] = (tmp >> 16) & 0xFF - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF - } + if (is_zero) { + significand_digits = 1; + significand[index] = 0; + } else { + significand_digits = 36; + i = 0; - if (placeHoldersLen === 2) { - tmp = - (revLookup[b64.charCodeAt(i)] << 2) | - (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[curByte++] = tmp & 0xFF + while (!significand[index]) { + i++; + significand_digits = significand_digits - 1; + index = index + 1; + } } - if (placeHoldersLen === 1) { - tmp = - (revLookup[b64.charCodeAt(i)] << 10) | - (revLookup[b64.charCodeAt(i + 1)] << 4) | - (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF - } + scientific_exponent = significand_digits - 1 + exponent; - return arr -} + // The scientific exponent checks are dictated by the string conversion + // specification and are somewhat arbitrary cutoffs. + // + // We must check exponent > 0, because if this is the case, the number + // has trailing zeros. However, we *cannot* output these trailing zeros, + // because doing so would change the precision of the value, and would + // change stored data if the string converted number is round tripped. -function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + - lookup[num >> 12 & 0x3F] + - lookup[num >> 6 & 0x3F] + - lookup[num & 0x3F] -} + if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) { + // Scientific format + string.push(significand[index++]); + significand_digits = significand_digits - 1; -function encodeChunk (uint8, start, end) { - var tmp - var output = [] - for (var i = start; i < end; i += 3) { - tmp = - ((uint8[i] << 16) & 0xFF0000) + - ((uint8[i + 1] << 8) & 0xFF00) + - (uint8[i + 2] & 0xFF) - output.push(tripletToBase64(tmp)) - } - return output.join('') -} + if (significand_digits) { + string.push('.'); + } -function fromByteArray (uint8) { - var tmp - var len = uint8.length - var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var parts = [] - var maxChunkLength = 16383 // must be multiple of 3 + for (i = 0; i < significand_digits; i++) { + string.push(significand[index++]); + } - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) - } + // Exponent + string.push('E'); + if (scientific_exponent > 0) { + string.push('+' + scientific_exponent); + } else { + string.push(scientific_exponent); + } + } else { + // Regular format with no decimal place + if (exponent >= 0) { + for (i = 0; i < significand_digits; i++) { + string.push(significand[index++]); + } + } else { + var radix_position = significand_digits + exponent; - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1] - parts.push( - lookup[tmp >> 2] + - lookup[(tmp << 4) & 0x3F] + - '==' - ) - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1] - parts.push( - lookup[tmp >> 10] + - lookup[(tmp >> 4) & 0x3F] + - lookup[(tmp << 2) & 0x3F] + - '=' - ) - } + // non-zero digits before radix + if (radix_position > 0) { + for (i = 0; i < radix_position; i++) { + string.push(significand[index++]); + } + } else { + string.push('0'); + } - return parts.join('') -} + string.push('.'); + // add leading zeros after radix + while (radix_position++ < 0) { + string.push('0'); + } -},{}],28:[function(require,module,exports){ -(function (process,global,setImmediate){(function (){ -/* @preserve - * The MIT License (MIT) - * - * Copyright (c) 2013-2017 Petka Antonov - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -/** - * bluebird build version 3.5.1 - * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each -*/ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o> 1, + nBits = -7, + i = bBE ? 0 : nBytes - 1, + d = bBE ? 1 : -1, + s = buffer[offset + i]; + i += d; -Async.prototype.fatalError = function(e, isNode) { - if (isNode) { - process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) + - "\n"); - process.exit(2); - } else { - this.throwLater(e); - } + e = s & ((1 << -nBits) - 1); + s >>= -nBits; + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); + + m = e & ((1 << -nBits) - 1); + e >>= -nBits; + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); + + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : (s ? -1 : 1) * Infinity; + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); }; -Async.prototype.throwLater = function(fn, arg) { - if (arguments.length === 1) { - arg = fn; - fn = function () { throw arg; }; +var writeIEEE754 = function(buffer, value, offset, endian, mLen, nBytes) { + var e, + m, + c, + bBE = endian === 'big', + eLen = nBytes * 8 - mLen - 1, + eMax = (1 << eLen) - 1, + eBias = eMax >> 1, + rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, + i = bBE ? nBytes - 1 : 0, + d = bBE ? -1 : 1, + s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; + + value = Math.abs(value); + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; } - if (typeof setTimeout !== "undefined") { - setTimeout(function() { - fn(arg); - }, 0); - } else try { - this._schedule(function() { - fn(arg); - }); - } catch (e) { - throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; } -}; -function AsyncInvokeLater(fn, receiver, arg) { - this._lateQueue.push(fn, receiver, arg); - this._queueTick(); -} + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } -function AsyncInvoke(fn, receiver, arg) { - this._normalQueue.push(fn, receiver, arg); - this._queueTick(); -} + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); -function AsyncSettlePromises(promise) { - this._normalQueue._pushOne(promise); - this._queueTick(); -} + e = (e << mLen) | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); -if (!util.hasDevTools) { - Async.prototype.invokeLater = AsyncInvokeLater; - Async.prototype.invoke = AsyncInvoke; - Async.prototype.settlePromises = AsyncSettlePromises; -} else { - Async.prototype.invokeLater = function (fn, receiver, arg) { - if (this._trampolineEnabled) { - AsyncInvokeLater.call(this, fn, receiver, arg); - } else { - this._schedule(function() { - setTimeout(function() { - fn.call(receiver, arg); - }, 100); - }); - } - }; + buffer[offset + i - d] |= s * 128; +}; - Async.prototype.invoke = function (fn, receiver, arg) { - if (this._trampolineEnabled) { - AsyncInvoke.call(this, fn, receiver, arg); - } else { - this._schedule(function() { - fn.call(receiver, arg); - }); - } - }; +exports.readIEEE754 = readIEEE754; +exports.writeIEEE754 = writeIEEE754; - Async.prototype.settlePromises = function(promise) { - if (this._trampolineEnabled) { - AsyncSettlePromises.call(this, promise); - } else { - this._schedule(function() { - promise._settlePromises(); - }); - } - }; -} +},{}],22:[function(require,module,exports){ +/** + * A class representation of a BSON Int32 type. + * + * @class + * @param {number} value the number we want to represent as an int32. + * @return {Int32} + */ +var Int32 = function(value) { + if (!(this instanceof Int32)) return new Int32(value); -Async.prototype._drainQueue = function(queue) { - while (queue.length() > 0) { - var fn = queue.shift(); - if (typeof fn !== "function") { - fn._settlePromises(); - continue; - } - var receiver = queue.shift(); - var arg = queue.shift(); - fn.call(receiver, arg); - } + this._bsontype = 'Int32'; + this.value = value; }; -Async.prototype._drainQueues = function () { - this._drainQueue(this._normalQueue); - this._reset(); - this._haveDrainedQueues = true; - this._drainQueue(this._lateQueue); +/** + * Access the number value. + * + * @method + * @return {number} returns the wrapped int32 number. + */ +Int32.prototype.valueOf = function() { + return this.value; }; -Async.prototype._queueTick = function () { - if (!this._isTickUsed) { - this._isTickUsed = true; - this._schedule(this.drainQueues); - } +/** + * @ignore + */ +Int32.prototype.toJSON = function() { + return this.value; }; -Async.prototype._reset = function () { - this._isTickUsed = false; -}; +module.exports = Int32; +module.exports.Int32 = Int32; -module.exports = Async; -module.exports.firstLineError = firstLineError; +},{}],23:[function(require,module,exports){ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2009 Google Inc. All Rights Reserved -},{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) { -var calledBind = false; -var rejectThis = function(_, e) { - this._reject(e); -}; +/** + * Defines a Long class for representing a 64-bit two's-complement + * integer value, which faithfully simulates the behavior of a Java "Long". This + * implementation is derived from LongLib in GWT. + * + * Constructs a 64-bit two's-complement integer, given its low and high 32-bit + * values as *signed* integers. See the from* functions below for more + * convenient ways of constructing Longs. + * + * The internal representation of a Long is the two given signed, 32-bit values. + * We use 32-bit pieces because these are the size of integers on which + * Javascript performs bit-operations. For operations like addition and + * multiplication, we split each number into 16-bit pieces, which can easily be + * multiplied within Javascript's floating-point representation without overflow + * or change in sign. + * + * In the algorithms below, we frequently reduce the negative case to the + * positive case by negating the input(s) and then post-processing the result. + * Note that we must ALWAYS check specially whether those values are MIN_VALUE + * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as + * a positive number, it overflows back into a negative). Not handling this + * case would often result in infinite recursion. + * + * @class + * @param {number} low the low (signed) 32 bits of the Long. + * @param {number} high the high (signed) 32 bits of the Long. + * @return {Long} + */ +function Long(low, high) { + if (!(this instanceof Long)) return new Long(low, high); -var targetRejected = function(e, context) { - context.promiseRejectionQueued = true; - context.bindingPromise._then(rejectThis, rejectThis, null, this, e); -}; + this._bsontype = 'Long'; + /** + * @type {number} + * @ignore + */ + this.low_ = low | 0; // force into 32 signed bits. -var bindingResolved = function(thisArg, context) { - if (((this._bitField & 50397184) === 0)) { - this._resolveCallback(context.target); - } -}; + /** + * @type {number} + * @ignore + */ + this.high_ = high | 0; // force into 32 signed bits. +} -var bindingRejected = function(e, context) { - if (!context.promiseRejectionQueued) this._reject(e); +/** + * Return the int value. + * + * @method + * @return {number} the value, assuming it is a 32-bit integer. + */ +Long.prototype.toInt = function() { + return this.low_; }; -Promise.prototype.bind = function (thisArg) { - if (!calledBind) { - calledBind = true; - Promise.prototype._propagateFrom = debug.propagateFromFunction(); - Promise.prototype._boundValue = debug.boundValueFunction(); - } - var maybePromise = tryConvertToPromise(thisArg); - var ret = new Promise(INTERNAL); - ret._propagateFrom(this, 1); - var target = this._target(); - ret._setBoundTo(maybePromise); - if (maybePromise instanceof Promise) { - var context = { - promiseRejectionQueued: false, - promise: ret, - target: target, - bindingPromise: maybePromise - }; - target._then(INTERNAL, targetRejected, undefined, ret, context); - maybePromise._then( - bindingResolved, bindingRejected, undefined, ret, context); - ret._setOnCancel(maybePromise); - } else { - ret._resolveCallback(target); - } - return ret; +/** + * Return the Number value. + * + * @method + * @return {number} the closest floating-point representation to this value. + */ +Long.prototype.toNumber = function() { + return this.high_ * Long.TWO_PWR_32_DBL_ + this.getLowBitsUnsigned(); }; -Promise.prototype._setBoundTo = function (obj) { - if (obj !== undefined) { - this._bitField = this._bitField | 2097152; - this._boundTo = obj; - } else { - this._bitField = this._bitField & (~2097152); - } -}; +/** Converts the Long to a BigInt (arbitrary precision). */ +Long.prototype.toBigInt = function () { + return BigInt(this.toString()); +} -Promise.prototype._isBound = function () { - return (this._bitField & 2097152) === 2097152; +/** + * Return the JSON value. + * + * @method + * @return {string} the JSON representation. + */ +Long.prototype.toJSON = function() { + return this.toString(); }; -Promise.bind = function (thisArg, value) { - return Promise.resolve(value).bind(thisArg); -}; -}; +/** + * Return the String value. + * + * @method + * @param {number} [opt_radix] the radix in which the text should be written. + * @return {string} the textual representation of this value. + */ +Long.prototype.toString = function(opt_radix) { + var radix = opt_radix || 10; + if (radix < 2 || 36 < radix) { + throw Error('radix out of range: ' + radix); + } -},{}],4:[function(_dereq_,module,exports){ -"use strict"; -var old; -if (typeof Promise !== "undefined") old = Promise; -function noConflict() { - try { if (Promise === bluebird) Promise = old; } - catch (e) {} - return bluebird; -} -var bluebird = _dereq_("./promise")(); -bluebird.noConflict = noConflict; -module.exports = bluebird; + if (this.isZero()) { + return '0'; + } -},{"./promise":22}],5:[function(_dereq_,module,exports){ -"use strict"; -var cr = Object.create; -if (cr) { - var callerCache = cr(null); - var getterCache = cr(null); - callerCache[" size"] = getterCache[" size"] = 0; -} + if (this.isNegative()) { + if (this.equals(Long.MIN_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = Long.fromNumber(radix); + var div = this.div(radixLong); + var rem = div.multiply(radixLong).subtract(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else { + return '-' + this.negate().toString(radix); + } + } -module.exports = function(Promise) { -var util = _dereq_("./util"); -var canEvaluate = util.canEvaluate; -var isIdentifier = util.isIdentifier; + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 6)); -var getMethodCaller; -var getGetter; -if (!true) { -var makeMethodCaller = function (methodName) { - return new Function("ensureMethod", " \n\ - return function(obj) { \n\ - 'use strict' \n\ - var len = this.length; \n\ - ensureMethod(obj, 'methodName'); \n\ - switch(len) { \n\ - case 1: return obj.methodName(this[0]); \n\ - case 2: return obj.methodName(this[0], this[1]); \n\ - case 3: return obj.methodName(this[0], this[1], this[2]); \n\ - case 0: return obj.methodName(); \n\ - default: \n\ - return obj.methodName.apply(obj, this); \n\ - } \n\ - }; \n\ - ".replace(/methodName/g, methodName))(ensureMethod); -}; + rem = this; + var result = ''; -var makeGetter = function (propertyName) { - return new Function("obj", " \n\ - 'use strict'; \n\ - return obj.propertyName; \n\ - ".replace("propertyName", propertyName)); -}; + while (!rem.isZero()) { + var remDiv = rem.div(radixToPower); + var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); + var digits = intval.toString(radix); -var getCompiled = function(name, compiler, cache) { - var ret = cache[name]; - if (typeof ret !== "function") { - if (!isIdentifier(name)) { - return null; - } - ret = compiler(name); - cache[name] = ret; - cache[" size"]++; - if (cache[" size"] > 512) { - var keys = Object.keys(cache); - for (var i = 0; i < 256; ++i) delete cache[keys[i]]; - cache[" size"] = keys.length - 256; - } + rem = remDiv; + if (rem.isZero()) { + return digits + result; + } else { + while (digits.length < 6) { + digits = '0' + digits; + } + result = '' + digits + result; } - return ret; + } }; -getMethodCaller = function(name) { - return getCompiled(name, makeMethodCaller, callerCache); +/** + * Return the high 32-bits value. + * + * @method + * @return {number} the high 32-bits as a signed value. + */ +Long.prototype.getHighBits = function() { + return this.high_; }; -getGetter = function(name) { - return getCompiled(name, makeGetter, getterCache); -}; -} - -function ensureMethod(obj, methodName) { - var fn; - if (obj != null) fn = obj[methodName]; - if (typeof fn !== "function") { - var message = "Object " + util.classString(obj) + " has no method '" + - util.toString(methodName) + "'"; - throw new Promise.TypeError(message); - } - return fn; -} +/** + * Return the low 32-bits value. + * + * @method + * @return {number} the low 32-bits as a signed value. + */ +Long.prototype.getLowBits = function() { + return this.low_; +}; -function caller(obj) { - var methodName = this.pop(); - var fn = ensureMethod(obj, methodName); - return fn.apply(obj, this); -} -Promise.prototype.call = function (methodName) { - var args = [].slice.call(arguments, 1);; - if (!true) { - if (canEvaluate) { - var maybeCaller = getMethodCaller(methodName); - if (maybeCaller !== null) { - return this._then( - maybeCaller, undefined, undefined, args, undefined); - } - } - } - args.push(methodName); - return this._then(caller, undefined, undefined, args, undefined); +/** + * Return the low unsigned 32-bits value. + * + * @method + * @return {number} the low 32-bits as an unsigned value. + */ +Long.prototype.getLowBitsUnsigned = function() { + return this.low_ >= 0 ? this.low_ : Long.TWO_PWR_32_DBL_ + this.low_; }; -function namedGetter(obj) { - return obj[this]; -} -function indexedGetter(obj) { - var index = +this; - if (index < 0) index = Math.max(0, index + obj.length); - return obj[index]; -} -Promise.prototype.get = function (propertyName) { - var isIndex = (typeof propertyName === "number"); - var getter; - if (!isIndex) { - if (canEvaluate) { - var maybeGetter = getGetter(propertyName); - getter = maybeGetter !== null ? maybeGetter : namedGetter; - } else { - getter = namedGetter; - } +/** + * Returns the number of bits needed to represent the absolute value of this Long. + * + * @method + * @return {number} Returns the number of bits needed to represent the absolute value of this Long. + */ +Long.prototype.getNumBitsAbs = function() { + if (this.isNegative()) { + if (this.equals(Long.MIN_VALUE)) { + return 64; } else { - getter = indexedGetter; + return this.negate().getNumBitsAbs(); } - return this._then(getter, undefined, undefined, propertyName, undefined); -}; -}; - -},{"./util":36}],6:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, PromiseArray, apiRejection, debug) { -var util = _dereq_("./util"); -var tryCatch = util.tryCatch; -var errorObj = util.errorObj; -var async = Promise._async; - -Promise.prototype["break"] = Promise.prototype.cancel = function() { - if (!debug.cancellation()) return this._warn("cancellation is disabled"); - - var promise = this; - var child = promise; - while (promise._isCancellable()) { - if (!promise._cancelBy(child)) { - if (child._isFollowing()) { - child._followee().cancel(); - } else { - child._cancelBranched(); - } - break; - } - - var parent = promise._cancellationParent; - if (parent == null || !parent._isCancellable()) { - if (promise._isFollowing()) { - promise._followee().cancel(); - } else { - promise._cancelBranched(); - } - break; - } else { - if (promise._isFollowing()) promise._followee().cancel(); - promise._setWillBeCancelled(); - child = promise; - promise = parent; - } + } else { + var val = this.high_ !== 0 ? this.high_ : this.low_; + for (var bit = 31; bit > 0; bit--) { + if ((val & (1 << bit)) !== 0) { + break; + } } + return this.high_ !== 0 ? bit + 33 : bit + 1; + } }; -Promise.prototype._branchHasCancelled = function() { - this._branchesRemainingToCancel--; -}; - -Promise.prototype._enoughBranchesHaveCancelled = function() { - return this._branchesRemainingToCancel === undefined || - this._branchesRemainingToCancel <= 0; +/** + * Return whether this value is zero. + * + * @method + * @return {boolean} whether this value is zero. + */ +Long.prototype.isZero = function() { + return this.high_ === 0 && this.low_ === 0; }; -Promise.prototype._cancelBy = function(canceller) { - if (canceller === this) { - this._branchesRemainingToCancel = 0; - this._invokeOnCancel(); - return true; - } else { - this._branchHasCancelled(); - if (this._enoughBranchesHaveCancelled()) { - this._invokeOnCancel(); - return true; - } - } - return false; +/** + * Return whether this value is negative. + * + * @method + * @return {boolean} whether this value is negative. + */ +Long.prototype.isNegative = function() { + return this.high_ < 0; }; -Promise.prototype._cancelBranched = function() { - if (this._enoughBranchesHaveCancelled()) { - this._cancel(); - } +/** + * Return whether this value is odd. + * + * @method + * @return {boolean} whether this value is odd. + */ +Long.prototype.isOdd = function() { + return (this.low_ & 1) === 1; }; -Promise.prototype._cancel = function() { - if (!this._isCancellable()) return; - this._setCancelled(); - async.invoke(this._cancelPromises, this, undefined); +/** + * Return whether this Long equals the other + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long equals the other + */ +Long.prototype.equals = function(other) { + return this.high_ === other.high_ && this.low_ === other.low_; }; -Promise.prototype._cancelPromises = function() { - if (this._length() > 0) this._settlePromises(); +/** + * Return whether this Long does not equal the other. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long does not equal the other. + */ +Long.prototype.notEquals = function(other) { + return this.high_ !== other.high_ || this.low_ !== other.low_; }; -Promise.prototype._unsetOnCancel = function() { - this._onCancelField = undefined; +/** + * Return whether this Long is less than the other. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long is less than the other. + */ +Long.prototype.lessThan = function(other) { + return this.compare(other) < 0; }; -Promise.prototype._isCancellable = function() { - return this.isPending() && !this._isCancelled(); +/** + * Return whether this Long is less than or equal to the other. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long is less than or equal to the other. + */ +Long.prototype.lessThanOrEqual = function(other) { + return this.compare(other) <= 0; }; -Promise.prototype.isCancellable = function() { - return this.isPending() && !this.isCancelled(); +/** + * Return whether this Long is greater than the other. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long is greater than the other. + */ +Long.prototype.greaterThan = function(other) { + return this.compare(other) > 0; }; -Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) { - if (util.isArray(onCancelCallback)) { - for (var i = 0; i < onCancelCallback.length; ++i) { - this._doInvokeOnCancel(onCancelCallback[i], internalOnly); - } - } else if (onCancelCallback !== undefined) { - if (typeof onCancelCallback === "function") { - if (!internalOnly) { - var e = tryCatch(onCancelCallback).call(this._boundValue()); - if (e === errorObj) { - this._attachExtraTrace(e.e); - async.throwLater(e.e); - } - } - } else { - onCancelCallback._resultCancelled(this); - } - } +/** + * Return whether this Long is greater than or equal to the other. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} whether this Long is greater than or equal to the other. + */ +Long.prototype.greaterThanOrEqual = function(other) { + return this.compare(other) >= 0; }; -Promise.prototype._invokeOnCancel = function() { - var onCancelCallback = this._onCancel(); - this._unsetOnCancel(); - async.invoke(this._doInvokeOnCancel, this, onCancelCallback); -}; +/** + * Compares this Long with the given one. + * + * @method + * @param {Long} other Long to compare against. + * @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater. + */ +Long.prototype.compare = function(other) { + if (this.equals(other)) { + return 0; + } -Promise.prototype._invokeInternalOnCancel = function() { - if (this._isCancellable()) { - this._doInvokeOnCancel(this._onCancel(), true); - this._unsetOnCancel(); - } -}; + var thisNeg = this.isNegative(); + var otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) { + return -1; + } + if (!thisNeg && otherNeg) { + return 1; + } -Promise.prototype._resultCancelled = function() { - this.cancel(); + // at this point, the signs are the same, so subtraction will not overflow + if (this.subtract(other).isNegative()) { + return -1; + } else { + return 1; + } }; +/** + * The negation of this value. + * + * @method + * @return {Long} the negation of this value. + */ +Long.prototype.negate = function() { + if (this.equals(Long.MIN_VALUE)) { + return Long.MIN_VALUE; + } else { + return this.not().add(Long.ONE); + } }; -},{"./util":36}],7:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(NEXT_FILTER) { -var util = _dereq_("./util"); -var getKeys = _dereq_("./es5").keys; -var tryCatch = util.tryCatch; -var errorObj = util.errorObj; +/** + * Returns the sum of this and the given Long. + * + * @method + * @param {Long} other Long to add to this one. + * @return {Long} the sum of this and the given Long. + */ +Long.prototype.add = function(other) { + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. -function catchFilter(instances, cb, promise) { - return function(e) { - var boundTo = promise._boundValue(); - predicateLoop: for (var i = 0; i < instances.length; ++i) { - var item = instances[i]; + var a48 = this.high_ >>> 16; + var a32 = this.high_ & 0xffff; + var a16 = this.low_ >>> 16; + var a00 = this.low_ & 0xffff; - if (item === Error || - (item != null && item.prototype instanceof Error)) { - if (e instanceof item) { - return tryCatch(cb).call(boundTo, e); - } - } else if (typeof item === "function") { - var matchesPredicate = tryCatch(item).call(boundTo, e); - if (matchesPredicate === errorObj) { - return matchesPredicate; - } else if (matchesPredicate) { - return tryCatch(cb).call(boundTo, e); - } - } else if (util.isObject(e)) { - var keys = getKeys(item); - for (var j = 0; j < keys.length; ++j) { - var key = keys[j]; - if (item[key] != e[key]) { - continue predicateLoop; - } - } - return tryCatch(cb).call(boundTo, e); - } - } - return NEXT_FILTER; - }; -} + var b48 = other.high_ >>> 16; + var b32 = other.high_ & 0xffff; + var b16 = other.low_ >>> 16; + var b00 = other.low_ & 0xffff; -return catchFilter; + var c48 = 0, + c32 = 0, + c16 = 0, + c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xffff; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xffff; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xffff; + c48 += a48 + b48; + c48 &= 0xffff; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); }; -},{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise) { -var longStackTraces = false; -var contextStack = []; - -Promise.prototype._promiseCreated = function() {}; -Promise.prototype._pushContext = function() {}; -Promise.prototype._popContext = function() {return null;}; -Promise._peekContext = Promise.prototype._peekContext = function() {}; - -function Context() { - this._trace = new Context.CapturedTrace(peekContext()); -} -Context.prototype._pushContext = function () { - if (this._trace !== undefined) { - this._trace._promiseCreated = null; - contextStack.push(this._trace); - } +/** + * Returns the difference of this and the given Long. + * + * @method + * @param {Long} other Long to subtract from this. + * @return {Long} the difference of this and the given Long. + */ +Long.prototype.subtract = function(other) { + return this.add(other.negate()); }; -Context.prototype._popContext = function () { - if (this._trace !== undefined) { - var trace = contextStack.pop(); - var ret = trace._promiseCreated; - trace._promiseCreated = null; - return ret; - } - return null; -}; +/** + * Returns the product of this and the given Long. + * + * @method + * @param {Long} other Long to multiply with this. + * @return {Long} the product of this and the other. + */ +Long.prototype.multiply = function(other) { + if (this.isZero()) { + return Long.ZERO; + } else if (other.isZero()) { + return Long.ZERO; + } -function createContext() { - if (longStackTraces) return new Context(); -} + if (this.equals(Long.MIN_VALUE)) { + return other.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } else if (other.equals(Long.MIN_VALUE)) { + return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } -function peekContext() { - var lastIndex = contextStack.length - 1; - if (lastIndex >= 0) { - return contextStack[lastIndex]; + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().multiply(other.negate()); + } else { + return this.negate() + .multiply(other) + .negate(); } - return undefined; -} -Context.CapturedTrace = null; -Context.create = createContext; -Context.deactivateLongStackTraces = function() {}; -Context.activateLongStackTraces = function() { - var Promise_pushContext = Promise.prototype._pushContext; - var Promise_popContext = Promise.prototype._popContext; - var Promise_PeekContext = Promise._peekContext; - var Promise_peekContext = Promise.prototype._peekContext; - var Promise_promiseCreated = Promise.prototype._promiseCreated; - Context.deactivateLongStackTraces = function() { - Promise.prototype._pushContext = Promise_pushContext; - Promise.prototype._popContext = Promise_popContext; - Promise._peekContext = Promise_PeekContext; - Promise.prototype._peekContext = Promise_peekContext; - Promise.prototype._promiseCreated = Promise_promiseCreated; - longStackTraces = false; - }; - longStackTraces = true; - Promise.prototype._pushContext = Context.prototype._pushContext; - Promise.prototype._popContext = Context.prototype._popContext; - Promise._peekContext = Promise.prototype._peekContext = peekContext; - Promise.prototype._promiseCreated = function() { - var ctx = this._peekContext(); - if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this; - }; -}; -return Context; -}; + } else if (other.isNegative()) { + return this.multiply(other.negate()).negate(); + } -},{}],9:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, Context) { -var getDomain = Promise._getDomain; -var async = Promise._async; -var Warning = _dereq_("./errors").Warning; -var util = _dereq_("./util"); -var canAttachTrace = util.canAttachTrace; -var unhandledRejectionHandled; -var possiblyUnhandledRejection; -var bluebirdFramePattern = - /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/; -var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/; -var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/; -var stackFramePattern = null; -var formatStack = null; -var indentStackFrames = false; -var printWarning; -var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 && - (true || - util.env("BLUEBIRD_DEBUG") || - util.env("NODE_ENV") === "development")); + // If both Longs are small, use float multiplication + if (this.lessThan(Long.TWO_PWR_24_) && other.lessThan(Long.TWO_PWR_24_)) { + return Long.fromNumber(this.toNumber() * other.toNumber()); + } -var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 && - (debugging || util.env("BLUEBIRD_WARNINGS"))); + // Divide each Long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. -var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 && - (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES"))); + var a48 = this.high_ >>> 16; + var a32 = this.high_ & 0xffff; + var a16 = this.low_ >>> 16; + var a00 = this.low_ & 0xffff; -var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 && - (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN")); + var b48 = other.high_ >>> 16; + var b32 = other.high_ & 0xffff; + var b16 = other.low_ >>> 16; + var b00 = other.low_ & 0xffff; -Promise.prototype.suppressUnhandledRejections = function() { - var target = this._target(); - target._bitField = ((target._bitField & (~1048576)) | - 524288); + var c48 = 0, + c32 = 0, + c16 = 0, + c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xffff; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xffff; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xffff; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xffff; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xffff; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xffff; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xffff; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); }; -Promise.prototype._ensurePossibleRejectionHandled = function () { - if ((this._bitField & 524288) !== 0) return; - this._setRejectionIsUnhandled(); - var self = this; - setTimeout(function() { - self._notifyUnhandledRejection(); - }, 1); -}; +/** + * Returns this Long divided by the given one. + * + * @method + * @param {Long} other Long by which to divide. + * @return {Long} this Long divided by the given one. + */ +Long.prototype.div = function(other) { + if (other.isZero()) { + throw Error('division by zero'); + } else if (this.isZero()) { + return Long.ZERO; + } -Promise.prototype._notifyUnhandledRejectionIsHandled = function () { - fireRejectionEvent("rejectionHandled", - unhandledRejectionHandled, undefined, this); -}; + if (this.equals(Long.MIN_VALUE)) { + if (other.equals(Long.ONE) || other.equals(Long.NEG_ONE)) { + return Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ONE; + } else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shiftRight(1); + var approx = halfThis.div(other).shiftLeft(1); + if (approx.equals(Long.ZERO)) { + return other.isNegative() ? Long.ONE : Long.NEG_ONE; + } else { + var rem = this.subtract(other.multiply(approx)); + var result = approx.add(rem.div(other)); + return result; + } + } + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ZERO; + } -Promise.prototype._setReturnedNonUndefined = function() { - this._bitField = this._bitField | 268435456; -}; + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().div(other.negate()); + } else { + return this.negate() + .div(other) + .negate(); + } + } else if (other.isNegative()) { + return this.div(other.negate()).negate(); + } -Promise.prototype._returnedNonUndefined = function() { - return (this._bitField & 268435456) !== 0; -}; + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + var res = Long.ZERO; + rem = this; + while (rem.greaterThanOrEqual(other)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); -Promise.prototype._notifyUnhandledRejection = function () { - if (this._isRejectionUnhandled()) { - var reason = this._settledValue(); - this._setUnhandledRejectionIsNotified(); - fireRejectionEvent("unhandledRejection", - possiblyUnhandledRejection, reason, this); + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2); + var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + var approxRes = Long.fromNumber(approx); + var approxRem = approxRes.multiply(other); + while (approxRem.isNegative() || approxRem.greaterThan(rem)) { + approx -= delta; + approxRes = Long.fromNumber(approx); + approxRem = approxRes.multiply(other); } -}; -Promise.prototype._setUnhandledRejectionIsNotified = function () { - this._bitField = this._bitField | 262144; -}; + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) { + approxRes = Long.ONE; + } -Promise.prototype._unsetUnhandledRejectionIsNotified = function () { - this._bitField = this._bitField & (~262144); + res = res.add(approxRes); + rem = rem.subtract(approxRem); + } + return res; }; -Promise.prototype._isUnhandledRejectionNotified = function () { - return (this._bitField & 262144) > 0; +/** + * Returns this Long modulo the given one. + * + * @method + * @param {Long} other Long by which to mod. + * @return {Long} this Long modulo the given one. + */ +Long.prototype.modulo = function(other) { + return this.subtract(this.div(other).multiply(other)); }; -Promise.prototype._setRejectionIsUnhandled = function () { - this._bitField = this._bitField | 1048576; +/** + * The bitwise-NOT of this value. + * + * @method + * @return {Long} the bitwise-NOT of this value. + */ +Long.prototype.not = function() { + return Long.fromBits(~this.low_, ~this.high_); }; -Promise.prototype._unsetRejectionIsUnhandled = function () { - this._bitField = this._bitField & (~1048576); - if (this._isUnhandledRejectionNotified()) { - this._unsetUnhandledRejectionIsNotified(); - this._notifyUnhandledRejectionIsHandled(); - } +/** + * Returns the bitwise-AND of this Long and the given one. + * + * @method + * @param {Long} other the Long with which to AND. + * @return {Long} the bitwise-AND of this and the other. + */ +Long.prototype.and = function(other) { + return Long.fromBits(this.low_ & other.low_, this.high_ & other.high_); }; -Promise.prototype._isRejectionUnhandled = function () { - return (this._bitField & 1048576) > 0; +/** + * Returns the bitwise-OR of this Long and the given one. + * + * @method + * @param {Long} other the Long with which to OR. + * @return {Long} the bitwise-OR of this and the other. + */ +Long.prototype.or = function(other) { + return Long.fromBits(this.low_ | other.low_, this.high_ | other.high_); }; -Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) { - return warn(message, shouldUseOwnTrace, promise || this); +/** + * Returns the bitwise-XOR of this Long and the given one. + * + * @method + * @param {Long} other the Long with which to XOR. + * @return {Long} the bitwise-XOR of this and the other. + */ +Long.prototype.xor = function(other) { + return Long.fromBits(this.low_ ^ other.low_, this.high_ ^ other.high_); }; -Promise.onPossiblyUnhandledRejection = function (fn) { - var domain = getDomain(); - possiblyUnhandledRejection = - typeof fn === "function" ? (domain === null ? - fn : util.domainBind(domain, fn)) - : undefined; +/** + * Returns this Long with bits shifted to the left by the given amount. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Long} this shifted to the left by the given amount. + */ +Long.prototype.shiftLeft = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var low = this.low_; + if (numBits < 32) { + var high = this.high_; + return Long.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits))); + } else { + return Long.fromBits(0, low << (numBits - 32)); + } + } }; -Promise.onUnhandledRejectionHandled = function (fn) { - var domain = getDomain(); - unhandledRejectionHandled = - typeof fn === "function" ? (domain === null ? - fn : util.domainBind(domain, fn)) - : undefined; +/** + * Returns this Long with bits shifted to the right by the given amount. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Long} this shifted to the right by the given amount. + */ +Long.prototype.shiftRight = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var high = this.high_; + if (numBits < 32) { + var low = this.low_; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits); + } else { + return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1); + } + } }; -var disableLongStackTraces = function() {}; -Promise.longStackTraces = function () { - if (async.haveItemsQueued() && !config.longStackTraces) { - throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - if (!config.longStackTraces && longStackTracesIsSupported()) { - var Promise_captureStackTrace = Promise.prototype._captureStackTrace; - var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace; - config.longStackTraces = true; - disableLongStackTraces = function() { - if (async.haveItemsQueued() && !config.longStackTraces) { - throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - Promise.prototype._captureStackTrace = Promise_captureStackTrace; - Promise.prototype._attachExtraTrace = Promise_attachExtraTrace; - Context.deactivateLongStackTraces(); - async.enableTrampoline(); - config.longStackTraces = false; - }; - Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace; - Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace; - Context.activateLongStackTraces(); - async.disableTrampolineIfNecessary(); +/** + * Returns this Long with bits shifted to the right by the given amount, with the new top bits matching the current sign bit. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Long} this shifted to the right by the given amount, with zeros placed into the new leading bits. + */ +Long.prototype.shiftRightUnsigned = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var high = this.high_; + if (numBits < 32) { + var low = this.low_; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits); + } else if (numBits === 32) { + return Long.fromBits(high, 0); + } else { + return Long.fromBits(high >>> (numBits - 32), 0); } + } }; -Promise.hasLongStackTraces = function () { - return config.longStackTraces && longStackTracesIsSupported(); -}; +/** + * Returns a Long representing the given (32-bit) integer value. + * + * @method + * @param {number} value the 32-bit integer in question. + * @return {Long} the corresponding Long value. + */ +Long.fromInt = function(value) { + if (-128 <= value && value < 128) { + var cachedObj = Long.INT_CACHE_[value]; + if (cachedObj) { + return cachedObj; + } + } -var fireDomEvent = (function() { - try { - if (typeof CustomEvent === "function") { - var event = new CustomEvent("CustomEvent"); - util.global.dispatchEvent(event); - return function(name, event) { - var domEvent = new CustomEvent(name.toLowerCase(), { - detail: event, - cancelable: true - }); - return !util.global.dispatchEvent(domEvent); - }; - } else if (typeof Event === "function") { - var event = new Event("CustomEvent"); - util.global.dispatchEvent(event); - return function(name, event) { - var domEvent = new Event(name.toLowerCase(), { - cancelable: true - }); - domEvent.detail = event; - return !util.global.dispatchEvent(domEvent); - }; - } else { - var event = document.createEvent("CustomEvent"); - event.initCustomEvent("testingtheevent", false, true, {}); - util.global.dispatchEvent(event); - return function(name, event) { - var domEvent = document.createEvent("CustomEvent"); - domEvent.initCustomEvent(name.toLowerCase(), false, true, - event); - return !util.global.dispatchEvent(domEvent); - }; - } - } catch (e) {} - return function() { - return false; - }; -})(); + var obj = new Long(value | 0, value < 0 ? -1 : 0); + if (-128 <= value && value < 128) { + Long.INT_CACHE_[value] = obj; + } + return obj; +}; -var fireGlobalEvent = (function() { - if (util.isNode) { - return function() { - return process.emit.apply(process, arguments); - }; - } else { - if (!util.global) { - return function() { - return false; - }; - } - return function(name) { - var methodName = "on" + name.toLowerCase(); - var method = util.global[methodName]; - if (!method) return false; - method.apply(util.global, [].slice.call(arguments, 1)); - return true; - }; - } -})(); +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * + * @method + * @param {number} value the number in question. + * @return {Long} the corresponding Long value. + */ +Long.fromNumber = function(value) { + if (isNaN(value) || !isFinite(value)) { + return Long.ZERO; + } else if (value <= -Long.TWO_PWR_63_DBL_) { + return Long.MIN_VALUE; + } else if (value + 1 >= Long.TWO_PWR_63_DBL_) { + return Long.MAX_VALUE; + } else if (value < 0) { + return Long.fromNumber(-value).negate(); + } else { + return new Long((value % Long.TWO_PWR_32_DBL_) | 0, (value / Long.TWO_PWR_32_DBL_) | 0); + } +}; -function generatePromiseLifecycleEventObject(name, promise) { - return {promise: promise}; +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * @param {bigint} value - The number in question + * @returns {Long} The corresponding Long value + */ +Long.fromBigInt = function(value) { + return Long.fromString(value.toString(10), 10); } -var eventToObjectGenerator = { - promiseCreated: generatePromiseLifecycleEventObject, - promiseFulfilled: generatePromiseLifecycleEventObject, - promiseRejected: generatePromiseLifecycleEventObject, - promiseResolved: generatePromiseLifecycleEventObject, - promiseCancelled: generatePromiseLifecycleEventObject, - promiseChained: function(name, promise, child) { - return {promise: promise, child: child}; - }, - warning: function(name, warning) { - return {warning: warning}; - }, - unhandledRejection: function (name, reason, promise) { - return {reason: reason, promise: promise}; - }, - rejectionHandled: generatePromiseLifecycleEventObject +/** + * Returns a Long representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits. + * + * @method + * @param {number} lowBits the low 32-bits. + * @param {number} highBits the high 32-bits. + * @return {Long} the corresponding Long value. + */ +Long.fromBits = function(lowBits, highBits) { + return new Long(lowBits, highBits); }; -var activeFireEvent = function (name) { - var globalEventFired = false; - try { - globalEventFired = fireGlobalEvent.apply(null, arguments); - } catch (e) { - async.throwLater(e); - globalEventFired = true; - } +/** + * Returns a Long representation of the given string, written using the given radix. + * + * @method + * @param {string} str the textual representation of the Long. + * @param {number} opt_radix the radix in which the text is written. + * @return {Long} the corresponding Long value. + */ +Long.fromString = function(str, opt_radix) { + if (str.length === 0) { + throw Error('number format error: empty string'); + } - var domEventFired = false; - try { - domEventFired = fireDomEvent(name, - eventToObjectGenerator[name].apply(null, arguments)); - } catch (e) { - async.throwLater(e); - domEventFired = true; - } + var radix = opt_radix || 10; + if (radix < 2 || 36 < radix) { + throw Error('radix out of range: ' + radix); + } - return domEventFired || globalEventFired; -}; + if (str.charAt(0) === '-') { + return Long.fromString(str.substring(1), radix).negate(); + } else if (str.indexOf('-') >= 0) { + throw Error('number format error: interior "-" character: ' + str); + } -Promise.config = function(opts) { - opts = Object(opts); - if ("longStackTraces" in opts) { - if (opts.longStackTraces) { - Promise.longStackTraces(); - } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) { - disableLongStackTraces(); - } - } - if ("warnings" in opts) { - var warningsOption = opts.warnings; - config.warnings = !!warningsOption; - wForgottenReturn = config.warnings; + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 8)); - if (util.isObject(warningsOption)) { - if ("wForgottenReturn" in warningsOption) { - wForgottenReturn = !!warningsOption.wForgottenReturn; - } - } + var result = Long.ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i); + var value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = Long.fromNumber(Math.pow(radix, size)); + result = result.multiply(power).add(Long.fromNumber(value)); + } else { + result = result.multiply(radixToPower); + result = result.add(Long.fromNumber(value)); } - if ("cancellation" in opts && opts.cancellation && !config.cancellation) { - if (async.haveItemsQueued()) { - throw new Error( - "cannot enable cancellation after promises are in use"); - } - Promise.prototype._clearCancellationData = - cancellationClearCancellationData; - Promise.prototype._propagateFrom = cancellationPropagateFrom; - Promise.prototype._onCancel = cancellationOnCancel; - Promise.prototype._setOnCancel = cancellationSetOnCancel; - Promise.prototype._attachCancellationCallback = - cancellationAttachCancellationCallback; - Promise.prototype._execute = cancellationExecute; - propagateFromFunction = cancellationPropagateFrom; - config.cancellation = true; - } - if ("monitoring" in opts) { - if (opts.monitoring && !config.monitoring) { - config.monitoring = true; - Promise.prototype._fireEvent = activeFireEvent; - } else if (!opts.monitoring && config.monitoring) { - config.monitoring = false; - Promise.prototype._fireEvent = defaultFireEvent; - } - } - return Promise; + } + return result; }; -function defaultFireEvent() { return false; } +// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the +// from* methods on which they depend. -Promise.prototype._fireEvent = defaultFireEvent; -Promise.prototype._execute = function(executor, resolve, reject) { - try { - executor(resolve, reject); - } catch (e) { - return e; - } -}; -Promise.prototype._onCancel = function () {}; -Promise.prototype._setOnCancel = function (handler) { ; }; -Promise.prototype._attachCancellationCallback = function(onCancel) { - ; -}; -Promise.prototype._captureStackTrace = function () {}; -Promise.prototype._attachExtraTrace = function () {}; -Promise.prototype._clearCancellationData = function() {}; -Promise.prototype._propagateFrom = function (parent, flags) { - ; - ; -}; +/** + * A cache of the Long representations of small integer values. + * @type {Object} + * @ignore + */ +Long.INT_CACHE_ = {}; -function cancellationExecute(executor, resolve, reject) { - var promise = this; - try { - executor(resolve, reject, function(onCancel) { - if (typeof onCancel !== "function") { - throw new TypeError("onCancel must be a function, got: " + - util.toString(onCancel)); - } - promise._attachCancellationCallback(onCancel); - }); - } catch (e) { - return e; - } -} +// NOTE: the compiler should inline these constant values below and then remove +// these variables, so there should be no runtime penalty for these. -function cancellationAttachCancellationCallback(onCancel) { - if (!this._isCancellable()) return this; +/** + * Number used repeated below in calculations. This must appear before the + * first call to any from* function below. + * @type {number} + * @ignore + */ +Long.TWO_PWR_16_DBL_ = 1 << 16; - var previousOnCancel = this._onCancel(); - if (previousOnCancel !== undefined) { - if (util.isArray(previousOnCancel)) { - previousOnCancel.push(onCancel); - } else { - this._setOnCancel([previousOnCancel, onCancel]); - } - } else { - this._setOnCancel(onCancel); - } -} +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_24_DBL_ = 1 << 24; -function cancellationOnCancel() { - return this._onCancelField; -} +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_32_DBL_ = Long.TWO_PWR_16_DBL_ * Long.TWO_PWR_16_DBL_; -function cancellationSetOnCancel(onCancel) { - this._onCancelField = onCancel; -} +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_31_DBL_ = Long.TWO_PWR_32_DBL_ / 2; -function cancellationClearCancellationData() { - this._cancellationParent = undefined; - this._onCancelField = undefined; -} +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_48_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_16_DBL_; -function cancellationPropagateFrom(parent, flags) { - if ((flags & 1) !== 0) { - this._cancellationParent = parent; - var branchesRemainingToCancel = parent._branchesRemainingToCancel; - if (branchesRemainingToCancel === undefined) { - branchesRemainingToCancel = 0; - } - parent._branchesRemainingToCancel = branchesRemainingToCancel + 1; - } - if ((flags & 2) !== 0 && parent._isBound()) { - this._setBoundTo(parent._boundTo); - } -} +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_64_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_32_DBL_; -function bindingPropagateFrom(parent, flags) { - if ((flags & 2) !== 0 && parent._isBound()) { - this._setBoundTo(parent._boundTo); - } -} -var propagateFromFunction = bindingPropagateFrom; +/** + * @type {number} + * @ignore + */ +Long.TWO_PWR_63_DBL_ = Long.TWO_PWR_64_DBL_ / 2; -function boundValueFunction() { - var ret = this._boundTo; - if (ret !== undefined) { - if (ret instanceof Promise) { - if (ret.isFulfilled()) { - return ret.value(); - } else { - return undefined; - } - } - } - return ret; -} +/** @type {Long} */ +Long.ZERO = Long.fromInt(0); -function longStackTracesCaptureStackTrace() { - this._trace = new CapturedTrace(this._peekContext()); -} +/** @type {Long} */ +Long.ONE = Long.fromInt(1); -function longStackTracesAttachExtraTrace(error, ignoreSelf) { - if (canAttachTrace(error)) { - var trace = this._trace; - if (trace !== undefined) { - if (ignoreSelf) trace = trace._parent; - } - if (trace !== undefined) { - trace.attachExtraTrace(error); - } else if (!error.__stackCleaned__) { - var parsed = parseStackAndMessage(error); - util.notEnumerableProp(error, "stack", - parsed.message + "\n" + parsed.stack.join("\n")); - util.notEnumerableProp(error, "__stackCleaned__", true); - } - } -} +/** @type {Long} */ +Long.NEG_ONE = Long.fromInt(-1); -function checkForgottenReturns(returnValue, promiseCreated, name, promise, - parent) { - if (returnValue === undefined && promiseCreated !== null && - wForgottenReturn) { - if (parent !== undefined && parent._returnedNonUndefined()) return; - if ((promise._bitField & 65535) === 0) return; +/** @type {Long} */ +Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0); - if (name) name = name + " "; - var handlerLine = ""; - var creatorLine = ""; - if (promiseCreated._trace) { - var traceLines = promiseCreated._trace.stack.split("\n"); - var stack = cleanStack(traceLines); - for (var i = stack.length - 1; i >= 0; --i) { - var line = stack[i]; - if (!nodeFramePattern.test(line)) { - var lineMatches = line.match(parseLinePattern); - if (lineMatches) { - handlerLine = "at " + lineMatches[1] + - ":" + lineMatches[2] + ":" + lineMatches[3] + " "; - } - break; - } - } +/** @type {Long} */ +Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0); - if (stack.length > 0) { - var firstUserLine = stack[0]; - for (var i = 0; i < traceLines.length; ++i) { +/** + * @type {Long} + * @ignore + */ +Long.TWO_PWR_24_ = Long.fromInt(1 << 24); - if (traceLines[i] === firstUserLine) { - if (i > 0) { - creatorLine = "\n" + traceLines[i - 1]; - } - break; - } - } +/** + * Expose. + */ +module.exports = Long; +module.exports.Long = Long; - } - } - var msg = "a promise was created in a " + name + - "handler " + handlerLine + "but was not returned from it, " + - "see http://goo.gl/rRqMUw" + - creatorLine; - promise._warn(msg, true, promiseCreated); - } -} +},{}],24:[function(require,module,exports){ +(function (global){(function (){ +'use strict'; -function deprecated(name, replacement) { - var message = name + - " is deprecated and will be removed in a future version."; - if (replacement) message += " Use " + replacement + " instead."; - return warn(message); -} +// We have an ES6 Map available, return the native instance +if (typeof global.Map !== 'undefined') { + module.exports = global.Map; + module.exports.Map = global.Map; +} else { + // We will return a polyfill + var Map = function(array) { + this._keys = []; + this._values = {}; -function warn(message, shouldUseOwnTrace, promise) { - if (!config.warnings) return; - var warning = new Warning(message); - var ctx; - if (shouldUseOwnTrace) { - promise._attachExtraTrace(warning); - } else if (config.longStackTraces && (ctx = Promise._peekContext())) { - ctx.attachExtraTrace(warning); - } else { - var parsed = parseStackAndMessage(warning); - warning.stack = parsed.message + "\n" + parsed.stack.join("\n"); + for (var i = 0; i < array.length; i++) { + if (array[i] == null) continue; // skip null and undefined + var entry = array[i]; + var key = entry[0]; + var value = entry[1]; + // Add the key to the list of keys in order + this._keys.push(key); + // Add the key and value to the values dictionary with a point + // to the location in the ordered keys list + this._values[key] = { v: value, i: this._keys.length - 1 }; } + }; - if (!activeFireEvent("warning", warning)) { - formatAndLogError(warning, "", true); - } -} + Map.prototype.clear = function() { + this._keys = []; + this._values = {}; + }; -function reconstructStack(message, stacks) { - for (var i = 0; i < stacks.length - 1; ++i) { - stacks[i].push("From previous event:"); - stacks[i] = stacks[i].join("\n"); - } - if (i < stacks.length) { - stacks[i] = stacks[i].join("\n"); - } - return message + "\n" + stacks.join("\n"); -} + Map.prototype.delete = function(key) { + var value = this._values[key]; + if (value == null) return false; + // Delete entry + delete this._values[key]; + // Remove the key from the ordered keys list + this._keys.splice(value.i, 1); + return true; + }; -function removeDuplicateOrEmptyJumps(stacks) { - for (var i = 0; i < stacks.length; ++i) { - if (stacks[i].length === 0 || - ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) { - stacks.splice(i, 1); - i--; - } - } -} + Map.prototype.entries = function() { + var self = this; + var index = 0; -function removeCommonRoots(stacks) { - var current = stacks[0]; - for (var i = 1; i < stacks.length; ++i) { - var prev = stacks[i]; - var currentLastIndex = current.length - 1; - var currentLastLine = current[currentLastIndex]; - var commonRootMeetPoint = -1; + return { + next: function() { + var key = self._keys[index++]; + return { + value: key !== undefined ? [key, self._values[key].v] : undefined, + done: key !== undefined ? false : true + }; + } + }; + }; - for (var j = prev.length - 1; j >= 0; --j) { - if (prev[j] === currentLastLine) { - commonRootMeetPoint = j; - break; - } - } + Map.prototype.forEach = function(callback, self) { + self = self || this; - for (var j = commonRootMeetPoint; j >= 0; --j) { - var line = prev[j]; - if (current[currentLastIndex] === line) { - current.pop(); - currentLastIndex--; - } else { - break; - } - } - current = prev; + for (var i = 0; i < this._keys.length; i++) { + var key = this._keys[i]; + // Call the forEach callback + callback.call(self, this._values[key].v, key, self); } -} + }; -function cleanStack(stack) { - var ret = []; - for (var i = 0; i < stack.length; ++i) { - var line = stack[i]; - var isTraceLine = " (No stack trace)" === line || - stackFramePattern.test(line); - var isInternalFrame = isTraceLine && shouldIgnore(line); - if (isTraceLine && !isInternalFrame) { - if (indentStackFrames && line.charAt(0) !== " ") { - line = " " + line; - } - ret.push(line); - } - } - return ret; -} + Map.prototype.get = function(key) { + return this._values[key] ? this._values[key].v : undefined; + }; -function stackFramesAsArray(error) { - var stack = error.stack.replace(/\s+$/g, "").split("\n"); - for (var i = 0; i < stack.length; ++i) { - var line = stack[i]; - if (" (No stack trace)" === line || stackFramePattern.test(line)) { - break; - } - } - if (i > 0 && error.name != "SyntaxError") { - stack = stack.slice(i); - } - return stack; -} + Map.prototype.has = function(key) { + return this._values[key] != null; + }; + + Map.prototype.keys = function() { + var self = this; + var index = 0; -function parseStackAndMessage(error) { - var stack = error.stack; - var message = error.toString(); - stack = typeof stack === "string" && stack.length > 0 - ? stackFramesAsArray(error) : [" (No stack trace)"]; return { - message: message, - stack: error.name == "SyntaxError" ? stack : cleanStack(stack) + next: function() { + var key = self._keys[index++]; + return { + value: key !== undefined ? key : undefined, + done: key !== undefined ? false : true + }; + } }; -} + }; -function formatAndLogError(error, title, isSoft) { - if (typeof console !== "undefined") { - var message; - if (util.isObject(error)) { - var stack = error.stack; - message = title + formatStack(stack, error); - } else { - message = title + String(error); - } - if (typeof printWarning === "function") { - printWarning(message, isSoft); - } else if (typeof console.log === "function" || - typeof console.log === "object") { - console.log(message); - } + Map.prototype.set = function(key, value) { + if (this._values[key]) { + this._values[key].v = value; + return this; } -} -function fireRejectionEvent(name, localHandler, reason, promise) { - var localEventFired = false; - try { - if (typeof localHandler === "function") { - localEventFired = true; - if (name === "rejectionHandled") { - localHandler(promise); - } else { - localHandler(reason, promise); - } - } - } catch (e) { - async.throwLater(e); - } + // Add the key to the list of keys in order + this._keys.push(key); + // Add the key and value to the values dictionary with a point + // to the location in the ordered keys list + this._values[key] = { v: value, i: this._keys.length - 1 }; + return this; + }; - if (name === "unhandledRejection") { - if (!activeFireEvent(name, reason, promise) && !localEventFired) { - formatAndLogError(reason, "Unhandled rejection "); - } - } else { - activeFireEvent(name, promise); - } -} + Map.prototype.values = function() { + var self = this; + var index = 0; -function formatNonError(obj) { - var str; - if (typeof obj === "function") { - str = "[function " + - (obj.name || "anonymous") + - "]"; - } else { - str = obj && typeof obj.toString === "function" - ? obj.toString() : util.toString(obj); - var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; - if (ruselessToString.test(str)) { - try { - var newStr = JSON.stringify(obj); - str = newStr; - } - catch(e) { + return { + next: function() { + var key = self._keys[index++]; + return { + value: key !== undefined ? self._values[key].v : undefined, + done: key !== undefined ? false : true + }; + } + }; + }; - } - } - if (str.length === 0) { - str = "(empty array)"; - } + // Last ismaster + Object.defineProperty(Map.prototype, 'size', { + enumerable: true, + get: function() { + return this._keys.length; } - return ("(<" + snip(str) + ">, no stack trace)"); + }); + + module.exports = Map; + module.exports.Map = Map; } -function snip(str) { - var maxChars = 41; - if (str.length < maxChars) { - return str; - } - return str.substr(0, maxChars - 3) + "..."; -} - -function longStackTracesIsSupported() { - return typeof captureStackTrace === "function"; -} +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],25:[function(require,module,exports){ +/** + * A class representation of the BSON MaxKey type. + * + * @class + * @return {MaxKey} A MaxKey instance + */ +function MaxKey() { + if (!(this instanceof MaxKey)) return new MaxKey(); -var shouldIgnore = function() { return false; }; -var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/; -function parseLineInfo(line) { - var matches = line.match(parseLineInfoRegex); - if (matches) { - return { - fileName: matches[1], - line: parseInt(matches[2], 10) - }; - } + this._bsontype = 'MaxKey'; } -function setBounds(firstLineError, lastLineError) { - if (!longStackTracesIsSupported()) return; - var firstStackLines = firstLineError.stack.split("\n"); - var lastStackLines = lastLineError.stack.split("\n"); - var firstIndex = -1; - var lastIndex = -1; - var firstFileName; - var lastFileName; - for (var i = 0; i < firstStackLines.length; ++i) { - var result = parseLineInfo(firstStackLines[i]); - if (result) { - firstFileName = result.fileName; - firstIndex = result.line; - break; - } - } - for (var i = 0; i < lastStackLines.length; ++i) { - var result = parseLineInfo(lastStackLines[i]); - if (result) { - lastFileName = result.fileName; - lastIndex = result.line; - break; - } - } - if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName || - firstFileName !== lastFileName || firstIndex >= lastIndex) { - return; - } +module.exports = MaxKey; +module.exports.MaxKey = MaxKey; - shouldIgnore = function(line) { - if (bluebirdFramePattern.test(line)) return true; - var info = parseLineInfo(line); - if (info) { - if (info.fileName === firstFileName && - (firstIndex <= info.line && info.line <= lastIndex)) { - return true; - } - } - return false; - }; -} +},{}],26:[function(require,module,exports){ +/** + * A class representation of the BSON MinKey type. + * + * @class + * @return {MinKey} A MinKey instance + */ +function MinKey() { + if (!(this instanceof MinKey)) return new MinKey(); -function CapturedTrace(parent) { - this._parent = parent; - this._promisesCreated = 0; - var length = this._length = 1 + (parent === undefined ? 0 : parent._length); - captureStackTrace(this, CapturedTrace); - if (length > 32) this.uncycle(); + this._bsontype = 'MinKey'; } -util.inherits(CapturedTrace, Error); -Context.CapturedTrace = CapturedTrace; - -CapturedTrace.prototype.uncycle = function() { - var length = this._length; - if (length < 2) return; - var nodes = []; - var stackToIndex = {}; - - for (var i = 0, node = this; node !== undefined; ++i) { - nodes.push(node); - node = node._parent; - } - length = this._length = i; - for (var i = length - 1; i >= 0; --i) { - var stack = nodes[i].stack; - if (stackToIndex[stack] === undefined) { - stackToIndex[stack] = i; - } - } - for (var i = 0; i < length; ++i) { - var currentStack = nodes[i].stack; - var index = stackToIndex[currentStack]; - if (index !== undefined && index !== i) { - if (index > 0) { - nodes[index - 1]._parent = undefined; - nodes[index - 1]._length = 1; - } - nodes[i]._parent = undefined; - nodes[i]._length = 1; - var cycleEdgeNode = i > 0 ? nodes[i - 1] : this; - if (index < length - 1) { - cycleEdgeNode._parent = nodes[index + 1]; - cycleEdgeNode._parent.uncycle(); - cycleEdgeNode._length = - cycleEdgeNode._parent._length + 1; - } else { - cycleEdgeNode._parent = undefined; - cycleEdgeNode._length = 1; - } - var currentChildLength = cycleEdgeNode._length + 1; - for (var j = i - 2; j >= 0; --j) { - nodes[j]._length = currentChildLength; - currentChildLength++; - } - return; - } - } -}; +module.exports = MinKey; +module.exports.MinKey = MinKey; -CapturedTrace.prototype.attachExtraTrace = function(error) { - if (error.__stackCleaned__) return; - this.uncycle(); - var parsed = parseStackAndMessage(error); - var message = parsed.message; - var stacks = [parsed.stack]; +},{}],27:[function(require,module,exports){ +(function (process,Buffer){(function (){ +// Custom inspect property name / symbol. +var inspect = 'inspect'; - var trace = this; - while (trace !== undefined) { - stacks.push(cleanStack(trace.stack.split("\n"))); - trace = trace._parent; - } - removeCommonRoots(stacks); - removeDuplicateOrEmptyJumps(stacks); - util.notEnumerableProp(error, "stack", reconstructStack(message, stacks)); - util.notEnumerableProp(error, "__stackCleaned__", true); -}; +var utils = require('./parser/utils'); -var captureStackTrace = (function stackDetection() { - var v8stackFramePattern = /^\s*at\s*/; - var v8stackFormatter = function(stack, error) { - if (typeof stack === "string") return stack; +/** + * Machine id. + * + * Create a random 3-byte value (i.e. unique for this + * process). Other drivers use a md5 of the machine id here, but + * that would mean an asyc call to gethostname, so we don't bother. + * @ignore + */ +var MACHINE_ID = parseInt(Math.random() * 0xffffff, 10); - if (error.name !== undefined && - error.message !== undefined) { - return error.toString(); - } - return formatNonError(error); - }; +// Regular expression that checks for hex value +var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); - if (typeof Error.stackTraceLimit === "number" && - typeof Error.captureStackTrace === "function") { - Error.stackTraceLimit += 6; - stackFramePattern = v8stackFramePattern; - formatStack = v8stackFormatter; - var captureStackTrace = Error.captureStackTrace; +// Check if buffer exists +try { + if (Buffer && Buffer.from) { + var hasBufferType = true; + inspect = require('util').inspect.custom || 'inspect'; + } +} catch (err) { + hasBufferType = false; +} - shouldIgnore = function(line) { - return bluebirdFramePattern.test(line); - }; - return function(receiver, ignoreUntil) { - Error.stackTraceLimit += 6; - captureStackTrace(receiver, ignoreUntil); - Error.stackTraceLimit -= 6; - }; - } - var err = new Error(); +/** +* Create a new ObjectID instance +* +* @class +* @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number. +* @property {number} generationTime The generation time of this ObjectId instance +* @return {ObjectID} instance of ObjectID. +*/ +var ObjectID = function ObjectID(id) { + // Duck-typing to support ObjectId from different npm packages + if (id instanceof ObjectID) return id; + if (!(this instanceof ObjectID)) return new ObjectID(id); - if (typeof err.stack === "string" && - err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) { - stackFramePattern = /@/; - formatStack = v8stackFormatter; - indentStackFrames = true; - return function captureStackTrace(o) { - o.stack = new Error().stack; - }; - } + this._bsontype = 'ObjectID'; - var hasStackAfterThrow; - try { throw new Error(); } - catch(e) { - hasStackAfterThrow = ("stack" in e); - } - if (!("stack" in err) && hasStackAfterThrow && - typeof Error.stackTraceLimit === "number") { - stackFramePattern = v8stackFramePattern; - formatStack = v8stackFormatter; - return function captureStackTrace(o) { - Error.stackTraceLimit += 6; - try { throw new Error(); } - catch(e) { o.stack = e.stack; } - Error.stackTraceLimit -= 6; - }; - } + // The most common usecase (blank id, new objectId instance) + if (id == null || typeof id === 'number') { + // Generate a new id + this.id = this.generate(id); + // If we are caching the hex string + if (ObjectID.cacheHexString) this.__id = this.toString('hex'); + // Return the object + return; + } - formatStack = function(stack, error) { - if (typeof stack === "string") return stack; + // Check if the passed in id is valid + var valid = ObjectID.isValid(id); - if ((typeof error === "object" || - typeof error === "function") && - error.name !== undefined && - error.message !== undefined) { - return error.toString(); - } - return formatNonError(error); - }; + // Throw an error if it's not a valid setup + if (!valid && id != null) { + throw new Error( + 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' + ); + } else if (valid && typeof id === 'string' && id.length === 24 && hasBufferType) { + return new ObjectID(utils.toBuffer(id, 'hex')); + } else if (valid && typeof id === 'string' && id.length === 24) { + return ObjectID.createFromHexString(id); + } else if (id != null && id.length === 12) { + // assume 12 byte string + this.id = id; + } else if (id != null && typeof id.toHexString === 'function') { + // Duck-typing to support ObjectId from different npm packages + return id; + } else { + throw new Error( + 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' + ); + } - return null; + if (ObjectID.cacheHexString) this.__id = this.toString('hex'); +}; -})([]); +// Allow usage of ObjectId as well as ObjectID +// var ObjectId = ObjectID; -if (typeof console !== "undefined" && typeof console.warn !== "undefined") { - printWarning = function (message) { - console.warn(message); - }; - if (util.isNode && process.stderr.isTTY) { - printWarning = function(message, isSoft) { - var color = isSoft ? "\u001b[33m" : "\u001b[31m"; - console.warn(color + message + "\u001b[0m\n"); - }; - } else if (!util.isNode && typeof (new Error().stack) === "string") { - printWarning = function(message, isSoft) { - console.warn("%c" + message, - isSoft ? "color: darkorange" : "color: red"); - }; - } +// Precomputed hex table enables speedy hex string conversion +var hexTable = []; +for (var i = 0; i < 256; i++) { + hexTable[i] = (i <= 15 ? '0' : '') + i.toString(16); } -var config = { - warnings: warnings, - longStackTraces: false, - cancellation: false, - monitoring: false -}; - -if (longStackTraces) Promise.longStackTraces(); +/** +* Return the ObjectID id as a 24 byte hex string representation +* +* @method +* @return {string} return the 24 byte hex string representation. +*/ +ObjectID.prototype.toHexString = function() { + if (ObjectID.cacheHexString && this.__id) return this.__id; -return { - longStackTraces: function() { - return config.longStackTraces; - }, - warnings: function() { - return config.warnings; - }, - cancellation: function() { - return config.cancellation; - }, - monitoring: function() { - return config.monitoring; - }, - propagateFromFunction: function() { - return propagateFromFunction; - }, - boundValueFunction: function() { - return boundValueFunction; - }, - checkForgottenReturns: checkForgottenReturns, - setBounds: setBounds, - warn: warn, - deprecated: deprecated, - CapturedTrace: CapturedTrace, - fireDomEvent: fireDomEvent, - fireGlobalEvent: fireGlobalEvent -}; -}; + var hexString = ''; + if (!this.id || !this.id.length) { + throw new Error( + 'invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [' + + JSON.stringify(this.id) + + ']' + ); + } -},{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise) { -function returner() { - return this.value; -} -function thrower() { - throw this.reason; -} + if (this.id instanceof _Buffer) { + hexString = convertToHex(this.id); + if (ObjectID.cacheHexString) this.__id = hexString; + return hexString; + } -Promise.prototype["return"] = -Promise.prototype.thenReturn = function (value) { - if (value instanceof Promise) value.suppressUnhandledRejections(); - return this._then( - returner, undefined, undefined, {value: value}, undefined); -}; + for (var i = 0; i < this.id.length; i++) { + hexString += hexTable[this.id.charCodeAt(i)]; + } -Promise.prototype["throw"] = -Promise.prototype.thenThrow = function (reason) { - return this._then( - thrower, undefined, undefined, {reason: reason}, undefined); + if (ObjectID.cacheHexString) this.__id = hexString; + return hexString; }; -Promise.prototype.catchThrow = function (reason) { - if (arguments.length <= 1) { - return this._then( - undefined, thrower, undefined, {reason: reason}, undefined); - } else { - var _reason = arguments[1]; - var handler = function() {throw _reason;}; - return this.caught(reason, handler); - } +/** +* Update the ObjectID index used in generating new ObjectID's on the driver +* +* @method +* @return {number} returns next index value. +* @ignore +*/ +ObjectID.prototype.get_inc = function() { + return (ObjectID.index = (ObjectID.index + 1) % 0xffffff); }; -Promise.prototype.catchReturn = function (value) { - if (arguments.length <= 1) { - if (value instanceof Promise) value.suppressUnhandledRejections(); - return this._then( - undefined, returner, undefined, {value: value}, undefined); - } else { - var _value = arguments[1]; - if (_value instanceof Promise) _value.suppressUnhandledRejections(); - var handler = function() {return _value;}; - return this.caught(value, handler); - } -}; +/** +* Update the ObjectID index used in generating new ObjectID's on the driver +* +* @method +* @return {number} returns next index value. +* @ignore +*/ +ObjectID.prototype.getInc = function() { + return this.get_inc(); }; -},{}],11:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL) { -var PromiseReduce = Promise.reduce; -var PromiseAll = Promise.all; - -function promiseAllThis() { - return PromiseAll(this); -} - -function PromiseMapSeries(promises, fn) { - return PromiseReduce(promises, fn, INTERNAL, INTERNAL); -} - -Promise.prototype.each = function (fn) { - return PromiseReduce(this, fn, INTERNAL, 0) - ._then(promiseAllThis, undefined, undefined, this, undefined); -}; +/** +* Generate a 12 byte id buffer used in ObjectID's +* +* @method +* @param {number} [time] optional parameter allowing to pass in a second based timestamp. +* @return {Buffer} return the 12 byte id buffer string. +*/ +ObjectID.prototype.generate = function(time) { + if ('number' !== typeof time) { + time = ~~(Date.now() / 1000); + } -Promise.prototype.mapSeries = function (fn) { - return PromiseReduce(this, fn, INTERNAL, INTERNAL); + // Use pid + var pid = + (typeof process === 'undefined' || process.pid === 1 + ? Math.floor(Math.random() * 100000) + : process.pid) % 0xffff; + var inc = this.get_inc(); + // Buffer used + var buffer = utils.allocBuffer(12); + // Encode time + buffer[3] = time & 0xff; + buffer[2] = (time >> 8) & 0xff; + buffer[1] = (time >> 16) & 0xff; + buffer[0] = (time >> 24) & 0xff; + // Encode machine + buffer[6] = MACHINE_ID & 0xff; + buffer[5] = (MACHINE_ID >> 8) & 0xff; + buffer[4] = (MACHINE_ID >> 16) & 0xff; + // Encode pid + buffer[8] = pid & 0xff; + buffer[7] = (pid >> 8) & 0xff; + // Encode index + buffer[11] = inc & 0xff; + buffer[10] = (inc >> 8) & 0xff; + buffer[9] = (inc >> 16) & 0xff; + // Return the buffer + return buffer; }; -Promise.each = function (promises, fn) { - return PromiseReduce(promises, fn, INTERNAL, 0) - ._then(promiseAllThis, undefined, undefined, promises, undefined); -}; +/** +* Converts the id into a 24 byte hex string for printing +* +* @param {String} format The Buffer toString format parameter. +* @return {String} return the 24 byte hex string representation. +* @ignore +*/ +ObjectID.prototype.toString = function(format) { + // Is the id a buffer then use the buffer toString method to return the format + if (this.id && this.id.copy) { + return this.id.toString(typeof format === 'string' ? format : 'hex'); + } -Promise.mapSeries = PromiseMapSeries; + // if(this.buffer ) + return this.toHexString(); }; +/** +* Converts to a string representation of this Id. +* +* @return {String} return the 24 byte hex string representation. +* @ignore +*/ +ObjectID.prototype[inspect] = ObjectID.prototype.toString; -},{}],12:[function(_dereq_,module,exports){ -"use strict"; -var es5 = _dereq_("./es5"); -var Objectfreeze = es5.freeze; -var util = _dereq_("./util"); -var inherits = util.inherits; -var notEnumerableProp = util.notEnumerableProp; - -function subError(nameProperty, defaultMessage) { - function SubError(message) { - if (!(this instanceof SubError)) return new SubError(message); - notEnumerableProp(this, "message", - typeof message === "string" ? message : defaultMessage); - notEnumerableProp(this, "name", nameProperty); - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } else { - Error.call(this); - } - } - inherits(SubError, Error); - return SubError; -} - -var _TypeError, _RangeError; -var Warning = subError("Warning", "warning"); -var CancellationError = subError("CancellationError", "cancellation error"); -var TimeoutError = subError("TimeoutError", "timeout error"); -var AggregateError = subError("AggregateError", "aggregate error"); -try { - _TypeError = TypeError; - _RangeError = RangeError; -} catch(e) { - _TypeError = subError("TypeError", "type error"); - _RangeError = subError("RangeError", "range error"); -} +/** +* Converts to its JSON representation. +* +* @return {String} return the 24 byte hex string representation. +* @ignore +*/ +ObjectID.prototype.toJSON = function() { + return this.toHexString(); +}; -var methods = ("join pop push shift unshift slice filter forEach some " + - "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); +/** +* Compares the equality of this ObjectID with `otherID`. +* +* @method +* @param {object} otherID ObjectID instance to compare against. +* @return {boolean} the result of comparing two ObjectID's +*/ +ObjectID.prototype.equals = function equals(otherId) { + // var id; -for (var i = 0; i < methods.length; ++i) { - if (typeof Array.prototype[methods[i]] === "function") { - AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; - } -} + if (otherId instanceof ObjectID) { + return this.toString() === otherId.toString(); + } else if ( + typeof otherId === 'string' && + ObjectID.isValid(otherId) && + otherId.length === 12 && + this.id instanceof _Buffer + ) { + return otherId === this.id.toString('binary'); + } else if (typeof otherId === 'string' && ObjectID.isValid(otherId) && otherId.length === 24) { + return otherId.toLowerCase() === this.toHexString(); + } else if (typeof otherId === 'string' && ObjectID.isValid(otherId) && otherId.length === 12) { + return otherId === this.id; + } else if (otherId != null && (otherId instanceof ObjectID || otherId.toHexString)) { + return otherId.toHexString() === this.toHexString(); + } else { + return false; + } +}; -es5.defineProperty(AggregateError.prototype, "length", { - value: 0, - configurable: false, - writable: true, - enumerable: true -}); -AggregateError.prototype["isOperational"] = true; -var level = 0; -AggregateError.prototype.toString = function() { - var indent = Array(level * 4 + 1).join(" "); - var ret = "\n" + indent + "AggregateError of:" + "\n"; - level++; - indent = Array(level * 4 + 1).join(" "); - for (var i = 0; i < this.length; ++i) { - var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; - var lines = str.split("\n"); - for (var j = 0; j < lines.length; ++j) { - lines[j] = indent + lines[j]; - } - str = lines.join("\n"); - ret += str + "\n"; - } - level--; - return ret; +/** +* Returns the generation date (accurate up to the second) that this ID was generated. +* +* @method +* @return {date} the generation date +*/ +ObjectID.prototype.getTimestamp = function() { + var timestamp = new Date(); + var time = this.id[3] | (this.id[2] << 8) | (this.id[1] << 16) | (this.id[0] << 24); + timestamp.setTime(Math.floor(time) * 1000); + return timestamp; }; -function OperationalError(message) { - if (!(this instanceof OperationalError)) - return new OperationalError(message); - notEnumerableProp(this, "name", "OperationalError"); - notEnumerableProp(this, "message", message); - this.cause = message; - this["isOperational"] = true; +/** +* @ignore +*/ +ObjectID.index = ~~(Math.random() * 0xffffff); - if (message instanceof Error) { - notEnumerableProp(this, "message", message.message); - notEnumerableProp(this, "stack", message.stack); - } else if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } +/** +* @ignore +*/ +ObjectID.createPk = function createPk() { + return new ObjectID(); +}; -} -inherits(OperationalError, Error); +/** +* Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID. +* +* @method +* @param {number} time an integer number representing a number of seconds. +* @return {ObjectID} return the created ObjectID +*/ +ObjectID.createFromTime = function createFromTime(time) { + var buffer = utils.toBuffer([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + // Encode time into first 4 bytes + buffer[3] = time & 0xff; + buffer[2] = (time >> 8) & 0xff; + buffer[1] = (time >> 16) & 0xff; + buffer[0] = (time >> 24) & 0xff; + // Return the new objectId + return new ObjectID(buffer); +}; -var errorTypes = Error["__BluebirdErrorTypes__"]; -if (!errorTypes) { - errorTypes = Objectfreeze({ - CancellationError: CancellationError, - TimeoutError: TimeoutError, - OperationalError: OperationalError, - RejectionError: OperationalError, - AggregateError: AggregateError - }); - es5.defineProperty(Error, "__BluebirdErrorTypes__", { - value: errorTypes, - writable: false, - enumerable: false, - configurable: false - }); -} +// Lookup tables +//var encodeLookup = '0123456789abcdef'.split(''); +var decodeLookup = []; +i = 0; +while (i < 10) decodeLookup[0x30 + i] = i++; +while (i < 16) decodeLookup[0x41 - 10 + i] = decodeLookup[0x61 - 10 + i] = i++; -module.exports = { - Error: Error, - TypeError: _TypeError, - RangeError: _RangeError, - CancellationError: errorTypes.CancellationError, - OperationalError: errorTypes.OperationalError, - TimeoutError: errorTypes.TimeoutError, - AggregateError: errorTypes.AggregateError, - Warning: Warning +var _Buffer = Buffer; +var convertToHex = function(bytes) { + return bytes.toString('hex'); }; -},{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){ -var isES5 = (function(){ - "use strict"; - return this === undefined; -})(); +/** +* Creates an ObjectID from a hex string representation of an ObjectID. +* +* @method +* @param {string} hexString create a ObjectID from a passed in 24 byte hexstring. +* @return {ObjectID} return the created ObjectID +*/ +ObjectID.createFromHexString = function createFromHexString(string) { + // Throw an error if it's not a valid setup + if (typeof string === 'undefined' || (string != null && string.length !== 24)) { + throw new Error( + 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' + ); + } -if (isES5) { - module.exports = { - freeze: Object.freeze, - defineProperty: Object.defineProperty, - getDescriptor: Object.getOwnPropertyDescriptor, - keys: Object.keys, - names: Object.getOwnPropertyNames, - getPrototypeOf: Object.getPrototypeOf, - isArray: Array.isArray, - isES5: isES5, - propertyIsWritable: function(obj, prop) { - var descriptor = Object.getOwnPropertyDescriptor(obj, prop); - return !!(!descriptor || descriptor.writable || descriptor.set); - } - }; -} else { - var has = {}.hasOwnProperty; - var str = {}.toString; - var proto = {}.constructor.prototype; + // Use Buffer.from method if available + if (hasBufferType) return new ObjectID(utils.toBuffer(string, 'hex')); - var ObjectKeys = function (o) { - var ret = []; - for (var key in o) { - if (has.call(o, key)) { - ret.push(key); - } - } - return ret; - }; + // Calculate lengths + var array = new _Buffer(12); + var n = 0; + var i = 0; - var ObjectGetDescriptor = function(o, key) { - return {value: o[key]}; - }; + while (i < 24) { + array[n++] = (decodeLookup[string.charCodeAt(i++)] << 4) | decodeLookup[string.charCodeAt(i++)]; + } - var ObjectDefineProperty = function (o, key, desc) { - o[key] = desc.value; - return o; - }; + return new ObjectID(array); +}; - var ObjectFreeze = function (obj) { - return obj; - }; +/** +* Checks if a value is a valid bson ObjectId +* +* @method +* @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise. +*/ +ObjectID.isValid = function isValid(id) { + if (id == null) return false; - var ObjectGetPrototypeOf = function (obj) { - try { - return Object(obj).constructor.prototype; - } - catch (e) { - return proto; - } - }; + if (typeof id === 'number') { + return true; + } - var ArrayIsArray = function (obj) { - try { - return str.call(obj) === "[object Array]"; - } - catch(e) { - return false; - } - }; + if (typeof id === 'string') { + return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id)); + } - module.exports = { - isArray: ArrayIsArray, - keys: ObjectKeys, - names: ObjectKeys, - defineProperty: ObjectDefineProperty, - getDescriptor: ObjectGetDescriptor, - freeze: ObjectFreeze, - getPrototypeOf: ObjectGetPrototypeOf, - isES5: isES5, - propertyIsWritable: function() { - return true; - } - }; -} + if (id instanceof ObjectID) { + return true; + } -},{}],14:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL) { -var PromiseMap = Promise.map; + if (id instanceof _Buffer) { + return true; + } -Promise.prototype.filter = function (fn, options) { - return PromiseMap(this, fn, options, INTERNAL); -}; + // Duck-Typing detection of ObjectId like objects + if ( + typeof id.toHexString === 'function' && + (id.id instanceof _Buffer || typeof id.id === 'string') + ) { + return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id)); + } -Promise.filter = function (promises, fn, options) { - return PromiseMap(promises, fn, options, INTERNAL); -}; + return false; }; -},{}],15:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) { -var util = _dereq_("./util"); -var CancellationError = Promise.CancellationError; -var errorObj = util.errorObj; -var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); +/** +* @ignore +*/ +Object.defineProperty(ObjectID.prototype, 'generationTime', { + enumerable: true, + get: function() { + return this.id[3] | (this.id[2] << 8) | (this.id[1] << 16) | (this.id[0] << 24); + }, + set: function(value) { + // Encode time into first 4 bytes + this.id[3] = value & 0xff; + this.id[2] = (value >> 8) & 0xff; + this.id[1] = (value >> 16) & 0xff; + this.id[0] = (value >> 24) & 0xff; + } +}); -function PassThroughHandlerContext(promise, type, handler) { - this.promise = promise; - this.type = type; - this.handler = handler; - this.called = false; - this.cancelPromise = null; -} +/** + * Expose. + */ +module.exports = ObjectID; +module.exports.ObjectID = ObjectID; +module.exports.ObjectId = ObjectID; -PassThroughHandlerContext.prototype.isFinallyHandler = function() { - return this.type === 0; -}; +}).call(this)}).call(this,require('_process'),require("buffer").Buffer) +},{"./parser/utils":31,"_process":369,"buffer":35,"util":378}],28:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; -function FinallyHandlerCancelReaction(finallyHandler) { - this.finallyHandler = finallyHandler; -} +var Long = require('../long').Long, + Double = require('../double').Double, + Timestamp = require('../timestamp').Timestamp, + ObjectID = require('../objectid').ObjectID, + Symbol = require('../symbol').Symbol, + BSONRegExp = require('../regexp').BSONRegExp, + Code = require('../code').Code, + Decimal128 = require('../decimal128'), + MinKey = require('../min_key').MinKey, + MaxKey = require('../max_key').MaxKey, + DBRef = require('../db_ref').DBRef, + Binary = require('../binary').Binary; -FinallyHandlerCancelReaction.prototype._resultCancelled = function() { - checkCancel(this.finallyHandler); -}; +var normalizedFunctionString = require('./utils').normalizedFunctionString; -function checkCancel(ctx, reason) { - if (ctx.cancelPromise != null) { - if (arguments.length > 1) { - ctx.cancelPromise._reject(reason); - } else { - ctx.cancelPromise._cancel(); - } - ctx.cancelPromise = null; - return true; - } - return false; -} +// To ensure that 0.4 of node works correctly +var isDate = function isDate(d) { + return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'; +}; -function succeed() { - return finallyHandler.call(this, this.promise._target()._settledValue()); -} -function fail(reason) { - if (checkCancel(this, reason)) return; - errorObj.e = reason; - return errorObj; -} -function finallyHandler(reasonOrValue) { - var promise = this.promise; - var handler = this.handler; +var calculateObjectSize = function calculateObjectSize( + object, + serializeFunctions, + ignoreUndefined +) { + var totalLength = 4 + 1; - if (!this.called) { - this.called = true; - var ret = this.isFinallyHandler() - ? handler.call(promise._boundValue()) - : handler.call(promise._boundValue(), reasonOrValue); - if (ret === NEXT_FILTER) { - return ret; - } else if (ret !== undefined) { - promise._setReturnedNonUndefined(); - var maybePromise = tryConvertToPromise(ret, promise); - if (maybePromise instanceof Promise) { - if (this.cancelPromise != null) { - if (maybePromise._isCancelled()) { - var reason = - new CancellationError("late cancellation observer"); - promise._attachExtraTrace(reason); - errorObj.e = reason; - return errorObj; - } else if (maybePromise.isPending()) { - maybePromise._attachCancellationCallback( - new FinallyHandlerCancelReaction(this)); - } - } - return maybePromise._then( - succeed, fail, undefined, this, undefined); - } - } + if (Array.isArray(object)) { + for (var i = 0; i < object.length; i++) { + totalLength += calculateElement( + i.toString(), + object[i], + serializeFunctions, + true, + ignoreUndefined + ); } - - if (promise.isRejected()) { - checkCancel(this); - errorObj.e = reasonOrValue; - return errorObj; - } else { - checkCancel(this); - return reasonOrValue; + } else { + // If we have toBSON defined, override the current object + if (object.toBSON) { + object = object.toBSON(); } -} -Promise.prototype._passThrough = function(handler, type, success, fail) { - if (typeof handler !== "function") return this.then(); - return this._then(success, - fail, - undefined, - new PassThroughHandlerContext(this, type, handler), - undefined); -}; + // Calculate size + for (var key in object) { + totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined); + } + } -Promise.prototype.lastly = -Promise.prototype["finally"] = function (handler) { - return this._passThrough(handler, - 0, - finallyHandler, - finallyHandler); + return totalLength; }; +/** + * @ignore + * @api private + */ +function calculateElement(name, value, serializeFunctions, isArray, ignoreUndefined) { + // If we have toBSON defined, override the current object + if (value && value.toBSON) { + value = value.toBSON(); + } -Promise.prototype.tap = function (handler) { - return this._passThrough(handler, 1, finallyHandler); -}; - -Promise.prototype.tapCatch = function (handlerOrPredicate) { - var len = arguments.length; - if(len === 1) { - return this._passThrough(handlerOrPredicate, - 1, - undefined, - finallyHandler); - } else { - var catchInstances = new Array(len - 1), - j = 0, i; - for (i = 0; i < len - 1; ++i) { - var item = arguments[i]; - if (util.isObject(item)) { - catchInstances[j++] = item; - } else { - return Promise.reject(new TypeError( - "tapCatch statement predicate: " - + "expecting an object but got " + util.classString(item) - )); - } + switch (typeof value) { + case 'string': + return 1 + Buffer.byteLength(name, 'utf8') + 1 + 4 + Buffer.byteLength(value, 'utf8') + 1; + case 'number': + if (Math.floor(value) === value && value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { + if (value >= BSON.BSON_INT32_MIN && value <= BSON.BSON_INT32_MAX) { + // 32 bit + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (4 + 1); + } else { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); } - catchInstances.length = j; - var handler = arguments[i]; - return this._passThrough(catchFilter(catchInstances, handler, this), - 1, - undefined, - finallyHandler); - } - -}; - -return PassThroughHandlerContext; -}; + } else { + // 64 bit + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); + } + case 'undefined': + if (isArray || !ignoreUndefined) + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + 1; + return 0; + case 'boolean': + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 1); + case 'object': + if ( + value == null || + value instanceof MinKey || + value instanceof MaxKey || + value['_bsontype'] === 'MinKey' || + value['_bsontype'] === 'MaxKey' + ) { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + 1; + } else if (value instanceof ObjectID || value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (12 + 1); + } else if (value instanceof Date || isDate(value)) { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); + } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.length + ); + } else if ( + value instanceof Long || + value instanceof Double || + value instanceof Timestamp || + value['_bsontype'] === 'Long' || + value['_bsontype'] === 'Double' || + value['_bsontype'] === 'Timestamp' + ) { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); + } else if (value instanceof Decimal128 || value['_bsontype'] === 'Decimal128') { + return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (16 + 1); + } else if (value instanceof Code || value['_bsontype'] === 'Code') { + // Calculate size depending on the availability of a scope + if (value.scope != null && Object.keys(value.scope).length > 0) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + 4 + + 4 + + Buffer.byteLength(value.code.toString(), 'utf8') + + 1 + + calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined) + ); + } else { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + 4 + + Buffer.byteLength(value.code.toString(), 'utf8') + + 1 + ); + } + } else if (value instanceof Binary || value['_bsontype'] === 'Binary') { + // Check what kind of subtype we have + if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + (value.position + 1 + 4 + 1 + 4) + ); + } else { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1) + ); + } + } else if (value instanceof Symbol || value['_bsontype'] === 'Symbol') { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + Buffer.byteLength(value.value, 'utf8') + + 4 + + 1 + + 1 + ); + } else if (value instanceof DBRef || value['_bsontype'] === 'DBRef') { + // Set up correct object for serialization + var ordered_values = { + $ref: value.namespace, + $id: value.oid + }; -},{"./catch_filter":7,"./util":36}],16:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, - apiRejection, - INTERNAL, - tryConvertToPromise, - Proxyable, - debug) { -var errors = _dereq_("./errors"); -var TypeError = errors.TypeError; -var util = _dereq_("./util"); -var errorObj = util.errorObj; -var tryCatch = util.tryCatch; -var yieldHandlers = []; + // Add db reference if it exists + if (null != value.db) { + ordered_values['$db'] = value.db; + } -function promiseFromYieldHandler(value, yieldHandlers, traceParent) { - for (var i = 0; i < yieldHandlers.length; ++i) { - traceParent._pushContext(); - var result = tryCatch(yieldHandlers[i])(value); - traceParent._popContext(); - if (result === errorObj) { - traceParent._pushContext(); - var ret = Promise.reject(errorObj.e); - traceParent._popContext(); - return ret; + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + calculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined) + ); + } else if ( + value instanceof RegExp || + Object.prototype.toString.call(value) === '[object RegExp]' + ) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + Buffer.byteLength(value.source, 'utf8') + + 1 + + (value.global ? 1 : 0) + + (value.ignoreCase ? 1 : 0) + + (value.multiline ? 1 : 0) + + 1 + ); + } else if (value instanceof BSONRegExp || value['_bsontype'] === 'BSONRegExp') { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + Buffer.byteLength(value.pattern, 'utf8') + + 1 + + Buffer.byteLength(value.options, 'utf8') + + 1 + ); + } else { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + calculateObjectSize(value, serializeFunctions, ignoreUndefined) + + 1 + ); + } + case 'function': + // WTF for 0.4.X where typeof /someregexp/ === 'function' + if ( + value instanceof RegExp || + Object.prototype.toString.call(value) === '[object RegExp]' || + String.call(value) === '[object RegExp]' + ) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + Buffer.byteLength(value.source, 'utf8') + + 1 + + (value.global ? 1 : 0) + + (value.ignoreCase ? 1 : 0) + + (value.multiline ? 1 : 0) + + 1 + ); + } else { + if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + 4 + + 4 + + Buffer.byteLength(normalizedFunctionString(value), 'utf8') + + 1 + + calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined) + ); + } else if (serializeFunctions) { + return ( + (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + + 1 + + 4 + + Buffer.byteLength(normalizedFunctionString(value), 'utf8') + + 1 + ); } - var maybePromise = tryConvertToPromise(result, traceParent); - if (maybePromise instanceof Promise) return maybePromise; - } - return null; -} + } + } -function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) { - if (debug.cancellation()) { - var internal = new Promise(INTERNAL); - var _finallyPromise = this._finallyPromise = new Promise(INTERNAL); - this._promise = internal.lastly(function() { - return _finallyPromise; - }); - internal._captureStackTrace(); - internal._setOnCancel(this); - } else { - var promise = this._promise = new Promise(INTERNAL); - promise._captureStackTrace(); - } - this._stack = stack; - this._generatorFunction = generatorFunction; - this._receiver = receiver; - this._generator = undefined; - this._yieldHandlers = typeof yieldHandler === "function" - ? [yieldHandler].concat(yieldHandlers) - : yieldHandlers; - this._yieldedPromise = null; - this._cancellationPhase = false; + return 0; } -util.inherits(PromiseSpawn, Proxyable); -PromiseSpawn.prototype._isResolved = function() { - return this._promise === null; -}; +var BSON = {}; -PromiseSpawn.prototype._cleanup = function() { - this._promise = this._generator = null; - if (debug.cancellation() && this._finallyPromise !== null) { - this._finallyPromise._fulfill(); - this._finallyPromise = null; - } -}; +// BSON MAX VALUES +BSON.BSON_INT32_MAX = 0x7fffffff; +BSON.BSON_INT32_MIN = -0x80000000; -PromiseSpawn.prototype._promiseCancelled = function() { - if (this._isResolved()) return; - var implementsReturn = typeof this._generator["return"] !== "undefined"; +// JS MAX PRECISE VALUES +BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. +BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. - var result; - if (!implementsReturn) { - var reason = new Promise.CancellationError( - "generator .return() sentinel"); - Promise.coroutine.returnSentinel = reason; - this._promise._attachExtraTrace(reason); - this._promise._pushContext(); - result = tryCatch(this._generator["throw"]).call(this._generator, - reason); - this._promise._popContext(); - } else { - this._promise._pushContext(); - result = tryCatch(this._generator["return"]).call(this._generator, - undefined); - this._promise._popContext(); - } - this._cancellationPhase = true; - this._yieldedPromise = null; - this._continue(result); -}; +module.exports = calculateObjectSize; -PromiseSpawn.prototype._promiseFulfilled = function(value) { - this._yieldedPromise = null; - this._promise._pushContext(); - var result = tryCatch(this._generator.next).call(this._generator, value); - this._promise._popContext(); - this._continue(result); -}; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../binary":15,"../code":17,"../db_ref":18,"../decimal128":19,"../double":20,"../long":23,"../max_key":25,"../min_key":26,"../objectid":27,"../regexp":32,"../symbol":33,"../timestamp":34,"./utils":31,"buffer":35}],29:[function(require,module,exports){ +'use strict'; -PromiseSpawn.prototype._promiseRejected = function(reason) { - this._yieldedPromise = null; - this._promise._attachExtraTrace(reason); - this._promise._pushContext(); - var result = tryCatch(this._generator["throw"]) - .call(this._generator, reason); - this._promise._popContext(); - this._continue(result); -}; +var Long = require('../long').Long, + Double = require('../double').Double, + Timestamp = require('../timestamp').Timestamp, + ObjectID = require('../objectid').ObjectID, + Symbol = require('../symbol').Symbol, + Code = require('../code').Code, + MinKey = require('../min_key').MinKey, + MaxKey = require('../max_key').MaxKey, + Decimal128 = require('../decimal128'), + Int32 = require('../int_32'), + DBRef = require('../db_ref').DBRef, + BSONRegExp = require('../regexp').BSONRegExp, + Binary = require('../binary').Binary; -PromiseSpawn.prototype._resultCancelled = function() { - if (this._yieldedPromise instanceof Promise) { - var promise = this._yieldedPromise; - this._yieldedPromise = null; - promise.cancel(); - } -}; +var utils = require('./utils'); -PromiseSpawn.prototype.promise = function () { - return this._promise; -}; +var deserialize = function(buffer, options, isArray) { + options = options == null ? {} : options; + var index = options && options.index ? options.index : 0; + // Read the document size + var size = + buffer[index] | + (buffer[index + 1] << 8) | + (buffer[index + 2] << 16) | + (buffer[index + 3] << 24); -PromiseSpawn.prototype._run = function () { - this._generator = this._generatorFunction.call(this._receiver); - this._receiver = - this._generatorFunction = undefined; - this._promiseFulfilled(undefined); -}; + // Ensure buffer is valid size + if (size < 5 || buffer.length < size || size + index > buffer.length) { + throw new Error('corrupt bson message'); + } -PromiseSpawn.prototype._continue = function (result) { - var promise = this._promise; - if (result === errorObj) { - this._cleanup(); - if (this._cancellationPhase) { - return promise.cancel(); - } else { - return promise._rejectCallback(result.e, false); - } - } + // Illegal end value + if (buffer[index + size - 1] !== 0) { + throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00"); + } - var value = result.value; - if (result.done === true) { - this._cleanup(); - if (this._cancellationPhase) { - return promise.cancel(); - } else { - return promise._resolveCallback(value); - } - } else { - var maybePromise = tryConvertToPromise(value, this._promise); - if (!(maybePromise instanceof Promise)) { - maybePromise = - promiseFromYieldHandler(maybePromise, - this._yieldHandlers, - this._promise); - if (maybePromise === null) { - this._promiseRejected( - new TypeError( - "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", String(value)) + - "From coroutine:\u000a" + - this._stack.split("\n").slice(1, -7).join("\n") - ) - ); - return; - } - } - maybePromise = maybePromise._target(); - var bitField = maybePromise._bitField; - ; - if (((bitField & 50397184) === 0)) { - this._yieldedPromise = maybePromise; - maybePromise._proxy(this, null); - } else if (((bitField & 33554432) !== 0)) { - Promise._async.invoke( - this._promiseFulfilled, this, maybePromise._value() - ); - } else if (((bitField & 16777216) !== 0)) { - Promise._async.invoke( - this._promiseRejected, this, maybePromise._reason() - ); - } else { - this._promiseCancelled(); - } - } + // Start deserializtion + return deserializeObject(buffer, index, options, isArray); }; -Promise.coroutine = function (generatorFunction, options) { - if (typeof generatorFunction !== "function") { - throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - var yieldHandler = Object(options).yieldHandler; - var PromiseSpawn$ = PromiseSpawn; - var stack = new Error().stack; - return function () { - var generator = generatorFunction.apply(this, arguments); - var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler, - stack); - var ret = spawn.promise(); - spawn._generator = generator; - spawn._promiseFulfilled(undefined); - return ret; - }; -}; +var deserializeObject = function(buffer, index, options, isArray) { + var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions']; + var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions']; + var cacheFunctionsCrc32 = + options['cacheFunctionsCrc32'] == null ? false : options['cacheFunctionsCrc32']; -Promise.coroutine.addYieldHandler = function(fn) { - if (typeof fn !== "function") { - throw new TypeError("expecting a function but got " + util.classString(fn)); - } - yieldHandlers.push(fn); -}; + if (!cacheFunctionsCrc32) var crc32 = null; -Promise.spawn = function (generatorFunction) { - debug.deprecated("Promise.spawn()", "Promise.coroutine()"); - if (typeof generatorFunction !== "function") { - return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - var spawn = new PromiseSpawn(generatorFunction, this); - var ret = spawn.promise(); - spawn._run(Promise.spawn); - return ret; -}; -}; + var fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; -},{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){ -"use strict"; -module.exports = -function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, - getDomain) { -var util = _dereq_("./util"); -var canEvaluate = util.canEvaluate; -var tryCatch = util.tryCatch; -var errorObj = util.errorObj; -var reject; + // Return raw bson buffer instead of parsing it + var raw = options['raw'] == null ? false : options['raw']; -if (!true) { -if (canEvaluate) { - var thenCallback = function(i) { - return new Function("value", "holder", " \n\ - 'use strict'; \n\ - holder.pIndex = value; \n\ - holder.checkFulfillment(this); \n\ - ".replace(/Index/g, i)); - }; + // Return BSONRegExp objects instead of native regular expressions + var bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; - var promiseSetter = function(i) { - return new Function("promise", "holder", " \n\ - 'use strict'; \n\ - holder.pIndex = promise; \n\ - ".replace(/Index/g, i)); - }; + // Controls the promotion of values vs wrapper classes + var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers']; + var promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs']; + var promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; - var generateHolderClass = function(total) { - var props = new Array(total); - for (var i = 0; i < props.length; ++i) { - props[i] = "this.p" + (i+1); - } - var assignment = props.join(" = ") + " = null;"; - var cancellationCode= "var promise;\n" + props.map(function(prop) { - return " \n\ - promise = " + prop + "; \n\ - if (promise instanceof Promise) { \n\ - promise.cancel(); \n\ - } \n\ - "; - }).join("\n"); - var passedArguments = props.join(", "); - var name = "Holder$" + total; + // Set the start index + var startIndex = index; + // Validate that we have at least 4 bytes of buffer + if (buffer.length < 5) throw new Error('corrupt bson message < 5 bytes long'); - var code = "return function(tryCatch, errorObj, Promise, async) { \n\ - 'use strict'; \n\ - function [TheName](fn) { \n\ - [TheProperties] \n\ - this.fn = fn; \n\ - this.asyncNeeded = true; \n\ - this.now = 0; \n\ - } \n\ - \n\ - [TheName].prototype._callFunction = function(promise) { \n\ - promise._pushContext(); \n\ - var ret = tryCatch(this.fn)([ThePassedArguments]); \n\ - promise._popContext(); \n\ - if (ret === errorObj) { \n\ - promise._rejectCallback(ret.e, false); \n\ - } else { \n\ - promise._resolveCallback(ret); \n\ - } \n\ - }; \n\ - \n\ - [TheName].prototype.checkFulfillment = function(promise) { \n\ - var now = ++this.now; \n\ - if (now === [TheTotal]) { \n\ - if (this.asyncNeeded) { \n\ - async.invoke(this._callFunction, this, promise); \n\ - } else { \n\ - this._callFunction(promise); \n\ - } \n\ - \n\ - } \n\ - }; \n\ - \n\ - [TheName].prototype._resultCancelled = function() { \n\ - [CancellationCode] \n\ - }; \n\ - \n\ - return [TheName]; \n\ - }(tryCatch, errorObj, Promise, async); \n\ - "; + // Read the document size + var size = + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); - code = code.replace(/\[TheName\]/g, name) - .replace(/\[TheTotal\]/g, total) - .replace(/\[ThePassedArguments\]/g, passedArguments) - .replace(/\[TheProperties\]/g, assignment) - .replace(/\[CancellationCode\]/g, cancellationCode); + // Ensure buffer is valid size + if (size < 5 || size > buffer.length) throw new Error('corrupt bson message'); - return new Function("tryCatch", "errorObj", "Promise", "async", code) - (tryCatch, errorObj, Promise, async); - }; + // Create holding object + var object = isArray ? [] : {}; + // Used for arrays to skip having to perform utf8 decoding + var arrayIndex = 0; - var holderClasses = []; - var thenCallbacks = []; - var promiseSetters = []; + var done = false; - for (var i = 0; i < 8; ++i) { - holderClasses.push(generateHolderClass(i + 1)); - thenCallbacks.push(thenCallback(i + 1)); - promiseSetters.push(promiseSetter(i + 1)); + // While we have more left data left keep parsing + // while (buffer[index + 1] !== 0) { + while (!done) { + // Read the type + var elementType = buffer[index++]; + // If we get a zero it's the last byte, exit + if (elementType === 0) break; + + // Get the start search index + var i = index; + // Locate the end of the c string + while (buffer[i] !== 0x00 && i < buffer.length) { + i++; } - reject = function (reason) { - this._reject(reason); - }; -}} + // If are at the end of the buffer there is a problem with the document + if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); + var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); -Promise.join = function () { - var last = arguments.length - 1; - var fn; - if (last > 0 && typeof arguments[last] === "function") { - fn = arguments[last]; - if (!true) { - if (last <= 8 && canEvaluate) { - var ret = new Promise(INTERNAL); - ret._captureStackTrace(); - var HolderClass = holderClasses[last - 1]; - var holder = new HolderClass(fn); - var callbacks = thenCallbacks; + index = i + 1; - for (var i = 0; i < last; ++i) { - var maybePromise = tryConvertToPromise(arguments[i], ret); - if (maybePromise instanceof Promise) { - maybePromise = maybePromise._target(); - var bitField = maybePromise._bitField; - ; - if (((bitField & 50397184) === 0)) { - maybePromise._then(callbacks[i], reject, - undefined, ret, holder); - promiseSetters[i](maybePromise, holder); - holder.asyncNeeded = false; - } else if (((bitField & 33554432) !== 0)) { - callbacks[i].call(ret, - maybePromise._value(), holder); - } else if (((bitField & 16777216) !== 0)) { - ret._reject(maybePromise._reason()); - } else { - ret._cancel(); - } - } else { - callbacks[i].call(ret, maybePromise, holder); - } - } + if (elementType === BSON.BSON_DATA_STRING) { + var stringSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + if ( + stringSize <= 0 || + stringSize > buffer.length - index || + buffer[index + stringSize - 1] !== 0 + ) + throw new Error('bad string length in bson'); + object[name] = buffer.toString('utf8', index, index + stringSize - 1); + index = index + stringSize; + } else if (elementType === BSON.BSON_DATA_OID) { + var oid = utils.allocBuffer(12); + buffer.copy(oid, 0, index, index + 12); + object[name] = new ObjectID(oid); + index = index + 12; + } else if (elementType === BSON.BSON_DATA_INT && promoteValues === false) { + object[name] = new Int32( + buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24) + ); + } else if (elementType === BSON.BSON_DATA_INT) { + object[name] = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + } else if (elementType === BSON.BSON_DATA_NUMBER && promoteValues === false) { + object[name] = new Double(buffer.readDoubleLE(index)); + index = index + 8; + } else if (elementType === BSON.BSON_DATA_NUMBER) { + object[name] = buffer.readDoubleLE(index); + index = index + 8; + } else if (elementType === BSON.BSON_DATA_DATE) { + var lowBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + var highBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + object[name] = new Date(new Long(lowBits, highBits).toNumber()); + } else if (elementType === BSON.BSON_DATA_BOOLEAN) { + if (buffer[index] !== 0 && buffer[index] !== 1) throw new Error('illegal boolean type value'); + object[name] = buffer[index++] === 1; + } else if (elementType === BSON.BSON_DATA_OBJECT) { + var _index = index; + var objectSize = + buffer[index] | + (buffer[index + 1] << 8) | + (buffer[index + 2] << 16) | + (buffer[index + 3] << 24); + if (objectSize <= 0 || objectSize > buffer.length - index) + throw new Error('bad embedded document length in bson'); - if (!ret._isFateSealed()) { - if (holder.asyncNeeded) { - var domain = getDomain(); - if (domain !== null) { - holder.fn = util.domainBind(domain, holder.fn); - } - } - ret._setAsyncGuaranteed(); - ret._setOnCancel(holder); - } - return ret; - } - } - } - var args = [].slice.call(arguments);; - if (fn) args.pop(); - var ret = new PromiseArray(args).promise(); - return fn !== undefined ? ret.spread(fn) : ret; -}; + // We have a raw value + if (raw) { + object[name] = buffer.slice(index, index + objectSize); + } else { + object[name] = deserializeObject(buffer, _index, options, false); + } -}; + index = index + objectSize; + } else if (elementType === BSON.BSON_DATA_ARRAY) { + _index = index; + objectSize = + buffer[index] | + (buffer[index + 1] << 8) | + (buffer[index + 2] << 16) | + (buffer[index + 3] << 24); + var arrayOptions = options; -},{"./util":36}],18:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, - PromiseArray, - apiRejection, - tryConvertToPromise, - INTERNAL, - debug) { -var getDomain = Promise._getDomain; -var util = _dereq_("./util"); -var tryCatch = util.tryCatch; -var errorObj = util.errorObj; -var async = Promise._async; + // Stop index + var stopIndex = index + objectSize; -function MappingPromiseArray(promises, fn, limit, _filter) { - this.constructor$(promises); - this._promise._captureStackTrace(); - var domain = getDomain(); - this._callback = domain === null ? fn : util.domainBind(domain, fn); - this._preservedValues = _filter === INTERNAL - ? new Array(this.length()) - : null; - this._limit = limit; - this._inFlight = 0; - this._queue = []; - async.invoke(this._asyncInit, this, undefined); -} -util.inherits(MappingPromiseArray, PromiseArray); + // All elements of array to be returned as raw bson + if (fieldsAsRaw && fieldsAsRaw[name]) { + arrayOptions = {}; + for (var n in options) arrayOptions[n] = options[n]; + arrayOptions['raw'] = true; + } -MappingPromiseArray.prototype._asyncInit = function() { - this._init$(undefined, -2); -}; + object[name] = deserializeObject(buffer, _index, arrayOptions, true); + index = index + objectSize; -MappingPromiseArray.prototype._init = function () {}; + if (buffer[index - 1] !== 0) throw new Error('invalid array terminator byte'); + if (index !== stopIndex) throw new Error('corrupted array bson'); + } else if (elementType === BSON.BSON_DATA_UNDEFINED) { + object[name] = undefined; + } else if (elementType === BSON.BSON_DATA_NULL) { + object[name] = null; + } else if (elementType === BSON.BSON_DATA_LONG) { + // Unpack the low and high bits + lowBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + highBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + var long = new Long(lowBits, highBits); + // Promote the long if possible + if (promoteLongs && promoteValues === true) { + object[name] = + long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG) + ? long.toNumber() + : long; + } else { + object[name] = long; + } + } else if (elementType === BSON.BSON_DATA_DECIMAL128) { + // Buffer to contain the decimal bytes + var bytes = utils.allocBuffer(16); + // Copy the next 16 bytes into the bytes buffer + buffer.copy(bytes, 0, index, index + 16); + // Update index + index = index + 16; + // Assign the new Decimal128 value + var decimal128 = new Decimal128(bytes); + // If we have an alternative mapper use that + object[name] = decimal128.toObject ? decimal128.toObject() : decimal128; + } else if (elementType === BSON.BSON_DATA_BINARY) { + var binarySize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + var totalBinarySize = binarySize; + var subType = buffer[index++]; -MappingPromiseArray.prototype._promiseFulfilled = function (value, index) { - var values = this._values; - var length = this.length(); - var preservedValues = this._preservedValues; - var limit = this._limit; + // Did we have a negative binary size, throw + if (binarySize < 0) throw new Error('Negative binary type element size found'); - if (index < 0) { - index = (index * -1) - 1; - values[index] = value; - if (limit >= 1) { - this._inFlight--; - this._drainQueue(); - if (this._isResolved()) return true; - } - } else { - if (limit >= 1 && this._inFlight >= limit) { - values[index] = value; - this._queue.push(index); - return false; - } - if (preservedValues !== null) preservedValues[index] = value; + // Is the length longer than the document + if (binarySize > buffer.length) throw new Error('Binary type size larger than document size'); - var promise = this._promise; - var callback = this._callback; - var receiver = promise._boundValue(); - promise._pushContext(); - var ret = tryCatch(callback).call(receiver, value, index, length); - var promiseCreated = promise._popContext(); - debug.checkForgottenReturns( - ret, - promiseCreated, - preservedValues !== null ? "Promise.filter" : "Promise.map", - promise - ); - if (ret === errorObj) { - this._reject(ret.e); - return true; + // Decode as raw Buffer object if options specifies it + if (buffer['slice'] != null) { + // If we have subtype 2 skip the 4 bytes for the size + if (subType === Binary.SUBTYPE_BYTE_ARRAY) { + binarySize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + if (binarySize < 0) + throw new Error('Negative binary type element size found for subtype 0x02'); + if (binarySize > totalBinarySize - 4) + throw new Error('Binary type with subtype 0x02 contains to long binary size'); + if (binarySize < totalBinarySize - 4) + throw new Error('Binary type with subtype 0x02 contains to short binary size'); } - var maybePromise = tryConvertToPromise(ret, this._promise); - if (maybePromise instanceof Promise) { - maybePromise = maybePromise._target(); - var bitField = maybePromise._bitField; - ; - if (((bitField & 50397184) === 0)) { - if (limit >= 1) this._inFlight++; - values[index] = maybePromise; - maybePromise._proxy(this, (index + 1) * -1); - return false; - } else if (((bitField & 33554432) !== 0)) { - ret = maybePromise._value(); - } else if (((bitField & 16777216) !== 0)) { - this._reject(maybePromise._reason()); - return true; - } else { - this._cancel(); - return true; - } - } - values[index] = ret; - } - var totalResolved = ++this._totalResolved; - if (totalResolved >= length) { - if (preservedValues !== null) { - this._filter(values, preservedValues); + if (promoteBuffers && promoteValues) { + object[name] = buffer.slice(index, index + binarySize); } else { - this._resolve(values); + object[name] = new Binary(buffer.slice(index, index + binarySize), subType); + } + } else { + var _buffer = + typeof Uint8Array !== 'undefined' + ? new Uint8Array(new ArrayBuffer(binarySize)) + : new Array(binarySize); + // If we have subtype 2 skip the 4 bytes for the size + if (subType === Binary.SUBTYPE_BYTE_ARRAY) { + binarySize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + if (binarySize < 0) + throw new Error('Negative binary type element size found for subtype 0x02'); + if (binarySize > totalBinarySize - 4) + throw new Error('Binary type with subtype 0x02 contains to long binary size'); + if (binarySize < totalBinarySize - 4) + throw new Error('Binary type with subtype 0x02 contains to short binary size'); } - return true; - } - return false; -}; - -MappingPromiseArray.prototype._drainQueue = function () { - var queue = this._queue; - var limit = this._limit; - var values = this._values; - while (queue.length > 0 && this._inFlight < limit) { - if (this._isResolved()) return; - var index = queue.pop(); - this._promiseFulfilled(values[index], index); - } -}; - -MappingPromiseArray.prototype._filter = function (booleans, values) { - var len = values.length; - var ret = new Array(len); - var j = 0; - for (var i = 0; i < len; ++i) { - if (booleans[i]) ret[j++] = values[i]; - } - ret.length = j; - this._resolve(ret); -}; - -MappingPromiseArray.prototype.preservedValues = function () { - return this._preservedValues; -}; -function map(promises, fn, options, _filter) { - if (typeof fn !== "function") { - return apiRejection("expecting a function but got " + util.classString(fn)); - } + // Copy the data + for (i = 0; i < binarySize; i++) { + _buffer[i] = buffer[index + i]; + } - var limit = 0; - if (options !== undefined) { - if (typeof options === "object" && options !== null) { - if (typeof options.concurrency !== "number") { - return Promise.reject( - new TypeError("'concurrency' must be a number but it is " + - util.classString(options.concurrency))); - } - limit = options.concurrency; + if (promoteBuffers && promoteValues) { + object[name] = _buffer; } else { - return Promise.reject(new TypeError( - "options argument must be an object but it is " + - util.classString(options))); + object[name] = new Binary(_buffer, subType); } - } - limit = typeof limit === "number" && - isFinite(limit) && limit >= 1 ? limit : 0; - return new MappingPromiseArray(promises, fn, limit, _filter).promise(); -} - -Promise.prototype.map = function (fn, options) { - return map(this, fn, options, null); -}; + } -Promise.map = function (promises, fn, options, _filter) { - return map(promises, fn, options, _filter); -}; + // Update the index + index = index + binarySize; + } else if (elementType === BSON.BSON_DATA_REGEXP && bsonRegExp === false) { + // Get the start search index + i = index; + // Locate the end of the c string + while (buffer[i] !== 0x00 && i < buffer.length) { + i++; + } + // If are at the end of the buffer there is a problem with the document + if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); + // Return the C string + var source = buffer.toString('utf8', index, i); + // Create the regexp + index = i + 1; + // Get the start search index + i = index; + // Locate the end of the c string + while (buffer[i] !== 0x00 && i < buffer.length) { + i++; + } + // If are at the end of the buffer there is a problem with the document + if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); + // Return the C string + var regExpOptions = buffer.toString('utf8', index, i); + index = i + 1; -}; + // For each option add the corresponding one for javascript + var optionsArray = new Array(regExpOptions.length); -},{"./util":36}],19:[function(_dereq_,module,exports){ -"use strict"; -module.exports = -function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) { -var util = _dereq_("./util"); -var tryCatch = util.tryCatch; + // Parse options + for (i = 0; i < regExpOptions.length; i++) { + switch (regExpOptions[i]) { + case 'm': + optionsArray[i] = 'm'; + break; + case 's': + optionsArray[i] = 'g'; + break; + case 'i': + optionsArray[i] = 'i'; + break; + } + } -Promise.method = function (fn) { - if (typeof fn !== "function") { - throw new Promise.TypeError("expecting a function but got " + util.classString(fn)); - } - return function () { - var ret = new Promise(INTERNAL); - ret._captureStackTrace(); - ret._pushContext(); - var value = tryCatch(fn).apply(this, arguments); - var promiseCreated = ret._popContext(); - debug.checkForgottenReturns( - value, promiseCreated, "Promise.method", ret); - ret._resolveFromSyncValue(value); - return ret; - }; -}; - -Promise.attempt = Promise["try"] = function (fn) { - if (typeof fn !== "function") { - return apiRejection("expecting a function but got " + util.classString(fn)); - } - var ret = new Promise(INTERNAL); - ret._captureStackTrace(); - ret._pushContext(); - var value; - if (arguments.length > 1) { - debug.deprecated("calling Promise.try with more than 1 argument"); - var arg = arguments[1]; - var ctx = arguments[2]; - value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg) - : tryCatch(fn).call(ctx, arg); - } else { - value = tryCatch(fn)(); - } - var promiseCreated = ret._popContext(); - debug.checkForgottenReturns( - value, promiseCreated, "Promise.try", ret); - ret._resolveFromSyncValue(value); - return ret; -}; - -Promise.prototype._resolveFromSyncValue = function (value) { - if (value === util.errorObj) { - this._rejectCallback(value.e, false); - } else { - this._resolveCallback(value, true); - } -}; -}; - -},{"./util":36}],20:[function(_dereq_,module,exports){ -"use strict"; -var util = _dereq_("./util"); -var maybeWrapAsError = util.maybeWrapAsError; -var errors = _dereq_("./errors"); -var OperationalError = errors.OperationalError; -var es5 = _dereq_("./es5"); + object[name] = new RegExp(source, optionsArray.join('')); + } else if (elementType === BSON.BSON_DATA_REGEXP && bsonRegExp === true) { + // Get the start search index + i = index; + // Locate the end of the c string + while (buffer[i] !== 0x00 && i < buffer.length) { + i++; + } + // If are at the end of the buffer there is a problem with the document + if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); + // Return the C string + source = buffer.toString('utf8', index, i); + index = i + 1; -function isUntypedError(obj) { - return obj instanceof Error && - es5.getPrototypeOf(obj) === Error.prototype; -} + // Get the start search index + i = index; + // Locate the end of the c string + while (buffer[i] !== 0x00 && i < buffer.length) { + i++; + } + // If are at the end of the buffer there is a problem with the document + if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); + // Return the C string + regExpOptions = buffer.toString('utf8', index, i); + index = i + 1; -var rErrorKey = /^(?:name|message|stack|cause)$/; -function wrapAsOperationalError(obj) { - var ret; - if (isUntypedError(obj)) { - ret = new OperationalError(obj); - ret.name = obj.name; - ret.message = obj.message; - ret.stack = obj.stack; - var keys = es5.keys(obj); - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - if (!rErrorKey.test(key)) { - ret[key] = obj[key]; - } - } - return ret; - } - util.markAsOriginatingFromRejection(obj); - return obj; -} + // Set the object + object[name] = new BSONRegExp(source, regExpOptions); + } else if (elementType === BSON.BSON_DATA_SYMBOL) { + stringSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + if ( + stringSize <= 0 || + stringSize > buffer.length - index || + buffer[index + stringSize - 1] !== 0 + ) + throw new Error('bad string length in bson'); + object[name] = new Symbol(buffer.toString('utf8', index, index + stringSize - 1)); + index = index + stringSize; + } else if (elementType === BSON.BSON_DATA_TIMESTAMP) { + lowBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + highBits = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + object[name] = new Timestamp(lowBits, highBits); + } else if (elementType === BSON.BSON_DATA_MIN_KEY) { + object[name] = new MinKey(); + } else if (elementType === BSON.BSON_DATA_MAX_KEY) { + object[name] = new MaxKey(); + } else if (elementType === BSON.BSON_DATA_CODE) { + stringSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + if ( + stringSize <= 0 || + stringSize > buffer.length - index || + buffer[index + stringSize - 1] !== 0 + ) + throw new Error('bad string length in bson'); + var functionString = buffer.toString('utf8', index, index + stringSize - 1); -function nodebackForPromise(promise, multiArgs) { - return function(err, value) { - if (promise === null) return; - if (err) { - var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); - promise._attachExtraTrace(wrapped); - promise._reject(wrapped); - } else if (!multiArgs) { - promise._fulfill(value); + // If we are evaluating the functions + if (evalFunctions) { + // If we have cache enabled let's look for the md5 of the function in the cache + if (cacheFunctions) { + var hash = cacheFunctionsCrc32 ? crc32(functionString) : functionString; + // Got to do this to avoid V8 deoptimizing the call due to finding eval + object[name] = isolateEvalWithHash(functionCache, hash, functionString, object); } else { - var args = [].slice.call(arguments, 1);; - promise._fulfill(args); + object[name] = isolateEval(functionString); } - promise = null; - }; -} - -module.exports = nodebackForPromise; + } else { + object[name] = new Code(functionString); + } -},{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise) { -var util = _dereq_("./util"); -var async = Promise._async; -var tryCatch = util.tryCatch; -var errorObj = util.errorObj; + // Update parse index position + index = index + stringSize; + } else if (elementType === BSON.BSON_DATA_CODE_W_SCOPE) { + var totalSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); -function spreadAdapter(val, nodeback) { - var promise = this; - if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback); - var ret = - tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val)); - if (ret === errorObj) { - async.throwLater(ret.e); - } -} + // Element cannot be shorter than totalSize + stringSize + documentSize + terminator + if (totalSize < 4 + 4 + 4 + 1) { + throw new Error('code_w_scope total size shorter minimum expected length'); + } -function successAdapter(val, nodeback) { - var promise = this; - var receiver = promise._boundValue(); - var ret = val === undefined - ? tryCatch(nodeback).call(receiver, null) - : tryCatch(nodeback).call(receiver, null, val); - if (ret === errorObj) { - async.throwLater(ret.e); - } -} -function errorAdapter(reason, nodeback) { - var promise = this; - if (!reason) { - var newReason = new Error(reason + ""); - newReason.cause = reason; - reason = newReason; - } - var ret = tryCatch(nodeback).call(promise._boundValue(), reason); - if (ret === errorObj) { - async.throwLater(ret.e); - } -} + // Get the code string size + stringSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + // Check if we have a valid string + if ( + stringSize <= 0 || + stringSize > buffer.length - index || + buffer[index + stringSize - 1] !== 0 + ) + throw new Error('bad string length in bson'); -Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback, - options) { - if (typeof nodeback == "function") { - var adapter = successAdapter; - if (options !== undefined && Object(options).spread) { - adapter = spreadAdapter; - } - this._then( - adapter, - errorAdapter, - undefined, - this, - nodeback - ); - } - return this; -}; -}; + // Javascript function + functionString = buffer.toString('utf8', index, index + stringSize - 1); + // Update parse index position + index = index + stringSize; + // Parse the element + _index = index; + // Decode the size of the object document + objectSize = + buffer[index] | + (buffer[index + 1] << 8) | + (buffer[index + 2] << 16) | + (buffer[index + 3] << 24); + // Decode the scope object + var scopeObject = deserializeObject(buffer, _index, options, false); + // Adjust the index + index = index + objectSize; -},{"./util":36}],22:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function() { -var makeSelfResolutionError = function () { - return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a"); -}; -var reflectHandler = function() { - return new Promise.PromiseInspection(this._target()); -}; -var apiRejection = function(msg) { - return Promise.reject(new TypeError(msg)); -}; -function Proxyable() {} -var UNDEFINED_BINDING = {}; -var util = _dereq_("./util"); + // Check if field length is to short + if (totalSize < 4 + 4 + objectSize + stringSize) { + throw new Error('code_w_scope total size is to short, truncating scope'); + } -var getDomain; -if (util.isNode) { - getDomain = function() { - var ret = process.domain; - if (ret === undefined) ret = null; - return ret; - }; -} else { - getDomain = function() { - return null; - }; -} -util.notEnumerableProp(Promise, "_getDomain", getDomain); + // Check if totalSize field is to long + if (totalSize > 4 + 4 + objectSize + stringSize) { + throw new Error('code_w_scope total size is to long, clips outer document'); + } -var es5 = _dereq_("./es5"); -var Async = _dereq_("./async"); -var async = new Async(); -es5.defineProperty(Promise, "_async", {value: async}); -var errors = _dereq_("./errors"); -var TypeError = Promise.TypeError = errors.TypeError; -Promise.RangeError = errors.RangeError; -var CancellationError = Promise.CancellationError = errors.CancellationError; -Promise.TimeoutError = errors.TimeoutError; -Promise.OperationalError = errors.OperationalError; -Promise.RejectionError = errors.OperationalError; -Promise.AggregateError = errors.AggregateError; -var INTERNAL = function(){}; -var APPLY = {}; -var NEXT_FILTER = {}; -var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL); -var PromiseArray = - _dereq_("./promise_array")(Promise, INTERNAL, - tryConvertToPromise, apiRejection, Proxyable); -var Context = _dereq_("./context")(Promise); - /*jshint unused:false*/ -var createContext = Context.create; -var debug = _dereq_("./debuggability")(Promise, Context); -var CapturedTrace = debug.CapturedTrace; -var PassThroughHandlerContext = - _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER); -var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); -var nodebackForPromise = _dereq_("./nodeback"); -var errorObj = util.errorObj; -var tryCatch = util.tryCatch; -function check(self, executor) { - if (self == null || self.constructor !== Promise) { - throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - if (typeof executor !== "function") { - throw new TypeError("expecting a function but got " + util.classString(executor)); - } + // If we are evaluating the functions + if (evalFunctions) { + // If we have cache enabled let's look for the md5 of the function in the cache + if (cacheFunctions) { + hash = cacheFunctionsCrc32 ? crc32(functionString) : functionString; + // Got to do this to avoid V8 deoptimizing the call due to finding eval + object[name] = isolateEvalWithHash(functionCache, hash, functionString, object); + } else { + object[name] = isolateEval(functionString); + } -} + object[name].scope = scopeObject; + } else { + object[name] = new Code(functionString, scopeObject); + } + } else if (elementType === BSON.BSON_DATA_DBPOINTER) { + // Get the code string size + stringSize = + buffer[index++] | + (buffer[index++] << 8) | + (buffer[index++] << 16) | + (buffer[index++] << 24); + // Check if we have a valid string + if ( + stringSize <= 0 || + stringSize > buffer.length - index || + buffer[index + stringSize - 1] !== 0 + ) + throw new Error('bad string length in bson'); + // Namespace + var namespace = buffer.toString('utf8', index, index + stringSize - 1); + // Update parse index position + index = index + stringSize; -function Promise(executor) { - if (executor !== INTERNAL) { - check(this, executor); - } - this._bitField = 0; - this._fulfillmentHandler0 = undefined; - this._rejectionHandler0 = undefined; - this._promise0 = undefined; - this._receiver0 = undefined; - this._resolveFromExecutor(executor); - this._promiseCreated(); - this._fireEvent("promiseCreated", this); -} + // Read the oid + var oidBuffer = utils.allocBuffer(12); + buffer.copy(oidBuffer, 0, index, index + 12); + oid = new ObjectID(oidBuffer); -Promise.prototype.toString = function () { - return "[object Promise]"; -}; + // Update the index + index = index + 12; -Promise.prototype.caught = Promise.prototype["catch"] = function (fn) { - var len = arguments.length; - if (len > 1) { - var catchInstances = new Array(len - 1), - j = 0, i; - for (i = 0; i < len - 1; ++i) { - var item = arguments[i]; - if (util.isObject(item)) { - catchInstances[j++] = item; - } else { - return apiRejection("Catch statement predicate: " + - "expecting an object but got " + util.classString(item)); - } - } - catchInstances.length = j; - fn = arguments[i]; - return this.then(undefined, catchFilter(catchInstances, fn, this)); + // Split the namespace + var parts = namespace.split('.'); + var db = parts.shift(); + var collection = parts.join('.'); + // Upgrade to DBRef type + object[name] = new DBRef(collection, oid, db); + } else { + throw new Error( + 'Detected unknown BSON type ' + + elementType.toString(16) + + ' for fieldname "' + + name + + '", are you using the latest BSON parser' + ); } - return this.then(undefined, fn); -}; + } -Promise.prototype.reflect = function () { - return this._then(reflectHandler, - reflectHandler, undefined, this, undefined); -}; + // Check if the deserialization was against a valid array/object + if (size !== index - startIndex) { + if (isArray) throw new Error('corrupt array bson'); + throw new Error('corrupt object bson'); + } -Promise.prototype.then = function (didFulfill, didReject) { - if (debug.warnings() && arguments.length > 0 && - typeof didFulfill !== "function" && - typeof didReject !== "function") { - var msg = ".then() only accepts functions but was passed: " + - util.classString(didFulfill); - if (arguments.length > 1) { - msg += ", " + util.classString(didReject); - } - this._warn(msg); - } - return this._then(didFulfill, didReject, undefined, undefined, undefined); + // Check if we have a db ref object + if (object['$id'] != null) object = new DBRef(object['$ref'], object['$id'], object['$db']); + return object; }; -Promise.prototype.done = function (didFulfill, didReject) { - var promise = - this._then(didFulfill, didReject, undefined, undefined, undefined); - promise._setIsFinal(); -}; +/** + * Ensure eval is isolated. + * + * @ignore + * @api private + */ +var isolateEvalWithHash = function(functionCache, hash, functionString, object) { + // Contains the value we are going to set + var value = null; -Promise.prototype.spread = function (fn) { - if (typeof fn !== "function") { - return apiRejection("expecting a function but got " + util.classString(fn)); - } - return this.all()._then(fn, undefined, undefined, APPLY, undefined); + // Check for cache hit, eval if missing and return cached function + if (functionCache[hash] == null) { + eval('value = ' + functionString); + functionCache[hash] = value; + } + // Set the object + return functionCache[hash].bind(object); }; -Promise.prototype.toJSON = function () { - var ret = { - isFulfilled: false, - isRejected: false, - fulfillmentValue: undefined, - rejectionReason: undefined - }; - if (this.isFulfilled()) { - ret.fulfillmentValue = this.value(); - ret.isFulfilled = true; - } else if (this.isRejected()) { - ret.rejectionReason = this.reason(); - ret.isRejected = true; - } - return ret; +/** + * Ensure eval is isolated. + * + * @ignore + * @api private + */ +var isolateEval = function(functionString) { + // Contains the value we are going to set + var value = null; + // Eval the function + eval('value = ' + functionString); + return value; }; -Promise.prototype.all = function () { - if (arguments.length > 0) { - this._warn(".all() was passed arguments but it does not take any"); - } - return new PromiseArray(this).promise(); -}; +var BSON = {}; -Promise.prototype.error = function (fn) { - return this.caught(util.originatesFromRejection, fn); -}; +/** + * Contains the function cache if we have that enable to allow for avoiding the eval step on each deserialization, comparison is by md5 + * + * @ignore + * @api private + */ +var functionCache = (BSON.functionCache = {}); -Promise.getNewLibraryCopy = module.exports; +/** + * Number BSON Type + * + * @classconstant BSON_DATA_NUMBER + **/ +BSON.BSON_DATA_NUMBER = 1; +/** + * String BSON Type + * + * @classconstant BSON_DATA_STRING + **/ +BSON.BSON_DATA_STRING = 2; +/** + * Object BSON Type + * + * @classconstant BSON_DATA_OBJECT + **/ +BSON.BSON_DATA_OBJECT = 3; +/** + * Array BSON Type + * + * @classconstant BSON_DATA_ARRAY + **/ +BSON.BSON_DATA_ARRAY = 4; +/** + * Binary BSON Type + * + * @classconstant BSON_DATA_BINARY + **/ +BSON.BSON_DATA_BINARY = 5; +/** + * Binary BSON Type + * + * @classconstant BSON_DATA_UNDEFINED + **/ +BSON.BSON_DATA_UNDEFINED = 6; +/** + * ObjectID BSON Type + * + * @classconstant BSON_DATA_OID + **/ +BSON.BSON_DATA_OID = 7; +/** + * Boolean BSON Type + * + * @classconstant BSON_DATA_BOOLEAN + **/ +BSON.BSON_DATA_BOOLEAN = 8; +/** + * Date BSON Type + * + * @classconstant BSON_DATA_DATE + **/ +BSON.BSON_DATA_DATE = 9; +/** + * null BSON Type + * + * @classconstant BSON_DATA_NULL + **/ +BSON.BSON_DATA_NULL = 10; +/** + * RegExp BSON Type + * + * @classconstant BSON_DATA_REGEXP + **/ +BSON.BSON_DATA_REGEXP = 11; +/** + * Code BSON Type + * + * @classconstant BSON_DATA_DBPOINTER + **/ +BSON.BSON_DATA_DBPOINTER = 12; +/** + * Code BSON Type + * + * @classconstant BSON_DATA_CODE + **/ +BSON.BSON_DATA_CODE = 13; +/** + * Symbol BSON Type + * + * @classconstant BSON_DATA_SYMBOL + **/ +BSON.BSON_DATA_SYMBOL = 14; +/** + * Code with Scope BSON Type + * + * @classconstant BSON_DATA_CODE_W_SCOPE + **/ +BSON.BSON_DATA_CODE_W_SCOPE = 15; +/** + * 32 bit Integer BSON Type + * + * @classconstant BSON_DATA_INT + **/ +BSON.BSON_DATA_INT = 16; +/** + * Timestamp BSON Type + * + * @classconstant BSON_DATA_TIMESTAMP + **/ +BSON.BSON_DATA_TIMESTAMP = 17; +/** + * Long BSON Type + * + * @classconstant BSON_DATA_LONG + **/ +BSON.BSON_DATA_LONG = 18; +/** + * Long BSON Type + * + * @classconstant BSON_DATA_DECIMAL128 + **/ +BSON.BSON_DATA_DECIMAL128 = 19; +/** + * MinKey BSON Type + * + * @classconstant BSON_DATA_MIN_KEY + **/ +BSON.BSON_DATA_MIN_KEY = 0xff; +/** + * MaxKey BSON Type + * + * @classconstant BSON_DATA_MAX_KEY + **/ +BSON.BSON_DATA_MAX_KEY = 0x7f; -Promise.is = function (val) { - return val instanceof Promise; -}; +/** + * Binary Default Type + * + * @classconstant BSON_BINARY_SUBTYPE_DEFAULT + **/ +BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; +/** + * Binary Function Type + * + * @classconstant BSON_BINARY_SUBTYPE_FUNCTION + **/ +BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; +/** + * Binary Byte Array Type + * + * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY + **/ +BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; +/** + * Binary UUID Type + * + * @classconstant BSON_BINARY_SUBTYPE_UUID + **/ +BSON.BSON_BINARY_SUBTYPE_UUID = 3; +/** + * Binary MD5 Type + * + * @classconstant BSON_BINARY_SUBTYPE_MD5 + **/ +BSON.BSON_BINARY_SUBTYPE_MD5 = 4; +/** + * Binary User Defined Type + * + * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED + **/ +BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; -Promise.fromNode = Promise.fromCallback = function(fn) { - var ret = new Promise(INTERNAL); - ret._captureStackTrace(); - var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs - : false; - var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs)); - if (result === errorObj) { - ret._rejectCallback(result.e, true); - } - if (!ret._isFateSealed()) ret._setAsyncGuaranteed(); - return ret; -}; +// BSON MAX VALUES +BSON.BSON_INT32_MAX = 0x7fffffff; +BSON.BSON_INT32_MIN = -0x80000000; -Promise.all = function (promises) { - return new PromiseArray(promises).promise(); -}; +BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; +BSON.BSON_INT64_MIN = -Math.pow(2, 63); -Promise.cast = function (obj) { - var ret = tryConvertToPromise(obj); - if (!(ret instanceof Promise)) { - ret = new Promise(INTERNAL); - ret._captureStackTrace(); - ret._setFulfilled(); - ret._rejectionHandler0 = obj; - } - return ret; -}; +// JS MAX PRECISE VALUES +BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. +BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. -Promise.resolve = Promise.fulfilled = Promise.cast; +// Internal long versions +var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. +var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. -Promise.reject = Promise.rejected = function (reason) { - var ret = new Promise(INTERNAL); - ret._captureStackTrace(); - ret._rejectCallback(reason, true); - return ret; -}; +module.exports = deserialize; -Promise.setScheduler = function(fn) { - if (typeof fn !== "function") { - throw new TypeError("expecting a function but got " + util.classString(fn)); - } - return async.setScheduler(fn); -}; +},{"../binary":15,"../code":17,"../db_ref":18,"../decimal128":19,"../double":20,"../int_32":22,"../long":23,"../max_key":25,"../min_key":26,"../objectid":27,"../regexp":32,"../symbol":33,"../timestamp":34,"./utils":31}],30:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; -Promise.prototype._then = function ( - didFulfill, - didReject, - _, receiver, - internalData -) { - var haveInternalData = internalData !== undefined; - var promise = haveInternalData ? internalData : new Promise(INTERNAL); - var target = this._target(); - var bitField = target._bitField; +var writeIEEE754 = require('../float_parser').writeIEEE754, + Long = require('../long').Long, + Map = require('../map'), + Binary = require('../binary').Binary; - if (!haveInternalData) { - promise._propagateFrom(this, 3); - promise._captureStackTrace(); - if (receiver === undefined && - ((this._bitField & 2097152) !== 0)) { - if (!((bitField & 50397184) === 0)) { - receiver = this._boundValue(); - } else { - receiver = target === this ? undefined : this._boundTo; - } - } - this._fireEvent("promiseChained", this, promise); - } +var normalizedFunctionString = require('./utils').normalizedFunctionString; - var domain = getDomain(); - if (!((bitField & 50397184) === 0)) { - var handler, value, settler = target._settlePromiseCtx; - if (((bitField & 33554432) !== 0)) { - value = target._rejectionHandler0; - handler = didFulfill; - } else if (((bitField & 16777216) !== 0)) { - value = target._fulfillmentHandler0; - handler = didReject; - target._unsetRejectionIsUnhandled(); - } else { - settler = target._settlePromiseLateCancellationObserver; - value = new CancellationError("late cancellation observer"); - target._attachExtraTrace(value); - handler = didReject; - } +// try { +// var _Buffer = Uint8Array; +// } catch (e) { +// _Buffer = Buffer; +// } - async.invoke(settler, target, { - handler: domain === null ? handler - : (typeof handler === "function" && - util.domainBind(domain, handler)), - promise: promise, - receiver: receiver, - value: value - }); - } else { - target._addCallbacks(didFulfill, didReject, promise, receiver, domain); - } +var regexp = /\x00/; // eslint-disable-line no-control-regex +var ignoreKeys = ['$db', '$ref', '$id', '$clusterTime']; - return promise; +// To ensure that 0.4 of node works correctly +var isDate = function isDate(d) { + return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'; }; -Promise.prototype._length = function () { - return this._bitField & 65535; +var isRegExp = function isRegExp(d) { + return Object.prototype.toString.call(d) === '[object RegExp]'; }; -Promise.prototype._isFateSealed = function () { - return (this._bitField & 117506048) !== 0; +var serializeString = function(buffer, key, value, index, isArray) { + // Encode String type + buffer[index++] = BSON.BSON_DATA_STRING; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes + 1; + buffer[index - 1] = 0; + // Write the string + var size = buffer.write(value, index + 4, 'utf8'); + // Write the size of the string to buffer + buffer[index + 3] = ((size + 1) >> 24) & 0xff; + buffer[index + 2] = ((size + 1) >> 16) & 0xff; + buffer[index + 1] = ((size + 1) >> 8) & 0xff; + buffer[index] = (size + 1) & 0xff; + // Update index + index = index + 4 + size; + // Write zero + buffer[index++] = 0; + return index; }; -Promise.prototype._isFollowing = function () { - return (this._bitField & 67108864) === 67108864; -}; +var serializeNumber = function(buffer, key, value, index, isArray) { + // We have an integer value + if (Math.floor(value) === value && value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { + // If the value fits in 32 bits encode as int, if it fits in a double + // encode it as a double, otherwise long + if (value >= BSON.BSON_INT32_MIN && value <= BSON.BSON_INT32_MAX) { + // Set int type 32 bits or less + buffer[index++] = BSON.BSON_DATA_INT; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write the int value + buffer[index++] = value & 0xff; + buffer[index++] = (value >> 8) & 0xff; + buffer[index++] = (value >> 16) & 0xff; + buffer[index++] = (value >> 24) & 0xff; + } else if (value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { + // Encode as double + buffer[index++] = BSON.BSON_DATA_NUMBER; + // Number of written bytes + numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write float + writeIEEE754(buffer, value, index, 'little', 52, 8); + // Ajust index + index = index + 8; + } else { + // Set long type + buffer[index++] = BSON.BSON_DATA_LONG; + // Number of written bytes + numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + var longVal = Long.fromNumber(value); + var lowBits = longVal.getLowBits(); + var highBits = longVal.getHighBits(); + // Encode low bits + buffer[index++] = lowBits & 0xff; + buffer[index++] = (lowBits >> 8) & 0xff; + buffer[index++] = (lowBits >> 16) & 0xff; + buffer[index++] = (lowBits >> 24) & 0xff; + // Encode high bits + buffer[index++] = highBits & 0xff; + buffer[index++] = (highBits >> 8) & 0xff; + buffer[index++] = (highBits >> 16) & 0xff; + buffer[index++] = (highBits >> 24) & 0xff; + } + } else { + // Encode as double + buffer[index++] = BSON.BSON_DATA_NUMBER; + // Number of written bytes + numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write float + writeIEEE754(buffer, value, index, 'little', 52, 8); + // Ajust index + index = index + 8; + } -Promise.prototype._setLength = function (len) { - this._bitField = (this._bitField & -65536) | - (len & 65535); + return index; }; -Promise.prototype._setFulfilled = function () { - this._bitField = this._bitField | 33554432; - this._fireEvent("promiseFulfilled", this); +var serializeNull = function(buffer, key, value, index, isArray) { + // Set long type + buffer[index++] = BSON.BSON_DATA_NULL; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + return index; }; -Promise.prototype._setRejected = function () { - this._bitField = this._bitField | 16777216; - this._fireEvent("promiseRejected", this); +var serializeBoolean = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_BOOLEAN; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Encode the boolean value + buffer[index++] = value ? 1 : 0; + return index; }; -Promise.prototype._setFollowing = function () { - this._bitField = this._bitField | 67108864; - this._fireEvent("promiseResolved", this); -}; +var serializeDate = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_DATE; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; -Promise.prototype._setIsFinal = function () { - this._bitField = this._bitField | 4194304; + // Write the date + var dateInMilis = Long.fromNumber(value.getTime()); + var lowBits = dateInMilis.getLowBits(); + var highBits = dateInMilis.getHighBits(); + // Encode low bits + buffer[index++] = lowBits & 0xff; + buffer[index++] = (lowBits >> 8) & 0xff; + buffer[index++] = (lowBits >> 16) & 0xff; + buffer[index++] = (lowBits >> 24) & 0xff; + // Encode high bits + buffer[index++] = highBits & 0xff; + buffer[index++] = (highBits >> 8) & 0xff; + buffer[index++] = (highBits >> 16) & 0xff; + buffer[index++] = (highBits >> 24) & 0xff; + return index; }; -Promise.prototype._isFinal = function () { - return (this._bitField & 4194304) > 0; +var serializeRegExp = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_REGEXP; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + if (value.source && value.source.match(regexp) != null) { + throw Error('value ' + value.source + ' must not contain null bytes'); + } + // Adjust the index + index = index + buffer.write(value.source, index, 'utf8'); + // Write zero + buffer[index++] = 0x00; + // Write the parameters + if (value.global) buffer[index++] = 0x73; // s + if (value.ignoreCase) buffer[index++] = 0x69; // i + if (value.multiline) buffer[index++] = 0x6d; // m + // Add ending zero + buffer[index++] = 0x00; + return index; }; -Promise.prototype._unsetCancelled = function() { - this._bitField = this._bitField & (~65536); -}; +var serializeBSONRegExp = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_REGEXP; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; -Promise.prototype._setCancelled = function() { - this._bitField = this._bitField | 65536; - this._fireEvent("promiseCancelled", this); -}; - -Promise.prototype._setWillBeCancelled = function() { - this._bitField = this._bitField | 8388608; -}; + // Check the pattern for 0 bytes + if (value.pattern.match(regexp) != null) { + // The BSON spec doesn't allow keys with null bytes because keys are + // null-terminated. + throw Error('pattern ' + value.pattern + ' must not contain null bytes'); + } -Promise.prototype._setAsyncGuaranteed = function() { - if (async.hasCustomScheduler()) return; - this._bitField = this._bitField | 134217728; + // Adjust the index + index = index + buffer.write(value.pattern, index, 'utf8'); + // Write zero + buffer[index++] = 0x00; + // Write the options + index = + index + + buffer.write( + value.options + .split('') + .sort() + .join(''), + index, + 'utf8' + ); + // Add ending zero + buffer[index++] = 0x00; + return index; }; -Promise.prototype._receiverAt = function (index) { - var ret = index === 0 ? this._receiver0 : this[ - index * 4 - 4 + 3]; - if (ret === UNDEFINED_BINDING) { - return undefined; - } else if (ret === undefined && this._isBound()) { - return this._boundValue(); - } - return ret; -}; +var serializeMinMax = function(buffer, key, value, index, isArray) { + // Write the type of either min or max key + if (value === null) { + buffer[index++] = BSON.BSON_DATA_NULL; + } else if (value._bsontype === 'MinKey') { + buffer[index++] = BSON.BSON_DATA_MIN_KEY; + } else { + buffer[index++] = BSON.BSON_DATA_MAX_KEY; + } -Promise.prototype._promiseAt = function (index) { - return this[ - index * 4 - 4 + 2]; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + return index; }; -Promise.prototype._fulfillmentHandlerAt = function (index) { - return this[ - index * 4 - 4 + 0]; -}; +var serializeObjectId = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_OID; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); -Promise.prototype._rejectionHandlerAt = function (index) { - return this[ - index * 4 - 4 + 1]; -}; + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; -Promise.prototype._boundValue = function() {}; + // Write the objectId into the shared buffer + if (typeof value.id === 'string') { + buffer.write(value.id, index, 'binary'); + } else if (value.id && value.id.copy) { + value.id.copy(buffer, index, 0, 12); + } else { + throw new Error('object [' + JSON.stringify(value) + '] is not a valid ObjectId'); + } -Promise.prototype._migrateCallback0 = function (follower) { - var bitField = follower._bitField; - var fulfill = follower._fulfillmentHandler0; - var reject = follower._rejectionHandler0; - var promise = follower._promise0; - var receiver = follower._receiverAt(0); - if (receiver === undefined) receiver = UNDEFINED_BINDING; - this._addCallbacks(fulfill, reject, promise, receiver, null); + // Ajust index + return index + 12; }; -Promise.prototype._migrateCallbackAt = function (follower, index) { - var fulfill = follower._fulfillmentHandlerAt(index); - var reject = follower._rejectionHandlerAt(index); - var promise = follower._promiseAt(index); - var receiver = follower._receiverAt(index); - if (receiver === undefined) receiver = UNDEFINED_BINDING; - this._addCallbacks(fulfill, reject, promise, receiver, null); +var serializeBuffer = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_BINARY; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Get size of the buffer (current write point) + var size = value.length; + // Write the size of the string to buffer + buffer[index++] = size & 0xff; + buffer[index++] = (size >> 8) & 0xff; + buffer[index++] = (size >> 16) & 0xff; + buffer[index++] = (size >> 24) & 0xff; + // Write the default subtype + buffer[index++] = BSON.BSON_BINARY_SUBTYPE_DEFAULT; + // Copy the content form the binary field to the buffer + value.copy(buffer, index, 0, size); + // Adjust the index + index = index + size; + return index; }; -Promise.prototype._addCallbacks = function ( - fulfill, - reject, - promise, - receiver, - domain +var serializeObject = function( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + isArray, + path ) { - var index = this._length(); - - if (index >= 65535 - 4) { - index = 0; - this._setLength(0); - } + for (var i = 0; i < path.length; i++) { + if (path[i] === value) throw new Error('cyclic dependency detected'); + } - if (index === 0) { - this._promise0 = promise; - this._receiver0 = receiver; - if (typeof fulfill === "function") { - this._fulfillmentHandler0 = - domain === null ? fulfill : util.domainBind(domain, fulfill); - } - if (typeof reject === "function") { - this._rejectionHandler0 = - domain === null ? reject : util.domainBind(domain, reject); - } - } else { - var base = index * 4 - 4; - this[base + 2] = promise; - this[base + 3] = receiver; - if (typeof fulfill === "function") { - this[base + 0] = - domain === null ? fulfill : util.domainBind(domain, fulfill); - } - if (typeof reject === "function") { - this[base + 1] = - domain === null ? reject : util.domainBind(domain, reject); - } - } - this._setLength(index + 1); - return index; + // Push value to stack + path.push(value); + // Write the type + buffer[index++] = Array.isArray(value) ? BSON.BSON_DATA_ARRAY : BSON.BSON_DATA_OBJECT; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + var endIndex = serializeInto( + buffer, + value, + checkKeys, + index, + depth + 1, + serializeFunctions, + ignoreUndefined, + path + ); + // Pop stack + path.pop(); + // Write size + return endIndex; }; -Promise.prototype._proxy = function (proxyable, arg) { - this._addCallbacks(undefined, undefined, arg, proxyable, null); +var serializeDecimal128 = function(buffer, key, value, index, isArray) { + buffer[index++] = BSON.BSON_DATA_DECIMAL128; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write the data from the value + value.bytes.copy(buffer, index, 0, 16); + return index + 16; }; -Promise.prototype._resolveCallback = function(value, shouldBind) { - if (((this._bitField & 117506048) !== 0)) return; - if (value === this) - return this._rejectCallback(makeSelfResolutionError(), false); - var maybePromise = tryConvertToPromise(value, this); - if (!(maybePromise instanceof Promise)) return this._fulfill(value); - - if (shouldBind) this._propagateFrom(maybePromise, 2); - - var promise = maybePromise._target(); - - if (promise === this) { - this._reject(makeSelfResolutionError()); - return; - } +var serializeLong = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = value._bsontype === 'Long' ? BSON.BSON_DATA_LONG : BSON.BSON_DATA_TIMESTAMP; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write the date + var lowBits = value.getLowBits(); + var highBits = value.getHighBits(); + // Encode low bits + buffer[index++] = lowBits & 0xff; + buffer[index++] = (lowBits >> 8) & 0xff; + buffer[index++] = (lowBits >> 16) & 0xff; + buffer[index++] = (lowBits >> 24) & 0xff; + // Encode high bits + buffer[index++] = highBits & 0xff; + buffer[index++] = (highBits >> 8) & 0xff; + buffer[index++] = (highBits >> 16) & 0xff; + buffer[index++] = (highBits >> 24) & 0xff; + return index; +}; - var bitField = promise._bitField; - if (((bitField & 50397184) === 0)) { - var len = this._length(); - if (len > 0) promise._migrateCallback0(this); - for (var i = 1; i < len; ++i) { - promise._migrateCallbackAt(this, i); - } - this._setFollowing(); - this._setLength(0); - this._setFollowee(promise); - } else if (((bitField & 33554432) !== 0)) { - this._fulfill(promise._value()); - } else if (((bitField & 16777216) !== 0)) { - this._reject(promise._reason()); - } else { - var reason = new CancellationError("late cancellation observer"); - promise._attachExtraTrace(reason); - this._reject(reason); - } +var serializeInt32 = function(buffer, key, value, index, isArray) { + // Set int type 32 bits or less + buffer[index++] = BSON.BSON_DATA_INT; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write the int value + buffer[index++] = value & 0xff; + buffer[index++] = (value >> 8) & 0xff; + buffer[index++] = (value >> 16) & 0xff; + buffer[index++] = (value >> 24) & 0xff; + return index; }; -Promise.prototype._rejectCallback = -function(reason, synchronous, ignoreNonErrorWarnings) { - var trace = util.ensureErrorObject(reason); - var hasStack = trace === reason; - if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) { - var message = "a promise was rejected with a non-error: " + - util.classString(reason); - this._warn(message, true); - } - this._attachExtraTrace(trace, synchronous ? hasStack : false); - this._reject(reason); +var serializeDouble = function(buffer, key, value, index, isArray) { + // Encode as double + buffer[index++] = BSON.BSON_DATA_NUMBER; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write float + writeIEEE754(buffer, value, index, 'little', 52, 8); + // Ajust index + index = index + 8; + return index; }; -Promise.prototype._resolveFromExecutor = function (executor) { - if (executor === INTERNAL) return; - var promise = this; - this._captureStackTrace(); - this._pushContext(); - var synchronous = true; - var r = this._execute(executor, function(value) { - promise._resolveCallback(value); - }, function (reason) { - promise._rejectCallback(reason, synchronous); - }); - synchronous = false; - this._popContext(); +var serializeFunction = function(buffer, key, value, index, checkKeys, depth, isArray) { + buffer[index++] = BSON.BSON_DATA_CODE; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Function string + var functionString = normalizedFunctionString(value); - if (r !== undefined) { - promise._rejectCallback(r, true); - } + // Write the string + var size = buffer.write(functionString, index + 4, 'utf8') + 1; + // Write the size of the string to buffer + buffer[index] = size & 0xff; + buffer[index + 1] = (size >> 8) & 0xff; + buffer[index + 2] = (size >> 16) & 0xff; + buffer[index + 3] = (size >> 24) & 0xff; + // Update index + index = index + 4 + size - 1; + // Write zero + buffer[index++] = 0; + return index; }; -Promise.prototype._settlePromiseFromHandler = function ( - handler, receiver, value, promise +var serializeCode = function( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + isArray ) { - var bitField = promise._bitField; - if (((bitField & 65536) !== 0)) return; - promise._pushContext(); - var x; - if (receiver === APPLY) { - if (!value || typeof value.length !== "number") { - x = errorObj; - x.e = new TypeError("cannot .spread() a non-array: " + - util.classString(value)); - } else { - x = tryCatch(handler).apply(this._boundValue(), value); - } - } else { - x = tryCatch(handler).call(receiver, value); - } - var promiseCreated = promise._popContext(); - bitField = promise._bitField; - if (((bitField & 65536) !== 0)) return; + if (value.scope && typeof value.scope === 'object') { + // Write the type + buffer[index++] = BSON.BSON_DATA_CODE_W_SCOPE; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; - if (x === NEXT_FILTER) { - promise._reject(value); - } else if (x === errorObj) { - promise._rejectCallback(x.e, false); - } else { - debug.checkForgottenReturns(x, promiseCreated, "", promise, this); - promise._resolveCallback(x); - } -}; + // Starting index + var startIndex = index; -Promise.prototype._target = function() { - var ret = this; - while (ret._isFollowing()) ret = ret._followee(); - return ret; -}; + // Serialize the function + // Get the function string + var functionString = typeof value.code === 'string' ? value.code : value.code.toString(); + // Index adjustment + index = index + 4; + // Write string into buffer + var codeSize = buffer.write(functionString, index + 4, 'utf8') + 1; + // Write the size of the string to buffer + buffer[index] = codeSize & 0xff; + buffer[index + 1] = (codeSize >> 8) & 0xff; + buffer[index + 2] = (codeSize >> 16) & 0xff; + buffer[index + 3] = (codeSize >> 24) & 0xff; + // Write end 0 + buffer[index + 4 + codeSize - 1] = 0; + // Write the + index = index + codeSize + 4; -Promise.prototype._followee = function() { - return this._rejectionHandler0; -}; + // + // Serialize the scope value + var endIndex = serializeInto( + buffer, + value.scope, + checkKeys, + index, + depth + 1, + serializeFunctions, + ignoreUndefined + ); + index = endIndex - 1; -Promise.prototype._setFollowee = function(promise) { - this._rejectionHandler0 = promise; -}; + // Writ the total + var totalSize = endIndex - startIndex; -Promise.prototype._settlePromise = function(promise, handler, receiver, value) { - var isPromise = promise instanceof Promise; - var bitField = this._bitField; - var asyncGuaranteed = ((bitField & 134217728) !== 0); - if (((bitField & 65536) !== 0)) { - if (isPromise) promise._invokeInternalOnCancel(); + // Write the total size of the object + buffer[startIndex++] = totalSize & 0xff; + buffer[startIndex++] = (totalSize >> 8) & 0xff; + buffer[startIndex++] = (totalSize >> 16) & 0xff; + buffer[startIndex++] = (totalSize >> 24) & 0xff; + // Write trailing zero + buffer[index++] = 0; + } else { + buffer[index++] = BSON.BSON_DATA_CODE; + // Number of written bytes + numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Function string + functionString = value.code.toString(); + // Write the string + var size = buffer.write(functionString, index + 4, 'utf8') + 1; + // Write the size of the string to buffer + buffer[index] = size & 0xff; + buffer[index + 1] = (size >> 8) & 0xff; + buffer[index + 2] = (size >> 16) & 0xff; + buffer[index + 3] = (size >> 24) & 0xff; + // Update index + index = index + 4 + size - 1; + // Write zero + buffer[index++] = 0; + } - if (receiver instanceof PassThroughHandlerContext && - receiver.isFinallyHandler()) { - receiver.cancelPromise = promise; - if (tryCatch(handler).call(receiver, value) === errorObj) { - promise._reject(errorObj.e); - } - } else if (handler === reflectHandler) { - promise._fulfill(reflectHandler.call(receiver)); - } else if (receiver instanceof Proxyable) { - receiver._promiseCancelled(promise); - } else if (isPromise || promise instanceof PromiseArray) { - promise._cancel(); - } else { - receiver.cancel(); - } - } else if (typeof handler === "function") { - if (!isPromise) { - handler.call(receiver, value, promise); - } else { - if (asyncGuaranteed) promise._setAsyncGuaranteed(); - this._settlePromiseFromHandler(handler, receiver, value, promise); - } - } else if (receiver instanceof Proxyable) { - if (!receiver._isResolved()) { - if (((bitField & 33554432) !== 0)) { - receiver._promiseFulfilled(value, promise); - } else { - receiver._promiseRejected(value, promise); - } - } - } else if (isPromise) { - if (asyncGuaranteed) promise._setAsyncGuaranteed(); - if (((bitField & 33554432) !== 0)) { - promise._fulfill(value); - } else { - promise._reject(value); - } - } -}; - -Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) { - var handler = ctx.handler; - var promise = ctx.promise; - var receiver = ctx.receiver; - var value = ctx.value; - if (typeof handler === "function") { - if (!(promise instanceof Promise)) { - handler.call(receiver, value, promise); - } else { - this._settlePromiseFromHandler(handler, receiver, value, promise); - } - } else if (promise instanceof Promise) { - promise._reject(value); - } -}; - -Promise.prototype._settlePromiseCtx = function(ctx) { - this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value); -}; - -Promise.prototype._settlePromise0 = function(handler, value, bitField) { - var promise = this._promise0; - var receiver = this._receiverAt(0); - this._promise0 = undefined; - this._receiver0 = undefined; - this._settlePromise(promise, handler, receiver, value); -}; - -Promise.prototype._clearCallbackDataAtIndex = function(index) { - var base = index * 4 - 4; - this[base + 2] = - this[base + 3] = - this[base + 0] = - this[base + 1] = undefined; -}; - -Promise.prototype._fulfill = function (value) { - var bitField = this._bitField; - if (((bitField & 117506048) >>> 16)) return; - if (value === this) { - var err = makeSelfResolutionError(); - this._attachExtraTrace(err); - return this._reject(err); - } - this._setFulfilled(); - this._rejectionHandler0 = value; - - if ((bitField & 65535) > 0) { - if (((bitField & 134217728) !== 0)) { - this._settlePromises(); - } else { - async.settlePromises(this); - } - } + return index; }; -Promise.prototype._reject = function (reason) { - var bitField = this._bitField; - if (((bitField & 117506048) >>> 16)) return; - this._setRejected(); - this._fulfillmentHandler0 = reason; - - if (this._isFinal()) { - return async.fatalError(reason, util.isNode); - } +var serializeBinary = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_BINARY; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Extract the buffer + var data = value.value(true); + // Calculate size + var size = value.position; + // Add the deprecated 02 type 4 bytes of size to total + if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) size = size + 4; + // Write the size of the string to buffer + buffer[index++] = size & 0xff; + buffer[index++] = (size >> 8) & 0xff; + buffer[index++] = (size >> 16) & 0xff; + buffer[index++] = (size >> 24) & 0xff; + // Write the subtype to the buffer + buffer[index++] = value.sub_type; - if ((bitField & 65535) > 0) { - async.settlePromises(this); - } else { - this._ensurePossibleRejectionHandled(); - } -}; + // If we have binary type 2 the 4 first bytes are the size + if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) { + size = size - 4; + buffer[index++] = size & 0xff; + buffer[index++] = (size >> 8) & 0xff; + buffer[index++] = (size >> 16) & 0xff; + buffer[index++] = (size >> 24) & 0xff; + } -Promise.prototype._fulfillPromises = function (len, value) { - for (var i = 1; i < len; i++) { - var handler = this._fulfillmentHandlerAt(i); - var promise = this._promiseAt(i); - var receiver = this._receiverAt(i); - this._clearCallbackDataAtIndex(i); - this._settlePromise(promise, handler, receiver, value); - } + // Write the data to the object + data.copy(buffer, index, 0, value.position); + // Adjust the index + index = index + value.position; + return index; }; -Promise.prototype._rejectPromises = function (len, reason) { - for (var i = 1; i < len; i++) { - var handler = this._rejectionHandlerAt(i); - var promise = this._promiseAt(i); - var receiver = this._receiverAt(i); - this._clearCallbackDataAtIndex(i); - this._settlePromise(promise, handler, receiver, reason); - } +var serializeSymbol = function(buffer, key, value, index, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_SYMBOL; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; + // Write the string + var size = buffer.write(value.value, index + 4, 'utf8') + 1; + // Write the size of the string to buffer + buffer[index] = size & 0xff; + buffer[index + 1] = (size >> 8) & 0xff; + buffer[index + 2] = (size >> 16) & 0xff; + buffer[index + 3] = (size >> 24) & 0xff; + // Update index + index = index + 4 + size - 1; + // Write zero + buffer[index++] = 0x00; + return index; }; -Promise.prototype._settlePromises = function () { - var bitField = this._bitField; - var len = (bitField & 65535); +var serializeDBRef = function(buffer, key, value, index, depth, serializeFunctions, isArray) { + // Write the type + buffer[index++] = BSON.BSON_DATA_OBJECT; + // Number of written bytes + var numberOfWrittenBytes = !isArray + ? buffer.write(key, index, 'utf8') + : buffer.write(key, index, 'ascii'); - if (len > 0) { - if (((bitField & 16842752) !== 0)) { - var reason = this._fulfillmentHandler0; - this._settlePromise0(this._rejectionHandler0, reason, bitField); - this._rejectPromises(len, reason); - } else { - var value = this._rejectionHandler0; - this._settlePromise0(this._fulfillmentHandler0, value, bitField); - this._fulfillPromises(len, value); - } - this._setLength(0); - } - this._clearCancellationData(); -}; + // Encode the name + index = index + numberOfWrittenBytes; + buffer[index++] = 0; -Promise.prototype._settledValue = function() { - var bitField = this._bitField; - if (((bitField & 33554432) !== 0)) { - return this._rejectionHandler0; - } else if (((bitField & 16777216) !== 0)) { - return this._fulfillmentHandler0; - } -}; + var startIndex = index; + var endIndex; -function deferResolve(v) {this.promise._resolveCallback(v);} -function deferReject(v) {this.promise._rejectCallback(v, false);} + // Serialize object + if (null != value.db) { + endIndex = serializeInto( + buffer, + { + $ref: value.namespace, + $id: value.oid, + $db: value.db + }, + false, + index, + depth + 1, + serializeFunctions + ); + } else { + endIndex = serializeInto( + buffer, + { + $ref: value.namespace, + $id: value.oid + }, + false, + index, + depth + 1, + serializeFunctions + ); + } -Promise.defer = Promise.pending = function() { - debug.deprecated("Promise.defer", "new Promise"); - var promise = new Promise(INTERNAL); - return { - promise: promise, - resolve: deferResolve, - reject: deferReject - }; + // Calculate object size + var size = endIndex - startIndex; + // Write the size + buffer[startIndex++] = size & 0xff; + buffer[startIndex++] = (size >> 8) & 0xff; + buffer[startIndex++] = (size >> 16) & 0xff; + buffer[startIndex++] = (size >> 24) & 0xff; + // Set index + return endIndex; }; -util.notEnumerableProp(Promise, - "_makeSelfResolutionError", - makeSelfResolutionError); +var serializeInto = function serializeInto( + buffer, + object, + checkKeys, + startingIndex, + depth, + serializeFunctions, + ignoreUndefined, + path +) { + startingIndex = startingIndex || 0; + path = path || []; -_dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection, - debug); -_dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug); -_dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug); -_dereq_("./direct_resolve")(Promise); -_dereq_("./synchronous_inspection")(Promise); -_dereq_("./join")( - Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain); -Promise.Promise = Promise; -Promise.version = "3.5.1"; -_dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); -_dereq_('./call_get.js')(Promise); -_dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug); -_dereq_('./timers.js')(Promise, INTERNAL, debug); -_dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug); -_dereq_('./nodeify.js')(Promise); -_dereq_('./promisify.js')(Promise, INTERNAL); -_dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection); -_dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection); -_dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); -_dereq_('./settle.js')(Promise, PromiseArray, debug); -_dereq_('./some.js')(Promise, PromiseArray, apiRejection); -_dereq_('./filter.js')(Promise, INTERNAL); -_dereq_('./each.js')(Promise, INTERNAL); -_dereq_('./any.js')(Promise); - - util.toFastProperties(Promise); - util.toFastProperties(Promise.prototype); - function fillTypes(value) { - var p = new Promise(INTERNAL); - p._fulfillmentHandler0 = value; - p._rejectionHandler0 = value; - p._promise0 = value; - p._receiver0 = value; - } - // Complete slack tracking, opt out of field-type tracking and - // stabilize map - fillTypes({a: 1}); - fillTypes({b: 2}); - fillTypes({c: 3}); - fillTypes(1); - fillTypes(function(){}); - fillTypes(undefined); - fillTypes(false); - fillTypes(new Promise(INTERNAL)); - debug.setBounds(Async.firstLineError, util.lastLineError); - return Promise; + // Push the object to the path + path.push(object); -}; + // Start place to serialize into + var index = startingIndex + 4; + // var self = this; -},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL, tryConvertToPromise, - apiRejection, Proxyable) { -var util = _dereq_("./util"); -var isArray = util.isArray; + // Special case isArray + if (Array.isArray(object)) { + // Get object keys + for (var i = 0; i < object.length; i++) { + var key = '' + i; + var value = object[i]; -function toResolutionValue(val) { - switch(val) { - case -2: return []; - case -3: return {}; - case -6: return new Map(); - } -} + // Is there an override value + if (value && value.toBSON) { + if (typeof value.toBSON !== 'function') throw new Error('toBSON is not a function'); + value = value.toBSON(); + } -function PromiseArray(values) { - var promise = this._promise = new Promise(INTERNAL); - if (values instanceof Promise) { - promise._propagateFrom(values, 3); + var type = typeof value; + if (type === 'string') { + index = serializeString(buffer, key, value, index, true); + } else if (type === 'number') { + index = serializeNumber(buffer, key, value, index, true); + } else if(type === 'bigint') { + throw new TypeError('Unsupported type BigInt, please use Decimal128'); + } else if (type === 'boolean') { + index = serializeBoolean(buffer, key, value, index, true); + } else if (value instanceof Date || isDate(value)) { + index = serializeDate(buffer, key, value, index, true); + } else if (value === undefined) { + index = serializeNull(buffer, key, value, index, true); + } else if (value === null) { + index = serializeNull(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { + index = serializeObjectId(buffer, key, value, index, true); + } else if (Buffer.isBuffer(value)) { + index = serializeBuffer(buffer, key, value, index, true); + } else if (value instanceof RegExp || isRegExp(value)) { + index = serializeRegExp(buffer, key, value, index, true); + } else if (type === 'object' && value['_bsontype'] == null) { + index = serializeObject( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + true, + path + ); + } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { + index = serializeDecimal128(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { + index = serializeLong(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'Double') { + index = serializeDouble(buffer, key, value, index, true); + } else if (typeof value === 'function' && serializeFunctions) { + index = serializeFunction( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + true + ); + } else if (value['_bsontype'] === 'Code') { + index = serializeCode( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + true + ); + } else if (value['_bsontype'] === 'Binary') { + index = serializeBinary(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'Symbol') { + index = serializeSymbol(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'DBRef') { + index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, true); + } else if (value['_bsontype'] === 'BSONRegExp') { + index = serializeBSONRegExp(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'Int32') { + index = serializeInt32(buffer, key, value, index, true); + } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { + index = serializeMinMax(buffer, key, value, index, true); + } else if (typeof value['_bsontype'] !== 'undefined') { + throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); + } } - promise._setOnCancel(this); - this._values = values; - this._length = 0; - this._totalResolved = 0; - this._init(undefined, -2); -} -util.inherits(PromiseArray, Proxyable); + } else if (object instanceof Map) { + var iterator = object.entries(); + var done = false; -PromiseArray.prototype.length = function () { - return this._length; -}; + while (!done) { + // Unpack the next entry + var entry = iterator.next(); + done = entry.done; + // Are we done, then skip and terminate + if (done) continue; -PromiseArray.prototype.promise = function () { - return this._promise; -}; + // Get the entry values + key = entry.value[0]; + value = entry.value[1]; -PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) { - var values = tryConvertToPromise(this._values, this._promise); - if (values instanceof Promise) { - values = values._target(); - var bitField = values._bitField; - ; - this._values = values; + // Check the type of the value + type = typeof value; - if (((bitField & 50397184) === 0)) { - this._promise._setAsyncGuaranteed(); - return values._then( - init, - this._reject, - undefined, - this, - resolveValueIfEmpty - ); - } else if (((bitField & 33554432) !== 0)) { - values = values._value(); - } else if (((bitField & 16777216) !== 0)) { - return this._reject(values._reason()); - } else { - return this._cancel(); + // Check the key and throw error if it's illegal + if (typeof key === 'string' && ignoreKeys.indexOf(key) === -1) { + if (key.match(regexp) != null) { + // The BSON spec doesn't allow keys with null bytes because keys are + // null-terminated. + throw Error('key ' + key + ' must not contain null bytes'); } - } - values = util.asArray(values); - if (values === null) { - var err = apiRejection( - "expecting an array or an iterable object but got " + util.classString(values)).reason(); - this._promise._rejectCallback(err, false); - return; - } - if (values.length === 0) { - if (resolveValueIfEmpty === -5) { - this._resolveEmptyArray(); - } - else { - this._resolve(toResolutionValue(resolveValueIfEmpty)); + if (checkKeys) { + if ('$' === key[0]) { + throw Error('key ' + key + " must not start with '$'"); + } else if (~key.indexOf('.')) { + throw Error('key ' + key + " must not contain '.'"); + } } - return; - } - this._iterate(values); -}; - -PromiseArray.prototype._iterate = function(values) { - var len = this.getActualLength(values.length); - this._length = len; - this._values = this.shouldCopyValues() ? new Array(len) : this._values; - var result = this._promise; - var isResolved = false; - var bitField = null; - for (var i = 0; i < len; ++i) { - var maybePromise = tryConvertToPromise(values[i], result); + } - if (maybePromise instanceof Promise) { - maybePromise = maybePromise._target(); - bitField = maybePromise._bitField; - } else { - bitField = null; + if (type === 'string') { + index = serializeString(buffer, key, value, index); + } else if (type === 'number') { + index = serializeNumber(buffer, key, value, index); + } else if(type === 'bigint') { + throw new TypeError('Unsupported type BigInt, please use Decimal128'); + } else if (type === 'boolean') { + index = serializeBoolean(buffer, key, value, index); + } else if (value instanceof Date || isDate(value)) { + index = serializeDate(buffer, key, value, index); + // } else if (value === undefined && ignoreUndefined === true) { + } else if (value === null || (value === undefined && ignoreUndefined === false)) { + index = serializeNull(buffer, key, value, index); + } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { + index = serializeObjectId(buffer, key, value, index); + } else if (Buffer.isBuffer(value)) { + index = serializeBuffer(buffer, key, value, index); + } else if (value instanceof RegExp || isRegExp(value)) { + index = serializeRegExp(buffer, key, value, index); + } else if (type === 'object' && value['_bsontype'] == null) { + index = serializeObject( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + false, + path + ); + } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { + index = serializeDecimal128(buffer, key, value, index); + } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { + index = serializeLong(buffer, key, value, index); + } else if (value['_bsontype'] === 'Double') { + index = serializeDouble(buffer, key, value, index); + } else if (value['_bsontype'] === 'Code') { + index = serializeCode( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined + ); + } else if (typeof value === 'function' && serializeFunctions) { + index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions); + } else if (value['_bsontype'] === 'Binary') { + index = serializeBinary(buffer, key, value, index); + } else if (value['_bsontype'] === 'Symbol') { + index = serializeSymbol(buffer, key, value, index); + } else if (value['_bsontype'] === 'DBRef') { + index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions); + } else if (value['_bsontype'] === 'BSONRegExp') { + index = serializeBSONRegExp(buffer, key, value, index); + } else if (value['_bsontype'] === 'Int32') { + index = serializeInt32(buffer, key, value, index); + } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { + index = serializeMinMax(buffer, key, value, index); + } else if (typeof value['_bsontype'] !== 'undefined') { + throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); + } + } + } else { + // Did we provide a custom serialization method + if (object.toBSON) { + if (typeof object.toBSON !== 'function') throw new Error('toBSON is not a function'); + object = object.toBSON(); + if (object != null && typeof object !== 'object') + throw new Error('toBSON function did not return an object'); + } + + // Iterate over all the keys + for (key in object) { + value = object[key]; + // Is there an override value + if (value && value.toBSON) { + if (typeof value.toBSON !== 'function') throw new Error('toBSON is not a function'); + value = value.toBSON(); + } + + // Check the type of the value + type = typeof value; + + // Check the key and throw error if it's illegal + if (typeof key === 'string' && ignoreKeys.indexOf(key) === -1) { + if (key.match(regexp) != null) { + // The BSON spec doesn't allow keys with null bytes because keys are + // null-terminated. + throw Error('key ' + key + ' must not contain null bytes'); } - if (isResolved) { - if (bitField !== null) { - maybePromise.suppressUnhandledRejections(); - } - } else if (bitField !== null) { - if (((bitField & 50397184) === 0)) { - maybePromise._proxy(this, i); - this._values[i] = maybePromise; - } else if (((bitField & 33554432) !== 0)) { - isResolved = this._promiseFulfilled(maybePromise._value(), i); - } else if (((bitField & 16777216) !== 0)) { - isResolved = this._promiseRejected(maybePromise._reason(), i); - } else { - isResolved = this._promiseCancelled(i); - } - } else { - isResolved = this._promiseFulfilled(maybePromise, i); + if (checkKeys) { + if ('$' === key[0]) { + throw Error('key ' + key + " must not start with '$'"); + } else if (~key.indexOf('.')) { + throw Error('key ' + key + " must not contain '.'"); + } } - } - if (!isResolved) result._setAsyncGuaranteed(); -}; + } -PromiseArray.prototype._isResolved = function () { - return this._values === null; -}; + if (type === 'string') { + index = serializeString(buffer, key, value, index); + } else if (type === 'number') { + index = serializeNumber(buffer, key, value, index); + } else if(type === 'bigint') { + throw new TypeError('Unsupported type BigInt, please use Decimal128'); + } else if (type === 'boolean') { + index = serializeBoolean(buffer, key, value, index); + } else if (value instanceof Date || isDate(value)) { + index = serializeDate(buffer, key, value, index); + } else if (value === undefined) { + if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index); + } else if (value === null) { + index = serializeNull(buffer, key, value, index); + } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { + index = serializeObjectId(buffer, key, value, index); + } else if (Buffer.isBuffer(value)) { + index = serializeBuffer(buffer, key, value, index); + } else if (value instanceof RegExp || isRegExp(value)) { + index = serializeRegExp(buffer, key, value, index); + } else if (type === 'object' && value['_bsontype'] == null) { + index = serializeObject( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined, + false, + path + ); + } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { + index = serializeDecimal128(buffer, key, value, index); + } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { + index = serializeLong(buffer, key, value, index); + } else if (value['_bsontype'] === 'Double') { + index = serializeDouble(buffer, key, value, index); + } else if (value['_bsontype'] === 'Code') { + index = serializeCode( + buffer, + key, + value, + index, + checkKeys, + depth, + serializeFunctions, + ignoreUndefined + ); + } else if (typeof value === 'function' && serializeFunctions) { + index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions); + } else if (value['_bsontype'] === 'Binary') { + index = serializeBinary(buffer, key, value, index); + } else if (value['_bsontype'] === 'Symbol') { + index = serializeSymbol(buffer, key, value, index); + } else if (value['_bsontype'] === 'DBRef') { + index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions); + } else if (value['_bsontype'] === 'BSONRegExp') { + index = serializeBSONRegExp(buffer, key, value, index); + } else if (value['_bsontype'] === 'Int32') { + index = serializeInt32(buffer, key, value, index); + } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { + index = serializeMinMax(buffer, key, value, index); + } else if (typeof value['_bsontype'] !== 'undefined') { + throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); + } + } + } -PromiseArray.prototype._resolve = function (value) { - this._values = null; - this._promise._fulfill(value); -}; + // Remove the path + path.pop(); -PromiseArray.prototype._cancel = function() { - if (this._isResolved() || !this._promise._isCancellable()) return; - this._values = null; - this._promise._cancel(); -}; + // Final padding byte for object + buffer[index++] = 0x00; -PromiseArray.prototype._reject = function (reason) { - this._values = null; - this._promise._rejectCallback(reason, false); + // Final size + var size = index - startingIndex; + // Write the size of the object + buffer[startingIndex++] = size & 0xff; + buffer[startingIndex++] = (size >> 8) & 0xff; + buffer[startingIndex++] = (size >> 16) & 0xff; + buffer[startingIndex++] = (size >> 24) & 0xff; + return index; }; -PromiseArray.prototype._promiseFulfilled = function (value, index) { - this._values[index] = value; - var totalResolved = ++this._totalResolved; - if (totalResolved >= this._length) { - this._resolve(this._values); - return true; - } - return false; -}; +var BSON = {}; -PromiseArray.prototype._promiseCancelled = function() { - this._cancel(); - return true; -}; +/** + * Contains the function cache if we have that enable to allow for avoiding the eval step on each deserialization, comparison is by md5 + * + * @ignore + * @api private + */ +// var functionCache = (BSON.functionCache = {}); -PromiseArray.prototype._promiseRejected = function (reason) { - this._totalResolved++; - this._reject(reason); - return true; -}; +/** + * Number BSON Type + * + * @classconstant BSON_DATA_NUMBER + **/ +BSON.BSON_DATA_NUMBER = 1; +/** + * String BSON Type + * + * @classconstant BSON_DATA_STRING + **/ +BSON.BSON_DATA_STRING = 2; +/** + * Object BSON Type + * + * @classconstant BSON_DATA_OBJECT + **/ +BSON.BSON_DATA_OBJECT = 3; +/** + * Array BSON Type + * + * @classconstant BSON_DATA_ARRAY + **/ +BSON.BSON_DATA_ARRAY = 4; +/** + * Binary BSON Type + * + * @classconstant BSON_DATA_BINARY + **/ +BSON.BSON_DATA_BINARY = 5; +/** + * ObjectID BSON Type, deprecated + * + * @classconstant BSON_DATA_UNDEFINED + **/ +BSON.BSON_DATA_UNDEFINED = 6; +/** + * ObjectID BSON Type + * + * @classconstant BSON_DATA_OID + **/ +BSON.BSON_DATA_OID = 7; +/** + * Boolean BSON Type + * + * @classconstant BSON_DATA_BOOLEAN + **/ +BSON.BSON_DATA_BOOLEAN = 8; +/** + * Date BSON Type + * + * @classconstant BSON_DATA_DATE + **/ +BSON.BSON_DATA_DATE = 9; +/** + * null BSON Type + * + * @classconstant BSON_DATA_NULL + **/ +BSON.BSON_DATA_NULL = 10; +/** + * RegExp BSON Type + * + * @classconstant BSON_DATA_REGEXP + **/ +BSON.BSON_DATA_REGEXP = 11; +/** + * Code BSON Type + * + * @classconstant BSON_DATA_CODE + **/ +BSON.BSON_DATA_CODE = 13; +/** + * Symbol BSON Type + * + * @classconstant BSON_DATA_SYMBOL + **/ +BSON.BSON_DATA_SYMBOL = 14; +/** + * Code with Scope BSON Type + * + * @classconstant BSON_DATA_CODE_W_SCOPE + **/ +BSON.BSON_DATA_CODE_W_SCOPE = 15; +/** + * 32 bit Integer BSON Type + * + * @classconstant BSON_DATA_INT + **/ +BSON.BSON_DATA_INT = 16; +/** + * Timestamp BSON Type + * + * @classconstant BSON_DATA_TIMESTAMP + **/ +BSON.BSON_DATA_TIMESTAMP = 17; +/** + * Long BSON Type + * + * @classconstant BSON_DATA_LONG + **/ +BSON.BSON_DATA_LONG = 18; +/** + * Long BSON Type + * + * @classconstant BSON_DATA_DECIMAL128 + **/ +BSON.BSON_DATA_DECIMAL128 = 19; +/** + * MinKey BSON Type + * + * @classconstant BSON_DATA_MIN_KEY + **/ +BSON.BSON_DATA_MIN_KEY = 0xff; +/** + * MaxKey BSON Type + * + * @classconstant BSON_DATA_MAX_KEY + **/ +BSON.BSON_DATA_MAX_KEY = 0x7f; +/** + * Binary Default Type + * + * @classconstant BSON_BINARY_SUBTYPE_DEFAULT + **/ +BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; +/** + * Binary Function Type + * + * @classconstant BSON_BINARY_SUBTYPE_FUNCTION + **/ +BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; +/** + * Binary Byte Array Type + * + * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY + **/ +BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; +/** + * Binary UUID Type + * + * @classconstant BSON_BINARY_SUBTYPE_UUID + **/ +BSON.BSON_BINARY_SUBTYPE_UUID = 3; +/** + * Binary MD5 Type + * + * @classconstant BSON_BINARY_SUBTYPE_MD5 + **/ +BSON.BSON_BINARY_SUBTYPE_MD5 = 4; +/** + * Binary User Defined Type + * + * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED + **/ +BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; -PromiseArray.prototype._resultCancelled = function() { - if (this._isResolved()) return; - var values = this._values; - this._cancel(); - if (values instanceof Promise) { - values.cancel(); - } else { - for (var i = 0; i < values.length; ++i) { - if (values[i] instanceof Promise) { - values[i].cancel(); - } - } - } -}; +// BSON MAX VALUES +BSON.BSON_INT32_MAX = 0x7fffffff; +BSON.BSON_INT32_MIN = -0x80000000; -PromiseArray.prototype.shouldCopyValues = function () { - return true; -}; +BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; +BSON.BSON_INT64_MIN = -Math.pow(2, 63); -PromiseArray.prototype.getActualLength = function (len) { - return len; -}; +// JS MAX PRECISE VALUES +BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. +BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. -return PromiseArray; -}; +// Internal long versions +// var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. +// var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. -},{"./util":36}],24:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL) { -var THIS = {}; -var util = _dereq_("./util"); -var nodebackForPromise = _dereq_("./nodeback"); -var withAppended = util.withAppended; -var maybeWrapAsError = util.maybeWrapAsError; -var canEvaluate = util.canEvaluate; -var TypeError = _dereq_("./errors").TypeError; -var defaultSuffix = "Async"; -var defaultPromisified = {__isPromisified__: true}; -var noCopyProps = [ - "arity", "length", - "name", - "arguments", - "caller", - "callee", - "prototype", - "__isPromisified__" -]; -var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$"); +module.exports = serializeInto; -var defaultFilter = function(name) { - return util.isIdentifier(name) && - name.charAt(0) !== "_" && - name !== "constructor"; -}; +}).call(this)}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) +},{"../../../../is-buffer/index.js":220,"../binary":15,"../float_parser":21,"../long":23,"../map":24,"./utils":31}],31:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; -function propsFilter(key) { - return !noCopyPropsPattern.test(key); +/** + * Normalizes our expected stringified form of a function across versions of node + * @param {Function} fn The function to stringify + */ +function normalizedFunctionString(fn) { + return fn.toString().replace(/function *\(/, 'function ('); } -function isPromisified(fn) { - try { - return fn.__isPromisified__ === true; - } - catch (e) { - return false; - } +function newBuffer(item, encoding) { + return new Buffer(item, encoding); } -function hasPromisified(obj, key, suffix) { - var val = util.getDataPropertyOrDefault(obj, key + suffix, - defaultPromisified); - return val ? isPromisified(val) : false; +function allocBuffer() { + return Buffer.alloc.apply(Buffer, arguments); } -function checkValid(ret, suffix, suffixRegexp) { - for (var i = 0; i < ret.length; i += 2) { - var key = ret[i]; - if (suffixRegexp.test(key)) { - var keyWithoutAsyncSuffix = key.replace(suffixRegexp, ""); - for (var j = 0; j < ret.length; j += 2) { - if (ret[j] === keyWithoutAsyncSuffix) { - throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a" - .replace("%s", suffix)); - } - } - } - } + +function toBuffer() { + return Buffer.from.apply(Buffer, arguments); } -function promisifiableMethods(obj, suffix, suffixRegexp, filter) { - var keys = util.inheritedDataKeys(obj); - var ret = []; - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - var value = obj[key]; - var passesDefaultFilter = filter === defaultFilter - ? true : defaultFilter(key, value, obj); - if (typeof value === "function" && - !isPromisified(value) && - !hasPromisified(obj, key, suffix) && - filter(key, value, obj, passesDefaultFilter)) { - ret.push(key, value); - } - } - checkValid(ret, suffix, suffixRegexp); - return ret; -} - -var escapeIdentRegex = function(str) { - return str.replace(/([$])/, "\\$"); +module.exports = { + normalizedFunctionString: normalizedFunctionString, + allocBuffer: typeof Buffer.alloc === 'function' ? allocBuffer : newBuffer, + toBuffer: typeof Buffer.from === 'function' ? toBuffer : newBuffer }; -var makeNodePromisifiedEval; -if (!true) { -var switchCaseArgumentOrder = function(likelyArgumentCount) { - var ret = [likelyArgumentCount]; - var min = Math.max(0, likelyArgumentCount - 1 - 3); - for(var i = likelyArgumentCount - 1; i >= min; --i) { - ret.push(i); - } - for(var i = likelyArgumentCount + 1; i <= 3; ++i) { - ret.push(i); - } - return ret; -}; -var argumentSequence = function(argumentCount) { - return util.filledRange(argumentCount, "_arg", ""); -}; +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":35}],32:[function(require,module,exports){ +/** + * A class representation of the BSON RegExp type. + * + * @class + * @return {BSONRegExp} A MinKey instance + */ +function BSONRegExp(pattern, options) { + if (!(this instanceof BSONRegExp)) return new BSONRegExp(); -var parameterDeclaration = function(parameterCount) { - return util.filledRange( - Math.max(parameterCount, 3), "_arg", ""); -}; + // Execute + this._bsontype = 'BSONRegExp'; + this.pattern = pattern || ''; + this.options = options || ''; -var parameterCount = function(fn) { - if (typeof fn.length === "number") { - return Math.max(Math.min(fn.length, 1023 + 1), 0); + // Validate options + for (var i = 0; i < this.options.length; i++) { + if ( + !( + this.options[i] === 'i' || + this.options[i] === 'm' || + this.options[i] === 'x' || + this.options[i] === 'l' || + this.options[i] === 's' || + this.options[i] === 'u' + ) + ) { + throw new Error('the regular expression options [' + this.options[i] + '] is not supported'); } - return 0; -}; + } +} -makeNodePromisifiedEval = -function(callback, receiver, originalName, fn, _, multiArgs) { - var newParameterCount = Math.max(0, parameterCount(fn) - 1); - var argumentOrder = switchCaseArgumentOrder(newParameterCount); - var shouldProxyThis = typeof callback === "string" || receiver === THIS; +module.exports = BSONRegExp; +module.exports.BSONRegExp = BSONRegExp; - function generateCallForArgumentCount(count) { - var args = argumentSequence(count).join(", "); - var comma = count > 0 ? ", " : ""; - var ret; - if (shouldProxyThis) { - ret = "ret = callback.call(this, {{args}}, nodeback); break;\n"; - } else { - ret = receiver === undefined - ? "ret = callback({{args}}, nodeback); break;\n" - : "ret = callback.call(receiver, {{args}}, nodeback); break;\n"; - } - return ret.replace("{{args}}", args).replace(", ", comma); - } +},{}],33:[function(require,module,exports){ +(function (Buffer){(function (){ +// Custom inspect property name / symbol. +var inspect = Buffer ? require('util').inspect.custom || 'inspect' : 'inspect'; - function generateArgumentSwitchCase() { - var ret = ""; - for (var i = 0; i < argumentOrder.length; ++i) { - ret += "case " + argumentOrder[i] +":" + - generateCallForArgumentCount(argumentOrder[i]); - } +/** + * A class representation of the BSON Symbol type. + * + * @class + * @deprecated + * @param {string} value the string representing the symbol. + * @return {Symbol} + */ +function Symbol(value) { + if (!(this instanceof Symbol)) return new Symbol(value); + this._bsontype = 'Symbol'; + this.value = value; +} - ret += " \n\ - default: \n\ - var args = new Array(len + 1); \n\ - var i = 0; \n\ - for (var i = 0; i < len; ++i) { \n\ - args[i] = arguments[i]; \n\ - } \n\ - args[i] = nodeback; \n\ - [CodeForCall] \n\ - break; \n\ - ".replace("[CodeForCall]", (shouldProxyThis - ? "ret = callback.apply(this, args);\n" - : "ret = callback.apply(receiver, args);\n")); - return ret; - } +/** + * Access the wrapped string value. + * + * @method + * @return {String} returns the wrapped string. + */ +Symbol.prototype.valueOf = function() { + return this.value; +}; - var getFunctionCode = typeof callback === "string" - ? ("this != null ? this['"+callback+"'] : fn") - : "fn"; - var body = "'use strict'; \n\ - var ret = function (Parameters) { \n\ - 'use strict'; \n\ - var len = arguments.length; \n\ - var promise = new Promise(INTERNAL); \n\ - promise._captureStackTrace(); \n\ - var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\ - var ret; \n\ - var callback = tryCatch([GetFunctionCode]); \n\ - switch(len) { \n\ - [CodeForSwitchCase] \n\ - } \n\ - if (ret === errorObj) { \n\ - promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\ - } \n\ - if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\ - return promise; \n\ - }; \n\ - notEnumerableProp(ret, '__isPromisified__', true); \n\ - return ret; \n\ - ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase()) - .replace("[GetFunctionCode]", getFunctionCode); - body = body.replace("Parameters", parameterDeclaration(newParameterCount)); - return new Function("Promise", - "fn", - "receiver", - "withAppended", - "maybeWrapAsError", - "nodebackForPromise", - "tryCatch", - "errorObj", - "notEnumerableProp", - "INTERNAL", - body)( - Promise, - fn, - receiver, - withAppended, - maybeWrapAsError, - nodebackForPromise, - util.tryCatch, - util.errorObj, - util.notEnumerableProp, - INTERNAL); +/** + * @ignore + */ +Symbol.prototype.toString = function() { + return this.value; }; -} -function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) { - var defaultThis = (function() {return this;})(); - var method = callback; - if (typeof method === "string") { - callback = fn; - } - function promisified() { - var _receiver = receiver; - if (receiver === THIS) _receiver = this; - var promise = new Promise(INTERNAL); - promise._captureStackTrace(); - var cb = typeof method === "string" && this !== defaultThis - ? this[method] : callback; - var fn = nodebackForPromise(promise, multiArgs); - try { - cb.apply(_receiver, withAppended(arguments, fn)); - } catch(e) { - promise._rejectCallback(maybeWrapAsError(e), true, true); - } - if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); - return promise; - } - util.notEnumerableProp(promisified, "__isPromisified__", true); - return promisified; -} +/** + * @ignore + */ +Symbol.prototype[inspect] = function() { + return this.value; +}; -var makeNodePromisified = canEvaluate - ? makeNodePromisifiedEval - : makeNodePromisifiedClosure; +/** + * @ignore + */ +Symbol.prototype.toJSON = function() { + return this.value; +}; -function promisifyAll(obj, suffix, filter, promisifier, multiArgs) { - var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$"); - var methods = - promisifiableMethods(obj, suffix, suffixRegexp, filter); +module.exports = Symbol; +module.exports.Symbol = Symbol; - for (var i = 0, len = methods.length; i < len; i+= 2) { - var key = methods[i]; - var fn = methods[i+1]; - var promisifiedKey = key + suffix; - if (promisifier === makeNodePromisified) { - obj[promisifiedKey] = - makeNodePromisified(key, THIS, key, fn, suffix, multiArgs); - } else { - var promisified = promisifier(fn, function() { - return makeNodePromisified(key, THIS, key, - fn, suffix, multiArgs); - }); - util.notEnumerableProp(promisified, "__isPromisified__", true); - obj[promisifiedKey] = promisified; - } - } - util.toFastProperties(obj); - return obj; -} +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":35,"util":378}],34:[function(require,module,exports){ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2009 Google Inc. All Rights Reserved -function promisify(callback, receiver, multiArgs) { - return makeNodePromisified(callback, receiver, undefined, - callback, null, multiArgs); +/** + * This type is for INTERNAL use in MongoDB only and should not be used in applications. + * The appropriate corresponding type is the JavaScript Date type. + * + * Defines a Timestamp class for representing a 64-bit two's-complement + * integer value, which faithfully simulates the behavior of a Java "Timestamp". This + * implementation is derived from TimestampLib in GWT. + * + * Constructs a 64-bit two's-complement integer, given its low and high 32-bit + * values as *signed* integers. See the from* functions below for more + * convenient ways of constructing Timestamps. + * + * The internal representation of a Timestamp is the two given signed, 32-bit values. + * We use 32-bit pieces because these are the size of integers on which + * Javascript performs bit-operations. For operations like addition and + * multiplication, we split each number into 16-bit pieces, which can easily be + * multiplied within Javascript's floating-point representation without overflow + * or change in sign. + * + * In the algorithms below, we frequently reduce the negative case to the + * positive case by negating the input(s) and then post-processing the result. + * Note that we must ALWAYS check specially whether those values are MIN_VALUE + * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as + * a positive number, it overflows back into a negative). Not handling this + * case would often result in infinite recursion. + * + * @class + * @param {number} low the low (signed) 32 bits of the Timestamp. + * @param {number} high the high (signed) 32 bits of the Timestamp. + */ +function Timestamp(low, high) { + if (!(this instanceof Timestamp)) return new Timestamp(low, high); + this._bsontype = 'Timestamp'; + /** + * @type {number} + * @ignore + */ + this.low_ = low | 0; // force into 32 signed bits. + + /** + * @type {number} + * @ignore + */ + this.high_ = high | 0; // force into 32 signed bits. } -Promise.promisify = function (fn, options) { - if (typeof fn !== "function") { - throw new TypeError("expecting a function but got " + util.classString(fn)); - } - if (isPromisified(fn)) { - return fn; - } - options = Object(options); - var receiver = options.context === undefined ? THIS : options.context; - var multiArgs = !!options.multiArgs; - var ret = promisify(fn, receiver, multiArgs); - util.copyDescriptors(fn, ret, propsFilter); - return ret; +/** + * Return the int value. + * + * @return {number} the value, assuming it is a 32-bit integer. + */ +Timestamp.prototype.toInt = function() { + return this.low_; }; -Promise.promisifyAll = function (target, options) { - if (typeof target !== "function" && typeof target !== "object") { - throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - options = Object(options); - var multiArgs = !!options.multiArgs; - var suffix = options.suffix; - if (typeof suffix !== "string") suffix = defaultSuffix; - var filter = options.filter; - if (typeof filter !== "function") filter = defaultFilter; - var promisifier = options.promisifier; - if (typeof promisifier !== "function") promisifier = makeNodePromisified; - - if (!util.isIdentifier(suffix)) { - throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - - var keys = util.inheritedDataKeys(target); - for (var i = 0; i < keys.length; ++i) { - var value = target[keys[i]]; - if (keys[i] !== "constructor" && - util.isClass(value)) { - promisifyAll(value.prototype, suffix, filter, promisifier, - multiArgs); - promisifyAll(value, suffix, filter, promisifier, multiArgs); - } - } - - return promisifyAll(target, suffix, filter, promisifier, multiArgs); -}; +/** + * Return the Number value. + * + * @method + * @return {number} the closest floating-point representation to this value. + */ +Timestamp.prototype.toNumber = function() { + return this.high_ * Timestamp.TWO_PWR_32_DBL_ + this.getLowBitsUnsigned(); }; +/** + * Return the JSON value. + * + * @method + * @return {string} the JSON representation. + */ +Timestamp.prototype.toJSON = function() { + return this.toString(); +}; -},{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function( - Promise, PromiseArray, tryConvertToPromise, apiRejection) { -var util = _dereq_("./util"); -var isObject = util.isObject; -var es5 = _dereq_("./es5"); -var Es6Map; -if (typeof Map === "function") Es6Map = Map; +/** + * Return the String value. + * + * @method + * @param {number} [opt_radix] the radix in which the text should be written. + * @return {string} the textual representation of this value. + */ +Timestamp.prototype.toString = function(opt_radix) { + var radix = opt_radix || 10; + if (radix < 2 || 36 < radix) { + throw Error('radix out of range: ' + radix); + } -var mapToEntries = (function() { - var index = 0; - var size = 0; + if (this.isZero()) { + return '0'; + } - function extractEntry(value, key) { - this[index] = value; - this[index + size] = key; - index++; + if (this.isNegative()) { + if (this.equals(Timestamp.MIN_VALUE)) { + // We need to change the Timestamp value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixTimestamp = Timestamp.fromNumber(radix); + var div = this.div(radixTimestamp); + var rem = div.multiply(radixTimestamp).subtract(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else { + return '-' + this.negate().toString(radix); } + } - return function mapToEntries(map) { - size = map.size; - index = 0; - var ret = new Array(map.size * 2); - map.forEach(extractEntry, ret); - return ret; - }; -})(); - -var entriesToMap = function(entries) { - var ret = new Es6Map(); - var length = entries.length / 2 | 0; - for (var i = 0; i < length; ++i) { - var key = entries[length + i]; - var value = entries[i]; - ret.set(key, value); - } - return ret; -}; + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Timestamp.fromNumber(Math.pow(radix, 6)); -function PropertiesPromiseArray(obj) { - var isMap = false; - var entries; - if (Es6Map !== undefined && obj instanceof Es6Map) { - entries = mapToEntries(obj); - isMap = true; - } else { - var keys = es5.keys(obj); - var len = keys.length; - entries = new Array(len * 2); - for (var i = 0; i < len; ++i) { - var key = keys[i]; - entries[i] = obj[key]; - entries[i + len] = key; - } - } - this.constructor$(entries); - this._isMap = isMap; - this._init$(undefined, isMap ? -6 : -3); -} -util.inherits(PropertiesPromiseArray, PromiseArray); + rem = this; + var result = ''; -PropertiesPromiseArray.prototype._init = function () {}; + while (!rem.isZero()) { + var remDiv = rem.div(radixToPower); + var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); + var digits = intval.toString(radix); -PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) { - this._values[index] = value; - var totalResolved = ++this._totalResolved; - if (totalResolved >= this._length) { - var val; - if (this._isMap) { - val = entriesToMap(this._values); - } else { - val = {}; - var keyOffset = this.length(); - for (var i = 0, len = this.length(); i < len; ++i) { - val[this._values[i + keyOffset]] = this._values[i]; - } - } - this._resolve(val); - return true; + rem = remDiv; + if (rem.isZero()) { + return digits + result; + } else { + while (digits.length < 6) { + digits = '0' + digits; + } + result = '' + digits + result; } - return false; + } }; -PropertiesPromiseArray.prototype.shouldCopyValues = function () { - return false; +/** + * Return the high 32-bits value. + * + * @method + * @return {number} the high 32-bits as a signed value. + */ +Timestamp.prototype.getHighBits = function() { + return this.high_; }; -PropertiesPromiseArray.prototype.getActualLength = function (len) { - return len >> 1; +/** + * Return the low 32-bits value. + * + * @method + * @return {number} the low 32-bits as a signed value. + */ +Timestamp.prototype.getLowBits = function() { + return this.low_; }; -function props(promises) { - var ret; - var castValue = tryConvertToPromise(promises); +/** + * Return the low unsigned 32-bits value. + * + * @method + * @return {number} the low 32-bits as an unsigned value. + */ +Timestamp.prototype.getLowBitsUnsigned = function() { + return this.low_ >= 0 ? this.low_ : Timestamp.TWO_PWR_32_DBL_ + this.low_; +}; - if (!isObject(castValue)) { - return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } else if (castValue instanceof Promise) { - ret = castValue._then( - Promise.props, undefined, undefined, undefined, undefined); +/** + * Returns the number of bits needed to represent the absolute value of this Timestamp. + * + * @method + * @return {number} Returns the number of bits needed to represent the absolute value of this Timestamp. + */ +Timestamp.prototype.getNumBitsAbs = function() { + if (this.isNegative()) { + if (this.equals(Timestamp.MIN_VALUE)) { + return 64; } else { - ret = new PropertiesPromiseArray(castValue).promise(); + return this.negate().getNumBitsAbs(); } - - if (castValue instanceof Promise) { - ret._propagateFrom(castValue, 2); + } else { + var val = this.high_ !== 0 ? this.high_ : this.low_; + for (var bit = 31; bit > 0; bit--) { + if ((val & (1 << bit)) !== 0) { + break; + } } - return ret; -} - -Promise.prototype.props = function () { - return props(this); + return this.high_ !== 0 ? bit + 33 : bit + 1; + } }; -Promise.props = function (promises) { - return props(promises); -}; +/** + * Return whether this value is zero. + * + * @method + * @return {boolean} whether this value is zero. + */ +Timestamp.prototype.isZero = function() { + return this.high_ === 0 && this.low_ === 0; }; -},{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){ -"use strict"; -function arrayMove(src, srcIndex, dst, dstIndex, len) { - for (var j = 0; j < len; ++j) { - dst[j + dstIndex] = src[j + srcIndex]; - src[j + srcIndex] = void 0; - } -} - -function Queue(capacity) { - this._capacity = capacity; - this._length = 0; - this._front = 0; -} - -Queue.prototype._willBeOverCapacity = function (size) { - return this._capacity < size; +/** + * Return whether this value is negative. + * + * @method + * @return {boolean} whether this value is negative. + */ +Timestamp.prototype.isNegative = function() { + return this.high_ < 0; }; -Queue.prototype._pushOne = function (arg) { - var length = this.length(); - this._checkCapacity(length + 1); - var i = (this._front + length) & (this._capacity - 1); - this[i] = arg; - this._length = length + 1; +/** + * Return whether this value is odd. + * + * @method + * @return {boolean} whether this value is odd. + */ +Timestamp.prototype.isOdd = function() { + return (this.low_ & 1) === 1; }; -Queue.prototype.push = function (fn, receiver, arg) { - var length = this.length() + 3; - if (this._willBeOverCapacity(length)) { - this._pushOne(fn); - this._pushOne(receiver); - this._pushOne(arg); - return; - } - var j = this._front + length - 3; - this._checkCapacity(length); - var wrapMask = this._capacity - 1; - this[(j + 0) & wrapMask] = fn; - this[(j + 1) & wrapMask] = receiver; - this[(j + 2) & wrapMask] = arg; - this._length = length; +/** + * Return whether this Timestamp equals the other + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp equals the other + */ +Timestamp.prototype.equals = function(other) { + return this.high_ === other.high_ && this.low_ === other.low_; }; -Queue.prototype.shift = function () { - var front = this._front, - ret = this[front]; +/** + * Return whether this Timestamp does not equal the other. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp does not equal the other. + */ +Timestamp.prototype.notEquals = function(other) { + return this.high_ !== other.high_ || this.low_ !== other.low_; +}; - this[front] = undefined; - this._front = (front + 1) & (this._capacity - 1); - this._length--; - return ret; +/** + * Return whether this Timestamp is less than the other. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp is less than the other. + */ +Timestamp.prototype.lessThan = function(other) { + return this.compare(other) < 0; }; -Queue.prototype.length = function () { - return this._length; +/** + * Return whether this Timestamp is less than or equal to the other. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp is less than or equal to the other. + */ +Timestamp.prototype.lessThanOrEqual = function(other) { + return this.compare(other) <= 0; }; -Queue.prototype._checkCapacity = function (size) { - if (this._capacity < size) { - this._resizeTo(this._capacity << 1); - } +/** + * Return whether this Timestamp is greater than the other. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp is greater than the other. + */ +Timestamp.prototype.greaterThan = function(other) { + return this.compare(other) > 0; }; -Queue.prototype._resizeTo = function (capacity) { - var oldCapacity = this._capacity; - this._capacity = capacity; - var front = this._front; - var length = this._length; - var moveItemsCount = (front + length) & (oldCapacity - 1); - arrayMove(this, 0, this, oldCapacity, moveItemsCount); +/** + * Return whether this Timestamp is greater than or equal to the other. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} whether this Timestamp is greater than or equal to the other. + */ +Timestamp.prototype.greaterThanOrEqual = function(other) { + return this.compare(other) >= 0; }; -module.exports = Queue; +/** + * Compares this Timestamp with the given one. + * + * @method + * @param {Timestamp} other Timestamp to compare against. + * @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater. + */ +Timestamp.prototype.compare = function(other) { + if (this.equals(other)) { + return 0; + } -},{}],27:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function( - Promise, INTERNAL, tryConvertToPromise, apiRejection) { -var util = _dereq_("./util"); + var thisNeg = this.isNegative(); + var otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) { + return -1; + } + if (!thisNeg && otherNeg) { + return 1; + } -var raceLater = function (promise) { - return promise.then(function(array) { - return race(array, promise); - }); + // at this point, the signs are the same, so subtraction will not overflow + if (this.subtract(other).isNegative()) { + return -1; + } else { + return 1; + } }; -function race(promises, parent) { - var maybePromise = tryConvertToPromise(promises); - - if (maybePromise instanceof Promise) { - return raceLater(maybePromise); - } else { - promises = util.asArray(promises); - if (promises === null) - return apiRejection("expecting an array or an iterable object but got " + util.classString(promises)); - } +/** + * The negation of this value. + * + * @method + * @return {Timestamp} the negation of this value. + */ +Timestamp.prototype.negate = function() { + if (this.equals(Timestamp.MIN_VALUE)) { + return Timestamp.MIN_VALUE; + } else { + return this.not().add(Timestamp.ONE); + } +}; - var ret = new Promise(INTERNAL); - if (parent !== undefined) { - ret._propagateFrom(parent, 3); - } - var fulfill = ret._fulfill; - var reject = ret._reject; - for (var i = 0, len = promises.length; i < len; ++i) { - var val = promises[i]; +/** + * Returns the sum of this and the given Timestamp. + * + * @method + * @param {Timestamp} other Timestamp to add to this one. + * @return {Timestamp} the sum of this and the given Timestamp. + */ +Timestamp.prototype.add = function(other) { + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - if (val === undefined && !(i in promises)) { - continue; - } + var a48 = this.high_ >>> 16; + var a32 = this.high_ & 0xffff; + var a16 = this.low_ >>> 16; + var a00 = this.low_ & 0xffff; - Promise.cast(val)._then(fulfill, reject, undefined, ret, null); - } - return ret; -} + var b48 = other.high_ >>> 16; + var b32 = other.high_ & 0xffff; + var b16 = other.low_ >>> 16; + var b00 = other.low_ & 0xffff; -Promise.race = function (promises) { - return race(promises, undefined); + var c48 = 0, + c32 = 0, + c16 = 0, + c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xffff; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xffff; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xffff; + c48 += a48 + b48; + c48 &= 0xffff; + return Timestamp.fromBits((c16 << 16) | c00, (c48 << 16) | c32); }; -Promise.prototype.race = function () { - return race(this, undefined); +/** + * Returns the difference of this and the given Timestamp. + * + * @method + * @param {Timestamp} other Timestamp to subtract from this. + * @return {Timestamp} the difference of this and the given Timestamp. + */ +Timestamp.prototype.subtract = function(other) { + return this.add(other.negate()); }; -}; +/** + * Returns the product of this and the given Timestamp. + * + * @method + * @param {Timestamp} other Timestamp to multiply with this. + * @return {Timestamp} the product of this and the other. + */ +Timestamp.prototype.multiply = function(other) { + if (this.isZero()) { + return Timestamp.ZERO; + } else if (other.isZero()) { + return Timestamp.ZERO; + } -},{"./util":36}],28:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, - PromiseArray, - apiRejection, - tryConvertToPromise, - INTERNAL, - debug) { -var getDomain = Promise._getDomain; -var util = _dereq_("./util"); -var tryCatch = util.tryCatch; + if (this.equals(Timestamp.MIN_VALUE)) { + return other.isOdd() ? Timestamp.MIN_VALUE : Timestamp.ZERO; + } else if (other.equals(Timestamp.MIN_VALUE)) { + return this.isOdd() ? Timestamp.MIN_VALUE : Timestamp.ZERO; + } -function ReductionPromiseArray(promises, fn, initialValue, _each) { - this.constructor$(promises); - var domain = getDomain(); - this._fn = domain === null ? fn : util.domainBind(domain, fn); - if (initialValue !== undefined) { - initialValue = Promise.resolve(initialValue); - initialValue._attachCancellationCallback(this); - } - this._initialValue = initialValue; - this._currentCancellable = null; - if(_each === INTERNAL) { - this._eachValues = Array(this._length); - } else if (_each === 0) { - this._eachValues = null; + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().multiply(other.negate()); } else { - this._eachValues = undefined; + return this.negate() + .multiply(other) + .negate(); } - this._promise._captureStackTrace(); - this._init$(undefined, -5); -} -util.inherits(ReductionPromiseArray, PromiseArray); + } else if (other.isNegative()) { + return this.multiply(other.negate()).negate(); + } -ReductionPromiseArray.prototype._gotAccum = function(accum) { - if (this._eachValues !== undefined && - this._eachValues !== null && - accum !== INTERNAL) { - this._eachValues.push(accum); - } -}; + // If both Timestamps are small, use float multiplication + if (this.lessThan(Timestamp.TWO_PWR_24_) && other.lessThan(Timestamp.TWO_PWR_24_)) { + return Timestamp.fromNumber(this.toNumber() * other.toNumber()); + } -ReductionPromiseArray.prototype._eachComplete = function(value) { - if (this._eachValues !== null) { - this._eachValues.push(value); - } - return this._eachValues; -}; + // Divide each Timestamp into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. -ReductionPromiseArray.prototype._init = function() {}; + var a48 = this.high_ >>> 16; + var a32 = this.high_ & 0xffff; + var a16 = this.low_ >>> 16; + var a00 = this.low_ & 0xffff; -ReductionPromiseArray.prototype._resolveEmptyArray = function() { - this._resolve(this._eachValues !== undefined ? this._eachValues - : this._initialValue); -}; + var b48 = other.high_ >>> 16; + var b32 = other.high_ & 0xffff; + var b16 = other.low_ >>> 16; + var b00 = other.low_ & 0xffff; -ReductionPromiseArray.prototype.shouldCopyValues = function () { - return false; + var c48 = 0, + c32 = 0, + c16 = 0, + c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xffff; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xffff; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xffff; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xffff; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xffff; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xffff; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xffff; + return Timestamp.fromBits((c16 << 16) | c00, (c48 << 16) | c32); }; -ReductionPromiseArray.prototype._resolve = function(value) { - this._promise._resolveCallback(value); - this._values = null; -}; +/** + * Returns this Timestamp divided by the given one. + * + * @method + * @param {Timestamp} other Timestamp by which to divide. + * @return {Timestamp} this Timestamp divided by the given one. + */ +Timestamp.prototype.div = function(other) { + if (other.isZero()) { + throw Error('division by zero'); + } else if (this.isZero()) { + return Timestamp.ZERO; + } -ReductionPromiseArray.prototype._resultCancelled = function(sender) { - if (sender === this._initialValue) return this._cancel(); - if (this._isResolved()) return; - this._resultCancelled$(); - if (this._currentCancellable instanceof Promise) { - this._currentCancellable.cancel(); - } - if (this._initialValue instanceof Promise) { - this._initialValue.cancel(); + if (this.equals(Timestamp.MIN_VALUE)) { + if (other.equals(Timestamp.ONE) || other.equals(Timestamp.NEG_ONE)) { + return Timestamp.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + } else if (other.equals(Timestamp.MIN_VALUE)) { + return Timestamp.ONE; + } else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shiftRight(1); + var approx = halfThis.div(other).shiftLeft(1); + if (approx.equals(Timestamp.ZERO)) { + return other.isNegative() ? Timestamp.ONE : Timestamp.NEG_ONE; + } else { + var rem = this.subtract(other.multiply(approx)); + var result = approx.add(rem.div(other)); + return result; + } } -}; + } else if (other.equals(Timestamp.MIN_VALUE)) { + return Timestamp.ZERO; + } -ReductionPromiseArray.prototype._iterate = function (values) { - this._values = values; - var value; - var i; - var length = values.length; - if (this._initialValue !== undefined) { - value = this._initialValue; - i = 0; + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().div(other.negate()); } else { - value = Promise.resolve(values[0]); - i = 1; + return this.negate() + .div(other) + .negate(); } + } else if (other.isNegative()) { + return this.div(other.negate()).negate(); + } - this._currentCancellable = value; + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + var res = Timestamp.ZERO; + rem = this; + while (rem.greaterThanOrEqual(other)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); - if (!value.isRejected()) { - for (; i < length; ++i) { - var ctx = { - accum: null, - value: values[i], - index: i, - length: length, - array: this - }; - value = value._then(gotAccum, undefined, undefined, ctx, undefined); - } + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2); + var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + var approxRes = Timestamp.fromNumber(approx); + var approxRem = approxRes.multiply(other); + while (approxRem.isNegative() || approxRem.greaterThan(rem)) { + approx -= delta; + approxRes = Timestamp.fromNumber(approx); + approxRem = approxRes.multiply(other); } - if (this._eachValues !== undefined) { - value = value - ._then(this._eachComplete, undefined, undefined, this, undefined); + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) { + approxRes = Timestamp.ONE; } - value._then(completed, completed, undefined, value, this); + + res = res.add(approxRes); + rem = rem.subtract(approxRem); + } + return res; }; -Promise.prototype.reduce = function (fn, initialValue) { - return reduce(this, fn, initialValue, null); +/** + * Returns this Timestamp modulo the given one. + * + * @method + * @param {Timestamp} other Timestamp by which to mod. + * @return {Timestamp} this Timestamp modulo the given one. + */ +Timestamp.prototype.modulo = function(other) { + return this.subtract(this.div(other).multiply(other)); }; -Promise.reduce = function (promises, fn, initialValue, _each) { - return reduce(promises, fn, initialValue, _each); +/** + * The bitwise-NOT of this value. + * + * @method + * @return {Timestamp} the bitwise-NOT of this value. + */ +Timestamp.prototype.not = function() { + return Timestamp.fromBits(~this.low_, ~this.high_); }; -function completed(valueOrReason, array) { - if (this.isFulfilled()) { - array._resolve(valueOrReason); - } else { - array._reject(valueOrReason); - } -} +/** + * Returns the bitwise-AND of this Timestamp and the given one. + * + * @method + * @param {Timestamp} other the Timestamp with which to AND. + * @return {Timestamp} the bitwise-AND of this and the other. + */ +Timestamp.prototype.and = function(other) { + return Timestamp.fromBits(this.low_ & other.low_, this.high_ & other.high_); +}; -function reduce(promises, fn, initialValue, _each) { - if (typeof fn !== "function") { - return apiRejection("expecting a function but got " + util.classString(fn)); - } - var array = new ReductionPromiseArray(promises, fn, initialValue, _each); - return array.promise(); -} +/** + * Returns the bitwise-OR of this Timestamp and the given one. + * + * @method + * @param {Timestamp} other the Timestamp with which to OR. + * @return {Timestamp} the bitwise-OR of this and the other. + */ +Timestamp.prototype.or = function(other) { + return Timestamp.fromBits(this.low_ | other.low_, this.high_ | other.high_); +}; -function gotAccum(accum) { - this.accum = accum; - this.array._gotAccum(accum); - var value = tryConvertToPromise(this.value, this.array._promise); - if (value instanceof Promise) { - this.array._currentCancellable = value; - return value._then(gotValue, undefined, undefined, this, undefined); +/** + * Returns the bitwise-XOR of this Timestamp and the given one. + * + * @method + * @param {Timestamp} other the Timestamp with which to XOR. + * @return {Timestamp} the bitwise-XOR of this and the other. + */ +Timestamp.prototype.xor = function(other) { + return Timestamp.fromBits(this.low_ ^ other.low_, this.high_ ^ other.high_); +}; + +/** + * Returns this Timestamp with bits shifted to the left by the given amount. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Timestamp} this shifted to the left by the given amount. + */ +Timestamp.prototype.shiftLeft = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var low = this.low_; + if (numBits < 32) { + var high = this.high_; + return Timestamp.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits))); } else { - return gotValue.call(this, value); + return Timestamp.fromBits(0, low << (numBits - 32)); } -} + } +}; -function gotValue(value) { - var array = this.array; - var promise = array._promise; - var fn = tryCatch(array._fn); - promise._pushContext(); - var ret; - if (array._eachValues !== undefined) { - ret = fn.call(promise._boundValue(), value, this.index, this.length); +/** + * Returns this Timestamp with bits shifted to the right by the given amount. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Timestamp} this shifted to the right by the given amount. + */ +Timestamp.prototype.shiftRight = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var high = this.high_; + if (numBits < 32) { + var low = this.low_; + return Timestamp.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits); } else { - ret = fn.call(promise._boundValue(), - this.accum, value, this.index, this.length); - } - if (ret instanceof Promise) { - array._currentCancellable = ret; + return Timestamp.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1); } - var promiseCreated = promise._popContext(); - debug.checkForgottenReturns( - ret, - promiseCreated, - array._eachValues !== undefined ? "Promise.each" : "Promise.reduce", - promise - ); - return ret; -} + } }; -},{"./util":36}],29:[function(_dereq_,module,exports){ -"use strict"; -var util = _dereq_("./util"); -var schedule; -var noAsyncScheduler = function() { - throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); +/** + * Returns this Timestamp with bits shifted to the right by the given amount, with the new top bits matching the current sign bit. + * + * @method + * @param {number} numBits the number of bits by which to shift. + * @return {Timestamp} this shifted to the right by the given amount, with zeros placed into the new leading bits. + */ +Timestamp.prototype.shiftRightUnsigned = function(numBits) { + numBits &= 63; + if (numBits === 0) { + return this; + } else { + var high = this.high_; + if (numBits < 32) { + var low = this.low_; + return Timestamp.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits); + } else if (numBits === 32) { + return Timestamp.fromBits(high, 0); + } else { + return Timestamp.fromBits(high >>> (numBits - 32), 0); + } + } }; -var NativePromise = util.getNativePromise(); -if (util.isNode && typeof MutationObserver === "undefined") { - var GlobalSetImmediate = global.setImmediate; - var ProcessNextTick = process.nextTick; - schedule = util.isRecentNode - ? function(fn) { GlobalSetImmediate.call(global, fn); } - : function(fn) { ProcessNextTick.call(process, fn); }; -} else if (typeof NativePromise === "function" && - typeof NativePromise.resolve === "function") { - var nativePromise = NativePromise.resolve(); - schedule = function(fn) { - nativePromise.then(fn); - }; -} else if ((typeof MutationObserver !== "undefined") && - !(typeof window !== "undefined" && - window.navigator && - (window.navigator.standalone || window.cordova))) { - schedule = (function() { - var div = document.createElement("div"); - var opts = {attributes: true}; - var toggleScheduled = false; - var div2 = document.createElement("div"); - var o2 = new MutationObserver(function() { - div.classList.toggle("foo"); - toggleScheduled = false; - }); - o2.observe(div2, opts); - - var scheduleToggle = function() { - if (toggleScheduled) return; - toggleScheduled = true; - div2.classList.toggle("foo"); - }; - - return function schedule(fn) { - var o = new MutationObserver(function() { - o.disconnect(); - fn(); - }); - o.observe(div, opts); - scheduleToggle(); - }; - })(); -} else if (typeof setImmediate !== "undefined") { - schedule = function (fn) { - setImmediate(fn); - }; -} else if (typeof setTimeout !== "undefined") { - schedule = function (fn) { - setTimeout(fn, 0); - }; -} else { - schedule = noAsyncScheduler; -} -module.exports = schedule; - -},{"./util":36}],30:[function(_dereq_,module,exports){ -"use strict"; -module.exports = - function(Promise, PromiseArray, debug) { -var PromiseInspection = Promise.PromiseInspection; -var util = _dereq_("./util"); - -function SettledPromiseArray(values) { - this.constructor$(values); -} -util.inherits(SettledPromiseArray, PromiseArray); -SettledPromiseArray.prototype._promiseResolved = function (index, inspection) { - this._values[index] = inspection; - var totalResolved = ++this._totalResolved; - if (totalResolved >= this._length) { - this._resolve(this._values); - return true; +/** + * Returns a Timestamp representing the given (32-bit) integer value. + * + * @method + * @param {number} value the 32-bit integer in question. + * @return {Timestamp} the corresponding Timestamp value. + */ +Timestamp.fromInt = function(value) { + if (-128 <= value && value < 128) { + var cachedObj = Timestamp.INT_CACHE_[value]; + if (cachedObj) { + return cachedObj; } - return false; -}; + } -SettledPromiseArray.prototype._promiseFulfilled = function (value, index) { - var ret = new PromiseInspection(); - ret._bitField = 33554432; - ret._settledValueField = value; - return this._promiseResolved(index, ret); -}; -SettledPromiseArray.prototype._promiseRejected = function (reason, index) { - var ret = new PromiseInspection(); - ret._bitField = 16777216; - ret._settledValueField = reason; - return this._promiseResolved(index, ret); + var obj = new Timestamp(value | 0, value < 0 ? -1 : 0); + if (-128 <= value && value < 128) { + Timestamp.INT_CACHE_[value] = obj; + } + return obj; }; -Promise.settle = function (promises) { - debug.deprecated(".settle()", ".reflect()"); - return new SettledPromiseArray(promises).promise(); +/** + * Returns a Timestamp representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * + * @method + * @param {number} value the number in question. + * @return {Timestamp} the corresponding Timestamp value. + */ +Timestamp.fromNumber = function(value) { + if (isNaN(value) || !isFinite(value)) { + return Timestamp.ZERO; + } else if (value <= -Timestamp.TWO_PWR_63_DBL_) { + return Timestamp.MIN_VALUE; + } else if (value + 1 >= Timestamp.TWO_PWR_63_DBL_) { + return Timestamp.MAX_VALUE; + } else if (value < 0) { + return Timestamp.fromNumber(-value).negate(); + } else { + return new Timestamp( + (value % Timestamp.TWO_PWR_32_DBL_) | 0, + (value / Timestamp.TWO_PWR_32_DBL_) | 0 + ); + } }; -Promise.prototype.settle = function () { - return Promise.settle(this); -}; +/** + * Returns a Timestamp representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits. + * + * @method + * @param {number} lowBits the low 32-bits. + * @param {number} highBits the high 32-bits. + * @return {Timestamp} the corresponding Timestamp value. + */ +Timestamp.fromBits = function(lowBits, highBits) { + return new Timestamp(lowBits, highBits); }; -},{"./util":36}],31:[function(_dereq_,module,exports){ -"use strict"; -module.exports = -function(Promise, PromiseArray, apiRejection) { -var util = _dereq_("./util"); -var RangeError = _dereq_("./errors").RangeError; -var AggregateError = _dereq_("./errors").AggregateError; -var isArray = util.isArray; -var CANCELLATION = {}; +/** + * Returns a Timestamp representation of the given string, written using the given radix. + * + * @method + * @param {string} str the textual representation of the Timestamp. + * @param {number} opt_radix the radix in which the text is written. + * @return {Timestamp} the corresponding Timestamp value. + */ +Timestamp.fromString = function(str, opt_radix) { + if (str.length === 0) { + throw Error('number format error: empty string'); + } + var radix = opt_radix || 10; + if (radix < 2 || 36 < radix) { + throw Error('radix out of range: ' + radix); + } -function SomePromiseArray(values) { - this.constructor$(values); - this._howMany = 0; - this._unwrap = false; - this._initialized = false; -} -util.inherits(SomePromiseArray, PromiseArray); + if (str.charAt(0) === '-') { + return Timestamp.fromString(str.substring(1), radix).negate(); + } else if (str.indexOf('-') >= 0) { + throw Error('number format error: interior "-" character: ' + str); + } -SomePromiseArray.prototype._init = function () { - if (!this._initialized) { - return; - } - if (this._howMany === 0) { - this._resolve([]); - return; - } - this._init$(undefined, -5); - var isArrayResolved = isArray(this._values); - if (!this._isResolved() && - isArrayResolved && - this._howMany > this._canPossiblyFulfill()) { - this._reject(this._getRangeError(this.length())); + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Timestamp.fromNumber(Math.pow(radix, 8)); + + var result = Timestamp.ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i); + var value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = Timestamp.fromNumber(Math.pow(radix, size)); + result = result.multiply(power).add(Timestamp.fromNumber(value)); + } else { + result = result.multiply(radixToPower); + result = result.add(Timestamp.fromNumber(value)); } + } + return result; }; -SomePromiseArray.prototype.init = function () { - this._initialized = true; - this._init(); -}; +// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the +// from* methods on which they depend. -SomePromiseArray.prototype.setUnwrap = function () { - this._unwrap = true; -}; +/** + * A cache of the Timestamp representations of small integer values. + * @type {Object} + * @ignore + */ +Timestamp.INT_CACHE_ = {}; -SomePromiseArray.prototype.howMany = function () { - return this._howMany; -}; +// NOTE: the compiler should inline these constant values below and then remove +// these variables, so there should be no runtime penalty for these. -SomePromiseArray.prototype.setHowMany = function (count) { - this._howMany = count; -}; +/** + * Number used repeated below in calculations. This must appear before the + * first call to any from* function below. + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_16_DBL_ = 1 << 16; -SomePromiseArray.prototype._promiseFulfilled = function (value) { - this._addFulfilled(value); - if (this._fulfilled() === this.howMany()) { - this._values.length = this.howMany(); - if (this.howMany() === 1 && this._unwrap) { - this._resolve(this._values[0]); - } else { - this._resolve(this._values); - } - return true; - } - return false; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_24_DBL_ = 1 << 24; -}; -SomePromiseArray.prototype._promiseRejected = function (reason) { - this._addRejected(reason); - return this._checkOutcome(); -}; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_32_DBL_ = Timestamp.TWO_PWR_16_DBL_ * Timestamp.TWO_PWR_16_DBL_; -SomePromiseArray.prototype._promiseCancelled = function () { - if (this._values instanceof Promise || this._values == null) { - return this._cancel(); - } - this._addRejected(CANCELLATION); - return this._checkOutcome(); -}; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_31_DBL_ = Timestamp.TWO_PWR_32_DBL_ / 2; -SomePromiseArray.prototype._checkOutcome = function() { - if (this.howMany() > this._canPossiblyFulfill()) { - var e = new AggregateError(); - for (var i = this.length(); i < this._values.length; ++i) { - if (this._values[i] !== CANCELLATION) { - e.push(this._values[i]); - } - } - if (e.length > 0) { - this._reject(e); - } else { - this._cancel(); - } - return true; - } - return false; -}; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_48_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_16_DBL_; -SomePromiseArray.prototype._fulfilled = function () { - return this._totalResolved; -}; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_64_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_32_DBL_; -SomePromiseArray.prototype._rejected = function () { - return this._values.length - this.length(); -}; +/** + * @type {number} + * @ignore + */ +Timestamp.TWO_PWR_63_DBL_ = Timestamp.TWO_PWR_64_DBL_ / 2; -SomePromiseArray.prototype._addRejected = function (reason) { - this._values.push(reason); -}; - -SomePromiseArray.prototype._addFulfilled = function (value) { - this._values[this._totalResolved++] = value; -}; +/** @type {Timestamp} */ +Timestamp.ZERO = Timestamp.fromInt(0); -SomePromiseArray.prototype._canPossiblyFulfill = function () { - return this.length() - this._rejected(); -}; +/** @type {Timestamp} */ +Timestamp.ONE = Timestamp.fromInt(1); -SomePromiseArray.prototype._getRangeError = function (count) { - var message = "Input array must contain at least " + - this._howMany + " items but contains only " + count + " items"; - return new RangeError(message); -}; +/** @type {Timestamp} */ +Timestamp.NEG_ONE = Timestamp.fromInt(-1); -SomePromiseArray.prototype._resolveEmptyArray = function () { - this._reject(this._getRangeError(0)); -}; +/** @type {Timestamp} */ +Timestamp.MAX_VALUE = Timestamp.fromBits(0xffffffff | 0, 0x7fffffff | 0); -function some(promises, howMany) { - if ((howMany | 0) !== howMany || howMany < 0) { - return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - var ret = new SomePromiseArray(promises); - var promise = ret.promise(); - ret.setHowMany(howMany); - ret.init(); - return promise; -} +/** @type {Timestamp} */ +Timestamp.MIN_VALUE = Timestamp.fromBits(0, 0x80000000 | 0); -Promise.some = function (promises, howMany) { - return some(promises, howMany); -}; +/** + * @type {Timestamp} + * @ignore + */ +Timestamp.TWO_PWR_24_ = Timestamp.fromInt(1 << 24); -Promise.prototype.some = function (howMany) { - return some(this, howMany); -}; +/** + * Expose. + */ +module.exports = Timestamp; +module.exports.Timestamp = Timestamp; -Promise._SomePromiseArray = SomePromiseArray; -}; +},{}],35:[function(require,module,exports){ +(function (Buffer){(function (){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ -},{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise) { -function PromiseInspection(promise) { - if (promise !== undefined) { - promise = promise._target(); - this._bitField = promise._bitField; - this._settledValueField = promise._isFateSealed() - ? promise._settledValue() : undefined; - } - else { - this._bitField = 0; - this._settledValueField = undefined; - } -} +'use strict' -PromiseInspection.prototype._settledValue = function() { - return this._settledValueField; -}; +var base64 = require('base64-js') +var ieee754 = require('ieee754') -var value = PromiseInspection.prototype.value = function () { - if (!this.isFulfilled()) { - throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - return this._settledValue(); -}; +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 -var reason = PromiseInspection.prototype.error = -PromiseInspection.prototype.reason = function () { - if (!this.isRejected()) { - throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); - } - return this._settledValue(); -}; +var K_MAX_LENGTH = 0x7fffffff +exports.kMaxLength = K_MAX_LENGTH -var isFulfilled = PromiseInspection.prototype.isFulfilled = function() { - return (this._bitField & 33554432) !== 0; -}; +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. + */ +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() -var isRejected = PromiseInspection.prototype.isRejected = function () { - return (this._bitField & 16777216) !== 0; -}; +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && + typeof console.error === 'function') { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ) +} -var isPending = PromiseInspection.prototype.isPending = function () { - return (this._bitField & 50397184) === 0; -}; +function typedArraySupport () { + // Can typed array instances can be augmented? + try { + var arr = new Uint8Array(1) + arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } + return arr.foo() === 42 + } catch (e) { + return false + } +} -var isResolved = PromiseInspection.prototype.isResolved = function () { - return (this._bitField & 50331648) !== 0; -}; +Object.defineProperty(Buffer.prototype, 'parent', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.buffer + } +}) -PromiseInspection.prototype.isCancelled = function() { - return (this._bitField & 8454144) !== 0; -}; +Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.byteOffset + } +}) -Promise.prototype.__isCancelled = function() { - return (this._bitField & 65536) === 65536; -}; +function createBuffer (length) { + if (length > K_MAX_LENGTH) { + throw new RangeError('The value "' + length + '" is invalid for option "size"') + } + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length) + buf.__proto__ = Buffer.prototype + return buf +} -Promise.prototype._isCancelled = function() { - return this._target().__isCancelled(); -}; +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ -Promise.prototype.isCancelled = function() { - return (this._target()._bitField & 8454144) !== 0; -}; +function Buffer (arg, encodingOrOffset, length) { + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new TypeError( + 'The "string" argument must be of type string. Received type number' + ) + } + return allocUnsafe(arg) + } + return from(arg, encodingOrOffset, length) +} -Promise.prototype.isPending = function() { - return isPending.call(this._target()); -}; +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species != null && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) +} -Promise.prototype.isRejected = function() { - return isRejected.call(this._target()); -}; +Buffer.poolSize = 8192 // not used by this implementation -Promise.prototype.isFulfilled = function() { - return isFulfilled.call(this._target()); -}; +function from (value, encodingOrOffset, length) { + if (typeof value === 'string') { + return fromString(value, encodingOrOffset) + } -Promise.prototype.isResolved = function() { - return isResolved.call(this._target()); -}; + if (ArrayBuffer.isView(value)) { + return fromArrayLike(value) + } -Promise.prototype.value = function() { - return value.call(this._target()); -}; + if (value == null) { + throw TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) + } -Promise.prototype.reason = function() { - var target = this._target(); - target._unsetRejectionIsUnhandled(); - return reason.call(target); -}; + if (isInstance(value, ArrayBuffer) || + (value && isInstance(value.buffer, ArrayBuffer))) { + return fromArrayBuffer(value, encodingOrOffset, length) + } -Promise.prototype._value = function() { - return this._settledValue(); -}; + if (typeof value === 'number') { + throw new TypeError( + 'The "value" argument must not be of type number. Received type number' + ) + } -Promise.prototype._reason = function() { - this._unsetRejectionIsUnhandled(); - return this._settledValue(); -}; + var valueOf = value.valueOf && value.valueOf() + if (valueOf != null && valueOf !== value) { + return Buffer.from(valueOf, encodingOrOffset, length) + } -Promise.PromiseInspection = PromiseInspection; -}; + var b = fromObject(value) + if (b) return b -},{}],33:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL) { -var util = _dereq_("./util"); -var errorObj = util.errorObj; -var isObject = util.isObject; + if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && + typeof value[Symbol.toPrimitive] === 'function') { + return Buffer.from( + value[Symbol.toPrimitive]('string'), encodingOrOffset, length + ) + } -function tryConvertToPromise(obj, context) { - if (isObject(obj)) { - if (obj instanceof Promise) return obj; - var then = getThen(obj); - if (then === errorObj) { - if (context) context._pushContext(); - var ret = Promise.reject(then.e); - if (context) context._popContext(); - return ret; - } else if (typeof then === "function") { - if (isAnyBluebirdPromise(obj)) { - var ret = new Promise(INTERNAL); - obj._then( - ret._fulfill, - ret._reject, - undefined, - ret, - null - ); - return ret; - } - return doThenable(obj, then, context); - } - } - return obj; + throw new TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) } -function doGetThen(obj) { - return obj.then; +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ +Buffer.from = function (value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length) } -function getThen(obj) { - try { - return doGetThen(obj); - } catch (e) { - errorObj.e = e; - return errorObj; - } -} +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array -var hasProp = {}.hasOwnProperty; -function isAnyBluebirdPromise(obj) { - try { - return hasProp.call(obj, "_promise0"); - } catch (e) { - return false; - } +function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be of type number') + } else if (size < 0) { + throw new RangeError('The value "' + size + '" is invalid for option "size"') + } } -function doThenable(x, then, context) { - var promise = new Promise(INTERNAL); - var ret = promise; - if (context) context._pushContext(); - promise._captureStackTrace(); - if (context) context._popContext(); - var synchronous = true; - var result = util.tryCatch(then).call(x, resolve, reject); - synchronous = false; - - if (promise && result === errorObj) { - promise._rejectCallback(result.e, true, true); - promise = null; - } - - function resolve(value) { - if (!promise) return; - promise._resolveCallback(value); - promise = null; - } - - function reject(reason) { - if (!promise) return; - promise._rejectCallback(reason, synchronous, true); - promise = null; - } - return ret; +function alloc (size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(size) + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill) + } + return createBuffer(size) } -return tryConvertToPromise; -}; +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ +Buffer.alloc = function (size, fill, encoding) { + return alloc(size, fill, encoding) +} -},{"./util":36}],34:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function(Promise, INTERNAL, debug) { -var util = _dereq_("./util"); -var TimeoutError = Promise.TimeoutError; +function allocUnsafe (size) { + assertSize(size) + return createBuffer(size < 0 ? 0 : checked(size) | 0) +} -function HandleWrapper(handle) { - this.handle = handle; +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ +Buffer.allocUnsafe = function (size) { + return allocUnsafe(size) +} +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ +Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(size) } -HandleWrapper.prototype._resultCancelled = function() { - clearTimeout(this.handle); -}; +function fromString (string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' + } -var afterValue = function(value) { return delay(+this).thenReturn(value); }; -var delay = Promise.delay = function (ms, value) { - var ret; - var handle; - if (value !== undefined) { - ret = Promise.resolve(value) - ._then(afterValue, null, null, ms, undefined); - if (debug.cancellation() && value instanceof Promise) { - ret._setOnCancel(value); - } - } else { - ret = new Promise(INTERNAL); - handle = setTimeout(function() { ret._fulfill(); }, +ms); - if (debug.cancellation()) { - ret._setOnCancel(new HandleWrapper(handle)); - } - ret._captureStackTrace(); - } - ret._setAsyncGuaranteed(); - return ret; -}; + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } -Promise.prototype.delay = function (ms) { - return delay(ms, this); -}; + var length = byteLength(string, encoding) | 0 + var buf = createBuffer(length) -var afterTimeout = function (promise, message, parent) { - var err; - if (typeof message !== "string") { - if (message instanceof Error) { - err = message; - } else { - err = new TimeoutError("operation timed out"); - } - } else { - err = new TimeoutError(message); - } - util.markAsOriginatingFromRejection(err); - promise._attachExtraTrace(err); - promise._reject(err); + var actual = buf.write(string, encoding) - if (parent != null) { - parent.cancel(); - } -}; + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual) + } -function successClear(value) { - clearTimeout(this.handle); - return value; + return buf } -function failureClear(reason) { - clearTimeout(this.handle); - throw reason; +function fromArrayLike (array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + var buf = createBuffer(length) + for (var i = 0; i < length; i += 1) { + buf[i] = array[i] & 255 + } + return buf } -Promise.prototype.timeout = function (ms, message) { - ms = +ms; - var ret, parent; +function fromArrayBuffer (array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('"offset" is outside of buffer bounds') + } - var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() { - if (ret.isPending()) { - afterTimeout(ret, message, parent); - } - }, ms)); + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('"length" is outside of buffer bounds') + } - if (debug.cancellation()) { - parent = this.then(); - ret = parent._then(successClear, failureClear, - undefined, handleWrapper, undefined); - ret._setOnCancel(handleWrapper); - } else { - ret = this._then(successClear, failureClear, - undefined, handleWrapper, undefined); - } - - return ret; -}; + var buf + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array) + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset) + } else { + buf = new Uint8Array(array, byteOffset, length) + } -}; + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype + return buf +} -},{"./util":36}],35:[function(_dereq_,module,exports){ -"use strict"; -module.exports = function (Promise, apiRejection, tryConvertToPromise, - createContext, INTERNAL, debug) { - var util = _dereq_("./util"); - var TypeError = _dereq_("./errors").TypeError; - var inherits = _dereq_("./util").inherits; - var errorObj = util.errorObj; - var tryCatch = util.tryCatch; - var NULL = {}; +function fromObject (obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + var buf = createBuffer(len) - function thrower(e) { - setTimeout(function(){throw e;}, 0); + if (buf.length === 0) { + return buf } - function castPreservingDisposable(thenable) { - var maybePromise = tryConvertToPromise(thenable); - if (maybePromise !== thenable && - typeof thenable._isDisposable === "function" && - typeof thenable._getDisposer === "function" && - thenable._isDisposable()) { - maybePromise._setDisposable(thenable._getDisposer()); - } - return maybePromise; - } - function dispose(resources, inspection) { - var i = 0; - var len = resources.length; - var ret = new Promise(INTERNAL); - function iterator() { - if (i >= len) return ret._fulfill(); - var maybePromise = castPreservingDisposable(resources[i++]); - if (maybePromise instanceof Promise && - maybePromise._isDisposable()) { - try { - maybePromise = tryConvertToPromise( - maybePromise._getDisposer().tryDispose(inspection), - resources.promise); - } catch (e) { - return thrower(e); - } - if (maybePromise instanceof Promise) { - return maybePromise._then(iterator, thrower, - null, null, null); - } - } - iterator(); - } - iterator(); - return ret; - } + obj.copy(buf, 0, 0, len) + return buf + } - function Disposer(data, promise, context) { - this._data = data; - this._promise = promise; - this._context = context; + if (obj.length !== undefined) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { + return createBuffer(0) } + return fromArrayLike(obj) + } - Disposer.prototype.data = function () { - return this._data; - }; - - Disposer.prototype.promise = function () { - return this._promise; - }; + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data) + } +} - Disposer.prototype.resource = function () { - if (this.promise().isFulfilled()) { - return this.promise().value(); - } - return NULL; - }; +function checked (length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') + } + return length | 0 +} - Disposer.prototype.tryDispose = function(inspection) { - var resource = this.resource(); - var context = this._context; - if (context !== undefined) context._pushContext(); - var ret = resource !== NULL - ? this.doDispose(resource, inspection) : null; - if (context !== undefined) context._popContext(); - this._promise._unsetDisposable(); - this._data = null; - return ret; - }; +function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) +} - Disposer.isDisposer = function (d) { - return (d != null && - typeof d.resource === "function" && - typeof d.tryDispose === "function"); - }; +Buffer.isBuffer = function isBuffer (b) { + return b != null && b._isBuffer === true && + b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false +} - function FunctionDisposer(fn, promise, context) { - this.constructor$(fn, promise, context); - } - inherits(FunctionDisposer, Disposer); +Buffer.compare = function compare (a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError( + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' + ) + } - FunctionDisposer.prototype.doDispose = function (resource, inspection) { - var fn = this.data(); - return fn.call(resource, resource, inspection); - }; + if (a === b) return 0 - function maybeUnwrapDisposer(value) { - if (Disposer.isDisposer(value)) { - this.resources[this.index]._setDisposable(value); - return value.promise(); - } - return value; - } + var x = a.length + var y = b.length - function ResourceList(length) { - this.length = length; - this.promise = null; - this[length-1] = null; + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break } + } - ResourceList.prototype._resultCancelled = function() { - var len = this.length; - for (var i = 0; i < len; ++i) { - var item = this[i]; - if (item instanceof Promise) { - item.cancel(); - } - } - }; + if (x < y) return -1 + if (y < x) return 1 + return 0 +} - Promise.using = function () { - var len = arguments.length; - if (len < 2) return apiRejection( - "you must pass at least 2 arguments to Promise.using"); - var fn = arguments[len - 1]; - if (typeof fn !== "function") { - return apiRejection("expecting a function but got " + util.classString(fn)); - } - var input; - var spreadArgs = true; - if (len === 2 && Array.isArray(arguments[0])) { - input = arguments[0]; - len = input.length; - spreadArgs = false; - } else { - input = arguments; - len--; - } - var resources = new ResourceList(len); - for (var i = 0; i < len; ++i) { - var resource = input[i]; - if (Disposer.isDisposer(resource)) { - var disposer = resource; - resource = resource.promise(); - resource._setDisposable(disposer); - } else { - var maybePromise = tryConvertToPromise(resource); - if (maybePromise instanceof Promise) { - resource = - maybePromise._then(maybeUnwrapDisposer, null, null, { - resources: resources, - index: i - }, undefined); - } - } - resources[i] = resource; - } +Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} - var reflectedResources = new Array(resources.length); - for (var i = 0; i < reflectedResources.length; ++i) { - reflectedResources[i] = Promise.resolve(resources[i]).reflect(); - } +Buffer.concat = function concat (list, length) { + if (!Array.isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } - var resultPromise = Promise.all(reflectedResources) - .then(function(inspections) { - for (var i = 0; i < inspections.length; ++i) { - var inspection = inspections[i]; - if (inspection.isRejected()) { - errorObj.e = inspection.error(); - return errorObj; - } else if (!inspection.isFulfilled()) { - resultPromise.cancel(); - return; - } - inspections[i] = inspection.value(); - } - promise._pushContext(); + if (list.length === 0) { + return Buffer.alloc(0) + } - fn = tryCatch(fn); - var ret = spreadArgs - ? fn.apply(undefined, inspections) : fn(inspections); - var promiseCreated = promise._popContext(); - debug.checkForgottenReturns( - ret, promiseCreated, "Promise.using", promise); - return ret; - }); + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; ++i) { + length += list[i].length + } + } - var promise = resultPromise.lastly(function() { - var inspection = new Promise.PromiseInspection(resultPromise); - return dispose(resources, inspection); - }); - resources.promise = promise; - promise._setOnCancel(resources); - return promise; - }; + var buffer = Buffer.allocUnsafe(length) + var pos = 0 + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (isInstance(buf, Uint8Array)) { + buf = Buffer.from(buf) + } + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length + } + return buffer +} - Promise.prototype._setDisposable = function (disposer) { - this._bitField = this._bitField | 131072; - this._disposer = disposer; - }; +function byteLength (string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + throw new TypeError( + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + + 'Received type ' + typeof string + ) + } - Promise.prototype._isDisposable = function () { - return (this._bitField & 131072) > 0; - }; + var len = string.length + var mustMatch = (arguments.length > 2 && arguments[2] === true) + if (!mustMatch && len === 0) return 0 - Promise.prototype._getDisposer = function () { - return this._disposer; - }; + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 + } + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} +Buffer.byteLength = byteLength - Promise.prototype._unsetDisposable = function () { - this._bitField = this._bitField & (~131072); - this._disposer = undefined; - }; +function slowToString (encoding, start, end) { + var loweredCase = false - Promise.prototype.disposer = function (fn) { - if (typeof fn === "function") { - return new FunctionDisposer(fn, this, createContext()); - } - throw new TypeError(); - }; + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. -}; + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' + } -},{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){ -"use strict"; -var es5 = _dereq_("./es5"); -var canEvaluate = typeof navigator == "undefined"; + if (end === undefined || end > this.length) { + end = this.length + } -var errorObj = {e: {}}; -var tryCatchTarget; -var globalObject = typeof self !== "undefined" ? self : - typeof window !== "undefined" ? window : - typeof global !== "undefined" ? global : - this !== undefined ? this : null; + if (end <= 0) { + return '' + } -function tryCatcher() { - try { - var target = tryCatchTarget; - tryCatchTarget = null; - return target.apply(this, arguments); - } catch (e) { - errorObj.e = e; - return errorObj; - } -} -function tryCatch(fn) { - tryCatchTarget = fn; - return tryCatcher; -} + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 -var inherits = function(Child, Parent) { - var hasProp = {}.hasOwnProperty; + if (end <= start) { + return '' + } - function T() { - this.constructor = Child; - this.constructor$ = Parent; - for (var propertyName in Parent.prototype) { - if (hasProp.call(Parent.prototype, propertyName) && - propertyName.charAt(propertyName.length-1) !== "$" - ) { - this[propertyName + "$"] = Parent.prototype[propertyName]; - } - } - } - T.prototype = Parent.prototype; - Child.prototype = new T(); - return Child.prototype; -}; + if (!encoding) encoding = 'utf8' + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) -function isPrimitive(val) { - return val == null || val === true || val === false || - typeof val === "string" || typeof val === "number"; + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) -} + case 'ascii': + return asciiSlice(this, start, end) -function isObject(value) { - return typeof value === "function" || - typeof value === "object" && value !== null; -} + case 'latin1': + case 'binary': + return latin1Slice(this, start, end) -function maybeWrapAsError(maybeError) { - if (!isPrimitive(maybeError)) return maybeError; + case 'base64': + return base64Slice(this, start, end) - return new Error(safeToString(maybeError)); -} + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) -function withAppended(target, appendee) { - var len = target.length; - var ret = new Array(len + 1); - var i; - for (i = 0; i < len; ++i) { - ret[i] = target[i]; + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true } - ret[i] = appendee; - return ret; + } } -function getDataPropertyOrDefault(obj, key, defaultValue) { - if (es5.isES5) { - var desc = Object.getOwnPropertyDescriptor(obj, key); +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 +Buffer.prototype._isBuffer = true - if (desc != null) { - return desc.get == null && desc.set == null - ? desc.value - : defaultValue; - } - } else { - return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined; - } +function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i } -function notEnumerableProp(obj, name, value) { - if (isPrimitive(obj)) return obj; - var descriptor = { - value: value, - configurable: true, - enumerable: false, - writable: true - }; - es5.defineProperty(obj, name, descriptor); - return obj; +Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this } -function thrower(r) { - throw r; +Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this } -var inheritedDataKeys = (function() { - var excludedPrototypes = [ - Array.prototype, - Object.prototype, - Function.prototype - ]; +Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this +} - var isExcludedProto = function(val) { - for (var i = 0; i < excludedPrototypes.length; ++i) { - if (excludedPrototypes[i] === val) { - return true; - } - } - return false; - }; +Buffer.prototype.toString = function toString () { + var length = this.length + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} - if (es5.isES5) { - var getKeys = Object.getOwnPropertyNames; - return function(obj) { - var ret = []; - var visitedKeys = Object.create(null); - while (obj != null && !isExcludedProto(obj)) { - var keys; - try { - keys = getKeys(obj); - } catch (e) { - return ret; - } - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - if (visitedKeys[key]) continue; - visitedKeys[key] = true; - var desc = Object.getOwnPropertyDescriptor(obj, key); - if (desc != null && desc.get == null && desc.set == null) { - ret.push(key); - } - } - obj = es5.getPrototypeOf(obj); - } - return ret; - }; - } else { - var hasProp = {}.hasOwnProperty; - return function(obj) { - if (isExcludedProto(obj)) return []; - var ret = []; +Buffer.prototype.toLocaleString = Buffer.prototype.toString - /*jshint forin:false */ - enumeration: for (var key in obj) { - if (hasProp.call(obj, key)) { - ret.push(key); - } else { - for (var i = 0; i < excludedPrototypes.length; ++i) { - if (hasProp.call(excludedPrototypes[i], key)) { - continue enumeration; - } - } - ret.push(key); - } - } - return ret; - }; - } +Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 +} -})(); +Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() + if (this.length > max) str += ' ... ' + return '' +} -var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/; -function isClass(fn) { - try { - if (typeof fn === "function") { - var keys = es5.names(fn.prototype); +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) { + target = Buffer.from(target, target.offset, target.byteLength) + } + if (!Buffer.isBuffer(target)) { + throw new TypeError( + 'The "target" argument must be one of type Buffer or Uint8Array. ' + + 'Received type ' + (typeof target) + ) + } - var hasMethods = es5.isES5 && keys.length > 1; - var hasMethodsOtherThanConstructor = keys.length > 0 && - !(keys.length === 1 && keys[0] === "constructor"); - var hasThisAssignmentAndStaticMethods = - thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0; + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } - if (hasMethods || hasMethodsOtherThanConstructor || - hasThisAssignmentAndStaticMethods) { - return true; - } - } - return false; - } catch (e) { - return false; - } -} + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } -function toFastProperties(obj) { - /*jshint -W027,-W055,-W031*/ - function FakeConstructor() {} - FakeConstructor.prototype = obj; - var l = 8; - while (l--) new FakeConstructor(); - return obj; - eval(obj); -} + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } -var rident = /^[a-z$_][a-z$_0-9]*$/i; -function isIdentifier(str) { - return rident.test(str); -} + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 -function filledRange(count, prefix, suffix) { - var ret = new Array(count); - for(var i = 0; i < count; ++i) { - ret[i] = prefix + i + suffix; - } - return ret; -} + if (this === target) return 0 -function safeToString(obj) { - try { - return obj + ""; - } catch (e) { - return "[no string representation]"; - } -} + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) -function isError(obj) { - return obj instanceof Error || - (obj !== null && - typeof obj === "object" && - typeof obj.message === "string" && - typeof obj.name === "string"); -} + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) -function markAsOriginatingFromRejection(e) { - try { - notEnumerableProp(e, "isOperational", true); + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break } - catch(ignore) {} -} + } -function originatesFromRejection(e) { - if (e == null) return false; - return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) || - e["isOperational"] === true); + if (x < y) return -1 + if (y < x) return 1 + return 0 } -function canAttachTrace(obj) { - return isError(obj) && es5.propertyIsWritable(obj, "stack"); -} +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 -var ensureErrorObject = (function() { - if (!("stack" in new Error())) { - return function(value) { - if (canAttachTrace(value)) return value; - try {throw new Error(safeToString(value));} - catch(err) {return err;} - }; - } else { - return function(value) { - if (canAttachTrace(value)) return value; - return new Error(safeToString(value)); - }; + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (numberIsNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } + + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding) + } + + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 } -})(); + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) + } -function classString(obj) { - return {}.toString.call(obj); + throw new TypeError('val must be string, number or Buffer') } -function copyDescriptors(from, to, filter) { - var keys = es5.names(from); - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - if (filter(key)) { - try { - es5.defineProperty(to, key, es5.getDescriptor(from, key)); - } catch (ignore) {} - } +function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 } -} + } -var asArray = function(v) { - if (es5.isArray(v)) { - return v; + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) } - return null; -}; + } -if (typeof Symbol !== "undefined" && Symbol.iterator) { - var ArrayFrom = typeof Array.from === "function" ? function(v) { - return Array.from(v); - } : function(v) { - var ret = []; - var it = v[Symbol.iterator](); - var itResult; - while (!((itResult = it.next()).done)) { - ret.push(itResult.value); + var i + if (dir) { + var foundIndex = -1 + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize + } else { + if (foundIndex !== -1) i -= i - foundIndex + foundIndex = -1 + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break } - return ret; - }; + } + if (found) return i + } + } - asArray = function(v) { - if (es5.isArray(v)) { - return v; - } else if (v != null && typeof v[Symbol.iterator] === "function") { - return ArrayFrom(v); - } - return null; - }; + return -1 } -var isNode = typeof process !== "undefined" && - classString(process).toLowerCase() === "[object process]"; - -var hasEnvVariables = typeof process !== "undefined" && - typeof process.env !== "undefined"; - -function env(key) { - return hasEnvVariables ? process.env[key] : undefined; +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 } -function getNativePromise() { - if (typeof Promise === "function") { - try { - var promise = new Promise(function(){}); - if ({}.toString.call(promise) === "[object Promise]") { - return Promise; - } - } catch (e) {} - } +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) } -function domainBind(self, cb) { - return self.bind(cb); +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) } -var ret = { - isClass: isClass, - isIdentifier: isIdentifier, - inheritedDataKeys: inheritedDataKeys, - getDataPropertyOrDefault: getDataPropertyOrDefault, - thrower: thrower, - isArray: es5.isArray, - asArray: asArray, - notEnumerableProp: notEnumerableProp, - isPrimitive: isPrimitive, - isObject: isObject, - isError: isError, - canEvaluate: canEvaluate, - errorObj: errorObj, - tryCatch: tryCatch, - inherits: inherits, - withAppended: withAppended, - maybeWrapAsError: maybeWrapAsError, - toFastProperties: toFastProperties, - filledRange: filledRange, - toString: safeToString, - canAttachTrace: canAttachTrace, - ensureErrorObject: ensureErrorObject, - originatesFromRejection: originatesFromRejection, - markAsOriginatingFromRejection: markAsOriginatingFromRejection, - classString: classString, - copyDescriptors: copyDescriptors, - hasDevTools: typeof chrome !== "undefined" && chrome && - typeof chrome.loadTimes === "function", - isNode: isNode, - hasEnvVariables: hasEnvVariables, - env: env, - global: globalObject, - getNativePromise: getNativePromise, - domainBind: domainBind -}; -ret.isRecentNode = ret.isNode && (function() { - var version = 'v16.13.0'.split(".").map(Number); - return (version[0] === 0 && version[1] > 10) || (version[0] > 0); -})(); +function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } -if (ret.isNode) ret.toFastProperties(process); + var strLen = string.length -try {throw new Error(); } catch (e) {ret.lastLineError = e;} -module.exports = ret; + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (numberIsNaN(parsed)) return i + buf[offset + i] = parsed + } + return i +} -},{"./es5":13}]},{},[4])(4) -}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; } -}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) -},{"_process":369,"timers":374}],29:[function(require,module,exports){ -(function (global){(function (){ -/** - * Module dependencies. - * @ignore - */ +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} -// Test if we're in Node via presence of "global" not absence of "window" -// to support hybrid environments like Electron -if (typeof global !== 'undefined') { - var Buffer = require('buffer').Buffer; // TODO just use global Buffer +function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) } -var utils = require('./parser/utils'); +function latin1Write (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) +} -/** - * A class representation of the BSON Binary type. - * - * Sub types - * - **BSON.BSON_BINARY_SUBTYPE_DEFAULT**, default BSON type. - * - **BSON.BSON_BINARY_SUBTYPE_FUNCTION**, BSON function type. - * - **BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY**, BSON byte array type. - * - **BSON.BSON_BINARY_SUBTYPE_UUID**, BSON uuid type. - * - **BSON.BSON_BINARY_SUBTYPE_MD5**, BSON md5 type. - * - **BSON.BSON_BINARY_SUBTYPE_USER_DEFINED**, BSON user defined type. - * - * @class - * @param {Buffer} buffer a buffer object containing the binary data. - * @param {Number} [subType] the option binary type. - * @return {Binary} - */ -function Binary(buffer, subType) { - if (!(this instanceof Binary)) return new Binary(buffer, subType); +function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) +} - if ( - buffer != null && - !(typeof buffer === 'string') && - !Buffer.isBuffer(buffer) && - !(buffer instanceof Uint8Array) && - !Array.isArray(buffer) - ) { - throw new Error('only String, Buffer, Uint8Array or Array accepted'); +function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) +} + +Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset >>> 0 + if (isFinite(length)) { + length = length >>> 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined + } + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) } - this._bsontype = 'Binary'; + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining - if (buffer instanceof Number) { - this.sub_type = buffer; - this.position = 0; - } else { - this.sub_type = subType == null ? BSON_BINARY_SUBTYPE_DEFAULT : subType; - this.position = 0; + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') } - if (buffer != null && !(buffer instanceof Number)) { - // Only accept Buffer, Uint8Array or Arrays - if (typeof buffer === 'string') { - // Different ways of writing the length of the string for the different types - if (typeof Buffer !== 'undefined') { - this.buffer = utils.toBuffer(buffer); - } else if ( - typeof Uint8Array !== 'undefined' || - Object.prototype.toString.call(buffer) === '[object Array]' - ) { - this.buffer = writeStringToArray(buffer); - } else { - throw new Error('only String, Buffer, Uint8Array or Array accepted'); - } - } else { - this.buffer = buffer; - } - this.position = buffer.length; - } else { - if (typeof Buffer !== 'undefined') { - this.buffer = utils.allocBuffer(Binary.BUFFER_SIZE); - } else if (typeof Uint8Array !== 'undefined') { - this.buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE)); - } else { - this.buffer = new Array(Binary.BUFFER_SIZE); + if (!encoding) encoding = 'utf8' + + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) + + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) + + case 'ascii': + return asciiWrite(this, string, offset, length) + + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length) + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true } - // Set position to start of buffer - this.position = 0; } } -/** - * Updates this binary with byte_value. - * - * @method - * @param {string} byte_value a single byte we wish to write. - */ -Binary.prototype.put = function put(byte_value) { - // If it's a string and a has more than one character throw an error - if (byte_value['length'] != null && typeof byte_value !== 'number' && byte_value.length !== 1) - throw new Error('only accepts single character String, Uint8Array or Array'); - if ((typeof byte_value !== 'number' && byte_value < 0) || byte_value > 255) - throw new Error('only accepts number in a valid unsigned byte range 0-255'); +Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } +} - // Decode the byte value once - var decoded_byte = null; - if (typeof byte_value === 'string') { - decoded_byte = byte_value.charCodeAt(0); - } else if (byte_value['length'] != null) { - decoded_byte = byte_value[0]; +function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) } else { - decoded_byte = byte_value; + return base64.fromByteArray(buf.slice(start, end)) } +} - if (this.buffer.length > this.position) { - this.buffer[this.position++] = decoded_byte; - } else { - if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { - // Create additional overflow buffer - var buffer = utils.allocBuffer(Binary.BUFFER_SIZE + this.buffer.length); - // Combine the two buffers together - this.buffer.copy(buffer, 0, 0, this.buffer.length); - this.buffer = buffer; - this.buffer[this.position++] = decoded_byte; - } else { - buffer = null; - // Create a new buffer (typed or normal array) - if (Object.prototype.toString.call(this.buffer) === '[object Uint8Array]') { - buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE + this.buffer.length)); - } else { - buffer = new Array(Binary.BUFFER_SIZE + this.buffer.length); - } +function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] - // We need to copy all the content to the new array - for (var i = 0; i < this.buffer.length; i++) { - buffer[i] = this.buffer[i]; + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } } + } - // Reassign the buffer - this.buffer = buffer; - // Write the byte - this.buffer[this.position++] = decoded_byte; + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF } + + res.push(codePoint) + i += bytesPerSequence } -}; -/** - * Writes a buffer or string to the binary. - * - * @method - * @param {(Buffer|string)} string a string or buffer to be written to the Binary BSON object. - * @param {number} offset specify the binary of where to write the content. - * @return {null} - */ -Binary.prototype.write = function write(string, offset) { - offset = typeof offset === 'number' ? offset : this.position; + return decodeCodePointsArray(res) +} - // If the buffer is to small let's extend the buffer - if (this.buffer.length < offset + string.length) { - var buffer = null; - // If we are in node.js - if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { - buffer = utils.allocBuffer(this.buffer.length + string.length); - this.buffer.copy(buffer, 0, 0, this.buffer.length); - } else if (Object.prototype.toString.call(this.buffer) === '[object Uint8Array]') { - // Create a new buffer - buffer = new Uint8Array(new ArrayBuffer(this.buffer.length + string.length)); - // Copy the content - for (var i = 0; i < this.position; i++) { - buffer[i] = this.buffer[i]; - } - } +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 - // Assign the new buffer - this.buffer = buffer; +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() } - if (typeof Buffer !== 'undefined' && Buffer.isBuffer(string) && Buffer.isBuffer(this.buffer)) { - string.copy(this.buffer, offset, 0, string.length); - this.position = offset + string.length > this.position ? offset + string.length : this.position; - // offset = string.length - } else if ( - typeof Buffer !== 'undefined' && - typeof string === 'string' && - Buffer.isBuffer(this.buffer) - ) { - this.buffer.write(string, offset, 'binary'); - this.position = offset + string.length > this.position ? offset + string.length : this.position; - // offset = string.length; - } else if ( - Object.prototype.toString.call(string) === '[object Uint8Array]' || - (Object.prototype.toString.call(string) === '[object Array]' && typeof string !== 'string') - ) { - for (i = 0; i < string.length; i++) { - this.buffer[offset++] = string[i]; - } + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res +} - this.position = offset > this.position ? offset : this.position; - } else if (typeof string === 'string') { - for (i = 0; i < string.length; i++) { - this.buffer[offset++] = string.charCodeAt(i); - } +function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) - this.position = offset > this.position ? offset : this.position; + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7F) } -}; + return ret +} -/** - * Reads **length** bytes starting at **position**. - * - * @method - * @param {number} position read from the given position in the Binary. - * @param {number} length the number of bytes to read. - * @return {Buffer} - */ -Binary.prototype.read = function read(position, length) { - length = length && length > 0 ? length : this.position; +function latin1Slice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) - // Let's return the data based on the type we have - if (this.buffer['slice']) { - return this.buffer.slice(position, position + length); - } else { - // Create a buffer to keep the result - var buffer = - typeof Uint8Array !== 'undefined' - ? new Uint8Array(new ArrayBuffer(length)) - : new Array(length); - for (var i = 0; i < length; i++) { - buffer[i] = this.buffer[position++]; - } + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]) } - // Return the buffer - return buffer; -}; + return ret +} -/** - * Returns the value of this binary as a string. - * - * @method - * @return {string} - */ -Binary.prototype.value = function value(asRaw) { - asRaw = asRaw == null ? false : asRaw; +function hexSlice (buf, start, end) { + var len = buf.length - // Optimize to serialize for the situation where the data == size of buffer - if ( - asRaw && - typeof Buffer !== 'undefined' && - Buffer.isBuffer(this.buffer) && - this.buffer.length === this.position - ) - return this.buffer; + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len - // If it's a node.js buffer object - if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) { - return asRaw - ? this.buffer.slice(0, this.position) - : this.buffer.toString('binary', 0, this.position); - } else { - if (asRaw) { - // we support the slice command use it - if (this.buffer['slice'] != null) { - return this.buffer.slice(0, this.position); - } else { - // Create a new buffer to copy content to - var newBuffer = - Object.prototype.toString.call(this.buffer) === '[object Uint8Array]' - ? new Uint8Array(new ArrayBuffer(this.position)) - : new Array(this.position); - // Copy content - for (var i = 0; i < this.position; i++) { - newBuffer[i] = this.buffer[i]; - } - // Return the buffer - return newBuffer; - } - } else { - return convertArraytoUtf8BinaryString(this.buffer, 0, this.position); - } + var out = '' + for (var i = start; i < end; ++i) { + out += toHex(buf[i]) } -}; - -/** - * Length. - * - * @method - * @return {number} the length of the binary. - */ -Binary.prototype.length = function length() { - return this.position; -}; + return out +} -/** - * @ignore - */ -Binary.prototype.toJSON = function() { - return this.buffer != null ? this.buffer.toString('base64') : ''; -}; +function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) + } + return res +} -/** - * @ignore - */ -Binary.prototype.toString = function(format) { - return this.buffer != null ? this.buffer.slice(0, this.position).toString(format) : ''; -}; +Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end -/** - * Binary default subtype - * @ignore - */ -var BSON_BINARY_SUBTYPE_DEFAULT = 0; + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len + } -/** - * @ignore - */ -var writeStringToArray = function(data) { - // Create a buffer - var buffer = - typeof Uint8Array !== 'undefined' - ? new Uint8Array(new ArrayBuffer(data.length)) - : new Array(data.length); - // Write the content to the buffer - for (var i = 0; i < data.length; i++) { - buffer[i] = data.charCodeAt(i); + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len } - // Write the string to the buffer - return buffer; -}; -/** - * Convert Array ot Uint8Array to Binary String - * - * @ignore + if (end < start) end = start + + var newBuf = this.subarray(start, end) + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype + return newBuf +} + +/* + * Need to make sure that buffer isn't trying to write out of bounds. */ -var convertArraytoUtf8BinaryString = function(byteArray, startIndex, endIndex) { - var result = ''; - for (var i = startIndex; i < endIndex; i++) { - result = result + String.fromCharCode(byteArray[i]); - } - return result; -}; +function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') +} -Binary.BUFFER_SIZE = 256; +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) -/** - * Default BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_DEFAULT = 0; -/** - * Function BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_FUNCTION = 1; -/** - * Byte Array BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_BYTE_ARRAY = 2; -/** - * OLD UUID BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_UUID_OLD = 3; -/** - * UUID BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_UUID = 4; -/** - * MD5 BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_MD5 = 5; -/** - * User BSON type - * - * @classconstant SUBTYPE_DEFAULT - **/ -Binary.SUBTYPE_USER_DEFINED = 128; + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } -/** - * Expose. - */ -module.exports = Binary; -module.exports.Binary = Binary; + return val +} -}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./parser/utils":45,"buffer":49}],30:[function(require,module,exports){ -'use strict'; +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) + } -var Map = require('./map'), - Long = require('./long'), - Double = require('./double'), - Timestamp = require('./timestamp'), - ObjectID = require('./objectid'), - BSONRegExp = require('./regexp'), - Symbol = require('./symbol'), - Int32 = require('./int_32'), - Code = require('./code'), - Decimal128 = require('./decimal128'), - MinKey = require('./min_key'), - MaxKey = require('./max_key'), - DBRef = require('./db_ref'), - Binary = require('./binary'); + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul + } -// Parts of the parser -var deserialize = require('./parser/deserializer'), - serializer = require('./parser/serializer'), - calculateObjectSize = require('./parser/calculate_size'), - utils = require('./parser/utils'); + return val +} -/** - * @ignore - * @api private - */ -// Default Max Size -var MAXSIZE = 1024 * 1024 * 17; +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} -// Current Internal Temporary Serialization Buffer -var buffer = utils.allocBuffer(MAXSIZE); +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} -var BSON = function() {}; +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} -/** - * Serialize a Javascript object. - * - * @param {Object} object the Javascript object to serialize. - * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. - * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. - * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. - * @param {Number} [options.minInternalBufferSize=1024*1024*17] minimum size of the internal temporary serialization buffer **(default:1024*1024*17)**. - * @return {Buffer} returns the Buffer object containing the serialized object. - * @api public - */ -BSON.prototype.serialize = function serialize(object, options) { - options = options || {}; - // Unpack the options - var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; - var serializeFunctions = - typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; - var ignoreUndefined = - typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; - var minInternalBufferSize = - typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; - - // Resize the internal serialization buffer if needed - if (buffer.length < minInternalBufferSize) { - buffer = utils.allocBuffer(minInternalBufferSize); - } +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) - // Attempt to serialize - var serializationIndex = serializer( - buffer, - object, - checkKeys, - 0, - 0, - serializeFunctions, - ignoreUndefined, - [] - ); - // Create the final buffer - var finishedBuffer = utils.allocBuffer(serializationIndex); - // Copy into the finished buffer - buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length); - // Return the buffer - return finishedBuffer; -}; + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) +} -/** - * Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization. - * - * @param {Object} object the Javascript object to serialize. - * @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. - * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. - * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. - * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. - * @param {Number} [options.index] the index in the buffer where we wish to start serializing into. - * @return {Number} returns the index pointing to the last written byte in the buffer. - * @api public - */ -BSON.prototype.serializeWithBufferAndIndex = function(object, finalBuffer, options) { - options = options || {}; - // Unpack the options - var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; - var serializeFunctions = - typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; - var ignoreUndefined = - typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; - var startIndex = typeof options.index === 'number' ? options.index : 0; +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) - // Attempt to serialize - var serializationIndex = serializer( - finalBuffer, - object, - checkKeys, - startIndex || 0, - 0, - serializeFunctions, - ignoreUndefined - ); + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) +} - // Return the index - return serializationIndex - 1; -}; +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) -/** - * Deserialize data as BSON. - * - * @param {Buffer} buffer the buffer containing the serialized set of BSON documents. - * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. - * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. - * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. - * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits - * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. - * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. - * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. - * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. - * @return {Object} returns the deserialized Javascript Object. - * @api public - */ -BSON.prototype.deserialize = function(buffer, options) { - return deserialize(buffer, options); -}; + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + mul *= 0x80 -/** - * Calculate the bson size for a passed in Javascript object. - * - * @param {Object} object the Javascript object to calculate the BSON byte size for. - * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. - * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. - * @return {Number} returns the number of bytes the BSON object will take up. - * @api public - */ -BSON.prototype.calculateObjectSize = function(object, options) { - options = options || {}; + if (val >= mul) val -= Math.pow(2, 8 * byteLength) - var serializeFunctions = - typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; - var ignoreUndefined = - typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; + return val +} - return calculateObjectSize(object, serializeFunctions, ignoreUndefined); -}; +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) -/** - * Deserialize stream data as BSON documents. - * - * @param {Buffer} data the buffer containing the serialized set of BSON documents. - * @param {Number} startIndex the start index in the data Buffer where the deserialization is to start. - * @param {Number} numberOfDocuments number of documents to deserialize. - * @param {Array} documents an array where to store the deserialized documents. - * @param {Number} docStartIndex the index in the documents array from where to start inserting documents. - * @param {Object} [options] additional options used for the deserialization. - * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. - * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. - * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. - * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits - * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. - * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. - * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. - * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. - * @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents. - * @api public - */ -BSON.prototype.deserializeStream = function( - data, - startIndex, - numberOfDocuments, - documents, - docStartIndex, - options -) { - options = options != null ? options : {}; - var index = startIndex; - // Loop over all documents - for (var i = 0; i < numberOfDocuments; i++) { - // Find size of the document - var size = - data[index] | (data[index + 1] << 8) | (data[index + 2] << 16) | (data[index + 3] << 24); - // Update options with index - options['index'] = index; - // Parse the document at this point - documents[docStartIndex + i] = this.deserialize(data, options); - // Adjust index by the document size - index = index + size; + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul } + mul *= 0x80 - // Return object containing end index of parsing and list of documents - return index; -}; + if (val >= mul) val -= Math.pow(2, 8 * byteLength) -/** - * @ignore - * @api private - */ -// BSON MAX VALUES -BSON.BSON_INT32_MAX = 0x7fffffff; -BSON.BSON_INT32_MIN = -0x80000000; + return val +} -BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; -BSON.BSON_INT64_MIN = -Math.pow(2, 63); +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) +} -// JS MAX PRECISE VALUES -BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. -BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} -// Internal long versions -// var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. -// var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} -/** - * Number BSON Type - * - * @classconstant BSON_DATA_NUMBER - **/ -BSON.BSON_DATA_NUMBER = 1; -/** - * String BSON Type - * - * @classconstant BSON_DATA_STRING - **/ -BSON.BSON_DATA_STRING = 2; -/** - * Object BSON Type - * - * @classconstant BSON_DATA_OBJECT - **/ -BSON.BSON_DATA_OBJECT = 3; -/** - * Array BSON Type - * - * @classconstant BSON_DATA_ARRAY - **/ -BSON.BSON_DATA_ARRAY = 4; -/** - * Binary BSON Type - * - * @classconstant BSON_DATA_BINARY - **/ -BSON.BSON_DATA_BINARY = 5; -/** - * ObjectID BSON Type - * - * @classconstant BSON_DATA_OID - **/ -BSON.BSON_DATA_OID = 7; -/** - * Boolean BSON Type - * - * @classconstant BSON_DATA_BOOLEAN - **/ -BSON.BSON_DATA_BOOLEAN = 8; -/** - * Date BSON Type - * - * @classconstant BSON_DATA_DATE - **/ -BSON.BSON_DATA_DATE = 9; -/** - * null BSON Type - * - * @classconstant BSON_DATA_NULL - **/ -BSON.BSON_DATA_NULL = 10; -/** - * RegExp BSON Type - * - * @classconstant BSON_DATA_REGEXP - **/ -BSON.BSON_DATA_REGEXP = 11; -/** - * Code BSON Type - * - * @classconstant BSON_DATA_CODE - **/ -BSON.BSON_DATA_CODE = 13; -/** - * Symbol BSON Type - * - * @classconstant BSON_DATA_SYMBOL - **/ -BSON.BSON_DATA_SYMBOL = 14; -/** - * Code with Scope BSON Type - * - * @classconstant BSON_DATA_CODE_W_SCOPE - **/ -BSON.BSON_DATA_CODE_W_SCOPE = 15; -/** - * 32 bit Integer BSON Type - * - * @classconstant BSON_DATA_INT - **/ -BSON.BSON_DATA_INT = 16; -/** - * Timestamp BSON Type - * - * @classconstant BSON_DATA_TIMESTAMP - **/ -BSON.BSON_DATA_TIMESTAMP = 17; -/** - * Long BSON Type - * - * @classconstant BSON_DATA_LONG - **/ -BSON.BSON_DATA_LONG = 18; -/** - * MinKey BSON Type - * - * @classconstant BSON_DATA_MIN_KEY - **/ -BSON.BSON_DATA_MIN_KEY = 0xff; -/** - * MaxKey BSON Type - * - * @classconstant BSON_DATA_MAX_KEY - **/ -BSON.BSON_DATA_MAX_KEY = 0x7f; +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) -/** - * Binary Default Type - * - * @classconstant BSON_BINARY_SUBTYPE_DEFAULT - **/ -BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; -/** - * Binary Function Type - * - * @classconstant BSON_BINARY_SUBTYPE_FUNCTION - **/ -BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; -/** - * Binary Byte Array Type - * - * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY - **/ -BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; -/** - * Binary UUID Type - * - * @classconstant BSON_BINARY_SUBTYPE_UUID - **/ -BSON.BSON_BINARY_SUBTYPE_UUID = 3; -/** - * Binary MD5 Type - * - * @classconstant BSON_BINARY_SUBTYPE_MD5 - **/ -BSON.BSON_BINARY_SUBTYPE_MD5 = 4; -/** - * Binary User Defined Type - * - * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED - **/ -BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) +} -// Return BSON -module.exports = BSON; -module.exports.Code = Code; -module.exports.Map = Map; -module.exports.Symbol = Symbol; -module.exports.BSON = BSON; -module.exports.DBRef = DBRef; -module.exports.Binary = Binary; -module.exports.ObjectID = ObjectID; -module.exports.Long = Long; -module.exports.Timestamp = Timestamp; -module.exports.Double = Double; -module.exports.Int32 = Int32; -module.exports.MinKey = MinKey; -module.exports.MaxKey = MaxKey; -module.exports.BSONRegExp = BSONRegExp; -module.exports.Decimal128 = Decimal128; +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) -},{"./binary":29,"./code":31,"./db_ref":32,"./decimal128":33,"./double":34,"./int_32":36,"./long":37,"./map":38,"./max_key":39,"./min_key":40,"./objectid":41,"./parser/calculate_size":42,"./parser/deserializer":43,"./parser/serializer":44,"./parser/utils":45,"./regexp":46,"./symbol":47,"./timestamp":48}],31:[function(require,module,exports){ -/** - * A class representation of the BSON Code type. - * - * @class - * @param {(string|function)} code a string or function. - * @param {Object} [scope] an optional scope for the function. - * @return {Code} - */ -var Code = function Code(code, scope) { - if (!(this instanceof Code)) return new Code(code, scope); - this._bsontype = 'Code'; - this.code = code; - this.scope = scope; -}; + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) +} -/** - * @ignore - */ -Code.prototype.toJSON = function() { - return { scope: this.scope, code: this.code }; -}; +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} -module.exports = Code; -module.exports.Code = Code; +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} -},{}],32:[function(require,module,exports){ -/** - * A class representation of the BSON DBRef type. - * - * @class - * @param {string} namespace the collection name. - * @param {ObjectID} oid the reference ObjectID. - * @param {string} [db] optional db name, if omitted the reference is local to the current db. - * @return {DBRef} - */ -function DBRef(namespace, oid, db) { - if (!(this instanceof DBRef)) return new DBRef(namespace, oid, db); +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} - this._bsontype = 'DBRef'; - this.namespace = namespace; - this.oid = oid; - this.db = db; +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + offset = offset >>> 0 + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) } -/** - * @ignore - * @api private - */ -DBRef.prototype.toJSON = function() { - return { - $ref: this.namespace, - $id: this.oid, - $db: this.db == null ? '' : this.db - }; -}; +function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') +} -module.exports = DBRef; -module.exports.DBRef = DBRef; +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } -},{}],33:[function(require,module,exports){ -'use strict'; + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } -var Long = require('./long'); + return offset + byteLength +} -var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/; -var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i; -var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i; +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } -var EXPONENT_MAX = 6111; -var EXPONENT_MIN = -6176; -var EXPONENT_BIAS = 6176; -var MAX_DIGITS = 34; + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } -// Nan value bits as 32 bit values (due to lack of longs) -var NAN_BUFFER = [ - 0x7c, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 -].reverse(); -// Infinity value bits 32 bit values (due to lack of longs) -var INF_NEGATIVE_BUFFER = [ - 0xf8, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 -].reverse(); -var INF_POSITIVE_BUFFER = [ - 0x78, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 -].reverse(); + return offset + byteLength +} -var EXPONENT_REGEX = /^([-+])?(\d+)?$/; +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + this[offset] = (value & 0xff) + return offset + 1 +} -var utils = require('./parser/utils'); +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + return offset + 2 +} -// Detect if the value is a digit -var isDigit = function(value) { - return !isNaN(parseInt(value, 10)); -}; +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + return offset + 2 +} -// Divide two uint128 values -var divideu128 = function(value) { - var DIVISOR = Long.fromNumber(1000 * 1000 * 1000); - var _rem = Long.fromNumber(0); - var i = 0; +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + return offset + 4 +} - if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) { - return { quotient: value, rem: _rem }; +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + return offset + 4 +} + +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) { + var limit = Math.pow(2, (8 * byteLength) - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) } - for (i = 0; i <= 3; i++) { - // Adjust remainder to match value of next dividend - _rem = _rem.shiftLeft(32); - // Add the divided to _rem - _rem = _rem.add(new Long(value.parts[i], 0)); - value.parts[i] = _rem.div(DIVISOR).low_; - _rem = _rem.modulo(DIVISOR); + var i = 0 + var mul = 1 + var sub = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } - return { quotient: value, rem: _rem }; -}; + return offset + byteLength +} -// Multiply two Long values and return the 128 bit value -var multiply64x2 = function(left, right) { - if (!left && !right) { - return { high: Long.fromNumber(0), low: Long.fromNumber(0) }; - } +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) { + var limit = Math.pow(2, (8 * byteLength) - 1) - var leftHigh = left.shiftRightUnsigned(32); - var leftLow = new Long(left.getLowBits(), 0); - var rightHigh = right.shiftRightUnsigned(32); - var rightLow = new Long(right.getLowBits(), 0); + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } - var productHigh = leftHigh.multiply(rightHigh); - var productMid = leftHigh.multiply(rightLow); - var productMid2 = leftLow.multiply(rightHigh); - var productLow = leftLow.multiply(rightLow); + var i = byteLength - 1 + var mul = 1 + var sub = 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } - productHigh = productHigh.add(productMid.shiftRightUnsigned(32)); - productMid = new Long(productMid.getLowBits(), 0) - .add(productMid2) - .add(productLow.shiftRightUnsigned(32)); + return offset + byteLength +} - productHigh = productHigh.add(productMid.shiftRightUnsigned(32)); - productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0)); +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 +} - // Return the 128 bit result - return { high: productHigh, low: productLow }; -}; +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + return offset + 2 +} -var lessThan = function(left, right) { - // Make values unsigned - var uhleft = left.high_ >>> 0; - var uhright = right.high_ >>> 0; +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + return offset + 2 +} - // Compare high bits first - if (uhleft < uhright) { - return true; - } else if (uhleft === uhright) { - var ulleft = left.low_ >>> 0; - var ulright = right.low_ >>> 0; - if (ulleft < ulright) return true; - } +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + return offset + 4 +} - return false; -}; +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + return offset + 4 +} -// var longtoHex = function(value) { -// var buffer = utils.allocBuffer(8); -// var index = 0; -// // Encode the low 64 bits of the decimal -// // Encode low bits -// buffer[index++] = value.low_ & 0xff; -// buffer[index++] = (value.low_ >> 8) & 0xff; -// buffer[index++] = (value.low_ >> 16) & 0xff; -// buffer[index++] = (value.low_ >> 24) & 0xff; -// // Encode high bits -// buffer[index++] = value.high_ & 0xff; -// buffer[index++] = (value.high_ >> 8) & 0xff; -// buffer[index++] = (value.high_ >> 16) & 0xff; -// buffer[index++] = (value.high_ >> 24) & 0xff; -// return buffer.reverse().toString('hex'); -// }; +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') +} -// var int32toHex = function(value) { -// var buffer = utils.allocBuffer(4); -// var index = 0; -// // Encode the low 64 bits of the decimal -// // Encode low bits -// buffer[index++] = value & 0xff; -// buffer[index++] = (value >> 8) & 0xff; -// buffer[index++] = (value >> 16) & 0xff; -// buffer[index++] = (value >> 24) & 0xff; -// return buffer.reverse().toString('hex'); -// }; +function writeFloat (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 +} -/** - * A class representation of the BSON Decimal128 type. - * - * @class - * @param {Buffer} bytes a buffer containing the raw Decimal128 bytes. - * @return {Double} - */ -var Decimal128 = function(bytes) { - this._bsontype = 'Decimal128'; - this.bytes = bytes; -}; +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) +} -/** - * Create a Decimal128 instance from a string representation - * - * @method - * @param {string} string a numeric string representation. - * @return {Decimal128} returns a Decimal128 instance. - */ -Decimal128.fromString = function(string) { - // Parse state tracking - var isNegative = false; - var sawRadix = false; - var foundNonZero = false; +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) +} - // Total number of significant digits (no leading or trailing zero) - var significantDigits = 0; - // Total number of significand digits read - var nDigitsRead = 0; - // Total number of digits (no leading zeros) - var nDigits = 0; - // The number of the digits after radix - var radixPosition = 0; - // The index of the first non-zero in *str* - var firstNonZero = 0; +function writeDouble (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 +} - // Digits Array - var digits = [0]; - // The number of digits in digits - var nDigitsStored = 0; - // Insertion pointer for digits - var digitsInsert = 0; - // The index of the first non-zero digit - var firstDigit = 0; - // The index of the last digit - var lastDigit = 0; +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) +} - // Exponent - var exponent = 0; - // loop index over array - var i = 0; - // The high 17 digits of the significand - var significandHigh = [0, 0]; - // The low 17 digits of the significand - var significandLow = [0, 0]; - // The biased exponent - var biasedExponent = 0; +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) +} - // Read index - var index = 0; +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start - // Trim the string - string = string.trim(); + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 - // Naively prevent against REDOS attacks. - // TODO: implementing a custom parsing for this, or refactoring the regex would yield - // further gains. - if (string.length >= 7000) { - throw new Error('' + string + ' not a valid Decimal128 string'); + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') } + if (start < 0 || start >= this.length) throw new RangeError('Index out of range') + if (end < 0) throw new RangeError('sourceEnd out of bounds') - // Results - var stringMatch = string.match(PARSE_STRING_REGEXP); - var infMatch = string.match(PARSE_INF_REGEXP); - var nanMatch = string.match(PARSE_NAN_REGEXP); - - // Validate the string - if ((!stringMatch && !infMatch && !nanMatch) || string.length === 0) { - throw new Error('' + string + ' not a valid Decimal128 string'); + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start } - // Check if we have an illegal exponent format - if (stringMatch && stringMatch[4] && stringMatch[2] === undefined) { - throw new Error('' + string + ' not a valid Decimal128 string'); - } - - // Get the negative or positive sign - if (string[index] === '+' || string[index] === '-') { - isNegative = string[index++] === '-'; - } + var len = end - start - // Check if user passed Infinity or NaN - if (!isDigit(string[index]) && string[index] !== '.') { - if (string[index] === 'i' || string[index] === 'I') { - return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); - } else if (string[index] === 'N') { - return new Decimal128(utils.toBuffer(NAN_BUFFER)); + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end) + } else if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (var i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start] } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, end), + targetStart + ) } - // Read all the digits - while (isDigit(string[index]) || string[index] === '.') { - if (string[index] === '.') { - if (sawRadix) { - return new Decimal128(utils.toBuffer(NAN_BUFFER)); - } + return len +} - sawRadix = true; - index = index + 1; - continue; +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length } - - if (nDigitsStored < 34) { - if (string[index] !== '0' || foundNonZero) { - if (!foundNonZero) { - firstNonZero = nDigitsRead; - } - - foundNonZero = true; - - // Only store 34 digits - digits[digitsInsert++] = parseInt(string[index], 10); - nDigitsStored = nDigitsStored + 1; - } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') } - - if (foundNonZero) { - nDigits = nDigits + 1; + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) } - - if (sawRadix) { - radixPosition = radixPosition + 1; + if (val.length === 1) { + var code = val.charCodeAt(0) + if ((encoding === 'utf8' && code < 128) || + encoding === 'latin1') { + // Fast path: If `val` fits into a single byte, use that numeric value. + val = code + } } - - nDigitsRead = nDigitsRead + 1; - index = index + 1; + } else if (typeof val === 'number') { + val = val & 255 } - if (sawRadix && !nDigitsRead) { - throw new Error('' + string + ' not a valid Decimal128 string'); + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') } - // Read exponent if exists - if (string[index] === 'e' || string[index] === 'E') { - // Read exponent digits - var match = string.substr(++index).match(EXPONENT_REGEX); + if (end <= start) { + return this + } - // No digits read - if (!match || !match[2]) { - return new Decimal128(utils.toBuffer(NAN_BUFFER)); - } + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 - // Get exponent - exponent = parseInt(match[0], 10); + if (!val) val = 0 - // Adjust the index - index = index + match[0].length; + var i + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : Buffer.from(val, encoding) + var len = bytes.length + if (len === 0) { + throw new TypeError('The value "' + val + + '" is invalid for argument "value"') + } + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] + } } - // Return not a number - if (string[index]) { - return new Decimal128(utils.toBuffer(NAN_BUFFER)); - } + return this +} - // Done reading input - // Find first non-zero digit in digits - firstDigit = 0; +// HELPER FUNCTIONS +// ================ - if (!nDigitsStored) { - firstDigit = 0; - lastDigit = 0; - digits[0] = 0; - nDigits = 1; - nDigitsStored = 1; - significantDigits = 0; - } else { - lastDigit = nDigitsStored - 1; - significantDigits = nDigits; +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g - if (exponent !== 0 && significantDigits !== 1) { - while (string[firstNonZero + significantDigits - 1] === '0') { - significantDigits = significantDigits - 1; - } - } +function base64clean (str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split('=')[0] + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = str.trim().replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' } + return str +} - // Normalization of exponent - // Correct exponent based on radix position, and shift significand as needed - // to represent user input +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) +} - // Overflow prevention - if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) { - exponent = EXPONENT_MIN; - } else { - exponent = exponent - radixPosition; - } +function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] - // Attempt to normalize the exponent - while (exponent > EXPONENT_MAX) { - // Shift exponent to significand and decrease - lastDigit = lastDigit + 1; + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i) - if (lastDigit - firstDigit > MAX_DIGITS) { - // Check if we have a zero then just hard clamp, otherwise fail - var digitsString = digits.join(''); - if (digitsString.match(/^0+$/)) { - exponent = EXPONENT_MAX; - break; - } else { - return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } + + // valid lead + leadSurrogate = codePoint + + continue } - } - exponent = exponent - 1; - } + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } - while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) { - // Shift last digit - if (lastDigit === 0) { - exponent = EXPONENT_MIN; - significantDigits = 0; - break; + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) } - if (nDigitsStored < nDigits) { - // adjust to match digits not stored - nDigits = nDigits - 1; - } else { - // adjust to round - lastDigit = lastDigit - 1; - } + leadSurrogate = null - if (exponent < EXPONENT_MAX) { - exponent = exponent + 1; + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) } else { - // Check if we have a zero then just hard clamp, otherwise fail - digitsString = digits.join(''); - if (digitsString.match(/^0+$/)) { - exponent = EXPONENT_MAX; - break; - } else { - return new Decimal128(utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER)); - } + throw new Error('Invalid code point') } } - // Round - // We've normalized the exponent, but might still need to round. - if (lastDigit - firstDigit + 1 < significantDigits && string[significantDigits] !== '0') { - var endOfString = nDigitsRead; + return bytes +} - // If we have seen a radix point, 'string' is 1 longer than we have - // documented with ndigits_read, so inc the position of the first nonzero - // digit and the position that digits are read to. - if (sawRadix && exponent === EXPONENT_MIN) { - firstNonZero = firstNonZero + 1; - endOfString = endOfString + 1; - } +function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) + } + return byteArray +} - var roundDigit = parseInt(string[firstNonZero + lastDigit + 1], 10); - var roundBit = 0; +function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break - if (roundDigit >= 5) { - roundBit = 1; + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } - if (roundDigit === 5) { - roundBit = digits[lastDigit] % 2 === 1; + return byteArray +} - for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) { - if (parseInt(string[i], 10)) { - roundBit = 1; - break; - } - } - } - } +function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) +} - if (roundBit) { - var dIdx = lastDigit; +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] + } + return i +} - for (; dIdx >= 0; dIdx--) { - if (++digits[dIdx] > 9) { - digits[dIdx] = 0; +// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass +// the `instanceof` check but they should be treated as of that type. +// See: https://github.com/feross/buffer/issues/166 +function isInstance (obj, type) { + return obj instanceof type || + (obj != null && obj.constructor != null && obj.constructor.name != null && + obj.constructor.name === type.name) +} +function numberIsNaN (obj) { + // For IE11 support + return obj !== obj // eslint-disable-line no-self-compare +} - // overflowed most significant digit - if (dIdx === 0) { - if (exponent < EXPONENT_MAX) { - exponent = exponent + 1; - digits[dIdx] = 1; - } else { - return new Decimal128( - utils.toBuffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER) - ); - } - } - } else { - break; - } - } - } - } +}).call(this)}).call(this,require("buffer").Buffer) +},{"base64-js":13,"buffer":35,"ieee754":217}],36:[function(require,module,exports){ +'use strict'; - // Encode significand - // The high 17 digits of the significand - significandHigh = Long.fromNumber(0); - // The low 17 digits of the significand - significandLow = Long.fromNumber(0); +var GetIntrinsic = require('get-intrinsic'); - // read a zero - if (significantDigits === 0) { - significandHigh = Long.fromNumber(0); - significandLow = Long.fromNumber(0); - } else if (lastDigit - firstDigit < 17) { - dIdx = firstDigit; - significandLow = Long.fromNumber(digits[dIdx++]); - significandHigh = new Long(0, 0); +var callBind = require('./'); - for (; dIdx <= lastDigit; dIdx++) { - significandLow = significandLow.multiply(Long.fromNumber(10)); - significandLow = significandLow.add(Long.fromNumber(digits[dIdx])); - } - } else { - dIdx = firstDigit; - significandHigh = Long.fromNumber(digits[dIdx++]); +var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf')); - for (; dIdx <= lastDigit - 17; dIdx++) { - significandHigh = significandHigh.multiply(Long.fromNumber(10)); - significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx])); - } +module.exports = function callBoundIntrinsic(name, allowMissing) { + var intrinsic = GetIntrinsic(name, !!allowMissing); + if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) { + return callBind(intrinsic); + } + return intrinsic; +}; - significandLow = Long.fromNumber(digits[dIdx++]); +},{"./":37,"get-intrinsic":38}],37:[function(require,module,exports){ +'use strict'; - for (; dIdx <= lastDigit; dIdx++) { - significandLow = significandLow.multiply(Long.fromNumber(10)); - significandLow = significandLow.add(Long.fromNumber(digits[dIdx])); - } - } +var bind = require('function-bind'); +var GetIntrinsic = require('get-intrinsic'); - var significand = multiply64x2(significandHigh, Long.fromString('100000000000000000')); +var $apply = GetIntrinsic('%Function.prototype.apply%'); +var $call = GetIntrinsic('%Function.prototype.call%'); +var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); - significand.low = significand.low.add(significandLow); +var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true); +var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); +var $max = GetIntrinsic('%Math.max%'); - if (lessThan(significand.low, significandLow)) { - significand.high = significand.high.add(Long.fromNumber(1)); - } +if ($defineProperty) { + try { + $defineProperty({}, 'a', { value: 1 }); + } catch (e) { + // IE 8 has a broken defineProperty + $defineProperty = null; + } +} - // Biased exponent - biasedExponent = exponent + EXPONENT_BIAS; - var dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) }; +module.exports = function callBind(originalFunction) { + var func = $reflectApply(bind, $call, arguments); + if ($gOPD && $defineProperty) { + var desc = $gOPD(func, 'length'); + if (desc.configurable) { + // original length, plus the receiver, minus any additional arguments (after the receiver) + $defineProperty( + func, + 'length', + { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) } + ); + } + } + return func; +}; - // Encode combination, exponent, and significand. - if ( - significand.high - .shiftRightUnsigned(49) - .and(Long.fromNumber(1)) - .equals(Long.fromNumber) - ) { - // Encode '11' into bits 1 to 3 - dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61)); - dec.high = dec.high.or( - Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)) - ); - dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff))); - } else { - dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49)); - dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff))); - } +var applyBind = function applyBind() { + return $reflectApply(bind, $apply, arguments); +}; - dec.low = significand.low; +if ($defineProperty) { + $defineProperty(module.exports, 'apply', { value: applyBind }); +} else { + module.exports.apply = applyBind; +} - // Encode sign - if (isNegative) { - dec.high = dec.high.or(Long.fromString('9223372036854775808')); - } +},{"function-bind":201,"get-intrinsic":38}],38:[function(require,module,exports){ +'use strict'; - // Encode into a buffer - var buffer = utils.allocBuffer(16); - index = 0; +var undefined; - // Encode the low 64 bits of the decimal - // Encode low bits - buffer[index++] = dec.low.low_ & 0xff; - buffer[index++] = (dec.low.low_ >> 8) & 0xff; - buffer[index++] = (dec.low.low_ >> 16) & 0xff; - buffer[index++] = (dec.low.low_ >> 24) & 0xff; - // Encode high bits - buffer[index++] = dec.low.high_ & 0xff; - buffer[index++] = (dec.low.high_ >> 8) & 0xff; - buffer[index++] = (dec.low.high_ >> 16) & 0xff; - buffer[index++] = (dec.low.high_ >> 24) & 0xff; +var $SyntaxError = SyntaxError; +var $Function = Function; +var $TypeError = TypeError; - // Encode the high 64 bits of the decimal - // Encode low bits - buffer[index++] = dec.high.low_ & 0xff; - buffer[index++] = (dec.high.low_ >> 8) & 0xff; - buffer[index++] = (dec.high.low_ >> 16) & 0xff; - buffer[index++] = (dec.high.low_ >> 24) & 0xff; - // Encode high bits - buffer[index++] = dec.high.high_ & 0xff; - buffer[index++] = (dec.high.high_ >> 8) & 0xff; - buffer[index++] = (dec.high.high_ >> 16) & 0xff; - buffer[index++] = (dec.high.high_ >> 24) & 0xff; - - // Return the new Decimal128 - return new Decimal128(buffer); +// eslint-disable-next-line consistent-return +var getEvalledConstructor = function (expressionSyntax) { + try { + return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); + } catch (e) {} }; -// Extract least significant 5 bits -var COMBINATION_MASK = 0x1f; -// Extract least significant 14 bits -var EXPONENT_MASK = 0x3fff; -// Value of combination field for Inf -var COMBINATION_INFINITY = 30; -// Value of combination field for NaN -var COMBINATION_NAN = 31; -// Value of combination field for NaN -// var COMBINATION_SNAN = 32; -// decimal128 exponent bias -EXPONENT_BIAS = 6176; - -/** - * Create a string representation of the raw Decimal128 value - * - * @method - * @return {string} returns a Decimal128 string representation. - */ -Decimal128.prototype.toString = function() { - // Note: bits in this routine are referred to starting at 0, - // from the sign bit, towards the coefficient. - - // bits 0 - 31 - var high; - // bits 32 - 63 - var midh; - // bits 64 - 95 - var midl; - // bits 96 - 127 - var low; - // bits 1 - 5 - var combination; - // decoded biased exponent (14 bits) - var biased_exponent; - // the number of significand digits - var significand_digits = 0; - // the base-10 digits in the significand - var significand = new Array(36); - for (var i = 0; i < significand.length; i++) significand[i] = 0; - // read pointer into significand - var index = 0; - - // unbiased exponent - var exponent; - // the exponent if scientific notation is used - var scientific_exponent; +var $gOPD = Object.getOwnPropertyDescriptor; +if ($gOPD) { + try { + $gOPD({}, ''); + } catch (e) { + $gOPD = null; // this is IE 8, which has a broken gOPD + } +} - // true if the number is zero - var is_zero = false; +var throwTypeError = function () { + throw new $TypeError(); +}; +var ThrowTypeError = $gOPD + ? (function () { + try { + // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties + arguments.callee; // IE 8 does not throw here + return throwTypeError; + } catch (calleeThrows) { + try { + // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') + return $gOPD(arguments, 'callee').get; + } catch (gOPDthrows) { + return throwTypeError; + } + } + }()) + : throwTypeError; - // the most signifcant significand bits (50-46) - var significand_msb; - // temporary storage for significand decoding - var significand128 = { parts: new Array(4) }; - // indexing variables - i; - var j, k; +var hasSymbols = require('has-symbols')(); - // Output string - var string = []; +var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto - // Unpack index - index = 0; +var needsEval = {}; - // Buffer reference - var buffer = this.bytes; +var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array); - // Unpack the low 64bits into a long - low = - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); - midl = - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); +var INTRINSICS = { + '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, + '%Array%': Array, + '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, + '%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined, + '%AsyncFromSyncIteratorPrototype%': undefined, + '%AsyncFunction%': needsEval, + '%AsyncGenerator%': needsEval, + '%AsyncGeneratorFunction%': needsEval, + '%AsyncIteratorPrototype%': needsEval, + '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, + '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, + '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array, + '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array, + '%Boolean%': Boolean, + '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, + '%Date%': Date, + '%decodeURI%': decodeURI, + '%decodeURIComponent%': decodeURIComponent, + '%encodeURI%': encodeURI, + '%encodeURIComponent%': encodeURIComponent, + '%Error%': Error, + '%eval%': eval, // eslint-disable-line no-eval + '%EvalError%': EvalError, + '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, + '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, + '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, + '%Function%': $Function, + '%GeneratorFunction%': needsEval, + '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, + '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, + '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, + '%isFinite%': isFinite, + '%isNaN%': isNaN, + '%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined, + '%JSON%': typeof JSON === 'object' ? JSON : undefined, + '%Map%': typeof Map === 'undefined' ? undefined : Map, + '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()), + '%Math%': Math, + '%Number%': Number, + '%Object%': Object, + '%parseFloat%': parseFloat, + '%parseInt%': parseInt, + '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, + '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, + '%RangeError%': RangeError, + '%ReferenceError%': ReferenceError, + '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, + '%RegExp%': RegExp, + '%Set%': typeof Set === 'undefined' ? undefined : Set, + '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()), + '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, + '%String%': String, + '%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined, + '%Symbol%': hasSymbols ? Symbol : undefined, + '%SyntaxError%': $SyntaxError, + '%ThrowTypeError%': ThrowTypeError, + '%TypedArray%': TypedArray, + '%TypeError%': $TypeError, + '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, + '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, + '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, + '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, + '%URIError%': URIError, + '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, + '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, + '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet +}; - // Unpack the high 64bits into a long - midh = - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); - high = - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); +try { + null.error; // eslint-disable-line no-unused-expressions +} catch (e) { + // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 + var errorProto = getProto(getProto(e)); + INTRINSICS['%Error.prototype%'] = errorProto; +} - // Unpack index - index = 0; +var doEval = function doEval(name) { + var value; + if (name === '%AsyncFunction%') { + value = getEvalledConstructor('async function () {}'); + } else if (name === '%GeneratorFunction%') { + value = getEvalledConstructor('function* () {}'); + } else if (name === '%AsyncGeneratorFunction%') { + value = getEvalledConstructor('async function* () {}'); + } else if (name === '%AsyncGenerator%') { + var fn = doEval('%AsyncGeneratorFunction%'); + if (fn) { + value = fn.prototype; + } + } else if (name === '%AsyncIteratorPrototype%') { + var gen = doEval('%AsyncGenerator%'); + if (gen) { + value = getProto(gen.prototype); + } + } - // Create the state of the decimal - var dec = { - low: new Long(low, midl), - high: new Long(midh, high) - }; + INTRINSICS[name] = value; - if (dec.high.lessThan(Long.ZERO)) { - string.push('-'); - } + return value; +}; - // Decode combination field and exponent - combination = (high >> 26) & COMBINATION_MASK; +var LEGACY_ALIASES = { + '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], + '%ArrayPrototype%': ['Array', 'prototype'], + '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], + '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], + '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], + '%ArrayProto_values%': ['Array', 'prototype', 'values'], + '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], + '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], + '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], + '%BooleanPrototype%': ['Boolean', 'prototype'], + '%DataViewPrototype%': ['DataView', 'prototype'], + '%DatePrototype%': ['Date', 'prototype'], + '%ErrorPrototype%': ['Error', 'prototype'], + '%EvalErrorPrototype%': ['EvalError', 'prototype'], + '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], + '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], + '%FunctionPrototype%': ['Function', 'prototype'], + '%Generator%': ['GeneratorFunction', 'prototype'], + '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], + '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], + '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], + '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], + '%JSONParse%': ['JSON', 'parse'], + '%JSONStringify%': ['JSON', 'stringify'], + '%MapPrototype%': ['Map', 'prototype'], + '%NumberPrototype%': ['Number', 'prototype'], + '%ObjectPrototype%': ['Object', 'prototype'], + '%ObjProto_toString%': ['Object', 'prototype', 'toString'], + '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], + '%PromisePrototype%': ['Promise', 'prototype'], + '%PromiseProto_then%': ['Promise', 'prototype', 'then'], + '%Promise_all%': ['Promise', 'all'], + '%Promise_reject%': ['Promise', 'reject'], + '%Promise_resolve%': ['Promise', 'resolve'], + '%RangeErrorPrototype%': ['RangeError', 'prototype'], + '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], + '%RegExpPrototype%': ['RegExp', 'prototype'], + '%SetPrototype%': ['Set', 'prototype'], + '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], + '%StringPrototype%': ['String', 'prototype'], + '%SymbolPrototype%': ['Symbol', 'prototype'], + '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], + '%TypedArrayPrototype%': ['TypedArray', 'prototype'], + '%TypeErrorPrototype%': ['TypeError', 'prototype'], + '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], + '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], + '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], + '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], + '%URIErrorPrototype%': ['URIError', 'prototype'], + '%WeakMapPrototype%': ['WeakMap', 'prototype'], + '%WeakSetPrototype%': ['WeakSet', 'prototype'] +}; - if (combination >> 3 === 3) { - // Check for 'special' values - if (combination === COMBINATION_INFINITY) { - return string.join('') + 'Infinity'; - } else if (combination === COMBINATION_NAN) { - return 'NaN'; - } else { - biased_exponent = (high >> 15) & EXPONENT_MASK; - significand_msb = 0x08 + ((high >> 14) & 0x01); - } - } else { - significand_msb = (high >> 14) & 0x07; - biased_exponent = (high >> 17) & EXPONENT_MASK; - } +var bind = require('function-bind'); +var hasOwn = require('has'); +var $concat = bind.call(Function.call, Array.prototype.concat); +var $spliceApply = bind.call(Function.apply, Array.prototype.splice); +var $replace = bind.call(Function.call, String.prototype.replace); +var $strSlice = bind.call(Function.call, String.prototype.slice); +var $exec = bind.call(Function.call, RegExp.prototype.exec); - exponent = biased_exponent - EXPONENT_BIAS; +/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ +var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; +var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ +var stringToPath = function stringToPath(string) { + var first = $strSlice(string, 0, 1); + var last = $strSlice(string, -1); + if (first === '%' && last !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); + } else if (last === '%' && first !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); + } + var result = []; + $replace(string, rePropName, function (match, number, quote, subString) { + result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; + }); + return result; +}; +/* end adaptation */ - // Create string of significand digits +var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { + var intrinsicName = name; + var alias; + if (hasOwn(LEGACY_ALIASES, intrinsicName)) { + alias = LEGACY_ALIASES[intrinsicName]; + intrinsicName = '%' + alias[0] + '%'; + } - // Convert the 114-bit binary number represented by - // (significand_high, significand_low) to at most 34 decimal - // digits through modulo and division. - significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14); - significand128.parts[1] = midh; - significand128.parts[2] = midl; - significand128.parts[3] = low; + if (hasOwn(INTRINSICS, intrinsicName)) { + var value = INTRINSICS[intrinsicName]; + if (value === needsEval) { + value = doEval(intrinsicName); + } + if (typeof value === 'undefined' && !allowMissing) { + throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); + } - if ( - significand128.parts[0] === 0 && - significand128.parts[1] === 0 && - significand128.parts[2] === 0 && - significand128.parts[3] === 0 - ) { - is_zero = true; - } else { - for (k = 3; k >= 0; k--) { - var least_digits = 0; - // Peform the divide - var result = divideu128(significand128); - significand128 = result.quotient; - least_digits = result.rem.low_; + return { + alias: alias, + name: intrinsicName, + value: value + }; + } - // We now have the 9 least significant digits (in base 2). - // Convert and output to string. - if (!least_digits) continue; + throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); +}; - for (j = 8; j >= 0; j--) { - // significand[k * 9 + j] = Math.round(least_digits % 10); - significand[k * 9 + j] = least_digits % 10; - // least_digits = Math.round(least_digits / 10); - least_digits = Math.floor(least_digits / 10); - } - } - } +module.exports = function GetIntrinsic(name, allowMissing) { + if (typeof name !== 'string' || name.length === 0) { + throw new $TypeError('intrinsic name must be a non-empty string'); + } + if (arguments.length > 1 && typeof allowMissing !== 'boolean') { + throw new $TypeError('"allowMissing" argument must be a boolean'); + } - // Output format options: - // Scientific - [-]d.dddE(+/-)dd or [-]dE(+/-)dd - // Regular - ddd.ddd + if ($exec(/^%?[^%]*%?$/, name) === null) { + throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name'); + } + var parts = stringToPath(name); + var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; - if (is_zero) { - significand_digits = 1; - significand[index] = 0; - } else { - significand_digits = 36; - i = 0; + var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); + var intrinsicRealName = intrinsic.name; + var value = intrinsic.value; + var skipFurtherCaching = false; - while (!significand[index]) { - i++; - significand_digits = significand_digits - 1; - index = index + 1; - } - } + var alias = intrinsic.alias; + if (alias) { + intrinsicBaseName = alias[0]; + $spliceApply(parts, $concat([0, 1], alias)); + } - scientific_exponent = significand_digits - 1 + exponent; + for (var i = 1, isOwn = true; i < parts.length; i += 1) { + var part = parts[i]; + var first = $strSlice(part, 0, 1); + var last = $strSlice(part, -1); + if ( + ( + (first === '"' || first === "'" || first === '`') + || (last === '"' || last === "'" || last === '`') + ) + && first !== last + ) { + throw new $SyntaxError('property names with quotes must have matching quotes'); + } + if (part === 'constructor' || !isOwn) { + skipFurtherCaching = true; + } - // The scientific exponent checks are dictated by the string conversion - // specification and are somewhat arbitrary cutoffs. - // - // We must check exponent > 0, because if this is the case, the number - // has trailing zeros. However, we *cannot* output these trailing zeros, - // because doing so would change the precision of the value, and would - // change stored data if the string converted number is round tripped. + intrinsicBaseName += '.' + part; + intrinsicRealName = '%' + intrinsicBaseName + '%'; - if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) { - // Scientific format - string.push(significand[index++]); - significand_digits = significand_digits - 1; + if (hasOwn(INTRINSICS, intrinsicRealName)) { + value = INTRINSICS[intrinsicRealName]; + } else if (value != null) { + if (!(part in value)) { + if (!allowMissing) { + throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.'); + } + return void undefined; + } + if ($gOPD && (i + 1) >= parts.length) { + var desc = $gOPD(value, part); + isOwn = !!desc; - if (significand_digits) { - string.push('.'); - } + // By convention, when a data property is converted to an accessor + // property to emulate a data property that does not suffer from + // the override mistake, that accessor's getter is marked with + // an `originalValue` property. Here, when we detect this, we + // uphold the illusion by pretending to see that original data + // property, i.e., returning the value rather than the getter + // itself. + if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { + value = desc.get; + } else { + value = value[part]; + } + } else { + isOwn = hasOwn(value, part); + value = value[part]; + } - for (i = 0; i < significand_digits; i++) { - string.push(significand[index++]); - } + if (isOwn && !skipFurtherCaching) { + INTRINSICS[intrinsicRealName] = value; + } + } + } + return value; +}; - // Exponent - string.push('E'); - if (scientific_exponent > 0) { - string.push('+' + scientific_exponent); - } else { - string.push(scientific_exponent); +},{"function-bind":201,"has":213,"has-symbols":210}],39:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CodeService = void 0; +var datatypes_1 = require("./datatypes/datatypes"); +var CodeService = /** @class */ (function () { + function CodeService(valueSetsJson) { + if (valueSetsJson === void 0) { valueSetsJson = {}; } + this.valueSets = {}; + for (var oid in valueSetsJson) { + this.valueSets[oid] = {}; + for (var version in valueSetsJson[oid]) { + var codes = valueSetsJson[oid][version].map(function (code) { return new datatypes_1.Code(code.code, code.system, code.version); }); + this.valueSets[oid][version] = new datatypes_1.ValueSet(oid, version, codes); + } + } } - } else { - // Regular format with no decimal place - if (exponent >= 0) { - for (i = 0; i < significand_digits; i++) { - string.push(significand[index++]); - } - } else { - var radix_position = significand_digits + exponent; - - // non-zero digits before radix - if (radix_position > 0) { - for (i = 0; i < radix_position; i++) { - string.push(significand[index++]); + CodeService.prototype.findValueSetsByOid = function (oid) { + return this.valueSets[oid] ? Object.values(this.valueSets[oid]) : []; + }; + CodeService.prototype.findValueSet = function (oid, version) { + if (version != null) { + return this.valueSets[oid] != null ? this.valueSets[oid][version] : null; } - } else { - string.push('0'); - } - - string.push('.'); - // add leading zeros after radix - while (radix_position++ < 0) { - string.push('0'); - } + else { + var results = this.findValueSetsByOid(oid); + if (results.length === 0) { + return null; + } + else { + return results.reduce(function (a, b) { + if (a.version > b.version) { + return a; + } + else { + return b; + } + }); + } + } + }; + return CodeService; +}()); +exports.CodeService = CodeService; - for (i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) { - string.push(significand[index++]); - } +},{"./datatypes/datatypes":43}],40:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PatientSource = exports.Patient = exports.Record = void 0; +var DT = __importStar(require("./datatypes/datatypes")); +var Record = /** @class */ (function () { + function Record(json) { + this.json = json; + this.id = this.json.id; } - } + Record.prototype._is = function (typeSpecifier) { + return this._typeHierarchy().some(function (t) { return t.type === typeSpecifier.type && t.name == typeSpecifier.name; }); + }; + Record.prototype._typeHierarchy = function () { + return [ + { + name: "{https://github.com/cqframework/cql-execution/simple}".concat(this.json.recordType), + type: 'NamedTypeSpecifier' + }, + { + name: '{https://github.com/cqframework/cql-execution/simple}Record', + type: 'NamedTypeSpecifier' + }, + { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' } + ]; + }; + Record.prototype._recursiveGet = function (field) { + if (field != null && field.indexOf('.') >= 0) { + var _a = field.split('.', 2), root = _a[0], rest = _a[1]; + return new Record(this._recursiveGet(root))._recursiveGet(rest); + } + return this.json[field]; + }; + Record.prototype.get = function (field) { + // the model should return the correct type for the field. For this simple model example, + // we just cheat and use the shape of the value to determine it. Real implementations should + // have a more sophisticated approach + var value = this._recursiveGet(field); + if (typeof value === 'string' && /\d{4}-\d{2}-\d{2}(T[\d\-.]+)?/.test(value)) { + return this.getDate(field); + } + if (value != null && typeof value === 'object' && value.code != null && value.system != null) { + return this.getCode(field); + } + if (value != null && typeof value === 'object' && (value.low != null || value.high != null)) { + return this.getInterval(field); + } + return value; + }; + Record.prototype.getId = function () { + return this.id; + }; + Record.prototype.getDate = function (field) { + var val = this._recursiveGet(field); + if (val != null) { + return DT.DateTime.parse(val); + } + else { + return null; + } + }; + Record.prototype.getInterval = function (field) { + var val = this._recursiveGet(field); + if (val != null && typeof val === 'object') { + var low = val.low != null ? DT.DateTime.parse(val.low) : null; + var high = val.high != null ? DT.DateTime.parse(val.high) : null; + return new DT.Interval(low, high); + } + }; + Record.prototype.getDateOrInterval = function (field) { + var val = this._recursiveGet(field); + if (val != null && typeof val === 'object') { + return this.getInterval(field); + } + else { + return this.getDate(field); + } + }; + Record.prototype.getCode = function (field) { + var val = this._recursiveGet(field); + if (val != null && typeof val === 'object') { + return new DT.Code(val.code, val.system, val.version); + } + }; + return Record; +}()); +exports.Record = Record; +var Patient = /** @class */ (function (_super) { + __extends(Patient, _super); + function Patient(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.gender = json.gender; + _this.birthDate = json.birthDate != null ? DT.DateTime.parse(json.birthDate) : undefined; + _this.records = {}; + (json.records || []).forEach(function (r) { + if (_this.records[r.recordType] == null) { + _this.records[r.recordType] = []; + } + _this.records[r.recordType].push(new Record(r)); + }); + return _this; + } + Patient.prototype.findRecords = function (profile) { + if (profile == null) { + return []; + } + var match = profile.match(/(\{https:\/\/github\.com\/cqframework\/cql-execution\/simple\})?(.*)/); + if (match == null) + return []; + var recordType = match[2]; + if (recordType === 'Patient') { + return [this]; + } + else { + return this.records[recordType] || []; + } + }; + return Patient; +}(Record)); +exports.Patient = Patient; +var PatientSource = /** @class */ (function () { + function PatientSource(patients) { + this.patients = patients; + this.nextPatient(); + } + PatientSource.prototype.currentPatient = function () { + return this.current; + }; + PatientSource.prototype.nextPatient = function () { + var currentJSON = this.patients.shift(); + this.current = currentJSON ? new Patient(currentJSON) : undefined; + return this.current; + }; + return PatientSource; +}()); +exports.PatientSource = PatientSource; - return string.join(''); +},{"./datatypes/datatypes":43}],41:[function(require,module,exports){ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; - -Decimal128.prototype.toJSON = function() { - return { $numberDecimal: this.toString() }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ValueSet = exports.Ratio = exports.Quantity = exports.Interval = exports.DateTime = exports.Date = exports.Concept = exports.CodeSystem = exports.Code = exports.CodeService = exports.PatientSource = exports.Patient = exports.NullMessageListener = exports.ConsoleMessageListener = exports.Results = exports.Executor = exports.UnfilteredContext = exports.PatientContext = exports.Context = exports.Expression = exports.Repository = exports.Library = void 0; +// Library-related classes +var library_1 = require("./elm/library"); +Object.defineProperty(exports, "Library", { enumerable: true, get: function () { return library_1.Library; } }); +var repository_1 = require("./runtime/repository"); +Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } }); +var expression_1 = require("./elm/expression"); +Object.defineProperty(exports, "Expression", { enumerable: true, get: function () { return expression_1.Expression; } }); +// Execution-related classes +var context_1 = require("./runtime/context"); +Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } }); +Object.defineProperty(exports, "PatientContext", { enumerable: true, get: function () { return context_1.PatientContext; } }); +Object.defineProperty(exports, "UnfilteredContext", { enumerable: true, get: function () { return context_1.UnfilteredContext; } }); +var executor_1 = require("./runtime/executor"); +Object.defineProperty(exports, "Executor", { enumerable: true, get: function () { return executor_1.Executor; } }); +var results_1 = require("./runtime/results"); +Object.defineProperty(exports, "Results", { enumerable: true, get: function () { return results_1.Results; } }); +var messageListeners_1 = require("./runtime/messageListeners"); +Object.defineProperty(exports, "ConsoleMessageListener", { enumerable: true, get: function () { return messageListeners_1.ConsoleMessageListener; } }); +Object.defineProperty(exports, "NullMessageListener", { enumerable: true, get: function () { return messageListeners_1.NullMessageListener; } }); +// PatientSource-related classes +var cql_patient_1 = require("./cql-patient"); +Object.defineProperty(exports, "Patient", { enumerable: true, get: function () { return cql_patient_1.Patient; } }); +Object.defineProperty(exports, "PatientSource", { enumerable: true, get: function () { return cql_patient_1.PatientSource; } }); +// TerminologyService-related classes +var cql_code_service_1 = require("./cql-code-service"); +Object.defineProperty(exports, "CodeService", { enumerable: true, get: function () { return cql_code_service_1.CodeService; } }); +// DataType classes +var datatypes_1 = require("./datatypes/datatypes"); +Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return datatypes_1.Code; } }); +Object.defineProperty(exports, "CodeSystem", { enumerable: true, get: function () { return datatypes_1.CodeSystem; } }); +Object.defineProperty(exports, "Concept", { enumerable: true, get: function () { return datatypes_1.Concept; } }); +Object.defineProperty(exports, "Date", { enumerable: true, get: function () { return datatypes_1.Date; } }); +Object.defineProperty(exports, "DateTime", { enumerable: true, get: function () { return datatypes_1.DateTime; } }); +Object.defineProperty(exports, "Interval", { enumerable: true, get: function () { return datatypes_1.Interval; } }); +Object.defineProperty(exports, "Quantity", { enumerable: true, get: function () { return datatypes_1.Quantity; } }); +Object.defineProperty(exports, "Ratio", { enumerable: true, get: function () { return datatypes_1.Ratio; } }); +Object.defineProperty(exports, "ValueSet", { enumerable: true, get: function () { return datatypes_1.ValueSet; } }); +// Custom Types +__exportStar(require("./types"), exports); +exports.default = { + Library: library_1.Library, + Repository: repository_1.Repository, + Expression: expression_1.Expression, + Context: context_1.Context, + PatientContext: context_1.PatientContext, + UnfilteredContext: context_1.UnfilteredContext, + Executor: executor_1.Executor, + Results: results_1.Results, + ConsoleMessageListener: messageListeners_1.ConsoleMessageListener, + NullMessageListener: messageListeners_1.NullMessageListener, + Patient: cql_patient_1.Patient, + PatientSource: cql_patient_1.PatientSource, + CodeService: cql_code_service_1.CodeService, + Code: datatypes_1.Code, + CodeSystem: datatypes_1.CodeSystem, + Concept: datatypes_1.Concept, + Date: datatypes_1.Date, + DateTime: datatypes_1.DateTime, + Interval: datatypes_1.Interval, + Quantity: datatypes_1.Quantity, + Ratio: datatypes_1.Ratio, + ValueSet: datatypes_1.ValueSet }; -module.exports = Decimal128; -module.exports.Decimal128 = Decimal128; - -},{"./long":37,"./parser/utils":45}],34:[function(require,module,exports){ -/** - * A class representation of the BSON Double type. - * - * @class - * @param {number} value the number we want to represent as a double. - * @return {Double} - */ -function Double(value) { - if (!(this instanceof Double)) return new Double(value); - - this._bsontype = 'Double'; - this.value = value; +},{"./cql-code-service":39,"./cql-patient":40,"./datatypes/datatypes":43,"./elm/expression":59,"./elm/library":64,"./runtime/context":79,"./runtime/executor":80,"./runtime/messageListeners":81,"./runtime/repository":82,"./runtime/results":83,"./types":86}],42:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CodeSystem = exports.ValueSet = exports.Concept = exports.Code = void 0; +var util_1 = require("../util/util"); +var Code = /** @class */ (function () { + function Code(code, system, version, display) { + this.code = code; + this.system = system; + this.version = version; + this.display = display; + } + Object.defineProperty(Code.prototype, "isCode", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Code.prototype.hasMatch = function (code) { + if (typeof code === 'string') { + // the specific behavior for this is not in the specification. Matching codesystem behavior. + return code === this.code; + } + else { + return codesInList(toCodeList(code), [this]); + } + }; + return Code; +}()); +exports.Code = Code; +var Concept = /** @class */ (function () { + function Concept(codes, display) { + this.codes = codes; + this.display = display; + this.codes || (this.codes = []); + } + Object.defineProperty(Concept.prototype, "isConcept", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Concept.prototype.hasMatch = function (code) { + return codesInList(toCodeList(code), this.codes); + }; + return Concept; +}()); +exports.Concept = Concept; +var ValueSet = /** @class */ (function () { + function ValueSet(oid, version, codes) { + if (codes === void 0) { codes = []; } + this.oid = oid; + this.version = version; + this.codes = codes; + this.codes || (this.codes = []); + } + Object.defineProperty(ValueSet.prototype, "isValueSet", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + ValueSet.prototype.hasMatch = function (code) { + var codesList = toCodeList(code); + // InValueSet String Overload + if (codesList.length === 1 && typeof codesList[0] === 'string') { + var matchFound = false; + var multipleCodeSystemsExist = false; + for (var _i = 0, _a = this.codes; _i < _a.length; _i++) { + var codeItem = _a[_i]; + // Confirm all code systems match + if (codeItem.system !== this.codes[0].system) { + multipleCodeSystemsExist = true; + } + if (codeItem.code === codesList[0]) { + matchFound = true; + } + if (multipleCodeSystemsExist && matchFound) { + throw new Error('In (valueset) is ambiguous -- multiple codes with multiple code systems exist in value set.'); + } + } + return matchFound; + } + else { + return codesInList(codesList, this.codes); + } + }; + return ValueSet; +}()); +exports.ValueSet = ValueSet; +function toCodeList(c) { + if (c == null) { + return []; + } + else if ((0, util_1.typeIsArray)(c)) { + var list = []; + for (var _i = 0, c_1 = c; _i < c_1.length; _i++) { + var c2 = c_1[_i]; + list = list.concat(toCodeList(c2)); + } + return list; + } + else if ((0, util_1.typeIsArray)(c.codes)) { + return c.codes; + } + else { + return [c]; + } +} +function codesInList(cl1, cl2) { + // test each code in c1 against each code in c2 looking for a match + return cl1.some(function (c1) { + return cl2.some(function (c2) { + // only the left argument (cl1) can contain strings. cl2 will only contain codes. + if (typeof c1 === 'string') { + // for "string in codesystem" this should compare the string to + // the code's "code" field according to the specification. + return c1 === c2.code; + } + else { + return codesMatch(c1, c2); + } + }); + }); +} +function codesMatch(code1, code2) { + return code1.code === code2.code && code1.system === code2.system; } +var CodeSystem = /** @class */ (function () { + function CodeSystem(id, version) { + this.id = id; + this.version = version; + } + return CodeSystem; +}()); +exports.CodeSystem = CodeSystem; -/** - * Access the number value. - * - * @method - * @return {number} returns the wrapped double number. - */ -Double.prototype.valueOf = function() { - return this.value; +},{"../util/util":92}],43:[function(require,module,exports){ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./logic"), exports); +__exportStar(require("./clinical"), exports); +__exportStar(require("./uncertainty"), exports); +__exportStar(require("./datetime"), exports); +__exportStar(require("./interval"), exports); +__exportStar(require("./quantity"), exports); +__exportStar(require("./ratio"), exports); -/** - * @ignore - */ -Double.prototype.toJSON = function() { - return this.value; +},{"./clinical":42,"./datetime":44,"./interval":46,"./logic":47,"./quantity":48,"./ratio":49,"./uncertainty":50}],44:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); }; - -module.exports = Double; -module.exports.Double = Double; - -},{}],35:[function(require,module,exports){ -// Copyright (c) 2008, Fair Oaks Labs, Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// -// Modifications to writeIEEE754 to support negative zeroes made by Brian White - -var readIEEE754 = function(buffer, offset, endian, mLen, nBytes) { - var e, - m, - bBE = endian === 'big', - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - nBits = -7, - i = bBE ? 0 : nBytes - 1, - d = bBE ? 1 : -1, - s = buffer[offset + i]; - - i += d; - - e = s & ((1 << -nBits) - 1); - s >>= -nBits; - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); - - m = e & ((1 << -nBits) - 1); - e >>= -nBits; - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); - - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : (s ? -1 : 1) * Infinity; - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen); -}; - -var writeIEEE754 = function(buffer, value, offset, endian, mLen, nBytes) { - var e, - m, - c, - bBE = endian === 'big', - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, - i = bBE ? nBytes - 1 : 0, - d = bBE ? -1 : 1, - s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; - - value = Math.abs(value); - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; - } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; - } - - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; - } - } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); - - e = (e << mLen) | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); - - buffer[offset + i - d] |= s * 128; -}; - -exports.readIEEE754 = readIEEE754; -exports.writeIEEE754 = writeIEEE754; - -},{}],36:[function(require,module,exports){ -/** - * A class representation of a BSON Int32 type. - * - * @class - * @param {number} value the number we want to represent as an int32. - * @return {Int32} - */ -var Int32 = function(value) { - if (!(this instanceof Int32)) return new Int32(value); - - this._bsontype = 'Int32'; - this.value = value; -}; - -/** - * Access the number value. - * - * @method - * @return {number} returns the wrapped int32 number. - */ -Int32.prototype.valueOf = function() { - return this.value; -}; - -/** - * @ignore - */ -Int32.prototype.toJSON = function() { - return this.value; -}; - -module.exports = Int32; -module.exports.Int32 = Int32; - -},{}],37:[function(require,module,exports){ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright 2009 Google Inc. All Rights Reserved - -/** - * Defines a Long class for representing a 64-bit two's-complement - * integer value, which faithfully simulates the behavior of a Java "Long". This - * implementation is derived from LongLib in GWT. - * - * Constructs a 64-bit two's-complement integer, given its low and high 32-bit - * values as *signed* integers. See the from* functions below for more - * convenient ways of constructing Longs. - * - * The internal representation of a Long is the two given signed, 32-bit values. - * We use 32-bit pieces because these are the size of integers on which - * Javascript performs bit-operations. For operations like addition and - * multiplication, we split each number into 16-bit pieces, which can easily be - * multiplied within Javascript's floating-point representation without overflow - * or change in sign. - * - * In the algorithms below, we frequently reduce the negative case to the - * positive case by negating the input(s) and then post-processing the result. - * Note that we must ALWAYS check specially whether those values are MIN_VALUE - * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as - * a positive number, it overflows back into a negative). Not handling this - * case would often result in infinite recursion. - * - * @class - * @param {number} low the low (signed) 32 bits of the Long. - * @param {number} high the high (signed) 32 bits of the Long. - * @return {Long} - */ -function Long(low, high) { - if (!(this instanceof Long)) return new Long(low, high); - - this._bsontype = 'Long'; - /** - * @type {number} - * @ignore - */ - this.low_ = low | 0; // force into 32 signed bits. - - /** - * @type {number} - * @ignore - */ - this.high_ = high | 0; // force into 32 signed bits. -} - -/** - * Return the int value. - * - * @method - * @return {number} the value, assuming it is a 32-bit integer. - */ -Long.prototype.toInt = function() { - return this.low_; -}; - -/** - * Return the Number value. - * - * @method - * @return {number} the closest floating-point representation to this value. - */ -Long.prototype.toNumber = function() { - return this.high_ * Long.TWO_PWR_32_DBL_ + this.getLowBitsUnsigned(); -}; - -/** Converts the Long to a BigInt (arbitrary precision). */ -Long.prototype.toBigInt = function () { - return BigInt(this.toString()); +var _a, _b; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MAX_TIME_VALUE = exports.MIN_TIME_VALUE = exports.MAX_DATE_VALUE = exports.MIN_DATE_VALUE = exports.MAX_DATETIME_VALUE = exports.MIN_DATETIME_VALUE = exports.Date = exports.DateTime = void 0; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var uncertainty_1 = require("./uncertainty"); +var util_1 = require("../util/util"); +var luxon_1 = require("luxon"); +// It's easiest and most performant to organize formats by length of the supported strings. +// This way we can test strings only against the formats that have a chance of working. +// NOTE: Formats use Luxon formats, documented here: https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens +var LENGTH_TO_DATE_FORMAT_MAP = (function () { + var ltdfMap = new Map(); + ltdfMap.set(4, 'yyyy'); + ltdfMap.set(7, 'yyyy-MM'); + ltdfMap.set(10, 'yyyy-MM-dd'); + return ltdfMap; +})(); +var LENGTH_TO_DATETIME_FORMATS_MAP = (function () { + var formats = { + yyyy: '2012', + 'yyyy-MM': '2012-01', + 'yyyy-MM-dd': '2012-01-31', + "yyyy-MM-dd'T''Z'": '2012-01-31TZ', + "yyyy-MM-dd'T'ZZ": '2012-01-31T-04:00', + "yyyy-MM-dd'T'HH": '2012-01-31T12', + "yyyy-MM-dd'T'HH'Z'": '2012-01-31T12Z', + "yyyy-MM-dd'T'HHZZ": '2012-01-31T12-04:00', + "yyyy-MM-dd'T'HH:mm": '2012-01-31T12:30', + "yyyy-MM-dd'T'HH:mm'Z'": '2012-01-31T12:30Z', + "yyyy-MM-dd'T'HH:mmZZ": '2012-01-31T12:30-04:00', + "yyyy-MM-dd'T'HH:mm:ss": '2012-01-31T12:30:59', + "yyyy-MM-dd'T'HH:mm:ss'Z'": '2012-01-31T12:30:59Z', + "yyyy-MM-dd'T'HH:mm:ssZZ": '2012-01-31T12:30:59-04:00', + "yyyy-MM-dd'T'HH:mm:ss.SSS": '2012-01-31T12:30:59.000', + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'": '2012-01-31T12:30:59.000Z', + "yyyy-MM-dd'T'HH:mm:ss.SSSZZ": '2012-01-31T12:30:59.000-04:00' + }; + var ltdtfMap = new Map(); + Object.keys(formats).forEach(function (k) { + var example = formats[k]; + if (!ltdtfMap.has(example.length)) { + ltdtfMap.set(example.length, [k]); + } + else { + ltdtfMap.get(example.length).push(k); + } + }); + return ltdtfMap; +})(); +function wholeLuxonDuration(duration, unit) { + var value = duration.get(unit); + return value >= 0 ? Math.floor(value) : Math.ceil(value); } - -/** - * Return the JSON value. - * - * @method - * @return {string} the JSON representation. - */ -Long.prototype.toJSON = function() { - return this.toString(); -}; - -/** - * Return the String value. - * - * @method - * @param {number} [opt_radix] the radix in which the text should be written. - * @return {string} the textual representation of this value. - */ -Long.prototype.toString = function(opt_radix) { - var radix = opt_radix || 10; - if (radix < 2 || 36 < radix) { - throw Error('radix out of range: ' + radix); - } - - if (this.isZero()) { - return '0'; - } - - if (this.isNegative()) { - if (this.equals(Long.MIN_VALUE)) { - // We need to change the Long value before it can be negated, so we remove - // the bottom-most digit in this base and then recurse to do the rest. - var radixLong = Long.fromNumber(radix); - var div = this.div(radixLong); - var rem = div.multiply(radixLong).subtract(this); - return div.toString(radix) + rem.toInt().toString(radix); - } else { - return '-' + this.negate().toString(radix); - } - } - - // Do several (6) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = Long.fromNumber(Math.pow(radix, 6)); - - rem = this; - var result = ''; - - while (!rem.isZero()) { - var remDiv = rem.div(radixToPower); - var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); - var digits = intval.toString(radix); - - rem = remDiv; - if (rem.isZero()) { - return digits + result; - } else { - while (digits.length < 6) { - digits = '0' + digits; - } - result = '' + digits + result; +function truncateLuxonDateTime(luxonDT, unit) { + // Truncating by week (to the previous Sunday) requires different logic than the rest + if (unit === DateTime.Unit.WEEK) { + // Sunday is ISO weekday 7 + if (luxonDT.weekday !== 7) { + luxonDT = luxonDT.set({ weekday: 7 }).minus({ weeks: 1 }); + } + unit = DateTime.Unit.DAY; } - } -}; - -/** - * Return the high 32-bits value. - * - * @method - * @return {number} the high 32-bits as a signed value. - */ -Long.prototype.getHighBits = function() { - return this.high_; -}; - -/** - * Return the low 32-bits value. - * - * @method - * @return {number} the low 32-bits as a signed value. - */ -Long.prototype.getLowBits = function() { - return this.low_; -}; - -/** - * Return the low unsigned 32-bits value. - * - * @method - * @return {number} the low 32-bits as an unsigned value. - */ -Long.prototype.getLowBitsUnsigned = function() { - return this.low_ >= 0 ? this.low_ : Long.TWO_PWR_32_DBL_ + this.low_; -}; - -/** - * Returns the number of bits needed to represent the absolute value of this Long. - * - * @method - * @return {number} Returns the number of bits needed to represent the absolute value of this Long. + return luxonDT.startOf(unit); +} +/* + * Base class for Date and DateTime to extend from + * Implements shared functions by both classes + * TODO: we can probably iterate on this more to improve the accessing of "FIELDS" and the overall structure + * TODO: we can also investigate if it's reasonable for DateTime to extend Date directly instead */ -Long.prototype.getNumBitsAbs = function() { - if (this.isNegative()) { - if (this.equals(Long.MIN_VALUE)) { - return 64; - } else { - return this.negate().getNumBitsAbs(); - } - } else { - var val = this.high_ !== 0 ? this.high_ : this.low_; - for (var bit = 31; bit > 0; bit--) { - if ((val & (1 << bit)) !== 0) { - break; - } +var AbstractDate = /** @class */ (function () { + function AbstractDate(year, month, day) { + if (year === void 0) { year = null; } + if (month === void 0) { month = null; } + if (day === void 0) { day = null; } + this.year = year; + this.month = month; + this.day = day; } - return this.high_ !== 0 ? bit + 33 : bit + 1; - } -}; - -/** - * Return whether this value is zero. - * - * @method - * @return {boolean} whether this value is zero. - */ -Long.prototype.isZero = function() { - return this.high_ === 0 && this.low_ === 0; -}; - -/** - * Return whether this value is negative. - * - * @method - * @return {boolean} whether this value is negative. - */ -Long.prototype.isNegative = function() { - return this.high_ < 0; -}; - -/** - * Return whether this value is odd. - * - * @method - * @return {boolean} whether this value is odd. - */ -Long.prototype.isOdd = function() { - return (this.low_ & 1) === 1; -}; - -/** - * Return whether this Long equals the other - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long equals the other - */ -Long.prototype.equals = function(other) { - return this.high_ === other.high_ && this.low_ === other.low_; -}; - -/** - * Return whether this Long does not equal the other. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long does not equal the other. - */ -Long.prototype.notEquals = function(other) { - return this.high_ !== other.high_ || this.low_ !== other.low_; -}; - -/** - * Return whether this Long is less than the other. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long is less than the other. - */ -Long.prototype.lessThan = function(other) { - return this.compare(other) < 0; -}; - -/** - * Return whether this Long is less than or equal to the other. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long is less than or equal to the other. - */ -Long.prototype.lessThanOrEqual = function(other) { - return this.compare(other) <= 0; -}; - -/** - * Return whether this Long is greater than the other. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long is greater than the other. - */ -Long.prototype.greaterThan = function(other) { - return this.compare(other) > 0; -}; - -/** - * Return whether this Long is greater than or equal to the other. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} whether this Long is greater than or equal to the other. - */ -Long.prototype.greaterThanOrEqual = function(other) { - return this.compare(other) >= 0; -}; - -/** - * Compares this Long with the given one. - * - * @method - * @param {Long} other Long to compare against. - * @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater. - */ -Long.prototype.compare = function(other) { - if (this.equals(other)) { - return 0; - } - - var thisNeg = this.isNegative(); - var otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) { - return -1; - } - if (!thisNeg && otherNeg) { - return 1; - } - - // at this point, the signs are the same, so subtraction will not overflow - if (this.subtract(other).isNegative()) { - return -1; - } else { - return 1; - } -}; - -/** - * The negation of this value. - * - * @method - * @return {Long} the negation of this value. - */ -Long.prototype.negate = function() { - if (this.equals(Long.MIN_VALUE)) { - return Long.MIN_VALUE; - } else { - return this.not().add(Long.ONE); - } -}; - -/** - * Returns the sum of this and the given Long. - * - * @method - * @param {Long} other Long to add to this one. - * @return {Long} the sum of this and the given Long. - */ -Long.prototype.add = function(other) { - // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - - var a48 = this.high_ >>> 16; - var a32 = this.high_ & 0xffff; - var a16 = this.low_ >>> 16; - var a00 = this.low_ & 0xffff; - - var b48 = other.high_ >>> 16; - var b32 = other.high_ & 0xffff; - var b16 = other.low_ >>> 16; - var b00 = other.low_ & 0xffff; - - var c48 = 0, - c32 = 0, - c16 = 0, - c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xffff; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xffff; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xffff; - c48 += a48 + b48; - c48 &= 0xffff; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); -}; - -/** - * Returns the difference of this and the given Long. - * - * @method - * @param {Long} other Long to subtract from this. - * @return {Long} the difference of this and the given Long. - */ -Long.prototype.subtract = function(other) { - return this.add(other.negate()); -}; - -/** - * Returns the product of this and the given Long. - * - * @method - * @param {Long} other Long to multiply with this. - * @return {Long} the product of this and the other. - */ -Long.prototype.multiply = function(other) { - if (this.isZero()) { - return Long.ZERO; - } else if (other.isZero()) { - return Long.ZERO; - } - - if (this.equals(Long.MIN_VALUE)) { - return other.isOdd() ? Long.MIN_VALUE : Long.ZERO; - } else if (other.equals(Long.MIN_VALUE)) { - return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; - } - - if (this.isNegative()) { - if (other.isNegative()) { - return this.negate().multiply(other.negate()); - } else { - return this.negate() - .multiply(other) - .negate(); - } - } else if (other.isNegative()) { - return this.multiply(other.negate()).negate(); - } - - // If both Longs are small, use float multiplication - if (this.lessThan(Long.TWO_PWR_24_) && other.lessThan(Long.TWO_PWR_24_)) { - return Long.fromNumber(this.toNumber() * other.toNumber()); - } - - // Divide each Long into 4 chunks of 16 bits, and then add up 4x4 products. - // We can skip products that would overflow. - - var a48 = this.high_ >>> 16; - var a32 = this.high_ & 0xffff; - var a16 = this.low_ >>> 16; - var a00 = this.low_ & 0xffff; - - var b48 = other.high_ >>> 16; - var b32 = other.high_ & 0xffff; - var b16 = other.low_ >>> 16; - var b00 = other.low_ & 0xffff; - - var c48 = 0, - c32 = 0, - c16 = 0, - c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xffff; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xffff; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xffff; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xffff; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xffff; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xffff; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xffff; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); -}; - -/** - * Returns this Long divided by the given one. - * - * @method - * @param {Long} other Long by which to divide. - * @return {Long} this Long divided by the given one. - */ -Long.prototype.div = function(other) { - if (other.isZero()) { - throw Error('division by zero'); - } else if (this.isZero()) { - return Long.ZERO; - } - - if (this.equals(Long.MIN_VALUE)) { - if (other.equals(Long.ONE) || other.equals(Long.NEG_ONE)) { - return Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE - } else if (other.equals(Long.MIN_VALUE)) { - return Long.ONE; - } else { - // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. - var halfThis = this.shiftRight(1); - var approx = halfThis.div(other).shiftLeft(1); - if (approx.equals(Long.ZERO)) { - return other.isNegative() ? Long.ONE : Long.NEG_ONE; - } else { - var rem = this.subtract(other.multiply(approx)); - var result = approx.add(rem.div(other)); - return result; - } - } - } else if (other.equals(Long.MIN_VALUE)) { - return Long.ZERO; - } - - if (this.isNegative()) { - if (other.isNegative()) { - return this.negate().div(other.negate()); - } else { - return this.negate() - .div(other) - .negate(); - } - } else if (other.isNegative()) { - return this.div(other.negate()).negate(); - } - - // Repeat the following until the remainder is less than other: find a - // floating-point that approximates remainder / other *from below*, add this - // into the result, and subtract it from the remainder. It is critical that - // the approximate value is less than or equal to the real value so that the - // remainder never becomes negative. - var res = Long.ZERO; - rem = this; - while (rem.greaterThanOrEqual(other)) { - // Approximate the result of division. This may be a little greater or - // smaller than the actual value. - approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); - - // We will tweak the approximate result by changing it in the 48-th digit or - // the smallest non-fractional digit, whichever is larger. - var log2 = Math.ceil(Math.log(approx) / Math.LN2); - var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); - - // Decrease the approximation until it is smaller than the remainder. Note - // that if it is too large, the product overflows and is negative. - var approxRes = Long.fromNumber(approx); - var approxRem = approxRes.multiply(other); - while (approxRem.isNegative() || approxRem.greaterThan(rem)) { - approx -= delta; - approxRes = Long.fromNumber(approx); - approxRem = approxRes.multiply(other); - } - - // We know the answer can't be zero... and actually, zero would cause - // infinite recursion since we would make no progress. - if (approxRes.isZero()) { - approxRes = Long.ONE; - } - - res = res.add(approxRes); - rem = rem.subtract(approxRem); - } - return res; -}; - -/** - * Returns this Long modulo the given one. - * - * @method - * @param {Long} other Long by which to mod. - * @return {Long} this Long modulo the given one. - */ -Long.prototype.modulo = function(other) { - return this.subtract(this.div(other).multiply(other)); -}; - -/** - * The bitwise-NOT of this value. - * - * @method - * @return {Long} the bitwise-NOT of this value. - */ -Long.prototype.not = function() { - return Long.fromBits(~this.low_, ~this.high_); -}; - -/** - * Returns the bitwise-AND of this Long and the given one. - * - * @method - * @param {Long} other the Long with which to AND. - * @return {Long} the bitwise-AND of this and the other. - */ -Long.prototype.and = function(other) { - return Long.fromBits(this.low_ & other.low_, this.high_ & other.high_); -}; - -/** - * Returns the bitwise-OR of this Long and the given one. - * - * @method - * @param {Long} other the Long with which to OR. - * @return {Long} the bitwise-OR of this and the other. - */ -Long.prototype.or = function(other) { - return Long.fromBits(this.low_ | other.low_, this.high_ | other.high_); -}; - -/** - * Returns the bitwise-XOR of this Long and the given one. - * - * @method - * @param {Long} other the Long with which to XOR. - * @return {Long} the bitwise-XOR of this and the other. - */ -Long.prototype.xor = function(other) { - return Long.fromBits(this.low_ ^ other.low_, this.high_ ^ other.high_); -}; - -/** - * Returns this Long with bits shifted to the left by the given amount. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Long} this shifted to the left by the given amount. - */ -Long.prototype.shiftLeft = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var low = this.low_; - if (numBits < 32) { - var high = this.high_; - return Long.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits))); - } else { - return Long.fromBits(0, low << (numBits - 32)); - } - } -}; - -/** - * Returns this Long with bits shifted to the right by the given amount. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Long} this shifted to the right by the given amount. - */ -Long.prototype.shiftRight = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var high = this.high_; - if (numBits < 32) { - var low = this.low_; - return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits); - } else { - return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1); - } - } -}; - -/** - * Returns this Long with bits shifted to the right by the given amount, with the new top bits matching the current sign bit. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Long} this shifted to the right by the given amount, with zeros placed into the new leading bits. - */ -Long.prototype.shiftRightUnsigned = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var high = this.high_; - if (numBits < 32) { - var low = this.low_; - return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits); - } else if (numBits === 32) { - return Long.fromBits(high, 0); - } else { - return Long.fromBits(high >>> (numBits - 32), 0); - } - } -}; - -/** - * Returns a Long representing the given (32-bit) integer value. - * - * @method - * @param {number} value the 32-bit integer in question. - * @return {Long} the corresponding Long value. - */ -Long.fromInt = function(value) { - if (-128 <= value && value < 128) { - var cachedObj = Long.INT_CACHE_[value]; - if (cachedObj) { - return cachedObj; - } - } - - var obj = new Long(value | 0, value < 0 ? -1 : 0); - if (-128 <= value && value < 128) { - Long.INT_CACHE_[value] = obj; - } - return obj; -}; - -/** - * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. - * - * @method - * @param {number} value the number in question. - * @return {Long} the corresponding Long value. - */ -Long.fromNumber = function(value) { - if (isNaN(value) || !isFinite(value)) { - return Long.ZERO; - } else if (value <= -Long.TWO_PWR_63_DBL_) { - return Long.MIN_VALUE; - } else if (value + 1 >= Long.TWO_PWR_63_DBL_) { - return Long.MAX_VALUE; - } else if (value < 0) { - return Long.fromNumber(-value).negate(); - } else { - return new Long((value % Long.TWO_PWR_32_DBL_) | 0, (value / Long.TWO_PWR_32_DBL_) | 0); - } -}; - -/** - * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. - * @param {bigint} value - The number in question - * @returns {Long} The corresponding Long value - */ -Long.fromBigInt = function(value) { - return Long.fromString(value.toString(10), 10); -} - -/** - * Returns a Long representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits. - * - * @method - * @param {number} lowBits the low 32-bits. - * @param {number} highBits the high 32-bits. - * @return {Long} the corresponding Long value. - */ -Long.fromBits = function(lowBits, highBits) { - return new Long(lowBits, highBits); -}; - -/** - * Returns a Long representation of the given string, written using the given radix. - * - * @method - * @param {string} str the textual representation of the Long. - * @param {number} opt_radix the radix in which the text is written. - * @return {Long} the corresponding Long value. - */ -Long.fromString = function(str, opt_radix) { - if (str.length === 0) { - throw Error('number format error: empty string'); - } - - var radix = opt_radix || 10; - if (radix < 2 || 36 < radix) { - throw Error('radix out of range: ' + radix); - } - - if (str.charAt(0) === '-') { - return Long.fromString(str.substring(1), radix).negate(); - } else if (str.indexOf('-') >= 0) { - throw Error('number format error: interior "-" character: ' + str); - } - - // Do several (8) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = Long.fromNumber(Math.pow(radix, 8)); - - var result = Long.ZERO; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i); - var value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = Long.fromNumber(Math.pow(radix, size)); - result = result.multiply(power).add(Long.fromNumber(value)); - } else { - result = result.multiply(radixToPower); - result = result.add(Long.fromNumber(value)); - } - } - return result; -}; - -// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the -// from* methods on which they depend. - -/** - * A cache of the Long representations of small integer values. - * @type {Object} - * @ignore - */ -Long.INT_CACHE_ = {}; - -// NOTE: the compiler should inline these constant values below and then remove -// these variables, so there should be no runtime penalty for these. - -/** - * Number used repeated below in calculations. This must appear before the - * first call to any from* function below. - * @type {number} - * @ignore - */ -Long.TWO_PWR_16_DBL_ = 1 << 16; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_24_DBL_ = 1 << 24; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_32_DBL_ = Long.TWO_PWR_16_DBL_ * Long.TWO_PWR_16_DBL_; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_31_DBL_ = Long.TWO_PWR_32_DBL_ / 2; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_48_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_16_DBL_; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_64_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_32_DBL_; - -/** - * @type {number} - * @ignore - */ -Long.TWO_PWR_63_DBL_ = Long.TWO_PWR_64_DBL_ / 2; - -/** @type {Long} */ -Long.ZERO = Long.fromInt(0); - -/** @type {Long} */ -Long.ONE = Long.fromInt(1); - -/** @type {Long} */ -Long.NEG_ONE = Long.fromInt(-1); - -/** @type {Long} */ -Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0); - -/** @type {Long} */ -Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0); - -/** - * @type {Long} - * @ignore - */ -Long.TWO_PWR_24_ = Long.fromInt(1 << 24); - -/** - * Expose. - */ -module.exports = Long; -module.exports.Long = Long; - -},{}],38:[function(require,module,exports){ -(function (global){(function (){ -'use strict'; - -// We have an ES6 Map available, return the native instance -if (typeof global.Map !== 'undefined') { - module.exports = global.Map; - module.exports.Map = global.Map; -} else { - // We will return a polyfill - var Map = function(array) { - this._keys = []; - this._values = {}; - - for (var i = 0; i < array.length; i++) { - if (array[i] == null) continue; // skip null and undefined - var entry = array[i]; - var key = entry[0]; - var value = entry[1]; - // Add the key to the list of keys in order - this._keys.push(key); - // Add the key and value to the values dictionary with a point - // to the location in the ordered keys list - this._values[key] = { v: value, i: this._keys.length - 1 }; - } - }; - - Map.prototype.clear = function() { - this._keys = []; - this._values = {}; - }; - - Map.prototype.delete = function(key) { - var value = this._values[key]; - if (value == null) return false; - // Delete entry - delete this._values[key]; - // Remove the key from the ordered keys list - this._keys.splice(value.i, 1); - return true; - }; - - Map.prototype.entries = function() { - var self = this; - var index = 0; - - return { - next: function() { - var key = self._keys[index++]; - return { - value: key !== undefined ? [key, self._values[key].v] : undefined, - done: key !== undefined ? false : true - }; - } - }; - }; - - Map.prototype.forEach = function(callback, self) { - self = self || this; - - for (var i = 0; i < this._keys.length; i++) { - var key = this._keys[i]; - // Call the forEach callback - callback.call(self, this._values[key].v, key, self); - } - }; - - Map.prototype.get = function(key) { - return this._values[key] ? this._values[key].v : undefined; - }; - - Map.prototype.has = function(key) { - return this._values[key] != null; - }; - - Map.prototype.keys = function() { - var self = this; - var index = 0; - - return { - next: function() { - var key = self._keys[index++]; - return { - value: key !== undefined ? key : undefined, - done: key !== undefined ? false : true - }; - } - }; - }; - - Map.prototype.set = function(key, value) { - if (this._values[key]) { - this._values[key].v = value; - return this; - } - - // Add the key to the list of keys in order - this._keys.push(key); - // Add the key and value to the values dictionary with a point - // to the location in the ordered keys list - this._values[key] = { v: value, i: this._keys.length - 1 }; - return this; - }; - - Map.prototype.values = function() { - var self = this; - var index = 0; - - return { - next: function() { - var key = self._keys[index++]; - return { - value: key !== undefined ? self._values[key].v : undefined, - done: key !== undefined ? false : true - }; - } - }; - }; - - // Last ismaster - Object.defineProperty(Map.prototype, 'size', { - enumerable: true, - get: function() { - return this._keys.length; - } - }); - - module.exports = Map; - module.exports.Map = Map; -} - -}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],39:[function(require,module,exports){ -/** - * A class representation of the BSON MaxKey type. - * - * @class - * @return {MaxKey} A MaxKey instance - */ -function MaxKey() { - if (!(this instanceof MaxKey)) return new MaxKey(); - - this._bsontype = 'MaxKey'; -} - -module.exports = MaxKey; -module.exports.MaxKey = MaxKey; - -},{}],40:[function(require,module,exports){ -/** - * A class representation of the BSON MinKey type. - * - * @class - * @return {MinKey} A MinKey instance - */ -function MinKey() { - if (!(this instanceof MinKey)) return new MinKey(); - - this._bsontype = 'MinKey'; -} - -module.exports = MinKey; -module.exports.MinKey = MinKey; - -},{}],41:[function(require,module,exports){ -(function (process,Buffer){(function (){ -// Custom inspect property name / symbol. -var inspect = 'inspect'; - -var utils = require('./parser/utils'); - -/** - * Machine id. - * - * Create a random 3-byte value (i.e. unique for this - * process). Other drivers use a md5 of the machine id here, but - * that would mean an asyc call to gethostname, so we don't bother. - * @ignore - */ -var MACHINE_ID = parseInt(Math.random() * 0xffffff, 10); - -// Regular expression that checks for hex value -var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); - -// Check if buffer exists -try { - if (Buffer && Buffer.from) { - var hasBufferType = true; - inspect = require('util').inspect.custom || 'inspect'; - } -} catch (err) { - hasBufferType = false; -} - -/** -* Create a new ObjectID instance -* -* @class -* @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number. -* @property {number} generationTime The generation time of this ObjectId instance -* @return {ObjectID} instance of ObjectID. -*/ -var ObjectID = function ObjectID(id) { - // Duck-typing to support ObjectId from different npm packages - if (id instanceof ObjectID) return id; - if (!(this instanceof ObjectID)) return new ObjectID(id); - - this._bsontype = 'ObjectID'; - - // The most common usecase (blank id, new objectId instance) - if (id == null || typeof id === 'number') { - // Generate a new id - this.id = this.generate(id); - // If we are caching the hex string - if (ObjectID.cacheHexString) this.__id = this.toString('hex'); - // Return the object - return; - } - - // Check if the passed in id is valid - var valid = ObjectID.isValid(id); - - // Throw an error if it's not a valid setup - if (!valid && id != null) { - throw new Error( - 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' - ); - } else if (valid && typeof id === 'string' && id.length === 24 && hasBufferType) { - return new ObjectID(utils.toBuffer(id, 'hex')); - } else if (valid && typeof id === 'string' && id.length === 24) { - return ObjectID.createFromHexString(id); - } else if (id != null && id.length === 12) { - // assume 12 byte string - this.id = id; - } else if (id != null && typeof id.toHexString === 'function') { - // Duck-typing to support ObjectId from different npm packages - return id; - } else { - throw new Error( - 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' - ); - } - - if (ObjectID.cacheHexString) this.__id = this.toString('hex'); -}; - -// Allow usage of ObjectId as well as ObjectID -// var ObjectId = ObjectID; - -// Precomputed hex table enables speedy hex string conversion -var hexTable = []; -for (var i = 0; i < 256; i++) { - hexTable[i] = (i <= 15 ? '0' : '') + i.toString(16); -} - -/** -* Return the ObjectID id as a 24 byte hex string representation -* -* @method -* @return {string} return the 24 byte hex string representation. -*/ -ObjectID.prototype.toHexString = function() { - if (ObjectID.cacheHexString && this.__id) return this.__id; - - var hexString = ''; - if (!this.id || !this.id.length) { - throw new Error( - 'invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [' + - JSON.stringify(this.id) + - ']' - ); - } - - if (this.id instanceof _Buffer) { - hexString = convertToHex(this.id); - if (ObjectID.cacheHexString) this.__id = hexString; - return hexString; - } - - for (var i = 0; i < this.id.length; i++) { - hexString += hexTable[this.id.charCodeAt(i)]; - } - - if (ObjectID.cacheHexString) this.__id = hexString; - return hexString; -}; - -/** -* Update the ObjectID index used in generating new ObjectID's on the driver -* -* @method -* @return {number} returns next index value. -* @ignore -*/ -ObjectID.prototype.get_inc = function() { - return (ObjectID.index = (ObjectID.index + 1) % 0xffffff); -}; - -/** -* Update the ObjectID index used in generating new ObjectID's on the driver -* -* @method -* @return {number} returns next index value. -* @ignore -*/ -ObjectID.prototype.getInc = function() { - return this.get_inc(); -}; - -/** -* Generate a 12 byte id buffer used in ObjectID's -* -* @method -* @param {number} [time] optional parameter allowing to pass in a second based timestamp. -* @return {Buffer} return the 12 byte id buffer string. -*/ -ObjectID.prototype.generate = function(time) { - if ('number' !== typeof time) { - time = ~~(Date.now() / 1000); - } - - // Use pid - var pid = - (typeof process === 'undefined' || process.pid === 1 - ? Math.floor(Math.random() * 100000) - : process.pid) % 0xffff; - var inc = this.get_inc(); - // Buffer used - var buffer = utils.allocBuffer(12); - // Encode time - buffer[3] = time & 0xff; - buffer[2] = (time >> 8) & 0xff; - buffer[1] = (time >> 16) & 0xff; - buffer[0] = (time >> 24) & 0xff; - // Encode machine - buffer[6] = MACHINE_ID & 0xff; - buffer[5] = (MACHINE_ID >> 8) & 0xff; - buffer[4] = (MACHINE_ID >> 16) & 0xff; - // Encode pid - buffer[8] = pid & 0xff; - buffer[7] = (pid >> 8) & 0xff; - // Encode index - buffer[11] = inc & 0xff; - buffer[10] = (inc >> 8) & 0xff; - buffer[9] = (inc >> 16) & 0xff; - // Return the buffer - return buffer; -}; - -/** -* Converts the id into a 24 byte hex string for printing -* -* @param {String} format The Buffer toString format parameter. -* @return {String} return the 24 byte hex string representation. -* @ignore -*/ -ObjectID.prototype.toString = function(format) { - // Is the id a buffer then use the buffer toString method to return the format - if (this.id && this.id.copy) { - return this.id.toString(typeof format === 'string' ? format : 'hex'); - } - - // if(this.buffer ) - return this.toHexString(); -}; - -/** -* Converts to a string representation of this Id. -* -* @return {String} return the 24 byte hex string representation. -* @ignore -*/ -ObjectID.prototype[inspect] = ObjectID.prototype.toString; - -/** -* Converts to its JSON representation. -* -* @return {String} return the 24 byte hex string representation. -* @ignore -*/ -ObjectID.prototype.toJSON = function() { - return this.toHexString(); -}; - -/** -* Compares the equality of this ObjectID with `otherID`. -* -* @method -* @param {object} otherID ObjectID instance to compare against. -* @return {boolean} the result of comparing two ObjectID's -*/ -ObjectID.prototype.equals = function equals(otherId) { - // var id; - - if (otherId instanceof ObjectID) { - return this.toString() === otherId.toString(); - } else if ( - typeof otherId === 'string' && - ObjectID.isValid(otherId) && - otherId.length === 12 && - this.id instanceof _Buffer - ) { - return otherId === this.id.toString('binary'); - } else if (typeof otherId === 'string' && ObjectID.isValid(otherId) && otherId.length === 24) { - return otherId.toLowerCase() === this.toHexString(); - } else if (typeof otherId === 'string' && ObjectID.isValid(otherId) && otherId.length === 12) { - return otherId === this.id; - } else if (otherId != null && (otherId instanceof ObjectID || otherId.toHexString)) { - return otherId.toHexString() === this.toHexString(); - } else { - return false; - } -}; - -/** -* Returns the generation date (accurate up to the second) that this ID was generated. -* -* @method -* @return {date} the generation date -*/ -ObjectID.prototype.getTimestamp = function() { - var timestamp = new Date(); - var time = this.id[3] | (this.id[2] << 8) | (this.id[1] << 16) | (this.id[0] << 24); - timestamp.setTime(Math.floor(time) * 1000); - return timestamp; -}; - -/** -* @ignore -*/ -ObjectID.index = ~~(Math.random() * 0xffffff); - -/** -* @ignore -*/ -ObjectID.createPk = function createPk() { - return new ObjectID(); -}; - -/** -* Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID. -* -* @method -* @param {number} time an integer number representing a number of seconds. -* @return {ObjectID} return the created ObjectID -*/ -ObjectID.createFromTime = function createFromTime(time) { - var buffer = utils.toBuffer([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); - // Encode time into first 4 bytes - buffer[3] = time & 0xff; - buffer[2] = (time >> 8) & 0xff; - buffer[1] = (time >> 16) & 0xff; - buffer[0] = (time >> 24) & 0xff; - // Return the new objectId - return new ObjectID(buffer); -}; - -// Lookup tables -//var encodeLookup = '0123456789abcdef'.split(''); -var decodeLookup = []; -i = 0; -while (i < 10) decodeLookup[0x30 + i] = i++; -while (i < 16) decodeLookup[0x41 - 10 + i] = decodeLookup[0x61 - 10 + i] = i++; - -var _Buffer = Buffer; -var convertToHex = function(bytes) { - return bytes.toString('hex'); -}; - -/** -* Creates an ObjectID from a hex string representation of an ObjectID. -* -* @method -* @param {string} hexString create a ObjectID from a passed in 24 byte hexstring. -* @return {ObjectID} return the created ObjectID -*/ -ObjectID.createFromHexString = function createFromHexString(string) { - // Throw an error if it's not a valid setup - if (typeof string === 'undefined' || (string != null && string.length !== 24)) { - throw new Error( - 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters' - ); - } - - // Use Buffer.from method if available - if (hasBufferType) return new ObjectID(utils.toBuffer(string, 'hex')); - - // Calculate lengths - var array = new _Buffer(12); - var n = 0; - var i = 0; - - while (i < 24) { - array[n++] = (decodeLookup[string.charCodeAt(i++)] << 4) | decodeLookup[string.charCodeAt(i++)]; - } - - return new ObjectID(array); -}; - -/** -* Checks if a value is a valid bson ObjectId -* -* @method -* @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise. -*/ -ObjectID.isValid = function isValid(id) { - if (id == null) return false; - - if (typeof id === 'number') { - return true; - } - - if (typeof id === 'string') { - return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id)); - } - - if (id instanceof ObjectID) { - return true; - } - - if (id instanceof _Buffer) { - return true; - } - - // Duck-Typing detection of ObjectId like objects - if ( - typeof id.toHexString === 'function' && - (id.id instanceof _Buffer || typeof id.id === 'string') - ) { - return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id)); - } - - return false; -}; - -/** -* @ignore -*/ -Object.defineProperty(ObjectID.prototype, 'generationTime', { - enumerable: true, - get: function() { - return this.id[3] | (this.id[2] << 8) | (this.id[1] << 16) | (this.id[0] << 24); - }, - set: function(value) { - // Encode time into first 4 bytes - this.id[3] = value & 0xff; - this.id[2] = (value >> 8) & 0xff; - this.id[1] = (value >> 16) & 0xff; - this.id[0] = (value >> 24) & 0xff; - } -}); - -/** - * Expose. - */ -module.exports = ObjectID; -module.exports.ObjectID = ObjectID; -module.exports.ObjectId = ObjectID; - -}).call(this)}).call(this,require('_process'),require("buffer").Buffer) -},{"./parser/utils":45,"_process":369,"buffer":49,"util":378}],42:[function(require,module,exports){ -(function (Buffer){(function (){ -'use strict'; - -var Long = require('../long').Long, - Double = require('../double').Double, - Timestamp = require('../timestamp').Timestamp, - ObjectID = require('../objectid').ObjectID, - Symbol = require('../symbol').Symbol, - BSONRegExp = require('../regexp').BSONRegExp, - Code = require('../code').Code, - Decimal128 = require('../decimal128'), - MinKey = require('../min_key').MinKey, - MaxKey = require('../max_key').MaxKey, - DBRef = require('../db_ref').DBRef, - Binary = require('../binary').Binary; - -var normalizedFunctionString = require('./utils').normalizedFunctionString; - -// To ensure that 0.4 of node works correctly -var isDate = function isDate(d) { - return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'; -}; - -var calculateObjectSize = function calculateObjectSize( - object, - serializeFunctions, - ignoreUndefined -) { - var totalLength = 4 + 1; - - if (Array.isArray(object)) { - for (var i = 0; i < object.length; i++) { - totalLength += calculateElement( - i.toString(), - object[i], - serializeFunctions, - true, - ignoreUndefined - ); - } - } else { - // If we have toBSON defined, override the current object - if (object.toBSON) { - object = object.toBSON(); - } - - // Calculate size - for (var key in object) { - totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined); - } - } - - return totalLength; -}; - -/** - * @ignore - * @api private - */ -function calculateElement(name, value, serializeFunctions, isArray, ignoreUndefined) { - // If we have toBSON defined, override the current object - if (value && value.toBSON) { - value = value.toBSON(); - } - - switch (typeof value) { - case 'string': - return 1 + Buffer.byteLength(name, 'utf8') + 1 + 4 + Buffer.byteLength(value, 'utf8') + 1; - case 'number': - if (Math.floor(value) === value && value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { - if (value >= BSON.BSON_INT32_MIN && value <= BSON.BSON_INT32_MAX) { - // 32 bit - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (4 + 1); - } else { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); - } - } else { - // 64 bit - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); - } - case 'undefined': - if (isArray || !ignoreUndefined) - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + 1; - return 0; - case 'boolean': - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 1); - case 'object': - if ( - value == null || - value instanceof MinKey || - value instanceof MaxKey || - value['_bsontype'] === 'MinKey' || - value['_bsontype'] === 'MaxKey' - ) { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + 1; - } else if (value instanceof ObjectID || value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (12 + 1); - } else if (value instanceof Date || isDate(value)) { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); - } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.length - ); - } else if ( - value instanceof Long || - value instanceof Double || - value instanceof Timestamp || - value['_bsontype'] === 'Long' || - value['_bsontype'] === 'Double' || - value['_bsontype'] === 'Timestamp' - ) { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1); - } else if (value instanceof Decimal128 || value['_bsontype'] === 'Decimal128') { - return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (16 + 1); - } else if (value instanceof Code || value['_bsontype'] === 'Code') { - // Calculate size depending on the availability of a scope - if (value.scope != null && Object.keys(value.scope).length > 0) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - 4 + - 4 + - Buffer.byteLength(value.code.toString(), 'utf8') + - 1 + - calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined) - ); - } else { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - 4 + - Buffer.byteLength(value.code.toString(), 'utf8') + - 1 - ); - } - } else if (value instanceof Binary || value['_bsontype'] === 'Binary') { - // Check what kind of subtype we have - if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - (value.position + 1 + 4 + 1 + 4) - ); - } else { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1) - ); - } - } else if (value instanceof Symbol || value['_bsontype'] === 'Symbol') { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - Buffer.byteLength(value.value, 'utf8') + - 4 + - 1 + - 1 - ); - } else if (value instanceof DBRef || value['_bsontype'] === 'DBRef') { - // Set up correct object for serialization - var ordered_values = { - $ref: value.namespace, - $id: value.oid - }; - - // Add db reference if it exists - if (null != value.db) { - ordered_values['$db'] = value.db; - } - - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - calculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined) - ); - } else if ( - value instanceof RegExp || - Object.prototype.toString.call(value) === '[object RegExp]' - ) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - Buffer.byteLength(value.source, 'utf8') + - 1 + - (value.global ? 1 : 0) + - (value.ignoreCase ? 1 : 0) + - (value.multiline ? 1 : 0) + - 1 - ); - } else if (value instanceof BSONRegExp || value['_bsontype'] === 'BSONRegExp') { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - Buffer.byteLength(value.pattern, 'utf8') + - 1 + - Buffer.byteLength(value.options, 'utf8') + - 1 - ); - } else { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - calculateObjectSize(value, serializeFunctions, ignoreUndefined) + - 1 - ); - } - case 'function': - // WTF for 0.4.X where typeof /someregexp/ === 'function' - if ( - value instanceof RegExp || - Object.prototype.toString.call(value) === '[object RegExp]' || - String.call(value) === '[object RegExp]' - ) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - Buffer.byteLength(value.source, 'utf8') + - 1 + - (value.global ? 1 : 0) + - (value.ignoreCase ? 1 : 0) + - (value.multiline ? 1 : 0) + - 1 - ); - } else { - if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - 4 + - 4 + - Buffer.byteLength(normalizedFunctionString(value), 'utf8') + - 1 + - calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined) - ); - } else if (serializeFunctions) { - return ( - (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + - 1 + - 4 + - Buffer.byteLength(normalizedFunctionString(value), 'utf8') + - 1 - ); - } - } - } - - return 0; -} - -var BSON = {}; - -// BSON MAX VALUES -BSON.BSON_INT32_MAX = 0x7fffffff; -BSON.BSON_INT32_MIN = -0x80000000; - -// JS MAX PRECISE VALUES -BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. -BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. - -module.exports = calculateObjectSize; - -}).call(this)}).call(this,require("buffer").Buffer) -},{"../binary":29,"../code":31,"../db_ref":32,"../decimal128":33,"../double":34,"../long":37,"../max_key":39,"../min_key":40,"../objectid":41,"../regexp":46,"../symbol":47,"../timestamp":48,"./utils":45,"buffer":49}],43:[function(require,module,exports){ -'use strict'; - -var Long = require('../long').Long, - Double = require('../double').Double, - Timestamp = require('../timestamp').Timestamp, - ObjectID = require('../objectid').ObjectID, - Symbol = require('../symbol').Symbol, - Code = require('../code').Code, - MinKey = require('../min_key').MinKey, - MaxKey = require('../max_key').MaxKey, - Decimal128 = require('../decimal128'), - Int32 = require('../int_32'), - DBRef = require('../db_ref').DBRef, - BSONRegExp = require('../regexp').BSONRegExp, - Binary = require('../binary').Binary; - -var utils = require('./utils'); - -var deserialize = function(buffer, options, isArray) { - options = options == null ? {} : options; - var index = options && options.index ? options.index : 0; - // Read the document size - var size = - buffer[index] | - (buffer[index + 1] << 8) | - (buffer[index + 2] << 16) | - (buffer[index + 3] << 24); - - // Ensure buffer is valid size - if (size < 5 || buffer.length < size || size + index > buffer.length) { - throw new Error('corrupt bson message'); - } - - // Illegal end value - if (buffer[index + size - 1] !== 0) { - throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00"); - } - - // Start deserializtion - return deserializeObject(buffer, index, options, isArray); -}; - -var deserializeObject = function(buffer, index, options, isArray) { - var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions']; - var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions']; - var cacheFunctionsCrc32 = - options['cacheFunctionsCrc32'] == null ? false : options['cacheFunctionsCrc32']; - - if (!cacheFunctionsCrc32) var crc32 = null; - - var fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; - - // Return raw bson buffer instead of parsing it - var raw = options['raw'] == null ? false : options['raw']; - - // Return BSONRegExp objects instead of native regular expressions - var bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; - - // Controls the promotion of values vs wrapper classes - var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers']; - var promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs']; - var promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; - - // Set the start index - var startIndex = index; - - // Validate that we have at least 4 bytes of buffer - if (buffer.length < 5) throw new Error('corrupt bson message < 5 bytes long'); - - // Read the document size - var size = - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); - - // Ensure buffer is valid size - if (size < 5 || size > buffer.length) throw new Error('corrupt bson message'); - - // Create holding object - var object = isArray ? [] : {}; - // Used for arrays to skip having to perform utf8 decoding - var arrayIndex = 0; - - var done = false; - - // While we have more left data left keep parsing - // while (buffer[index + 1] !== 0) { - while (!done) { - // Read the type - var elementType = buffer[index++]; - // If we get a zero it's the last byte, exit - if (elementType === 0) break; - - // Get the start search index - var i = index; - // Locate the end of the c string - while (buffer[i] !== 0x00 && i < buffer.length) { - i++; - } - - // If are at the end of the buffer there is a problem with the document - if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); - var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); - - index = i + 1; - - if (elementType === BSON.BSON_DATA_STRING) { - var stringSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - if ( - stringSize <= 0 || - stringSize > buffer.length - index || - buffer[index + stringSize - 1] !== 0 - ) - throw new Error('bad string length in bson'); - object[name] = buffer.toString('utf8', index, index + stringSize - 1); - index = index + stringSize; - } else if (elementType === BSON.BSON_DATA_OID) { - var oid = utils.allocBuffer(12); - buffer.copy(oid, 0, index, index + 12); - object[name] = new ObjectID(oid); - index = index + 12; - } else if (elementType === BSON.BSON_DATA_INT && promoteValues === false) { - object[name] = new Int32( - buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24) - ); - } else if (elementType === BSON.BSON_DATA_INT) { - object[name] = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - } else if (elementType === BSON.BSON_DATA_NUMBER && promoteValues === false) { - object[name] = new Double(buffer.readDoubleLE(index)); - index = index + 8; - } else if (elementType === BSON.BSON_DATA_NUMBER) { - object[name] = buffer.readDoubleLE(index); - index = index + 8; - } else if (elementType === BSON.BSON_DATA_DATE) { - var lowBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - var highBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - object[name] = new Date(new Long(lowBits, highBits).toNumber()); - } else if (elementType === BSON.BSON_DATA_BOOLEAN) { - if (buffer[index] !== 0 && buffer[index] !== 1) throw new Error('illegal boolean type value'); - object[name] = buffer[index++] === 1; - } else if (elementType === BSON.BSON_DATA_OBJECT) { - var _index = index; - var objectSize = - buffer[index] | - (buffer[index + 1] << 8) | - (buffer[index + 2] << 16) | - (buffer[index + 3] << 24); - if (objectSize <= 0 || objectSize > buffer.length - index) - throw new Error('bad embedded document length in bson'); - - // We have a raw value - if (raw) { - object[name] = buffer.slice(index, index + objectSize); - } else { - object[name] = deserializeObject(buffer, _index, options, false); - } - - index = index + objectSize; - } else if (elementType === BSON.BSON_DATA_ARRAY) { - _index = index; - objectSize = - buffer[index] | - (buffer[index + 1] << 8) | - (buffer[index + 2] << 16) | - (buffer[index + 3] << 24); - var arrayOptions = options; - - // Stop index - var stopIndex = index + objectSize; - - // All elements of array to be returned as raw bson - if (fieldsAsRaw && fieldsAsRaw[name]) { - arrayOptions = {}; - for (var n in options) arrayOptions[n] = options[n]; - arrayOptions['raw'] = true; - } - - object[name] = deserializeObject(buffer, _index, arrayOptions, true); - index = index + objectSize; - - if (buffer[index - 1] !== 0) throw new Error('invalid array terminator byte'); - if (index !== stopIndex) throw new Error('corrupted array bson'); - } else if (elementType === BSON.BSON_DATA_UNDEFINED) { - object[name] = undefined; - } else if (elementType === BSON.BSON_DATA_NULL) { - object[name] = null; - } else if (elementType === BSON.BSON_DATA_LONG) { - // Unpack the low and high bits - lowBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - highBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - var long = new Long(lowBits, highBits); - // Promote the long if possible - if (promoteLongs && promoteValues === true) { - object[name] = - long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG) - ? long.toNumber() - : long; - } else { - object[name] = long; - } - } else if (elementType === BSON.BSON_DATA_DECIMAL128) { - // Buffer to contain the decimal bytes - var bytes = utils.allocBuffer(16); - // Copy the next 16 bytes into the bytes buffer - buffer.copy(bytes, 0, index, index + 16); - // Update index - index = index + 16; - // Assign the new Decimal128 value - var decimal128 = new Decimal128(bytes); - // If we have an alternative mapper use that - object[name] = decimal128.toObject ? decimal128.toObject() : decimal128; - } else if (elementType === BSON.BSON_DATA_BINARY) { - var binarySize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - var totalBinarySize = binarySize; - var subType = buffer[index++]; - - // Did we have a negative binary size, throw - if (binarySize < 0) throw new Error('Negative binary type element size found'); - - // Is the length longer than the document - if (binarySize > buffer.length) throw new Error('Binary type size larger than document size'); - - // Decode as raw Buffer object if options specifies it - if (buffer['slice'] != null) { - // If we have subtype 2 skip the 4 bytes for the size - if (subType === Binary.SUBTYPE_BYTE_ARRAY) { - binarySize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - if (binarySize < 0) - throw new Error('Negative binary type element size found for subtype 0x02'); - if (binarySize > totalBinarySize - 4) - throw new Error('Binary type with subtype 0x02 contains to long binary size'); - if (binarySize < totalBinarySize - 4) - throw new Error('Binary type with subtype 0x02 contains to short binary size'); - } - - if (promoteBuffers && promoteValues) { - object[name] = buffer.slice(index, index + binarySize); - } else { - object[name] = new Binary(buffer.slice(index, index + binarySize), subType); - } - } else { - var _buffer = - typeof Uint8Array !== 'undefined' - ? new Uint8Array(new ArrayBuffer(binarySize)) - : new Array(binarySize); - // If we have subtype 2 skip the 4 bytes for the size - if (subType === Binary.SUBTYPE_BYTE_ARRAY) { - binarySize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - if (binarySize < 0) - throw new Error('Negative binary type element size found for subtype 0x02'); - if (binarySize > totalBinarySize - 4) - throw new Error('Binary type with subtype 0x02 contains to long binary size'); - if (binarySize < totalBinarySize - 4) - throw new Error('Binary type with subtype 0x02 contains to short binary size'); - } - - // Copy the data - for (i = 0; i < binarySize; i++) { - _buffer[i] = buffer[index + i]; - } - - if (promoteBuffers && promoteValues) { - object[name] = _buffer; - } else { - object[name] = new Binary(_buffer, subType); - } - } - - // Update the index - index = index + binarySize; - } else if (elementType === BSON.BSON_DATA_REGEXP && bsonRegExp === false) { - // Get the start search index - i = index; - // Locate the end of the c string - while (buffer[i] !== 0x00 && i < buffer.length) { - i++; - } - // If are at the end of the buffer there is a problem with the document - if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); - // Return the C string - var source = buffer.toString('utf8', index, i); - // Create the regexp - index = i + 1; - - // Get the start search index - i = index; - // Locate the end of the c string - while (buffer[i] !== 0x00 && i < buffer.length) { - i++; - } - // If are at the end of the buffer there is a problem with the document - if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); - // Return the C string - var regExpOptions = buffer.toString('utf8', index, i); - index = i + 1; - - // For each option add the corresponding one for javascript - var optionsArray = new Array(regExpOptions.length); - - // Parse options - for (i = 0; i < regExpOptions.length; i++) { - switch (regExpOptions[i]) { - case 'm': - optionsArray[i] = 'm'; - break; - case 's': - optionsArray[i] = 'g'; - break; - case 'i': - optionsArray[i] = 'i'; - break; - } - } - - object[name] = new RegExp(source, optionsArray.join('')); - } else if (elementType === BSON.BSON_DATA_REGEXP && bsonRegExp === true) { - // Get the start search index - i = index; - // Locate the end of the c string - while (buffer[i] !== 0x00 && i < buffer.length) { - i++; - } - // If are at the end of the buffer there is a problem with the document - if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); - // Return the C string - source = buffer.toString('utf8', index, i); - index = i + 1; - - // Get the start search index - i = index; - // Locate the end of the c string - while (buffer[i] !== 0x00 && i < buffer.length) { - i++; - } - // If are at the end of the buffer there is a problem with the document - if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); - // Return the C string - regExpOptions = buffer.toString('utf8', index, i); - index = i + 1; - - // Set the object - object[name] = new BSONRegExp(source, regExpOptions); - } else if (elementType === BSON.BSON_DATA_SYMBOL) { - stringSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - if ( - stringSize <= 0 || - stringSize > buffer.length - index || - buffer[index + stringSize - 1] !== 0 - ) - throw new Error('bad string length in bson'); - object[name] = new Symbol(buffer.toString('utf8', index, index + stringSize - 1)); - index = index + stringSize; - } else if (elementType === BSON.BSON_DATA_TIMESTAMP) { - lowBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - highBits = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - object[name] = new Timestamp(lowBits, highBits); - } else if (elementType === BSON.BSON_DATA_MIN_KEY) { - object[name] = new MinKey(); - } else if (elementType === BSON.BSON_DATA_MAX_KEY) { - object[name] = new MaxKey(); - } else if (elementType === BSON.BSON_DATA_CODE) { - stringSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - if ( - stringSize <= 0 || - stringSize > buffer.length - index || - buffer[index + stringSize - 1] !== 0 - ) - throw new Error('bad string length in bson'); - var functionString = buffer.toString('utf8', index, index + stringSize - 1); - - // If we are evaluating the functions - if (evalFunctions) { - // If we have cache enabled let's look for the md5 of the function in the cache - if (cacheFunctions) { - var hash = cacheFunctionsCrc32 ? crc32(functionString) : functionString; - // Got to do this to avoid V8 deoptimizing the call due to finding eval - object[name] = isolateEvalWithHash(functionCache, hash, functionString, object); - } else { - object[name] = isolateEval(functionString); - } - } else { - object[name] = new Code(functionString); - } - - // Update parse index position - index = index + stringSize; - } else if (elementType === BSON.BSON_DATA_CODE_W_SCOPE) { - var totalSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - - // Element cannot be shorter than totalSize + stringSize + documentSize + terminator - if (totalSize < 4 + 4 + 4 + 1) { - throw new Error('code_w_scope total size shorter minimum expected length'); - } - - // Get the code string size - stringSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - // Check if we have a valid string - if ( - stringSize <= 0 || - stringSize > buffer.length - index || - buffer[index + stringSize - 1] !== 0 - ) - throw new Error('bad string length in bson'); - - // Javascript function - functionString = buffer.toString('utf8', index, index + stringSize - 1); - // Update parse index position - index = index + stringSize; - // Parse the element - _index = index; - // Decode the size of the object document - objectSize = - buffer[index] | - (buffer[index + 1] << 8) | - (buffer[index + 2] << 16) | - (buffer[index + 3] << 24); - // Decode the scope object - var scopeObject = deserializeObject(buffer, _index, options, false); - // Adjust the index - index = index + objectSize; - - // Check if field length is to short - if (totalSize < 4 + 4 + objectSize + stringSize) { - throw new Error('code_w_scope total size is to short, truncating scope'); - } - - // Check if totalSize field is to long - if (totalSize > 4 + 4 + objectSize + stringSize) { - throw new Error('code_w_scope total size is to long, clips outer document'); - } - - // If we are evaluating the functions - if (evalFunctions) { - // If we have cache enabled let's look for the md5 of the function in the cache - if (cacheFunctions) { - hash = cacheFunctionsCrc32 ? crc32(functionString) : functionString; - // Got to do this to avoid V8 deoptimizing the call due to finding eval - object[name] = isolateEvalWithHash(functionCache, hash, functionString, object); - } else { - object[name] = isolateEval(functionString); - } - - object[name].scope = scopeObject; - } else { - object[name] = new Code(functionString, scopeObject); - } - } else if (elementType === BSON.BSON_DATA_DBPOINTER) { - // Get the code string size - stringSize = - buffer[index++] | - (buffer[index++] << 8) | - (buffer[index++] << 16) | - (buffer[index++] << 24); - // Check if we have a valid string - if ( - stringSize <= 0 || - stringSize > buffer.length - index || - buffer[index + stringSize - 1] !== 0 - ) - throw new Error('bad string length in bson'); - // Namespace - var namespace = buffer.toString('utf8', index, index + stringSize - 1); - // Update parse index position - index = index + stringSize; - - // Read the oid - var oidBuffer = utils.allocBuffer(12); - buffer.copy(oidBuffer, 0, index, index + 12); - oid = new ObjectID(oidBuffer); - - // Update the index - index = index + 12; - - // Split the namespace - var parts = namespace.split('.'); - var db = parts.shift(); - var collection = parts.join('.'); - // Upgrade to DBRef type - object[name] = new DBRef(collection, oid, db); - } else { - throw new Error( - 'Detected unknown BSON type ' + - elementType.toString(16) + - ' for fieldname "' + - name + - '", are you using the latest BSON parser' - ); - } - } - - // Check if the deserialization was against a valid array/object - if (size !== index - startIndex) { - if (isArray) throw new Error('corrupt array bson'); - throw new Error('corrupt object bson'); - } - - // Check if we have a db ref object - if (object['$id'] != null) object = new DBRef(object['$ref'], object['$id'], object['$db']); - return object; -}; - -/** - * Ensure eval is isolated. - * - * @ignore - * @api private - */ -var isolateEvalWithHash = function(functionCache, hash, functionString, object) { - // Contains the value we are going to set - var value = null; - - // Check for cache hit, eval if missing and return cached function - if (functionCache[hash] == null) { - eval('value = ' + functionString); - functionCache[hash] = value; - } - // Set the object - return functionCache[hash].bind(object); -}; - -/** - * Ensure eval is isolated. - * - * @ignore - * @api private - */ -var isolateEval = function(functionString) { - // Contains the value we are going to set - var value = null; - // Eval the function - eval('value = ' + functionString); - return value; -}; - -var BSON = {}; - -/** - * Contains the function cache if we have that enable to allow for avoiding the eval step on each deserialization, comparison is by md5 - * - * @ignore - * @api private - */ -var functionCache = (BSON.functionCache = {}); - -/** - * Number BSON Type - * - * @classconstant BSON_DATA_NUMBER - **/ -BSON.BSON_DATA_NUMBER = 1; -/** - * String BSON Type - * - * @classconstant BSON_DATA_STRING - **/ -BSON.BSON_DATA_STRING = 2; -/** - * Object BSON Type - * - * @classconstant BSON_DATA_OBJECT - **/ -BSON.BSON_DATA_OBJECT = 3; -/** - * Array BSON Type - * - * @classconstant BSON_DATA_ARRAY - **/ -BSON.BSON_DATA_ARRAY = 4; -/** - * Binary BSON Type - * - * @classconstant BSON_DATA_BINARY - **/ -BSON.BSON_DATA_BINARY = 5; -/** - * Binary BSON Type - * - * @classconstant BSON_DATA_UNDEFINED - **/ -BSON.BSON_DATA_UNDEFINED = 6; -/** - * ObjectID BSON Type - * - * @classconstant BSON_DATA_OID - **/ -BSON.BSON_DATA_OID = 7; -/** - * Boolean BSON Type - * - * @classconstant BSON_DATA_BOOLEAN - **/ -BSON.BSON_DATA_BOOLEAN = 8; -/** - * Date BSON Type - * - * @classconstant BSON_DATA_DATE - **/ -BSON.BSON_DATA_DATE = 9; -/** - * null BSON Type - * - * @classconstant BSON_DATA_NULL - **/ -BSON.BSON_DATA_NULL = 10; -/** - * RegExp BSON Type - * - * @classconstant BSON_DATA_REGEXP - **/ -BSON.BSON_DATA_REGEXP = 11; -/** - * Code BSON Type - * - * @classconstant BSON_DATA_DBPOINTER - **/ -BSON.BSON_DATA_DBPOINTER = 12; -/** - * Code BSON Type - * - * @classconstant BSON_DATA_CODE - **/ -BSON.BSON_DATA_CODE = 13; -/** - * Symbol BSON Type - * - * @classconstant BSON_DATA_SYMBOL - **/ -BSON.BSON_DATA_SYMBOL = 14; -/** - * Code with Scope BSON Type - * - * @classconstant BSON_DATA_CODE_W_SCOPE - **/ -BSON.BSON_DATA_CODE_W_SCOPE = 15; -/** - * 32 bit Integer BSON Type - * - * @classconstant BSON_DATA_INT - **/ -BSON.BSON_DATA_INT = 16; -/** - * Timestamp BSON Type - * - * @classconstant BSON_DATA_TIMESTAMP - **/ -BSON.BSON_DATA_TIMESTAMP = 17; -/** - * Long BSON Type - * - * @classconstant BSON_DATA_LONG - **/ -BSON.BSON_DATA_LONG = 18; -/** - * Long BSON Type - * - * @classconstant BSON_DATA_DECIMAL128 - **/ -BSON.BSON_DATA_DECIMAL128 = 19; -/** - * MinKey BSON Type - * - * @classconstant BSON_DATA_MIN_KEY - **/ -BSON.BSON_DATA_MIN_KEY = 0xff; -/** - * MaxKey BSON Type - * - * @classconstant BSON_DATA_MAX_KEY - **/ -BSON.BSON_DATA_MAX_KEY = 0x7f; - -/** - * Binary Default Type - * - * @classconstant BSON_BINARY_SUBTYPE_DEFAULT - **/ -BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; -/** - * Binary Function Type - * - * @classconstant BSON_BINARY_SUBTYPE_FUNCTION - **/ -BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; -/** - * Binary Byte Array Type - * - * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY - **/ -BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; -/** - * Binary UUID Type - * - * @classconstant BSON_BINARY_SUBTYPE_UUID - **/ -BSON.BSON_BINARY_SUBTYPE_UUID = 3; -/** - * Binary MD5 Type - * - * @classconstant BSON_BINARY_SUBTYPE_MD5 - **/ -BSON.BSON_BINARY_SUBTYPE_MD5 = 4; -/** - * Binary User Defined Type - * - * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED - **/ -BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; - -// BSON MAX VALUES -BSON.BSON_INT32_MAX = 0x7fffffff; -BSON.BSON_INT32_MIN = -0x80000000; - -BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; -BSON.BSON_INT64_MIN = -Math.pow(2, 63); - -// JS MAX PRECISE VALUES -BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. -BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. - -// Internal long versions -var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. -var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. - -module.exports = deserialize; - -},{"../binary":29,"../code":31,"../db_ref":32,"../decimal128":33,"../double":34,"../int_32":36,"../long":37,"../max_key":39,"../min_key":40,"../objectid":41,"../regexp":46,"../symbol":47,"../timestamp":48,"./utils":45}],44:[function(require,module,exports){ -(function (Buffer){(function (){ -'use strict'; - -var writeIEEE754 = require('../float_parser').writeIEEE754, - Long = require('../long').Long, - Map = require('../map'), - Binary = require('../binary').Binary; - -var normalizedFunctionString = require('./utils').normalizedFunctionString; - -// try { -// var _Buffer = Uint8Array; -// } catch (e) { -// _Buffer = Buffer; -// } - -var regexp = /\x00/; // eslint-disable-line no-control-regex -var ignoreKeys = ['$db', '$ref', '$id', '$clusterTime']; - -// To ensure that 0.4 of node works correctly -var isDate = function isDate(d) { - return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'; -}; - -var isRegExp = function isRegExp(d) { - return Object.prototype.toString.call(d) === '[object RegExp]'; -}; - -var serializeString = function(buffer, key, value, index, isArray) { - // Encode String type - buffer[index++] = BSON.BSON_DATA_STRING; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes + 1; - buffer[index - 1] = 0; - // Write the string - var size = buffer.write(value, index + 4, 'utf8'); - // Write the size of the string to buffer - buffer[index + 3] = ((size + 1) >> 24) & 0xff; - buffer[index + 2] = ((size + 1) >> 16) & 0xff; - buffer[index + 1] = ((size + 1) >> 8) & 0xff; - buffer[index] = (size + 1) & 0xff; - // Update index - index = index + 4 + size; - // Write zero - buffer[index++] = 0; - return index; -}; - -var serializeNumber = function(buffer, key, value, index, isArray) { - // We have an integer value - if (Math.floor(value) === value && value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { - // If the value fits in 32 bits encode as int, if it fits in a double - // encode it as a double, otherwise long - if (value >= BSON.BSON_INT32_MIN && value <= BSON.BSON_INT32_MAX) { - // Set int type 32 bits or less - buffer[index++] = BSON.BSON_DATA_INT; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write the int value - buffer[index++] = value & 0xff; - buffer[index++] = (value >> 8) & 0xff; - buffer[index++] = (value >> 16) & 0xff; - buffer[index++] = (value >> 24) & 0xff; - } else if (value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) { - // Encode as double - buffer[index++] = BSON.BSON_DATA_NUMBER; - // Number of written bytes - numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write float - writeIEEE754(buffer, value, index, 'little', 52, 8); - // Ajust index - index = index + 8; - } else { - // Set long type - buffer[index++] = BSON.BSON_DATA_LONG; - // Number of written bytes - numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - var longVal = Long.fromNumber(value); - var lowBits = longVal.getLowBits(); - var highBits = longVal.getHighBits(); - // Encode low bits - buffer[index++] = lowBits & 0xff; - buffer[index++] = (lowBits >> 8) & 0xff; - buffer[index++] = (lowBits >> 16) & 0xff; - buffer[index++] = (lowBits >> 24) & 0xff; - // Encode high bits - buffer[index++] = highBits & 0xff; - buffer[index++] = (highBits >> 8) & 0xff; - buffer[index++] = (highBits >> 16) & 0xff; - buffer[index++] = (highBits >> 24) & 0xff; - } - } else { - // Encode as double - buffer[index++] = BSON.BSON_DATA_NUMBER; - // Number of written bytes - numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write float - writeIEEE754(buffer, value, index, 'little', 52, 8); - // Ajust index - index = index + 8; - } - - return index; -}; - -var serializeNull = function(buffer, key, value, index, isArray) { - // Set long type - buffer[index++] = BSON.BSON_DATA_NULL; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - return index; -}; - -var serializeBoolean = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_BOOLEAN; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Encode the boolean value - buffer[index++] = value ? 1 : 0; - return index; -}; - -var serializeDate = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_DATE; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - - // Write the date - var dateInMilis = Long.fromNumber(value.getTime()); - var lowBits = dateInMilis.getLowBits(); - var highBits = dateInMilis.getHighBits(); - // Encode low bits - buffer[index++] = lowBits & 0xff; - buffer[index++] = (lowBits >> 8) & 0xff; - buffer[index++] = (lowBits >> 16) & 0xff; - buffer[index++] = (lowBits >> 24) & 0xff; - // Encode high bits - buffer[index++] = highBits & 0xff; - buffer[index++] = (highBits >> 8) & 0xff; - buffer[index++] = (highBits >> 16) & 0xff; - buffer[index++] = (highBits >> 24) & 0xff; - return index; -}; - -var serializeRegExp = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_REGEXP; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - if (value.source && value.source.match(regexp) != null) { - throw Error('value ' + value.source + ' must not contain null bytes'); - } - // Adjust the index - index = index + buffer.write(value.source, index, 'utf8'); - // Write zero - buffer[index++] = 0x00; - // Write the parameters - if (value.global) buffer[index++] = 0x73; // s - if (value.ignoreCase) buffer[index++] = 0x69; // i - if (value.multiline) buffer[index++] = 0x6d; // m - // Add ending zero - buffer[index++] = 0x00; - return index; -}; - -var serializeBSONRegExp = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_REGEXP; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - - // Check the pattern for 0 bytes - if (value.pattern.match(regexp) != null) { - // The BSON spec doesn't allow keys with null bytes because keys are - // null-terminated. - throw Error('pattern ' + value.pattern + ' must not contain null bytes'); - } - - // Adjust the index - index = index + buffer.write(value.pattern, index, 'utf8'); - // Write zero - buffer[index++] = 0x00; - // Write the options - index = - index + - buffer.write( - value.options - .split('') - .sort() - .join(''), - index, - 'utf8' - ); - // Add ending zero - buffer[index++] = 0x00; - return index; -}; - -var serializeMinMax = function(buffer, key, value, index, isArray) { - // Write the type of either min or max key - if (value === null) { - buffer[index++] = BSON.BSON_DATA_NULL; - } else if (value._bsontype === 'MinKey') { - buffer[index++] = BSON.BSON_DATA_MIN_KEY; - } else { - buffer[index++] = BSON.BSON_DATA_MAX_KEY; - } - - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - return index; -}; - -var serializeObjectId = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_OID; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - - // Write the objectId into the shared buffer - if (typeof value.id === 'string') { - buffer.write(value.id, index, 'binary'); - } else if (value.id && value.id.copy) { - value.id.copy(buffer, index, 0, 12); - } else { - throw new Error('object [' + JSON.stringify(value) + '] is not a valid ObjectId'); - } - - // Ajust index - return index + 12; -}; - -var serializeBuffer = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_BINARY; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Get size of the buffer (current write point) - var size = value.length; - // Write the size of the string to buffer - buffer[index++] = size & 0xff; - buffer[index++] = (size >> 8) & 0xff; - buffer[index++] = (size >> 16) & 0xff; - buffer[index++] = (size >> 24) & 0xff; - // Write the default subtype - buffer[index++] = BSON.BSON_BINARY_SUBTYPE_DEFAULT; - // Copy the content form the binary field to the buffer - value.copy(buffer, index, 0, size); - // Adjust the index - index = index + size; - return index; -}; - -var serializeObject = function( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - isArray, - path -) { - for (var i = 0; i < path.length; i++) { - if (path[i] === value) throw new Error('cyclic dependency detected'); - } - - // Push value to stack - path.push(value); - // Write the type - buffer[index++] = Array.isArray(value) ? BSON.BSON_DATA_ARRAY : BSON.BSON_DATA_OBJECT; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - var endIndex = serializeInto( - buffer, - value, - checkKeys, - index, - depth + 1, - serializeFunctions, - ignoreUndefined, - path - ); - // Pop stack - path.pop(); - // Write size - return endIndex; -}; - -var serializeDecimal128 = function(buffer, key, value, index, isArray) { - buffer[index++] = BSON.BSON_DATA_DECIMAL128; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write the data from the value - value.bytes.copy(buffer, index, 0, 16); - return index + 16; -}; - -var serializeLong = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = value._bsontype === 'Long' ? BSON.BSON_DATA_LONG : BSON.BSON_DATA_TIMESTAMP; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write the date - var lowBits = value.getLowBits(); - var highBits = value.getHighBits(); - // Encode low bits - buffer[index++] = lowBits & 0xff; - buffer[index++] = (lowBits >> 8) & 0xff; - buffer[index++] = (lowBits >> 16) & 0xff; - buffer[index++] = (lowBits >> 24) & 0xff; - // Encode high bits - buffer[index++] = highBits & 0xff; - buffer[index++] = (highBits >> 8) & 0xff; - buffer[index++] = (highBits >> 16) & 0xff; - buffer[index++] = (highBits >> 24) & 0xff; - return index; -}; - -var serializeInt32 = function(buffer, key, value, index, isArray) { - // Set int type 32 bits or less - buffer[index++] = BSON.BSON_DATA_INT; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write the int value - buffer[index++] = value & 0xff; - buffer[index++] = (value >> 8) & 0xff; - buffer[index++] = (value >> 16) & 0xff; - buffer[index++] = (value >> 24) & 0xff; - return index; -}; - -var serializeDouble = function(buffer, key, value, index, isArray) { - // Encode as double - buffer[index++] = BSON.BSON_DATA_NUMBER; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write float - writeIEEE754(buffer, value, index, 'little', 52, 8); - // Ajust index - index = index + 8; - return index; -}; - -var serializeFunction = function(buffer, key, value, index, checkKeys, depth, isArray) { - buffer[index++] = BSON.BSON_DATA_CODE; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Function string - var functionString = normalizedFunctionString(value); - - // Write the string - var size = buffer.write(functionString, index + 4, 'utf8') + 1; - // Write the size of the string to buffer - buffer[index] = size & 0xff; - buffer[index + 1] = (size >> 8) & 0xff; - buffer[index + 2] = (size >> 16) & 0xff; - buffer[index + 3] = (size >> 24) & 0xff; - // Update index - index = index + 4 + size - 1; - // Write zero - buffer[index++] = 0; - return index; -}; - -var serializeCode = function( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - isArray -) { - if (value.scope && typeof value.scope === 'object') { - // Write the type - buffer[index++] = BSON.BSON_DATA_CODE_W_SCOPE; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - - // Starting index - var startIndex = index; - - // Serialize the function - // Get the function string - var functionString = typeof value.code === 'string' ? value.code : value.code.toString(); - // Index adjustment - index = index + 4; - // Write string into buffer - var codeSize = buffer.write(functionString, index + 4, 'utf8') + 1; - // Write the size of the string to buffer - buffer[index] = codeSize & 0xff; - buffer[index + 1] = (codeSize >> 8) & 0xff; - buffer[index + 2] = (codeSize >> 16) & 0xff; - buffer[index + 3] = (codeSize >> 24) & 0xff; - // Write end 0 - buffer[index + 4 + codeSize - 1] = 0; - // Write the - index = index + codeSize + 4; - - // - // Serialize the scope value - var endIndex = serializeInto( - buffer, - value.scope, - checkKeys, - index, - depth + 1, - serializeFunctions, - ignoreUndefined - ); - index = endIndex - 1; - - // Writ the total - var totalSize = endIndex - startIndex; - - // Write the total size of the object - buffer[startIndex++] = totalSize & 0xff; - buffer[startIndex++] = (totalSize >> 8) & 0xff; - buffer[startIndex++] = (totalSize >> 16) & 0xff; - buffer[startIndex++] = (totalSize >> 24) & 0xff; - // Write trailing zero - buffer[index++] = 0; - } else { - buffer[index++] = BSON.BSON_DATA_CODE; - // Number of written bytes - numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Function string - functionString = value.code.toString(); - // Write the string - var size = buffer.write(functionString, index + 4, 'utf8') + 1; - // Write the size of the string to buffer - buffer[index] = size & 0xff; - buffer[index + 1] = (size >> 8) & 0xff; - buffer[index + 2] = (size >> 16) & 0xff; - buffer[index + 3] = (size >> 24) & 0xff; - // Update index - index = index + 4 + size - 1; - // Write zero - buffer[index++] = 0; - } - - return index; -}; - -var serializeBinary = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_BINARY; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Extract the buffer - var data = value.value(true); - // Calculate size - var size = value.position; - // Add the deprecated 02 type 4 bytes of size to total - if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) size = size + 4; - // Write the size of the string to buffer - buffer[index++] = size & 0xff; - buffer[index++] = (size >> 8) & 0xff; - buffer[index++] = (size >> 16) & 0xff; - buffer[index++] = (size >> 24) & 0xff; - // Write the subtype to the buffer - buffer[index++] = value.sub_type; - - // If we have binary type 2 the 4 first bytes are the size - if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) { - size = size - 4; - buffer[index++] = size & 0xff; - buffer[index++] = (size >> 8) & 0xff; - buffer[index++] = (size >> 16) & 0xff; - buffer[index++] = (size >> 24) & 0xff; - } - - // Write the data to the object - data.copy(buffer, index, 0, value.position); - // Adjust the index - index = index + value.position; - return index; -}; - -var serializeSymbol = function(buffer, key, value, index, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_SYMBOL; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - // Write the string - var size = buffer.write(value.value, index + 4, 'utf8') + 1; - // Write the size of the string to buffer - buffer[index] = size & 0xff; - buffer[index + 1] = (size >> 8) & 0xff; - buffer[index + 2] = (size >> 16) & 0xff; - buffer[index + 3] = (size >> 24) & 0xff; - // Update index - index = index + 4 + size - 1; - // Write zero - buffer[index++] = 0x00; - return index; -}; - -var serializeDBRef = function(buffer, key, value, index, depth, serializeFunctions, isArray) { - // Write the type - buffer[index++] = BSON.BSON_DATA_OBJECT; - // Number of written bytes - var numberOfWrittenBytes = !isArray - ? buffer.write(key, index, 'utf8') - : buffer.write(key, index, 'ascii'); - - // Encode the name - index = index + numberOfWrittenBytes; - buffer[index++] = 0; - - var startIndex = index; - var endIndex; - - // Serialize object - if (null != value.db) { - endIndex = serializeInto( - buffer, - { - $ref: value.namespace, - $id: value.oid, - $db: value.db - }, - false, - index, - depth + 1, - serializeFunctions - ); - } else { - endIndex = serializeInto( - buffer, - { - $ref: value.namespace, - $id: value.oid - }, - false, - index, - depth + 1, - serializeFunctions - ); - } - - // Calculate object size - var size = endIndex - startIndex; - // Write the size - buffer[startIndex++] = size & 0xff; - buffer[startIndex++] = (size >> 8) & 0xff; - buffer[startIndex++] = (size >> 16) & 0xff; - buffer[startIndex++] = (size >> 24) & 0xff; - // Set index - return endIndex; -}; - -var serializeInto = function serializeInto( - buffer, - object, - checkKeys, - startingIndex, - depth, - serializeFunctions, - ignoreUndefined, - path -) { - startingIndex = startingIndex || 0; - path = path || []; - - // Push the object to the path - path.push(object); - - // Start place to serialize into - var index = startingIndex + 4; - // var self = this; - - // Special case isArray - if (Array.isArray(object)) { - // Get object keys - for (var i = 0; i < object.length; i++) { - var key = '' + i; - var value = object[i]; - - // Is there an override value - if (value && value.toBSON) { - if (typeof value.toBSON !== 'function') throw new Error('toBSON is not a function'); - value = value.toBSON(); - } - - var type = typeof value; - if (type === 'string') { - index = serializeString(buffer, key, value, index, true); - } else if (type === 'number') { - index = serializeNumber(buffer, key, value, index, true); - } else if(type === 'bigint') { - throw new TypeError('Unsupported type BigInt, please use Decimal128'); - } else if (type === 'boolean') { - index = serializeBoolean(buffer, key, value, index, true); - } else if (value instanceof Date || isDate(value)) { - index = serializeDate(buffer, key, value, index, true); - } else if (value === undefined) { - index = serializeNull(buffer, key, value, index, true); - } else if (value === null) { - index = serializeNull(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { - index = serializeObjectId(buffer, key, value, index, true); - } else if (Buffer.isBuffer(value)) { - index = serializeBuffer(buffer, key, value, index, true); - } else if (value instanceof RegExp || isRegExp(value)) { - index = serializeRegExp(buffer, key, value, index, true); - } else if (type === 'object' && value['_bsontype'] == null) { - index = serializeObject( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - true, - path - ); - } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { - index = serializeDecimal128(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { - index = serializeLong(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'Double') { - index = serializeDouble(buffer, key, value, index, true); - } else if (typeof value === 'function' && serializeFunctions) { - index = serializeFunction( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - true - ); - } else if (value['_bsontype'] === 'Code') { - index = serializeCode( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - true - ); - } else if (value['_bsontype'] === 'Binary') { - index = serializeBinary(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'Symbol') { - index = serializeSymbol(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'DBRef') { - index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, true); - } else if (value['_bsontype'] === 'BSONRegExp') { - index = serializeBSONRegExp(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'Int32') { - index = serializeInt32(buffer, key, value, index, true); - } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { - index = serializeMinMax(buffer, key, value, index, true); - } else if (typeof value['_bsontype'] !== 'undefined') { - throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); - } - } - } else if (object instanceof Map) { - var iterator = object.entries(); - var done = false; - - while (!done) { - // Unpack the next entry - var entry = iterator.next(); - done = entry.done; - // Are we done, then skip and terminate - if (done) continue; - - // Get the entry values - key = entry.value[0]; - value = entry.value[1]; - - // Check the type of the value - type = typeof value; - - // Check the key and throw error if it's illegal - if (typeof key === 'string' && ignoreKeys.indexOf(key) === -1) { - if (key.match(regexp) != null) { - // The BSON spec doesn't allow keys with null bytes because keys are - // null-terminated. - throw Error('key ' + key + ' must not contain null bytes'); - } - - if (checkKeys) { - if ('$' === key[0]) { - throw Error('key ' + key + " must not start with '$'"); - } else if (~key.indexOf('.')) { - throw Error('key ' + key + " must not contain '.'"); - } - } - } - - if (type === 'string') { - index = serializeString(buffer, key, value, index); - } else if (type === 'number') { - index = serializeNumber(buffer, key, value, index); - } else if(type === 'bigint') { - throw new TypeError('Unsupported type BigInt, please use Decimal128'); - } else if (type === 'boolean') { - index = serializeBoolean(buffer, key, value, index); - } else if (value instanceof Date || isDate(value)) { - index = serializeDate(buffer, key, value, index); - // } else if (value === undefined && ignoreUndefined === true) { - } else if (value === null || (value === undefined && ignoreUndefined === false)) { - index = serializeNull(buffer, key, value, index); - } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { - index = serializeObjectId(buffer, key, value, index); - } else if (Buffer.isBuffer(value)) { - index = serializeBuffer(buffer, key, value, index); - } else if (value instanceof RegExp || isRegExp(value)) { - index = serializeRegExp(buffer, key, value, index); - } else if (type === 'object' && value['_bsontype'] == null) { - index = serializeObject( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - false, - path - ); - } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { - index = serializeDecimal128(buffer, key, value, index); - } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { - index = serializeLong(buffer, key, value, index); - } else if (value['_bsontype'] === 'Double') { - index = serializeDouble(buffer, key, value, index); - } else if (value['_bsontype'] === 'Code') { - index = serializeCode( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined - ); - } else if (typeof value === 'function' && serializeFunctions) { - index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions); - } else if (value['_bsontype'] === 'Binary') { - index = serializeBinary(buffer, key, value, index); - } else if (value['_bsontype'] === 'Symbol') { - index = serializeSymbol(buffer, key, value, index); - } else if (value['_bsontype'] === 'DBRef') { - index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions); - } else if (value['_bsontype'] === 'BSONRegExp') { - index = serializeBSONRegExp(buffer, key, value, index); - } else if (value['_bsontype'] === 'Int32') { - index = serializeInt32(buffer, key, value, index); - } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { - index = serializeMinMax(buffer, key, value, index); - } else if (typeof value['_bsontype'] !== 'undefined') { - throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); - } - } - } else { - // Did we provide a custom serialization method - if (object.toBSON) { - if (typeof object.toBSON !== 'function') throw new Error('toBSON is not a function'); - object = object.toBSON(); - if (object != null && typeof object !== 'object') - throw new Error('toBSON function did not return an object'); - } - - // Iterate over all the keys - for (key in object) { - value = object[key]; - // Is there an override value - if (value && value.toBSON) { - if (typeof value.toBSON !== 'function') throw new Error('toBSON is not a function'); - value = value.toBSON(); - } - - // Check the type of the value - type = typeof value; - - // Check the key and throw error if it's illegal - if (typeof key === 'string' && ignoreKeys.indexOf(key) === -1) { - if (key.match(regexp) != null) { - // The BSON spec doesn't allow keys with null bytes because keys are - // null-terminated. - throw Error('key ' + key + ' must not contain null bytes'); - } - - if (checkKeys) { - if ('$' === key[0]) { - throw Error('key ' + key + " must not start with '$'"); - } else if (~key.indexOf('.')) { - throw Error('key ' + key + " must not contain '.'"); - } - } - } - - if (type === 'string') { - index = serializeString(buffer, key, value, index); - } else if (type === 'number') { - index = serializeNumber(buffer, key, value, index); - } else if(type === 'bigint') { - throw new TypeError('Unsupported type BigInt, please use Decimal128'); - } else if (type === 'boolean') { - index = serializeBoolean(buffer, key, value, index); - } else if (value instanceof Date || isDate(value)) { - index = serializeDate(buffer, key, value, index); - } else if (value === undefined) { - if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index); - } else if (value === null) { - index = serializeNull(buffer, key, value, index); - } else if (value['_bsontype'] === 'ObjectID' || value['_bsontype'] === 'ObjectId') { - index = serializeObjectId(buffer, key, value, index); - } else if (Buffer.isBuffer(value)) { - index = serializeBuffer(buffer, key, value, index); - } else if (value instanceof RegExp || isRegExp(value)) { - index = serializeRegExp(buffer, key, value, index); - } else if (type === 'object' && value['_bsontype'] == null) { - index = serializeObject( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined, - false, - path - ); - } else if (type === 'object' && value['_bsontype'] === 'Decimal128') { - index = serializeDecimal128(buffer, key, value, index); - } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') { - index = serializeLong(buffer, key, value, index); - } else if (value['_bsontype'] === 'Double') { - index = serializeDouble(buffer, key, value, index); - } else if (value['_bsontype'] === 'Code') { - index = serializeCode( - buffer, - key, - value, - index, - checkKeys, - depth, - serializeFunctions, - ignoreUndefined - ); - } else if (typeof value === 'function' && serializeFunctions) { - index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions); - } else if (value['_bsontype'] === 'Binary') { - index = serializeBinary(buffer, key, value, index); - } else if (value['_bsontype'] === 'Symbol') { - index = serializeSymbol(buffer, key, value, index); - } else if (value['_bsontype'] === 'DBRef') { - index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions); - } else if (value['_bsontype'] === 'BSONRegExp') { - index = serializeBSONRegExp(buffer, key, value, index); - } else if (value['_bsontype'] === 'Int32') { - index = serializeInt32(buffer, key, value, index); - } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') { - index = serializeMinMax(buffer, key, value, index); - } else if (typeof value['_bsontype'] !== 'undefined') { - throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']); - } - } - } - - // Remove the path - path.pop(); - - // Final padding byte for object - buffer[index++] = 0x00; - - // Final size - var size = index - startingIndex; - // Write the size of the object - buffer[startingIndex++] = size & 0xff; - buffer[startingIndex++] = (size >> 8) & 0xff; - buffer[startingIndex++] = (size >> 16) & 0xff; - buffer[startingIndex++] = (size >> 24) & 0xff; - return index; -}; - -var BSON = {}; - -/** - * Contains the function cache if we have that enable to allow for avoiding the eval step on each deserialization, comparison is by md5 - * - * @ignore - * @api private - */ -// var functionCache = (BSON.functionCache = {}); - -/** - * Number BSON Type - * - * @classconstant BSON_DATA_NUMBER - **/ -BSON.BSON_DATA_NUMBER = 1; -/** - * String BSON Type - * - * @classconstant BSON_DATA_STRING - **/ -BSON.BSON_DATA_STRING = 2; -/** - * Object BSON Type - * - * @classconstant BSON_DATA_OBJECT - **/ -BSON.BSON_DATA_OBJECT = 3; -/** - * Array BSON Type - * - * @classconstant BSON_DATA_ARRAY - **/ -BSON.BSON_DATA_ARRAY = 4; -/** - * Binary BSON Type - * - * @classconstant BSON_DATA_BINARY - **/ -BSON.BSON_DATA_BINARY = 5; -/** - * ObjectID BSON Type, deprecated - * - * @classconstant BSON_DATA_UNDEFINED - **/ -BSON.BSON_DATA_UNDEFINED = 6; -/** - * ObjectID BSON Type - * - * @classconstant BSON_DATA_OID - **/ -BSON.BSON_DATA_OID = 7; -/** - * Boolean BSON Type - * - * @classconstant BSON_DATA_BOOLEAN - **/ -BSON.BSON_DATA_BOOLEAN = 8; -/** - * Date BSON Type - * - * @classconstant BSON_DATA_DATE - **/ -BSON.BSON_DATA_DATE = 9; -/** - * null BSON Type - * - * @classconstant BSON_DATA_NULL - **/ -BSON.BSON_DATA_NULL = 10; -/** - * RegExp BSON Type - * - * @classconstant BSON_DATA_REGEXP - **/ -BSON.BSON_DATA_REGEXP = 11; -/** - * Code BSON Type - * - * @classconstant BSON_DATA_CODE - **/ -BSON.BSON_DATA_CODE = 13; -/** - * Symbol BSON Type - * - * @classconstant BSON_DATA_SYMBOL - **/ -BSON.BSON_DATA_SYMBOL = 14; -/** - * Code with Scope BSON Type - * - * @classconstant BSON_DATA_CODE_W_SCOPE - **/ -BSON.BSON_DATA_CODE_W_SCOPE = 15; -/** - * 32 bit Integer BSON Type - * - * @classconstant BSON_DATA_INT - **/ -BSON.BSON_DATA_INT = 16; -/** - * Timestamp BSON Type - * - * @classconstant BSON_DATA_TIMESTAMP - **/ -BSON.BSON_DATA_TIMESTAMP = 17; -/** - * Long BSON Type - * - * @classconstant BSON_DATA_LONG - **/ -BSON.BSON_DATA_LONG = 18; -/** - * Long BSON Type - * - * @classconstant BSON_DATA_DECIMAL128 - **/ -BSON.BSON_DATA_DECIMAL128 = 19; -/** - * MinKey BSON Type - * - * @classconstant BSON_DATA_MIN_KEY - **/ -BSON.BSON_DATA_MIN_KEY = 0xff; -/** - * MaxKey BSON Type - * - * @classconstant BSON_DATA_MAX_KEY - **/ -BSON.BSON_DATA_MAX_KEY = 0x7f; -/** - * Binary Default Type - * - * @classconstant BSON_BINARY_SUBTYPE_DEFAULT - **/ -BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; -/** - * Binary Function Type - * - * @classconstant BSON_BINARY_SUBTYPE_FUNCTION - **/ -BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; -/** - * Binary Byte Array Type - * - * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY - **/ -BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; -/** - * Binary UUID Type - * - * @classconstant BSON_BINARY_SUBTYPE_UUID - **/ -BSON.BSON_BINARY_SUBTYPE_UUID = 3; -/** - * Binary MD5 Type - * - * @classconstant BSON_BINARY_SUBTYPE_MD5 - **/ -BSON.BSON_BINARY_SUBTYPE_MD5 = 4; -/** - * Binary User Defined Type - * - * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED - **/ -BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; - -// BSON MAX VALUES -BSON.BSON_INT32_MAX = 0x7fffffff; -BSON.BSON_INT32_MIN = -0x80000000; - -BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; -BSON.BSON_INT64_MIN = -Math.pow(2, 63); - -// JS MAX PRECISE VALUES -BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. -BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. - -// Internal long versions -// var JS_INT_MAX_LONG = Long.fromNumber(0x20000000000000); // Any integer up to 2^53 can be precisely represented by a double. -// var JS_INT_MIN_LONG = Long.fromNumber(-0x20000000000000); // Any integer down to -2^53 can be precisely represented by a double. - -module.exports = serializeInto; - -}).call(this)}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) -},{"../../../../is-buffer/index.js":217,"../binary":29,"../float_parser":35,"../long":37,"../map":38,"./utils":45}],45:[function(require,module,exports){ -(function (Buffer){(function (){ -'use strict'; - -/** - * Normalizes our expected stringified form of a function across versions of node - * @param {Function} fn The function to stringify - */ -function normalizedFunctionString(fn) { - return fn.toString().replace(/function *\(/, 'function ('); -} - -function newBuffer(item, encoding) { - return new Buffer(item, encoding); -} - -function allocBuffer() { - return Buffer.alloc.apply(Buffer, arguments); -} - -function toBuffer() { - return Buffer.from.apply(Buffer, arguments); -} - -module.exports = { - normalizedFunctionString: normalizedFunctionString, - allocBuffer: typeof Buffer.alloc === 'function' ? allocBuffer : newBuffer, - toBuffer: typeof Buffer.from === 'function' ? toBuffer : newBuffer -}; - - -}).call(this)}).call(this,require("buffer").Buffer) -},{"buffer":49}],46:[function(require,module,exports){ -/** - * A class representation of the BSON RegExp type. - * - * @class - * @return {BSONRegExp} A MinKey instance - */ -function BSONRegExp(pattern, options) { - if (!(this instanceof BSONRegExp)) return new BSONRegExp(); - - // Execute - this._bsontype = 'BSONRegExp'; - this.pattern = pattern || ''; - this.options = options || ''; - - // Validate options - for (var i = 0; i < this.options.length; i++) { - if ( - !( - this.options[i] === 'i' || - this.options[i] === 'm' || - this.options[i] === 'x' || - this.options[i] === 'l' || - this.options[i] === 's' || - this.options[i] === 'u' - ) - ) { - throw new Error('the regular expression options [' + this.options[i] + '] is not supported'); - } - } -} - -module.exports = BSONRegExp; -module.exports.BSONRegExp = BSONRegExp; - -},{}],47:[function(require,module,exports){ -(function (Buffer){(function (){ -// Custom inspect property name / symbol. -var inspect = Buffer ? require('util').inspect.custom || 'inspect' : 'inspect'; - -/** - * A class representation of the BSON Symbol type. - * - * @class - * @deprecated - * @param {string} value the string representing the symbol. - * @return {Symbol} - */ -function Symbol(value) { - if (!(this instanceof Symbol)) return new Symbol(value); - this._bsontype = 'Symbol'; - this.value = value; -} - -/** - * Access the wrapped string value. - * - * @method - * @return {String} returns the wrapped string. - */ -Symbol.prototype.valueOf = function() { - return this.value; -}; - -/** - * @ignore - */ -Symbol.prototype.toString = function() { - return this.value; -}; - -/** - * @ignore - */ -Symbol.prototype[inspect] = function() { - return this.value; -}; - -/** - * @ignore - */ -Symbol.prototype.toJSON = function() { - return this.value; -}; - -module.exports = Symbol; -module.exports.Symbol = Symbol; - -}).call(this)}).call(this,require("buffer").Buffer) -},{"buffer":49,"util":378}],48:[function(require,module,exports){ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright 2009 Google Inc. All Rights Reserved - -/** - * This type is for INTERNAL use in MongoDB only and should not be used in applications. - * The appropriate corresponding type is the JavaScript Date type. - * - * Defines a Timestamp class for representing a 64-bit two's-complement - * integer value, which faithfully simulates the behavior of a Java "Timestamp". This - * implementation is derived from TimestampLib in GWT. - * - * Constructs a 64-bit two's-complement integer, given its low and high 32-bit - * values as *signed* integers. See the from* functions below for more - * convenient ways of constructing Timestamps. - * - * The internal representation of a Timestamp is the two given signed, 32-bit values. - * We use 32-bit pieces because these are the size of integers on which - * Javascript performs bit-operations. For operations like addition and - * multiplication, we split each number into 16-bit pieces, which can easily be - * multiplied within Javascript's floating-point representation without overflow - * or change in sign. - * - * In the algorithms below, we frequently reduce the negative case to the - * positive case by negating the input(s) and then post-processing the result. - * Note that we must ALWAYS check specially whether those values are MIN_VALUE - * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as - * a positive number, it overflows back into a negative). Not handling this - * case would often result in infinite recursion. - * - * @class - * @param {number} low the low (signed) 32 bits of the Timestamp. - * @param {number} high the high (signed) 32 bits of the Timestamp. - */ -function Timestamp(low, high) { - if (!(this instanceof Timestamp)) return new Timestamp(low, high); - this._bsontype = 'Timestamp'; - /** - * @type {number} - * @ignore - */ - this.low_ = low | 0; // force into 32 signed bits. - - /** - * @type {number} - * @ignore - */ - this.high_ = high | 0; // force into 32 signed bits. -} - -/** - * Return the int value. - * - * @return {number} the value, assuming it is a 32-bit integer. - */ -Timestamp.prototype.toInt = function() { - return this.low_; -}; - -/** - * Return the Number value. - * - * @method - * @return {number} the closest floating-point representation to this value. - */ -Timestamp.prototype.toNumber = function() { - return this.high_ * Timestamp.TWO_PWR_32_DBL_ + this.getLowBitsUnsigned(); -}; - -/** - * Return the JSON value. - * - * @method - * @return {string} the JSON representation. - */ -Timestamp.prototype.toJSON = function() { - return this.toString(); -}; - -/** - * Return the String value. - * - * @method - * @param {number} [opt_radix] the radix in which the text should be written. - * @return {string} the textual representation of this value. - */ -Timestamp.prototype.toString = function(opt_radix) { - var radix = opt_radix || 10; - if (radix < 2 || 36 < radix) { - throw Error('radix out of range: ' + radix); - } - - if (this.isZero()) { - return '0'; - } - - if (this.isNegative()) { - if (this.equals(Timestamp.MIN_VALUE)) { - // We need to change the Timestamp value before it can be negated, so we remove - // the bottom-most digit in this base and then recurse to do the rest. - var radixTimestamp = Timestamp.fromNumber(radix); - var div = this.div(radixTimestamp); - var rem = div.multiply(radixTimestamp).subtract(this); - return div.toString(radix) + rem.toInt().toString(radix); - } else { - return '-' + this.negate().toString(radix); - } - } - - // Do several (6) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = Timestamp.fromNumber(Math.pow(radix, 6)); - - rem = this; - var result = ''; - - while (!rem.isZero()) { - var remDiv = rem.div(radixToPower); - var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); - var digits = intval.toString(radix); - - rem = remDiv; - if (rem.isZero()) { - return digits + result; - } else { - while (digits.length < 6) { - digits = '0' + digits; - } - result = '' + digits + result; - } - } -}; - -/** - * Return the high 32-bits value. - * - * @method - * @return {number} the high 32-bits as a signed value. - */ -Timestamp.prototype.getHighBits = function() { - return this.high_; -}; - -/** - * Return the low 32-bits value. - * - * @method - * @return {number} the low 32-bits as a signed value. - */ -Timestamp.prototype.getLowBits = function() { - return this.low_; -}; - -/** - * Return the low unsigned 32-bits value. - * - * @method - * @return {number} the low 32-bits as an unsigned value. - */ -Timestamp.prototype.getLowBitsUnsigned = function() { - return this.low_ >= 0 ? this.low_ : Timestamp.TWO_PWR_32_DBL_ + this.low_; -}; - -/** - * Returns the number of bits needed to represent the absolute value of this Timestamp. - * - * @method - * @return {number} Returns the number of bits needed to represent the absolute value of this Timestamp. - */ -Timestamp.prototype.getNumBitsAbs = function() { - if (this.isNegative()) { - if (this.equals(Timestamp.MIN_VALUE)) { - return 64; - } else { - return this.negate().getNumBitsAbs(); - } - } else { - var val = this.high_ !== 0 ? this.high_ : this.low_; - for (var bit = 31; bit > 0; bit--) { - if ((val & (1 << bit)) !== 0) { - break; - } - } - return this.high_ !== 0 ? bit + 33 : bit + 1; - } -}; - -/** - * Return whether this value is zero. - * - * @method - * @return {boolean} whether this value is zero. - */ -Timestamp.prototype.isZero = function() { - return this.high_ === 0 && this.low_ === 0; -}; - -/** - * Return whether this value is negative. - * - * @method - * @return {boolean} whether this value is negative. - */ -Timestamp.prototype.isNegative = function() { - return this.high_ < 0; -}; - -/** - * Return whether this value is odd. - * - * @method - * @return {boolean} whether this value is odd. - */ -Timestamp.prototype.isOdd = function() { - return (this.low_ & 1) === 1; -}; - -/** - * Return whether this Timestamp equals the other - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp equals the other - */ -Timestamp.prototype.equals = function(other) { - return this.high_ === other.high_ && this.low_ === other.low_; -}; - -/** - * Return whether this Timestamp does not equal the other. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp does not equal the other. - */ -Timestamp.prototype.notEquals = function(other) { - return this.high_ !== other.high_ || this.low_ !== other.low_; -}; - -/** - * Return whether this Timestamp is less than the other. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp is less than the other. - */ -Timestamp.prototype.lessThan = function(other) { - return this.compare(other) < 0; -}; - -/** - * Return whether this Timestamp is less than or equal to the other. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp is less than or equal to the other. - */ -Timestamp.prototype.lessThanOrEqual = function(other) { - return this.compare(other) <= 0; -}; - -/** - * Return whether this Timestamp is greater than the other. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp is greater than the other. - */ -Timestamp.prototype.greaterThan = function(other) { - return this.compare(other) > 0; -}; - -/** - * Return whether this Timestamp is greater than or equal to the other. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} whether this Timestamp is greater than or equal to the other. - */ -Timestamp.prototype.greaterThanOrEqual = function(other) { - return this.compare(other) >= 0; -}; - -/** - * Compares this Timestamp with the given one. - * - * @method - * @param {Timestamp} other Timestamp to compare against. - * @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater. - */ -Timestamp.prototype.compare = function(other) { - if (this.equals(other)) { - return 0; - } - - var thisNeg = this.isNegative(); - var otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) { - return -1; - } - if (!thisNeg && otherNeg) { - return 1; - } - - // at this point, the signs are the same, so subtraction will not overflow - if (this.subtract(other).isNegative()) { - return -1; - } else { - return 1; - } -}; - -/** - * The negation of this value. - * - * @method - * @return {Timestamp} the negation of this value. - */ -Timestamp.prototype.negate = function() { - if (this.equals(Timestamp.MIN_VALUE)) { - return Timestamp.MIN_VALUE; - } else { - return this.not().add(Timestamp.ONE); - } -}; - -/** - * Returns the sum of this and the given Timestamp. - * - * @method - * @param {Timestamp} other Timestamp to add to this one. - * @return {Timestamp} the sum of this and the given Timestamp. - */ -Timestamp.prototype.add = function(other) { - // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - - var a48 = this.high_ >>> 16; - var a32 = this.high_ & 0xffff; - var a16 = this.low_ >>> 16; - var a00 = this.low_ & 0xffff; - - var b48 = other.high_ >>> 16; - var b32 = other.high_ & 0xffff; - var b16 = other.low_ >>> 16; - var b00 = other.low_ & 0xffff; - - var c48 = 0, - c32 = 0, - c16 = 0, - c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xffff; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xffff; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xffff; - c48 += a48 + b48; - c48 &= 0xffff; - return Timestamp.fromBits((c16 << 16) | c00, (c48 << 16) | c32); -}; - -/** - * Returns the difference of this and the given Timestamp. - * - * @method - * @param {Timestamp} other Timestamp to subtract from this. - * @return {Timestamp} the difference of this and the given Timestamp. - */ -Timestamp.prototype.subtract = function(other) { - return this.add(other.negate()); -}; - -/** - * Returns the product of this and the given Timestamp. - * - * @method - * @param {Timestamp} other Timestamp to multiply with this. - * @return {Timestamp} the product of this and the other. - */ -Timestamp.prototype.multiply = function(other) { - if (this.isZero()) { - return Timestamp.ZERO; - } else if (other.isZero()) { - return Timestamp.ZERO; - } - - if (this.equals(Timestamp.MIN_VALUE)) { - return other.isOdd() ? Timestamp.MIN_VALUE : Timestamp.ZERO; - } else if (other.equals(Timestamp.MIN_VALUE)) { - return this.isOdd() ? Timestamp.MIN_VALUE : Timestamp.ZERO; - } - - if (this.isNegative()) { - if (other.isNegative()) { - return this.negate().multiply(other.negate()); - } else { - return this.negate() - .multiply(other) - .negate(); - } - } else if (other.isNegative()) { - return this.multiply(other.negate()).negate(); - } - - // If both Timestamps are small, use float multiplication - if (this.lessThan(Timestamp.TWO_PWR_24_) && other.lessThan(Timestamp.TWO_PWR_24_)) { - return Timestamp.fromNumber(this.toNumber() * other.toNumber()); - } - - // Divide each Timestamp into 4 chunks of 16 bits, and then add up 4x4 products. - // We can skip products that would overflow. - - var a48 = this.high_ >>> 16; - var a32 = this.high_ & 0xffff; - var a16 = this.low_ >>> 16; - var a00 = this.low_ & 0xffff; - - var b48 = other.high_ >>> 16; - var b32 = other.high_ & 0xffff; - var b16 = other.low_ >>> 16; - var b00 = other.low_ & 0xffff; - - var c48 = 0, - c32 = 0, - c16 = 0, - c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xffff; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xffff; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xffff; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xffff; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xffff; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xffff; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xffff; - return Timestamp.fromBits((c16 << 16) | c00, (c48 << 16) | c32); -}; - -/** - * Returns this Timestamp divided by the given one. - * - * @method - * @param {Timestamp} other Timestamp by which to divide. - * @return {Timestamp} this Timestamp divided by the given one. - */ -Timestamp.prototype.div = function(other) { - if (other.isZero()) { - throw Error('division by zero'); - } else if (this.isZero()) { - return Timestamp.ZERO; - } - - if (this.equals(Timestamp.MIN_VALUE)) { - if (other.equals(Timestamp.ONE) || other.equals(Timestamp.NEG_ONE)) { - return Timestamp.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE - } else if (other.equals(Timestamp.MIN_VALUE)) { - return Timestamp.ONE; - } else { - // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. - var halfThis = this.shiftRight(1); - var approx = halfThis.div(other).shiftLeft(1); - if (approx.equals(Timestamp.ZERO)) { - return other.isNegative() ? Timestamp.ONE : Timestamp.NEG_ONE; - } else { - var rem = this.subtract(other.multiply(approx)); - var result = approx.add(rem.div(other)); - return result; - } - } - } else if (other.equals(Timestamp.MIN_VALUE)) { - return Timestamp.ZERO; - } - - if (this.isNegative()) { - if (other.isNegative()) { - return this.negate().div(other.negate()); - } else { - return this.negate() - .div(other) - .negate(); - } - } else if (other.isNegative()) { - return this.div(other.negate()).negate(); - } - - // Repeat the following until the remainder is less than other: find a - // floating-point that approximates remainder / other *from below*, add this - // into the result, and subtract it from the remainder. It is critical that - // the approximate value is less than or equal to the real value so that the - // remainder never becomes negative. - var res = Timestamp.ZERO; - rem = this; - while (rem.greaterThanOrEqual(other)) { - // Approximate the result of division. This may be a little greater or - // smaller than the actual value. - approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); - - // We will tweak the approximate result by changing it in the 48-th digit or - // the smallest non-fractional digit, whichever is larger. - var log2 = Math.ceil(Math.log(approx) / Math.LN2); - var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); - - // Decrease the approximation until it is smaller than the remainder. Note - // that if it is too large, the product overflows and is negative. - var approxRes = Timestamp.fromNumber(approx); - var approxRem = approxRes.multiply(other); - while (approxRem.isNegative() || approxRem.greaterThan(rem)) { - approx -= delta; - approxRes = Timestamp.fromNumber(approx); - approxRem = approxRes.multiply(other); - } - - // We know the answer can't be zero... and actually, zero would cause - // infinite recursion since we would make no progress. - if (approxRes.isZero()) { - approxRes = Timestamp.ONE; - } - - res = res.add(approxRes); - rem = rem.subtract(approxRem); - } - return res; -}; - -/** - * Returns this Timestamp modulo the given one. - * - * @method - * @param {Timestamp} other Timestamp by which to mod. - * @return {Timestamp} this Timestamp modulo the given one. - */ -Timestamp.prototype.modulo = function(other) { - return this.subtract(this.div(other).multiply(other)); -}; - -/** - * The bitwise-NOT of this value. - * - * @method - * @return {Timestamp} the bitwise-NOT of this value. - */ -Timestamp.prototype.not = function() { - return Timestamp.fromBits(~this.low_, ~this.high_); -}; - -/** - * Returns the bitwise-AND of this Timestamp and the given one. - * - * @method - * @param {Timestamp} other the Timestamp with which to AND. - * @return {Timestamp} the bitwise-AND of this and the other. - */ -Timestamp.prototype.and = function(other) { - return Timestamp.fromBits(this.low_ & other.low_, this.high_ & other.high_); -}; - -/** - * Returns the bitwise-OR of this Timestamp and the given one. - * - * @method - * @param {Timestamp} other the Timestamp with which to OR. - * @return {Timestamp} the bitwise-OR of this and the other. - */ -Timestamp.prototype.or = function(other) { - return Timestamp.fromBits(this.low_ | other.low_, this.high_ | other.high_); -}; - -/** - * Returns the bitwise-XOR of this Timestamp and the given one. - * - * @method - * @param {Timestamp} other the Timestamp with which to XOR. - * @return {Timestamp} the bitwise-XOR of this and the other. - */ -Timestamp.prototype.xor = function(other) { - return Timestamp.fromBits(this.low_ ^ other.low_, this.high_ ^ other.high_); -}; - -/** - * Returns this Timestamp with bits shifted to the left by the given amount. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Timestamp} this shifted to the left by the given amount. - */ -Timestamp.prototype.shiftLeft = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var low = this.low_; - if (numBits < 32) { - var high = this.high_; - return Timestamp.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits))); - } else { - return Timestamp.fromBits(0, low << (numBits - 32)); - } - } -}; - -/** - * Returns this Timestamp with bits shifted to the right by the given amount. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Timestamp} this shifted to the right by the given amount. - */ -Timestamp.prototype.shiftRight = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var high = this.high_; - if (numBits < 32) { - var low = this.low_; - return Timestamp.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits); - } else { - return Timestamp.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1); - } - } -}; - -/** - * Returns this Timestamp with bits shifted to the right by the given amount, with the new top bits matching the current sign bit. - * - * @method - * @param {number} numBits the number of bits by which to shift. - * @return {Timestamp} this shifted to the right by the given amount, with zeros placed into the new leading bits. - */ -Timestamp.prototype.shiftRightUnsigned = function(numBits) { - numBits &= 63; - if (numBits === 0) { - return this; - } else { - var high = this.high_; - if (numBits < 32) { - var low = this.low_; - return Timestamp.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits); - } else if (numBits === 32) { - return Timestamp.fromBits(high, 0); - } else { - return Timestamp.fromBits(high >>> (numBits - 32), 0); - } - } -}; - -/** - * Returns a Timestamp representing the given (32-bit) integer value. - * - * @method - * @param {number} value the 32-bit integer in question. - * @return {Timestamp} the corresponding Timestamp value. - */ -Timestamp.fromInt = function(value) { - if (-128 <= value && value < 128) { - var cachedObj = Timestamp.INT_CACHE_[value]; - if (cachedObj) { - return cachedObj; - } - } - - var obj = new Timestamp(value | 0, value < 0 ? -1 : 0); - if (-128 <= value && value < 128) { - Timestamp.INT_CACHE_[value] = obj; - } - return obj; -}; - -/** - * Returns a Timestamp representing the given value, provided that it is a finite number. Otherwise, zero is returned. - * - * @method - * @param {number} value the number in question. - * @return {Timestamp} the corresponding Timestamp value. - */ -Timestamp.fromNumber = function(value) { - if (isNaN(value) || !isFinite(value)) { - return Timestamp.ZERO; - } else if (value <= -Timestamp.TWO_PWR_63_DBL_) { - return Timestamp.MIN_VALUE; - } else if (value + 1 >= Timestamp.TWO_PWR_63_DBL_) { - return Timestamp.MAX_VALUE; - } else if (value < 0) { - return Timestamp.fromNumber(-value).negate(); - } else { - return new Timestamp( - (value % Timestamp.TWO_PWR_32_DBL_) | 0, - (value / Timestamp.TWO_PWR_32_DBL_) | 0 - ); - } -}; - -/** - * Returns a Timestamp representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits. - * - * @method - * @param {number} lowBits the low 32-bits. - * @param {number} highBits the high 32-bits. - * @return {Timestamp} the corresponding Timestamp value. - */ -Timestamp.fromBits = function(lowBits, highBits) { - return new Timestamp(lowBits, highBits); -}; - -/** - * Returns a Timestamp representation of the given string, written using the given radix. - * - * @method - * @param {string} str the textual representation of the Timestamp. - * @param {number} opt_radix the radix in which the text is written. - * @return {Timestamp} the corresponding Timestamp value. - */ -Timestamp.fromString = function(str, opt_radix) { - if (str.length === 0) { - throw Error('number format error: empty string'); - } - - var radix = opt_radix || 10; - if (radix < 2 || 36 < radix) { - throw Error('radix out of range: ' + radix); - } - - if (str.charAt(0) === '-') { - return Timestamp.fromString(str.substring(1), radix).negate(); - } else if (str.indexOf('-') >= 0) { - throw Error('number format error: interior "-" character: ' + str); - } - - // Do several (8) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = Timestamp.fromNumber(Math.pow(radix, 8)); - - var result = Timestamp.ZERO; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i); - var value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = Timestamp.fromNumber(Math.pow(radix, size)); - result = result.multiply(power).add(Timestamp.fromNumber(value)); - } else { - result = result.multiply(radixToPower); - result = result.add(Timestamp.fromNumber(value)); - } - } - return result; -}; - -// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the -// from* methods on which they depend. - -/** - * A cache of the Timestamp representations of small integer values. - * @type {Object} - * @ignore - */ -Timestamp.INT_CACHE_ = {}; - -// NOTE: the compiler should inline these constant values below and then remove -// these variables, so there should be no runtime penalty for these. - -/** - * Number used repeated below in calculations. This must appear before the - * first call to any from* function below. - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_16_DBL_ = 1 << 16; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_24_DBL_ = 1 << 24; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_32_DBL_ = Timestamp.TWO_PWR_16_DBL_ * Timestamp.TWO_PWR_16_DBL_; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_31_DBL_ = Timestamp.TWO_PWR_32_DBL_ / 2; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_48_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_16_DBL_; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_64_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_32_DBL_; - -/** - * @type {number} - * @ignore - */ -Timestamp.TWO_PWR_63_DBL_ = Timestamp.TWO_PWR_64_DBL_ / 2; - -/** @type {Timestamp} */ -Timestamp.ZERO = Timestamp.fromInt(0); - -/** @type {Timestamp} */ -Timestamp.ONE = Timestamp.fromInt(1); - -/** @type {Timestamp} */ -Timestamp.NEG_ONE = Timestamp.fromInt(-1); - -/** @type {Timestamp} */ -Timestamp.MAX_VALUE = Timestamp.fromBits(0xffffffff | 0, 0x7fffffff | 0); - -/** @type {Timestamp} */ -Timestamp.MIN_VALUE = Timestamp.fromBits(0, 0x80000000 | 0); - -/** - * @type {Timestamp} - * @ignore - */ -Timestamp.TWO_PWR_24_ = Timestamp.fromInt(1 << 24); - -/** - * Expose. - */ -module.exports = Timestamp; -module.exports.Timestamp = Timestamp; - -},{}],49:[function(require,module,exports){ -(function (Buffer){(function (){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ -/* eslint-disable no-proto */ - -'use strict' - -var base64 = require('base64-js') -var ieee754 = require('ieee754') - -exports.Buffer = Buffer -exports.SlowBuffer = SlowBuffer -exports.INSPECT_MAX_BYTES = 50 - -var K_MAX_LENGTH = 0x7fffffff -exports.kMaxLength = K_MAX_LENGTH - -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ -Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() - -if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && - typeof console.error === 'function') { - console.error( - 'This browser lacks typed array (Uint8Array) support which is required by ' + - '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' - ) -} - -function typedArraySupport () { - // Can typed array instances can be augmented? - try { - var arr = new Uint8Array(1) - arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } - return arr.foo() === 42 - } catch (e) { - return false - } -} - -Object.defineProperty(Buffer.prototype, 'parent', { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined - return this.buffer - } -}) - -Object.defineProperty(Buffer.prototype, 'offset', { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined - return this.byteOffset - } -}) - -function createBuffer (length) { - if (length > K_MAX_LENGTH) { - throw new RangeError('The value "' + length + '" is invalid for option "size"') - } - // Return an augmented `Uint8Array` instance - var buf = new Uint8Array(length) - buf.__proto__ = Buffer.prototype - return buf -} - -/** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - -function Buffer (arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new TypeError( - 'The "string" argument must be of type string. Received type number' - ) - } - return allocUnsafe(arg) - } - return from(arg, encodingOrOffset, length) -} - -// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 -if (typeof Symbol !== 'undefined' && Symbol.species != null && - Buffer[Symbol.species] === Buffer) { - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true, - enumerable: false, - writable: false - }) -} - -Buffer.poolSize = 8192 // not used by this implementation - -function from (value, encodingOrOffset, length) { - if (typeof value === 'string') { - return fromString(value, encodingOrOffset) - } - - if (ArrayBuffer.isView(value)) { - return fromArrayLike(value) - } - - if (value == null) { - throw TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + (typeof value) - ) - } - - if (isInstance(value, ArrayBuffer) || - (value && isInstance(value.buffer, ArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length) - } - - if (typeof value === 'number') { - throw new TypeError( - 'The "value" argument must not be of type number. Received type number' - ) - } - - var valueOf = value.valueOf && value.valueOf() - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length) - } - - var b = fromObject(value) - if (b) return b - - if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && - typeof value[Symbol.toPrimitive] === 'function') { - return Buffer.from( - value[Symbol.toPrimitive]('string'), encodingOrOffset, length - ) - } - - throw new TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + (typeof value) - ) -} - -/** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ -Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length) -} - -// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: -// https://github.com/feross/buffer/pull/148 -Buffer.prototype.__proto__ = Uint8Array.prototype -Buffer.__proto__ = Uint8Array - -function assertSize (size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be of type number') - } else if (size < 0) { - throw new RangeError('The value "' + size + '" is invalid for option "size"') - } -} - -function alloc (size, fill, encoding) { - assertSize(size) - if (size <= 0) { - return createBuffer(size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' - ? createBuffer(size).fill(fill, encoding) - : createBuffer(size).fill(fill) - } - return createBuffer(size) -} - -/** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ -Buffer.alloc = function (size, fill, encoding) { - return alloc(size, fill, encoding) -} - -function allocUnsafe (size) { - assertSize(size) - return createBuffer(size < 0 ? 0 : checked(size) | 0) -} - -/** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ -Buffer.allocUnsafe = function (size) { - return allocUnsafe(size) -} -/** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ -Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(size) -} - -function fromString (string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8' - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - - var length = byteLength(string, encoding) | 0 - var buf = createBuffer(length) - - var actual = buf.write(string, encoding) - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual) - } - - return buf -} - -function fromArrayLike (array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0 - var buf = createBuffer(length) - for (var i = 0; i < length; i += 1) { - buf[i] = array[i] & 255 - } - return buf -} - -function fromArrayBuffer (array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('"offset" is outside of buffer bounds') - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('"length" is outside of buffer bounds') - } - - var buf - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array) - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset) - } else { - buf = new Uint8Array(array, byteOffset, length) - } - - // Return an augmented `Uint8Array` instance - buf.__proto__ = Buffer.prototype - return buf -} - -function fromObject (obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0 - var buf = createBuffer(len) - - if (buf.length === 0) { - return buf - } - - obj.copy(buf, 0, 0, len) - return buf - } - - if (obj.length !== undefined) { - if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { - return createBuffer(0) - } - return fromArrayLike(obj) - } - - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { - return fromArrayLike(obj.data) - } -} - -function checked (length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') - } - return length | 0 -} - -function SlowBuffer (length) { - if (+length != length) { // eslint-disable-line eqeqeq - length = 0 - } - return Buffer.alloc(+length) -} - -Buffer.isBuffer = function isBuffer (b) { - return b != null && b._isBuffer === true && - b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false -} - -Buffer.compare = function compare (a, b) { - if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) - if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError( - 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' - ) - } - - if (a === b) return 0 - - var x = a.length - var y = b.length - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i] - y = b[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 -} - -Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } -} - -Buffer.concat = function concat (list, length) { - if (!Array.isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - - if (list.length === 0) { - return Buffer.alloc(0) - } - - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; ++i) { - length += list[i].length - } - } - - var buffer = Buffer.allocUnsafe(length) - var pos = 0 - for (i = 0; i < list.length; ++i) { - var buf = list[i] - if (isInstance(buf, Uint8Array)) { - buf = Buffer.from(buf) - } - if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - buf.copy(buffer, pos) - pos += buf.length - } - return buffer -} - -function byteLength (string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length - } - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - throw new TypeError( - 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + - 'Received type ' + typeof string - ) - } - - var len = string.length - var mustMatch = (arguments.length > 2 && arguments[2] === true) - if (!mustMatch && len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 - } - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} -Buffer.byteLength = byteLength - -function slowToString (encoding, start, end) { - var loweredCase = false - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0 - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' - } - - if (end === undefined || end > this.length) { - end = this.length - } - - if (end <= 0) { - return '' - } - - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0 - start >>>= 0 - - if (end <= start) { - return '' - } - - if (!encoding) encoding = 'utf8' - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'latin1': - case 'binary': - return latin1Slice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } - } -} - -// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) -// to detect a Buffer instance. It's not possible to use `instanceof Buffer` -// reliably in a browserify context because there could be multiple different -// copies of the 'buffer' package in use. This method works even for Buffer -// instances that were created from another copy of the `buffer` package. -// See: https://github.com/feross/buffer/issues/154 -Buffer.prototype._isBuffer = true - -function swap (b, n, m) { - var i = b[n] - b[n] = b[m] - b[m] = i -} - -Buffer.prototype.swap16 = function swap16 () { - var len = this.length - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1) - } - return this -} - -Buffer.prototype.swap32 = function swap32 () { - var len = this.length - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3) - swap(this, i + 1, i + 2) - } - return this -} - -Buffer.prototype.swap64 = function swap64 () { - var len = this.length - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits') - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7) - swap(this, i + 1, i + 6) - swap(this, i + 2, i + 5) - swap(this, i + 3, i + 4) - } - return this -} - -Buffer.prototype.toString = function toString () { - var length = this.length - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) -} - -Buffer.prototype.toLocaleString = Buffer.prototype.toString - -Buffer.prototype.equals = function equals (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 -} - -Buffer.prototype.inspect = function inspect () { - var str = '' - var max = exports.INSPECT_MAX_BYTES - str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() - if (this.length > max) str += ' ... ' - return '' -} - -Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { - if (isInstance(target, Uint8Array)) { - target = Buffer.from(target, target.offset, target.byteLength) - } - if (!Buffer.isBuffer(target)) { - throw new TypeError( - 'The "target" argument must be one of type Buffer or Uint8Array. ' + - 'Received type ' + (typeof target) - ) - } - - if (start === undefined) { - start = 0 - } - if (end === undefined) { - end = target ? target.length : 0 - } - if (thisStart === undefined) { - thisStart = 0 - } - if (thisEnd === undefined) { - thisEnd = this.length - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } - - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } - - start >>>= 0 - end >>>= 0 - thisStart >>>= 0 - thisEnd >>>= 0 - - if (this === target) return 0 - - var x = thisEnd - thisStart - var y = end - start - var len = Math.min(x, y) - - var thisCopy = this.slice(thisStart, thisEnd) - var targetCopy = target.slice(start, end) - - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i] - y = targetCopy[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 -} - -// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, -// OR the last index of `val` in `buffer` at offset <= `byteOffset`. -// -// Arguments: -// - buffer - a Buffer to search -// - val - a string, Buffer, or number -// - byteOffset - an index into `buffer`; will be clamped to an int32 -// - encoding - an optional encoding, relevant is val is a string -// - dir - true for indexOf, false for lastIndexOf -function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1 - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset - byteOffset = 0 - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000 - } - byteOffset = +byteOffset // Coerce to Number. - if (numberIsNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : (buffer.length - 1) - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset - if (byteOffset >= buffer.length) { - if (dir) return -1 - else byteOffset = buffer.length - 1 - } else if (byteOffset < 0) { - if (dir) byteOffset = 0 - else return -1 - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding) - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir) - } else if (typeof val === 'number') { - val = val & 0xFF // Search for a byte value [0-255] - if (typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) - } - } - return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) - } - - throw new TypeError('val must be string, number or Buffer') -} - -function arrayIndexOf (arr, val, byteOffset, encoding, dir) { - var indexSize = 1 - var arrLength = arr.length - var valLength = val.length - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase() - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2 - arrLength /= 2 - valLength /= 2 - byteOffset /= 2 - } - } - - function read (buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } - } - - var i - if (dir) { - var foundIndex = -1 - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex - foundIndex = -1 - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength - for (i = byteOffset; i >= 0; i--) { - var found = true - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false - break - } - } - if (found) return i - } - } - - return -1 -} - -Buffer.prototype.includes = function includes (val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 -} - -Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true) -} - -Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false) -} - -function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - - var strLen = string.length - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (numberIsNaN(parsed)) return i - buf[offset + i] = parsed - } - return i -} - -function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) -} - -function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) -} - -function latin1Write (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) -} - -function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) -} - -function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) -} - -Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0 - if (isFinite(length)) { - length = length >>> 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined - } - } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) - } - - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8' - - var loweredCase = false - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'latin1': - case 'binary': - return latin1Write(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} - -Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } -} - -function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) - } -} - -function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end) - var res = [] - - var i = start - while (i < end) { - var firstByte = buf[i] - var codePoint = null - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte - } - break - case 2: - secondByte = buf[i + 1] - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint - } - } - break - case 3: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint - } - } - break - case 4: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - fourthByte = buf[i + 3] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD - bytesPerSequence = 1 - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000 - res.push(codePoint >>> 10 & 0x3FF | 0xD800) - codePoint = 0xDC00 | codePoint & 0x3FF - } - - res.push(codePoint) - i += bytesPerSequence - } - - return decodeCodePointsArray(res) -} - -// Based on http://stackoverflow.com/a/22747272/680742, the browser with -// the lowest limit is Chrome, with 0x10000 args. -// We go 1 magnitude less, for safety -var MAX_ARGUMENTS_LENGTH = 0x1000 - -function decodeCodePointsArray (codePoints) { - var len = codePoints.length - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = '' - var i = 0 - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ) - } - return res -} - -function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret -} - -function latin1Slice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]) - } - return ret -} - -function hexSlice (buf, start, end) { - var len = buf.length - - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len - - var out = '' - for (var i = start; i < end; ++i) { - out += toHex(buf[i]) - } - return out -} - -function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) - } - return res -} - -Buffer.prototype.slice = function slice (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len - } - - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len - } - - if (end < start) end = start - - var newBuf = this.subarray(start, end) - // Return an augmented `Uint8Array` instance - newBuf.__proto__ = Buffer.prototype - return newBuf -} - -/* - * Need to make sure that buffer isn't trying to write out of bounds. - */ -function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') -} - -Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - - return val -} - -Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) - } - - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } - - return val -} - -Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] -} - -Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) -} - -Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] -} - -Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) -} - -Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) -} - -Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) -} - -Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) -} - -Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) -} - -Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) -} - -Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) -} - -Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) -} - -Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) -} - -function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') -} - -Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - this[offset] = (value & 0xff) - return offset + 1 -} - -Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - return offset + 2 -} - -Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - return offset + 2 -} - -Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - return offset + 4 -} - -Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - return offset + 4 -} - -Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - var limit = Math.pow(2, (8 * byteLength) - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = 0 - var mul = 1 - var sub = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - var limit = Math.pow(2, (8 * byteLength) - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = byteLength - 1 - var mul = 1 - var sub = 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (value < 0) value = 0xff + value + 1 - this[offset] = (value & 0xff) - return offset + 1 -} - -Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - return offset + 2 -} - -Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - return offset + 2 -} - -Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - return offset + 4 -} - -Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - return offset + 4 -} - -function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') -} - -function writeFloat (buf, value, offset, littleEndian, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 -} - -Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) -} - -function writeDouble (buf, value, offset, littleEndian, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 -} - -Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) -} - -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('Index out of range') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start - } - - var len = end - start - - if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { - // Use built-in when available, missing from IE11 - this.copyWithin(targetStart, start, end) - } else if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (var i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, end), - targetStart - ) - } - - return len -} - -// Usage: -// buffer.fill(number[, offset[, end]]) -// buffer.fill(buffer[, offset[, end]]) -// buffer.fill(string[, offset[, end]][, encoding]) -Buffer.prototype.fill = function fill (val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start - start = 0 - end = this.length - } else if (typeof end === 'string') { - encoding = end - end = this.length - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - if (val.length === 1) { - var code = val.charCodeAt(0) - if ((encoding === 'utf8' && code < 128) || - encoding === 'latin1') { - // Fast path: If `val` fits into a single byte, use that numeric value. - val = code - } + // Shared functions + AbstractDate.prototype.isPrecise = function () { + var _this = this; + // @ts-ignore + return this.constructor.FIELDS.every(function (field) { return _this[field] != null; }); + }; + AbstractDate.prototype.isImprecise = function () { + return !this.isPrecise(); + }; + AbstractDate.prototype.isMorePrecise = function (other) { + // @ts-ignore + if (typeof other === 'string' && this.constructor.FIELDS.includes(other)) { + // @ts-ignore + if (this[other] == null) { + return false; + } + } + else { + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // @ts-ignore + if (other[field] != null && this[field] == null) { + return false; + } + } + } + return !this.isSamePrecision(other); + }; + // This function can take another Date-ish object, or a precision string (e.g. 'month') + AbstractDate.prototype.isLessPrecise = function (other) { + return !this.isSamePrecision(other) && !this.isMorePrecise(other); + }; + // This function can take another Date-ish object, or a precision string (e.g. 'month') + AbstractDate.prototype.isSamePrecision = function (other) { + // @ts-ignore + if (typeof other === 'string' && this.constructor.FIELDS.includes(other)) { + return other === this.getPrecision(); + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // @ts-ignore + if (this[field] != null && other[field] == null) { + return false; + } + // @ts-ignore + if (this[field] == null && other[field] != null) { + return false; + } + } + return true; + }; + AbstractDate.prototype.equals = function (other) { + return compareWithDefaultResult(this, other, null); + }; + AbstractDate.prototype.equivalent = function (other) { + return compareWithDefaultResult(this, other, false); + }; + AbstractDate.prototype.sameAs = function (other, precision) { + if (!(other.isDate || other.isDateTime)) { + return null; + } + else if (this.isDate && other.isDateTime) { + return this.getDateTime().sameAs(other, precision); + } + else if (this.isDateTime && other.isDate) { + other = other.getDateTime(); + } + // @ts-ignore + if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { + throw new Error("Invalid precision: ".concat(precision)); + } + // make a copy of other in the correct timezone offset if they don't match. + // When comparing DateTime values with different timezone offsets, implementations + // should normalize to the timezone offset of the evaluation request timestamp, + // but only when the comparison precision is hours, minutes, seconds, or milliseconds. + if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { + if (this.timezoneOffset !== other.timezoneOffset) { + other = other.convertToTimezoneOffset(this.timezoneOffset); + } + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + // @ts-ignore + if (this[field] != null && other[field] != null) { + // if they are different then return with false + // @ts-ignore + if (this[field] !== other[field]) { + return false; + } + // if both dont have this precision, return true of precision is not defined + // @ts-ignore + } + else if (this[field] == null && other[field] == null) { + if (precision == null) { + return true; + } + else { + // we havent met precision yet + return null; + } + // otherwise they have inconclusive precision, return null + } + else { + return null; + } + // if precision is defined and we have reached expected precision, we can leave the loop + if (precision != null && precision === field) { + break; + } + } + // if we made it here, then all fields matched. + return true; + }; + AbstractDate.prototype.sameOrBefore = function (other, precision) { + if (!(other.isDate || other.isDateTime)) { + return null; + } + else if (this.isDate && other.isDateTime) { + return this.getDateTime().sameOrBefore(other, precision); + } + else if (this.isDateTime && other.isDate) { + other = other.getDateTime(); + } + // @ts-ignore + if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { + throw new Error("Invalid precision: ".concat(precision)); + } + // make a copy of other in the correct timezone offset if they don't match. + // When comparing DateTime values with different timezone offsets, implementations + // should normalize to the timezone offset of the evaluation request timestamp, + // but only when the comparison precision is hours, minutes, seconds, or milliseconds. + if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { + if (this.timezoneOffset !== other.timezoneOffset) { + other = other.convertToTimezoneOffset(this.timezoneOffset); + } + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + // @ts-ignore + if (this[field] != null && other[field] != null) { + // if this value is less than the other return with true. this is before other + // @ts-ignore + if (this[field] < other[field]) { + return true; + // if this value is greater than the other return with false. this is after + // @ts-ignore + } + else if (this[field] > other[field]) { + return false; + } + // execution continues if the values are the same + // if both dont have this precision, return true if precision is not defined + // @ts-ignore + } + else if (this[field] == null && other[field] == null) { + if (precision == null) { + return true; + } + else { + // we havent met precision yet + return null; + } + // otherwise they have inconclusive precision, return null + } + else { + return null; + } + // if precision is defined and we have reached expected precision, we can leave the loop + if (precision != null && precision === field) { + break; + } + } + // if we made it here, then all fields matched and they are same + return true; + }; + AbstractDate.prototype.sameOrAfter = function (other, precision) { + if (!(other.isDate || other.isDateTime)) { + return null; + } + else if (this.isDate && other.isDateTime) { + return this.getDateTime().sameOrAfter(other, precision); + } + else if (this.isDateTime && other.isDate) { + other = other.getDateTime(); + } + // @ts-ignore + if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { + throw new Error("Invalid precision: ".concat(precision)); + } + // make a copy of other in the correct timezone offset if they don't match. + // When comparing DateTime values with different timezone offsets, implementations + // should normalize to the timezone offset of the evaluation request timestamp, + // but only when the comparison precision is hours, minutes, seconds, or milliseconds. + if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { + if (this.timezoneOffset !== other.timezoneOffset) { + other = other.convertToTimezoneOffset(this.timezoneOffset); + } + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + // @ts-ignore + if (this[field] != null && other[field] != null) { + // if this value is greater than the other return with true. this is after other + // @ts-ignore + if (this[field] > other[field]) { + return true; + // if this value is greater than the other return with false. this is before + // @ts-ignore + } + else if (this[field] < other[field]) { + return false; + } + // execution continues if the values are the same + // if both dont have this precision, return true if precision is not defined + // @ts-ignore + } + else if (this[field] == null && other[field] == null) { + if (precision == null) { + return true; + } + else { + // we havent met precision yet + return null; + } + // otherwise they have inconclusive precision, return null + } + else { + return null; + } + // if precision is defined and we have reached expected precision, we can leave the loop + if (precision != null && precision === field) { + break; + } + } + // if we made it here, then all fields matched and they are same + return true; + }; + AbstractDate.prototype.before = function (other, precision) { + if (!(other.isDate || other.isDateTime)) { + return null; + } + else if (this.isDate && other.isDateTime) { + return this.getDateTime().before(other, precision); + } + else if (this.isDateTime && other.isDate) { + other = other.getDateTime(); + } + // @ts-ignore + if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { + throw new Error("Invalid precision: ".concat(precision)); + } + // make a copy of other in the correct timezone offset if they don't match. + // When comparing DateTime values with different timezone offsets, implementations + // should normalize to the timezone offset of the evaluation request timestamp, + // but only when the comparison precision is hours, minutes, seconds, or milliseconds. + if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { + if (this.timezoneOffset !== other.timezoneOffset) { + other = other.convertToTimezoneOffset(this.timezoneOffset); + } + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + // @ts-ignore + if (this[field] != null && other[field] != null) { + // if this value is less than the other return with true. this is before other + // @ts-ignore + if (this[field] < other[field]) { + return true; + // if this value is greater than the other return with false. this is after + // @ts-ignore + } + else if (this[field] > other[field]) { + return false; + } + // execution continues if the values are the same + // if both dont have this precision, return false if precision is not defined + // @ts-ignore + } + else if (this[field] == null && other[field] == null) { + if (precision == null) { + return false; + } + else { + // we havent met precision yet + return null; + } + // otherwise they have inconclusive precision, return null + } + else { + return null; + } + // if precision is defined and we have reached expected precision, we can leave the loop + if (precision != null && precision === field) { + break; + } + } + // if we made it here, then all fields matched and they are same + return false; + }; + AbstractDate.prototype.after = function (other, precision) { + if (!(other.isDate || other.isDateTime)) { + return null; + } + else if (this.isDate && other.isDateTime) { + return this.getDateTime().after(other, precision); + } + else if (this.isDateTime && other.isDate) { + other = other.getDateTime(); + } + // @ts-ignore + if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { + throw new Error("Invalid precision: ".concat(precision)); + } + // make a copy of other in the correct timezone offset if they don't match. + // When comparing DateTime values with different timezone offsets, implementations + // should normalize to the timezone offset of the evaluation request timestamp, + // but only when the comparison precision is hours, minutes, seconds, or milliseconds. + if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { + if (this.timezoneOffset !== other.timezoneOffset) { + other = other.convertToTimezoneOffset(this.timezoneOffset); + } + } + // @ts-ignore + for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + // @ts-ignore + if (this[field] != null && other[field] != null) { + // if this value is greater than the other return with true. this is after other + // @ts-ignore + if (this[field] > other[field]) { + return true; + // if this value is greater than the other return with false. this is before + // @ts-ignore + } + else if (this[field] < other[field]) { + return false; + } + // execution continues if the values are the same + // if both dont have this precision, return false if precision is not defined + // @ts-ignore + } + else if (this[field] == null && other[field] == null) { + if (precision == null) { + return false; + } + else { + // we havent met precision yet + return null; + } + // otherwise they have inconclusive precision, return null + } + else { + return null; + } + // if precision is defined and we have reached expected precision, we can leave the loop + if (precision != null && precision === field) { + break; + } + } + // if we made it here, then all fields matched and they are same + return false; + }; + AbstractDate.prototype.add = function (offset, field) { + var _a; + if (offset === 0 || this.year == null) { + return this.copy(); + } + // Use luxon to do the date math because it honors DST and it has the leap-year/end-of-month semantics we want. + // NOTE: The luxonDateTime will contain default values where this[unit] is null, but we'll account for that. + var luxonDateTime = this.toLuxonDateTime(); + // From the spec: "The operation is performed by converting the time-based quantity to the most precise value + // specified in the date/time (truncating any resulting decimal portion) and then adding it to the date/time value." + // However, since you can't really convert days to months, if "this" is less precise than the field being added, we can + // add to the earliest possible value of "this" or subtract from the latest possible value of "this" (depending on the + // sign of the offset), and then null out the imprecise fields again after doing the calculation. Due to the way + // luxonDateTime is constructed above, it is already at the earliest value, so only adjust if the offset is negative. + // @ts-ignore + var offsetIsMorePrecise = this[field] == null; //whether the quantity we are adding is more precise than "this". + if (offsetIsMorePrecise && offset < 0) { + luxonDateTime = luxonDateTime.endOf(this.getPrecision()); + } + // Now do the actual math and convert it back to a Date/DateTime w/ originally null fields nulled out again + var luxonResult = luxonDateTime.plus((_a = {}, _a[field] = offset, _a)); + var result = this.constructor + .fromLuxonDateTime(luxonResult) + .reducedPrecision(this.getPrecision()); + // Luxon never has a null offset, but sometimes "this" does, so reset to null if applicable + if (this.isDateTime && this.timezoneOffset == null) { + result.timezoneOffset = null; + } + // Can't use overflowsOrUnderflows from math.js due to circular dependencies when we require it + if (result.after(exports.MAX_DATETIME_VALUE || result.before(exports.MIN_DATETIME_VALUE))) { + return null; + } + else { + return result; + } + }; + AbstractDate.prototype.getFieldFloor = function (field) { + switch (field) { + case 'month': + return 1; + case 'day': + return 1; + case 'hour': + return 0; + case 'minute': + return 0; + case 'second': + return 0; + case 'millisecond': + return 0; + default: + throw new Error('Tried to floor a field that has no floor value: ' + field); + } + }; + AbstractDate.prototype.getFieldCieling = function (field) { + switch (field) { + case 'month': + return 12; + case 'day': + return daysInMonth(this.year, this.month); + case 'hour': + return 23; + case 'minute': + return 59; + case 'second': + return 59; + case 'millisecond': + return 999; + default: + throw new Error('Tried to clieling a field that has no cieling value: ' + field); + } + }; + return AbstractDate; +}()); +var DateTime = /** @class */ (function (_super) { + __extends(DateTime, _super); + function DateTime(year, month, day, hour, minute, second, millisecond, timezoneOffset) { + if (year === void 0) { year = null; } + if (month === void 0) { month = null; } + if (day === void 0) { day = null; } + if (hour === void 0) { hour = null; } + if (minute === void 0) { minute = null; } + if (second === void 0) { second = null; } + if (millisecond === void 0) { millisecond = null; } + var _this = + // from the spec: If no timezone is specified, the timezone of the evaluation request timestamp is used. + // NOTE: timezoneOffset will be explicitly null for the Time overload, whereas + // it will be undefined if simply unspecified + _super.call(this, year, month, day) || this; + _this.hour = hour; + _this.minute = minute; + _this.second = second; + _this.millisecond = millisecond; + if (timezoneOffset === undefined) { + _this.timezoneOffset = (new util_1.jsDate().getTimezoneOffset() / 60) * -1; + } + else { + _this.timezoneOffset = timezoneOffset; + } + return _this; } - } else if (typeof val === 'number') { - val = val & 255 - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } - - if (end <= start) { - return this - } - - start = start >>> 0 - end = end === undefined ? this.length : end >>> 0 - - if (!val) val = 0 - - var i - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val + DateTime.parse = function (string) { + if (string === null) { + return null; + } + var matches = /(\d{4})(-(\d{2}))?(-(\d{2}))?(T((\d{2})(:(\d{2})(:(\d{2})(\.(\d+))?)?)?)?(Z|(([+-])(\d{2})(:?(\d{2}))?))?)?/.exec(string); + if (matches == null) { + return null; + } + var years = matches[1]; + var months = matches[3]; + var days = matches[5]; + var hours = matches[8]; + var minutes = matches[10]; + var seconds = matches[12]; + var milliseconds = matches[14]; + if (milliseconds != null) { + milliseconds = (0, util_1.normalizeMillisecondsField)(milliseconds); + } + if (milliseconds != null) { + string = (0, util_1.normalizeMillisecondsFieldInString)(string, matches[14]); + } + if (!isValidDateTimeStringFormat(string)) { + return null; + } + // convert the args to integers + var args = [years, months, days, hours, minutes, seconds, milliseconds].map(function (arg) { + return arg != null ? parseInt(arg) : arg; + }); + // convert timezone offset to decimal and add it to arguments + if (matches[18] != null) { + var num = parseInt(matches[18]) + (matches[20] != null ? parseInt(matches[20]) / 60 : 0); + args.push(matches[17] === '+' ? num : num * -1); + } + else if (matches[15] === 'Z') { + args.push(0); + } + // @ts-ignore + return new (DateTime.bind.apply(DateTime, __spreadArray([void 0], args, false)))(); + }; + // TODO: Note: using the jsDate type causes issues, fix later + DateTime.fromJSDate = function (date, timezoneOffset) { + //This is from a JS Date, not a CQL Date + if (date instanceof DateTime) { + return date; + } + if (timezoneOffset != null) { + date = new util_1.jsDate(date.getTime() + timezoneOffset * 60 * 60 * 1000); + return new DateTime(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds(), timezoneOffset); + } + else { + return new DateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); + } + }; + DateTime.fromLuxonDateTime = function (luxonDT) { + if (luxonDT instanceof DateTime) { + return luxonDT; + } + return new DateTime(luxonDT.year, luxonDT.month, luxonDT.day, luxonDT.hour, luxonDT.minute, luxonDT.second, luxonDT.millisecond, luxonDT.offset / 60); + }; + Object.defineProperty(DateTime.prototype, "isDateTime", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(DateTime.prototype, "isDate", { + get: function () { + return false; + }, + enumerable: false, + configurable: true + }); + DateTime.prototype.copy = function () { + return new DateTime(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond, this.timezoneOffset); + }; + DateTime.prototype.successor = function () { + if (this.millisecond != null) { + return this.add(1, DateTime.Unit.MILLISECOND); + } + else if (this.second != null) { + return this.add(1, DateTime.Unit.SECOND); + } + else if (this.minute != null) { + return this.add(1, DateTime.Unit.MINUTE); + } + else if (this.hour != null) { + return this.add(1, DateTime.Unit.HOUR); + } + else if (this.day != null) { + return this.add(1, DateTime.Unit.DAY); + } + else if (this.month != null) { + return this.add(1, DateTime.Unit.MONTH); + } + else if (this.year != null) { + return this.add(1, DateTime.Unit.YEAR); + } + }; + DateTime.prototype.predecessor = function () { + if (this.millisecond != null) { + return this.add(-1, DateTime.Unit.MILLISECOND); + } + else if (this.second != null) { + return this.add(-1, DateTime.Unit.SECOND); + } + else if (this.minute != null) { + return this.add(-1, DateTime.Unit.MINUTE); + } + else if (this.hour != null) { + return this.add(-1, DateTime.Unit.HOUR); + } + else if (this.day != null) { + return this.add(-1, DateTime.Unit.DAY); + } + else if (this.month != null) { + return this.add(-1, DateTime.Unit.MONTH); + } + else if (this.year != null) { + return this.add(-1, DateTime.Unit.YEAR); + } + }; + DateTime.prototype.convertToTimezoneOffset = function (timezoneOffset) { + if (timezoneOffset === void 0) { timezoneOffset = 0; } + var shiftedLuxonDT = this.toLuxonDateTime().setZone(luxon_1.FixedOffsetZone.instance(timezoneOffset * 60)); + var shiftedDT = DateTime.fromLuxonDateTime(shiftedLuxonDT); + return shiftedDT.reducedPrecision(this.getPrecision()); + }; + DateTime.prototype.differenceBetween = function (other, unitField) { + other = this._implicitlyConvert(other); + if (other == null || !other.isDateTime) { + return null; + } + // According to CQL spec: + // * "Difference calculations are performed by truncating the datetime values at the next precision, + // and then performing the corresponding duration calculation on the truncated values." + // * "When difference is calculated for hours or finer units, timezone offsets should be normalized + // prior to truncation to correctly consider real (actual elapsed) time. When difference is calculated + // for days or coarser units, however, the time components (including timezone offset) should be truncated + // without normalization to correctly reflect the difference in calendar days, months, and years." + var a = this.toLuxonUncertainty(); + var b = other.toLuxonUncertainty(); + // If unit is days or above, reset all the DateTimes to UTC since TZ offset should not be considered; + // Otherwise, we don't actually have to "normalize" to a common TZ because Luxon takes TZ into account. + if ([DateTime.Unit.YEAR, DateTime.Unit.MONTH, DateTime.Unit.WEEK, DateTime.Unit.DAY].includes(unitField)) { + a.low = a.low.toUTC(0, { keepLocalTime: true }); + a.high = a.high.toUTC(0, { keepLocalTime: true }); + b.low = b.low.toUTC(0, { keepLocalTime: true }); + b.high = b.high.toUTC(0, { keepLocalTime: true }); + } + // Truncate all dates at precision below specified unit + a.low = truncateLuxonDateTime(a.low, unitField); + a.high = truncateLuxonDateTime(a.high, unitField); + b.low = truncateLuxonDateTime(b.low, unitField); + b.high = truncateLuxonDateTime(b.high, unitField); + // Return the duration based on the normalize and truncated values + return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + }; + DateTime.prototype.durationBetween = function (other, unitField) { + other = this._implicitlyConvert(other); + if (other == null || !other.isDateTime) { + return null; + } + var a = this.toLuxonUncertainty(); + var b = other.toLuxonUncertainty(); + return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + }; + DateTime.prototype.isUTC = function () { + // A timezoneOffset of 0 indicates UTC time. + return !this.timezoneOffset; + }; + DateTime.prototype.getPrecision = function () { + var result = null; + if (this.year != null) { + result = DateTime.Unit.YEAR; + } + else { + return result; + } + if (this.month != null) { + result = DateTime.Unit.MONTH; + } + else { + return result; + } + if (this.day != null) { + result = DateTime.Unit.DAY; + } + else { + return result; + } + if (this.hour != null) { + result = DateTime.Unit.HOUR; + } + else { + return result; + } + if (this.minute != null) { + result = DateTime.Unit.MINUTE; + } + else { + return result; + } + if (this.second != null) { + result = DateTime.Unit.SECOND; + } + else { + return result; + } + if (this.millisecond != null) { + result = DateTime.Unit.MILLISECOND; + } + return result; + }; + DateTime.prototype.getPrecisionValue = function () { + return this.isTime() + ? TIME_PRECISION_VALUE_MAP.get(this.getPrecision()) + : DATETIME_PRECISION_VALUE_MAP.get(this.getPrecision()); + }; + DateTime.prototype.toLuxonDateTime = function () { + var _a, _b, _c, _d, _e, _f, _g; + var offsetMins = this.timezoneOffset != null + ? this.timezoneOffset * 60 + : new util_1.jsDate().getTimezoneOffset() * -1; + return luxon_1.DateTime.fromObject({ + year: (_a = this.year) !== null && _a !== void 0 ? _a : undefined, + month: (_b = this.month) !== null && _b !== void 0 ? _b : undefined, + day: (_c = this.day) !== null && _c !== void 0 ? _c : undefined, + hour: (_d = this.hour) !== null && _d !== void 0 ? _d : undefined, + minute: (_e = this.minute) !== null && _e !== void 0 ? _e : undefined, + second: (_f = this.second) !== null && _f !== void 0 ? _f : undefined, + millisecond: (_g = this.millisecond) !== null && _g !== void 0 ? _g : undefined, + zone: luxon_1.FixedOffsetZone.instance(offsetMins) + }); + }; + DateTime.prototype.toLuxonUncertainty = function () { + var low = this.toLuxonDateTime(); + var high = low.endOf(this.getPrecision()); + return new uncertainty_1.Uncertainty(low, high); + }; + DateTime.prototype.toJSDate = function (ignoreTimezone) { + if (ignoreTimezone === void 0) { ignoreTimezone = false; } + var luxonDT = this.toLuxonDateTime(); + // I don't know if anyone is using "ignoreTimezone" anymore (we aren't), but just in case + if (ignoreTimezone) { + var offset = new util_1.jsDate().getTimezoneOffset() * -1; + luxonDT = luxonDT.setZone(luxon_1.FixedOffsetZone.instance(offset), { keepLocalTime: true }); + } + return luxonDT.toJSDate(); + }; + DateTime.prototype.toJSON = function () { + return this.toString(); + }; + DateTime.prototype._pad = function (num) { + return String('0' + num).slice(-2); + }; + DateTime.prototype.toString = function () { + if (this.isTime()) { + return this.toStringTime(); + } + else { + return this.toStringDateTime(); + } + }; + DateTime.prototype.toStringTime = function () { + var str = ''; + if (this.hour != null) { + str += this._pad(this.hour); + if (this.minute != null) { + str += ':' + this._pad(this.minute); + if (this.second != null) { + str += ':' + this._pad(this.second); + if (this.millisecond != null) { + str += '.' + String('00' + this.millisecond).slice(-3); + } + } + } + } + return str; + }; + DateTime.prototype.toStringDateTime = function () { + var str = ''; + if (this.year != null) { + str += this.year; + if (this.month != null) { + str += '-' + this._pad(this.month); + if (this.day != null) { + str += '-' + this._pad(this.day); + if (this.hour != null) { + str += 'T' + this._pad(this.hour); + if (this.minute != null) { + str += ':' + this._pad(this.minute); + if (this.second != null) { + str += ':' + this._pad(this.second); + if (this.millisecond != null) { + str += '.' + String('00' + this.millisecond).slice(-3); + } + } + } + } + } + } + } + if (str.indexOf('T') !== -1 && this.timezoneOffset != null) { + str += this.timezoneOffset < 0 ? '-' : '+'; + var offsetHours = Math.floor(Math.abs(this.timezoneOffset)); + str += this._pad(offsetHours); + var offsetMin = (Math.abs(this.timezoneOffset) - offsetHours) * 60; + str += ':' + this._pad(offsetMin); + } + return str; + }; + DateTime.prototype.getDateTime = function () { + return this; + }; + DateTime.prototype.getDate = function () { + return new Date(this.year, this.month, this.day); + }; + DateTime.prototype.getTime = function () { + // Times no longer have timezoneOffets, so we must explicitly set it to null + return new DateTime(0, 1, 1, this.hour, this.minute, this.second, this.millisecond, null); + }; + DateTime.prototype.isTime = function () { + return this.year === 0 && this.month === 1 && this.day === 1; + }; + DateTime.prototype._implicitlyConvert = function (other) { + if (other != null && other.isDate) { + return other.getDateTime(); + } + return other; + }; + DateTime.prototype.reducedPrecision = function (unitField) { + if (unitField === void 0) { unitField = DateTime.Unit.MILLISECOND; } + var reduced = this.copy(); + if (unitField != null && unitField !== DateTime.Unit.MILLISECOND) { + var fieldIndex = DateTime.FIELDS.indexOf(unitField); + var fieldsToRemove = DateTime.FIELDS.slice(fieldIndex + 1); + for (var _i = 0, fieldsToRemove_1 = fieldsToRemove; _i < fieldsToRemove_1.length; _i++) { + var field = fieldsToRemove_1[_i]; + // @ts-ignore + reduced[field] = null; + } + } + return reduced; + }; + DateTime.Unit = { + YEAR: 'year', + MONTH: 'month', + WEEK: 'week', + DAY: 'day', + HOUR: 'hour', + MINUTE: 'minute', + SECOND: 'second', + MILLISECOND: 'millisecond' + }; + DateTime.FIELDS = [ + DateTime.Unit.YEAR, + DateTime.Unit.MONTH, + DateTime.Unit.DAY, + DateTime.Unit.HOUR, + DateTime.Unit.MINUTE, + DateTime.Unit.SECOND, + DateTime.Unit.MILLISECOND + ]; + return DateTime; +}(AbstractDate)); +exports.DateTime = DateTime; +var Date = /** @class */ (function (_super) { + __extends(Date, _super); + function Date(year, month, day) { + if (year === void 0) { year = null; } + if (month === void 0) { month = null; } + if (day === void 0) { day = null; } + return _super.call(this, year, month, day) || this; } - } else { - var bytes = Buffer.isBuffer(val) - ? val - : Buffer.from(val, encoding) - var len = bytes.length - if (len === 0) { - throw new TypeError('The value "' + val + - '" is invalid for argument "value"') + Date.parse = function (string) { + if (string === null) { + return null; + } + var matches = /(\d{4})(-(\d{2}))?(-(\d{2}))?/.exec(string); + if (matches == null) { + return null; + } + var years = matches[1]; + var months = matches[3]; + var days = matches[5]; + if (!isValidDateStringFormat(string)) { + return null; + } + // convert args to integers + var args = [years, months, days].map(function (arg) { return (arg != null ? parseInt(arg) : arg); }); + // @ts-ignore + return new (Date.bind.apply(Date, __spreadArray([void 0], args, false)))(); + }; + Object.defineProperty(Date.prototype, "isDate", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Date.prototype, "isDateTime", { + get: function () { + return false; + }, + enumerable: false, + configurable: true + }); + Date.prototype.copy = function () { + return new Date(this.year, this.month, this.day); + }; + Date.prototype.successor = function () { + if (this.day != null) { + return this.add(1, Date.Unit.DAY); + } + else if (this.month != null) { + return this.add(1, Date.Unit.MONTH); + } + else if (this.year != null) { + return this.add(1, Date.Unit.YEAR); + } + }; + Date.prototype.predecessor = function () { + if (this.day != null) { + return this.add(-1, Date.Unit.DAY); + } + else if (this.month != null) { + return this.add(-1, Date.Unit.MONTH); + } + else if (this.year != null) { + return this.add(-1, Date.Unit.YEAR); + } + }; + Date.prototype.differenceBetween = function (other, unitField) { + if (other != null && other.isDateTime) { + return this.getDateTime().differenceBetween(other, unitField); + } + if (other == null || !other.isDate) { + return null; + } + // According to CQL spec: + // * "Difference calculations are performed by truncating the datetime values at the next precision, + // and then performing the corresponding duration calculation on the truncated values." + var a = this.toLuxonUncertainty(); + var b = other.toLuxonUncertainty(); + // Truncate all dates at precision below specified unit + a.low = truncateLuxonDateTime(a.low, unitField); + a.high = truncateLuxonDateTime(a.high, unitField); + b.low = truncateLuxonDateTime(b.low, unitField); + b.high = truncateLuxonDateTime(b.high, unitField); + // Return the duration based on the normalize and truncated values + return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + }; + Date.prototype.durationBetween = function (other, unitField) { + if (other != null && other.isDateTime) { + return this.getDateTime().durationBetween(other, unitField); + } + if (other == null || !other.isDate) { + return null; + } + var a = this.toLuxonUncertainty(); + var b = other.toLuxonUncertainty(); + return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + }; + Date.prototype.getPrecision = function () { + var result = null; + if (this.year != null) { + result = Date.Unit.YEAR; + } + else { + return result; + } + if (this.month != null) { + result = Date.Unit.MONTH; + } + else { + return result; + } + if (this.day != null) { + result = Date.Unit.DAY; + } + else { + return result; + } + return result; + }; + Date.prototype.getPrecisionValue = function () { + return DATETIME_PRECISION_VALUE_MAP.get(this.getPrecision()); + }; + Date.prototype.toLuxonDateTime = function () { + var _a, _b, _c; + return luxon_1.DateTime.fromObject({ + year: (_a = this.year) !== null && _a !== void 0 ? _a : undefined, + month: (_b = this.month) !== null && _b !== void 0 ? _b : undefined, + day: (_c = this.day) !== null && _c !== void 0 ? _c : undefined, + zone: luxon_1.FixedOffsetZone.utcInstance + }); + }; + Date.prototype.toLuxonUncertainty = function () { + var low = this.toLuxonDateTime(); + var high = low.endOf(this.getPrecision()).startOf('day'); // Date type is always at T00:00:00.0 + return new uncertainty_1.Uncertainty(low, high); + }; + Date.prototype.toJSDate = function () { + var _a = [ + this.year, + this.month != null ? this.month - 1 : 0, + this.day != null ? this.day : 1 + ], y = _a[0], mo = _a[1], d = _a[2]; + return new util_1.jsDate(y, mo, d); + }; + Date.fromJSDate = function (date) { + if (date instanceof Date) { + return date; + } + return new Date(date.getFullYear(), date.getMonth() + 1, date.getDate()); + }; + Date.fromLuxonDateTime = function (luxonDT) { + if (luxonDT instanceof Date) { + return luxonDT; + } + return new Date(luxonDT.year, luxonDT.month, luxonDT.day); + }; + Date.prototype.toJSON = function () { + return this.toString(); + }; + Date.prototype.toString = function () { + var str = ''; + if (this.year != null) { + str += this.year.toString(); + if (this.month != null) { + str += '-' + this.month.toString().padStart(2, '0'); + if (this.day != null) { + str += '-' + this.day.toString().padStart(2, '0'); + } + } + } + return str; + }; + Date.prototype.getDateTime = function () { + // from the spec: the result will be a DateTime with the time components unspecified, + // except for the timezone offset, which will be set to the timezone offset of the evaluation + // request timestamp. (this last part is achieved by just not passing in timezone offset) + if (this.year != null && this.month != null && this.day != null) { + return new DateTime(this.year, this.month, this.day, null, null, null, null); + // from spec: no component may be specified at a precision below an unspecified precision. + // For example, hour may be null, but if it is, minute, second, and millisecond must all be null as well. + } + else { + return new DateTime(this.year, this.month, this.day); + } + }; + Date.prototype.reducedPrecision = function (unitField) { + if (unitField === void 0) { unitField = Date.Unit.DAY; } + var reduced = this.copy(); + if (unitField !== Date.Unit.DAY) { + var fieldIndex = Date.FIELDS.indexOf(unitField); + var fieldsToRemove = Date.FIELDS.slice(fieldIndex + 1); + for (var _i = 0, fieldsToRemove_2 = fieldsToRemove; _i < fieldsToRemove_2.length; _i++) { + var field = fieldsToRemove_2[_i]; + // @ts-ignore + reduced[field] = null; + } + } + return reduced; + }; + Date.Unit = { YEAR: 'year', MONTH: 'month', WEEK: 'week', DAY: 'day' }; + Date.FIELDS = [Date.Unit.YEAR, Date.Unit.MONTH, Date.Unit.DAY]; + return Date; +}(AbstractDate)); +exports.Date = Date; +// Require MIN/MAX here because math.js requires this file, and when we make this file require +// math.js before it exports DateTime and Date, it errors due to the circular dependency... +// const { MAX_DATETIME_VALUE, MIN_DATETIME_VALUE } = require('../util/math'); +exports.MIN_DATETIME_VALUE = DateTime.parse('0001-01-01T00:00:00.000'); +exports.MAX_DATETIME_VALUE = DateTime.parse('9999-12-31T23:59:59.999'); +exports.MIN_DATE_VALUE = Date.parse('0001-01-01'); +exports.MAX_DATE_VALUE = Date.parse('9999-12-31'); +exports.MIN_TIME_VALUE = (_a = DateTime.parse('0000-01-01T00:00:00.000')) === null || _a === void 0 ? void 0 : _a.getTime(); +exports.MAX_TIME_VALUE = (_b = DateTime.parse('0000-01-01T23:59:59.999')) === null || _b === void 0 ? void 0 : _b.getTime(); +var DATETIME_PRECISION_VALUE_MAP = (function () { + var dtpvMap = new Map(); + dtpvMap.set(DateTime.Unit.YEAR, 4); + dtpvMap.set(DateTime.Unit.MONTH, 6); + dtpvMap.set(DateTime.Unit.DAY, 8); + dtpvMap.set(DateTime.Unit.HOUR, 10); + dtpvMap.set(DateTime.Unit.MINUTE, 12); + dtpvMap.set(DateTime.Unit.SECOND, 14); + dtpvMap.set(DateTime.Unit.MILLISECOND, 17); + return dtpvMap; +})(); +var TIME_PRECISION_VALUE_MAP = (function () { + var tpvMap = new Map(); + tpvMap.set(DateTime.Unit.HOUR, 2); + tpvMap.set(DateTime.Unit.MINUTE, 4); + tpvMap.set(DateTime.Unit.SECOND, 6); + tpvMap.set(DateTime.Unit.MILLISECOND, 9); + return tpvMap; +})(); +function compareWithDefaultResult(a, b, defaultResult) { + // return false there is a type mismatch + if ((!a.isDate || !b.isDate) && (!a.isDateTime || !b.isDateTime)) { + return false; } - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len] + // make a copy of other in the correct timezone offset if they don't match. + if (a.timezoneOffset !== b.timezoneOffset) { + b = b.convertToTimezoneOffset(a.timezoneOffset); } - } - - return this -} - -// HELPER FUNCTIONS -// ================ - -var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g - -function base64clean (str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split('=')[0] - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = str.trim().replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str -} - -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} - -function utf8ToBytes (string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] - - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i) - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue + for (var _i = 0, _a = a.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + // if both have this precision defined + if (a[field] != null && b[field] != null) { + // For the purposes of comparison, seconds and milliseconds are combined + // as a single precision using a decimal, with decimal equality semantics + if (field === 'second') { + // NOTE: if millisecond is null it will calcualte like this anyway, but + // if millisecond is undefined, using it will result in NaN calculations + var aMillisecond = a['millisecond'] != null ? a['millisecond'] : 0; + var aSecondAndMillisecond = a[field] + aMillisecond / 1000; + var bMillisecond = b['millisecond'] != null ? b['millisecond'] : 0; + var bSecondAndMillisecond = b[field] + bMillisecond / 1000; + // second/millisecond is the most precise comparison, so we can directly return + return aSecondAndMillisecond === bSecondAndMillisecond; + } + // if they are different then return with false + if (a[field] !== b[field]) { + return false; + } + // if both dont have this precision, return true + } + else if (a[field] == null && b[field] == null) { + return true; + // otherwise they have inconclusive precision, return defaultResult + } + else { + return defaultResult; } - - // valid lead - leadSurrogate = codePoint - - continue - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - } - - leadSurrogate = null - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') } - } - - return bytes -} - -function asciiToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray -} - -function utf16leToBytes (str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray -} - -function base64ToBytes (str) { - return base64.toByteArray(base64clean(str)) -} - -function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] - } - return i -} - -// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass -// the `instanceof` check but they should be treated as of that type. -// See: https://github.com/feross/buffer/issues/166 -function isInstance (obj, type) { - return obj instanceof type || - (obj != null && obj.constructor != null && obj.constructor.name != null && - obj.constructor.name === type.name) -} -function numberIsNaN (obj) { - // For IE11 support - return obj !== obj // eslint-disable-line no-self-compare -} - -}).call(this)}).call(this,require("buffer").Buffer) -},{"base64-js":27,"buffer":49,"ieee754":214}],50:[function(require,module,exports){ -'use strict'; - -var GetIntrinsic = require('get-intrinsic'); - -var callBind = require('./'); - -var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf')); - -module.exports = function callBoundIntrinsic(name, allowMissing) { - var intrinsic = GetIntrinsic(name, !!allowMissing); - if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) { - return callBind(intrinsic); - } - return intrinsic; -}; - -},{"./":51,"get-intrinsic":52}],51:[function(require,module,exports){ -'use strict'; - -var bind = require('function-bind'); -var GetIntrinsic = require('get-intrinsic'); - -var $apply = GetIntrinsic('%Function.prototype.apply%'); -var $call = GetIntrinsic('%Function.prototype.call%'); -var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); - -var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true); -var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); -var $max = GetIntrinsic('%Math.max%'); - -if ($defineProperty) { - try { - $defineProperty({}, 'a', { value: 1 }); - } catch (e) { - // IE 8 has a broken defineProperty - $defineProperty = null; - } -} - -module.exports = function callBind(originalFunction) { - var func = $reflectApply(bind, $call, arguments); - if ($gOPD && $defineProperty) { - var desc = $gOPD(func, 'length'); - if (desc.configurable) { - // original length, plus the receiver, minus any additional arguments (after the receiver) - $defineProperty( - func, - 'length', - { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) } - ); - } - } - return func; -}; - -var applyBind = function applyBind() { - return $reflectApply(bind, $apply, arguments); -}; - -if ($defineProperty) { - $defineProperty(module.exports, 'apply', { value: applyBind }); -} else { - module.exports.apply = applyBind; + // if we made it here, then all fields matched. + return true; } - -},{"function-bind":198,"get-intrinsic":52}],52:[function(require,module,exports){ -'use strict'; - -var undefined; - -var $SyntaxError = SyntaxError; -var $Function = Function; -var $TypeError = TypeError; - -// eslint-disable-next-line consistent-return -var getEvalledConstructor = function (expressionSyntax) { - try { - return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); - } catch (e) {} -}; - -var $gOPD = Object.getOwnPropertyDescriptor; -if ($gOPD) { - try { - $gOPD({}, ''); - } catch (e) { - $gOPD = null; // this is IE 8, which has a broken gOPD - } +function daysInMonth(year, month) { + if (year == null || month == null) { + throw new Error('daysInMonth requires year and month as arguments'); + } + // Month is 1-indexed here because of the 0 day + return new util_1.jsDate(year, month, 0).getDate(); } - -var throwTypeError = function () { - throw new $TypeError(); -}; -var ThrowTypeError = $gOPD - ? (function () { - try { - // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties - arguments.callee; // IE 8 does not throw here - return throwTypeError; - } catch (calleeThrows) { - try { - // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') - return $gOPD(arguments, 'callee').get; - } catch (gOPDthrows) { - return throwTypeError; - } - } - }()) - : throwTypeError; - -var hasSymbols = require('has-symbols')(); - -var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto - -var needsEval = {}; - -var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array); - -var INTRINSICS = { - '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, - '%Array%': Array, - '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, - '%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined, - '%AsyncFromSyncIteratorPrototype%': undefined, - '%AsyncFunction%': needsEval, - '%AsyncGenerator%': needsEval, - '%AsyncGeneratorFunction%': needsEval, - '%AsyncIteratorPrototype%': needsEval, - '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, - '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, - '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array, - '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array, - '%Boolean%': Boolean, - '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, - '%Date%': Date, - '%decodeURI%': decodeURI, - '%decodeURIComponent%': decodeURIComponent, - '%encodeURI%': encodeURI, - '%encodeURIComponent%': encodeURIComponent, - '%Error%': Error, - '%eval%': eval, // eslint-disable-line no-eval - '%EvalError%': EvalError, - '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, - '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, - '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, - '%Function%': $Function, - '%GeneratorFunction%': needsEval, - '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, - '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, - '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, - '%isFinite%': isFinite, - '%isNaN%': isNaN, - '%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined, - '%JSON%': typeof JSON === 'object' ? JSON : undefined, - '%Map%': typeof Map === 'undefined' ? undefined : Map, - '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()), - '%Math%': Math, - '%Number%': Number, - '%Object%': Object, - '%parseFloat%': parseFloat, - '%parseInt%': parseInt, - '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, - '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, - '%RangeError%': RangeError, - '%ReferenceError%': ReferenceError, - '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, - '%RegExp%': RegExp, - '%Set%': typeof Set === 'undefined' ? undefined : Set, - '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()), - '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, - '%String%': String, - '%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined, - '%Symbol%': hasSymbols ? Symbol : undefined, - '%SyntaxError%': $SyntaxError, - '%ThrowTypeError%': ThrowTypeError, - '%TypedArray%': TypedArray, - '%TypeError%': $TypeError, - '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, - '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, - '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, - '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, - '%URIError%': URIError, - '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, - '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, - '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet -}; - -try { - null.error; // eslint-disable-line no-unused-expressions -} catch (e) { - // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 - var errorProto = getProto(getProto(e)); - INTRINSICS['%Error.prototype%'] = errorProto; +function isValidDateStringFormat(string) { + if (typeof string !== 'string') { + return false; + } + var format = LENGTH_TO_DATE_FORMAT_MAP.get(string.length); + if (format == null) { + return false; + } + return luxon_1.DateTime.fromFormat(string, format).isValid; +} +function isValidDateTimeStringFormat(string) { + if (typeof string !== 'string') { + return false; + } + // Luxon doesn't support +hh offset, so change it to +hh:00 + if (/T[\d:.]*[+-]\d{2}$/.test(string)) { + string += ':00'; + } + var formats = LENGTH_TO_DATETIME_FORMATS_MAP.get(string.length); + if (formats == null) { + return false; + } + return formats.some(function (fmt) { return luxon_1.DateTime.fromFormat(string, fmt).isValid; }); +} +// Will return true if provided precision is unspecified or if +// precision is hours, minutes, seconds, or milliseconds +function isPrecisionUnspecifiedOrGreaterThanDay(precision) { + return precision == null || /^h|mi|s/.test(precision); } -var doEval = function doEval(name) { - var value; - if (name === '%AsyncFunction%') { - value = getEvalledConstructor('async function () {}'); - } else if (name === '%GeneratorFunction%') { - value = getEvalledConstructor('function* () {}'); - } else if (name === '%AsyncGeneratorFunction%') { - value = getEvalledConstructor('async function* () {}'); - } else if (name === '%AsyncGenerator%') { - var fn = doEval('%AsyncGeneratorFunction%'); - if (fn) { - value = fn.prototype; - } - } else if (name === '%AsyncIteratorPrototype%') { - var gen = doEval('%AsyncGenerator%'); - if (gen) { - value = getProto(gen.prototype); - } - } - - INTRINSICS[name] = value; - - return value; -}; - -var LEGACY_ALIASES = { - '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], - '%ArrayPrototype%': ['Array', 'prototype'], - '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], - '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], - '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], - '%ArrayProto_values%': ['Array', 'prototype', 'values'], - '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], - '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], - '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], - '%BooleanPrototype%': ['Boolean', 'prototype'], - '%DataViewPrototype%': ['DataView', 'prototype'], - '%DatePrototype%': ['Date', 'prototype'], - '%ErrorPrototype%': ['Error', 'prototype'], - '%EvalErrorPrototype%': ['EvalError', 'prototype'], - '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], - '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], - '%FunctionPrototype%': ['Function', 'prototype'], - '%Generator%': ['GeneratorFunction', 'prototype'], - '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], - '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], - '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], - '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], - '%JSONParse%': ['JSON', 'parse'], - '%JSONStringify%': ['JSON', 'stringify'], - '%MapPrototype%': ['Map', 'prototype'], - '%NumberPrototype%': ['Number', 'prototype'], - '%ObjectPrototype%': ['Object', 'prototype'], - '%ObjProto_toString%': ['Object', 'prototype', 'toString'], - '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], - '%PromisePrototype%': ['Promise', 'prototype'], - '%PromiseProto_then%': ['Promise', 'prototype', 'then'], - '%Promise_all%': ['Promise', 'all'], - '%Promise_reject%': ['Promise', 'reject'], - '%Promise_resolve%': ['Promise', 'resolve'], - '%RangeErrorPrototype%': ['RangeError', 'prototype'], - '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], - '%RegExpPrototype%': ['RegExp', 'prototype'], - '%SetPrototype%': ['Set', 'prototype'], - '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], - '%StringPrototype%': ['String', 'prototype'], - '%SymbolPrototype%': ['Symbol', 'prototype'], - '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], - '%TypedArrayPrototype%': ['TypedArray', 'prototype'], - '%TypeErrorPrototype%': ['TypeError', 'prototype'], - '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], - '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], - '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], - '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], - '%URIErrorPrototype%': ['URIError', 'prototype'], - '%WeakMapPrototype%': ['WeakMap', 'prototype'], - '%WeakSetPrototype%': ['WeakSet', 'prototype'] -}; - -var bind = require('function-bind'); -var hasOwn = require('has'); -var $concat = bind.call(Function.call, Array.prototype.concat); -var $spliceApply = bind.call(Function.apply, Array.prototype.splice); -var $replace = bind.call(Function.call, String.prototype.replace); -var $strSlice = bind.call(Function.call, String.prototype.slice); -var $exec = bind.call(Function.call, RegExp.prototype.exec); - -/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ -var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; -var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ -var stringToPath = function stringToPath(string) { - var first = $strSlice(string, 0, 1); - var last = $strSlice(string, -1); - if (first === '%' && last !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); - } else if (last === '%' && first !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); - } - var result = []; - $replace(string, rePropName, function (match, number, quote, subString) { - result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; - }); - return result; -}; -/* end adaptation */ - -var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { - var intrinsicName = name; - var alias; - if (hasOwn(LEGACY_ALIASES, intrinsicName)) { - alias = LEGACY_ALIASES[intrinsicName]; - intrinsicName = '%' + alias[0] + '%'; - } - - if (hasOwn(INTRINSICS, intrinsicName)) { - var value = INTRINSICS[intrinsicName]; - if (value === needsEval) { - value = doEval(intrinsicName); - } - if (typeof value === 'undefined' && !allowMissing) { - throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); - } - - return { - alias: alias, - name: intrinsicName, - value: value - }; - } - - throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); -}; - -module.exports = function GetIntrinsic(name, allowMissing) { - if (typeof name !== 'string' || name.length === 0) { - throw new $TypeError('intrinsic name must be a non-empty string'); - } - if (arguments.length > 1 && typeof allowMissing !== 'boolean') { - throw new $TypeError('"allowMissing" argument must be a boolean'); - } - - if ($exec(/^%?[^%]*%?$/, name) === null) { - throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name'); - } - var parts = stringToPath(name); - var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; - - var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); - var intrinsicRealName = intrinsic.name; - var value = intrinsic.value; - var skipFurtherCaching = false; - - var alias = intrinsic.alias; - if (alias) { - intrinsicBaseName = alias[0]; - $spliceApply(parts, $concat([0, 1], alias)); - } - - for (var i = 1, isOwn = true; i < parts.length; i += 1) { - var part = parts[i]; - var first = $strSlice(part, 0, 1); - var last = $strSlice(part, -1); - if ( - ( - (first === '"' || first === "'" || first === '`') - || (last === '"' || last === "'" || last === '`') - ) - && first !== last - ) { - throw new $SyntaxError('property names with quotes must have matching quotes'); - } - if (part === 'constructor' || !isOwn) { - skipFurtherCaching = true; - } - - intrinsicBaseName += '.' + part; - intrinsicRealName = '%' + intrinsicBaseName + '%'; - - if (hasOwn(INTRINSICS, intrinsicRealName)) { - value = INTRINSICS[intrinsicRealName]; - } else if (value != null) { - if (!(part in value)) { - if (!allowMissing) { - throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.'); - } - return void undefined; - } - if ($gOPD && (i + 1) >= parts.length) { - var desc = $gOPD(value, part); - isOwn = !!desc; - - // By convention, when a data property is converted to an accessor - // property to emulate a data property that does not suffer from - // the override mistake, that accessor's getter is marked with - // an `originalValue` property. Here, when we detect this, we - // uphold the illusion by pretending to see that original data - // property, i.e., returning the value rather than the getter - // itself. - if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { - value = desc.get; - } else { - value = value[part]; - } - } else { - isOwn = hasOwn(value, part); - value = value[part]; - } - - if (isOwn && !skipFurtherCaching) { - INTRINSICS[intrinsicRealName] = value; - } - } - } - return value; -}; +},{"../util/util":92,"./uncertainty":50,"luxon":109}],45:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Exception = void 0; +var Exception = /** @class */ (function () { + function Exception(message, wrapped) { + this.message = message; + this.wrapped = wrapped; + } + return Exception; +}()); +exports.Exception = Exception; -},{"function-bind":198,"has":210,"has-symbols":207}],53:[function(require,module,exports){ +},{}],46:[function(require,module,exports){ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.CodeService = void 0; -var datatypes_1 = require("./datatypes/datatypes"); -var CodeService = /** @class */ (function () { - function CodeService(valueSetsJson) { - if (valueSetsJson === void 0) { valueSetsJson = {}; } - this.valueSets = {}; - for (var oid in valueSetsJson) { - this.valueSets[oid] = {}; - for (var version in valueSetsJson[oid]) { - var codes = valueSetsJson[oid][version].map(function (code) { return new datatypes_1.Code(code.code, code.system, code.version); }); - this.valueSets[oid][version] = new datatypes_1.ValueSet(oid, version, codes); +exports.Interval = void 0; +var uncertainty_1 = require("./uncertainty"); +var quantity_1 = require("./quantity"); +var logic_1 = require("./logic"); +var math_1 = require("../util/math"); +var cmp = __importStar(require("../util/comparison")); +var Interval = /** @class */ (function () { + function Interval(low, high, lowClosed, highClosed, defaultPointType // defaultPointType is used in the case that both endpoints are null + ) { + this.low = low; + this.high = high; + this.lowClosed = lowClosed; + this.highClosed = highClosed; + this.defaultPointType = defaultPointType; + this.lowClosed = lowClosed != null ? lowClosed : true; + this.highClosed = highClosed != null ? highClosed : true; + } + Object.defineProperty(Interval.prototype, "isInterval", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Interval.prototype, "pointType", { + get: function () { + var pointType = null; + var point = this.low != null ? this.low : this.high; + if (point != null) { + if (typeof point === 'number') { + pointType = Number.isInteger(point) + ? '{urn:hl7-org:elm-types:r1}Integer' + : '{urn:hl7-org:elm-types:r1}Decimal'; + } + else if (point.isTime && point.isTime()) { + pointType = '{urn:hl7-org:elm-types:r1}Time'; + } + else if (point.isDate) { + pointType = '{urn:hl7-org:elm-types:r1}Date'; + } + else if (point.isDateTime) { + pointType = '{urn:hl7-org:elm-types:r1}DateTime'; + } + else if (point.isQuantity) { + pointType = '{urn:hl7-org:elm-types:r1}Quantity'; + } + } + if (pointType == null && this.defaultPointType != null) { + pointType = this.defaultPointType; + } + return pointType; + }, + enumerable: false, + configurable: true + }); + Interval.prototype.copy = function () { + var newLow = this.low; + var newHigh = this.high; + if (this.low != null && typeof this.low.copy === 'function') { + newLow = this.low.copy(); + } + if (this.high != null && typeof this.high.copy === 'function') { + newHigh = this.high.copy(); + } + return new Interval(newLow, newHigh, this.lowClosed, this.highClosed); + }; + Interval.prototype.contains = function (item, precision) { + // These first two checks ensure correct handling of edge case where an item equals the closed boundary + if (this.lowClosed && this.low != null && cmp.equals(this.low, item)) { + return true; + } + if (this.highClosed && this.high != null && cmp.equals(this.high, item)) { + return true; + } + if (item != null && item.isInterval) { + throw new Error('Argument to contains must be a point'); + } + var lowFn; + if (this.lowClosed && this.low == null) { + lowFn = function () { return true; }; + } + else if (this.lowClosed) { + lowFn = cmp.lessThanOrEquals; + } + else { + lowFn = cmp.lessThan; + } + var highFn; + if (this.highClosed && this.high == null) { + highFn = function () { return true; }; + } + else if (this.highClosed) { + highFn = cmp.greaterThanOrEquals; + } + else { + highFn = cmp.greaterThan; + } + return logic_1.ThreeValuedLogic.and(lowFn(this.low, item, precision), highFn(this.high, item, precision)); + }; + Interval.prototype.properlyIncludes = function (other, precision) { + if (other == null || !other.isInterval) { + throw new Error('Argument to properlyIncludes must be an interval'); + } + return logic_1.ThreeValuedLogic.and(this.includes(other, precision), logic_1.ThreeValuedLogic.not(other.includes(this, precision))); + }; + Interval.prototype.includes = function (other, precision) { + if (other == null || !other.isInterval) { + return this.contains(other, precision); + } + var a = this.toClosed(); + var b = other.toClosed(); + return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(a.low, b.low, precision), cmp.greaterThanOrEquals(a.high, b.high, precision)); + }; + Interval.prototype.includedIn = function (other, precision) { + // For the point overload, this operator is a synonym for the in operator + if (other == null || !other.isInterval) { + return this.contains(other, precision); + } + else { + return other.includes(this); + } + }; + Interval.prototype.overlaps = function (item, precision) { + var closed = this.toClosed(); + var _a = (function () { + if (item != null && item.isInterval) { + var itemClosed = item.toClosed(); + return [itemClosed.low, itemClosed.high]; + } + else { + return [item, item]; + } + })(), low = _a[0], high = _a[1]; + return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThanOrEquals(closed.high, low, precision)); + }; + Interval.prototype.overlapsAfter = function (item, precision) { + var closed = this.toClosed(); + var high = item != null && item.isInterval ? item.toClosed().high : item; + return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThan(closed.high, high, precision)); + }; + Interval.prototype.overlapsBefore = function (item, precision) { + var closed = this.toClosed(); + var low = item != null && item.isInterval ? item.toClosed().low : item; + return logic_1.ThreeValuedLogic.and(cmp.lessThan(closed.low, low, precision), cmp.greaterThanOrEquals(closed.high, low, precision)); + }; + Interval.prototype.union = function (other) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + if (other == null || !other.isInterval) { + throw new Error('Argument to union must be an interval'); + } + // Note that interval union is only defined if the arguments overlap or meet. + if (this.overlaps(other) || this.meets(other)) { + var _l = [this.toClosed(), other.toClosed()], a = _l[0], b = _l[1]; + var l = void 0, lc = void 0; + if (cmp.lessThanOrEquals(a.low, b.low)) { + _a = [this.low, this.lowClosed], l = _a[0], lc = _a[1]; + } + else if (cmp.greaterThanOrEquals(a.low, b.low)) { + _b = [other.low, other.lowClosed], l = _b[0], lc = _b[1]; + } + else if (areNumeric(a.low, b.low)) { + _c = [lowestNumericUncertainty(a.low, b.low), true], l = _c[0], lc = _c[1]; + // TODO: Do we need to support quantities here? + } + else if (areDateTimes(a.low, b.low) && a.low.isMorePrecise(b.low)) { + _d = [other.low, other.lowClosed], l = _d[0], lc = _d[1]; + } + else { + _e = [this.low, this.lowClosed], l = _e[0], lc = _e[1]; + } + var h = void 0, hc = void 0; + if (cmp.greaterThanOrEquals(a.high, b.high)) { + _f = [this.high, this.highClosed], h = _f[0], hc = _f[1]; + } + else if (cmp.lessThanOrEquals(a.high, b.high)) { + _g = [other.high, other.highClosed], h = _g[0], hc = _g[1]; + } + else if (areNumeric(a.high, b.high)) { + _h = [highestNumericUncertainty(a.high, b.high), true], h = _h[0], hc = _h[1]; + // TODO: Do we need to support quantities here? + } + else if (areDateTimes(a.high, b.high) && a.high.isMorePrecise(b.high)) { + _j = [other.high, other.highClosed], h = _j[0], hc = _j[1]; + } + else { + _k = [this.high, this.highClosed], h = _k[0], hc = _k[1]; + } + return new Interval(l, h, lc, hc); + } + else { + return null; + } + }; + Interval.prototype.intersect = function (other) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + if (other == null || !other.isInterval) { + throw new Error('Argument to union must be an interval'); + } + // Note that interval union is only defined if the arguments overlap. + if (this.overlaps(other)) { + var _l = [this.toClosed(), other.toClosed()], a = _l[0], b = _l[1]; + var l = void 0, lc = void 0; + if (cmp.greaterThanOrEquals(a.low, b.low)) { + _a = [this.low, this.lowClosed], l = _a[0], lc = _a[1]; + } + else if (cmp.lessThanOrEquals(a.low, b.low)) { + _b = [other.low, other.lowClosed], l = _b[0], lc = _b[1]; + } + else if (areNumeric(a.low, b.low)) { + _c = [highestNumericUncertainty(a.low, b.low), true], l = _c[0], lc = _c[1]; + // TODO: Do we need to support quantities here? + } + else if (areDateTimes(a.low, b.low) && b.low.isMorePrecise(a.low)) { + _d = [other.low, other.lowClosed], l = _d[0], lc = _d[1]; + } + else { + _e = [this.low, this.lowClosed], l = _e[0], lc = _e[1]; + } + var h = void 0, hc = void 0; + if (cmp.lessThanOrEquals(a.high, b.high)) { + _f = [this.high, this.highClosed], h = _f[0], hc = _f[1]; + } + else if (cmp.greaterThanOrEquals(a.high, b.high)) { + _g = [other.high, other.highClosed], h = _g[0], hc = _g[1]; + } + else if (areNumeric(a.high, b.high)) { + _h = [lowestNumericUncertainty(a.high, b.high), true], h = _h[0], hc = _h[1]; + // TODO: Do we need to support quantities here? + } + else if (areDateTimes(a.high, b.high) && b.high.isMorePrecise(a.high)) { + _j = [other.high, other.highClosed], h = _j[0], hc = _j[1]; + } + else { + _k = [this.high, this.highClosed], h = _k[0], hc = _k[1]; } + return new Interval(l, h, lc, hc); + } + else { + return null; } - } - CodeService.prototype.findValueSetsByOid = function (oid) { - return this.valueSets[oid] ? Object.values(this.valueSets[oid]) : []; }; - CodeService.prototype.findValueSet = function (oid, version) { - if (version != null) { - return this.valueSets[oid] != null ? this.valueSets[oid][version] : null; + Interval.prototype.except = function (other) { + if (other === null) { + return null; } - else { - var results = this.findValueSetsByOid(oid); - if (results.length === 0) { + if (other == null || !other.isInterval) { + throw new Error('Argument to except must be an interval'); + } + var ol = this.overlaps(other); + if (ol === true) { + var olb = this.overlapsBefore(other); + var ola = this.overlapsAfter(other); + if (olb === true && ola === false) { + return new Interval(this.low, other.low, this.lowClosed, !other.lowClosed); + } + else if (ola === true && olb === false) { + return new Interval(other.high, this.high, !other.highClosed, this.highClosed); + } + else { return null; } + } + else if (ol === false) { + return this; + } + else { + // ol is null + return null; + } + }; + Interval.prototype.sameAs = function (other, precision) { + // This large if and else if block handles the scenarios where there is an open ended null + // If both lows or highs exists, it can be determined that intervals are not Same As + if ((this.low != null && + other.low != null && + this.high == null && + other.high != null && + !this.highClosed) || + (this.low != null && + other.low != null && + this.high != null && + other.high == null && + !other.highClosed) || + (this.low != null && + other.low != null && + this.high == null && + other.high == null && + !other.highClosed && + !this.highClosed)) { + if (typeof this.low === 'number') { + if (!(this.start() === other.start())) { + return false; + } + } else { - return results.reduce(function (a, b) { - if (a.version > b.version) { - return a; - } - else { - return b; - } - }); + if (!this.start().sameAs(other.start(), precision)) { + return false; + } + } + } + else if ((this.low != null && other.low == null && this.high != null && other.high != null) || + (this.low == null && other.low != null && this.high != null && other.high != null) || + (this.low == null && other.low == null && this.high != null && other.high != null)) { + if (typeof this.high === 'number') { + if (!(this.end() === other.end())) { + return false; + } } + else { + if (!this.end().sameAs(other.end(), precision)) { + return false; + } + } + } + // Checks to see if any of the Intervals have a open, null boundary + if ((this.low == null && !this.lowClosed) || + (this.high == null && !this.highClosed) || + (other.low == null && !other.lowClosed) || + (other.high == null && !other.highClosed)) { + return null; + } + // For the special cases where @ is Interval[null,null] + if (this.lowClosed && this.low == null && this.highClosed && this.high == null) { + return other.lowClosed && other.low == null && other.highClosed && other.high == null; + } + // For the special case where Interval[...] same as Interval[null,null] should return false. + // This accounts for the inverse of the if statement above: where the second Interval is + // [null,null] and not the first Interval. + // The reason why this isn't caught below is due to how start() and end() work. + // There is no way to tell the datatype for MIN and MAX if both boundaries are null. + if (other.lowClosed && other.low == null && other.highClosed && other.high == null) { + return false; + } + if (typeof this.low === 'number') { + return this.start() === other.start() && this.end() === other.end(); + } + else { + return (this.start().sameAs(other.start(), precision) && this.end().sameAs(other.end(), precision)); } }; - return CodeService; -}()); -exports.CodeService = CodeService; - -},{"./datatypes/datatypes":57}],54:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); + Interval.prototype.sameOrBefore = function (other, precision) { + if (this.end() == null || other == null || other.start() == null) { + return null; + } + else { + return cmp.lessThanOrEquals(this.end(), other.start(), precision); + } }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + Interval.prototype.sameOrAfter = function (other, precision) { + if (this.start() == null || other == null || other.end() == null) { + return null; + } + else { + return cmp.greaterThanOrEquals(this.start(), other.end(), precision); + } }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PatientSource = exports.Patient = exports.Record = void 0; -var DT = __importStar(require("./datatypes/datatypes")); -var Record = /** @class */ (function () { - function Record(json) { - this.json = json; - this.id = this.json.id; - } - Record.prototype._is = function (typeSpecifier) { - return this._typeHierarchy().some(function (t) { return t.type === typeSpecifier.type && t.name == typeSpecifier.name; }); + Interval.prototype.equals = function (other) { + if (other != null && other.isInterval) { + var _a = [this.toClosed(), other.toClosed()], a = _a[0], b = _a[1]; + return logic_1.ThreeValuedLogic.and(cmp.equals(a.low, b.low), cmp.equals(a.high, b.high)); + } + else { + return false; + } }; - Record.prototype._typeHierarchy = function () { - return [ - { - name: "{https://github.com/cqframework/cql-execution/simple}".concat(this.json.recordType), - type: 'NamedTypeSpecifier' - }, - { - name: '{https://github.com/cqframework/cql-execution/simple}Record', - type: 'NamedTypeSpecifier' - }, - { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' } - ]; + Interval.prototype.after = function (other, precision) { + var closed = this.toClosed(); + // Meets spec, but not 100% correct (e.g., (null, 5] after [6, 10] --> null) + // Simple way to fix it: and w/ not overlaps + if (other.toClosed) { + return cmp.greaterThan(closed.low, other.toClosed().high, precision); + } + else { + return cmp.greaterThan(closed.low, other, precision); + } }; - Record.prototype._recursiveGet = function (field) { - if (field != null && field.indexOf('.') >= 0) { - var _a = field.split('.', 2), root = _a[0], rest = _a[1]; - return new Record(this._recursiveGet(root))._recursiveGet(rest); + Interval.prototype.before = function (other, precision) { + var closed = this.toClosed(); + // Meets spec, but not 100% correct (e.g., (null, 5] after [6, 10] --> null) + // Simple way to fix it: and w/ not overlaps + if (other.toClosed) { + return cmp.lessThan(closed.high, other.toClosed().low, precision); + } + else { + return cmp.lessThan(closed.high, other, precision); } - return this.json[field]; }; - Record.prototype.get = function (field) { - // the model should return the correct type for the field. For this simple model example, - // we just cheat and use the shape of the value to determine it. Real implementations should - // have a more sophisticated approach - var value = this._recursiveGet(field); - if (typeof value === 'string' && /\d{4}-\d{2}-\d{2}(T[\d\-.]+)?/.test(value)) { - return this.getDate(field); + Interval.prototype.meets = function (other, precision) { + return logic_1.ThreeValuedLogic.or(this.meetsBefore(other, precision), this.meetsAfter(other, precision)); + }; + Interval.prototype.meetsAfter = function (other, precision) { + try { + if (precision != null && this.low != null && this.low.isDateTime) { + return this.toClosed().low.sameAs(other.toClosed().high != null ? other.toClosed().high.add(1, precision) : null, precision); + } + else { + return cmp.equals(this.toClosed().low, (0, math_1.successor)(other.toClosed().high)); + } } - if (value != null && typeof value === 'object' && value.code != null && value.system != null) { - return this.getCode(field); + catch (error) { + return false; } - if (value != null && typeof value === 'object' && (value.low != null || value.high != null)) { - return this.getInterval(field); + }; + Interval.prototype.meetsBefore = function (other, precision) { + try { + if (precision != null && this.high != null && this.high.isDateTime) { + return this.toClosed().high.sameAs(other.toClosed().low != null ? other.toClosed().low.add(-1, precision) : null, precision); + } + else { + return cmp.equals(this.toClosed().high, (0, math_1.predecessor)(other.toClosed().low)); + } + } + catch (error) { + return false; } - return value; }; - Record.prototype.getId = function () { - return this.id; + Interval.prototype.start = function () { + if (this.low == null) { + if (this.lowClosed) { + return (0, math_1.minValueForInstance)(this.high); + } + else { + return this.low; + } + } + return this.toClosed().low; }; - Record.prototype.getDate = function (field) { - var val = this._recursiveGet(field); - if (val != null) { - return DT.DateTime.parse(val); + Interval.prototype.end = function () { + if (this.high == null) { + if (this.highClosed) { + return (0, math_1.maxValueForInstance)(this.low); + } + else { + return this.high; + } + } + return this.toClosed().high; + }; + Interval.prototype.starts = function (other, precision) { + var startEqual; + if (precision != null && this.low != null && this.low.isDateTime) { + startEqual = this.low.sameAs(other.low, precision); } else { - return null; + startEqual = cmp.equals(this.low, other.low); } + var endLessThanOrEqual = cmp.lessThanOrEquals(this.high, other.high, precision); + return startEqual && endLessThanOrEqual; }; - Record.prototype.getInterval = function (field) { - var val = this._recursiveGet(field); - if (val != null && typeof val === 'object') { - var low = val.low != null ? DT.DateTime.parse(val.low) : null; - var high = val.high != null ? DT.DateTime.parse(val.high) : null; - return new DT.Interval(low, high); + Interval.prototype.ends = function (other, precision) { + var endEqual; + var startGreaterThanOrEqual = cmp.greaterThanOrEquals(this.low, other.low, precision); + if (precision != null && (this.low != null ? this.low.isDateTime : undefined)) { + endEqual = this.high.sameAs(other.high, precision); + } + else { + endEqual = cmp.equals(this.high, other.high); } + return startGreaterThanOrEqual && endEqual; }; - Record.prototype.getDateOrInterval = function (field) { - var val = this._recursiveGet(field); - if (val != null && typeof val === 'object') { - return this.getInterval(field); + Interval.prototype.width = function () { + if ((this.low != null && (this.low.isDateTime || this.low.isDate)) || + (this.high != null && (this.high.isDateTime || this.high.isDate))) { + throw new Error('Width of Date, DateTime, and Time intervals is not supported'); + } + var closed = this.toClosed(); + if ((closed.low != null && closed.low.isUncertainty) || + (closed.high != null && closed.high.isUncertainty)) { + return null; + } + else if (closed.low.isQuantity) { + if (closed.low.unit !== closed.high.unit) { + throw new Error('Cannot calculate width of Quantity Interval with different units'); + } + var lowValue = closed.low.value; + var highValue = closed.high.value; + var diff = Math.abs(highValue - lowValue); + diff = Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); + return new quantity_1.Quantity(diff, closed.low.unit); } else { - return this.getDate(field); + // TODO: Fix precision to 8 decimals in other places that return numbers + var diff = Math.abs(closed.high - closed.low); + return Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); } }; - Record.prototype.getCode = function (field) { - var val = this._recursiveGet(field); - if (val != null && typeof val === 'object') { - return new DT.Code(val.code, val.system, val.version); + Interval.prototype.size = function () { + var pointSize = this.getPointSize(); + if ((this.low != null && (this.low.isDateTime || this.low.isDate)) || + (this.high != null && (this.high.isDateTime || this.high.isDate))) { + throw new Error('Size of Date, DateTime, and Time intervals is not supported'); } - }; - return Record; -}()); -exports.Record = Record; -var Patient = /** @class */ (function (_super) { - __extends(Patient, _super); - function Patient(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.gender = json.gender; - _this.birthDate = json.birthDate != null ? DT.DateTime.parse(json.birthDate) : undefined; - _this.records = {}; - (json.records || []).forEach(function (r) { - if (_this.records[r.recordType] == null) { - _this.records[r.recordType] = []; - } - _this.records[r.recordType].push(new Record(r)); - }); - return _this; - } - Patient.prototype.findRecords = function (profile) { - if (profile == null) { - return []; + var closed = this.toClosed(); + if ((closed.low != null && closed.low.isUncertainty) || + (closed.high != null && closed.high.isUncertainty)) { + return null; } - var match = profile.match(/(\{https:\/\/github\.com\/cqframework\/cql-execution\/simple\})?(.*)/); - if (match == null) - return []; - var recordType = match[2]; - if (recordType === 'Patient') { - return [this]; + else if (closed.low.isQuantity) { + if (closed.low.unit !== closed.high.unit) { + throw new Error('Cannot calculate size of Quantity Interval with different units'); + } + var lowValue = closed.low.value; + var highValue = closed.high.value; + var diff = Math.abs(highValue - lowValue) + pointSize.value; + Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); + return new quantity_1.Quantity(diff, closed.low.unit); } else { - return this.records[recordType] || []; + var diff = Math.abs(closed.high - closed.low) + pointSize.value; + return Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); } }; - return Patient; -}(Record)); -exports.Patient = Patient; -var PatientSource = /** @class */ (function () { - function PatientSource(patients) { - this.patients = patients; - this.nextPatient(); - } - PatientSource.prototype.currentPatient = function () { - return this.current; - }; - PatientSource.prototype.nextPatient = function () { - var currentJSON = this.patients.shift(); - this.current = currentJSON ? new Patient(currentJSON) : undefined; - return this.current; - }; - return PatientSource; -}()); -exports.PatientSource = PatientSource; - -},{"./datatypes/datatypes":57}],55:[function(require,module,exports){ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ValueSet = exports.Ratio = exports.Quantity = exports.Interval = exports.DateTime = exports.Date = exports.Concept = exports.CodeSystem = exports.Code = exports.CodeService = exports.PatientSource = exports.Patient = exports.NullMessageListener = exports.ConsoleMessageListener = exports.Results = exports.Executor = exports.UnfilteredContext = exports.PatientContext = exports.Context = exports.Expression = exports.Repository = exports.Library = void 0; -// Library-related classes -var library_1 = require("./elm/library"); -Object.defineProperty(exports, "Library", { enumerable: true, get: function () { return library_1.Library; } }); -var repository_1 = require("./runtime/repository"); -Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } }); -var expression_1 = require("./elm/expression"); -Object.defineProperty(exports, "Expression", { enumerable: true, get: function () { return expression_1.Expression; } }); -// Execution-related classes -var context_1 = require("./runtime/context"); -Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } }); -Object.defineProperty(exports, "PatientContext", { enumerable: true, get: function () { return context_1.PatientContext; } }); -Object.defineProperty(exports, "UnfilteredContext", { enumerable: true, get: function () { return context_1.UnfilteredContext; } }); -var executor_1 = require("./runtime/executor"); -Object.defineProperty(exports, "Executor", { enumerable: true, get: function () { return executor_1.Executor; } }); -var results_1 = require("./runtime/results"); -Object.defineProperty(exports, "Results", { enumerable: true, get: function () { return results_1.Results; } }); -var messageListeners_1 = require("./runtime/messageListeners"); -Object.defineProperty(exports, "ConsoleMessageListener", { enumerable: true, get: function () { return messageListeners_1.ConsoleMessageListener; } }); -Object.defineProperty(exports, "NullMessageListener", { enumerable: true, get: function () { return messageListeners_1.NullMessageListener; } }); -// PatientSource-related classes -var cql_patient_1 = require("./cql-patient"); -Object.defineProperty(exports, "Patient", { enumerable: true, get: function () { return cql_patient_1.Patient; } }); -Object.defineProperty(exports, "PatientSource", { enumerable: true, get: function () { return cql_patient_1.PatientSource; } }); -// TerminologyService-related classes -var cql_code_service_1 = require("./cql-code-service"); -Object.defineProperty(exports, "CodeService", { enumerable: true, get: function () { return cql_code_service_1.CodeService; } }); -// DataType classes -var datatypes_1 = require("./datatypes/datatypes"); -Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return datatypes_1.Code; } }); -Object.defineProperty(exports, "CodeSystem", { enumerable: true, get: function () { return datatypes_1.CodeSystem; } }); -Object.defineProperty(exports, "Concept", { enumerable: true, get: function () { return datatypes_1.Concept; } }); -Object.defineProperty(exports, "Date", { enumerable: true, get: function () { return datatypes_1.Date; } }); -Object.defineProperty(exports, "DateTime", { enumerable: true, get: function () { return datatypes_1.DateTime; } }); -Object.defineProperty(exports, "Interval", { enumerable: true, get: function () { return datatypes_1.Interval; } }); -Object.defineProperty(exports, "Quantity", { enumerable: true, get: function () { return datatypes_1.Quantity; } }); -Object.defineProperty(exports, "Ratio", { enumerable: true, get: function () { return datatypes_1.Ratio; } }); -Object.defineProperty(exports, "ValueSet", { enumerable: true, get: function () { return datatypes_1.ValueSet; } }); -// Custom Types -__exportStar(require("./types"), exports); -exports.default = { - Library: library_1.Library, - Repository: repository_1.Repository, - Expression: expression_1.Expression, - Context: context_1.Context, - PatientContext: context_1.PatientContext, - UnfilteredContext: context_1.UnfilteredContext, - Executor: executor_1.Executor, - Results: results_1.Results, - ConsoleMessageListener: messageListeners_1.ConsoleMessageListener, - NullMessageListener: messageListeners_1.NullMessageListener, - Patient: cql_patient_1.Patient, - PatientSource: cql_patient_1.PatientSource, - CodeService: cql_code_service_1.CodeService, - Code: datatypes_1.Code, - CodeSystem: datatypes_1.CodeSystem, - Concept: datatypes_1.Concept, - Date: datatypes_1.Date, - DateTime: datatypes_1.DateTime, - Interval: datatypes_1.Interval, - Quantity: datatypes_1.Quantity, - Ratio: datatypes_1.Ratio, - ValueSet: datatypes_1.ValueSet -}; - -},{"./cql-code-service":53,"./cql-patient":54,"./datatypes/datatypes":57,"./elm/expression":73,"./elm/library":78,"./runtime/context":93,"./runtime/executor":94,"./runtime/messageListeners":95,"./runtime/repository":96,"./runtime/results":97,"./types":100}],56:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.CodeSystem = exports.ValueSet = exports.Concept = exports.Code = void 0; -var util_1 = require("../util/util"); -var Code = /** @class */ (function () { - function Code(code, system, version, display) { - this.code = code; - this.system = system; - this.version = version; - this.display = display; - } - Object.defineProperty(Code.prototype, "isCode", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Code.prototype.hasMatch = function (code) { - if (typeof code === 'string') { - // the specific behavior for this is not in the specification. Matching codesystem behavior. - return code === this.code; + Interval.prototype.getPointSize = function () { + var pointSize; + if (this.low != null) { + if (this.low.isDateTime || this.low.isDate || this.low.isTime) { + pointSize = new quantity_1.Quantity(1, this.low.getPrecision()); + } + else if (this.low.isQuantity) { + pointSize = (0, quantity_1.doSubtraction)((0, math_1.successor)(this.low), this.low); + } + else { + pointSize = (0, math_1.successor)(this.low) - this.low; + } + } + else if (this.high != null) { + if (this.high.isDateTime || this.high.isDate || this.high.isTime) { + pointSize = new quantity_1.Quantity(1, this.high.getPrecision()); + } + else if (this.high.isQuantity) { + pointSize = (0, quantity_1.doSubtraction)((0, math_1.successor)(this.high), this.high); + } + else { + pointSize = (0, math_1.successor)(this.high) - this.high; + } } else { - return codesInList(toCodeList(code), [this]); + throw new Error('Point type of intervals cannot be determined.'); } + if (typeof pointSize === 'number') { + pointSize = new quantity_1.Quantity(pointSize, '1'); + } + return pointSize; }; - return Code; -}()); -exports.Code = Code; -var Concept = /** @class */ (function () { - function Concept(codes, display) { - this.codes = codes; - this.display = display; - this.codes || (this.codes = []); - } - Object.defineProperty(Concept.prototype, "isConcept", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Concept.prototype.hasMatch = function (code) { - return codesInList(toCodeList(code), this.codes); - }; - return Concept; -}()); -exports.Concept = Concept; -var ValueSet = /** @class */ (function () { - function ValueSet(oid, version, codes) { - if (codes === void 0) { codes = []; } - this.oid = oid; - this.version = version; - this.codes = codes; - this.codes || (this.codes = []); - } - Object.defineProperty(ValueSet.prototype, "isValueSet", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - ValueSet.prototype.hasMatch = function (code) { - var codesList = toCodeList(code); - // InValueSet String Overload - if (codesList.length === 1 && typeof codesList[0] === 'string') { - var matchFound = false; - var multipleCodeSystemsExist = false; - for (var _i = 0, _a = this.codes; _i < _a.length; _i++) { - var codeItem = _a[_i]; - // Confirm all code systems match - if (codeItem.system !== this.codes[0].system) { - multipleCodeSystemsExist = true; - } - if (codeItem.code === codesList[0]) { - matchFound = true; - } - if (multipleCodeSystemsExist && matchFound) { - throw new Error('In (valueset) is ambiguous -- multiple codes with multiple code systems exist in value set.'); - } + Interval.prototype.toClosed = function () { + // Calculate the closed flags. Despite the name of this function, if a boundary is null open, + // we cannot close the boundary because that changes its meaning from "unknown" to "max/min value" + var lowClosed = this.lowClosed || this.low != null; + var highClosed = this.highClosed || this.high != null; + if (this.pointType != null) { + var low = void 0; + if (this.lowClosed && this.low == null) { + low = (0, math_1.minValueForType)(this.pointType); } - return matchFound; + else if (!this.lowClosed && this.low != null) { + low = (0, math_1.successor)(this.low); + } + else { + low = this.low; + } + var high = void 0; + if (this.highClosed && this.high == null) { + high = (0, math_1.maxValueForType)(this.pointType); + } + else if (!this.highClosed && this.high != null) { + high = (0, math_1.predecessor)(this.high); + } + else { + high = this.high; + } + if (low == null) { + low = new uncertainty_1.Uncertainty((0, math_1.minValueForType)(this.pointType), high); + } + if (high == null) { + high = new uncertainty_1.Uncertainty(low, (0, math_1.maxValueForType)(this.pointType)); + } + return new Interval(low, high, lowClosed, highClosed); } else { - return codesInList(codesList, this.codes); + return new Interval(this.low, this.high, lowClosed, highClosed); } }; - return ValueSet; + Interval.prototype.toString = function () { + var start = this.lowClosed ? '[' : '('; + var end = this.highClosed ? ']' : ')'; + return start + this.low.toString() + ', ' + this.high.toString() + end; + }; + return Interval; }()); -exports.ValueSet = ValueSet; -function toCodeList(c) { - if (c == null) { - return []; +exports.Interval = Interval; +function areDateTimes(x, y) { + return [x, y].every(function (z) { return z != null && z.isDateTime; }); +} +function areNumeric(x, y) { + return [x, y].every(function (z) { + return typeof z === 'number' || (z != null && z.isUncertainty && typeof z.low === 'number'); + }); +} +function lowestNumericUncertainty(x, y) { + if (x == null || !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x); } - else if ((0, util_1.typeIsArray)(c)) { - var list = []; - for (var _i = 0, c_1 = c; _i < c_1.length; _i++) { - var c2 = c_1[_i]; - list = list.concat(toCodeList(c2)); - } - return list; + if (y == null || !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y); } - else if ((0, util_1.typeIsArray)(c.codes)) { - return c.codes; + var low = x.low < y.low ? x.low : y.low; + var high = x.high < y.high ? x.high : y.high; + if (low !== high) { + return new uncertainty_1.Uncertainty(low, high); } else { - return [c]; + return low; } } -function codesInList(cl1, cl2) { - // test each code in c1 against each code in c2 looking for a match - return cl1.some(function (c1) { - return cl2.some(function (c2) { - // only the left argument (cl1) can contain strings. cl2 will only contain codes. - if (typeof c1 === 'string') { - // for "string in codesystem" this should compare the string to - // the code's "code" field according to the specification. - return c1 === c2.code; - } - else { - return codesMatch(c1, c2); - } - }); - }); -} -function codesMatch(code1, code2) { - return code1.code === code2.code && code1.system === code2.system; -} -var CodeSystem = /** @class */ (function () { - function CodeSystem(id, version) { - this.id = id; - this.version = version; +function highestNumericUncertainty(x, y) { + if (x == null || !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x); } - return CodeSystem; -}()); -exports.CodeSystem = CodeSystem; + if (y == null || !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y); + } + var low = x.low > y.low ? x.low : y.low; + var high = x.high > y.high ? x.high : y.high; + if (low !== high) { + return new uncertainty_1.Uncertainty(low, high); + } + else { + return low; + } +} -},{"../util/util":106}],57:[function(require,module,exports){ +},{"../util/comparison":89,"../util/math":90,"./logic":47,"./quantity":48,"./uncertainty":50}],47:[function(require,module,exports){ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./logic"), exports); -__exportStar(require("./clinical"), exports); -__exportStar(require("./uncertainty"), exports); -__exportStar(require("./datetime"), exports); -__exportStar(require("./interval"), exports); -__exportStar(require("./quantity"), exports); -__exportStar(require("./ratio"), exports); - -},{"./clinical":56,"./datetime":58,"./interval":60,"./logic":61,"./quantity":62,"./ratio":63,"./uncertainty":64}],58:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } +exports.ThreeValuedLogic = void 0; +var ThreeValuedLogic = /** @class */ (function () { + function ThreeValuedLogic() { } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var _a, _b; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MAX_TIME_VALUE = exports.MIN_TIME_VALUE = exports.MAX_DATE_VALUE = exports.MIN_DATE_VALUE = exports.MAX_DATETIME_VALUE = exports.MIN_DATETIME_VALUE = exports.Date = exports.DateTime = void 0; -/* eslint-disable @typescript-eslint/ban-ts-comment */ -var uncertainty_1 = require("./uncertainty"); -var util_1 = require("../util/util"); -var luxon_1 = require("luxon"); -// It's easiest and most performant to organize formats by length of the supported strings. -// This way we can test strings only against the formats that have a chance of working. -// NOTE: Formats use Luxon formats, documented here: https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens -var LENGTH_TO_DATE_FORMAT_MAP = (function () { - var ltdfMap = new Map(); - ltdfMap.set(4, 'yyyy'); - ltdfMap.set(7, 'yyyy-MM'); - ltdfMap.set(10, 'yyyy-MM-dd'); - return ltdfMap; -})(); -var LENGTH_TO_DATETIME_FORMATS_MAP = (function () { - var formats = { - yyyy: '2012', - 'yyyy-MM': '2012-01', - 'yyyy-MM-dd': '2012-01-31', - "yyyy-MM-dd'T''Z'": '2012-01-31TZ', - "yyyy-MM-dd'T'ZZ": '2012-01-31T-04:00', - "yyyy-MM-dd'T'HH": '2012-01-31T12', - "yyyy-MM-dd'T'HH'Z'": '2012-01-31T12Z', - "yyyy-MM-dd'T'HHZZ": '2012-01-31T12-04:00', - "yyyy-MM-dd'T'HH:mm": '2012-01-31T12:30', - "yyyy-MM-dd'T'HH:mm'Z'": '2012-01-31T12:30Z', - "yyyy-MM-dd'T'HH:mmZZ": '2012-01-31T12:30-04:00', - "yyyy-MM-dd'T'HH:mm:ss": '2012-01-31T12:30:59', - "yyyy-MM-dd'T'HH:mm:ss'Z'": '2012-01-31T12:30:59Z', - "yyyy-MM-dd'T'HH:mm:ssZZ": '2012-01-31T12:30:59-04:00', - "yyyy-MM-dd'T'HH:mm:ss.SSS": '2012-01-31T12:30:59.000', - "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'": '2012-01-31T12:30:59.000Z', - "yyyy-MM-dd'T'HH:mm:ss.SSSZZ": '2012-01-31T12:30:59.000-04:00' - }; - var ltdtfMap = new Map(); - Object.keys(formats).forEach(function (k) { - var example = formats[k]; - if (!ltdtfMap.has(example.length)) { - ltdtfMap.set(example.length, [k]); + ThreeValuedLogic.and = function () { + var val = []; + for (var _i = 0; _i < arguments.length; _i++) { + val[_i] = arguments[_i]; } - else { - ltdtfMap.get(example.length).push(k); + if (val.includes(false)) { + return false; } - }); - return ltdtfMap; -})(); -function wholeLuxonDuration(duration, unit) { - var value = duration.get(unit); - return value >= 0 ? Math.floor(value) : Math.ceil(value); -} -function truncateLuxonDateTime(luxonDT, unit) { - // Truncating by week (to the previous Sunday) requires different logic than the rest - if (unit === DateTime.Unit.WEEK) { - // Sunday is ISO weekday 7 - if (luxonDT.weekday !== 7) { - luxonDT = luxonDT.set({ weekday: 7 }).minus({ weeks: 1 }); + else if (val.includes(null)) { + return null; + } + else { + return true; } - unit = DateTime.Unit.DAY; - } - return luxonDT.startOf(unit); -} -/* - * Base class for Date and DateTime to extend from - * Implements shared functions by both classes - * TODO: we can probably iterate on this more to improve the accessing of "FIELDS" and the overall structure - * TODO: we can also investigate if it's reasonable for DateTime to extend Date directly instead - */ -var AbstractDate = /** @class */ (function () { - function AbstractDate(year, month, day) { - if (year === void 0) { year = null; } - if (month === void 0) { month = null; } - if (day === void 0) { day = null; } - this.year = year; - this.month = month; - this.day = day; - } - // Shared functions - AbstractDate.prototype.isPrecise = function () { - var _this = this; - // @ts-ignore - return this.constructor.FIELDS.every(function (field) { return _this[field] != null; }); - }; - AbstractDate.prototype.isImprecise = function () { - return !this.isPrecise(); }; - AbstractDate.prototype.isMorePrecise = function (other) { - // @ts-ignore - if (typeof other === 'string' && this.constructor.FIELDS.includes(other)) { - // @ts-ignore - if (this[other] == null) { - return false; - } + ThreeValuedLogic.or = function () { + var val = []; + for (var _i = 0; _i < arguments.length; _i++) { + val[_i] = arguments[_i]; + } + if (val.includes(true)) { + return true; + } + else if (val.includes(null)) { + return null; } else { - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // @ts-ignore - if (other[field] != null && this[field] == null) { - return false; - } - } + return false; } - return !this.isSamePrecision(other); - }; - // This function can take another Date-ish object, or a precision string (e.g. 'month') - AbstractDate.prototype.isLessPrecise = function (other) { - return !this.isSamePrecision(other) && !this.isMorePrecise(other); }; - // This function can take another Date-ish object, or a precision string (e.g. 'month') - AbstractDate.prototype.isSamePrecision = function (other) { - // @ts-ignore - if (typeof other === 'string' && this.constructor.FIELDS.includes(other)) { - return other === this.getPrecision(); + ThreeValuedLogic.xor = function () { + var val = []; + for (var _i = 0; _i < arguments.length; _i++) { + val[_i] = arguments[_i]; } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // @ts-ignore - if (this[field] != null && other[field] == null) { - return false; - } + if (val.includes(null)) { + return null; + } + else { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - if (this[field] == null && other[field] != null) { - return false; - } + return val.reduce(function (a, b) { return (!a ^ !b) === 1; }); } - return true; - }; - AbstractDate.prototype.equals = function (other) { - return compareWithDefaultResult(this, other, null); - }; - AbstractDate.prototype.equivalent = function (other) { - return compareWithDefaultResult(this, other, false); }; - AbstractDate.prototype.sameAs = function (other, precision) { - if (!(other.isDate || other.isDateTime)) { + ThreeValuedLogic.not = function (val) { + if (val != null) { + return !val; + } + else { return null; } - else if (this.isDate && other.isDateTime) { - return this.getDateTime().sameAs(other, precision); + }; + return ThreeValuedLogic; +}()); +exports.ThreeValuedLogic = ThreeValuedLogic; + +},{}],48:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.doMultiplication = exports.doDivision = exports.doSubtraction = exports.doAddition = exports.parseQuantity = exports.Quantity = void 0; +var math_1 = require("../util/math"); +var units_1 = require("../util/units"); +var Quantity = /** @class */ (function () { + function Quantity(value, unit) { + this.value = value; + this.unit = unit; + if (this.value == null || isNaN(this.value)) { + throw new Error('Cannot create a quantity with an undefined value'); } - else if (this.isDateTime && other.isDate) { - other = other.getDateTime(); + else if (!(0, math_1.isValidDecimal)(this.value)) { + throw new Error('Cannot create a quantity with an invalid decimal value'); } - // @ts-ignore - if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { - throw new Error("Invalid precision: ".concat(precision)); + // Attempt to parse the unit with UCUM. If it fails, throw a friendly error. + if (this.unit != null) { + var validation = (0, units_1.checkUnit)(this.unit); + if (!validation.valid) { + throw new Error(validation.message); + } } - // make a copy of other in the correct timezone offset if they don't match. - // When comparing DateTime values with different timezone offsets, implementations - // should normalize to the timezone offset of the evaluation request timestamp, - // but only when the comparison precision is hours, minutes, seconds, or milliseconds. - if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { - if (this.timezoneOffset !== other.timezoneOffset) { - other = other.convertToTimezoneOffset(this.timezoneOffset); + } + Object.defineProperty(Quantity.prototype, "isQuantity", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Quantity.prototype.clone = function () { + return new Quantity(this.value, this.unit); + }; + Quantity.prototype.toString = function () { + return "".concat(this.value, " '").concat(this.unit, "'"); + }; + Quantity.prototype.sameOrBefore = function (other) { + if (other != null && other.isQuantity) { + var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); + if (otherVal == null) { + return null; + } + else { + return this.value <= otherVal; } } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - // @ts-ignore - if (this[field] != null && other[field] != null) { - // if they are different then return with false - // @ts-ignore - if (this[field] !== other[field]) { - return false; - } - // if both dont have this precision, return true of precision is not defined - // @ts-ignore + }; + Quantity.prototype.sameOrAfter = function (other) { + if (other != null && other.isQuantity) { + var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); + if (otherVal == null) { + return null; } - else if (this[field] == null && other[field] == null) { - if (precision == null) { - return true; - } - else { - // we havent met precision yet - return null; - } - // otherwise they have inconclusive precision, return null + else { + return this.value >= otherVal; + } + } + }; + Quantity.prototype.after = function (other) { + if (other != null && other.isQuantity) { + var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); + if (otherVal == null) { + return null; } else { + return this.value > otherVal; + } + } + }; + Quantity.prototype.before = function (other) { + if (other != null && other.isQuantity) { + var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); + if (otherVal == null) { return null; } - // if precision is defined and we have reached expected precision, we can leave the loop - if (precision != null && precision === field) { - break; + else { + return this.value < otherVal; } } - // if we made it here, then all fields matched. - return true; }; - AbstractDate.prototype.sameOrBefore = function (other, precision) { - if (!(other.isDate || other.isDateTime)) { - return null; - } - else if (this.isDate && other.isDateTime) { - return this.getDateTime().sameOrBefore(other, precision); - } - else if (this.isDateTime && other.isDate) { - other = other.getDateTime(); - } - // @ts-ignore - if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { - throw new Error("Invalid precision: ".concat(precision)); - } - // make a copy of other in the correct timezone offset if they don't match. - // When comparing DateTime values with different timezone offsets, implementations - // should normalize to the timezone offset of the evaluation request timestamp, - // but only when the comparison precision is hours, minutes, seconds, or milliseconds. - if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { - if (this.timezoneOffset !== other.timezoneOffset) { - other = other.convertToTimezoneOffset(this.timezoneOffset); + Quantity.prototype.equals = function (other) { + if (other != null && other.isQuantity) { + if ((!this.unit && other.unit) || (this.unit && !other.unit)) { + return false; } - } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - // @ts-ignore - if (this[field] != null && other[field] != null) { - // if this value is less than the other return with true. this is before other - // @ts-ignore - if (this[field] < other[field]) { - return true; - // if this value is greater than the other return with false. this is after - // @ts-ignore - } - else if (this[field] > other[field]) { - return false; - } - // execution continues if the values are the same - // if both dont have this precision, return true if precision is not defined - // @ts-ignore + else if (!this.unit && !other.unit) { + return this.value === other.value; } - else if (this[field] == null && other[field] == null) { - if (precision == null) { - return true; + else { + var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); + if (otherVal == null) { + return null; } else { - // we havent met precision yet - return null; + return (0, math_1.decimalAdjust)('round', this.value, -8) === otherVal; } - // otherwise they have inconclusive precision, return null - } - else { - return null; - } - // if precision is defined and we have reached expected precision, we can leave the loop - if (precision != null && precision === field) { - break; } } - // if we made it here, then all fields matched and they are same - return true; }; - AbstractDate.prototype.sameOrAfter = function (other, precision) { - if (!(other.isDate || other.isDateTime)) { + Quantity.prototype.convertUnit = function (toUnit) { + var value = (0, units_1.convertUnit)(this.value, this.unit, toUnit); + // Need to pass through constructor again to catch invalid units + return new Quantity(value, toUnit); + }; + Quantity.prototype.dividedBy = function (other) { + if (other == null || other === 0 || other.value === 0) { return null; } - else if (this.isDate && other.isDateTime) { - return this.getDateTime().sameOrAfter(other, precision); + else if (!other.isQuantity) { + // convert it to a quantity w/ unit 1 + other = new Quantity(other, '1'); } - else if (this.isDateTime && other.isDate) { - other = other.getDateTime(); + var _a = (0, units_1.normalizeUnitsWhenPossible)(this.value, this.unit, other.value, other.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; + var resultValue = val1 / val2; + var resultUnit = (0, units_1.getQuotientOfUnits)(unit1, unit2); + // Check for invalid unit or value + if (resultUnit == null || (0, math_1.overflowsOrUnderflows)(resultValue)) { + return null; } - // @ts-ignore - if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { - throw new Error("Invalid precision: ".concat(precision)); + return new Quantity((0, math_1.decimalAdjust)('round', resultValue, -8), resultUnit); + }; + Quantity.prototype.multiplyBy = function (other) { + if (other == null) { + return null; } - // make a copy of other in the correct timezone offset if they don't match. - // When comparing DateTime values with different timezone offsets, implementations - // should normalize to the timezone offset of the evaluation request timestamp, - // but only when the comparison precision is hours, minutes, seconds, or milliseconds. - if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { - if (this.timezoneOffset !== other.timezoneOffset) { - other = other.convertToTimezoneOffset(this.timezoneOffset); - } + else if (!other.isQuantity) { + // convert it to a quantity w/ unit 1 + other = new Quantity(other, '1'); } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - // @ts-ignore - if (this[field] != null && other[field] != null) { - // if this value is greater than the other return with true. this is after other - // @ts-ignore - if (this[field] > other[field]) { - return true; - // if this value is greater than the other return with false. this is before - // @ts-ignore - } - else if (this[field] < other[field]) { - return false; - } - // execution continues if the values are the same - // if both dont have this precision, return true if precision is not defined - // @ts-ignore - } - else if (this[field] == null && other[field] == null) { - if (precision == null) { - return true; - } - else { - // we havent met precision yet - return null; - } - // otherwise they have inconclusive precision, return null - } - else { - return null; - } - // if precision is defined and we have reached expected precision, we can leave the loop - if (precision != null && precision === field) { - break; - } + var _a = (0, units_1.normalizeUnitsWhenPossible)(this.value, this.unit, other.value, other.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; + var resultValue = val1 * val2; + var resultUnit = (0, units_1.getProductOfUnits)(unit1, unit2); + // Check for invalid unit or value + if (resultUnit == null || (0, math_1.overflowsOrUnderflows)(resultValue)) { + return null; } - // if we made it here, then all fields matched and they are same - return true; + return new Quantity((0, math_1.decimalAdjust)('round', resultValue, -8), resultUnit); }; - AbstractDate.prototype.before = function (other, precision) { - if (!(other.isDate || other.isDateTime)) { + return Quantity; +}()); +exports.Quantity = Quantity; +function parseQuantity(str) { + var components = /([+|-]?\d+\.?\d*)\s*('(.+)')?/.exec(str); + if (components != null && components[1] != null) { + var value = parseFloat(components[1]); + if (!(0, math_1.isValidDecimal)(value)) { return null; } - else if (this.isDate && other.isDateTime) { - return this.getDateTime().before(other, precision); + var unit = void 0; + if (components[3] != null) { + unit = components[3].trim(); } - else if (this.isDateTime && other.isDate) { - other = other.getDateTime(); + else { + unit = ''; } - // @ts-ignore - if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { - throw new Error("Invalid precision: ".concat(precision)); + return new Quantity(value, unit); + } + else { + return null; + } +} +exports.parseQuantity = parseQuantity; +function doScaledAddition(a, b, scaleForB) { + if (a != null && a.isQuantity && b != null && b.isQuantity) { + var _a = (0, units_1.normalizeUnitsWhenPossible)(a.value, a.unit, b.value * scaleForB, b.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; + if (unit1 !== unit2) { + // not compatible units, so we can't do addition + return null; } - // make a copy of other in the correct timezone offset if they don't match. - // When comparing DateTime values with different timezone offsets, implementations - // should normalize to the timezone offset of the evaluation request timestamp, - // but only when the comparison precision is hours, minutes, seconds, or milliseconds. - if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { - if (this.timezoneOffset !== other.timezoneOffset) { - other = other.convertToTimezoneOffset(this.timezoneOffset); - } + var sum = val1 + val2; + if ((0, math_1.overflowsOrUnderflows)(sum)) { + return null; } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - // @ts-ignore - if (this[field] != null && other[field] != null) { - // if this value is less than the other return with true. this is before other - // @ts-ignore - if (this[field] < other[field]) { - return true; - // if this value is greater than the other return with false. this is after - // @ts-ignore - } - else if (this[field] > other[field]) { - return false; - } - // execution continues if the values are the same - // if both dont have this precision, return false if precision is not defined - // @ts-ignore + return new Quantity(sum, unit1); + } + else if (a.copy && a.add) { + // Date / DateTime require a CQL time unit + var cqlUnitB = (0, units_1.convertToCQLDateUnit)(b.unit) || b.unit; + return a.copy().add(b.value * scaleForB, cqlUnitB); + } + else { + throw new Error('Unsupported argument types.'); + } +} +function doAddition(a, b) { + return doScaledAddition(a, b, 1); +} +exports.doAddition = doAddition; +function doSubtraction(a, b) { + return doScaledAddition(a, b, -1); +} +exports.doSubtraction = doSubtraction; +function doDivision(a, b) { + if (a != null && a.isQuantity) { + return a.dividedBy(b); + } +} +exports.doDivision = doDivision; +function doMultiplication(a, b) { + if (a != null && a.isQuantity) { + return a.multiplyBy(b); + } + else { + return b.multiplyBy(a); + } +} +exports.doMultiplication = doMultiplication; + +},{"../util/math":90,"../util/units":91}],49:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Ratio = void 0; +var Ratio = /** @class */ (function () { + function Ratio(numerator, denominator) { + this.numerator = numerator; + this.denominator = denominator; + if (numerator == null) { + throw new Error('Cannot create a ratio with an undefined numerator'); + } + if (denominator == null) { + throw new Error('Cannot create a ratio with an undefined denominator'); + } + } + Object.defineProperty(Ratio.prototype, "isRatio", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Ratio.prototype.clone = function () { + return new Ratio(this.numerator.clone(), this.denominator.clone()); + }; + Ratio.prototype.toString = function () { + return "".concat(this.numerator.toString(), " : ").concat(this.denominator.toString()); + }; + Ratio.prototype.equals = function (other) { + if (other != null && other.isRatio) { + var divided_this = this.numerator.dividedBy(this.denominator); + var divided_other = other.numerator.dividedBy(other.denominator); + return divided_this === null || divided_this === void 0 ? void 0 : divided_this.equals(divided_other); + } + else { + return false; + } + }; + Ratio.prototype.equivalent = function (other) { + var equal = this.equals(other); + return equal != null ? equal : false; + }; + return Ratio; +}()); +exports.Ratio = Ratio; + +},{}],50:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Uncertainty = void 0; +var logic_1 = require("./logic"); +var Uncertainty = /** @class */ (function () { + function Uncertainty(low, high) { + var _a; + if (low === void 0) { low = null; } + this.low = low; + this.high = high; + var gt = function (a, b) { + if (typeof a !== typeof b) { + // TODO: This should probably throw rather than return false. + // Uncertainties with different types probably shouldn't be supported. + return false; } - else if (this[field] == null && other[field] == null) { - if (precision == null) { - return false; - } - else { - // we havent met precision yet - return null; - } - // otherwise they have inconclusive precision, return null + if (typeof a.after === 'function') { + return a.after(b); } else { - return null; - } - // if precision is defined and we have reached expected precision, we can leave the loop - if (precision != null && precision === field) { - break; + return a > b; } + }; + var isNonEnumerable = function (val) { + return val != null && (val.isCode || val.isConcept || val.isValueSet); + }; + if (typeof this.high === 'undefined') { + this.high = this.low; } - // if we made it here, then all fields matched and they are same - return false; - }; - AbstractDate.prototype.after = function (other, precision) { - if (!(other.isDate || other.isDateTime)) { - return null; + if (isNonEnumerable(this.low) || isNonEnumerable(this.high)) { + this.low = this.high = null; } - else if (this.isDate && other.isDateTime) { - return this.getDateTime().after(other, precision); + if (this.low != null && this.high != null && gt(this.low, this.high)) { + _a = [this.high, this.low], this.low = _a[0], this.high = _a[1]; } - else if (this.isDateTime && other.isDate) { - other = other.getDateTime(); + } + Uncertainty.from = function (obj) { + if (obj != null && obj.isUncertainty) { + return obj; } - // @ts-ignore - if (precision != null && this.constructor.FIELDS.indexOf(precision) < 0) { - throw new Error("Invalid precision: ".concat(precision)); + else { + return new Uncertainty(obj); } - // make a copy of other in the correct timezone offset if they don't match. - // When comparing DateTime values with different timezone offsets, implementations - // should normalize to the timezone offset of the evaluation request timestamp, - // but only when the comparison precision is hours, minutes, seconds, or milliseconds. - if (isPrecisionUnspecifiedOrGreaterThanDay(precision)) { - if (this.timezoneOffset !== other.timezoneOffset) { - other = other.convertToTimezoneOffset(this.timezoneOffset); - } + }; + Object.defineProperty(Uncertainty.prototype, "isUncertainty", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Uncertainty.prototype.copy = function () { + var newLow = this.low; + var newHigh = this.high; + if (typeof this.low.copy === 'function') { + newLow = this.low.copy(); } - // @ts-ignore - for (var _i = 0, _a = this.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - // @ts-ignore - if (this[field] != null && other[field] != null) { - // if this value is greater than the other return with true. this is after other - // @ts-ignore - if (this[field] > other[field]) { - return true; - // if this value is greater than the other return with false. this is before - // @ts-ignore - } - else if (this[field] < other[field]) { - return false; - } - // execution continues if the values are the same - // if both dont have this precision, return false if precision is not defined - // @ts-ignore + if (typeof this.high.copy === 'function') { + newHigh = this.high.copy(); + } + return new Uncertainty(newLow, newHigh); + }; + Uncertainty.prototype.isPoint = function () { + // Note: Can't use normal equality, as that fails for Javascript dates + // TODO: Fix after we don't need to support Javascript date uncertainties anymore + var lte = function (a, b) { + if (typeof a !== typeof b) { + return false; } - else if (this[field] == null && other[field] == null) { - if (precision == null) { - return false; - } - else { - // we havent met precision yet - return null; - } - // otherwise they have inconclusive precision, return null + if (typeof a.sameOrBefore === 'function') { + return a.sameOrBefore(b); } else { - return null; + return a <= b; } - // if precision is defined and we have reached expected precision, we can leave the loop - if (precision != null && precision === field) { - break; + }; + var gte = function (a, b) { + if (typeof a !== typeof b) { + return false; + } + if (typeof a.sameOrBefore === 'function') { + return a.sameOrAfter(b); + } + else { + return a >= b; + } + }; + return (this.low != null && this.high != null && lte(this.low, this.high) && gte(this.low, this.high)); + }; + Uncertainty.prototype.equals = function (other) { + other = Uncertainty.from(other); + return logic_1.ThreeValuedLogic.not(logic_1.ThreeValuedLogic.or(this.lessThan(other), this.greaterThan(other))); + }; + Uncertainty.prototype.lessThan = function (other) { + var lt = function (a, b) { + if (typeof a !== typeof b) { + return false; + } + if (typeof a.before === 'function') { + return a.before(b); + } + else { + return a < b; } + }; + other = Uncertainty.from(other); + var bestCase = this.low == null || other.high == null || lt(this.low, other.high); + var worstCase = this.high != null && other.low != null && lt(this.high, other.low); + if (bestCase === worstCase) { + return bestCase; + } + else { + return null; + } + }; + Uncertainty.prototype.greaterThan = function (other) { + return Uncertainty.from(other).lessThan(this); + }; + Uncertainty.prototype.lessThanOrEquals = function (other) { + return logic_1.ThreeValuedLogic.not(this.greaterThan(Uncertainty.from(other))); + }; + Uncertainty.prototype.greaterThanOrEquals = function (other) { + return logic_1.ThreeValuedLogic.not(this.lessThan(Uncertainty.from(other))); + }; + return Uncertainty; +}()); +exports.Uncertainty = Uncertainty; + +},{"./logic":47}],51:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AnyTrue = exports.AllTrue = exports.PopulationVariance = exports.Variance = exports.PopulationStdDev = exports.GeometricMean = exports.Product = exports.StdDev = exports.Mode = exports.Median = exports.Avg = exports.Max = exports.Min = exports.Sum = exports.Count = void 0; +var expression_1 = require("./expression"); +var util_1 = require("../util/util"); +var datatypes_1 = require("../datatypes/datatypes"); +var exception_1 = require("../datatypes/exception"); +var comparison_1 = require("../util/comparison"); +var builder_1 = require("./builder"); +var AggregateExpression = /** @class */ (function (_super) { + __extends(AggregateExpression, _super); + function AggregateExpression(json) { + var _this = _super.call(this, json) || this; + _this.source = (0, builder_1.build)(json.source); + return _this; + } + return AggregateExpression; +}(expression_1.Expression)); +var Count = /** @class */ (function (_super) { + __extends(Count, _super); + function Count(json) { + return _super.call(this, json) || this; + } + Count.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if ((0, util_1.typeIsArray)(items)) { + return (0, util_1.removeNulls)(items).length; } - // if we made it here, then all fields matched and they are same - return false; + return 0; }; - AbstractDate.prototype.add = function (offset, field) { - var _a; - if (offset === 0 || this.year == null) { - return this.copy(); + return Count; +}(AggregateExpression)); +exports.Count = Count; +var Sum = /** @class */ (function (_super) { + __extends(Sum, _super); + function Sum(json) { + return _super.call(this, json) || this; + } + Sum.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { + return null; } - // Use luxon to do the date math because it honors DST and it has the leap-year/end-of-month semantics we want. - // NOTE: The luxonDateTime will contain default values where this[unit] is null, but we'll account for that. - var luxonDateTime = this.toLuxonDateTime(); - // From the spec: "The operation is performed by converting the time-based quantity to the most precise value - // specified in the date/time (truncating any resulting decimal portion) and then adding it to the date/time value." - // However, since you can't really convert days to months, if "this" is less precise than the field being added, we can - // add to the earliest possible value of "this" or subtract from the latest possible value of "this" (depending on the - // sign of the offset), and then null out the imprecise fields again after doing the calculation. Due to the way - // luxonDateTime is constructed above, it is already at the earliest value, so only adjust if the offset is negative. - // @ts-ignore - var offsetIsMorePrecise = this[field] == null; //whether the quantity we are adding is more precise than "this". - if (offsetIsMorePrecise && offset < 0) { - luxonDateTime = luxonDateTime.endOf(this.getPrecision()); + try { + items = processQuantities(items); } - // Now do the actual math and convert it back to a Date/DateTime w/ originally null fields nulled out again - var luxonResult = luxonDateTime.plus((_a = {}, _a[field] = offset, _a)); - var result = this.constructor - .fromLuxonDateTime(luxonResult) - .reducedPrecision(this.getPrecision()); - // Luxon never has a null offset, but sometimes "this" does, so reset to null if applicable - if (this.isDateTime && this.timezoneOffset == null) { - result.timezoneOffset = null; + catch (e) { + return null; } - // Can't use overflowsOrUnderflows from math.js due to circular dependencies when we require it - if (result.after(exports.MAX_DATETIME_VALUE || result.before(exports.MIN_DATETIME_VALUE))) { + if (items.length === 0) { return null; } + if (hasOnlyQuantities(items)) { + var values = getValuesFromQuantities(items); + var sum = values.reduce(function (x, y) { return x + y; }); + return new datatypes_1.Quantity(sum, items[0].unit); + } else { - return result; + return items.reduce(function (x, y) { return x + y; }); } }; - AbstractDate.prototype.getFieldFloor = function (field) { - switch (field) { - case 'month': - return 1; - case 'day': - return 1; - case 'hour': - return 0; - case 'minute': - return 0; - case 'second': - return 0; - case 'millisecond': - return 0; - default: - throw new Error('Tried to floor a field that has no floor value: ' + field); + return Sum; +}(AggregateExpression)); +exports.Sum = Sum; +var Min = /** @class */ (function (_super) { + __extends(Min, _super); + function Min(json) { + return _super.call(this, json) || this; + } + Min.prototype.exec = function (ctx) { + var list = this.source.execute(ctx); + if (list == null) { + return null; } - }; - AbstractDate.prototype.getFieldCieling = function (field) { - switch (field) { - case 'month': - return 12; - case 'day': - return daysInMonth(this.year, this.month); - case 'hour': - return 23; - case 'minute': - return 59; - case 'second': - return 59; - case 'millisecond': - return 999; - default: - throw new Error('Tried to clieling a field that has no cieling value: ' + field); + var listWithoutNulls = (0, util_1.removeNulls)(list); + // Check for incompatible units and return null. We don't want to convert + // the units for Min/Max, so we throw away the converted array if it succeeds + try { + processQuantities(list); } - }; - return AbstractDate; -}()); -var DateTime = /** @class */ (function (_super) { - __extends(DateTime, _super); - function DateTime(year, month, day, hour, minute, second, millisecond, timezoneOffset) { - if (year === void 0) { year = null; } - if (month === void 0) { month = null; } - if (day === void 0) { day = null; } - if (hour === void 0) { hour = null; } - if (minute === void 0) { minute = null; } - if (second === void 0) { second = null; } - if (millisecond === void 0) { millisecond = null; } - var _this = - // from the spec: If no timezone is specified, the timezone of the evaluation request timestamp is used. - // NOTE: timezoneOffset will be explicitly null for the Time overload, whereas - // it will be undefined if simply unspecified - _super.call(this, year, month, day) || this; - _this.hour = hour; - _this.minute = minute; - _this.second = second; - _this.millisecond = millisecond; - if (timezoneOffset === undefined) { - _this.timezoneOffset = (new util_1.jsDate().getTimezoneOffset() / 60) * -1; + catch (e) { + return null; } - else { - _this.timezoneOffset = timezoneOffset; + if (listWithoutNulls.length === 0) { + return null; } - return _this; + // We assume the list is an array of all the same type. + var minimum = listWithoutNulls[0]; + for (var _i = 0, listWithoutNulls_1 = listWithoutNulls; _i < listWithoutNulls_1.length; _i++) { + var element = listWithoutNulls_1[_i]; + if ((0, comparison_1.lessThan)(element, minimum)) { + minimum = element; + } + } + return minimum; + }; + return Min; +}(AggregateExpression)); +exports.Min = Min; +var Max = /** @class */ (function (_super) { + __extends(Max, _super); + function Max(json) { + return _super.call(this, json) || this; } - DateTime.parse = function (string) { - if (string === null) { + Max.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (items == null) { return null; } - var matches = /(\d{4})(-(\d{2}))?(-(\d{2}))?(T((\d{2})(:(\d{2})(:(\d{2})(\.(\d+))?)?)?)?(Z|(([+-])(\d{2})(:?(\d{2}))?))?)?/.exec(string); - if (matches == null) { + var listWithoutNulls = (0, util_1.removeNulls)(items); + // Check for incompatible units and return null. We don't want to convert + // the units for Min/Max, so we throw away the converted array if it succeeds + try { + processQuantities(items); + } + catch (e) { return null; } - var years = matches[1]; - var months = matches[3]; - var days = matches[5]; - var hours = matches[8]; - var minutes = matches[10]; - var seconds = matches[12]; - var milliseconds = matches[14]; - if (milliseconds != null) { - milliseconds = (0, util_1.normalizeMillisecondsField)(milliseconds); + if (listWithoutNulls.length === 0) { + return null; } - if (milliseconds != null) { - string = (0, util_1.normalizeMillisecondsFieldInString)(string, matches[14]); + // We assume the list is an array of all the same type. + var maximum = listWithoutNulls[0]; + for (var _i = 0, listWithoutNulls_2 = listWithoutNulls; _i < listWithoutNulls_2.length; _i++) { + var element = listWithoutNulls_2[_i]; + if ((0, comparison_1.greaterThan)(element, maximum)) { + maximum = element; + } } - if (!isValidDateTimeStringFormat(string)) { + return maximum; + }; + return Max; +}(AggregateExpression)); +exports.Max = Max; +var Avg = /** @class */ (function (_super) { + __extends(Avg, _super); + function Avg(json) { + return _super.call(this, json) || this; + } + Avg.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { return null; } - // convert the args to integers - var args = [years, months, days, hours, minutes, seconds, milliseconds].map(function (arg) { - return arg != null ? parseInt(arg) : arg; - }); - // convert timezone offset to decimal and add it to arguments - if (matches[18] != null) { - var num = parseInt(matches[18]) + (matches[20] != null ? parseInt(matches[20]) / 60 : 0); - args.push(matches[17] === '+' ? num : num * -1); + try { + items = processQuantities(items); } - else if (matches[15] === 'Z') { - args.push(0); + catch (e) { + return null; } - // @ts-ignore - return new (DateTime.bind.apply(DateTime, __spreadArray([void 0], args, false)))(); - }; - // TODO: Note: using the jsDate type causes issues, fix later - DateTime.fromJSDate = function (date, timezoneOffset) { - //This is from a JS Date, not a CQL Date - if (date instanceof DateTime) { - return date; + if (items.length === 0) { + return null; } - if (timezoneOffset != null) { - date = new util_1.jsDate(date.getTime() + timezoneOffset * 60 * 60 * 1000); - return new DateTime(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds(), timezoneOffset); + if (hasOnlyQuantities(items)) { + var values = getValuesFromQuantities(items); + var sum = values.reduce(function (x, y) { return x + y; }); + return new datatypes_1.Quantity(sum / values.length, items[0].unit); } else { - return new DateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); - } - }; - DateTime.fromLuxonDateTime = function (luxonDT) { - if (luxonDT instanceof DateTime) { - return luxonDT; + var sum = items.reduce(function (x, y) { return x + y; }); + return sum / items.length; } - return new DateTime(luxonDT.year, luxonDT.month, luxonDT.day, luxonDT.hour, luxonDT.minute, luxonDT.second, luxonDT.millisecond, luxonDT.offset / 60); - }; - Object.defineProperty(DateTime.prototype, "isDateTime", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(DateTime.prototype, "isDate", { - get: function () { - return false; - }, - enumerable: false, - configurable: true - }); - DateTime.prototype.copy = function () { - return new DateTime(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond, this.timezoneOffset); }; - DateTime.prototype.successor = function () { - if (this.millisecond != null) { - return this.add(1, DateTime.Unit.MILLISECOND); - } - else if (this.second != null) { - return this.add(1, DateTime.Unit.SECOND); - } - else if (this.minute != null) { - return this.add(1, DateTime.Unit.MINUTE); + return Avg; +}(AggregateExpression)); +exports.Avg = Avg; +var Median = /** @class */ (function (_super) { + __extends(Median, _super); + function Median(json) { + return _super.call(this, json) || this; + } + Median.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { + return null; } - else if (this.hour != null) { - return this.add(1, DateTime.Unit.HOUR); + if (items.length === 0) { + return null; } - else if (this.day != null) { - return this.add(1, DateTime.Unit.DAY); + try { + items = processQuantities(items); } - else if (this.month != null) { - return this.add(1, DateTime.Unit.MONTH); + catch (e) { + return null; } - else if (this.year != null) { - return this.add(1, DateTime.Unit.YEAR); + if (!hasOnlyQuantities(items)) { + return medianOfNumbers(items); } + var values = getValuesFromQuantities(items); + var median = medianOfNumbers(values); + return new datatypes_1.Quantity(median, items[0].unit); }; - DateTime.prototype.predecessor = function () { - if (this.millisecond != null) { - return this.add(-1, DateTime.Unit.MILLISECOND); - } - else if (this.second != null) { - return this.add(-1, DateTime.Unit.SECOND); + return Median; +}(AggregateExpression)); +exports.Median = Median; +var Mode = /** @class */ (function (_super) { + __extends(Mode, _super); + function Mode(json) { + return _super.call(this, json) || this; + } + Mode.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { + return null; } - else if (this.minute != null) { - return this.add(-1, DateTime.Unit.MINUTE); + if (items.length === 0) { + return null; } - else if (this.hour != null) { - return this.add(-1, DateTime.Unit.HOUR); + var filtered; + try { + filtered = processQuantities(items); } - else if (this.day != null) { - return this.add(-1, DateTime.Unit.DAY); + catch (e) { + return null; } - else if (this.month != null) { - return this.add(-1, DateTime.Unit.MONTH); + if (hasOnlyQuantities(filtered)) { + var values = getValuesFromQuantities(filtered); + var mode = this.mode(values); + if (mode.length === 1) { + mode = mode[0]; + } + return new datatypes_1.Quantity(mode, items[0].unit); } - else if (this.year != null) { - return this.add(-1, DateTime.Unit.YEAR); + else { + var mode = this.mode(filtered); + if (mode.length === 1) { + return mode[0]; + } + else { + return mode; + } } }; - DateTime.prototype.convertToTimezoneOffset = function (timezoneOffset) { - if (timezoneOffset === void 0) { timezoneOffset = 0; } - var shiftedLuxonDT = this.toLuxonDateTime().setZone(luxon_1.FixedOffsetZone.instance(timezoneOffset * 60)); - var shiftedDT = DateTime.fromLuxonDateTime(shiftedLuxonDT); - return shiftedDT.reducedPrecision(this.getPrecision()); + Mode.prototype.mode = function (arr) { + var max = 0; + var counts = {}; + var results = []; + for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) { + var elem = arr_1[_i]; + var cnt = (counts[elem] = (counts[elem] != null ? counts[elem] : 0) + 1); + if (cnt === max && !results.includes(elem)) { + results.push(elem); + } + else if (cnt > max) { + results = [elem]; + max = cnt; + } + } + return results; }; - DateTime.prototype.differenceBetween = function (other, unitField) { - other = this._implicitlyConvert(other); - if (other == null || !other.isDateTime) { + return Mode; +}(AggregateExpression)); +exports.Mode = Mode; +var StdDev = /** @class */ (function (_super) { + __extends(StdDev, _super); + function StdDev(json) { + var _this = _super.call(this, json) || this; + _this.type = 'standard_deviation'; + return _this; + } + StdDev.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { return null; } - // According to CQL spec: - // * "Difference calculations are performed by truncating the datetime values at the next precision, - // and then performing the corresponding duration calculation on the truncated values." - // * "When difference is calculated for hours or finer units, timezone offsets should be normalized - // prior to truncation to correctly consider real (actual elapsed) time. When difference is calculated - // for days or coarser units, however, the time components (including timezone offset) should be truncated - // without normalization to correctly reflect the difference in calendar days, months, and years." - var a = this.toLuxonUncertainty(); - var b = other.toLuxonUncertainty(); - // If unit is days or above, reset all the DateTimes to UTC since TZ offset should not be considered; - // Otherwise, we don't actually have to "normalize" to a common TZ because Luxon takes TZ into account. - if ([DateTime.Unit.YEAR, DateTime.Unit.MONTH, DateTime.Unit.WEEK, DateTime.Unit.DAY].includes(unitField)) { - a.low = a.low.toUTC(0, { keepLocalTime: true }); - a.high = a.high.toUTC(0, { keepLocalTime: true }); - b.low = b.low.toUTC(0, { keepLocalTime: true }); - b.high = b.high.toUTC(0, { keepLocalTime: true }); + try { + items = processQuantities(items); } - // Truncate all dates at precision below specified unit - a.low = truncateLuxonDateTime(a.low, unitField); - a.high = truncateLuxonDateTime(a.high, unitField); - b.low = truncateLuxonDateTime(b.low, unitField); - b.high = truncateLuxonDateTime(b.high, unitField); - // Return the duration based on the normalize and truncated values - return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); - }; - DateTime.prototype.durationBetween = function (other, unitField) { - other = this._implicitlyConvert(other); - if (other == null || !other.isDateTime) { + catch (e) { return null; } - var a = this.toLuxonUncertainty(); - var b = other.toLuxonUncertainty(); - return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); - }; - DateTime.prototype.isUTC = function () { - // A timezoneOffset of 0 indicates UTC time. - return !this.timezoneOffset; - }; - DateTime.prototype.getPrecision = function () { - var result = null; - if (this.year != null) { - result = DateTime.Unit.YEAR; + if (items.length === 0) { + return null; + } + if (hasOnlyQuantities(items)) { + var values = getValuesFromQuantities(items); + var stdDev = this.standardDeviation(values); + return new datatypes_1.Quantity(stdDev, items[0].unit); } else { - return result; + return this.standardDeviation(items); } - if (this.month != null) { - result = DateTime.Unit.MONTH; + }; + StdDev.prototype.standardDeviation = function (list) { + var val = this.stats(list); + if (val) { + return val[this.type]; } - else { - return result; + }; + StdDev.prototype.stats = function (list) { + var sum = list.reduce(function (x, y) { return x + y; }); + var mean = sum / list.length; + var sumOfSquares = 0; + for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { + var sq = list_1[_i]; + sumOfSquares += Math.pow(sq - mean, 2); } - if (this.day != null) { - result = DateTime.Unit.DAY; + var std_var = (1 / (list.length - 1)) * sumOfSquares; + var pop_var = (1 / list.length) * sumOfSquares; + var std_dev = Math.sqrt(std_var); + var pop_dev = Math.sqrt(pop_var); + return { + standard_variance: std_var, + population_variance: pop_var, + standard_deviation: std_dev, + population_deviation: pop_dev + }; + }; + return StdDev; +}(AggregateExpression)); +exports.StdDev = StdDev; +var Product = /** @class */ (function (_super) { + __extends(Product, _super); + function Product(json) { + return _super.call(this, json) || this; + } + Product.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { + return null; } - else { - return result; + try { + items = processQuantities(items); } - if (this.hour != null) { - result = DateTime.Unit.HOUR; + catch (e) { + return null; + } + if (items.length === 0) { + return null; + } + if (hasOnlyQuantities(items)) { + var values = getValuesFromQuantities(items); + var product = values.reduce(function (x, y) { return x * y; }); + // Units are not multiplied for the geometric product + return new datatypes_1.Quantity(product, items[0].unit); } else { - return result; + return items.reduce(function (x, y) { return x * y; }); } - if (this.minute != null) { - result = DateTime.Unit.MINUTE; + }; + return Product; +}(AggregateExpression)); +exports.Product = Product; +var GeometricMean = /** @class */ (function (_super) { + __extends(GeometricMean, _super); + function GeometricMean(json) { + return _super.call(this, json) || this; + } + GeometricMean.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + if (!(0, util_1.typeIsArray)(items)) { + return null; } - else { - return result; + try { + items = processQuantities(items); } - if (this.second != null) { - result = DateTime.Unit.SECOND; + catch (e) { + return null; } - else { - return result; + if (items.length === 0) { + return null; } - if (this.millisecond != null) { - result = DateTime.Unit.MILLISECOND; + if (hasOnlyQuantities(items)) { + var values = getValuesFromQuantities(items); + var product = values.reduce(function (x, y) { return x * y; }); + var geoMean = Math.pow(product, 1.0 / items.length); + return new datatypes_1.Quantity(geoMean, items[0].unit); + } + else { + var product = items.reduce(function (x, y) { return x * y; }); + return Math.pow(product, 1.0 / items.length); } - return result; - }; - DateTime.prototype.getPrecisionValue = function () { - return this.isTime() - ? TIME_PRECISION_VALUE_MAP.get(this.getPrecision()) - : DATETIME_PRECISION_VALUE_MAP.get(this.getPrecision()); - }; - DateTime.prototype.toLuxonDateTime = function () { - var _a, _b, _c, _d, _e, _f, _g; - var offsetMins = this.timezoneOffset != null - ? this.timezoneOffset * 60 - : new util_1.jsDate().getTimezoneOffset() * -1; - return luxon_1.DateTime.fromObject({ - year: (_a = this.year) !== null && _a !== void 0 ? _a : undefined, - month: (_b = this.month) !== null && _b !== void 0 ? _b : undefined, - day: (_c = this.day) !== null && _c !== void 0 ? _c : undefined, - hour: (_d = this.hour) !== null && _d !== void 0 ? _d : undefined, - minute: (_e = this.minute) !== null && _e !== void 0 ? _e : undefined, - second: (_f = this.second) !== null && _f !== void 0 ? _f : undefined, - millisecond: (_g = this.millisecond) !== null && _g !== void 0 ? _g : undefined, - zone: luxon_1.FixedOffsetZone.instance(offsetMins) - }); }; - DateTime.prototype.toLuxonUncertainty = function () { - var low = this.toLuxonDateTime(); - var high = low.endOf(this.getPrecision()); - return new uncertainty_1.Uncertainty(low, high); + return GeometricMean; +}(AggregateExpression)); +exports.GeometricMean = GeometricMean; +var PopulationStdDev = /** @class */ (function (_super) { + __extends(PopulationStdDev, _super); + function PopulationStdDev(json) { + var _this = _super.call(this, json) || this; + _this.type = 'population_deviation'; + return _this; + } + return PopulationStdDev; +}(StdDev)); +exports.PopulationStdDev = PopulationStdDev; +var Variance = /** @class */ (function (_super) { + __extends(Variance, _super); + function Variance(json) { + var _this = _super.call(this, json) || this; + _this.type = 'standard_variance'; + return _this; + } + return Variance; +}(StdDev)); +exports.Variance = Variance; +var PopulationVariance = /** @class */ (function (_super) { + __extends(PopulationVariance, _super); + function PopulationVariance(json) { + var _this = _super.call(this, json) || this; + _this.type = 'population_variance'; + return _this; + } + return PopulationVariance; +}(StdDev)); +exports.PopulationVariance = PopulationVariance; +var AllTrue = /** @class */ (function (_super) { + __extends(AllTrue, _super); + function AllTrue(json) { + return _super.call(this, json) || this; + } + AllTrue.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + return (0, util_1.allTrue)((0, util_1.removeNulls)(items)); }; - DateTime.prototype.toJSDate = function (ignoreTimezone) { - if (ignoreTimezone === void 0) { ignoreTimezone = false; } - var luxonDT = this.toLuxonDateTime(); - // I don't know if anyone is using "ignoreTimezone" anymore (we aren't), but just in case - if (ignoreTimezone) { - var offset = new util_1.jsDate().getTimezoneOffset() * -1; - luxonDT = luxonDT.setZone(luxon_1.FixedOffsetZone.instance(offset), { keepLocalTime: true }); - } - return luxonDT.toJSDate(); + return AllTrue; +}(AggregateExpression)); +exports.AllTrue = AllTrue; +var AnyTrue = /** @class */ (function (_super) { + __extends(AnyTrue, _super); + function AnyTrue(json) { + return _super.call(this, json) || this; + } + AnyTrue.prototype.exec = function (ctx) { + var items = this.source.execute(ctx); + return (0, util_1.anyTrue)(items); }; - DateTime.prototype.toJSON = function () { - return this.toString(); + return AnyTrue; +}(AggregateExpression)); +exports.AnyTrue = AnyTrue; +function processQuantities(values) { + var items = (0, util_1.removeNulls)(values); + if (hasOnlyQuantities(items)) { + return convertAllUnits(items); + } + else if (hasSomeQuantities(items)) { + throw new exception_1.Exception('Cannot perform aggregate operations on mixed values of Quantities and non Quantities'); + } + else { + return items; + } +} +function getValuesFromQuantities(quantities) { + return quantities.map(function (quantity) { return quantity.value; }); +} +function hasOnlyQuantities(arr) { + return arr.every(function (x) { return x.isQuantity; }); +} +function hasSomeQuantities(arr) { + return arr.some(function (x) { return x.isQuantity; }); +} +function convertAllUnits(arr) { + // convert all quantities in array to match the unit of the first item + return arr.map(function (q) { return q.convertUnit(arr[0].unit); }); +} +function medianOfNumbers(numbers) { + var items = (0, util_1.numerical_sort)(numbers, 'asc'); + if (items.length % 2 === 1) { + // Odd number of items + return items[(items.length - 1) / 2]; + } + else { + // Even number of items + return (items[items.length / 2 - 1] + items[items.length / 2]) / 2; + } +} + +},{"../datatypes/datatypes":43,"../datatypes/exception":45,"../util/comparison":89,"../util/util":92,"./builder":53,"./expression":59}],52:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); }; - DateTime.prototype._pad = function (num) { - return String('0' + num).slice(-2); + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - DateTime.prototype.toString = function () { - if (this.isTime()) { - return this.toStringTime(); +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Predecessor = exports.Successor = exports.MaxValue = exports.MinValue = exports.Power = exports.Log = exports.Exp = exports.Ln = exports.Round = exports.Negate = exports.Abs = exports.Truncate = exports.Floor = exports.Ceiling = exports.Modulo = exports.TruncatedDivide = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = void 0; +var expression_1 = require("./expression"); +var MathUtil = __importStar(require("../util/math")); +var quantity_1 = require("../datatypes/quantity"); +var uncertainty_1 = require("../datatypes/uncertainty"); +var builder_1 = require("./builder"); +var Add = /** @class */ (function (_super) { + __extends(Add, _super); + function Add(json) { + return _super.call(this, json) || this; + } + Add.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; } - else { - return this.toStringDateTime(); + var sum = args.reduce(function (x, y) { + if (x.isUncertainty && !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y, y); + } + else if (y.isUncertainty && !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x, x); + } + if (x.isQuantity || x.isDateTime || x.isDate || (x.isTime && x.isTime())) { + return (0, quantity_1.doAddition)(x, y); + } + else if (x.isUncertainty && y.isUncertainty) { + if (x.low.isQuantity || + x.low.isDateTime || + x.low.isDate || + (x.low.isTime && x.low.isTime())) { + return new uncertainty_1.Uncertainty((0, quantity_1.doAddition)(x.low, y.low), (0, quantity_1.doAddition)(x.high, y.high)); + } + else { + return new uncertainty_1.Uncertainty(x.low + y.low, x.high + y.high); + } + } + else { + return x + y; + } + }); + if (MathUtil.overflowsOrUnderflows(sum)) { + return null; } + return sum; }; - DateTime.prototype.toStringTime = function () { - var str = ''; - if (this.hour != null) { - str += this._pad(this.hour); - if (this.minute != null) { - str += ':' + this._pad(this.minute); - if (this.second != null) { - str += ':' + this._pad(this.second); - if (this.millisecond != null) { - str += '.' + String('00' + this.millisecond).slice(-3); - } + return Add; +}(expression_1.Expression)); +exports.Add = Add; +var Subtract = /** @class */ (function (_super) { + __extends(Subtract, _super); + function Subtract(json) { + return _super.call(this, json) || this; + } + Subtract.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; + } + var difference = args.reduce(function (x, y) { + if (x.isUncertainty && !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y, y); + } + else if (y.isUncertainty && !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x, x); + } + if (x.isQuantity || x.isDateTime || x.isDate) { + return (0, quantity_1.doSubtraction)(x, y); + } + else if (x.isUncertainty && y.isUncertainty) { + if (x.low.isQuantity || x.low.isDateTime || x.low.isDate) { + return new uncertainty_1.Uncertainty((0, quantity_1.doSubtraction)(x.low, y.high), (0, quantity_1.doSubtraction)(x.high, y.low)); + } + else { + return new uncertainty_1.Uncertainty(x.low - y.high, x.high - y.low); } } + else { + return x - y; + } + }); + if (MathUtil.overflowsOrUnderflows(difference)) { + return null; } - return str; + return difference; }; - DateTime.prototype.toStringDateTime = function () { - var str = ''; - if (this.year != null) { - str += this.year; - if (this.month != null) { - str += '-' + this._pad(this.month); - if (this.day != null) { - str += '-' + this._pad(this.day); - if (this.hour != null) { - str += 'T' + this._pad(this.hour); - if (this.minute != null) { - str += ':' + this._pad(this.minute); - if (this.second != null) { - str += ':' + this._pad(this.second); - if (this.millisecond != null) { - str += '.' + String('00' + this.millisecond).slice(-3); - } - } - } - } + return Subtract; +}(expression_1.Expression)); +exports.Subtract = Subtract; +var Multiply = /** @class */ (function (_super) { + __extends(Multiply, _super); + function Multiply(json) { + return _super.call(this, json) || this; + } + Multiply.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; + } + var product = args.reduce(function (x, y) { + if (x.isUncertainty && !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y, y); + } + else if (y.isUncertainty && !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x, x); + } + if (x.isQuantity || y.isQuantity) { + return (0, quantity_1.doMultiplication)(x, y); + } + else if (x.isUncertainty && y.isUncertainty) { + if (x.low.isQuantity) { + return new uncertainty_1.Uncertainty((0, quantity_1.doMultiplication)(x.low, y.low), (0, quantity_1.doMultiplication)(x.high, y.high)); + } + else { + return new uncertainty_1.Uncertainty(x.low * y.low, x.high * y.high); } } + else { + return x * y; + } + }); + if (MathUtil.overflowsOrUnderflows(product)) { + return null; } - if (str.indexOf('T') !== -1 && this.timezoneOffset != null) { - str += this.timezoneOffset < 0 ? '-' : '+'; - var offsetHours = Math.floor(Math.abs(this.timezoneOffset)); - str += this._pad(offsetHours); - var offsetMin = (Math.abs(this.timezoneOffset) - offsetHours) * 60; - str += ':' + this._pad(offsetMin); - } - return str; - }; - DateTime.prototype.getDateTime = function () { - return this; - }; - DateTime.prototype.getDate = function () { - return new Date(this.year, this.month, this.day); - }; - DateTime.prototype.getTime = function () { - // Times no longer have timezoneOffets, so we must explicitly set it to null - return new DateTime(0, 1, 1, this.hour, this.minute, this.second, this.millisecond, null); + return product; }; - DateTime.prototype.isTime = function () { - return this.year === 0 && this.month === 1 && this.day === 1; + return Multiply; +}(expression_1.Expression)); +exports.Multiply = Multiply; +var Divide = /** @class */ (function (_super) { + __extends(Divide, _super); + function Divide(json) { + return _super.call(this, json) || this; + } + Divide.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; + } + var quotient = args.reduce(function (x, y) { + if (x.isUncertainty && !y.isUncertainty) { + y = new uncertainty_1.Uncertainty(y, y); + } + else if (y.isUncertainty && !x.isUncertainty) { + x = new uncertainty_1.Uncertainty(x, x); + } + if (x.isQuantity) { + return (0, quantity_1.doDivision)(x, y); + } + else if (x.isUncertainty && y.isUncertainty) { + if (x.low.isQuantity) { + return new uncertainty_1.Uncertainty((0, quantity_1.doDivision)(x.low, y.high), (0, quantity_1.doDivision)(x.high, y.low)); + } + else { + return new uncertainty_1.Uncertainty(x.low / y.high, x.high / y.low); + } + } + else { + return x / y; + } + }); + // Note, anything divided by 0 is Infinity in Javascript, which will be + // considered as overflow by this check. + if (MathUtil.overflowsOrUnderflows(quotient)) { + return null; + } + return quotient; }; - DateTime.prototype._implicitlyConvert = function (other) { - if (other != null && other.isDate) { - return other.getDateTime(); + return Divide; +}(expression_1.Expression)); +exports.Divide = Divide; +var TruncatedDivide = /** @class */ (function (_super) { + __extends(TruncatedDivide, _super); + function TruncatedDivide(json) { + return _super.call(this, json) || this; + } + TruncatedDivide.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; } - return other; + var quotient = args.reduce(function (x, y) { return x / y; }); + var truncatedQuotient = quotient >= 0 ? Math.floor(quotient) : Math.ceil(quotient); + if (MathUtil.overflowsOrUnderflows(truncatedQuotient)) { + return null; + } + return truncatedQuotient; }; - DateTime.prototype.reducedPrecision = function (unitField) { - if (unitField === void 0) { unitField = DateTime.Unit.MILLISECOND; } - var reduced = this.copy(); - if (unitField != null && unitField !== DateTime.Unit.MILLISECOND) { - var fieldIndex = DateTime.FIELDS.indexOf(unitField); - var fieldsToRemove = DateTime.FIELDS.slice(fieldIndex + 1); - for (var _i = 0, fieldsToRemove_1 = fieldsToRemove; _i < fieldsToRemove_1.length; _i++) { - var field = fieldsToRemove_1[_i]; - // @ts-ignore - reduced[field] = null; - } + return TruncatedDivide; +}(expression_1.Expression)); +exports.TruncatedDivide = TruncatedDivide; +var Modulo = /** @class */ (function (_super) { + __extends(Modulo, _super); + function Modulo(json) { + return _super.call(this, json) || this; + } + Modulo.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; } - return reduced; + var modulo = args.reduce(function (x, y) { return x % y; }); + return MathUtil.decimalOrNull(modulo); }; - DateTime.Unit = { - YEAR: 'year', - MONTH: 'month', - WEEK: 'week', - DAY: 'day', - HOUR: 'hour', - MINUTE: 'minute', - SECOND: 'second', - MILLISECOND: 'millisecond' + return Modulo; +}(expression_1.Expression)); +exports.Modulo = Modulo; +var Ceiling = /** @class */ (function (_super) { + __extends(Ceiling, _super); + function Ceiling(json) { + return _super.call(this, json) || this; + } + Ceiling.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; + } + return Math.ceil(arg); }; - DateTime.FIELDS = [ - DateTime.Unit.YEAR, - DateTime.Unit.MONTH, - DateTime.Unit.DAY, - DateTime.Unit.HOUR, - DateTime.Unit.MINUTE, - DateTime.Unit.SECOND, - DateTime.Unit.MILLISECOND - ]; - return DateTime; -}(AbstractDate)); -exports.DateTime = DateTime; -var Date = /** @class */ (function (_super) { - __extends(Date, _super); - function Date(year, month, day) { - if (year === void 0) { year = null; } - if (month === void 0) { month = null; } - if (day === void 0) { day = null; } - return _super.call(this, year, month, day) || this; + return Ceiling; +}(expression_1.Expression)); +exports.Ceiling = Ceiling; +var Floor = /** @class */ (function (_super) { + __extends(Floor, _super); + function Floor(json) { + return _super.call(this, json) || this; } - Date.parse = function (string) { - if (string === null) { - return null; - } - var matches = /(\d{4})(-(\d{2}))?(-(\d{2}))?/.exec(string); - if (matches == null) { + Floor.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { return null; } - var years = matches[1]; - var months = matches[3]; - var days = matches[5]; - if (!isValidDateStringFormat(string)) { + return Math.floor(arg); + }; + return Floor; +}(expression_1.Expression)); +exports.Floor = Floor; +var Truncate = /** @class */ (function (_super) { + __extends(Truncate, _super); + function Truncate(json) { + return _super.call(this, json) || this; + } + Truncate.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { return null; } - // convert args to integers - var args = [years, months, days].map(function (arg) { return (arg != null ? parseInt(arg) : arg); }); - // @ts-ignore - return new (Date.bind.apply(Date, __spreadArray([void 0], args, false)))(); - }; - Object.defineProperty(Date.prototype, "isDate", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(Date.prototype, "isDateTime", { - get: function () { - return false; - }, - enumerable: false, - configurable: true - }); - Date.prototype.copy = function () { - return new Date(this.year, this.month, this.day); + return arg >= 0 ? Math.floor(arg) : Math.ceil(arg); }; - Date.prototype.successor = function () { - if (this.day != null) { - return this.add(1, Date.Unit.DAY); + return Truncate; +}(expression_1.Expression)); +exports.Truncate = Truncate; +var Abs = /** @class */ (function (_super) { + __extends(Abs, _super); + function Abs(json) { + return _super.call(this, json) || this; + } + Abs.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - else if (this.month != null) { - return this.add(1, Date.Unit.MONTH); + else if (arg.isQuantity) { + return new quantity_1.Quantity(Math.abs(arg.value), arg.unit); } - else if (this.year != null) { - return this.add(1, Date.Unit.YEAR); + else { + return Math.abs(arg); } }; - Date.prototype.predecessor = function () { - if (this.day != null) { - return this.add(-1, Date.Unit.DAY); + return Abs; +}(expression_1.Expression)); +exports.Abs = Abs; +var Negate = /** @class */ (function (_super) { + __extends(Negate, _super); + function Negate(json) { + return _super.call(this, json) || this; + } + Negate.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - else if (this.month != null) { - return this.add(-1, Date.Unit.MONTH); + else if (arg.isQuantity) { + return new quantity_1.Quantity(arg.value * -1, arg.unit); } - else if (this.year != null) { - return this.add(-1, Date.Unit.YEAR); + else { + return arg * -1; } }; - Date.prototype.differenceBetween = function (other, unitField) { - if (other != null && other.isDateTime) { - return this.getDateTime().differenceBetween(other, unitField); + return Negate; +}(expression_1.Expression)); +exports.Negate = Negate; +var Round = /** @class */ (function (_super) { + __extends(Round, _super); + function Round(json) { + var _this = _super.call(this, json) || this; + _this.precision = (0, builder_1.build)(json.precision); + return _this; + } + Round.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - if (other == null || !other.isDate) { + var dec = this.precision != null ? this.precision.execute(ctx) : 0; + return Math.round(arg * Math.pow(10, dec)) / Math.pow(10, dec); + }; + return Round; +}(expression_1.Expression)); +exports.Round = Round; +var Ln = /** @class */ (function (_super) { + __extends(Ln, _super); + function Ln(json) { + return _super.call(this, json) || this; + } + Ln.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { return null; } - // According to CQL spec: - // * "Difference calculations are performed by truncating the datetime values at the next precision, - // and then performing the corresponding duration calculation on the truncated values." - var a = this.toLuxonUncertainty(); - var b = other.toLuxonUncertainty(); - // Truncate all dates at precision below specified unit - a.low = truncateLuxonDateTime(a.low, unitField); - a.high = truncateLuxonDateTime(a.high, unitField); - b.low = truncateLuxonDateTime(b.low, unitField); - b.high = truncateLuxonDateTime(b.high, unitField); - // Return the duration based on the normalize and truncated values - return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + var ln = Math.log(arg); + return MathUtil.decimalOrNull(ln); }; - Date.prototype.durationBetween = function (other, unitField) { - if (other != null && other.isDateTime) { - return this.getDateTime().durationBetween(other, unitField); + return Ln; +}(expression_1.Expression)); +exports.Ln = Ln; +var Exp = /** @class */ (function (_super) { + __extends(Exp, _super); + function Exp(json) { + return _super.call(this, json) || this; + } + Exp.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - if (other == null || !other.isDate) { + var power = Math.exp(arg); + if (MathUtil.overflowsOrUnderflows(power)) { return null; } - var a = this.toLuxonUncertainty(); - var b = other.toLuxonUncertainty(); - return new uncertainty_1.Uncertainty(wholeLuxonDuration(b.low.diff(a.high, unitField), unitField), wholeLuxonDuration(b.high.diff(a.low, unitField), unitField)); + return power; }; - Date.prototype.getPrecision = function () { - var result = null; - if (this.year != null) { - result = Date.Unit.YEAR; - } - else { - return result; + return Exp; +}(expression_1.Expression)); +exports.Exp = Exp; +var Log = /** @class */ (function (_super) { + __extends(Log, _super); + function Log(json) { + return _super.call(this, json) || this; + } + Log.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; } - if (this.month != null) { - result = Date.Unit.MONTH; + var log = args.reduce(function (x, y) { return Math.log(x) / Math.log(y); }); + return MathUtil.decimalOrNull(log); + }; + return Log; +}(expression_1.Expression)); +exports.Log = Log; +var Power = /** @class */ (function (_super) { + __extends(Power, _super); + function Power(json) { + return _super.call(this, json) || this; + } + Power.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args == null || args.some(function (x) { return x == null; })) { + return null; } - else { - return result; + var power = args.reduce(function (x, y) { return Math.pow(x, y); }); + if (MathUtil.overflowsOrUnderflows(power)) { + return null; } - if (this.day != null) { - result = Date.Unit.DAY; + return power; + }; + return Power; +}(expression_1.Expression)); +exports.Power = Power; +var MinValue = /** @class */ (function (_super) { + __extends(MinValue, _super); + function MinValue(json) { + var _this = _super.call(this, json) || this; + _this.valueType = json.valueType; + return _this; + } + MinValue.prototype.exec = function (ctx) { + if (MinValue.MIN_VALUES[this.valueType]) { + if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') { + var minDateTime = MinValue.MIN_VALUES[this.valueType].copy(); + minDateTime.timezoneOffset = ctx.getTimezoneOffset(); + return minDateTime; + } + else { + return MinValue.MIN_VALUES[this.valueType]; + } } else { - return result; + throw new Error("Minimum not supported for ".concat(this.valueType)); } - return result; - }; - Date.prototype.getPrecisionValue = function () { - return DATETIME_PRECISION_VALUE_MAP.get(this.getPrecision()); - }; - Date.prototype.toLuxonDateTime = function () { - var _a, _b, _c; - return luxon_1.DateTime.fromObject({ - year: (_a = this.year) !== null && _a !== void 0 ? _a : undefined, - month: (_b = this.month) !== null && _b !== void 0 ? _b : undefined, - day: (_c = this.day) !== null && _c !== void 0 ? _c : undefined, - zone: luxon_1.FixedOffsetZone.utcInstance - }); - }; - Date.prototype.toLuxonUncertainty = function () { - var low = this.toLuxonDateTime(); - var high = low.endOf(this.getPrecision()).startOf('day'); // Date type is always at T00:00:00.0 - return new uncertainty_1.Uncertainty(low, high); }; - Date.prototype.toJSDate = function () { - var _a = [ - this.year, - this.month != null ? this.month - 1 : 0, - this.day != null ? this.day : 1 - ], y = _a[0], mo = _a[1], d = _a[2]; - return new util_1.jsDate(y, mo, d); + MinValue.MIN_VALUES = { + '{urn:hl7-org:elm-types:r1}Integer': MathUtil.MIN_INT_VALUE, + '{urn:hl7-org:elm-types:r1}Decimal': MathUtil.MIN_FLOAT_VALUE, + '{urn:hl7-org:elm-types:r1}DateTime': MathUtil.MIN_DATETIME_VALUE, + '{urn:hl7-org:elm-types:r1}Date': MathUtil.MIN_DATE_VALUE, + '{urn:hl7-org:elm-types:r1}Time': MathUtil.MIN_TIME_VALUE }; - Date.fromJSDate = function (date) { - if (date instanceof Date) { - return date; + return MinValue; +}(expression_1.Expression)); +exports.MinValue = MinValue; +var MaxValue = /** @class */ (function (_super) { + __extends(MaxValue, _super); + function MaxValue(json) { + var _this = _super.call(this, json) || this; + _this.valueType = json.valueType; + return _this; + } + MaxValue.prototype.exec = function (ctx) { + if (MaxValue.MAX_VALUES[this.valueType] != null) { + if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') { + var maxDateTime = MaxValue.MAX_VALUES[this.valueType].copy(); + maxDateTime.timezoneOffset = ctx.getTimezoneOffset(); + return maxDateTime; + } + else { + return MaxValue.MAX_VALUES[this.valueType]; + } } - return new Date(date.getFullYear(), date.getMonth() + 1, date.getDate()); - }; - Date.fromLuxonDateTime = function (luxonDT) { - if (luxonDT instanceof Date) { - return luxonDT; + else { + throw new Error("Maximum not supported for ".concat(this.valueType)); } - return new Date(luxonDT.year, luxonDT.month, luxonDT.day); - }; - Date.prototype.toJSON = function () { - return this.toString(); }; - Date.prototype.toString = function () { - var str = ''; - if (this.year != null) { - str += this.year.toString(); - if (this.month != null) { - str += '-' + this.month.toString().padStart(2, '0'); - if (this.day != null) { - str += '-' + this.day.toString().padStart(2, '0'); - } - } - } - return str; + MaxValue.MAX_VALUES = { + '{urn:hl7-org:elm-types:r1}Integer': MathUtil.MAX_INT_VALUE, + '{urn:hl7-org:elm-types:r1}Decimal': MathUtil.MAX_FLOAT_VALUE, + '{urn:hl7-org:elm-types:r1}DateTime': MathUtil.MAX_DATETIME_VALUE, + '{urn:hl7-org:elm-types:r1}Date': MathUtil.MAX_DATE_VALUE, + '{urn:hl7-org:elm-types:r1}Time': MathUtil.MAX_TIME_VALUE }; - Date.prototype.getDateTime = function () { - // from the spec: the result will be a DateTime with the time components unspecified, - // except for the timezone offset, which will be set to the timezone offset of the evaluation - // request timestamp. (this last part is achieved by just not passing in timezone offset) - if (this.year != null && this.month != null && this.day != null) { - return new DateTime(this.year, this.month, this.day, null, null, null, null); - // from spec: no component may be specified at a precision below an unspecified precision. - // For example, hour may be null, but if it is, minute, second, and millisecond must all be null as well. + return MaxValue; +}(expression_1.Expression)); +exports.MaxValue = MaxValue; +var Successor = /** @class */ (function (_super) { + __extends(Successor, _super); + function Successor(json) { + return _super.call(this, json) || this; + } + Successor.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - else { - return new DateTime(this.year, this.month, this.day); + var successor = null; + try { + // MathUtil.successor throws on overflow, and the exception is used in + // the logic for evaluating `meets`, so it can't be changed to just return null + successor = MathUtil.successor(arg); } - }; - Date.prototype.reducedPrecision = function (unitField) { - if (unitField === void 0) { unitField = Date.Unit.DAY; } - var reduced = this.copy(); - if (unitField !== Date.Unit.DAY) { - var fieldIndex = Date.FIELDS.indexOf(unitField); - var fieldsToRemove = Date.FIELDS.slice(fieldIndex + 1); - for (var _i = 0, fieldsToRemove_2 = fieldsToRemove; _i < fieldsToRemove_2.length; _i++) { - var field = fieldsToRemove_2[_i]; - // @ts-ignore - reduced[field] = null; + catch (e) { + if (e instanceof MathUtil.OverFlowException) { + return null; } } - return reduced; + if (MathUtil.overflowsOrUnderflows(successor)) { + return null; + } + return successor; }; - Date.Unit = { YEAR: 'year', MONTH: 'month', WEEK: 'week', DAY: 'day' }; - Date.FIELDS = [Date.Unit.YEAR, Date.Unit.MONTH, Date.Unit.DAY]; - return Date; -}(AbstractDate)); -exports.Date = Date; -// Require MIN/MAX here because math.js requires this file, and when we make this file require -// math.js before it exports DateTime and Date, it errors due to the circular dependency... -// const { MAX_DATETIME_VALUE, MIN_DATETIME_VALUE } = require('../util/math'); -exports.MIN_DATETIME_VALUE = DateTime.parse('0001-01-01T00:00:00.000'); -exports.MAX_DATETIME_VALUE = DateTime.parse('9999-12-31T23:59:59.999'); -exports.MIN_DATE_VALUE = Date.parse('0001-01-01'); -exports.MAX_DATE_VALUE = Date.parse('9999-12-31'); -exports.MIN_TIME_VALUE = (_a = DateTime.parse('0000-01-01T00:00:00.000')) === null || _a === void 0 ? void 0 : _a.getTime(); -exports.MAX_TIME_VALUE = (_b = DateTime.parse('0000-01-01T23:59:59.999')) === null || _b === void 0 ? void 0 : _b.getTime(); -var DATETIME_PRECISION_VALUE_MAP = (function () { - var dtpvMap = new Map(); - dtpvMap.set(DateTime.Unit.YEAR, 4); - dtpvMap.set(DateTime.Unit.MONTH, 6); - dtpvMap.set(DateTime.Unit.DAY, 8); - dtpvMap.set(DateTime.Unit.HOUR, 10); - dtpvMap.set(DateTime.Unit.MINUTE, 12); - dtpvMap.set(DateTime.Unit.SECOND, 14); - dtpvMap.set(DateTime.Unit.MILLISECOND, 17); - return dtpvMap; -})(); -var TIME_PRECISION_VALUE_MAP = (function () { - var tpvMap = new Map(); - tpvMap.set(DateTime.Unit.HOUR, 2); - tpvMap.set(DateTime.Unit.MINUTE, 4); - tpvMap.set(DateTime.Unit.SECOND, 6); - tpvMap.set(DateTime.Unit.MILLISECOND, 9); - return tpvMap; -})(); -function compareWithDefaultResult(a, b, defaultResult) { - // return false there is a type mismatch - if ((!a.isDate || !b.isDate) && (!a.isDateTime || !b.isDateTime)) { - return false; - } - // make a copy of other in the correct timezone offset if they don't match. - if (a.timezoneOffset !== b.timezoneOffset) { - b = b.convertToTimezoneOffset(a.timezoneOffset); + return Successor; +}(expression_1.Expression)); +exports.Successor = Successor; +var Predecessor = /** @class */ (function (_super) { + __extends(Predecessor, _super); + function Predecessor(json) { + return _super.call(this, json) || this; } - for (var _i = 0, _a = a.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - // if both have this precision defined - if (a[field] != null && b[field] != null) { - // For the purposes of comparison, seconds and milliseconds are combined - // as a single precision using a decimal, with decimal equality semantics - if (field === 'second') { - // NOTE: if millisecond is null it will calcualte like this anyway, but - // if millisecond is undefined, using it will result in NaN calculations - var aMillisecond = a['millisecond'] != null ? a['millisecond'] : 0; - var aSecondAndMillisecond = a[field] + aMillisecond / 1000; - var bMillisecond = b['millisecond'] != null ? b['millisecond'] : 0; - var bSecondAndMillisecond = b[field] + bMillisecond / 1000; - // second/millisecond is the most precise comparison, so we can directly return - return aSecondAndMillisecond === bSecondAndMillisecond; - } - // if they are different then return with false - if (a[field] !== b[field]) { - return false; - } - // if both dont have this precision, return true + Predecessor.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - else if (a[field] == null && b[field] == null) { - return true; - // otherwise they have inconclusive precision, return defaultResult + var predecessor = null; + try { + // MathUtil.predecessor throws on underflow, and the exception is used in + // the logic for evaluating `meets`, so it can't be changed to just return null + predecessor = MathUtil.predecessor(arg); } - else { - return defaultResult; + catch (e) { + if (e instanceof MathUtil.OverFlowException) { + return null; + } } + if (MathUtil.overflowsOrUnderflows(predecessor)) { + return null; + } + return predecessor; + }; + return Predecessor; +}(expression_1.Expression)); +exports.Predecessor = Predecessor; + +},{"../datatypes/quantity":48,"../datatypes/uncertainty":50,"../util/math":90,"./builder":53,"./expression":59}],53:[function(require,module,exports){ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.build = void 0; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var E = __importStar(require("./expressions")); +var util_1 = require("../util/util"); +function build(json) { + if (json == null) { + return json; } - // if we made it here, then all fields matched. - return true; -} -function daysInMonth(year, month) { - if (year == null || month == null) { - throw new Error('daysInMonth requires year and month as arguments'); - } - // Month is 1-indexed here because of the 0 day - return new util_1.jsDate(year, month, 0).getDate(); -} -function isValidDateStringFormat(string) { - if (typeof string !== 'string') { - return false; + if ((0, util_1.typeIsArray)(json)) { + return json.map(function (child) { return build(child); }); } - var format = LENGTH_TO_DATE_FORMAT_MAP.get(string.length); - if (format == null) { - return false; + if (json.type === 'FunctionRef') { + return new E.FunctionRef(json); } - return luxon_1.DateTime.fromFormat(string, format).isValid; -} -function isValidDateTimeStringFormat(string) { - if (typeof string !== 'string') { - return false; + else if (json.type === 'Literal') { + return E.Literal.from(json); } - // Luxon doesn't support +hh offset, so change it to +hh:00 - if (/T[\d:.]*[+-]\d{2}$/.test(string)) { - string += ':00'; + else if (functionExists(json.type)) { + return constructByName(json.type, json); } - var formats = LENGTH_TO_DATETIME_FORMATS_MAP.get(string.length); - if (formats == null) { - return false; + else { + return null; } - return formats.some(function (fmt) { return luxon_1.DateTime.fromFormat(string, fmt).isValid; }); } -// Will return true if provided precision is unspecified or if -// precision is hours, minutes, seconds, or milliseconds -function isPrecisionUnspecifiedOrGreaterThanDay(precision) { - return precision == null || /^h|mi|s/.test(precision); +exports.build = build; +function functionExists(name) { + // @ts-ignore + return typeof E[name] === 'function'; +} +function constructByName(name, json) { + // @ts-ignore + return new E[name](json); } -},{"../util/util":106,"./uncertainty":64,"luxon":224}],59:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Exception = void 0; -var Exception = /** @class */ (function () { - function Exception(message, wrapped) { - this.message = message; - this.wrapped = wrapped; - } - return Exception; -}()); -exports.Exception = Exception; - -},{}],60:[function(require,module,exports){ +},{"../util/util":92,"./expressions":60}],54:[function(require,module,exports){ "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -24382,1568 +21498,2007 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Interval = void 0; -var uncertainty_1 = require("./uncertainty"); -var quantity_1 = require("./quantity"); -var logic_1 = require("./logic"); -var math_1 = require("../util/math"); -var cmp = __importStar(require("../util/comparison")); -var Interval = /** @class */ (function () { - function Interval(low, high, lowClosed, highClosed, defaultPointType // defaultPointType is used in the case that both endpoints are null - ) { - this.low = low; - this.high = high; - this.lowClosed = lowClosed; - this.highClosed = highClosed; - this.defaultPointType = defaultPointType; - this.lowClosed = lowClosed != null ? lowClosed : true; - this.highClosed = highClosed != null ? highClosed : true; +exports.CalculateAgeAt = exports.CalculateAge = exports.Concept = exports.ConceptRef = exports.ConceptDef = exports.Code = exports.CodeRef = exports.CodeDef = exports.CodeSystemDef = exports.InValueSet = exports.AnyInValueSet = exports.ValueSetRef = exports.ValueSetDef = void 0; +var expression_1 = require("./expression"); +var dt = __importStar(require("../datatypes/datatypes")); +var builder_1 = require("./builder"); +var ValueSetDef = /** @class */ (function (_super) { + __extends(ValueSetDef, _super); + function ValueSetDef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.id = json.id; + _this.version = json.version; + return _this; } - Object.defineProperty(Interval.prototype, "isInterval", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(Interval.prototype, "pointType", { - get: function () { - var pointType = null; - var point = this.low != null ? this.low : this.high; - if (point != null) { - if (typeof point === 'number') { - pointType = Number.isInteger(point) - ? '{urn:hl7-org:elm-types:r1}Integer' - : '{urn:hl7-org:elm-types:r1}Decimal'; - } - else if (point.isTime && point.isTime()) { - pointType = '{urn:hl7-org:elm-types:r1}Time'; - } - else if (point.isDate) { - pointType = '{urn:hl7-org:elm-types:r1}Date'; - } - else if (point.isDateTime) { - pointType = '{urn:hl7-org:elm-types:r1}DateTime'; - } - else if (point.isQuantity) { - pointType = '{urn:hl7-org:elm-types:r1}Quantity'; - } - } - if (pointType == null && this.defaultPointType != null) { - pointType = this.defaultPointType; - } - return pointType; - }, - enumerable: false, - configurable: true - }); - Interval.prototype.copy = function () { - var newLow = this.low; - var newHigh = this.high; - if (this.low != null && typeof this.low.copy === 'function') { - newLow = this.low.copy(); - } - if (this.high != null && typeof this.high.copy === 'function') { - newHigh = this.high.copy(); - } - return new Interval(newLow, newHigh, this.lowClosed, this.highClosed); + //todo: code systems and versions + ValueSetDef.prototype.exec = function (ctx) { + var valueset = ctx.codeService.findValueSet(this.id, this.version) || new dt.ValueSet(this.id, this.version); + ctx.rootContext().set(this.name, valueset); + return valueset; }; - Interval.prototype.contains = function (item, precision) { - // These first two checks ensure correct handling of edge case where an item equals the closed boundary - if (this.lowClosed && this.low != null && cmp.equals(this.low, item)) { - return true; - } - if (this.highClosed && this.high != null && cmp.equals(this.high, item)) { - return true; - } - if (item != null && item.isInterval) { - throw new Error('Argument to contains must be a point'); - } - var lowFn; - if (this.lowClosed && this.low == null) { - lowFn = function () { return true; }; + return ValueSetDef; +}(expression_1.Expression)); +exports.ValueSetDef = ValueSetDef; +var ValueSetRef = /** @class */ (function (_super) { + __extends(ValueSetRef, _super); + function ValueSetRef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.libraryName = json.libraryName; + return _this; + } + ValueSetRef.prototype.exec = function (ctx) { + // TODO: This calls the code service every time-- should be optimized + var valueset = ctx.getValueSet(this.name, this.libraryName); + if (valueset instanceof expression_1.Expression) { + valueset = valueset.execute(ctx); } - else if (this.lowClosed) { - lowFn = cmp.lessThanOrEquals; + return valueset; + }; + return ValueSetRef; +}(expression_1.Expression)); +exports.ValueSetRef = ValueSetRef; +var AnyInValueSet = /** @class */ (function (_super) { + __extends(AnyInValueSet, _super); + function AnyInValueSet(json) { + var _this = _super.call(this, json) || this; + _this.codes = (0, builder_1.build)(json.codes); + _this.valueset = new ValueSetRef(json.valueset); + return _this; + } + AnyInValueSet.prototype.exec = function (ctx) { + var valueset = this.valueset.execute(ctx); + // If the value set reference cannot be resolved, a run-time error is thrown. + if (valueset == null || !valueset.isValueSet) { + throw new Error('ValueSet must be provided to InValueSet function'); } - else { - lowFn = cmp.lessThan; + var codes = this.codes.exec(ctx); + return codes != null && codes.some(function (code) { return valueset.hasMatch(code); }); + }; + return AnyInValueSet; +}(expression_1.Expression)); +exports.AnyInValueSet = AnyInValueSet; +var InValueSet = /** @class */ (function (_super) { + __extends(InValueSet, _super); + function InValueSet(json) { + var _this = _super.call(this, json) || this; + _this.code = (0, builder_1.build)(json.code); + _this.valueset = new ValueSetRef(json.valueset); + return _this; + } + InValueSet.prototype.exec = function (ctx) { + // If the code argument is null, the result is false + if (this.code == null) { + return false; } - var highFn; - if (this.highClosed && this.high == null) { - highFn = function () { return true; }; + if (this.valueset == null) { + throw new Error('ValueSet must be provided to InValueSet function'); } - else if (this.highClosed) { - highFn = cmp.greaterThanOrEquals; + var code = this.code.execute(ctx); + // spec indicates to return false if code is null, throw error if value set cannot be resolved + if (code == null) { + return false; } - else { - highFn = cmp.greaterThan; + var valueset = this.valueset.execute(ctx); + if (valueset == null || !valueset.isValueSet) { + throw new Error('ValueSet must be provided to InValueSet function'); } - return logic_1.ThreeValuedLogic.and(lowFn(this.low, item, precision), highFn(this.high, item, precision)); + // If there is a code and valueset return whether or not the valueset has the code + return valueset.hasMatch(code); }; - Interval.prototype.properlyIncludes = function (other, precision) { - if (other == null || !other.isInterval) { - throw new Error('Argument to properlyIncludes must be an interval'); - } - return logic_1.ThreeValuedLogic.and(this.includes(other, precision), logic_1.ThreeValuedLogic.not(other.includes(this, precision))); + return InValueSet; +}(expression_1.Expression)); +exports.InValueSet = InValueSet; +var CodeSystemDef = /** @class */ (function (_super) { + __extends(CodeSystemDef, _super); + function CodeSystemDef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.id = json.id; + _this.version = json.version; + return _this; + } + CodeSystemDef.prototype.exec = function (_ctx) { + return new dt.CodeSystem(this.id, this.version); }; - Interval.prototype.includes = function (other, precision) { - if (other == null || !other.isInterval) { - return this.contains(other, precision); - } - var a = this.toClosed(); - var b = other.toClosed(); - return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(a.low, b.low, precision), cmp.greaterThanOrEquals(a.high, b.high, precision)); + return CodeSystemDef; +}(expression_1.Expression)); +exports.CodeSystemDef = CodeSystemDef; +var CodeDef = /** @class */ (function (_super) { + __extends(CodeDef, _super); + function CodeDef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.id = json.id; + _this.systemName = json.codeSystem.name; + _this.display = json.display; + return _this; + } + CodeDef.prototype.exec = function (ctx) { + var system = ctx.getCodeSystem(this.systemName).execute(ctx); + return new dt.Code(this.id, system.id, system.version, this.display); }; - Interval.prototype.includedIn = function (other, precision) { - // For the point overload, this operator is a synonym for the in operator - if (other == null || !other.isInterval) { - return this.contains(other, precision); - } - else { - return other.includes(this); - } + return CodeDef; +}(expression_1.Expression)); +exports.CodeDef = CodeDef; +var CodeRef = /** @class */ (function (_super) { + __extends(CodeRef, _super); + function CodeRef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.library = json.libraryName; + return _this; + } + CodeRef.prototype.exec = function (ctx) { + ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; + var codeDef = ctx.getCode(this.name); + return codeDef ? codeDef.execute(ctx) : undefined; }; - Interval.prototype.overlaps = function (item, precision) { - var closed = this.toClosed(); - var _a = (function () { - if (item != null && item.isInterval) { - var itemClosed = item.toClosed(); - return [itemClosed.low, itemClosed.high]; - } - else { - return [item, item]; - } - })(), low = _a[0], high = _a[1]; - return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThanOrEquals(closed.high, low, precision)); + return CodeRef; +}(expression_1.Expression)); +exports.CodeRef = CodeRef; +var Code = /** @class */ (function (_super) { + __extends(Code, _super); + function Code(json) { + var _this = _super.call(this, json) || this; + _this.code = json.code; + _this.systemName = json.system.name; + _this.version = json.version; + _this.display = json.display; + return _this; + } + Object.defineProperty(Code.prototype, "isCode", { + // Define a simple getter to allow type-checking of this class without instanceof + // and in a way that survives minification (as opposed to checking constructor.name) + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Code.prototype.exec = function (ctx) { + var system = ctx.getCodeSystem(this.systemName) || {}; + return new dt.Code(this.code, system.id, this.version, this.display); }; - Interval.prototype.overlapsAfter = function (item, precision) { - var closed = this.toClosed(); - var high = item != null && item.isInterval ? item.toClosed().high : item; - return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThan(closed.high, high, precision)); + return Code; +}(expression_1.Expression)); +exports.Code = Code; +var ConceptDef = /** @class */ (function (_super) { + __extends(ConceptDef, _super); + function ConceptDef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.display = json.display; + _this.codes = json.code; + return _this; + } + ConceptDef.prototype.exec = function (ctx) { + var codes = this.codes.map(function (code) { + var codeDef = ctx.getCode(code.name); + return codeDef ? codeDef.execute(ctx) : undefined; + }); + return new dt.Concept(codes, this.display); }; - Interval.prototype.overlapsBefore = function (item, precision) { - var closed = this.toClosed(); - var low = item != null && item.isInterval ? item.toClosed().low : item; - return logic_1.ThreeValuedLogic.and(cmp.lessThan(closed.low, low, precision), cmp.greaterThanOrEquals(closed.high, low, precision)); + return ConceptDef; +}(expression_1.Expression)); +exports.ConceptDef = ConceptDef; +var ConceptRef = /** @class */ (function (_super) { + __extends(ConceptRef, _super); + function ConceptRef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + return _this; + } + ConceptRef.prototype.exec = function (ctx) { + var conceptDef = ctx.getConcept(this.name); + return conceptDef ? conceptDef.execute(ctx) : undefined; }; - Interval.prototype.union = function (other) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; - if (other == null || !other.isInterval) { - throw new Error('Argument to union must be an interval'); - } - // Note that interval union is only defined if the arguments overlap or meet. - if (this.overlaps(other) || this.meets(other)) { - var _l = [this.toClosed(), other.toClosed()], a = _l[0], b = _l[1]; - var l = void 0, lc = void 0; - if (cmp.lessThanOrEquals(a.low, b.low)) { - _a = [this.low, this.lowClosed], l = _a[0], lc = _a[1]; - } - else if (cmp.greaterThanOrEquals(a.low, b.low)) { - _b = [other.low, other.lowClosed], l = _b[0], lc = _b[1]; - } - else if (areNumeric(a.low, b.low)) { - _c = [lowestNumericUncertainty(a.low, b.low), true], l = _c[0], lc = _c[1]; - // TODO: Do we need to support quantities here? - } - else if (areDateTimes(a.low, b.low) && a.low.isMorePrecise(b.low)) { - _d = [other.low, other.lowClosed], l = _d[0], lc = _d[1]; - } - else { - _e = [this.low, this.lowClosed], l = _e[0], lc = _e[1]; - } - var h = void 0, hc = void 0; - if (cmp.greaterThanOrEquals(a.high, b.high)) { - _f = [this.high, this.highClosed], h = _f[0], hc = _f[1]; - } - else if (cmp.lessThanOrEquals(a.high, b.high)) { - _g = [other.high, other.highClosed], h = _g[0], hc = _g[1]; - } - else if (areNumeric(a.high, b.high)) { - _h = [highestNumericUncertainty(a.high, b.high), true], h = _h[0], hc = _h[1]; - // TODO: Do we need to support quantities here? - } - else if (areDateTimes(a.high, b.high) && a.high.isMorePrecise(b.high)) { - _j = [other.high, other.highClosed], h = _j[0], hc = _j[1]; - } - else { - _k = [this.high, this.highClosed], h = _k[0], hc = _k[1]; - } - return new Interval(l, h, lc, hc); - } - else { - return null; - } + return ConceptRef; +}(expression_1.Expression)); +exports.ConceptRef = ConceptRef; +var Concept = /** @class */ (function (_super) { + __extends(Concept, _super); + function Concept(json) { + var _this = _super.call(this, json) || this; + _this.codes = json.code; + _this.display = json.display; + return _this; + } + Object.defineProperty(Concept.prototype, "isConcept", { + // Define a simple getter to allow type-checking of this class without instanceof + // and in a way that survives minification (as opposed to checking constructor.name) + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + Concept.prototype.toCode = function (ctx, code) { + var system = ctx.getCodeSystem(code.system.name) || {}; + return new dt.Code(code.code, system.id, code.version, code.display); }; - Interval.prototype.intersect = function (other) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; - if (other == null || !other.isInterval) { - throw new Error('Argument to union must be an interval'); - } - // Note that interval union is only defined if the arguments overlap. - if (this.overlaps(other)) { - var _l = [this.toClosed(), other.toClosed()], a = _l[0], b = _l[1]; - var l = void 0, lc = void 0; - if (cmp.greaterThanOrEquals(a.low, b.low)) { - _a = [this.low, this.lowClosed], l = _a[0], lc = _a[1]; - } - else if (cmp.lessThanOrEquals(a.low, b.low)) { - _b = [other.low, other.lowClosed], l = _b[0], lc = _b[1]; - } - else if (areNumeric(a.low, b.low)) { - _c = [highestNumericUncertainty(a.low, b.low), true], l = _c[0], lc = _c[1]; - // TODO: Do we need to support quantities here? - } - else if (areDateTimes(a.low, b.low) && b.low.isMorePrecise(a.low)) { - _d = [other.low, other.lowClosed], l = _d[0], lc = _d[1]; - } - else { - _e = [this.low, this.lowClosed], l = _e[0], lc = _e[1]; - } - var h = void 0, hc = void 0; - if (cmp.lessThanOrEquals(a.high, b.high)) { - _f = [this.high, this.highClosed], h = _f[0], hc = _f[1]; - } - else if (cmp.greaterThanOrEquals(a.high, b.high)) { - _g = [other.high, other.highClosed], h = _g[0], hc = _g[1]; - } - else if (areNumeric(a.high, b.high)) { - _h = [lowestNumericUncertainty(a.high, b.high), true], h = _h[0], hc = _h[1]; - // TODO: Do we need to support quantities here? - } - else if (areDateTimes(a.high, b.high) && b.high.isMorePrecise(a.high)) { - _j = [other.high, other.highClosed], h = _j[0], hc = _j[1]; - } - else { - _k = [this.high, this.highClosed], h = _k[0], hc = _k[1]; - } - return new Interval(l, h, lc, hc); - } - else { - return null; - } + Concept.prototype.exec = function (ctx) { + var _this = this; + var codes = this.codes.map(function (code) { return _this.toCode(ctx, code); }); + return new dt.Concept(codes, this.display); }; - Interval.prototype.except = function (other) { - if (other === null) { - return null; - } - if (other == null || !other.isInterval) { - throw new Error('Argument to except must be an interval'); - } - var ol = this.overlaps(other); - if (ol === true) { - var olb = this.overlapsBefore(other); - var ola = this.overlapsAfter(other); - if (olb === true && ola === false) { - return new Interval(this.low, other.low, this.lowClosed, !other.lowClosed); - } - else if (ola === true && olb === false) { - return new Interval(other.high, this.high, !other.highClosed, this.highClosed); - } - else { - return null; - } - } - else if (ol === false) { - return this; + return Concept; +}(expression_1.Expression)); +exports.Concept = Concept; +var CalculateAge = /** @class */ (function (_super) { + __extends(CalculateAge, _super); + function CalculateAge(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; + } + CalculateAge.prototype.exec = function (ctx) { + var date1 = this.execArgs(ctx); + var date2 = dt.DateTime.fromJSDate(ctx.getExecutionDateTime()); + var result = date1 != null ? date1.durationBetween(date2, this.precision.toLowerCase()) : undefined; + if (result != null && result.isPoint()) { + return result.low; } else { - // ol is null - return null; + return result; } }; - Interval.prototype.sameAs = function (other, precision) { - // This large if and else if block handles the scenarios where there is an open ended null - // If both lows or highs exists, it can be determined that intervals are not Same As - if ((this.low != null && - other.low != null && - this.high == null && - other.high != null && - !this.highClosed) || - (this.low != null && - other.low != null && - this.high != null && - other.high == null && - !other.highClosed) || - (this.low != null && - other.low != null && - this.high == null && - other.high == null && - !other.highClosed && - !this.highClosed)) { - if (typeof this.low === 'number') { - if (!(this.start() === other.start())) { - return false; - } - } - else { - if (!this.start().sameAs(other.start(), precision)) { - return false; - } + return CalculateAge; +}(expression_1.Expression)); +exports.CalculateAge = CalculateAge; +var CalculateAgeAt = /** @class */ (function (_super) { + __extends(CalculateAgeAt, _super); + function CalculateAgeAt(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; + } + CalculateAgeAt.prototype.exec = function (ctx) { + // eslint-disable-next-line prefer-const + var _a = this.execArgs(ctx), date1 = _a[0], date2 = _a[1]; + if (date1 != null && date2 != null) { + // date1 is the birthdate, convert it to date if date2 is a date (to support ignoring time) + if (date2.isDate && date1.isDateTime) { + date1 = date1.getDate(); } - } - else if ((this.low != null && other.low == null && this.high != null && other.high != null) || - (this.low == null && other.low != null && this.high != null && other.high != null) || - (this.low == null && other.low == null && this.high != null && other.high != null)) { - if (typeof this.high === 'number') { - if (!(this.end() === other.end())) { - return false; - } + var result = date1.durationBetween(date2, this.precision.toLowerCase()); + if (result != null && result.isPoint()) { + return result.low; } else { - if (!this.end().sameAs(other.end(), precision)) { - return false; - } + return result; } } - // Checks to see if any of the Intervals have a open, null boundary - if ((this.low == null && !this.lowClosed) || - (this.high == null && !this.highClosed) || - (other.low == null && !other.lowClosed) || - (other.high == null && !other.highClosed)) { + return null; + }; + return CalculateAgeAt; +}(expression_1.Expression)); +exports.CalculateAgeAt = CalculateAgeAt; + +},{"../datatypes/datatypes":43,"./builder":53,"./expression":59}],55:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GreaterOrEqual = exports.Greater = exports.LessOrEqual = exports.Less = void 0; +var expression_1 = require("./expression"); +var datatypes_1 = require("../datatypes/datatypes"); +// Equal is completely handled by overloaded#Equal +// NotEqual is completely handled by overloaded#Equal +var Less = /** @class */ (function (_super) { + __extends(Less, _super); + function Less(json) { + return _super.call(this, json) || this; + } + Less.prototype.exec = function (ctx) { + var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); + if (args[0] == null || args[1] == null) { return null; } - // For the special cases where @ is Interval[null,null] - if (this.lowClosed && this.low == null && this.highClosed && this.high == null) { - return other.lowClosed && other.low == null && other.highClosed && other.high == null; - } - // For the special case where Interval[...] same as Interval[null,null] should return false. - // This accounts for the inverse of the if statement above: where the second Interval is - // [null,null] and not the first Interval. - // The reason why this isn't caught below is due to how start() and end() work. - // There is no way to tell the datatype for MIN and MAX if both boundaries are null. - if (other.lowClosed && other.low == null && other.highClosed && other.high == null) { - return false; - } - if (typeof this.low === 'number') { - return this.start() === other.start() && this.end() === other.end(); - } - else { - return (this.start().sameAs(other.start(), precision) && this.end().sameAs(other.end(), precision)); - } + return args[0].lessThan(args[1]); }; - Interval.prototype.sameOrBefore = function (other, precision) { - if (this.end() == null || other == null || other.start() == null) { + return Less; +}(expression_1.Expression)); +exports.Less = Less; +var LessOrEqual = /** @class */ (function (_super) { + __extends(LessOrEqual, _super); + function LessOrEqual(json) { + return _super.call(this, json) || this; + } + LessOrEqual.prototype.exec = function (ctx) { + var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); + if (args[0] == null || args[1] == null) { return null; } - else { - return cmp.lessThanOrEquals(this.end(), other.start(), precision); - } + return args[0].lessThanOrEquals(args[1]); }; - Interval.prototype.sameOrAfter = function (other, precision) { - if (this.start() == null || other == null || other.end() == null) { + return LessOrEqual; +}(expression_1.Expression)); +exports.LessOrEqual = LessOrEqual; +var Greater = /** @class */ (function (_super) { + __extends(Greater, _super); + function Greater(json) { + return _super.call(this, json) || this; + } + Greater.prototype.exec = function (ctx) { + var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); + if (args[0] == null || args[1] == null) { return null; } - else { - return cmp.greaterThanOrEquals(this.start(), other.end(), precision); + return args[0].greaterThan(args[1]); + }; + return Greater; +}(expression_1.Expression)); +exports.Greater = Greater; +var GreaterOrEqual = /** @class */ (function (_super) { + __extends(GreaterOrEqual, _super); + function GreaterOrEqual(json) { + return _super.call(this, json) || this; + } + GreaterOrEqual.prototype.exec = function (ctx) { + var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); + if (args[0] == null || args[1] == null) { + return null; } + return args[0].greaterThanOrEquals(args[1]); }; - Interval.prototype.equals = function (other) { - if (other != null && other.isInterval) { - var _a = [this.toClosed(), other.toClosed()], a = _a[0], b = _a[1]; - return logic_1.ThreeValuedLogic.and(cmp.equals(a.low, b.low), cmp.equals(a.high, b.high)); + return GreaterOrEqual; +}(expression_1.Expression)); +exports.GreaterOrEqual = GreaterOrEqual; + +},{"../datatypes/datatypes":43,"./expression":59}],56:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Case = exports.CaseItem = exports.If = void 0; +var expression_1 = require("./expression"); +var builder_1 = require("./builder"); +var comparison_1 = require("../util/comparison"); +// TODO: Spec lists "Conditional", but it's "If" in the XSD +var If = /** @class */ (function (_super) { + __extends(If, _super); + function If(json) { + var _this = _super.call(this, json) || this; + _this.condition = (0, builder_1.build)(json.condition); + _this.th = (0, builder_1.build)(json.then); + _this.els = (0, builder_1.build)(json.else); + return _this; + } + If.prototype.exec = function (ctx) { + if (this.condition.execute(ctx)) { + return this.th.execute(ctx); } else { - return false; + return this.els.execute(ctx); } }; - Interval.prototype.after = function (other, precision) { - var closed = this.toClosed(); - // Meets spec, but not 100% correct (e.g., (null, 5] after [6, 10] --> null) - // Simple way to fix it: and w/ not overlaps - if (other.toClosed) { - return cmp.greaterThan(closed.low, other.toClosed().high, precision); + return If; +}(expression_1.Expression)); +exports.If = If; +var CaseItem = /** @class */ (function () { + function CaseItem(json) { + this.when = (0, builder_1.build)(json.when); + this.then = (0, builder_1.build)(json.then); + } + return CaseItem; +}()); +exports.CaseItem = CaseItem; +var Case = /** @class */ (function (_super) { + __extends(Case, _super); + function Case(json) { + var _this = _super.call(this, json) || this; + _this.comparand = (0, builder_1.build)(json.comparand); + _this.caseItems = json.caseItem.map(function (ci) { return new CaseItem(ci); }); + _this.els = (0, builder_1.build)(json.else); + return _this; + } + Case.prototype.exec = function (ctx) { + if (this.comparand) { + return this.exec_selected(ctx); } else { - return cmp.greaterThan(closed.low, other, precision); + return this.exec_standard(ctx); } }; - Interval.prototype.before = function (other, precision) { - var closed = this.toClosed(); - // Meets spec, but not 100% correct (e.g., (null, 5] after [6, 10] --> null) - // Simple way to fix it: and w/ not overlaps - if (other.toClosed) { - return cmp.lessThan(closed.high, other.toClosed().low, precision); + Case.prototype.exec_selected = function (ctx) { + var val = this.comparand.execute(ctx); + for (var _i = 0, _a = this.caseItems; _i < _a.length; _i++) { + var ci = _a[_i]; + if ((0, comparison_1.equals)(ci.when.execute(ctx), val)) { + return ci.then.execute(ctx); + } } - else { - return cmp.lessThan(closed.high, other, precision); + return this.els.execute(ctx); + }; + Case.prototype.exec_standard = function (ctx) { + for (var _i = 0, _a = this.caseItems; _i < _a.length; _i++) { + var ci = _a[_i]; + if (ci.when.execute(ctx)) { + return ci.then.execute(ctx); + } } + return this.els.execute(ctx); }; - Interval.prototype.meets = function (other, precision) { - return logic_1.ThreeValuedLogic.or(this.meetsBefore(other, precision), this.meetsAfter(other, precision)); + return Case; +}(expression_1.Expression)); +exports.Case = Case; + +},{"../util/comparison":89,"./builder":53,"./expression":59}],57:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); }; - Interval.prototype.meetsAfter = function (other, precision) { - try { - if (precision != null && this.low != null && this.low.isDateTime) { - return this.toClosed().low.sameAs(other.toClosed().high != null ? other.toClosed().high.add(1, precision) : null, precision); + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DurationBetween = exports.DifferenceBetween = exports.doBefore = exports.doAfter = exports.TimezoneOffsetFrom = exports.TimeFrom = exports.DateFrom = exports.DateTimeComponentFrom = exports.TimeOfDay = exports.Now = exports.Today = exports.Time = exports.Date = exports.DateTime = void 0; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var expression_1 = require("./expression"); +var builder_1 = require("./builder"); +var literal_1 = require("./literal"); +var DT = __importStar(require("../datatypes/datatypes")); +var DateTime = /** @class */ (function (_super) { + __extends(DateTime, _super); + function DateTime(json) { + var _this = _super.call(this, json) || this; + _this.json = json; + return _this; + } + DateTime.prototype.exec = function (ctx) { + var _a; + var _this = this; + for (var _i = 0, _b = DateTime.PROPERTIES; _i < _b.length; _i++) { + var property = _b[_i]; + // if json does not contain 'timezoneOffset' set it to the executionDateTime from the context + if (this.json[property] != null) { + // @ts-ignore + this[property] = (0, builder_1.build)(this.json[property]); } - else { - return cmp.equals(this.toClosed().low, (0, math_1.successor)(other.toClosed().high)); + else if (property === 'timezoneOffset' && ctx.getTimezoneOffset() != null) { + // @ts-ignore + this[property] = literal_1.Literal.from({ + type: 'Literal', + value: ctx.getTimezoneOffset(), + valueType: '{urn:hl7-org:elm-types:r1}Integer' + }); } } - catch (error) { - return false; - } + // @ts-ignore + var args = DateTime.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); + return new ((_a = DT.DateTime).bind.apply(_a, __spreadArray([void 0], args, false)))(); }; - Interval.prototype.meetsBefore = function (other, precision) { - try { - if (precision != null && this.high != null && this.high.isDateTime) { - return this.toClosed().high.sameAs(other.toClosed().low != null ? other.toClosed().low.add(-1, precision) : null, precision); - } - else { - return cmp.equals(this.toClosed().high, (0, math_1.predecessor)(other.toClosed().low)); + DateTime.PROPERTIES = [ + 'year', + 'month', + 'day', + 'hour', + 'minute', + 'second', + 'millisecond', + 'timezoneOffset' + ]; + return DateTime; +}(expression_1.Expression)); +exports.DateTime = DateTime; +var Date = /** @class */ (function (_super) { + __extends(Date, _super); + function Date(json) { + var _this = _super.call(this, json) || this; + _this.json = json; + return _this; + } + Date.prototype.exec = function (ctx) { + var _a; + var _this = this; + for (var _i = 0, _b = Date.PROPERTIES; _i < _b.length; _i++) { + var property = _b[_i]; + if (this.json[property] != null) { + // @ts-ignore + this[property] = (0, builder_1.build)(this.json[property]); } } - catch (error) { - return false; - } + // @ts-ignore + var args = Date.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); + return new ((_a = DT.Date).bind.apply(_a, __spreadArray([void 0], args, false)))(); }; - Interval.prototype.start = function () { - if (this.low == null) { - if (this.lowClosed) { - return (0, math_1.minValueForInstance)(this.high); - } - else { - return this.low; + Date.PROPERTIES = ['year', 'month', 'day']; + return Date; +}(expression_1.Expression)); +exports.Date = Date; +var Time = /** @class */ (function (_super) { + __extends(Time, _super); + function Time(json) { + var _this = _super.call(this, json) || this; + for (var _i = 0, _a = Time.PROPERTIES; _i < _a.length; _i++) { + var property = _a[_i]; + if (json[property] != null) { + // @ts-ignore + _this[property] = (0, builder_1.build)(json[property]); } } - return this.toClosed().low; + return _this; + } + Time.prototype.exec = function (ctx) { + var _a; + var _this = this; + // @ts-ignore + var args = Time.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); + return new ((_a = DT.DateTime).bind.apply(_a, __spreadArray([void 0, 0, 1, 1], args, false)))().getTime(); }; - Interval.prototype.end = function () { - if (this.high == null) { - if (this.highClosed) { - return (0, math_1.maxValueForInstance)(this.low); - } - else { - return this.high; - } + Time.PROPERTIES = ['hour', 'minute', 'second', 'millisecond']; + return Time; +}(expression_1.Expression)); +exports.Time = Time; +var Today = /** @class */ (function (_super) { + __extends(Today, _super); + function Today(json) { + return _super.call(this, json) || this; + } + Today.prototype.exec = function (ctx) { + return ctx.getExecutionDateTime().getDate(); + }; + return Today; +}(expression_1.Expression)); +exports.Today = Today; +var Now = /** @class */ (function (_super) { + __extends(Now, _super); + function Now(json) { + return _super.call(this, json) || this; + } + Now.prototype.exec = function (ctx) { + return ctx.getExecutionDateTime(); + }; + return Now; +}(expression_1.Expression)); +exports.Now = Now; +var TimeOfDay = /** @class */ (function (_super) { + __extends(TimeOfDay, _super); + function TimeOfDay(json) { + return _super.call(this, json) || this; + } + TimeOfDay.prototype.exec = function (ctx) { + return ctx.getExecutionDateTime().getTime(); + }; + return TimeOfDay; +}(expression_1.Expression)); +exports.TimeOfDay = TimeOfDay; +var DateTimeComponentFrom = /** @class */ (function (_super) { + __extends(DateTimeComponentFrom, _super); + function DateTimeComponentFrom(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; + } + DateTimeComponentFrom.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return arg[this.precision.toLowerCase()]; + } + else { + return null; } - return this.toClosed().high; }; - Interval.prototype.starts = function (other, precision) { - var startEqual; - if (precision != null && this.low != null && this.low.isDateTime) { - startEqual = this.low.sameAs(other.low, precision); + return DateTimeComponentFrom; +}(expression_1.Expression)); +exports.DateTimeComponentFrom = DateTimeComponentFrom; +var DateFrom = /** @class */ (function (_super) { + __extends(DateFrom, _super); + function DateFrom(json) { + return _super.call(this, json) || this; + } + DateFrom.prototype.exec = function (ctx) { + var date = this.execArgs(ctx); + if (date != null) { + return date.getDate(); } else { - startEqual = cmp.equals(this.low, other.low); + return null; } - var endLessThanOrEqual = cmp.lessThanOrEquals(this.high, other.high, precision); - return startEqual && endLessThanOrEqual; }; - Interval.prototype.ends = function (other, precision) { - var endEqual; - var startGreaterThanOrEqual = cmp.greaterThanOrEquals(this.low, other.low, precision); - if (precision != null && (this.low != null ? this.low.isDateTime : undefined)) { - endEqual = this.high.sameAs(other.high, precision); + return DateFrom; +}(expression_1.Expression)); +exports.DateFrom = DateFrom; +var TimeFrom = /** @class */ (function (_super) { + __extends(TimeFrom, _super); + function TimeFrom(json) { + return _super.call(this, json) || this; + } + TimeFrom.prototype.exec = function (ctx) { + var date = this.execArgs(ctx); + if (date != null) { + return date.getTime(); } else { - endEqual = cmp.equals(this.high, other.high); - } - return startGreaterThanOrEqual && endEqual; - }; - Interval.prototype.width = function () { - if ((this.low != null && (this.low.isDateTime || this.low.isDate)) || - (this.high != null && (this.high.isDateTime || this.high.isDate))) { - throw new Error('Width of Date, DateTime, and Time intervals is not supported'); - } - var closed = this.toClosed(); - if ((closed.low != null && closed.low.isUncertainty) || - (closed.high != null && closed.high.isUncertainty)) { return null; } - else if (closed.low.isQuantity) { - if (closed.low.unit !== closed.high.unit) { - throw new Error('Cannot calculate width of Quantity Interval with different units'); - } - var lowValue = closed.low.value; - var highValue = closed.high.value; - var diff = Math.abs(highValue - lowValue); - diff = Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); - return new quantity_1.Quantity(diff, closed.low.unit); + }; + return TimeFrom; +}(expression_1.Expression)); +exports.TimeFrom = TimeFrom; +var TimezoneOffsetFrom = /** @class */ (function (_super) { + __extends(TimezoneOffsetFrom, _super); + function TimezoneOffsetFrom(json) { + return _super.call(this, json) || this; + } + TimezoneOffsetFrom.prototype.exec = function (ctx) { + var date = this.execArgs(ctx); + if (date != null) { + return date.timezoneOffset; } else { - // TODO: Fix precision to 8 decimals in other places that return numbers - var diff = Math.abs(closed.high - closed.low); - return Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); + return null; } }; - Interval.prototype.size = function () { - var pointSize = this.getPointSize(); - if ((this.low != null && (this.low.isDateTime || this.low.isDate)) || - (this.high != null && (this.high.isDateTime || this.high.isDate))) { - throw new Error('Size of Date, DateTime, and Time intervals is not supported'); - } - var closed = this.toClosed(); - if ((closed.low != null && closed.low.isUncertainty) || - (closed.high != null && closed.high.isUncertainty)) { + return TimezoneOffsetFrom; +}(expression_1.Expression)); +exports.TimezoneOffsetFrom = TimezoneOffsetFrom; +// Delegated to by overloaded#After +function doAfter(a, b, precision) { + return a.after(b, precision); +} +exports.doAfter = doAfter; +// Delegated to by overloaded#Before +function doBefore(a, b, precision) { + return a.before(b, precision); +} +exports.doBefore = doBefore; +var DifferenceBetween = /** @class */ (function (_super) { + __extends(DifferenceBetween, _super); + function DifferenceBetween(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; + } + DifferenceBetween.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + // Check to make sure args exist and that they have differenceBetween functions so that they can be compared to one another + if (args[0] == null || + args[1] == null || + typeof args[0].differenceBetween !== 'function' || + typeof args[1].differenceBetween !== 'function') { return null; } - else if (closed.low.isQuantity) { - if (closed.low.unit !== closed.high.unit) { - throw new Error('Cannot calculate size of Quantity Interval with different units'); - } - var lowValue = closed.low.value; - var highValue = closed.high.value; - var diff = Math.abs(highValue - lowValue) + pointSize.value; - Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); - return new quantity_1.Quantity(diff, closed.low.unit); + var result = args[0].differenceBetween(args[1], this.precision != null ? this.precision.toLowerCase() : undefined); + if (result != null && result.isPoint()) { + return result.low; } else { - var diff = Math.abs(closed.high - closed.low) + pointSize.value; - return Math.round(diff * Math.pow(10, 8)) / Math.pow(10, 8); + return result; } }; - Interval.prototype.getPointSize = function () { - var pointSize; - if (this.low != null) { - if (this.low.isDateTime || this.low.isDate || this.low.isTime) { - pointSize = new quantity_1.Quantity(1, this.low.getPrecision()); - } - else if (this.low.isQuantity) { - pointSize = (0, quantity_1.doSubtraction)((0, math_1.successor)(this.low), this.low); - } - else { - pointSize = (0, math_1.successor)(this.low) - this.low; - } + return DifferenceBetween; +}(expression_1.Expression)); +exports.DifferenceBetween = DifferenceBetween; +var DurationBetween = /** @class */ (function (_super) { + __extends(DurationBetween, _super); + function DurationBetween(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; + } + DurationBetween.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + // Check to make sure args exist and that they have durationBetween functions so that they can be compared to one another + if (args[0] == null || + args[1] == null || + typeof args[0].durationBetween !== 'function' || + typeof args[1].durationBetween !== 'function') { + return null; } - else if (this.high != null) { - if (this.high.isDateTime || this.high.isDate || this.high.isTime) { - pointSize = new quantity_1.Quantity(1, this.high.getPrecision()); - } - else if (this.high.isQuantity) { - pointSize = (0, quantity_1.doSubtraction)((0, math_1.successor)(this.high), this.high); - } - else { - pointSize = (0, math_1.successor)(this.high) - this.high; - } + var result = args[0].durationBetween(args[1], this.precision != null ? this.precision.toLowerCase() : undefined); + if (result != null && result.isPoint()) { + return result.low; } else { - throw new Error('Point type of intervals cannot be determined.'); - } - if (typeof pointSize === 'number') { - pointSize = new quantity_1.Quantity(pointSize, '1'); + return result; } - return pointSize; }; - Interval.prototype.toClosed = function () { - // Calculate the closed flags. Despite the name of this function, if a boundary is null open, - // we cannot close the boundary because that changes its meaning from "unknown" to "max/min value" - var lowClosed = this.lowClosed || this.low != null; - var highClosed = this.highClosed || this.high != null; - if (this.pointType != null) { - var low = void 0; - if (this.lowClosed && this.low == null) { - low = (0, math_1.minValueForType)(this.pointType); - } - else if (!this.lowClosed && this.low != null) { - low = (0, math_1.successor)(this.low); - } - else { - low = this.low; - } - var high = void 0; - if (this.highClosed && this.high == null) { - high = (0, math_1.maxValueForType)(this.pointType); - } - else if (!this.highClosed && this.high != null) { - high = (0, math_1.predecessor)(this.high); - } - else { - high = this.high; - } - if (low == null) { - low = new uncertainty_1.Uncertainty((0, math_1.minValueForType)(this.pointType), high); - } - if (high == null) { - high = new uncertainty_1.Uncertainty(low, (0, math_1.maxValueForType)(this.pointType)); - } - return new Interval(low, high, lowClosed, highClosed); - } - else { - return new Interval(this.low, this.high, lowClosed, highClosed); - } + return DurationBetween; +}(expression_1.Expression)); +exports.DurationBetween = DurationBetween; + +},{"../datatypes/datatypes":43,"./builder":53,"./expression":59,"./literal":66}],58:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); }; - Interval.prototype.toString = function () { - var start = this.lowClosed ? '[' : '('; - var end = this.highClosed ? ']' : ')'; - return start + this.low.toString() + ', ' + this.high.toString() + end; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - return Interval; -}()); -exports.Interval = Interval; -function areDateTimes(x, y) { - return [x, y].every(function (z) { return z != null && z.isDateTime; }); -} -function areNumeric(x, y) { - return [x, y].every(function (z) { - return typeof z === 'number' || (z != null && z.isUncertainty && typeof z.low === 'number'); - }); -} -function lowestNumericUncertainty(x, y) { - if (x == null || !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x); - } - if (y == null || !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y); - } - var low = x.low < y.low ? x.low : y.low; - var high = x.high < y.high ? x.high : y.high; - if (low !== high) { - return new uncertainty_1.Uncertainty(low, high); - } - else { - return low; - } -} -function highestNumericUncertainty(x, y) { - if (x == null || !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x); - } - if (y == null || !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y); +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VersionedIdentifier = exports.IncludeDef = exports.UsingDef = void 0; +var expression_1 = require("./expression"); +var UsingDef = /** @class */ (function (_super) { + __extends(UsingDef, _super); + function UsingDef() { + return _super !== null && _super.apply(this, arguments) || this; } - var low = x.low > y.low ? x.low : y.low; - var high = x.high > y.high ? x.high : y.high; - if (low !== high) { - return new uncertainty_1.Uncertainty(low, high); + return UsingDef; +}(expression_1.UnimplementedExpression)); +exports.UsingDef = UsingDef; +var IncludeDef = /** @class */ (function (_super) { + __extends(IncludeDef, _super); + function IncludeDef() { + return _super !== null && _super.apply(this, arguments) || this; } - else { - return low; + return IncludeDef; +}(expression_1.UnimplementedExpression)); +exports.IncludeDef = IncludeDef; +var VersionedIdentifier = /** @class */ (function (_super) { + __extends(VersionedIdentifier, _super); + function VersionedIdentifier() { + return _super !== null && _super.apply(this, arguments) || this; } -} + return VersionedIdentifier; +}(expression_1.UnimplementedExpression)); +exports.VersionedIdentifier = VersionedIdentifier; -},{"../util/comparison":103,"../util/math":104,"./logic":61,"./quantity":62,"./uncertainty":64}],61:[function(require,module,exports){ +},{"./expression":59}],59:[function(require,module,exports){ "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.ThreeValuedLogic = void 0; -var ThreeValuedLogic = /** @class */ (function () { - function ThreeValuedLogic() { - } - ThreeValuedLogic.and = function () { - var val = []; - for (var _i = 0; _i < arguments.length; _i++) { - val[_i] = arguments[_i]; +exports.UnimplementedExpression = exports.Expression = void 0; +var util_1 = require("../util/util"); +var builder_1 = require("./builder"); +var Expression = /** @class */ (function () { + function Expression(json) { + if (json.operand != null) { + var op = (0, builder_1.build)(json.operand); + if ((0, util_1.typeIsArray)(json.operand)) { + this.args = op; + } + else { + this.arg = op; + } } - if (val.includes(false)) { - return false; + if (json.localId != null) { + this.localId = json.localId; } - else if (val.includes(null)) { - return null; + } + Expression.prototype.execute = function (ctx) { + if (this.localId != null) { + // Store the localId and result on the root context of this library + var execValue = this.exec(ctx); + ctx.rootContext().setLocalIdWithResult(this.localId, execValue); + return execValue; } else { - return true; + return this.exec(ctx); } }; - ThreeValuedLogic.or = function () { - var val = []; - for (var _i = 0; _i < arguments.length; _i++) { - val[_i] = arguments[_i]; - } - if (val.includes(true)) { - return true; - } - else if (val.includes(null)) { - return null; - } - else { - return false; - } + Expression.prototype.exec = function (_ctx) { + return this; }; - ThreeValuedLogic.xor = function () { - var val = []; - for (var _i = 0; _i < arguments.length; _i++) { - val[_i] = arguments[_i]; - } - if (val.includes(null)) { - return null; - } - else { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - return val.reduce(function (a, b) { return (!a ^ !b) === 1; }); + Expression.prototype.execArgs = function (ctx) { + if (this.args != null) { + return this.args.map(function (arg) { return arg.execute(ctx); }); } - }; - ThreeValuedLogic.not = function (val) { - if (val != null) { - return !val; + else if (this.arg != null) { + return this.arg.execute(ctx); } else { return null; } }; - return ThreeValuedLogic; + return Expression; }()); -exports.ThreeValuedLogic = ThreeValuedLogic; +exports.Expression = Expression; +var UnimplementedExpression = /** @class */ (function (_super) { + __extends(UnimplementedExpression, _super); + function UnimplementedExpression(json) { + var _this = _super.call(this, json) || this; + _this.json = json; + return _this; + } + UnimplementedExpression.prototype.exec = function (_ctx) { + throw new Error("Unimplemented Expression: ".concat(this.json.type)); + }; + return UnimplementedExpression; +}(Expression)); +exports.UnimplementedExpression = UnimplementedExpression; -},{}],62:[function(require,module,exports){ +},{"../util/util":92,"./builder":53}],60:[function(require,module,exports){ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.doMultiplication = exports.doDivision = exports.doSubtraction = exports.doAddition = exports.parseQuantity = exports.Quantity = void 0; -var math_1 = require("../util/math"); -var units_1 = require("../util/units"); -var Quantity = /** @class */ (function () { - function Quantity(value, unit) { - this.value = value; - this.unit = unit; - if (this.value == null || isNaN(this.value)) { - throw new Error('Cannot create a quantity with an undefined value'); - } - else if (!(0, math_1.isValidDecimal)(this.value)) { - throw new Error('Cannot create a quantity with an invalid decimal value'); - } - // Attempt to parse the unit with UCUM. If it fails, throw a friendly error. - if (this.unit != null) { - var validation = (0, units_1.checkUnit)(this.unit); - if (!validation.valid) { - throw new Error(validation.message); - } - } - } - Object.defineProperty(Quantity.prototype, "isQuantity", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Quantity.prototype.clone = function () { - return new Quantity(this.value, this.unit); - }; - Quantity.prototype.toString = function () { - return "".concat(this.value, " '").concat(this.unit, "'"); - }; - Quantity.prototype.sameOrBefore = function (other) { - if (other != null && other.isQuantity) { - var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); - if (otherVal == null) { - return null; - } - else { - return this.value <= otherVal; - } - } - }; - Quantity.prototype.sameOrAfter = function (other) { - if (other != null && other.isQuantity) { - var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); - if (otherVal == null) { - return null; - } - else { - return this.value >= otherVal; - } - } - }; - Quantity.prototype.after = function (other) { - if (other != null && other.isQuantity) { - var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); - if (otherVal == null) { - return null; - } - else { - return this.value > otherVal; - } - } +exports.doContains = exports.doExcept = exports.doIncludes = exports.doIntersect = exports.doProperIncludes = exports.doAfter = exports.doUnion = exports.doBefore = void 0; +__exportStar(require("./expression"), exports); +__exportStar(require("./aggregate"), exports); +__exportStar(require("./arithmetic"), exports); +__exportStar(require("./clinical"), exports); +__exportStar(require("./comparison"), exports); +__exportStar(require("./conditional"), exports); +__exportStar(require("./datetime"), exports); +__exportStar(require("./declaration"), exports); +__exportStar(require("./external"), exports); +__exportStar(require("./instance"), exports); +__exportStar(require("./interval"), exports); +__exportStar(require("./list"), exports); +__exportStar(require("./literal"), exports); +__exportStar(require("./logical"), exports); +__exportStar(require("./message"), exports); +__exportStar(require("./nullological"), exports); +__exportStar(require("./parameters"), exports); +__exportStar(require("./quantity"), exports); +__exportStar(require("./query"), exports); +__exportStar(require("./ratio"), exports); +__exportStar(require("./reusable"), exports); +__exportStar(require("./string"), exports); +__exportStar(require("./structured"), exports); +__exportStar(require("./type"), exports); +__exportStar(require("./overloaded"), exports); +// Re-exporting interval functions as overrides to avoid ambiguity +// https://stackoverflow.com/questions/41293108/how-to-do-re-export-with-overrides +// TODO: we should improve this by perhaps renaming and reworking these functions +// it's a bit confusing right now giving the interval exports precedence over the others +var interval_1 = require("./interval"); +Object.defineProperty(exports, "doBefore", { enumerable: true, get: function () { return interval_1.doBefore; } }); +Object.defineProperty(exports, "doUnion", { enumerable: true, get: function () { return interval_1.doUnion; } }); +Object.defineProperty(exports, "doAfter", { enumerable: true, get: function () { return interval_1.doAfter; } }); +Object.defineProperty(exports, "doProperIncludes", { enumerable: true, get: function () { return interval_1.doProperIncludes; } }); +Object.defineProperty(exports, "doIntersect", { enumerable: true, get: function () { return interval_1.doIntersect; } }); +Object.defineProperty(exports, "doIncludes", { enumerable: true, get: function () { return interval_1.doIncludes; } }); +Object.defineProperty(exports, "doExcept", { enumerable: true, get: function () { return interval_1.doExcept; } }); +Object.defineProperty(exports, "doContains", { enumerable: true, get: function () { return interval_1.doContains; } }); + +},{"./aggregate":51,"./arithmetic":52,"./clinical":54,"./comparison":55,"./conditional":56,"./datetime":57,"./declaration":58,"./expression":59,"./external":61,"./instance":62,"./interval":63,"./list":65,"./literal":66,"./logical":67,"./message":68,"./nullological":69,"./overloaded":70,"./parameters":71,"./quantity":72,"./query":73,"./ratio":74,"./reusable":75,"./string":76,"./structured":77,"./type":78}],61:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); }; - Quantity.prototype.before = function (other) { - if (other != null && other.isQuantity) { - var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); - if (otherVal == null) { - return null; - } - else { - return this.value < otherVal; - } + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; } + return t; }; - Quantity.prototype.equals = function (other) { - if (other != null && other.isQuantity) { - if ((!this.unit && other.unit) || (this.unit && !other.unit)) { - return false; - } - else if (!this.unit && !other.unit) { - return this.value === other.value; - } - else { - var otherVal = (0, units_1.convertUnit)(other.value, other.unit, this.unit); - if (otherVal == null) { - return null; - } - else { - return (0, math_1.decimalAdjust)('round', this.value, -8) === otherVal; - } + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Retrieve = void 0; +var expression_1 = require("./expression"); +var util_1 = require("../util/util"); +var builder_1 = require("./builder"); +var Retrieve = /** @class */ (function (_super) { + __extends(Retrieve, _super); + function Retrieve(json) { + var _this = _super.call(this, json) || this; + _this.datatype = json.dataType; + _this.templateId = json.templateId; + _this.codeProperty = json.codeProperty; + _this.codes = (0, builder_1.build)(json.codes); + _this.dateProperty = json.dateProperty; + _this.dateRange = (0, builder_1.build)(json.dateRange); + return _this; + } + Retrieve.prototype.exec = function (ctx) { + var _a; + var _this = this; + // Object with retrieve information to pass back to patient source + // Always assign datatype. Assign codeProperty and dateProperty if present + var retrieveDetails = __assign(__assign({ datatype: this.datatype }, (this.codeProperty ? { codeProperty: this.codeProperty } : {})), (this.dateProperty ? { dateProperty: this.dateProperty } : {})); + if (this.codes) { + var resolvedCodes = this.codes.execute(ctx); + if (resolvedCodes == null) { + return []; } + retrieveDetails.codes = resolvedCodes; } - }; - Quantity.prototype.convertUnit = function (toUnit) { - var value = (0, units_1.convertUnit)(this.value, this.unit, toUnit); - // Need to pass through constructor again to catch invalid units - return new Quantity(value, toUnit); - }; - Quantity.prototype.dividedBy = function (other) { - if (other == null || other === 0 || other.value === 0) { - return null; + if (this.dateRange) { + retrieveDetails.dateRange = this.dateRange.execute(ctx); } - else if (!other.isQuantity) { - // convert it to a quantity w/ unit 1 - other = new Quantity(other, '1'); + if (this.templateId) { + retrieveDetails.templateId = this.templateId; } - var _a = (0, units_1.normalizeUnitsWhenPossible)(this.value, this.unit, other.value, other.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; - var resultValue = val1 / val2; - var resultUnit = (0, units_1.getQuotientOfUnits)(unit1, unit2); - // Check for invalid unit or value - if (resultUnit == null || (0, math_1.overflowsOrUnderflows)(resultValue)) { - return null; + var records = ctx.findRecords(this.templateId != null ? this.templateId : this.datatype, retrieveDetails); + if (retrieveDetails.codes) { + records = records.filter(function (r) { return _this.recordMatchesCodesOrVS(r, retrieveDetails.codes); }); } - return new Quantity((0, math_1.decimalAdjust)('round', resultValue, -8), resultUnit); - }; - Quantity.prototype.multiplyBy = function (other) { - if (other == null) { - return null; + if (retrieveDetails.dateRange && this.dateProperty) { + records = records.filter(function (r) { var _a; return (_a = retrieveDetails.dateRange) === null || _a === void 0 ? void 0 : _a.includes(r.getDateOrInterval(_this.dateProperty)); }); } - else if (!other.isQuantity) { - // convert it to a quantity w/ unit 1 - other = new Quantity(other, '1'); + if (Array.isArray(records)) { + (_a = ctx.evaluatedRecords).push.apply(_a, records); } - var _a = (0, units_1.normalizeUnitsWhenPossible)(this.value, this.unit, other.value, other.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; - var resultValue = val1 * val2; - var resultUnit = (0, units_1.getProductOfUnits)(unit1, unit2); - // Check for invalid unit or value - if (resultUnit == null || (0, math_1.overflowsOrUnderflows)(resultValue)) { - return null; + else { + ctx.evaluatedRecords.push(records); } - return new Quantity((0, math_1.decimalAdjust)('round', resultValue, -8), resultUnit); + return records; }; - return Quantity; -}()); -exports.Quantity = Quantity; -function parseQuantity(str) { - var components = /([+|-]?\d+\.?\d*)\s*('(.+)')?/.exec(str); - if (components != null && components[1] != null) { - var value = parseFloat(components[1]); - if (!(0, math_1.isValidDecimal)(value)) { - return null; - } - var unit = void 0; - if (components[3] != null) { - unit = components[3].trim(); + Retrieve.prototype.recordMatchesCodesOrVS = function (record, codes) { + var _this = this; + if ((0, util_1.typeIsArray)(codes)) { + return codes.some(function (c) { return c.hasMatch(record.getCode(_this.codeProperty)); }); } else { - unit = ''; - } - return new Quantity(value, unit); - } - else { - return null; - } -} -exports.parseQuantity = parseQuantity; -function doScaledAddition(a, b, scaleForB) { - if (a != null && a.isQuantity && b != null && b.isQuantity) { - var _a = (0, units_1.normalizeUnitsWhenPossible)(a.value, a.unit, b.value * scaleForB, b.unit), val1 = _a[0], unit1 = _a[1], val2 = _a[2], unit2 = _a[3]; - if (unit1 !== unit2) { - // not compatible units, so we can't do addition - return null; - } - var sum = val1 + val2; - if ((0, math_1.overflowsOrUnderflows)(sum)) { - return null; + return codes.hasMatch(record.getCode(this.codeProperty)); } - return new Quantity(sum, unit1); - } - else if (a.copy && a.add) { - // Date / DateTime require a CQL time unit - var cqlUnitB = (0, units_1.convertToCQLDateUnit)(b.unit) || b.unit; - return a.copy().add(b.value * scaleForB, cqlUnitB); - } - else { - throw new Error('Unsupported argument types.'); - } -} -function doAddition(a, b) { - return doScaledAddition(a, b, 1); -} -exports.doAddition = doAddition; -function doSubtraction(a, b) { - return doScaledAddition(a, b, -1); -} -exports.doSubtraction = doSubtraction; -function doDivision(a, b) { - if (a != null && a.isQuantity) { - return a.dividedBy(b); - } -} -exports.doDivision = doDivision; -function doMultiplication(a, b) { - if (a != null && a.isQuantity) { - return a.multiplyBy(b); - } - else { - return b.multiplyBy(a); - } -} -exports.doMultiplication = doMultiplication; + }; + return Retrieve; +}(expression_1.Expression)); +exports.Retrieve = Retrieve; -},{"../util/math":104,"../util/units":105}],63:[function(require,module,exports){ +},{"../util/util":92,"./builder":53,"./expression":59}],62:[function(require,module,exports){ "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.Ratio = void 0; -var Ratio = /** @class */ (function () { - function Ratio(numerator, denominator) { - this.numerator = numerator; - this.denominator = denominator; - if (numerator == null) { - throw new Error('Cannot create a ratio with an undefined numerator'); - } - if (denominator == null) { - throw new Error('Cannot create a ratio with an undefined denominator'); - } +exports.Instance = void 0; +var expression_1 = require("./expression"); +var quantity_1 = require("../datatypes/quantity"); +var datatypes_1 = require("../datatypes/datatypes"); +var builder_1 = require("./builder"); +var Element = /** @class */ (function () { + function Element(json) { + this.name = json.name; + this.value = (0, builder_1.build)(json.value); } - Object.defineProperty(Ratio.prototype, "isRatio", { - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Ratio.prototype.clone = function () { - return new Ratio(this.numerator.clone(), this.denominator.clone()); - }; - Ratio.prototype.toString = function () { - return "".concat(this.numerator.toString(), " : ").concat(this.denominator.toString()); + Element.prototype.exec = function (ctx) { + return this.value != null ? this.value.execute(ctx) : undefined; }; - Ratio.prototype.equals = function (other) { - if (other != null && other.isRatio) { - var divided_this = this.numerator.dividedBy(this.denominator); - var divided_other = other.numerator.dividedBy(other.denominator); - return divided_this === null || divided_this === void 0 ? void 0 : divided_this.equals(divided_other); + return Element; +}()); +var Instance = /** @class */ (function (_super) { + __extends(Instance, _super); + function Instance(json) { + var _this = _super.call(this, json) || this; + _this.classType = json.classType; + _this.element = json.element.map(function (child) { return new Element(child); }); + return _this; + } + Instance.prototype.exec = function (ctx) { + var obj = {}; + for (var _i = 0, _a = this.element; _i < _a.length; _i++) { + var el = _a[_i]; + obj[el.name] = el.exec(ctx); } - else { - return false; + switch (this.classType) { + case '{urn:hl7-org:elm-types:r1}Quantity': + return new quantity_1.Quantity(obj.value, obj.unit); + case '{urn:hl7-org:elm-types:r1}Code': + return new datatypes_1.Code(obj.code, obj.system, obj.version, obj.display); + case '{urn:hl7-org:elm-types:r1}Concept': + return new datatypes_1.Concept(obj.codes, obj.display); + default: + return obj; } }; - Ratio.prototype.equivalent = function (other) { - var equal = this.equals(other); - return equal != null ? equal : false; - }; - return Ratio; -}()); -exports.Ratio = Ratio; + return Instance; +}(expression_1.Expression)); +exports.Instance = Instance; -},{}],64:[function(require,module,exports){ +},{"../datatypes/datatypes":43,"../datatypes/quantity":48,"./builder":53,"./expression":59}],63:[function(require,module,exports){ "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Uncertainty = void 0; -var logic_1 = require("./logic"); -var Uncertainty = /** @class */ (function () { - function Uncertainty(low, high) { - var _a; - if (low === void 0) { low = null; } - this.low = low; - this.high = high; - var gt = function (a, b) { - if (typeof a !== typeof b) { - // TODO: This should probably throw rather than return false. - // Uncertainties with different types probably shouldn't be supported. - return false; - } - if (typeof a.after === 'function') { - return a.after(b); - } - else { - return a > b; - } - }; - var isNonEnumerable = function (val) { - return val != null && (val.isCode || val.isConcept || val.isValueSet); - }; - if (typeof this.high === 'undefined') { - this.high = this.low; - } - if (isNonEnumerable(this.low) || isNonEnumerable(this.high)) { - this.low = this.high = null; - } - if (this.low != null && this.high != null && gt(this.low, this.high)) { - _a = [this.high, this.low], this.low = _a[0], this.high = _a[1]; - } +exports.Collapse = exports.Expand = exports.Ends = exports.Starts = exports.End = exports.Start = exports.Size = exports.Width = exports.doIntersect = exports.doExcept = exports.doUnion = exports.OverlapsBefore = exports.OverlapsAfter = exports.Overlaps = exports.MeetsBefore = exports.MeetsAfter = exports.Meets = exports.doBefore = exports.doAfter = exports.doProperIncludes = exports.doIncludes = exports.doContains = exports.Interval = void 0; +var expression_1 = require("./expression"); +var quantity_1 = require("../datatypes/quantity"); +var math_1 = require("../util/math"); +var units_1 = require("../util/units"); +var dtivl = __importStar(require("../datatypes/interval")); +var builder_1 = require("./builder"); +var Interval = /** @class */ (function (_super) { + __extends(Interval, _super); + function Interval(json) { + var _this = _super.call(this, json) || this; + _this.lowClosed = json.lowClosed; + _this.lowClosedExpression = (0, builder_1.build)(json.lowClosedExpression); + _this.highClosed = json.highClosed; + _this.highClosedExpression = (0, builder_1.build)(json.highClosedExpression); + _this.low = (0, builder_1.build)(json.low); + _this.high = (0, builder_1.build)(json.high); + return _this; } - Uncertainty.from = function (obj) { - if (obj != null && obj.isUncertainty) { - return obj; - } - else { - return new Uncertainty(obj); - } - }; - Object.defineProperty(Uncertainty.prototype, "isUncertainty", { + Object.defineProperty(Interval.prototype, "isInterval", { + // Define a simple getter to allow type-checking of this class without instanceof + // and in a way that survives minification (as opposed to checking constructor.name) get: function () { return true; }, enumerable: false, configurable: true }); - Uncertainty.prototype.copy = function () { - var newLow = this.low; - var newHigh = this.high; - if (typeof this.low.copy === 'function') { - newLow = this.low.copy(); - } - if (typeof this.high.copy === 'function') { - newHigh = this.high.copy(); - } - return new Uncertainty(newLow, newHigh); - }; - Uncertainty.prototype.isPoint = function () { - // Note: Can't use normal equality, as that fails for Javascript dates - // TODO: Fix after we don't need to support Javascript date uncertainties anymore - var lte = function (a, b) { - if (typeof a !== typeof b) { - return false; - } - if (typeof a.sameOrBefore === 'function') { - return a.sameOrBefore(b); - } - else { - return a <= b; - } - }; - var gte = function (a, b) { - if (typeof a !== typeof b) { - return false; - } - if (typeof a.sameOrBefore === 'function') { - return a.sameOrAfter(b); + Interval.prototype.exec = function (ctx) { + var lowValue = this.low.execute(ctx); + var highValue = this.high.execute(ctx); + var lowClosed = this.lowClosed != null + ? this.lowClosed + : this.lowClosedExpression && this.lowClosedExpression.execute(ctx); + var highClosed = this.highClosed != null + ? this.highClosed + : this.highClosedExpression && this.highClosedExpression.execute(ctx); + var defaultPointType; + if (lowValue == null && highValue == null) { + // try to get the default point type from a cast + if (this.low.asTypeSpecifier && this.low.asTypeSpecifier.type === 'NamedTypeSpecifier') { + defaultPointType = this.low.asTypeSpecifier.name; } - else { - return a >= b; + else if (this.high.asTypeSpecifier && + this.high.asTypeSpecifier.type === 'NamedTypeSpecifier') { + defaultPointType = this.high.asTypeSpecifier.name; } - }; - return (this.low != null && this.high != null && lte(this.low, this.high) && gte(this.low, this.high)); + } + return new dtivl.Interval(lowValue, highValue, lowClosed, highClosed, defaultPointType); }; - Uncertainty.prototype.equals = function (other) { - other = Uncertainty.from(other); - return logic_1.ThreeValuedLogic.not(logic_1.ThreeValuedLogic.or(this.lessThan(other), this.greaterThan(other))); + return Interval; +}(expression_1.Expression)); +exports.Interval = Interval; +// Equal is completely handled by overloaded#Equal +// NotEqual is completely handled by overloaded#Equal +// Delegated to by overloaded#Contains and overloaded#In +function doContains(interval, item, precision) { + return interval.contains(item, precision); +} +exports.doContains = doContains; +// Delegated to by overloaded#Includes and overloaded#IncludedIn +function doIncludes(interval, subinterval, precision) { + return interval.includes(subinterval, precision); +} +exports.doIncludes = doIncludes; +// Delegated to by overloaded#ProperIncludes and overloaded@ProperIncludedIn +function doProperIncludes(interval, subinterval, precision) { + return interval.properlyIncludes(subinterval, precision); +} +exports.doProperIncludes = doProperIncludes; +// Delegated to by overloaded#After +function doAfter(a, b, precision) { + return a.after(b, precision); +} +exports.doAfter = doAfter; +// Delegated to by overloaded#Before +function doBefore(a, b, precision) { + return a.before(b, precision); +} +exports.doBefore = doBefore; +var Meets = /** @class */ (function (_super) { + __extends(Meets, _super); + function Meets(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + Meets.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.meets(b, this.precision); + } + else { + return null; + } }; - Uncertainty.prototype.lessThan = function (other) { - var lt = function (a, b) { - if (typeof a !== typeof b) { - return false; - } - if (typeof a.before === 'function') { - return a.before(b); - } - else { - return a < b; - } - }; - other = Uncertainty.from(other); - var bestCase = this.low == null || other.high == null || lt(this.low, other.high); - var worstCase = this.high != null && other.low != null && lt(this.high, other.low); - if (bestCase === worstCase) { - return bestCase; + return Meets; +}(expression_1.Expression)); +exports.Meets = Meets; +var MeetsAfter = /** @class */ (function (_super) { + __extends(MeetsAfter, _super); + function MeetsAfter(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + MeetsAfter.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.meetsAfter(b, this.precision); } else { return null; } }; - Uncertainty.prototype.greaterThan = function (other) { - return Uncertainty.from(other).lessThan(this); - }; - Uncertainty.prototype.lessThanOrEquals = function (other) { - return logic_1.ThreeValuedLogic.not(this.greaterThan(Uncertainty.from(other))); - }; - Uncertainty.prototype.greaterThanOrEquals = function (other) { - return logic_1.ThreeValuedLogic.not(this.lessThan(Uncertainty.from(other))); - }; - return Uncertainty; -}()); -exports.Uncertainty = Uncertainty; - -},{"./logic":61}],65:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AnyTrue = exports.AllTrue = exports.PopulationVariance = exports.Variance = exports.PopulationStdDev = exports.GeometricMean = exports.Product = exports.StdDev = exports.Mode = exports.Median = exports.Avg = exports.Max = exports.Min = exports.Sum = exports.Count = void 0; -var expression_1 = require("./expression"); -var util_1 = require("../util/util"); -var datatypes_1 = require("../datatypes/datatypes"); -var exception_1 = require("../datatypes/exception"); -var comparison_1 = require("../util/comparison"); -var builder_1 = require("./builder"); -var AggregateExpression = /** @class */ (function (_super) { - __extends(AggregateExpression, _super); - function AggregateExpression(json) { + return MeetsAfter; +}(expression_1.Expression)); +exports.MeetsAfter = MeetsAfter; +var MeetsBefore = /** @class */ (function (_super) { + __extends(MeetsBefore, _super); + function MeetsBefore(json) { var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; return _this; } - return AggregateExpression; -}(expression_1.Expression)); -var Count = /** @class */ (function (_super) { - __extends(Count, _super); - function Count(json) { - return _super.call(this, json) || this; - } - Count.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if ((0, util_1.typeIsArray)(items)) { - return (0, util_1.removeNulls)(items).length; + MeetsBefore.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.meetsBefore(b, this.precision); } - return 0; - }; - return Count; -}(AggregateExpression)); -exports.Count = Count; -var Sum = /** @class */ (function (_super) { - __extends(Sum, _super); - function Sum(json) { - return _super.call(this, json) || this; - } - Sum.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { + else { return null; } - try { - items = processQuantities(items); + }; + return MeetsBefore; +}(expression_1.Expression)); +exports.MeetsBefore = MeetsBefore; +var Overlaps = /** @class */ (function (_super) { + __extends(Overlaps, _super); + function Overlaps(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + Overlaps.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.overlaps(b, this.precision); } - catch (e) { + else { return null; } - if (items.length === 0) { + }; + return Overlaps; +}(expression_1.Expression)); +exports.Overlaps = Overlaps; +var OverlapsAfter = /** @class */ (function (_super) { + __extends(OverlapsAfter, _super); + function OverlapsAfter(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + OverlapsAfter.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.overlapsAfter(b, this.precision); + } + else { return null; } - if (hasOnlyQuantities(items)) { - var values = getValuesFromQuantities(items); - var sum = values.reduce(function (x, y) { return x + y; }); - return new datatypes_1.Quantity(sum, items[0].unit); + }; + return OverlapsAfter; +}(expression_1.Expression)); +exports.OverlapsAfter = OverlapsAfter; +var OverlapsBefore = /** @class */ (function (_super) { + __extends(OverlapsBefore, _super); + function OverlapsBefore(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + OverlapsBefore.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.overlapsBefore(b, this.precision); } else { - return items.reduce(function (x, y) { return x + y; }); + return null; } }; - return Sum; -}(AggregateExpression)); -exports.Sum = Sum; -var Min = /** @class */ (function (_super) { - __extends(Min, _super); - function Min(json) { + return OverlapsBefore; +}(expression_1.Expression)); +exports.OverlapsBefore = OverlapsBefore; +// Delegated to by overloaded#Union +function doUnion(a, b) { + return a.union(b); +} +exports.doUnion = doUnion; +// Delegated to by overloaded#Except +function doExcept(a, b) { + if (a != null && b != null) { + return a.except(b); + } + else { + return null; + } +} +exports.doExcept = doExcept; +// Delegated to by overloaded#Intersect +function doIntersect(a, b) { + if (a != null && b != null) { + return a.intersect(b); + } + else { + return null; + } +} +exports.doIntersect = doIntersect; +var Width = /** @class */ (function (_super) { + __extends(Width, _super); + function Width(json) { return _super.call(this, json) || this; } - Min.prototype.exec = function (ctx) { - var list = this.source.execute(ctx); - if (list == null) { + Width.prototype.exec = function (ctx) { + var interval = this.arg.execute(ctx); + if (interval == null) { return null; } - var listWithoutNulls = (0, util_1.removeNulls)(list); - // Check for incompatible units and return null. We don't want to convert - // the units for Min/Max, so we throw away the converted array if it succeeds - try { - processQuantities(list); - } - catch (e) { + return interval.width(); + }; + return Width; +}(expression_1.Expression)); +exports.Width = Width; +var Size = /** @class */ (function (_super) { + __extends(Size, _super); + function Size(json) { + return _super.call(this, json) || this; + } + Size.prototype.exec = function (ctx) { + var interval = this.arg.execute(ctx); + if (interval == null) { return null; } - if (listWithoutNulls.length === 0) { + return interval.size(); + }; + return Size; +}(expression_1.Expression)); +exports.Size = Size; +var Start = /** @class */ (function (_super) { + __extends(Start, _super); + function Start(json) { + return _super.call(this, json) || this; + } + Start.prototype.exec = function (ctx) { + var interval = this.arg.execute(ctx); + if (interval == null) { return null; } - // We assume the list is an array of all the same type. - var minimum = listWithoutNulls[0]; - for (var _i = 0, listWithoutNulls_1 = listWithoutNulls; _i < listWithoutNulls_1.length; _i++) { - var element = listWithoutNulls_1[_i]; - if ((0, comparison_1.lessThan)(element, minimum)) { - minimum = element; - } + var start = interval.start(); + // fix the timezoneOffset of minimum Datetime to match context offset + if (start && start.isDateTime && start.equals(math_1.MIN_DATETIME_VALUE)) { + start.timezoneOffset = ctx.getTimezoneOffset(); } - return minimum; + return start; }; - return Min; -}(AggregateExpression)); -exports.Min = Min; -var Max = /** @class */ (function (_super) { - __extends(Max, _super); - function Max(json) { + return Start; +}(expression_1.Expression)); +exports.Start = Start; +var End = /** @class */ (function (_super) { + __extends(End, _super); + function End(json) { return _super.call(this, json) || this; } - Max.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (items == null) { + End.prototype.exec = function (ctx) { + var interval = this.arg.execute(ctx); + if (interval == null) { return null; } - var listWithoutNulls = (0, util_1.removeNulls)(items); - // Check for incompatible units and return null. We don't want to convert - // the units for Min/Max, so we throw away the converted array if it succeeds - try { - processQuantities(items); + var end = interval.end(); + // fix the timezoneOffset of maximum Datetime to match context offset + if (end && end.isDateTime && end.equals(math_1.MAX_DATETIME_VALUE)) { + end.timezoneOffset = ctx.getTimezoneOffset(); } - catch (e) { - return null; + return end; + }; + return End; +}(expression_1.Expression)); +exports.End = End; +var Starts = /** @class */ (function (_super) { + __extends(Starts, _super); + function Starts(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + Starts.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.starts(b, this.precision); } - if (listWithoutNulls.length === 0) { + else { return null; } - // We assume the list is an array of all the same type. - var maximum = listWithoutNulls[0]; - for (var _i = 0, listWithoutNulls_2 = listWithoutNulls; _i < listWithoutNulls_2.length; _i++) { - var element = listWithoutNulls_2[_i]; - if ((0, comparison_1.greaterThan)(element, maximum)) { - maximum = element; - } - } - return maximum; }; - return Max; -}(AggregateExpression)); -exports.Max = Max; -var Avg = /** @class */ (function (_super) { - __extends(Avg, _super); - function Avg(json) { - return _super.call(this, json) || this; + return Starts; +}(expression_1.Expression)); +exports.Starts = Starts; +var Ends = /** @class */ (function (_super) { + __extends(Ends, _super); + function Ends(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; } - Avg.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { - return null; - } - try { - items = processQuantities(items); + Ends.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.ends(b, this.precision); } - catch (e) { + else { return null; } - if (items.length === 0) { - return null; + }; + return Ends; +}(expression_1.Expression)); +exports.Ends = Ends; +function intervalListType(intervals) { + // Returns one of null, 'time', 'date', 'datetime', 'quantity', 'integer', 'decimal' or 'mismatch' + var type = null; + for (var _i = 0, intervals_1 = intervals; _i < intervals_1.length; _i++) { + var itvl = intervals_1[_i]; + if (itvl == null) { + continue; } - if (hasOnlyQuantities(items)) { - var values = getValuesFromQuantities(items); - var sum = values.reduce(function (x, y) { return x + y; }); - return new datatypes_1.Quantity(sum / values.length, items[0].unit); + if (itvl.low == null && itvl.high == null) { + //can't really determine type from this + continue; } - else { - var sum = items.reduce(function (x, y) { return x + y; }); - return sum / items.length; + // if one end is null (but not both), the type can be determined from the other end + var low = itvl.low != null ? itvl.low : itvl.high; + var high = itvl.high != null ? itvl.high : itvl.low; + if (low.isTime && low.isTime() && high.isTime && high.isTime()) { + if (type == null) { + type = 'time'; + } + else if (type === 'time') { + continue; + } + else { + return 'mismatch'; + } + // if an interval mixes date and datetime, type is datetime (for implicit conversion) } - }; - return Avg; -}(AggregateExpression)); -exports.Avg = Avg; -var Median = /** @class */ (function (_super) { - __extends(Median, _super); - function Median(json) { - return _super.call(this, json) || this; - } - Median.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { - return null; + else if ((low.isDateTime || high.isDateTime) && + (low.isDateTime || low.isDate) && + (high.isDateTime || high.isDate)) { + if (type == null || type === 'date') { + type = 'datetime'; + } + else if (type === 'datetime') { + continue; + } + else { + return 'mismatch'; + } } - if (items.length === 0) { - return null; + else if (low.isDate && high.isDate) { + if (type == null) { + type = 'date'; + } + else if (type === 'date' || type === 'datetime') { + continue; + } + else { + return 'mismatch'; + } } - try { - items = processQuantities(items); + else if (low.isQuantity && high.isQuantity) { + if (type == null) { + type = 'quantity'; + } + else if (type === 'quantity') { + continue; + } + else { + return 'mismatch'; + } } - catch (e) { - return null; + else if (Number.isInteger(low) && Number.isInteger(high)) { + if (type == null) { + type = 'integer'; + } + else if (type === 'integer' || type === 'decimal') { + continue; + } + else { + return 'mismatch'; + } } - if (!hasOnlyQuantities(items)) { - return medianOfNumbers(items); + else if (typeof low === 'number' && typeof high === 'number') { + if (type == null || type === 'integer') { + type = 'decimal'; + } + else if (type === 'decimal') { + continue; + } + else { + return 'mismatch'; + } + //if we are here ends are mismatched } - var values = getValuesFromQuantities(items); - var median = medianOfNumbers(values); - return new datatypes_1.Quantity(median, items[0].unit); - }; - return Median; -}(AggregateExpression)); -exports.Median = Median; -var Mode = /** @class */ (function (_super) { - __extends(Mode, _super); - function Mode(json) { + else { + return 'mismatch'; + } + } + return type; +} +var Expand = /** @class */ (function (_super) { + __extends(Expand, _super); + function Expand(json) { return _super.call(this, json) || this; } - Mode.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { - return null; + Expand.prototype.exec = function (ctx) { + // expand(argument List>, per Quantity) List> + var defaultPer, expandFunction; + var _a = this.execArgs(ctx), intervals = _a[0], per = _a[1]; + // CQL 1.5 introduced an overload to allow singular intervals; make it a list so we can use the same logic for either overload + if (!Array.isArray(intervals)) { + intervals = [intervals]; } - if (items.length === 0) { + var type = intervalListType(intervals); + if (type === 'mismatch') { + throw new Error('List of intervals contains mismatched types.'); + } + if (type == null) { return null; } - var filtered; - try { - filtered = processQuantities(items); + // this step collapses overlaps, and also returns a clone of intervals so we can feel free to mutate + intervals = collapseIntervals(intervals, per); + if (intervals.length === 0) { + return []; } - catch (e) { - return null; + if (['time', 'date', 'datetime'].includes(type)) { + expandFunction = this.expandDTishInterval; + defaultPer = function (interval) { return new quantity_1.Quantity(1, interval.low.getPrecision()); }; } - if (hasOnlyQuantities(filtered)) { - var values = getValuesFromQuantities(filtered); - var mode = this.mode(values); - if (mode.length === 1) { - mode = mode[0]; - } - return new datatypes_1.Quantity(mode, items[0].unit); + else if (['quantity'].includes(type)) { + expandFunction = this.expandQuantityInterval; + defaultPer = function (interval) { return new quantity_1.Quantity(1, interval.low.unit); }; + } + else if (['integer', 'decimal'].includes(type)) { + expandFunction = this.expandNumericInterval; + defaultPer = function (_interval) { return new quantity_1.Quantity(1, '1'); }; } else { - var mode = this.mode(filtered); - if (mode.length === 1) { - return mode[0]; - } - else { - return mode; - } + throw new Error('Interval list type not yet supported.'); } - }; - Mode.prototype.mode = function (arr) { - var max = 0; - var counts = {}; var results = []; - for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) { - var elem = arr_1[_i]; - var cnt = (counts[elem] = (counts[elem] != null ? counts[elem] : 0) + 1); - if (cnt === max && !results.includes(elem)) { - results.push(elem); + for (var _i = 0, intervals_2 = intervals; _i < intervals_2.length; _i++) { + var interval = intervals_2[_i]; + if (interval == null) { + continue; + } + // We do not support open ended intervals since result would likely be too long + if (interval.low == null || interval.high == null) { + return null; + } + if (type === 'datetime') { + //support for implicitly converting dates to datetime + interval.low = interval.low.getDateTime(); + interval.high = interval.high.getDateTime(); } - else if (cnt > max) { - results = [elem]; - max = cnt; + per = per != null ? per : defaultPer(interval); + var items = expandFunction.call(this, interval, per); + if (items === null) { + return null; } + results.push.apply(results, (items || [])); } return results; }; - return Mode; -}(AggregateExpression)); -exports.Mode = Mode; -var StdDev = /** @class */ (function (_super) { - __extends(StdDev, _super); - function StdDev(json) { - var _this = _super.call(this, json) || this; - _this.type = 'standard_deviation'; - return _this; - } - StdDev.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { - return null; - } - try { - items = processQuantities(items); + Expand.prototype.expandDTishInterval = function (interval, per) { + per.unit = (0, units_1.convertToCQLDateUnit)(per.unit); + if (per.unit === 'week') { + per.value *= 7; + per.unit = 'day'; } - catch (e) { + // Precision Checks + // return null if precision not applicable (e.g. gram, or minutes for dates) + if (!interval.low.constructor.FIELDS.includes(per.unit)) { return null; } - if (items.length === 0) { + // open interval with null boundaries do not contribute to output + // closed interval with null boundaries are not allowed for performance reasons + if (interval.low == null || interval.high == null) { return null; } - if (hasOnlyQuantities(items)) { - var values = getValuesFromQuantities(items); - var stdDev = this.standardDeviation(values); - return new datatypes_1.Quantity(stdDev, items[0].unit); + var low = interval.lowClosed ? interval.low : interval.low.successor(); + var high = interval.highClosed ? interval.high : interval.high.predecessor(); + if (low.after(high)) { + return []; } - else { - return this.standardDeviation(items); + if (interval.low.isLessPrecise(per.unit) || interval.high.isLessPrecise(per.unit)) { + return []; } - }; - StdDev.prototype.standardDeviation = function (list) { - var val = this.stats(list); - if (val) { - return val[this.type]; + var current_low = low; + var results = []; + low = this.truncateToPrecision(low, per.unit); + high = this.truncateToPrecision(high, per.unit); + var current_high = current_low.add(per.value, per.unit).predecessor(); + var intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); + while (intervalToAdd.high.sameOrBefore(high)) { + results.push(intervalToAdd); + current_low = current_low.add(per.value, per.unit); + current_high = current_low.add(per.value, per.unit).predecessor(); + intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); } + return results; }; - StdDev.prototype.stats = function (list) { - var sum = list.reduce(function (x, y) { return x + y; }); - var mean = sum / list.length; - var sumOfSquares = 0; - for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { - var sq = list_1[_i]; - sumOfSquares += Math.pow(sq - mean, 2); + Expand.prototype.truncateToPrecision = function (value, unit) { + // If interval boundaries are more precise than per quantity, truncate to + // the precision specified by the per + var shouldTruncate = false; + for (var _i = 0, _a = value.constructor.FIELDS; _i < _a.length; _i++) { + var field = _a[_i]; + if (shouldTruncate) { + value[field] = null; + } + if (field === unit) { + // Start truncating after this unit + shouldTruncate = true; + } } - var std_var = (1 / (list.length - 1)) * sumOfSquares; - var pop_var = (1 / list.length) * sumOfSquares; - var std_dev = Math.sqrt(std_var); - var pop_dev = Math.sqrt(pop_var); - return { - standard_variance: std_var, - population_variance: pop_var, - standard_deviation: std_dev, - population_deviation: pop_dev - }; + return value; }; - return StdDev; -}(AggregateExpression)); -exports.StdDev = StdDev; -var Product = /** @class */ (function (_super) { - __extends(Product, _super); - function Product(json) { - return _super.call(this, json) || this; - } - Product.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { - return null; - } - try { - items = processQuantities(items); + Expand.prototype.expandQuantityInterval = function (interval, per) { + // we want to convert everything to the more precise of the interval.low or per + var result_units; + var res = (0, units_1.compareUnits)(interval.low.unit, per.unit); + if (res != null && res > 0) { + //interval.low.unit is 'bigger' aka les precise + result_units = per.unit; } - catch (e) { - return null; + else { + result_units = interval.low.unit; } - if (items.length === 0) { + var low_value = (0, units_1.convertUnit)(interval.low.value, interval.low.unit, result_units); + var high_value = (0, units_1.convertUnit)(interval.high.value, interval.high.unit, result_units); + var per_value = (0, units_1.convertUnit)(per.value, per.unit, result_units); + // return null if unit conversion failed, must have mismatched units + if (!(low_value != null && high_value != null && per_value != null)) { return null; } - if (hasOnlyQuantities(items)) { - var values = getValuesFromQuantities(items); - var product = values.reduce(function (x, y) { return x * y; }); - // Units are not multiplied for the geometric product - return new datatypes_1.Quantity(product, items[0].unit); - } - else { - return items.reduce(function (x, y) { return x * y; }); + var results = this.makeNumericIntervalList(low_value, high_value, interval.lowClosed, interval.highClosed, per_value); + for (var _i = 0, results_1 = results; _i < results_1.length; _i++) { + var itvl = results_1[_i]; + itvl.low = new quantity_1.Quantity(itvl.low, result_units); + itvl.high = new quantity_1.Quantity(itvl.high, result_units); } + return results; }; - return Product; -}(AggregateExpression)); -exports.Product = Product; -var GeometricMean = /** @class */ (function (_super) { - __extends(GeometricMean, _super); - function GeometricMean(json) { - return _super.call(this, json) || this; - } - GeometricMean.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - if (!(0, util_1.typeIsArray)(items)) { + Expand.prototype.expandNumericInterval = function (interval, per) { + if (per.unit !== '1' && per.unit !== '') { return null; } - try { - items = processQuantities(items); + return this.makeNumericIntervalList(interval.low, interval.high, interval.lowClosed, interval.highClosed, per.value); + }; + Expand.prototype.makeNumericIntervalList = function (low, high, lowClosed, highClosed, perValue) { + // If the per value is a Decimal (has a .), 8 decimal places are appropriate + // Integers should have 0 Decimal places + var perIsDecimal = perValue.toString().includes('.'); + var decimalPrecision = perIsDecimal ? 8 : 0; + low = lowClosed ? low : (0, math_1.successor)(low); + high = highClosed ? high : (0, math_1.predecessor)(high); + // If the interval boundaries are more precise than the per quantity, the + // more precise values will be truncated to the precision specified by the + // per quantity. + low = truncateDecimal(low, decimalPrecision); + high = truncateDecimal(high, decimalPrecision); + if (low > high) { + return []; } - catch (e) { - return null; + if (low == null || high == null) { + return []; } - if (items.length === 0) { - return null; + var perUnitSize = perIsDecimal ? 0.00000001 : 1; + if (low === high && + Number.isInteger(low) && + Number.isInteger(high) && + !Number.isInteger(perValue)) { + high = parseFloat((high + 1).toFixed(decimalPrecision)); } - if (hasOnlyQuantities(items)) { - var values = getValuesFromQuantities(items); - var product = values.reduce(function (x, y) { return x * y; }); - var geoMean = Math.pow(product, 1.0 / items.length); - return new datatypes_1.Quantity(geoMean, items[0].unit); + var current_low = low; + var results = []; + if (perValue > high - low + perUnitSize) { + return []; } - else { - var product = items.reduce(function (x, y) { return x * y; }); - return Math.pow(product, 1.0 / items.length); + var current_high = parseFloat((current_low + perValue - perUnitSize).toFixed(decimalPrecision)); + var intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); + while (intervalToAdd.high <= high) { + results.push(intervalToAdd); + current_low = parseFloat((current_low + perValue).toFixed(decimalPrecision)); + current_high = parseFloat((current_low + perValue - perUnitSize).toFixed(decimalPrecision)); + intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); } + return results; }; - return GeometricMean; -}(AggregateExpression)); -exports.GeometricMean = GeometricMean; -var PopulationStdDev = /** @class */ (function (_super) { - __extends(PopulationStdDev, _super); - function PopulationStdDev(json) { - var _this = _super.call(this, json) || this; - _this.type = 'population_deviation'; - return _this; - } - return PopulationStdDev; -}(StdDev)); -exports.PopulationStdDev = PopulationStdDev; -var Variance = /** @class */ (function (_super) { - __extends(Variance, _super); - function Variance(json) { - var _this = _super.call(this, json) || this; - _this.type = 'standard_variance'; - return _this; - } - return Variance; -}(StdDev)); -exports.Variance = Variance; -var PopulationVariance = /** @class */ (function (_super) { - __extends(PopulationVariance, _super); - function PopulationVariance(json) { - var _this = _super.call(this, json) || this; - _this.type = 'population_variance'; - return _this; - } - return PopulationVariance; -}(StdDev)); -exports.PopulationVariance = PopulationVariance; -var AllTrue = /** @class */ (function (_super) { - __extends(AllTrue, _super); - function AllTrue(json) { + return Expand; +}(expression_1.Expression)); +exports.Expand = Expand; +var Collapse = /** @class */ (function (_super) { + __extends(Collapse, _super); + function Collapse(json) { return _super.call(this, json) || this; } - AllTrue.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - return (0, util_1.allTrue)((0, util_1.removeNulls)(items)); + Collapse.prototype.exec = function (ctx) { + // collapse(argument List>, per Quantity) List> + var _a = this.execArgs(ctx), intervals = _a[0], perWidth = _a[1]; + return collapseIntervals(intervals, perWidth); }; - return AllTrue; -}(AggregateExpression)); -exports.AllTrue = AllTrue; -var AnyTrue = /** @class */ (function (_super) { - __extends(AnyTrue, _super); - function AnyTrue(json) { - return _super.call(this, json) || this; + return Collapse; +}(expression_1.Expression)); +exports.Collapse = Collapse; +function collapseIntervals(intervals, perWidth) { + // Clone intervals so this function remains idempotent + var intervalsClone = []; + for (var _i = 0, intervals_3 = intervals; _i < intervals_3.length; _i++) { + var interval = intervals_3[_i]; + // The spec says to ignore null intervals + if (interval != null) { + intervalsClone.push(interval.copy()); + } } - AnyTrue.prototype.exec = function (ctx) { - var items = this.source.execute(ctx); - return (0, util_1.anyTrue)(items); - }; - return AnyTrue; -}(AggregateExpression)); -exports.AnyTrue = AnyTrue; -function processQuantities(values) { - var items = (0, util_1.removeNulls)(values); - if (hasOnlyQuantities(items)) { - return convertAllUnits(items); + // If the list is null, return null + if (intervals == null) { + return null; } - else if (hasSomeQuantities(items)) { - throw new exception_1.Exception('Cannot perform aggregate operations on mixed values of Quantities and non Quantities'); + else if (intervalsClone.length <= 1) { + return intervalsClone; } else { - return items; + // If the per argument is null, the default unit interval for the point type + // of the intervals involved will be used (i.e. the interval that has a + // width equal to the result of the successor function for the point type). + if (perWidth == null) { + perWidth = intervalsClone[0].getPointSize(); + } + // sort intervalsClone by start + intervalsClone.sort(function (a, b) { + if (a.low && typeof a.low.before === 'function') { + if (b.low != null && a.low.before(b.low)) { + return -1; + } + if (b.low == null || a.low.after(b.low)) { + return 1; + } + } + else if (a.low != null && b.low != null) { + if (a.low < b.low) { + return -1; + } + if (a.low > b.low) { + return 1; + } + } + else if (a.low != null && b.low == null) { + return 1; + } + else if (a.low == null && b.low != null) { + return -1; + } + // if both lows are undefined, sort by high + if (a.high && typeof a.high.before === 'function') { + if (b.high == null || a.high.before(b.high)) { + return -1; + } + if (a.high.after(b.high)) { + return 1; + } + } + else if (a.high != null && b.high != null) { + if (a.high < b.high) { + return -1; + } + if (a.high > b.high) { + return 1; + } + } + else if (a.high != null && b.high == null) { + return -1; + } + else if (a.high == null && b.high != null) { + return 1; + } + return 0; + }); + // collapse intervals as necessary + var collapsedIntervals = []; + var a = intervalsClone.shift(); + var b = intervalsClone.shift(); + while (b) { + if (b.low && typeof b.low.durationBetween === 'function') { + // handle DateTimes using durationBetween + if (a.high != null ? a.high.sameOrAfter(b.low) : undefined) { + // overlap + if (b.high == null || b.high.after(a.high)) { + a.high = b.high; + } + } + else if ((a.high != null ? a.high.durationBetween(b.low, perWidth.unit).high : undefined) <= + perWidth.value) { + a.high = b.high; + } + else { + collapsedIntervals.push(a); + a = b; + } + } + else if (b.low && typeof b.low.sameOrBefore === 'function') { + if (a.high != null && b.low.sameOrBefore((0, quantity_1.doAddition)(a.high, perWidth))) { + if (b.high == null || b.high.after(a.high)) { + a.high = b.high; + } + } + else { + collapsedIntervals.push(a); + a = b; + } + } + else { + if (b.low - a.high <= perWidth.value) { + if (b.high > a.high || b.high == null) { + a.high = b.high; + } + } + else { + collapsedIntervals.push(a); + a = b; + } + } + b = intervalsClone.shift(); + } + collapsedIntervals.push(a); + return collapsedIntervals; } } -function getValuesFromQuantities(quantities) { - return quantities.map(function (quantity) { return quantity.value; }); -} -function hasOnlyQuantities(arr) { - return arr.every(function (x) { return x.isQuantity; }); -} -function hasSomeQuantities(arr) { - return arr.some(function (x) { return x.isQuantity; }); -} -function convertAllUnits(arr) { - // convert all quantities in array to match the unit of the first item - return arr.map(function (q) { return q.convertUnit(arr[0].unit); }); +function truncateDecimal(decimal, decimalPlaces) { + // like parseFloat().toFixed() but floor rather than round + // Needed for when per precision is less than the interval input precision + var re = new RegExp('^-?\\d+(?:.\\d{0,' + (decimalPlaces || -1) + '})?'); + return parseFloat(decimal.toString().match(re)[0]); } -function medianOfNumbers(numbers) { - var items = (0, util_1.numerical_sort)(numbers, 'asc'); - if (items.length % 2 === 1) { - // Odd number of items - return items[(items.length - 1) / 2]; - } - else { - // Even number of items - return (items[items.length / 2 - 1] + items[items.length / 2]) / 2; + +},{"../datatypes/interval":46,"../datatypes/quantity":48,"../util/math":90,"../util/units":91,"./builder":53,"./expression":59}],64:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Library = void 0; +var expressions_1 = require("./expressions"); +var Library = /** @class */ (function () { + function Library(json, libraryManager) { + this.source = json; + // usings + var usingDefs = (json.library.usings && json.library.usings.def) || []; + this.usings = usingDefs + .filter(function (u) { return u.localIdentifier !== 'System'; }) + .map(function (u) { + return { name: u.localIdentifier, version: u.version }; + }); + // parameters + var paramDefs = (json.library.parameters && json.library.parameters.def) || []; + this.parameters = {}; + for (var _i = 0, paramDefs_1 = paramDefs; _i < paramDefs_1.length; _i++) { + var param = paramDefs_1[_i]; + this.parameters[param.name] = new expressions_1.ParameterDef(param); + } + // code systems + var csDefs = (json.library.codeSystems && json.library.codeSystems.def) || []; + this.codesystems = {}; + for (var _a = 0, csDefs_1 = csDefs; _a < csDefs_1.length; _a++) { + var codesystem = csDefs_1[_a]; + this.codesystems[codesystem.name] = new expressions_1.CodeSystemDef(codesystem); + } + // value sets + var vsDefs = (json.library.valueSets && json.library.valueSets.def) || []; + this.valuesets = {}; + for (var _b = 0, vsDefs_1 = vsDefs; _b < vsDefs_1.length; _b++) { + var valueset = vsDefs_1[_b]; + this.valuesets[valueset.name] = new expressions_1.ValueSetDef(valueset); + } + // codes + var codeDefs = (json.library.codes && json.library.codes.def) || []; + this.codes = {}; + for (var _c = 0, codeDefs_1 = codeDefs; _c < codeDefs_1.length; _c++) { + var code = codeDefs_1[_c]; + this.codes[code.name] = new expressions_1.CodeDef(code); + } + // concepts + var conceptDefs = (json.library.concepts && json.library.concepts.def) || []; + this.concepts = {}; + for (var _d = 0, conceptDefs_1 = conceptDefs; _d < conceptDefs_1.length; _d++) { + var concept = conceptDefs_1[_d]; + this.concepts[concept.name] = new expressions_1.ConceptDef(concept); + } + // expressions + var exprDefs = (json.library.statements && json.library.statements.def) || []; + this.expressions = {}; + this.functions = {}; + for (var _e = 0, exprDefs_1 = exprDefs; _e < exprDefs_1.length; _e++) { + var expr = exprDefs_1[_e]; + if (expr.type === 'FunctionDef') { + if (!this.functions[expr.name]) { + this.functions[expr.name] = []; + } + this.functions[expr.name].push(new expressions_1.FunctionDef(expr)); + } + else { + this.expressions[expr.name] = new expressions_1.ExpressionDef(expr); + } + } + // includes + var inclDefs = (json.library.includes && json.library.includes.def) || []; + this.includes = {}; + for (var _f = 0, inclDefs_1 = inclDefs; _f < inclDefs_1.length; _f++) { + var incl = inclDefs_1[_f]; + if (libraryManager) { + this.includes[incl.localIdentifier] = libraryManager.resolve(incl.path, incl.version); + } + } + // Include codesystems from includes + for (var iProperty in this.includes) { + if (this.includes[iProperty] && this.includes[iProperty].codesystems) { + for (var csProperty in this.includes[iProperty].codesystems) { + this.codesystems[csProperty] = this.includes[iProperty].codesystems[csProperty]; + } + } + } } -} + Library.prototype.getFunction = function (identifier) { + return this.functions[identifier]; + }; + Library.prototype.get = function (identifier) { + return (this.expressions[identifier] || this.includes[identifier] || this.getFunction(identifier)); + }; + Library.prototype.getValueSet = function (identifier, libraryName) { + if (this.valuesets[identifier] != null) { + return this.valuesets[identifier]; + } + return this.includes[libraryName] != null + ? this.includes[libraryName].valuesets[identifier] + : undefined; + }; + Library.prototype.getCodeSystem = function (identifier) { + return this.codesystems[identifier]; + }; + Library.prototype.getCode = function (identifier) { + return this.codes[identifier]; + }; + Library.prototype.getConcept = function (identifier) { + return this.concepts[identifier]; + }; + Library.prototype.getParameter = function (name) { + return this.parameters[name]; + }; + return Library; +}()); +exports.Library = Library; -},{"../datatypes/datatypes":57,"../datatypes/exception":59,"../util/comparison":103,"../util/util":106,"./builder":67,"./expression":73}],66:[function(require,module,exports){ +},{"./expressions":60}],65:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -25960,586 +23515,317 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Predecessor = exports.Successor = exports.MaxValue = exports.MinValue = exports.Power = exports.Log = exports.Exp = exports.Ln = exports.Round = exports.Negate = exports.Abs = exports.Truncate = exports.Floor = exports.Ceiling = exports.Modulo = exports.TruncatedDivide = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = void 0; +exports.Slice = exports.Last = exports.First = exports.Current = exports.Distinct = exports.Flatten = exports.ForEach = exports.doProperIncludes = exports.doIncludes = exports.doContains = exports.IndexOf = exports.ToList = exports.SingletonFrom = exports.Filter = exports.Times = exports.doIntersect = exports.doExcept = exports.doUnion = exports.Exists = exports.List = void 0; var expression_1 = require("./expression"); -var MathUtil = __importStar(require("../util/math")); -var quantity_1 = require("../datatypes/quantity"); -var uncertainty_1 = require("../datatypes/uncertainty"); var builder_1 = require("./builder"); -var Add = /** @class */ (function (_super) { - __extends(Add, _super); - function Add(json) { - return _super.call(this, json) || this; - } - Add.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var sum = args.reduce(function (x, y) { - if (x.isUncertainty && !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y, y); - } - else if (y.isUncertainty && !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x, x); - } - if (x.isQuantity || x.isDateTime || x.isDate || (x.isTime && x.isTime())) { - return (0, quantity_1.doAddition)(x, y); - } - else if (x.isUncertainty && y.isUncertainty) { - if (x.low.isQuantity || - x.low.isDateTime || - x.low.isDate || - (x.low.isTime && x.low.isTime())) { - return new uncertainty_1.Uncertainty((0, quantity_1.doAddition)(x.low, y.low), (0, quantity_1.doAddition)(x.high, y.high)); - } - else { - return new uncertainty_1.Uncertainty(x.low + y.low, x.high + y.high); - } - } - else { - return x + y; - } - }); - if (MathUtil.overflowsOrUnderflows(sum)) { - return null; - } - return sum; - }; - return Add; -}(expression_1.Expression)); -exports.Add = Add; -var Subtract = /** @class */ (function (_super) { - __extends(Subtract, _super); - function Subtract(json) { - return _super.call(this, json) || this; - } - Subtract.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var difference = args.reduce(function (x, y) { - if (x.isUncertainty && !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y, y); - } - else if (y.isUncertainty && !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x, x); - } - if (x.isQuantity || x.isDateTime || x.isDate) { - return (0, quantity_1.doSubtraction)(x, y); - } - else if (x.isUncertainty && y.isUncertainty) { - if (x.low.isQuantity || x.low.isDateTime || x.low.isDate) { - return new uncertainty_1.Uncertainty((0, quantity_1.doSubtraction)(x.low, y.high), (0, quantity_1.doSubtraction)(x.high, y.low)); - } - else { - return new uncertainty_1.Uncertainty(x.low - y.high, x.high - y.low); - } - } - else { - return x - y; - } - }); - if (MathUtil.overflowsOrUnderflows(difference)) { - return null; - } - return difference; - }; - return Subtract; -}(expression_1.Expression)); -exports.Subtract = Subtract; -var Multiply = /** @class */ (function (_super) { - __extends(Multiply, _super); - function Multiply(json) { - return _super.call(this, json) || this; +var util_1 = require("../util/util"); +var comparison_1 = require("../util/comparison"); +var List = /** @class */ (function (_super) { + __extends(List, _super); + function List(json) { + var _this = _super.call(this, json) || this; + _this.elements = (0, builder_1.build)(json.element) || []; + return _this; } - Multiply.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var product = args.reduce(function (x, y) { - if (x.isUncertainty && !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y, y); - } - else if (y.isUncertainty && !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x, x); - } - if (x.isQuantity || y.isQuantity) { - return (0, quantity_1.doMultiplication)(x, y); - } - else if (x.isUncertainty && y.isUncertainty) { - if (x.low.isQuantity) { - return new uncertainty_1.Uncertainty((0, quantity_1.doMultiplication)(x.low, y.low), (0, quantity_1.doMultiplication)(x.high, y.high)); - } - else { - return new uncertainty_1.Uncertainty(x.low * y.low, x.high * y.high); - } - } - else { - return x * y; - } - }); - if (MathUtil.overflowsOrUnderflows(product)) { - return null; - } - return product; + Object.defineProperty(List.prototype, "isList", { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + List.prototype.exec = function (ctx) { + return this.elements.map(function (item) { return item.execute(ctx); }); }; - return Multiply; + return List; }(expression_1.Expression)); -exports.Multiply = Multiply; -var Divide = /** @class */ (function (_super) { - __extends(Divide, _super); - function Divide(json) { +exports.List = List; +var Exists = /** @class */ (function (_super) { + __extends(Exists, _super); + function Exists(json) { return _super.call(this, json) || this; } - Divide.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var quotient = args.reduce(function (x, y) { - if (x.isUncertainty && !y.isUncertainty) { - y = new uncertainty_1.Uncertainty(y, y); - } - else if (y.isUncertainty && !x.isUncertainty) { - x = new uncertainty_1.Uncertainty(x, x); - } - if (x.isQuantity) { - return (0, quantity_1.doDivision)(x, y); - } - else if (x.isUncertainty && y.isUncertainty) { - if (x.low.isQuantity) { - return new uncertainty_1.Uncertainty((0, quantity_1.doDivision)(x.low, y.high), (0, quantity_1.doDivision)(x.high, y.low)); - } - else { - return new uncertainty_1.Uncertainty(x.low / y.high, x.high / y.low); - } - } - else { - return x / y; - } - }); - // Note, anything divided by 0 is Infinity in Javascript, which will be - // considered as overflow by this check. - if (MathUtil.overflowsOrUnderflows(quotient)) { - return null; + Exists.prototype.exec = function (ctx) { + var list = this.execArgs(ctx); + // if list exists and has non empty length we need to make sure it isnt just full of nulls + if (list) { + return list.some(function (item) { return item != null; }); } - return quotient; + return false; }; - return Divide; + return Exists; }(expression_1.Expression)); -exports.Divide = Divide; -var TruncatedDivide = /** @class */ (function (_super) { - __extends(TruncatedDivide, _super); - function TruncatedDivide(json) { - return _super.call(this, json) || this; +exports.Exists = Exists; +// Equal is completely handled by overloaded#Equal +// NotEqual is completely handled by overloaded#Equal +// Delegated to by overloaded#Union +function doUnion(a, b) { + var distinct = doDistinct(a.concat(b)); + return removeDuplicateNulls(distinct); +} +exports.doUnion = doUnion; +// Delegated to by overloaded#Except +function doExcept(a, b) { + var distinct = doDistinct(a); + var setList = removeDuplicateNulls(distinct); + return setList.filter(function (item) { return !doContains(b, item, true); }); +} +exports.doExcept = doExcept; +// Delegated to by overloaded#Intersect +function doIntersect(a, b) { + var distinct = doDistinct(a); + var setList = removeDuplicateNulls(distinct); + return setList.filter(function (item) { return doContains(b, item, true); }); +} +exports.doIntersect = doIntersect; +// ELM-only, not a product of CQL +var Times = /** @class */ (function (_super) { + __extends(Times, _super); + function Times() { + return _super !== null && _super.apply(this, arguments) || this; } - TruncatedDivide.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var quotient = args.reduce(function (x, y) { return x / y; }); - var truncatedQuotient = quotient >= 0 ? Math.floor(quotient) : Math.ceil(quotient); - if (MathUtil.overflowsOrUnderflows(truncatedQuotient)) { - return null; - } - return truncatedQuotient; - }; - return TruncatedDivide; -}(expression_1.Expression)); -exports.TruncatedDivide = TruncatedDivide; -var Modulo = /** @class */ (function (_super) { - __extends(Modulo, _super); - function Modulo(json) { - return _super.call(this, json) || this; + return Times; +}(expression_1.UnimplementedExpression)); +exports.Times = Times; +// ELM-only, not a product of CQL +var Filter = /** @class */ (function (_super) { + __extends(Filter, _super); + function Filter() { + return _super !== null && _super.apply(this, arguments) || this; } - Modulo.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var modulo = args.reduce(function (x, y) { return x % y; }); - return MathUtil.decimalOrNull(modulo); - }; - return Modulo; -}(expression_1.Expression)); -exports.Modulo = Modulo; -var Ceiling = /** @class */ (function (_super) { - __extends(Ceiling, _super); - function Ceiling(json) { + return Filter; +}(expression_1.UnimplementedExpression)); +exports.Filter = Filter; +var SingletonFrom = /** @class */ (function (_super) { + __extends(SingletonFrom, _super); + function SingletonFrom(json) { return _super.call(this, json) || this; } - Ceiling.prototype.exec = function (ctx) { + SingletonFrom.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); - if (arg == null) { - return null; + if (arg != null && arg.length > 1) { + throw new Error("IllegalArgument: 'SingletonFrom' requires a 0 or 1 arg array"); } - return Math.ceil(arg); - }; - return Ceiling; -}(expression_1.Expression)); -exports.Ceiling = Ceiling; -var Floor = /** @class */ (function (_super) { - __extends(Floor, _super); - function Floor(json) { - return _super.call(this, json) || this; - } - Floor.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; + else if (arg != null && arg.length === 1) { + return arg[0]; } - return Math.floor(arg); - }; - return Floor; -}(expression_1.Expression)); -exports.Floor = Floor; -var Truncate = /** @class */ (function (_super) { - __extends(Truncate, _super); - function Truncate(json) { - return _super.call(this, json) || this; - } - Truncate.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { + else { return null; } - return arg >= 0 ? Math.floor(arg) : Math.ceil(arg); }; - return Truncate; + return SingletonFrom; }(expression_1.Expression)); -exports.Truncate = Truncate; -var Abs = /** @class */ (function (_super) { - __extends(Abs, _super); - function Abs(json) { +exports.SingletonFrom = SingletonFrom; +var ToList = /** @class */ (function (_super) { + __extends(ToList, _super); + function ToList(json) { return _super.call(this, json) || this; } - Abs.prototype.exec = function (ctx) { + ToList.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - else if (arg.isQuantity) { - return new quantity_1.Quantity(Math.abs(arg.value), arg.unit); + if (arg != null) { + return [arg]; } else { - return Math.abs(arg); + return []; } }; - return Abs; + return ToList; }(expression_1.Expression)); -exports.Abs = Abs; -var Negate = /** @class */ (function (_super) { - __extends(Negate, _super); - function Negate(json) { - return _super.call(this, json) || this; +exports.ToList = ToList; +var IndexOf = /** @class */ (function (_super) { + __extends(IndexOf, _super); + function IndexOf(json) { + var _this = _super.call(this, json) || this; + _this.source = (0, builder_1.build)(json.source); + _this.element = (0, builder_1.build)(json.element); + return _this; } - Negate.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { + IndexOf.prototype.exec = function (ctx) { + var index; + var src = this.source.execute(ctx); + var el = this.element.execute(ctx); + if (src == null || el == null) { return null; } - else if (arg.isQuantity) { - return new quantity_1.Quantity(arg.value * -1, arg.unit); + for (var i = 0; i < src.length; i++) { + var itm = src[i]; + if ((0, comparison_1.equals)(itm, el)) { + index = i; + break; + } } - else { - return arg * -1; + if (index != null) { + return index; } - }; - return Negate; -}(expression_1.Expression)); -exports.Negate = Negate; -var Round = /** @class */ (function (_super) { - __extends(Round, _super); - function Round(json) { - var _this = _super.call(this, json) || this; - _this.precision = (0, builder_1.build)(json.precision); - return _this; - } - Round.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; + else { + return -1; } - var dec = this.precision != null ? this.precision.execute(ctx) : 0; - return Math.round(arg * Math.pow(10, dec)) / Math.pow(10, dec); }; - return Round; + return IndexOf; }(expression_1.Expression)); -exports.Round = Round; -var Ln = /** @class */ (function (_super) { - __extends(Ln, _super); - function Ln(json) { - return _super.call(this, json) || this; +exports.IndexOf = IndexOf; +// Indexer is completely handled by overloaded#Indexer +// Delegated to by overloaded#Contains and overloaded#In +function doContains(container, item, nullEquivalence) { + if (nullEquivalence === void 0) { nullEquivalence = false; } + return container.some(function (element) { return (0, comparison_1.equals)(element, item) || (nullEquivalence && element == null && item == null); }); +} +exports.doContains = doContains; +// Delegated to by overloaded#Includes and overloaded@IncludedIn +function doIncludes(list, sublist) { + return sublist.every(function (x) { return doContains(list, x); }); +} +exports.doIncludes = doIncludes; +// Delegated to by overloaded#ProperIncludes and overloaded@ProperIncludedIn +function doProperIncludes(list, sublist) { + return list.length > sublist.length && doIncludes(list, sublist); +} +exports.doProperIncludes = doProperIncludes; +// ELM-only, not a product of CQL +var ForEach = /** @class */ (function (_super) { + __extends(ForEach, _super); + function ForEach() { + return _super !== null && _super.apply(this, arguments) || this; } - Ln.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - var ln = Math.log(arg); - return MathUtil.decimalOrNull(ln); - }; - return Ln; -}(expression_1.Expression)); -exports.Ln = Ln; -var Exp = /** @class */ (function (_super) { - __extends(Exp, _super); - function Exp(json) { + return ForEach; +}(expression_1.UnimplementedExpression)); +exports.ForEach = ForEach; +var Flatten = /** @class */ (function (_super) { + __extends(Flatten, _super); + function Flatten(json) { return _super.call(this, json) || this; } - Exp.prototype.exec = function (ctx) { + Flatten.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - var power = Math.exp(arg); - if (MathUtil.overflowsOrUnderflows(power)) { - return null; + if ((0, util_1.typeIsArray)(arg) && arg.every(function (x) { return (0, util_1.typeIsArray)(x); })) { + return arg.reduce(function (x, y) { return x.concat(y); }, []); } - return power; - }; - return Exp; -}(expression_1.Expression)); -exports.Exp = Exp; -var Log = /** @class */ (function (_super) { - __extends(Log, _super); - function Log(json) { - return _super.call(this, json) || this; - } - Log.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; + else { + return arg; } - var log = args.reduce(function (x, y) { return Math.log(x) / Math.log(y); }); - return MathUtil.decimalOrNull(log); - }; - return Log; -}(expression_1.Expression)); -exports.Log = Log; -var Power = /** @class */ (function (_super) { - __extends(Power, _super); - function Power(json) { + }; + return Flatten; +}(expression_1.Expression)); +exports.Flatten = Flatten; +var Distinct = /** @class */ (function (_super) { + __extends(Distinct, _super); + function Distinct(json) { return _super.call(this, json) || this; } - Power.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args == null || args.some(function (x) { return x == null; })) { - return null; - } - var power = args.reduce(function (x, y) { return Math.pow(x, y); }); - if (MathUtil.overflowsOrUnderflows(power)) { + Distinct.prototype.exec = function (ctx) { + var result = this.execArgs(ctx); + if (result == null) { return null; } - return power; + return doDistinct(result); }; - return Power; + return Distinct; }(expression_1.Expression)); -exports.Power = Power; -var MinValue = /** @class */ (function (_super) { - __extends(MinValue, _super); - function MinValue(json) { +exports.Distinct = Distinct; +function doDistinct(list) { + var distinct = []; + list.forEach(function (item) { + var isNew = distinct.every(function (seenItem) { return !(0, comparison_1.equals)(item, seenItem); }); + if (isNew) { + distinct.push(item); + } + }); + return removeDuplicateNulls(distinct); +} +function removeDuplicateNulls(list) { + // Remove duplicate null elements + var firstNullFound = false; + var setList = []; + for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { + var item = list_1[_i]; + if (item !== null) { + setList.push(item); + } + else if (item === null && !firstNullFound) { + setList.push(item); + firstNullFound = true; + } + } + return setList; +} +// ELM-only, not a product of CQL +var Current = /** @class */ (function (_super) { + __extends(Current, _super); + function Current() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Current; +}(expression_1.UnimplementedExpression)); +exports.Current = Current; +var First = /** @class */ (function (_super) { + __extends(First, _super); + function First(json) { var _this = _super.call(this, json) || this; - _this.valueType = json.valueType; + _this.source = (0, builder_1.build)(json.source); return _this; } - MinValue.prototype.exec = function (ctx) { - if (MinValue.MIN_VALUES[this.valueType]) { - if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') { - var minDateTime = MinValue.MIN_VALUES[this.valueType].copy(); - minDateTime.timezoneOffset = ctx.getTimezoneOffset(); - return minDateTime; - } - else { - return MinValue.MIN_VALUES[this.valueType]; - } + First.prototype.exec = function (ctx) { + var src = this.source.exec(ctx); + if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) { + return src[0]; } else { - throw new Error("Minimum not supported for ".concat(this.valueType)); + return null; } }; - MinValue.MIN_VALUES = { - '{urn:hl7-org:elm-types:r1}Integer': MathUtil.MIN_INT_VALUE, - '{urn:hl7-org:elm-types:r1}Decimal': MathUtil.MIN_FLOAT_VALUE, - '{urn:hl7-org:elm-types:r1}DateTime': MathUtil.MIN_DATETIME_VALUE, - '{urn:hl7-org:elm-types:r1}Date': MathUtil.MIN_DATE_VALUE, - '{urn:hl7-org:elm-types:r1}Time': MathUtil.MIN_TIME_VALUE - }; - return MinValue; + return First; }(expression_1.Expression)); -exports.MinValue = MinValue; -var MaxValue = /** @class */ (function (_super) { - __extends(MaxValue, _super); - function MaxValue(json) { +exports.First = First; +var Last = /** @class */ (function (_super) { + __extends(Last, _super); + function Last(json) { var _this = _super.call(this, json) || this; - _this.valueType = json.valueType; + _this.source = (0, builder_1.build)(json.source); return _this; } - MaxValue.prototype.exec = function (ctx) { - if (MaxValue.MAX_VALUES[this.valueType] != null) { - if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') { - var maxDateTime = MaxValue.MAX_VALUES[this.valueType].copy(); - maxDateTime.timezoneOffset = ctx.getTimezoneOffset(); - return maxDateTime; - } - else { - return MaxValue.MAX_VALUES[this.valueType]; - } + Last.prototype.exec = function (ctx) { + var src = this.source.exec(ctx); + if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) { + return src[src.length - 1]; } else { - throw new Error("Maximum not supported for ".concat(this.valueType)); - } - }; - MaxValue.MAX_VALUES = { - '{urn:hl7-org:elm-types:r1}Integer': MathUtil.MAX_INT_VALUE, - '{urn:hl7-org:elm-types:r1}Decimal': MathUtil.MAX_FLOAT_VALUE, - '{urn:hl7-org:elm-types:r1}DateTime': MathUtil.MAX_DATETIME_VALUE, - '{urn:hl7-org:elm-types:r1}Date': MathUtil.MAX_DATE_VALUE, - '{urn:hl7-org:elm-types:r1}Time': MathUtil.MAX_TIME_VALUE - }; - return MaxValue; -}(expression_1.Expression)); -exports.MaxValue = MaxValue; -var Successor = /** @class */ (function (_super) { - __extends(Successor, _super); - function Successor(json) { - return _super.call(this, json) || this; - } - Successor.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - var successor = null; - try { - // MathUtil.successor throws on overflow, and the exception is used in - // the logic for evaluating `meets`, so it can't be changed to just return null - successor = MathUtil.successor(arg); - } - catch (e) { - if (e instanceof MathUtil.OverFlowException) { - return null; - } - } - if (MathUtil.overflowsOrUnderflows(successor)) { return null; } - return successor; }; - return Successor; + return Last; }(expression_1.Expression)); -exports.Successor = Successor; -var Predecessor = /** @class */ (function (_super) { - __extends(Predecessor, _super); - function Predecessor(json) { - return _super.call(this, json) || this; +exports.Last = Last; +var Slice = /** @class */ (function (_super) { + __extends(Slice, _super); + function Slice(json) { + var _this = _super.call(this, json) || this; + _this.source = (0, builder_1.build)(json.source); + _this.startIndex = (0, builder_1.build)(json.startIndex); + _this.endIndex = (0, builder_1.build)(json.endIndex); + return _this; } - Predecessor.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - var predecessor = null; - try { - // MathUtil.predecessor throws on underflow, and the exception is used in - // the logic for evaluating `meets`, so it can't be changed to just return null - predecessor = MathUtil.predecessor(arg); - } - catch (e) { - if (e instanceof MathUtil.OverFlowException) { - return null; + Slice.prototype.exec = function (ctx) { + var src = this.source.exec(ctx); + if (src != null && (0, util_1.typeIsArray)(src)) { + var startIndex = this.startIndex.exec(ctx); + var endIndex = this.endIndex.exec(ctx); + var start = startIndex != null ? startIndex : 0; + var end = endIndex != null ? endIndex : src.length; + if (src.length === 0 || start < 0 || end < 0 || end < start) { + return []; } + return src.slice(start, end); } - if (MathUtil.overflowsOrUnderflows(predecessor)) { - return null; - } - return predecessor; + return null; }; - return Predecessor; + return Slice; }(expression_1.Expression)); -exports.Predecessor = Predecessor; - -},{"../datatypes/quantity":62,"../datatypes/uncertainty":64,"../util/math":104,"./builder":67,"./expression":73}],67:[function(require,module,exports){ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.build = void 0; -/* eslint-disable @typescript-eslint/ban-ts-comment */ -var E = __importStar(require("./expressions")); -var util_1 = require("../util/util"); -function build(json) { - if (json == null) { - return json; - } - if ((0, util_1.typeIsArray)(json)) { - return json.map(function (child) { return build(child); }); - } - if (json.type === 'FunctionRef') { - return new E.FunctionRef(json); - } - else if (json.type === 'Literal') { - return E.Literal.from(json); - } - else if (functionExists(json.type)) { - return constructByName(json.type, json); - } - else { - return null; - } -} -exports.build = build; -function functionExists(name) { - // @ts-ignore - return typeof E[name] === 'function'; -} -function constructByName(name, json) { - // @ts-ignore - return new E[name](json); -} +exports.Slice = Slice; +// Length is completely handled by overloaded#Length -},{"../util/util":106,"./expressions":74}],68:[function(require,module,exports){ +},{"../util/comparison":89,"../util/util":92,"./builder":53,"./expression":59}],66:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -26556,177 +23842,46 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.CalculateAgeAt = exports.CalculateAge = exports.Concept = exports.ConceptRef = exports.ConceptDef = exports.Code = exports.CodeRef = exports.CodeDef = exports.CodeSystemDef = exports.InValueSet = exports.AnyInValueSet = exports.ValueSetRef = exports.ValueSetDef = void 0; +exports.StringLiteral = exports.DecimalLiteral = exports.IntegerLiteral = exports.BooleanLiteral = exports.Literal = void 0; var expression_1 = require("./expression"); -var dt = __importStar(require("../datatypes/datatypes")); -var builder_1 = require("./builder"); -var ValueSetDef = /** @class */ (function (_super) { - __extends(ValueSetDef, _super); - function ValueSetDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.id = json.id; - _this.version = json.version; - return _this; - } - //todo: code systems and versions - ValueSetDef.prototype.exec = function (ctx) { - var valueset = ctx.codeService.findValueSet(this.id, this.version) || new dt.ValueSet(this.id, this.version); - ctx.rootContext().set(this.name, valueset); - return valueset; - }; - return ValueSetDef; -}(expression_1.Expression)); -exports.ValueSetDef = ValueSetDef; -var ValueSetRef = /** @class */ (function (_super) { - __extends(ValueSetRef, _super); - function ValueSetRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.libraryName = json.libraryName; - return _this; - } - ValueSetRef.prototype.exec = function (ctx) { - // TODO: This calls the code service every time-- should be optimized - var valueset = ctx.getValueSet(this.name, this.libraryName); - if (valueset instanceof expression_1.Expression) { - valueset = valueset.execute(ctx); - } - return valueset; - }; - return ValueSetRef; -}(expression_1.Expression)); -exports.ValueSetRef = ValueSetRef; -var AnyInValueSet = /** @class */ (function (_super) { - __extends(AnyInValueSet, _super); - function AnyInValueSet(json) { - var _this = _super.call(this, json) || this; - _this.codes = (0, builder_1.build)(json.codes); - _this.valueset = new ValueSetRef(json.valueset); - return _this; - } - AnyInValueSet.prototype.exec = function (ctx) { - var valueset = this.valueset.execute(ctx); - // If the value set reference cannot be resolved, a run-time error is thrown. - if (valueset == null || !valueset.isValueSet) { - throw new Error('ValueSet must be provided to InValueSet function'); - } - var codes = this.codes.exec(ctx); - return codes != null && codes.some(function (code) { return valueset.hasMatch(code); }); - }; - return AnyInValueSet; -}(expression_1.Expression)); -exports.AnyInValueSet = AnyInValueSet; -var InValueSet = /** @class */ (function (_super) { - __extends(InValueSet, _super); - function InValueSet(json) { +var Literal = /** @class */ (function (_super) { + __extends(Literal, _super); + function Literal(json) { var _this = _super.call(this, json) || this; - _this.code = (0, builder_1.build)(json.code); - _this.valueset = new ValueSetRef(json.valueset); + _this.valueType = json.valueType; + _this.value = json.value; return _this; } - InValueSet.prototype.exec = function (ctx) { - // If the code argument is null, the result is false - if (this.code == null) { - return false; - } - if (this.valueset == null) { - throw new Error('ValueSet must be provided to InValueSet function'); - } - var code = this.code.execute(ctx); - // spec indicates to return false if code is null, throw error if value set cannot be resolved - if (code == null) { - return false; - } - var valueset = this.valueset.execute(ctx); - if (valueset == null || !valueset.isValueSet) { - throw new Error('ValueSet must be provided to InValueSet function'); + Literal.from = function (json) { + switch (json.valueType) { + case '{urn:hl7-org:elm-types:r1}Boolean': + return new BooleanLiteral(json); + case '{urn:hl7-org:elm-types:r1}Integer': + return new IntegerLiteral(json); + case '{urn:hl7-org:elm-types:r1}Decimal': + return new DecimalLiteral(json); + case '{urn:hl7-org:elm-types:r1}String': + return new StringLiteral(json); + default: + return new Literal(json); } - // If there is a code and valueset return whether or not the valueset has the code - return valueset.hasMatch(code); - }; - return InValueSet; -}(expression_1.Expression)); -exports.InValueSet = InValueSet; -var CodeSystemDef = /** @class */ (function (_super) { - __extends(CodeSystemDef, _super); - function CodeSystemDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.id = json.id; - _this.version = json.version; - return _this; - } - CodeSystemDef.prototype.exec = function (_ctx) { - return new dt.CodeSystem(this.id, this.version); - }; - return CodeSystemDef; -}(expression_1.Expression)); -exports.CodeSystemDef = CodeSystemDef; -var CodeDef = /** @class */ (function (_super) { - __extends(CodeDef, _super); - function CodeDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.id = json.id; - _this.systemName = json.codeSystem.name; - _this.display = json.display; - return _this; - } - CodeDef.prototype.exec = function (ctx) { - var system = ctx.getCodeSystem(this.systemName).execute(ctx); - return new dt.Code(this.id, system.id, system.version, this.display); }; - return CodeDef; -}(expression_1.Expression)); -exports.CodeDef = CodeDef; -var CodeRef = /** @class */ (function (_super) { - __extends(CodeRef, _super); - function CodeRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.library = json.libraryName; - return _this; - } - CodeRef.prototype.exec = function (ctx) { - ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; - var codeDef = ctx.getCode(this.name); - return codeDef ? codeDef.execute(ctx) : undefined; + Literal.prototype.exec = function (_ctx) { + return this.value; }; - return CodeRef; + return Literal; }(expression_1.Expression)); -exports.CodeRef = CodeRef; -var Code = /** @class */ (function (_super) { - __extends(Code, _super); - function Code(json) { +exports.Literal = Literal; +// The following are not defined in ELM, but helpful for execution +var BooleanLiteral = /** @class */ (function (_super) { + __extends(BooleanLiteral, _super); + function BooleanLiteral(json) { var _this = _super.call(this, json) || this; - _this.code = json.code; - _this.systemName = json.system.name; - _this.version = json.version; - _this.display = json.display; + _this.value = _this.value === 'true'; return _this; } - Object.defineProperty(Code.prototype, "isCode", { + Object.defineProperty(BooleanLiteral.prototype, "isBooleanLiteral", { // Define a simple getter to allow type-checking of this class without instanceof // and in a way that survives minification (as opposed to checking constructor.name) get: function () { @@ -26735,55 +23890,42 @@ var Code = /** @class */ (function (_super) { enumerable: false, configurable: true }); - Code.prototype.exec = function (ctx) { - var system = ctx.getCodeSystem(this.systemName) || {}; - return new dt.Code(this.code, system.id, this.version, this.display); - }; - return Code; -}(expression_1.Expression)); -exports.Code = Code; -var ConceptDef = /** @class */ (function (_super) { - __extends(ConceptDef, _super); - function ConceptDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.display = json.display; - _this.codes = json.code; - return _this; - } - ConceptDef.prototype.exec = function (ctx) { - var codes = this.codes.map(function (code) { - var codeDef = ctx.getCode(code.name); - return codeDef ? codeDef.execute(ctx) : undefined; - }); - return new dt.Concept(codes, this.display); + BooleanLiteral.prototype.exec = function (_ctx) { + return this.value; }; - return ConceptDef; -}(expression_1.Expression)); -exports.ConceptDef = ConceptDef; -var ConceptRef = /** @class */ (function (_super) { - __extends(ConceptRef, _super); - function ConceptRef(json) { + return BooleanLiteral; +}(Literal)); +exports.BooleanLiteral = BooleanLiteral; +var IntegerLiteral = /** @class */ (function (_super) { + __extends(IntegerLiteral, _super); + function IntegerLiteral(json) { var _this = _super.call(this, json) || this; - _this.name = json.name; + _this.value = parseInt(_this.value, 10); return _this; } - ConceptRef.prototype.exec = function (ctx) { - var conceptDef = ctx.getConcept(this.name); - return conceptDef ? conceptDef.execute(ctx) : undefined; + Object.defineProperty(IntegerLiteral.prototype, "isIntegerLiteral", { + // Define a simple getter to allow type-checking of this class without instanceof + // and in a way that survives minification (as opposed to checking constructor.name) + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + IntegerLiteral.prototype.exec = function (_ctx) { + return this.value; }; - return ConceptRef; -}(expression_1.Expression)); -exports.ConceptRef = ConceptRef; -var Concept = /** @class */ (function (_super) { - __extends(Concept, _super); - function Concept(json) { + return IntegerLiteral; +}(Literal)); +exports.IntegerLiteral = IntegerLiteral; +var DecimalLiteral = /** @class */ (function (_super) { + __extends(DecimalLiteral, _super); + function DecimalLiteral(json) { var _this = _super.call(this, json) || this; - _this.codes = json.code; - _this.display = json.display; + _this.value = parseFloat(_this.value); return _this; } - Object.defineProperty(Concept.prototype, "isConcept", { + Object.defineProperty(DecimalLiteral.prototype, "isDecimalLiteral", { // Define a simple getter to allow type-checking of this class without instanceof // and in a way that survives minification (as opposed to checking constructor.name) get: function () { @@ -26792,69 +23934,35 @@ var Concept = /** @class */ (function (_super) { enumerable: false, configurable: true }); - Concept.prototype.toCode = function (ctx, code) { - var system = ctx.getCodeSystem(code.system.name) || {}; - return new dt.Code(code.code, system.id, code.version, code.display); - }; - Concept.prototype.exec = function (ctx) { - var _this = this; - var codes = this.codes.map(function (code) { return _this.toCode(ctx, code); }); - return new dt.Concept(codes, this.display); - }; - return Concept; -}(expression_1.Expression)); -exports.Concept = Concept; -var CalculateAge = /** @class */ (function (_super) { - __extends(CalculateAge, _super); - function CalculateAge(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision; - return _this; - } - CalculateAge.prototype.exec = function (ctx) { - var date1 = this.execArgs(ctx); - var date2 = dt.DateTime.fromJSDate(ctx.getExecutionDateTime()); - var result = date1 != null ? date1.durationBetween(date2, this.precision.toLowerCase()) : undefined; - if (result != null && result.isPoint()) { - return result.low; - } - else { - return result; - } + DecimalLiteral.prototype.exec = function (_ctx) { + return this.value; }; - return CalculateAge; -}(expression_1.Expression)); -exports.CalculateAge = CalculateAge; -var CalculateAgeAt = /** @class */ (function (_super) { - __extends(CalculateAgeAt, _super); - function CalculateAgeAt(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision; - return _this; + return DecimalLiteral; +}(Literal)); +exports.DecimalLiteral = DecimalLiteral; +var StringLiteral = /** @class */ (function (_super) { + __extends(StringLiteral, _super); + function StringLiteral(json) { + return _super.call(this, json) || this; } - CalculateAgeAt.prototype.exec = function (ctx) { - // eslint-disable-next-line prefer-const - var _a = this.execArgs(ctx), date1 = _a[0], date2 = _a[1]; - if (date1 != null && date2 != null) { - // date1 is the birthdate, convert it to date if date2 is a date (to support ignoring time) - if (date2.isDate && date1.isDateTime) { - date1 = date1.getDate(); - } - var result = date1.durationBetween(date2, this.precision.toLowerCase()); - if (result != null && result.isPoint()) { - return result.low; - } - else { - return result; - } - } - return null; + Object.defineProperty(StringLiteral.prototype, "isStringLiteral", { + // Define a simple getter to allow type-checking of this class without instanceof + // and in a way that survives minification (as opposed to checking constructor.name) + get: function () { + return true; + }, + enumerable: false, + configurable: true + }); + StringLiteral.prototype.exec = function (_ctx) { + // TODO: Remove these replacements when CQL-to-ELM fixes bug: https://github.com/cqframework/clinical_quality_language/issues/82 + return this.value.replace(/\\'/g, "'").replace(/\\"/g, '"'); }; - return CalculateAgeAt; -}(expression_1.Expression)); -exports.CalculateAgeAt = CalculateAgeAt; + return StringLiteral; +}(Literal)); +exports.StringLiteral = StringLiteral; -},{"../datatypes/datatypes":57,"./builder":67,"./expression":73}],69:[function(require,module,exports){ +},{"./expression":59}],67:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -26872,73 +23980,77 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.GreaterOrEqual = exports.Greater = exports.LessOrEqual = exports.Less = void 0; +exports.IsFalse = exports.IsTrue = exports.Xor = exports.Not = exports.Or = exports.And = void 0; var expression_1 = require("./expression"); var datatypes_1 = require("../datatypes/datatypes"); -// Equal is completely handled by overloaded#Equal -// NotEqual is completely handled by overloaded#Equal -var Less = /** @class */ (function (_super) { - __extends(Less, _super); - function Less(json) { +var And = /** @class */ (function (_super) { + __extends(And, _super); + function And(json) { return _super.call(this, json) || this; } - Less.prototype.exec = function (ctx) { - var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); - if (args[0] == null || args[1] == null) { - return null; - } - return args[0].lessThan(args[1]); + And.prototype.exec = function (ctx) { + return datatypes_1.ThreeValuedLogic.and.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); }; - return Less; + return And; }(expression_1.Expression)); -exports.Less = Less; -var LessOrEqual = /** @class */ (function (_super) { - __extends(LessOrEqual, _super); - function LessOrEqual(json) { +exports.And = And; +var Or = /** @class */ (function (_super) { + __extends(Or, _super); + function Or(json) { return _super.call(this, json) || this; } - LessOrEqual.prototype.exec = function (ctx) { - var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); - if (args[0] == null || args[1] == null) { - return null; - } - return args[0].lessThanOrEquals(args[1]); + Or.prototype.exec = function (ctx) { + return datatypes_1.ThreeValuedLogic.or.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); }; - return LessOrEqual; + return Or; }(expression_1.Expression)); -exports.LessOrEqual = LessOrEqual; -var Greater = /** @class */ (function (_super) { - __extends(Greater, _super); - function Greater(json) { +exports.Or = Or; +var Not = /** @class */ (function (_super) { + __extends(Not, _super); + function Not(json) { return _super.call(this, json) || this; } - Greater.prototype.exec = function (ctx) { - var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); - if (args[0] == null || args[1] == null) { - return null; - } - return args[0].greaterThan(args[1]); + Not.prototype.exec = function (ctx) { + return datatypes_1.ThreeValuedLogic.not(this.execArgs(ctx)); }; - return Greater; + return Not; }(expression_1.Expression)); -exports.Greater = Greater; -var GreaterOrEqual = /** @class */ (function (_super) { - __extends(GreaterOrEqual, _super); - function GreaterOrEqual(json) { +exports.Not = Not; +var Xor = /** @class */ (function (_super) { + __extends(Xor, _super); + function Xor(json) { return _super.call(this, json) || this; } - GreaterOrEqual.prototype.exec = function (ctx) { - var args = this.execArgs(ctx).map(function (x) { return datatypes_1.Uncertainty.from(x); }); - if (args[0] == null || args[1] == null) { - return null; - } - return args[0].greaterThanOrEquals(args[1]); + Xor.prototype.exec = function (ctx) { + return datatypes_1.ThreeValuedLogic.xor.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); }; - return GreaterOrEqual; + return Xor; }(expression_1.Expression)); -exports.GreaterOrEqual = GreaterOrEqual; +exports.Xor = Xor; +var IsTrue = /** @class */ (function (_super) { + __extends(IsTrue, _super); + function IsTrue(json) { + return _super.call(this, json) || this; + } + IsTrue.prototype.exec = function (ctx) { + return true === this.execArgs(ctx); + }; + return IsTrue; +}(expression_1.Expression)); +exports.IsTrue = IsTrue; +var IsFalse = /** @class */ (function (_super) { + __extends(IsFalse, _super); + function IsFalse(json) { + return _super.call(this, json) || this; + } + IsFalse.prototype.exec = function (ctx) { + return false === this.execArgs(ctx); + }; + return IsFalse; +}(expression_1.Expression)); +exports.IsFalse = IsFalse; -},{"../datatypes/datatypes":57,"./expression":73}],70:[function(require,module,exports){ +},{"../datatypes/datatypes":43,"./expression":59}],68:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -26956,80 +24068,111 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.Case = exports.CaseItem = exports.If = void 0; +exports.Message = void 0; var expression_1 = require("./expression"); var builder_1 = require("./builder"); -var comparison_1 = require("../util/comparison"); -// TODO: Spec lists "Conditional", but it's "If" in the XSD -var If = /** @class */ (function (_super) { - __extends(If, _super); - function If(json) { +var Message = /** @class */ (function (_super) { + __extends(Message, _super); + function Message(json) { var _this = _super.call(this, json) || this; + _this.source = (0, builder_1.build)(json.source); _this.condition = (0, builder_1.build)(json.condition); - _this.th = (0, builder_1.build)(json.then); - _this.els = (0, builder_1.build)(json.else); + _this.code = (0, builder_1.build)(json.code); + _this.severity = (0, builder_1.build)(json.severity); + _this.message = (0, builder_1.build)(json.message); return _this; } - If.prototype.exec = function (ctx) { - if (this.condition.execute(ctx)) { - return this.th.execute(ctx); - } - else { - return this.els.execute(ctx); + Message.prototype.exec = function (ctx) { + var source = this.source.execute(ctx); + var condition = this.condition.execute(ctx); + if (condition) { + var code = this.code.execute(ctx); + var severity = this.severity.execute(ctx); + var message = this.message.execute(ctx); + var listener = ctx.getMessageListener(); + if (listener && typeof listener.onMessage === 'function') { + listener.onMessage(source, code, severity, message); + } } + return source; }; - return If; + return Message; }(expression_1.Expression)); -exports.If = If; -var CaseItem = /** @class */ (function () { - function CaseItem(json) { - this.when = (0, builder_1.build)(json.when); - this.then = (0, builder_1.build)(json.then); - } - return CaseItem; -}()); -exports.CaseItem = CaseItem; -var Case = /** @class */ (function (_super) { - __extends(Case, _super); - function Case(json) { - var _this = _super.call(this, json) || this; - _this.comparand = (0, builder_1.build)(json.comparand); - _this.caseItems = json.caseItem.map(function (ci) { return new CaseItem(ci); }); - _this.els = (0, builder_1.build)(json.else); - return _this; +exports.Message = Message; + +},{"./builder":53,"./expression":59}],69:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Coalesce = exports.IsNull = exports.Null = void 0; +var expression_1 = require("./expression"); +var Null = /** @class */ (function (_super) { + __extends(Null, _super); + function Null(json) { + return _super.call(this, json) || this; } - Case.prototype.exec = function (ctx) { - if (this.comparand) { - return this.exec_selected(ctx); - } - else { - return this.exec_standard(ctx); - } + Null.prototype.exec = function (_ctx) { + return null; }; - Case.prototype.exec_selected = function (ctx) { - var val = this.comparand.execute(ctx); - for (var _i = 0, _a = this.caseItems; _i < _a.length; _i++) { - var ci = _a[_i]; - if ((0, comparison_1.equals)(ci.when.execute(ctx), val)) { - return ci.then.execute(ctx); - } - } - return this.els.execute(ctx); + return Null; +}(expression_1.Expression)); +exports.Null = Null; +var IsNull = /** @class */ (function (_super) { + __extends(IsNull, _super); + function IsNull(json) { + return _super.call(this, json) || this; + } + IsNull.prototype.exec = function (ctx) { + return this.execArgs(ctx) == null; }; - Case.prototype.exec_standard = function (ctx) { - for (var _i = 0, _a = this.caseItems; _i < _a.length; _i++) { - var ci = _a[_i]; - if (ci.when.execute(ctx)) { - return ci.then.execute(ctx); + return IsNull; +}(expression_1.Expression)); +exports.IsNull = IsNull; +var Coalesce = /** @class */ (function (_super) { + __extends(Coalesce, _super); + function Coalesce(json) { + return _super.call(this, json) || this; + } + Coalesce.prototype.exec = function (ctx) { + if (this.args) { + for (var _i = 0, _a = this.args; _i < _a.length; _i++) { + var arg = _a[_i]; + var result = arg.execute(ctx); + // if a single arg that's a list, coalesce over the list + if (this.args.length === 1 && Array.isArray(result)) { + var item = result.find(function (item) { return item != null; }); + if (item != null) { + return item; + } + } + else { + if (result != null) { + return result; + } + } } } - return this.els.execute(ctx); + return null; }; - return Case; + return Coalesce; }(expression_1.Expression)); -exports.Case = Case; +exports.Coalesce = Coalesce; -},{"../util/comparison":103,"./builder":67,"./expression":73}],71:[function(require,module,exports){ +},{"./expression":59}],70:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -27065,283 +24208,403 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.DurationBetween = exports.DifferenceBetween = exports.doBefore = exports.doAfter = exports.TimezoneOffsetFrom = exports.TimeFrom = exports.DateFrom = exports.DateTimeComponentFrom = exports.TimeOfDay = exports.Now = exports.Today = exports.Time = exports.Date = exports.DateTime = void 0; +exports.Precision = exports.SameOrBefore = exports.SameOrAfter = exports.SameAs = exports.Before = exports.After = exports.Length = exports.ProperIncludedIn = exports.ProperIncludes = exports.IncludedIn = exports.Includes = exports.Contains = exports.In = exports.Indexer = exports.Intersect = exports.Except = exports.Union = exports.NotEqual = exports.Equivalent = exports.Equal = void 0; /* eslint-disable @typescript-eslint/ban-ts-comment */ var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var literal_1 = require("./literal"); -var DT = __importStar(require("../datatypes/datatypes")); -var DateTime = /** @class */ (function (_super) { - __extends(DateTime, _super); - function DateTime(json) { - var _this = _super.call(this, json) || this; - _this.json = json; - return _this; +var logic_1 = require("../datatypes/logic"); +var datetime_1 = require("../datatypes/datetime"); +var util_1 = require("../util/util"); +var comparison_1 = require("../util/comparison"); +var DT = __importStar(require("./datetime")); +var LIST = __importStar(require("./list")); +var IVL = __importStar(require("./interval")); +var Equal = /** @class */ (function (_super) { + __extends(Equal, _super); + function Equal(json) { + return _super.call(this, json) || this; } - DateTime.prototype.exec = function (ctx) { - var _a; - var _this = this; - for (var _i = 0, _b = DateTime.PROPERTIES; _i < _b.length; _i++) { - var property = _b[_i]; - // if json does not contain 'timezoneOffset' set it to the executionDateTime from the context - if (this.json[property] != null) { - // @ts-ignore - this[property] = (0, builder_1.build)(this.json[property]); + Equal.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args[0] == null || args[1] == null) { + return null; + } + // @ts-ignore + return comparison_1.equals.apply(void 0, args); + }; + return Equal; +}(expression_1.Expression)); +exports.Equal = Equal; +var Equivalent = /** @class */ (function (_super) { + __extends(Equivalent, _super); + function Equivalent(json) { + return _super.call(this, json) || this; + } + Equivalent.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null && b == null) { + return true; + } + else if (a == null || b == null) { + return false; + } + else { + return (0, comparison_1.equivalent)(a, b); + } + }; + return Equivalent; +}(expression_1.Expression)); +exports.Equivalent = Equivalent; +var NotEqual = /** @class */ (function (_super) { + __extends(NotEqual, _super); + function NotEqual(json) { + return _super.call(this, json) || this; + } + NotEqual.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args[0] == null || args[1] == null) { + return null; + } + // @ts-ignore + return logic_1.ThreeValuedLogic.not(comparison_1.equals.apply(void 0, this.execArgs(ctx))); + }; + return NotEqual; +}(expression_1.Expression)); +exports.NotEqual = NotEqual; +var Union = /** @class */ (function (_super) { + __extends(Union, _super); + function Union(json) { + return _super.call(this, json) || this; + } + Union.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null && b == null) { + return this.listTypeArgs() ? [] : null; + } + if (a == null || b == null) { + var notNull = a || b; + if ((0, util_1.typeIsArray)(notNull)) { + return notNull; } - else if (property === 'timezoneOffset' && ctx.getTimezoneOffset() != null) { - // @ts-ignore - this[property] = literal_1.Literal.from({ - type: 'Literal', - value: ctx.getTimezoneOffset(), - valueType: '{urn:hl7-org:elm-types:r1}Integer' - }); + else { + return null; } } - // @ts-ignore - var args = DateTime.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); - return new ((_a = DT.DateTime).bind.apply(_a, __spreadArray([void 0], args, false)))(); + var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; + return lib.doUnion(a, b); }; - DateTime.PROPERTIES = [ - 'year', - 'month', - 'day', - 'hour', - 'minute', - 'second', - 'millisecond', - 'timezoneOffset' - ]; - return DateTime; + Union.prototype.listTypeArgs = function () { + var _a; + return (_a = this.args) === null || _a === void 0 ? void 0 : _a.some(function (arg) { + return arg.asTypeSpecifier != null && arg.asTypeSpecifier.type === 'ListTypeSpecifier'; + }); + }; + return Union; }(expression_1.Expression)); -exports.DateTime = DateTime; -var Date = /** @class */ (function (_super) { - __extends(Date, _super); - function Date(json) { +exports.Union = Union; +var Except = /** @class */ (function (_super) { + __extends(Except, _super); + function Except(json) { + return _super.call(this, json) || this; + } + Except.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null) { + return null; + } + if (b == null) { + return (0, util_1.typeIsArray)(a) ? a : null; + } + var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; + return lib.doExcept(a, b); + }; + return Except; +}(expression_1.Expression)); +exports.Except = Except; +var Intersect = /** @class */ (function (_super) { + __extends(Intersect, _super); + function Intersect(json) { + return _super.call(this, json) || this; + } + Intersect.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null || b == null) { + return null; + } + var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; + return lib.doIntersect(a, b); + }; + return Intersect; +}(expression_1.Expression)); +exports.Intersect = Intersect; +var Indexer = /** @class */ (function (_super) { + __extends(Indexer, _super); + function Indexer(json) { + return _super.call(this, json) || this; + } + Indexer.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), operand = _a[0], index = _a[1]; + if (operand == null || index == null) { + return null; + } + if (index < 0 || index >= operand.length) { + return null; + } + return operand[index]; + }; + return Indexer; +}(expression_1.Expression)); +exports.Indexer = Indexer; +var In = /** @class */ (function (_super) { + __extends(In, _super); + function In(json) { var _this = _super.call(this, json) || this; - _this.json = json; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; return _this; } - Date.prototype.exec = function (ctx) { - var _a; - var _this = this; - for (var _i = 0, _b = Date.PROPERTIES; _i < _b.length; _i++) { - var property = _b[_i]; - if (this.json[property] != null) { - // @ts-ignore - this[property] = (0, builder_1.build)(this.json[property]); - } + In.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), item = _a[0], container = _a[1]; + if (item == null) { + return null; } - // @ts-ignore - var args = Date.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); - return new ((_a = DT.Date).bind.apply(_a, __spreadArray([void 0], args, false)))(); + if (container == null) { + return false; + } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doContains(container, item, this.precision); }; - Date.PROPERTIES = ['year', 'month', 'day']; - return Date; + return In; }(expression_1.Expression)); -exports.Date = Date; -var Time = /** @class */ (function (_super) { - __extends(Time, _super); - function Time(json) { +exports.In = In; +var Contains = /** @class */ (function (_super) { + __extends(Contains, _super); + function Contains(json) { var _this = _super.call(this, json) || this; - for (var _i = 0, _a = Time.PROPERTIES; _i < _a.length; _i++) { - var property = _a[_i]; - if (json[property] != null) { - // @ts-ignore - _this[property] = (0, builder_1.build)(json[property]); - } - } + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; return _this; } - Time.prototype.exec = function (ctx) { - var _a; - var _this = this; - // @ts-ignore - var args = Time.PROPERTIES.map(function (p) { return (_this[p] != null ? _this[p].execute(ctx) : undefined); }); - return new ((_a = DT.DateTime).bind.apply(_a, __spreadArray([void 0, 0, 1, 1], args, false)))().getTime(); + Contains.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), container = _a[0], item = _a[1]; + if (container == null) { + return false; + } + if (item == null) { + return null; + } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doContains(container, item, this.precision); }; - Time.PROPERTIES = ['hour', 'minute', 'second', 'millisecond']; - return Time; + return Contains; }(expression_1.Expression)); -exports.Time = Time; -var Today = /** @class */ (function (_super) { - __extends(Today, _super); - function Today(json) { - return _super.call(this, json) || this; +exports.Contains = Contains; +var Includes = /** @class */ (function (_super) { + __extends(Includes, _super); + function Includes(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; } - Today.prototype.exec = function (ctx) { - return ctx.getExecutionDateTime().getDate(); + Includes.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), container = _a[0], contained = _a[1]; + if (container == null || contained == null) { + return null; + } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doIncludes(container, contained, this.precision); }; - return Today; + return Includes; }(expression_1.Expression)); -exports.Today = Today; -var Now = /** @class */ (function (_super) { - __extends(Now, _super); - function Now(json) { - return _super.call(this, json) || this; +exports.Includes = Includes; +var IncludedIn = /** @class */ (function (_super) { + __extends(IncludedIn, _super); + function IncludedIn(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; } - Now.prototype.exec = function (ctx) { - return ctx.getExecutionDateTime(); + IncludedIn.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), contained = _a[0], container = _a[1]; + if (container == null || contained == null) { + return null; + } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doIncludes(container, contained, this.precision); }; - return Now; + return IncludedIn; }(expression_1.Expression)); -exports.Now = Now; -var TimeOfDay = /** @class */ (function (_super) { - __extends(TimeOfDay, _super); - function TimeOfDay(json) { - return _super.call(this, json) || this; +exports.IncludedIn = IncludedIn; +var ProperIncludes = /** @class */ (function (_super) { + __extends(ProperIncludes, _super); + function ProperIncludes(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; } - TimeOfDay.prototype.exec = function (ctx) { - return ctx.getExecutionDateTime().getTime(); + ProperIncludes.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), container = _a[0], contained = _a[1]; + if (container == null || contained == null) { + return null; + } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doProperIncludes(container, contained, this.precision); }; - return TimeOfDay; + return ProperIncludes; }(expression_1.Expression)); -exports.TimeOfDay = TimeOfDay; -var DateTimeComponentFrom = /** @class */ (function (_super) { - __extends(DateTimeComponentFrom, _super); - function DateTimeComponentFrom(json) { +exports.ProperIncludes = ProperIncludes; +var ProperIncludedIn = /** @class */ (function (_super) { + __extends(ProperIncludedIn, _super); + function ProperIncludedIn(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; return _this; } - DateTimeComponentFrom.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return arg[this.precision.toLowerCase()]; - } - else { + ProperIncludedIn.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), contained = _a[0], container = _a[1]; + if (container == null || contained == null) { return null; } + var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; + return lib.doProperIncludes(container, contained, this.precision); }; - return DateTimeComponentFrom; + return ProperIncludedIn; }(expression_1.Expression)); -exports.DateTimeComponentFrom = DateTimeComponentFrom; -var DateFrom = /** @class */ (function (_super) { - __extends(DateFrom, _super); - function DateFrom(json) { +exports.ProperIncludedIn = ProperIncludedIn; +var Length = /** @class */ (function (_super) { + __extends(Length, _super); + function Length(json) { return _super.call(this, json) || this; } - DateFrom.prototype.exec = function (ctx) { - var date = this.execArgs(ctx); - if (date != null) { - return date.getDate(); + Length.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return arg.length; + } + else if (this.arg.asTypeSpecifier.type === 'ListTypeSpecifier') { + return 0; } else { return null; } }; - return DateFrom; + return Length; }(expression_1.Expression)); -exports.DateFrom = DateFrom; -var TimeFrom = /** @class */ (function (_super) { - __extends(TimeFrom, _super); - function TimeFrom(json) { - return _super.call(this, json) || this; +exports.Length = Length; +var After = /** @class */ (function (_super) { + __extends(After, _super); + function After(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; } - TimeFrom.prototype.exec = function (ctx) { - var date = this.execArgs(ctx); - if (date != null) { - return date.getTime(); + After.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null || b == null) { + return null; } - else { + var lib = a instanceof datetime_1.DateTime ? DT : IVL; + return lib.doAfter(a, b, this.precision); + }; + return After; +}(expression_1.Expression)); +exports.After = After; +var Before = /** @class */ (function (_super) { + __extends(Before, _super); + function Before(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + return _this; + } + Before.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a == null || b == null) { return null; } + var lib = a instanceof datetime_1.DateTime ? DT : IVL; + return lib.doBefore(a, b, this.precision); }; - return TimeFrom; + return Before; }(expression_1.Expression)); -exports.TimeFrom = TimeFrom; -var TimezoneOffsetFrom = /** @class */ (function (_super) { - __extends(TimezoneOffsetFrom, _super); - function TimezoneOffsetFrom(json) { - return _super.call(this, json) || this; +exports.Before = Before; +var SameAs = /** @class */ (function (_super) { + __extends(SameAs, _super); + function SameAs(json) { + var _this = _super.call(this, json) || this; + _this.precision = json.precision; + return _this; } - TimezoneOffsetFrom.prototype.exec = function (ctx) { - var date = this.execArgs(ctx); - if (date != null) { - return date.timezoneOffset; + SameAs.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; + if (a != null && b != null) { + return a.sameAs(b, this.precision != null ? this.precision.toLowerCase() : undefined); } else { return null; } }; - return TimezoneOffsetFrom; + return SameAs; }(expression_1.Expression)); -exports.TimezoneOffsetFrom = TimezoneOffsetFrom; -// Delegated to by overloaded#After -function doAfter(a, b, precision) { - return a.after(b, precision); -} -exports.doAfter = doAfter; -// Delegated to by overloaded#Before -function doBefore(a, b, precision) { - return a.before(b, precision); -} -exports.doBefore = doBefore; -var DifferenceBetween = /** @class */ (function (_super) { - __extends(DifferenceBetween, _super); - function DifferenceBetween(json) { +exports.SameAs = SameAs; +var SameOrAfter = /** @class */ (function (_super) { + __extends(SameOrAfter, _super); + function SameOrAfter(json) { var _this = _super.call(this, json) || this; _this.precision = json.precision; return _this; } - DifferenceBetween.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - // Check to make sure args exist and that they have differenceBetween functions so that they can be compared to one another - if (args[0] == null || - args[1] == null || - typeof args[0].differenceBetween !== 'function' || - typeof args[1].differenceBetween !== 'function') { - return null; - } - var result = args[0].differenceBetween(args[1], this.precision != null ? this.precision.toLowerCase() : undefined); - if (result != null && result.isPoint()) { - return result.low; + SameOrAfter.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), d1 = _a[0], d2 = _a[1]; + if (d1 != null && d2 != null) { + return d1.sameOrAfter(d2, this.precision != null ? this.precision.toLowerCase() : undefined); } else { - return result; + return null; } }; - return DifferenceBetween; + return SameOrAfter; }(expression_1.Expression)); -exports.DifferenceBetween = DifferenceBetween; -var DurationBetween = /** @class */ (function (_super) { - __extends(DurationBetween, _super); - function DurationBetween(json) { +exports.SameOrAfter = SameOrAfter; +var SameOrBefore = /** @class */ (function (_super) { + __extends(SameOrBefore, _super); + function SameOrBefore(json) { var _this = _super.call(this, json) || this; _this.precision = json.precision; return _this; } - DurationBetween.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - // Check to make sure args exist and that they have durationBetween functions so that they can be compared to one another - if (args[0] == null || - args[1] == null || - typeof args[0].durationBetween !== 'function' || - typeof args[1].durationBetween !== 'function') { + SameOrBefore.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), d1 = _a[0], d2 = _a[1]; + if (d1 != null && d2 != null) { + return d1.sameOrBefore(d2, this.precision != null ? this.precision.toLowerCase() : undefined); + } + else { return null; } - var result = args[0].durationBetween(args[1], this.precision != null ? this.precision.toLowerCase() : undefined); - if (result != null && result.isPoint()) { - return result.low; + }; + return SameOrBefore; +}(expression_1.Expression)); +exports.SameOrBefore = SameOrBefore; +// Implemented for DateTime, Date, and Time but not for Decimal yet +var Precision = /** @class */ (function (_super) { + __extends(Precision, _super); + function Precision(json) { + return _super.call(this, json) || this; + } + Precision.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { + return null; } - else { - return result; + // Since we can't extend UnimplementedExpression directly for this overloaded function, + // we have to copy the error to throw here if we are not using the correct type + if (!arg.getPrecisionValue) { + throw new Error("Unimplemented Expression: Precision"); } + return arg.getPrecisionValue(); }; - return DurationBetween; + return Precision; }(expression_1.Expression)); -exports.DurationBetween = DurationBetween; +exports.Precision = Precision; -},{"../datatypes/datatypes":57,"./builder":67,"./expression":73,"./literal":80}],72:[function(require,module,exports){ +},{"../datatypes/datetime":44,"../datatypes/logic":47,"../util/comparison":89,"../util/util":92,"./datetime":57,"./expression":59,"./interval":63,"./list":65}],71:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -27359,34 +24622,54 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.VersionedIdentifier = exports.IncludeDef = exports.UsingDef = void 0; +exports.ParameterRef = exports.ParameterDef = void 0; var expression_1 = require("./expression"); -var UsingDef = /** @class */ (function (_super) { - __extends(UsingDef, _super); - function UsingDef() { - return _super !== null && _super.apply(this, arguments) || this; - } - return UsingDef; -}(expression_1.UnimplementedExpression)); -exports.UsingDef = UsingDef; -var IncludeDef = /** @class */ (function (_super) { - __extends(IncludeDef, _super); - function IncludeDef() { - return _super !== null && _super.apply(this, arguments) || this; +var builder_1 = require("./builder"); +var ParameterDef = /** @class */ (function (_super) { + __extends(ParameterDef, _super); + function ParameterDef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.default = (0, builder_1.build)(json.default); + _this.parameterTypeSpecifier = json.parameterTypeSpecifier; + return _this; } - return IncludeDef; -}(expression_1.UnimplementedExpression)); -exports.IncludeDef = IncludeDef; -var VersionedIdentifier = /** @class */ (function (_super) { - __extends(VersionedIdentifier, _super); - function VersionedIdentifier() { - return _super !== null && _super.apply(this, arguments) || this; + ParameterDef.prototype.exec = function (ctx) { + // If context parameters contains the name, return value. + if (ctx && ctx.parameters[this.name] !== undefined) { + return ctx.parameters[this.name]; + // If the parent context contains the name, return that + } + else if (ctx.getParentParameter(this.name) !== undefined) { + var parentParam = ctx.getParentParameter(this.name); + return parentParam.default != null ? parentParam.default.execute(ctx) : parentParam; + // If default type exists, execute the default type + } + else if (this.default != null) { + this.default.execute(ctx); + } + }; + return ParameterDef; +}(expression_1.Expression)); +exports.ParameterDef = ParameterDef; +var ParameterRef = /** @class */ (function (_super) { + __extends(ParameterRef, _super); + function ParameterRef(json) { + var _this = _super.call(this, json) || this; + _this.name = json.name; + _this.library = json.libraryName; + return _this; } - return VersionedIdentifier; -}(expression_1.UnimplementedExpression)); -exports.VersionedIdentifier = VersionedIdentifier; + ParameterRef.prototype.exec = function (ctx) { + ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; + var param = ctx.getParameter(this.name); + return param != null ? param.execute(ctx) : undefined; + }; + return ParameterRef; +}(expression_1.Expression)); +exports.ParameterRef = ParameterRef; -},{"./expression":73}],73:[function(require,module,exports){ +},{"./builder":53,"./expression":59}],72:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -27403,69 +24686,6 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UnimplementedExpression = exports.Expression = void 0; -var util_1 = require("../util/util"); -var builder_1 = require("./builder"); -var Expression = /** @class */ (function () { - function Expression(json) { - if (json.operand != null) { - var op = (0, builder_1.build)(json.operand); - if ((0, util_1.typeIsArray)(json.operand)) { - this.args = op; - } - else { - this.arg = op; - } - } - if (json.localId != null) { - this.localId = json.localId; - } - } - Expression.prototype.execute = function (ctx) { - if (this.localId != null) { - // Store the localId and result on the root context of this library - var execValue = this.exec(ctx); - ctx.rootContext().setLocalIdWithResult(this.localId, execValue); - return execValue; - } - else { - return this.exec(ctx); - } - }; - Expression.prototype.exec = function (_ctx) { - return this; - }; - Expression.prototype.execArgs = function (ctx) { - if (this.args != null) { - return this.args.map(function (arg) { return arg.execute(ctx); }); - } - else if (this.arg != null) { - return this.arg.execute(ctx); - } - else { - return null; - } - }; - return Expression; -}()); -exports.Expression = Expression; -var UnimplementedExpression = /** @class */ (function (_super) { - __extends(UnimplementedExpression, _super); - function UnimplementedExpression(json) { - var _this = _super.call(this, json) || this; - _this.json = json; - return _this; - } - UnimplementedExpression.prototype.exec = function (_ctx) { - throw new Error("Unimplemented Expression: ".concat(this.json.type)); - }; - return UnimplementedExpression; -}(Expression)); -exports.UnimplementedExpression = UnimplementedExpression; - -},{"../util/util":106,"./builder":67}],74:[function(require,module,exports){ -"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -27473,51 +24693,40 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi if (k2 === undefined) k2 = k; o[k2] = m[k]; })); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.doContains = exports.doExcept = exports.doIncludes = exports.doIntersect = exports.doProperIncludes = exports.doAfter = exports.doUnion = exports.doBefore = void 0; -__exportStar(require("./expression"), exports); -__exportStar(require("./aggregate"), exports); -__exportStar(require("./arithmetic"), exports); -__exportStar(require("./clinical"), exports); -__exportStar(require("./comparison"), exports); -__exportStar(require("./conditional"), exports); -__exportStar(require("./datetime"), exports); -__exportStar(require("./declaration"), exports); -__exportStar(require("./external"), exports); -__exportStar(require("./instance"), exports); -__exportStar(require("./interval"), exports); -__exportStar(require("./list"), exports); -__exportStar(require("./literal"), exports); -__exportStar(require("./logical"), exports); -__exportStar(require("./message"), exports); -__exportStar(require("./nullological"), exports); -__exportStar(require("./parameters"), exports); -__exportStar(require("./quantity"), exports); -__exportStar(require("./query"), exports); -__exportStar(require("./ratio"), exports); -__exportStar(require("./reusable"), exports); -__exportStar(require("./string"), exports); -__exportStar(require("./structured"), exports); -__exportStar(require("./type"), exports); -__exportStar(require("./overloaded"), exports); -// Re-exporting interval functions as overrides to avoid ambiguity -// https://stackoverflow.com/questions/41293108/how-to-do-re-export-with-overrides -// TODO: we should improve this by perhaps renaming and reworking these functions -// it's a bit confusing right now giving the interval exports precedence over the others -var interval_1 = require("./interval"); -Object.defineProperty(exports, "doBefore", { enumerable: true, get: function () { return interval_1.doBefore; } }); -Object.defineProperty(exports, "doUnion", { enumerable: true, get: function () { return interval_1.doUnion; } }); -Object.defineProperty(exports, "doAfter", { enumerable: true, get: function () { return interval_1.doAfter; } }); -Object.defineProperty(exports, "doProperIncludes", { enumerable: true, get: function () { return interval_1.doProperIncludes; } }); -Object.defineProperty(exports, "doIntersect", { enumerable: true, get: function () { return interval_1.doIntersect; } }); -Object.defineProperty(exports, "doIncludes", { enumerable: true, get: function () { return interval_1.doIncludes; } }); -Object.defineProperty(exports, "doExcept", { enumerable: true, get: function () { return interval_1.doExcept; } }); -Object.defineProperty(exports, "doContains", { enumerable: true, get: function () { return interval_1.doContains; } }); +exports.Quantity = void 0; +var expression_1 = require("./expression"); +var DT = __importStar(require("../datatypes/datatypes")); +// Unit conversation is currently implemented on for time duration comparison operations +// TODO: Implement unit conversation for time duration mathematical operations +var Quantity = /** @class */ (function (_super) { + __extends(Quantity, _super); + function Quantity(json) { + var _this = _super.call(this, json) || this; + _this.value = parseFloat(json.value); + _this.unit = json.unit; + return _this; + } + Quantity.prototype.exec = function (_ctx) { + return new DT.Quantity(this.value, this.unit); + }; + return Quantity; +}(expression_1.Expression)); +exports.Quantity = Quantity; -},{"./aggregate":65,"./arithmetic":66,"./clinical":68,"./comparison":69,"./conditional":70,"./datetime":71,"./declaration":72,"./expression":73,"./external":75,"./instance":76,"./interval":77,"./list":79,"./literal":80,"./logical":81,"./message":82,"./nullological":83,"./overloaded":84,"./parameters":85,"./quantity":86,"./query":87,"./ratio":88,"./reusable":89,"./string":90,"./structured":91,"./type":92}],75:[function(require,module,exports){ +},{"../datatypes/datatypes":43,"./expression":59}],73:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -27534,144 +24743,348 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Retrieve = void 0; +exports.QueryLetRef = exports.AliasRef = exports.Query = exports.SortClause = exports.ReturnClause = exports.ByColumn = exports.ByExpression = exports.ByDirection = exports.Sort = exports.Without = exports.With = exports.LetClause = exports.AliasedQuerySource = void 0; var expression_1 = require("./expression"); +var context_1 = require("../runtime/context"); var util_1 = require("../util/util"); +var comparison_1 = require("../util/comparison"); var builder_1 = require("./builder"); -var Retrieve = /** @class */ (function (_super) { - __extends(Retrieve, _super); - function Retrieve(json) { +var AliasedQuerySource = /** @class */ (function () { + function AliasedQuerySource(json) { + this.alias = json.alias; + this.expression = (0, builder_1.build)(json.expression); + } + return AliasedQuerySource; +}()); +exports.AliasedQuerySource = AliasedQuerySource; +var LetClause = /** @class */ (function () { + function LetClause(json) { + this.identifier = json.identifier; + this.expression = (0, builder_1.build)(json.expression); + } + return LetClause; +}()); +exports.LetClause = LetClause; +var With = /** @class */ (function (_super) { + __extends(With, _super); + function With(json) { var _this = _super.call(this, json) || this; - _this.datatype = json.dataType; - _this.templateId = json.templateId; - _this.codeProperty = json.codeProperty; - _this.codes = (0, builder_1.build)(json.codes); - _this.dateProperty = json.dateProperty; - _this.dateRange = (0, builder_1.build)(json.dateRange); + _this.alias = json.alias; + _this.expression = (0, builder_1.build)(json.expression); + _this.suchThat = (0, builder_1.build)(json.suchThat); return _this; } - Retrieve.prototype.exec = function (ctx) { - var _a; + With.prototype.exec = function (ctx) { var _this = this; - // Object with retrieve information to pass back to patient source - // Always assign datatype. Assign codeProperty and dateProperty if present - var retrieveDetails = __assign(__assign({ datatype: this.datatype }, (this.codeProperty ? { codeProperty: this.codeProperty } : {})), (this.dateProperty ? { dateProperty: this.dateProperty } : {})); - if (this.codes) { - var resolvedCodes = this.codes.execute(ctx); - if (resolvedCodes == null) { - return []; + var records = this.expression.execute(ctx); + if (!(0, util_1.typeIsArray)(records)) { + records = [records]; + } + var returns = records.map(function (rec) { + var childCtx = ctx.childContext(); + childCtx.set(_this.alias, rec); + return _this.suchThat.execute(childCtx); + }); + return returns.some(function (x) { return x; }); + }; + return With; +}(expression_1.Expression)); +exports.With = With; +var Without = /** @class */ (function (_super) { + __extends(Without, _super); + function Without(json) { + return _super.call(this, json) || this; + } + Without.prototype.exec = function (ctx) { + return !_super.prototype.exec.call(this, ctx); + }; + return Without; +}(With)); +exports.Without = Without; +// ELM-only, not a product of CQL +var Sort = /** @class */ (function (_super) { + __extends(Sort, _super); + function Sort() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Sort; +}(expression_1.UnimplementedExpression)); +exports.Sort = Sort; +var ByDirection = /** @class */ (function (_super) { + __extends(ByDirection, _super); + function ByDirection(json) { + var _this = _super.call(this, json) || this; + _this.direction = json.direction; + _this.low_order = _this.direction === 'asc' || _this.direction === 'ascending' ? -1 : 1; + _this.high_order = _this.low_order * -1; + return _this; + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + ByDirection.prototype.exec = function (ctx, a, b) { + if (a === b) { + return 0; + } + else if (a.isQuantity && b.isQuantity) { + if (a.before(b)) { + return this.low_order; + } + else { + return this.high_order; } - retrieveDetails.codes = resolvedCodes; } - if (this.dateRange) { - retrieveDetails.dateRange = this.dateRange.execute(ctx); + else if (a < b) { + return this.low_order; } - if (this.templateId) { - retrieveDetails.templateId = this.templateId; + else { + return this.high_order; } - var records = ctx.findRecords(this.templateId != null ? this.templateId : this.datatype, retrieveDetails); - if (retrieveDetails.codes) { - records = records.filter(function (r) { return _this.recordMatchesCodesOrVS(r, retrieveDetails.codes); }); + }; + return ByDirection; +}(expression_1.Expression)); +exports.ByDirection = ByDirection; +var ByExpression = /** @class */ (function (_super) { + __extends(ByExpression, _super); + function ByExpression(json) { + var _this = _super.call(this, json) || this; + _this.expression = (0, builder_1.build)(json.expression); + _this.direction = json.direction; + _this.low_order = _this.direction === 'asc' || _this.direction === 'ascending' ? -1 : 1; + _this.high_order = _this.low_order * -1; + return _this; + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + ByExpression.prototype.exec = function (ctx, a, b) { + var sctx = ctx.childContext(a); + var a_val = this.expression.execute(sctx); + sctx = ctx.childContext(b); + var b_val = this.expression.execute(sctx); + if (a_val === b_val || (a_val == null && b_val == null)) { + return 0; } - if (retrieveDetails.dateRange && this.dateProperty) { - records = records.filter(function (r) { var _a; return (_a = retrieveDetails.dateRange) === null || _a === void 0 ? void 0 : _a.includes(r.getDateOrInterval(_this.dateProperty)); }); + else if (a_val == null || b_val == null) { + return a_val == null ? this.low_order : this.high_order; } - if (Array.isArray(records)) { - (_a = ctx.evaluatedRecords).push.apply(_a, records); + else if (a_val.isQuantity && b_val.isQuantity) { + return a_val.before(b_val) ? this.low_order : this.high_order; } else { - ctx.evaluatedRecords.push(records); + return a_val < b_val ? this.low_order : this.high_order; } - return records; }; - Retrieve.prototype.recordMatchesCodesOrVS = function (record, codes) { + return ByExpression; +}(expression_1.Expression)); +exports.ByExpression = ByExpression; +var ByColumn = /** @class */ (function (_super) { + __extends(ByColumn, _super); + function ByColumn(json) { + var _this = _super.call(this, json) || this; + _this.expression = (0, builder_1.build)({ + name: json.path, + type: 'IdentifierRef' + }); + return _this; + } + return ByColumn; +}(ByExpression)); +exports.ByColumn = ByColumn; +var ReturnClause = /** @class */ (function () { + function ReturnClause(json) { + this.expression = (0, builder_1.build)(json.expression); + this.distinct = json.distinct != null ? json.distinct : true; + } + return ReturnClause; +}()); +exports.ReturnClause = ReturnClause; +var SortClause = /** @class */ (function () { + function SortClause(json) { + this.by = (0, builder_1.build)(json != null ? json.by : undefined); + } + SortClause.prototype.sort = function (ctx, values) { var _this = this; - if ((0, util_1.typeIsArray)(codes)) { - return codes.some(function (c) { return c.hasMatch(record.getCode(_this.codeProperty)); }); + if (this.by) { + return values.sort(function (a, b) { + var order = 0; + for (var _i = 0, _a = _this.by; _i < _a.length; _i++) { + var item = _a[_i]; + // Do not use execute here because the value of the sort order is not important. + order = item.exec(ctx, a, b); + if (order !== 0) { + break; + } + } + return order; + }); } - else { - return codes.hasMatch(record.getCode(this.codeProperty)); + }; + return SortClause; +}()); +exports.SortClause = SortClause; +var toDistinctList = function (xList) { + var yList = []; + xList.forEach(function (x) { + if (!yList.some(function (y) { return (0, comparison_1.equals)(x, y); })) { + yList.push(x); } + }); + return yList; +}; +var AggregateClause = /** @class */ (function (_super) { + __extends(AggregateClause, _super); + function AggregateClause(json) { + var _this = _super.call(this, json) || this; + _this.identifier = json.identifier; + _this.expression = (0, builder_1.build)(json.expression); + _this.starting = json.starting ? (0, builder_1.build)(json.starting) : null; + _this.distinct = json.distinct != null ? json.distinct : true; + return _this; + } + AggregateClause.prototype.aggregate = function (returnedValues, ctx) { + var _this = this; + var aggregateValue = this.starting != null ? this.starting.exec(ctx) : null; + returnedValues.forEach(function (contextValues) { + var childContext = ctx.childContext(contextValues); + childContext.set(_this.identifier, aggregateValue); + aggregateValue = _this.expression.exec(childContext); + }); + return aggregateValue; }; - return Retrieve; + return AggregateClause; }(expression_1.Expression)); -exports.Retrieve = Retrieve; - -},{"../util/util":106,"./builder":67,"./expression":73}],76:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Instance = void 0; -var expression_1 = require("./expression"); -var quantity_1 = require("../datatypes/quantity"); -var datatypes_1 = require("../datatypes/datatypes"); -var builder_1 = require("./builder"); -var Element = /** @class */ (function () { - function Element(json) { - this.name = json.name; - this.value = (0, builder_1.build)(json.value); +var Query = /** @class */ (function (_super) { + __extends(Query, _super); + function Query(json) { + var _this = _super.call(this, json) || this; + _this.sources = new MultiSource(json.source.map(function (s) { return new AliasedQuerySource(s); })); + _this.letClauses = json.let != null ? json.let.map(function (d) { return new LetClause(d); }) : []; + _this.relationship = json.relationship != null ? (0, builder_1.build)(json.relationship) : []; + _this.where = (0, builder_1.build)(json.where); + _this.returnClause = json.return != null ? new ReturnClause(json.return) : null; + _this.aggregateClause = json.aggregate != null ? new AggregateClause(json.aggregate) : null; + _this.aliases = _this.sources.aliases(); + _this.sortClause = json.sort != null ? new SortClause(json.sort) : null; + return _this; } - Element.prototype.exec = function (ctx) { - return this.value != null ? this.value.execute(ctx) : undefined; + Query.prototype.isDistinct = function () { + if (this.aggregateClause != null && this.aggregateClause.distinct != null) { + return this.aggregateClause.distinct; + } + else if (this.returnClause != null && this.returnClause.distinct != null) { + return this.returnClause.distinct; + } + return true; }; - return Element; -}()); -var Instance = /** @class */ (function (_super) { - __extends(Instance, _super); - function Instance(json) { + Query.prototype.exec = function (ctx) { + var _this = this; + var returnedValues = []; + this.sources.forEach(ctx, function (rctx) { + for (var _i = 0, _a = _this.letClauses; _i < _a.length; _i++) { + var def = _a[_i]; + rctx.set(def.identifier, def.expression.execute(rctx)); + } + var relations = _this.relationship.map(function (rel) { + var child_ctx = rctx.childContext(); + return rel.execute(child_ctx); + }); + var passed = (0, util_1.allTrue)(relations) && (_this.where ? _this.where.execute(rctx) : true); + if (passed) { + if (_this.returnClause != null) { + var val = _this.returnClause.expression.execute(rctx); + returnedValues.push(val); + } + else { + if (_this.aliases.length === 1 && _this.aggregateClause == null) { + returnedValues.push(rctx.get(_this.aliases[0])); + } + else { + returnedValues.push(rctx.context_values); + } + } + } + }); + if (this.isDistinct()) { + returnedValues = toDistinctList(returnedValues); + } + if (this.aggregateClause != null) { + returnedValues = this.aggregateClause.aggregate(returnedValues, ctx); + } + if (this.sortClause != null) { + this.sortClause.sort(ctx, returnedValues); + } + if (this.sources.returnsList() || this.aggregateClause != null) { + return returnedValues; + } + else { + return returnedValues[0]; + } + }; + return Query; +}(expression_1.Expression)); +exports.Query = Query; +var AliasRef = /** @class */ (function (_super) { + __extends(AliasRef, _super); + function AliasRef(json) { var _this = _super.call(this, json) || this; - _this.classType = json.classType; - _this.element = json.element.map(function (child) { return new Element(child); }); + _this.name = json.name; return _this; } - Instance.prototype.exec = function (ctx) { - var obj = {}; - for (var _i = 0, _a = this.element; _i < _a.length; _i++) { - var el = _a[_i]; - obj[el.name] = el.exec(ctx); + AliasRef.prototype.exec = function (ctx) { + return ctx != null ? ctx.get(this.name) : undefined; + }; + return AliasRef; +}(expression_1.Expression)); +exports.AliasRef = AliasRef; +var QueryLetRef = /** @class */ (function (_super) { + __extends(QueryLetRef, _super); + function QueryLetRef(json) { + return _super.call(this, json) || this; + } + return QueryLetRef; +}(AliasRef)); +exports.QueryLetRef = QueryLetRef; +// The following is not defined by ELM but is helpful for execution +var MultiSource = /** @class */ (function () { + function MultiSource(sources) { + this.sources = sources; + this.alias = this.sources[0].alias; + this.expression = this.sources[0].expression; + this.isList = true; + if (this.sources.length > 1) { + this.rest = new MultiSource(this.sources.slice(1)); } - switch (this.classType) { - case '{urn:hl7-org:elm-types:r1}Quantity': - return new quantity_1.Quantity(obj.value, obj.unit); - case '{urn:hl7-org:elm-types:r1}Code': - return new datatypes_1.Code(obj.code, obj.system, obj.version, obj.display); - case '{urn:hl7-org:elm-types:r1}Concept': - return new datatypes_1.Concept(obj.codes, obj.display); - default: - return obj; + } + MultiSource.prototype.aliases = function () { + var a = [this.alias]; + if (this.rest) { + a = a.concat(this.rest.aliases()); } + return a; }; - return Instance; -}(expression_1.Expression)); -exports.Instance = Instance; + MultiSource.prototype.returnsList = function () { + return this.isList || (this.rest && this.rest.returnsList()); + }; + MultiSource.prototype.forEach = function (ctx, func) { + var _this = this; + var records = this.expression.execute(ctx); + this.isList = (0, util_1.typeIsArray)(records); + records = this.isList ? records : [records]; + return records.map(function (rec) { + var rctx = new context_1.Context(ctx); + rctx.set(_this.alias, rec); + if (_this.rest) { + return _this.rest.forEach(rctx, func); + } + else { + return func(rctx); + } + }); + }; + return MultiSource; +}()); -},{"../datatypes/datatypes":57,"../datatypes/quantity":62,"./builder":67,"./expression":73}],77:[function(require,module,exports){ +},{"../runtime/context":79,"../util/comparison":89,"../util/util":92,"./builder":53,"./expression":59}],74:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -27708,875 +25121,506 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Collapse = exports.Expand = exports.Ends = exports.Starts = exports.End = exports.Start = exports.Size = exports.Width = exports.doIntersect = exports.doExcept = exports.doUnion = exports.OverlapsBefore = exports.OverlapsAfter = exports.Overlaps = exports.MeetsBefore = exports.MeetsAfter = exports.Meets = exports.doBefore = exports.doAfter = exports.doProperIncludes = exports.doIncludes = exports.doContains = exports.Interval = void 0; -var expression_1 = require("./expression"); -var quantity_1 = require("../datatypes/quantity"); -var math_1 = require("../util/math"); -var units_1 = require("../util/units"); -var dtivl = __importStar(require("../datatypes/interval")); -var builder_1 = require("./builder"); -var Interval = /** @class */ (function (_super) { - __extends(Interval, _super); - function Interval(json) { - var _this = _super.call(this, json) || this; - _this.lowClosed = json.lowClosed; - _this.lowClosedExpression = (0, builder_1.build)(json.lowClosedExpression); - _this.highClosed = json.highClosed; - _this.highClosedExpression = (0, builder_1.build)(json.highClosedExpression); - _this.low = (0, builder_1.build)(json.low); - _this.high = (0, builder_1.build)(json.high); - return _this; - } - Object.defineProperty(Interval.prototype, "isInterval", { - // Define a simple getter to allow type-checking of this class without instanceof - // and in a way that survives minification (as opposed to checking constructor.name) - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - Interval.prototype.exec = function (ctx) { - var lowValue = this.low.execute(ctx); - var highValue = this.high.execute(ctx); - var lowClosed = this.lowClosed != null - ? this.lowClosed - : this.lowClosedExpression && this.lowClosedExpression.execute(ctx); - var highClosed = this.highClosed != null - ? this.highClosed - : this.highClosedExpression && this.highClosedExpression.execute(ctx); - var defaultPointType; - if (lowValue == null && highValue == null) { - // try to get the default point type from a cast - if (this.low.asTypeSpecifier && this.low.asTypeSpecifier.type === 'NamedTypeSpecifier') { - defaultPointType = this.low.asTypeSpecifier.name; - } - else if (this.high.asTypeSpecifier && - this.high.asTypeSpecifier.type === 'NamedTypeSpecifier') { - defaultPointType = this.high.asTypeSpecifier.name; - } - } - return new dtivl.Interval(lowValue, highValue, lowClosed, highClosed, defaultPointType); - }; - return Interval; -}(expression_1.Expression)); -exports.Interval = Interval; -// Equal is completely handled by overloaded#Equal -// NotEqual is completely handled by overloaded#Equal -// Delegated to by overloaded#Contains and overloaded#In -function doContains(interval, item, precision) { - return interval.contains(item, precision); -} -exports.doContains = doContains; -// Delegated to by overloaded#Includes and overloaded#IncludedIn -function doIncludes(interval, subinterval, precision) { - return interval.includes(subinterval, precision); -} -exports.doIncludes = doIncludes; -// Delegated to by overloaded#ProperIncludes and overloaded@ProperIncludedIn -function doProperIncludes(interval, subinterval, precision) { - return interval.properlyIncludes(subinterval, precision); -} -exports.doProperIncludes = doProperIncludes; -// Delegated to by overloaded#After -function doAfter(a, b, precision) { - return a.after(b, precision); -} -exports.doAfter = doAfter; -// Delegated to by overloaded#Before -function doBefore(a, b, precision) { - return a.before(b, precision); -} -exports.doBefore = doBefore; -var Meets = /** @class */ (function (_super) { - __extends(Meets, _super); - function Meets(json) { +exports.Ratio = void 0; +var expression_1 = require("./expression"); +var quantity_1 = require("../datatypes/quantity"); +var DT = __importStar(require("../datatypes/datatypes")); +var Ratio = /** @class */ (function (_super) { + __extends(Ratio, _super); + function Ratio(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - Meets.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.meets(b, this.precision); + if (json.numerator == null) { + throw new Error('Cannot create a ratio with an undefined numerator value'); } else { - return null; + _this.numerator = new quantity_1.Quantity(json.numerator.value, json.numerator.unit); } - }; - return Meets; -}(expression_1.Expression)); -exports.Meets = Meets; -var MeetsAfter = /** @class */ (function (_super) { - __extends(MeetsAfter, _super); - function MeetsAfter(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - MeetsAfter.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.meetsAfter(b, this.precision); + if (json.denominator == null) { + throw new Error('Cannot create a ratio with an undefined denominator value'); } else { - return null; + _this.denominator = new quantity_1.Quantity(json.denominator.value, json.denominator.unit); } + return _this; + } + Ratio.prototype.exec = function (_ctx) { + return new DT.Ratio(this.numerator, this.denominator); }; - return MeetsAfter; + return Ratio; }(expression_1.Expression)); -exports.MeetsAfter = MeetsAfter; -var MeetsBefore = /** @class */ (function (_super) { - __extends(MeetsBefore, _super); - function MeetsBefore(json) { +exports.Ratio = Ratio; + +},{"../datatypes/datatypes":43,"../datatypes/quantity":48,"./expression":59}],75:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.IdentifierRef = exports.OperandRef = exports.FunctionRef = exports.FunctionDef = exports.ExpressionRef = exports.ExpressionDef = void 0; +var expression_1 = require("./expression"); +var builder_1 = require("./builder"); +var ExpressionDef = /** @class */ (function (_super) { + __extends(ExpressionDef, _super); + function ExpressionDef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; + _this.context = json.context; + _this.expression = (0, builder_1.build)(json.expression); return _this; } - MeetsBefore.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.meetsBefore(b, this.precision); - } - else { - return null; - } + ExpressionDef.prototype.exec = function (ctx) { + var value = this.expression != null ? this.expression.execute(ctx) : undefined; + ctx.rootContext().set(this.name, value); + return value; }; - return MeetsBefore; + return ExpressionDef; }(expression_1.Expression)); -exports.MeetsBefore = MeetsBefore; -var Overlaps = /** @class */ (function (_super) { - __extends(Overlaps, _super); - function Overlaps(json) { +exports.ExpressionDef = ExpressionDef; +var ExpressionRef = /** @class */ (function (_super) { + __extends(ExpressionRef, _super); + function ExpressionRef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; + _this.library = json.libraryName; return _this; } - Overlaps.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.overlaps(b, this.precision); - } - else { - return null; + ExpressionRef.prototype.exec = function (ctx) { + ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; + var value = ctx.get(this.name); + if (value instanceof expression_1.Expression) { + value = value.execute(ctx); } + return value; }; - return Overlaps; + return ExpressionRef; }(expression_1.Expression)); -exports.Overlaps = Overlaps; -var OverlapsAfter = /** @class */ (function (_super) { - __extends(OverlapsAfter, _super); - function OverlapsAfter(json) { +exports.ExpressionRef = ExpressionRef; +var FunctionDef = /** @class */ (function (_super) { + __extends(FunctionDef, _super); + function FunctionDef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; + _this.expression = (0, builder_1.build)(json.expression); + _this.parameters = json.operand; return _this; } - OverlapsAfter.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.overlapsAfter(b, this.precision); - } - else { - return null; - } + FunctionDef.prototype.exec = function (_ctx) { + return this; }; - return OverlapsAfter; + return FunctionDef; }(expression_1.Expression)); -exports.OverlapsAfter = OverlapsAfter; -var OverlapsBefore = /** @class */ (function (_super) { - __extends(OverlapsBefore, _super); - function OverlapsBefore(json) { +exports.FunctionDef = FunctionDef; +var FunctionRef = /** @class */ (function (_super) { + __extends(FunctionRef, _super); + function FunctionRef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; + _this.library = json.libraryName; return _this; } - OverlapsBefore.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.overlapsBefore(b, this.precision); + FunctionRef.prototype.exec = function (ctx) { + var functionDefs, child_ctx; + if (this.library) { + var lib = ctx.get(this.library); + functionDefs = lib ? lib.getFunction(this.name) : undefined; + var libCtx = ctx.getLibraryContext(this.library); + child_ctx = libCtx ? libCtx.childContext() : undefined; } else { - return null; - } - }; - return OverlapsBefore; -}(expression_1.Expression)); -exports.OverlapsBefore = OverlapsBefore; -// Delegated to by overloaded#Union -function doUnion(a, b) { - return a.union(b); -} -exports.doUnion = doUnion; -// Delegated to by overloaded#Except -function doExcept(a, b) { - if (a != null && b != null) { - return a.except(b); - } - else { - return null; - } -} -exports.doExcept = doExcept; -// Delegated to by overloaded#Intersect -function doIntersect(a, b) { - if (a != null && b != null) { - return a.intersect(b); - } - else { - return null; - } -} -exports.doIntersect = doIntersect; -var Width = /** @class */ (function (_super) { - __extends(Width, _super); - function Width(json) { - return _super.call(this, json) || this; - } - Width.prototype.exec = function (ctx) { - var interval = this.arg.execute(ctx); - if (interval == null) { - return null; - } - return interval.width(); - }; - return Width; -}(expression_1.Expression)); -exports.Width = Width; -var Size = /** @class */ (function (_super) { - __extends(Size, _super); - function Size(json) { - return _super.call(this, json) || this; - } - Size.prototype.exec = function (ctx) { - var interval = this.arg.execute(ctx); - if (interval == null) { - return null; + functionDefs = ctx.get(this.name); + child_ctx = ctx.childContext(); } - return interval.size(); - }; - return Size; -}(expression_1.Expression)); -exports.Size = Size; -var Start = /** @class */ (function (_super) { - __extends(Start, _super); - function Start(json) { - return _super.call(this, json) || this; - } - Start.prototype.exec = function (ctx) { - var interval = this.arg.execute(ctx); - if (interval == null) { - return null; + var args = this.execArgs(ctx); + // Filter out functions w/ wrong number of arguments. + functionDefs = functionDefs.filter(function (f) { return f.parameters.length === args.length; }); + // If there is still > 1 matching function, filter by argument types + if (functionDefs.length > 1) { + functionDefs = functionDefs.filter(function (f) { + var match = true; + for (var i = 0; i < args.length && match; i++) { + if (args[i] !== null) { + var operandTypeSpecifier = f.parameters[i].operandTypeSpecifier; + if (operandTypeSpecifier == null && f.parameters[i].operandType != null) { + // convert it to a NamedTypedSpecifier + operandTypeSpecifier = { + name: f.parameters[i].operandType, + type: 'NamedTypeSpecifier' + }; + } + match = ctx.matchesTypeSpecifier(args[i], operandTypeSpecifier); + } + } + return match; + }); } - var start = interval.start(); - // fix the timezoneOffset of minimum Datetime to match context offset - if (start && start.isDateTime && start.equals(math_1.MIN_DATETIME_VALUE)) { - start.timezoneOffset = ctx.getTimezoneOffset(); + // If there is still > 1 matching function, calculate a score based on quality of matches + if (functionDefs.length > 1) { + // TODO } - return start; - }; - return Start; -}(expression_1.Expression)); -exports.Start = Start; -var End = /** @class */ (function (_super) { - __extends(End, _super); - function End(json) { - return _super.call(this, json) || this; - } - End.prototype.exec = function (ctx) { - var interval = this.arg.execute(ctx); - if (interval == null) { - return null; + if (functionDefs.length === 0) { + throw new Error('no function with matching signature could be found'); } - var end = interval.end(); - // fix the timezoneOffset of maximum Datetime to match context offset - if (end && end.isDateTime && end.equals(math_1.MAX_DATETIME_VALUE)) { - end.timezoneOffset = ctx.getTimezoneOffset(); + // By this point, we should have only one function, but until implementation is completed, + // use the last one (no matter how many still remain) + var functionDef = functionDefs[functionDefs.length - 1]; + for (var i = 0; i < functionDef.parameters.length; i++) { + child_ctx.set(functionDef.parameters[i].name, args[i]); } - return end; + return functionDef.expression.execute(child_ctx); }; - return End; + return FunctionRef; }(expression_1.Expression)); -exports.End = End; -var Starts = /** @class */ (function (_super) { - __extends(Starts, _super); - function Starts(json) { +exports.FunctionRef = FunctionRef; +var OperandRef = /** @class */ (function (_super) { + __extends(OperandRef, _super); + function OperandRef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; return _this; } - Starts.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.starts(b, this.precision); - } - else { - return null; - } + OperandRef.prototype.exec = function (ctx) { + return ctx.get(this.name); }; - return Starts; + return OperandRef; }(expression_1.Expression)); -exports.Starts = Starts; -var Ends = /** @class */ (function (_super) { - __extends(Ends, _super); - function Ends(json) { +exports.OperandRef = OperandRef; +var IdentifierRef = /** @class */ (function (_super) { + __extends(IdentifierRef, _super); + function IdentifierRef(json) { var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + _this.name = json.name; + _this.library = json.libraryName; return _this; } - Ends.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.ends(b, this.precision); - } - else { - return null; - } - }; - return Ends; -}(expression_1.Expression)); -exports.Ends = Ends; -function intervalListType(intervals) { - // Returns one of null, 'time', 'date', 'datetime', 'quantity', 'integer', 'decimal' or 'mismatch' - var type = null; - for (var _i = 0, intervals_1 = intervals; _i < intervals_1.length; _i++) { - var itvl = intervals_1[_i]; - if (itvl == null) { - continue; - } - if (itvl.low == null && itvl.high == null) { - //can't really determine type from this - continue; - } - // if one end is null (but not both), the type can be determined from the other end - var low = itvl.low != null ? itvl.low : itvl.high; - var high = itvl.high != null ? itvl.high : itvl.low; - if (low.isTime && low.isTime() && high.isTime && high.isTime()) { - if (type == null) { - type = 'time'; - } - else if (type === 'time') { - continue; - } - else { - return 'mismatch'; - } - // if an interval mixes date and datetime, type is datetime (for implicit conversion) - } - else if ((low.isDateTime || high.isDateTime) && - (low.isDateTime || low.isDate) && - (high.isDateTime || high.isDate)) { - if (type == null || type === 'date') { - type = 'datetime'; - } - else if (type === 'datetime') { - continue; - } - else { - return 'mismatch'; - } - } - else if (low.isDate && high.isDate) { - if (type == null) { - type = 'date'; - } - else if (type === 'date' || type === 'datetime') { - continue; - } - else { - return 'mismatch'; - } - } - else if (low.isQuantity && high.isQuantity) { - if (type == null) { - type = 'quantity'; - } - else if (type === 'quantity') { - continue; - } - else { - return 'mismatch'; - } - } - else if (Number.isInteger(low) && Number.isInteger(high)) { - if (type == null) { - type = 'integer'; - } - else if (type === 'integer' || type === 'decimal') { - continue; - } - else { - return 'mismatch'; + IdentifierRef.prototype.exec = function (ctx) { + // TODO: Technically, the ELM Translator should never output one of these + // but this code is needed since it does, as a work-around to get queries + // to work properly when sorting by a field in a tuple + var lib = this.library ? ctx.get(this.library) : undefined; + var val = lib ? lib.get(this.name) : ctx.get(this.name); + if (val == null) { + var parts = this.name.split('.'); + val = ctx.get(parts[0]); + if (val != null && parts.length > 1) { + var curr_obj = val; + for (var _i = 0, _a = parts.slice(1); _i < _a.length; _i++) { + var part = _a[_i]; + // _obj = curr_obj?[part] ? curr_obj?.get?(part) + // curr_obj = if _obj instanceof Function then _obj.call(curr_obj) else _obj + var _obj = void 0; + if (curr_obj != null) { + _obj = curr_obj[part]; + if (_obj === undefined && typeof curr_obj.get === 'function') { + _obj = curr_obj.get(part); + } + } + curr_obj = _obj instanceof Function ? _obj.call(curr_obj) : _obj; + } + val = curr_obj; } } - else if (typeof low === 'number' && typeof high === 'number') { - if (type == null || type === 'integer') { - type = 'decimal'; - } - else if (type === 'decimal') { - continue; - } - else { - return 'mismatch'; - } - //if we are here ends are mismatched + if (val instanceof Function) { + return val.call(ctx.context_values); } else { - return 'mismatch'; + return val; } - } - return type; -} -var Expand = /** @class */ (function (_super) { - __extends(Expand, _super); - function Expand(json) { + }; + return IdentifierRef; +}(expression_1.Expression)); +exports.IdentifierRef = IdentifierRef; + +},{"./builder":53,"./expression":59}],76:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ReplaceMatches = exports.EndsWith = exports.StartsWith = exports.Substring = exports.Matches = exports.LastPositionOf = exports.PositionOf = exports.Lower = exports.Upper = exports.SplitOnMatches = exports.Split = exports.Combine = exports.Concatenate = void 0; +var expression_1 = require("./expression"); +var builder_1 = require("./builder"); +var Concatenate = /** @class */ (function (_super) { + __extends(Concatenate, _super); + function Concatenate(json) { return _super.call(this, json) || this; - } - Expand.prototype.exec = function (ctx) { - // expand(argument List>, per Quantity) List> - var defaultPer, expandFunction; - var _a = this.execArgs(ctx), intervals = _a[0], per = _a[1]; - // CQL 1.5 introduced an overload to allow singular intervals; make it a list so we can use the same logic for either overload - if (!Array.isArray(intervals)) { - intervals = [intervals]; - } - var type = intervalListType(intervals); - if (type === 'mismatch') { - throw new Error('List of intervals contains mismatched types.'); - } - if (type == null) { - return null; - } - // this step collapses overlaps, and also returns a clone of intervals so we can feel free to mutate - intervals = collapseIntervals(intervals, per); - if (intervals.length === 0) { - return []; - } - if (['time', 'date', 'datetime'].includes(type)) { - expandFunction = this.expandDTishInterval; - defaultPer = function (interval) { return new quantity_1.Quantity(1, interval.low.getPrecision()); }; - } - else if (['quantity'].includes(type)) { - expandFunction = this.expandQuantityInterval; - defaultPer = function (interval) { return new quantity_1.Quantity(1, interval.low.unit); }; - } - else if (['integer', 'decimal'].includes(type)) { - expandFunction = this.expandNumericInterval; - defaultPer = function (_interval) { return new quantity_1.Quantity(1, '1'); }; + } + Concatenate.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args.some(function (x) { return x == null; })) { + return null; } else { - throw new Error('Interval list type not yet supported.'); + return args.reduce(function (x, y) { return x + y; }); } - var results = []; - for (var _i = 0, intervals_2 = intervals; _i < intervals_2.length; _i++) { - var interval = intervals_2[_i]; - if (interval == null) { - continue; - } - // We do not support open ended intervals since result would likely be too long - if (interval.low == null || interval.high == null) { + }; + return Concatenate; +}(expression_1.Expression)); +exports.Concatenate = Concatenate; +var Combine = /** @class */ (function (_super) { + __extends(Combine, _super); + function Combine(json) { + var _this = _super.call(this, json) || this; + _this.source = (0, builder_1.build)(json.source); + _this.separator = (0, builder_1.build)(json.separator); + return _this; + } + Combine.prototype.exec = function (ctx) { + var source = this.source.execute(ctx); + var separator = this.separator != null ? this.separator.execute(ctx) : ''; + if (source == null) { + return null; + } + else { + var filteredArray = source.filter(function (x) { return x != null; }); + if (filteredArray.length === 0) { return null; } - if (type === 'datetime') { - //support for implicitly converting dates to datetime - interval.low = interval.low.getDateTime(); - interval.high = interval.high.getDateTime(); - } - per = per != null ? per : defaultPer(interval); - var items = expandFunction.call(this, interval, per); - if (items === null) { - return null; + else { + return filteredArray.join(separator); } - results.push.apply(results, (items || [])); } - return results; }; - Expand.prototype.expandDTishInterval = function (interval, per) { - per.unit = (0, units_1.convertToCQLDateUnit)(per.unit); - if (per.unit === 'week') { - per.value *= 7; - per.unit = 'day'; - } - // Precision Checks - // return null if precision not applicable (e.g. gram, or minutes for dates) - if (!interval.low.constructor.FIELDS.includes(per.unit)) { - return null; - } - // open interval with null boundaries do not contribute to output - // closed interval with null boundaries are not allowed for performance reasons - if (interval.low == null || interval.high == null) { - return null; - } - var low = interval.lowClosed ? interval.low : interval.low.successor(); - var high = interval.highClosed ? interval.high : interval.high.predecessor(); - if (low.after(high)) { - return []; - } - if (interval.low.isLessPrecise(per.unit) || interval.high.isLessPrecise(per.unit)) { - return []; - } - var current_low = low; - var results = []; - low = this.truncateToPrecision(low, per.unit); - high = this.truncateToPrecision(high, per.unit); - var current_high = current_low.add(per.value, per.unit).predecessor(); - var intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); - while (intervalToAdd.high.sameOrBefore(high)) { - results.push(intervalToAdd); - current_low = current_low.add(per.value, per.unit); - current_high = current_low.add(per.value, per.unit).predecessor(); - intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); + return Combine; +}(expression_1.Expression)); +exports.Combine = Combine; +var Split = /** @class */ (function (_super) { + __extends(Split, _super); + function Split(json) { + var _this = _super.call(this, json) || this; + _this.stringToSplit = (0, builder_1.build)(json.stringToSplit); + _this.separator = (0, builder_1.build)(json.separator); + return _this; + } + Split.prototype.exec = function (ctx) { + var stringToSplit = this.stringToSplit.execute(ctx); + var separator = this.separator.execute(ctx); + if (stringToSplit && separator) { + return stringToSplit.split(separator); } - return results; + return stringToSplit ? [stringToSplit] : null; }; - Expand.prototype.truncateToPrecision = function (value, unit) { - // If interval boundaries are more precise than per quantity, truncate to - // the precision specified by the per - var shouldTruncate = false; - for (var _i = 0, _a = value.constructor.FIELDS; _i < _a.length; _i++) { - var field = _a[_i]; - if (shouldTruncate) { - value[field] = null; - } - if (field === unit) { - // Start truncating after this unit - shouldTruncate = true; - } + return Split; +}(expression_1.Expression)); +exports.Split = Split; +var SplitOnMatches = /** @class */ (function (_super) { + __extends(SplitOnMatches, _super); + function SplitOnMatches(json) { + var _this = _super.call(this, json) || this; + _this.stringToSplit = (0, builder_1.build)(json.stringToSplit); + _this.separatorPattern = (0, builder_1.build)(json.separatorPattern); + return _this; + } + SplitOnMatches.prototype.exec = function (ctx) { + var stringToSplit = this.stringToSplit.execute(ctx); + var separatorPattern = this.separatorPattern.execute(ctx); + if (stringToSplit && separatorPattern) { + return stringToSplit.split(new RegExp(separatorPattern)); } - return value; + return stringToSplit ? [stringToSplit] : null; }; - Expand.prototype.expandQuantityInterval = function (interval, per) { - // we want to convert everything to the more precise of the interval.low or per - var result_units; - var res = (0, units_1.compareUnits)(interval.low.unit, per.unit); - if (res != null && res > 0) { - //interval.low.unit is 'bigger' aka les precise - result_units = per.unit; + return SplitOnMatches; +}(expression_1.Expression)); +exports.SplitOnMatches = SplitOnMatches; +// Length is completely handled by overloaded#Length +var Upper = /** @class */ (function (_super) { + __extends(Upper, _super); + function Upper(json) { + return _super.call(this, json) || this; + } + Upper.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return arg.toUpperCase(); } else { - result_units = interval.low.unit; - } - var low_value = (0, units_1.convertUnit)(interval.low.value, interval.low.unit, result_units); - var high_value = (0, units_1.convertUnit)(interval.high.value, interval.high.unit, result_units); - var per_value = (0, units_1.convertUnit)(per.value, per.unit, result_units); - // return null if unit conversion failed, must have mismatched units - if (!(low_value != null && high_value != null && per_value != null)) { return null; } - var results = this.makeNumericIntervalList(low_value, high_value, interval.lowClosed, interval.highClosed, per_value); - for (var _i = 0, results_1 = results; _i < results_1.length; _i++) { - var itvl = results_1[_i]; - itvl.low = new quantity_1.Quantity(itvl.low, result_units); - itvl.high = new quantity_1.Quantity(itvl.high, result_units); - } - return results; }; - Expand.prototype.expandNumericInterval = function (interval, per) { - if (per.unit !== '1' && per.unit !== '') { + return Upper; +}(expression_1.Expression)); +exports.Upper = Upper; +var Lower = /** @class */ (function (_super) { + __extends(Lower, _super); + function Lower(json) { + return _super.call(this, json) || this; + } + Lower.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return arg.toLowerCase(); + } + else { return null; } - return this.makeNumericIntervalList(interval.low, interval.high, interval.lowClosed, interval.highClosed, per.value); }; - Expand.prototype.makeNumericIntervalList = function (low, high, lowClosed, highClosed, perValue) { - // If the per value is a Decimal (has a .), 8 decimal places are appropriate - // Integers should have 0 Decimal places - var perIsDecimal = perValue.toString().includes('.'); - var decimalPrecision = perIsDecimal ? 8 : 0; - low = lowClosed ? low : (0, math_1.successor)(low); - high = highClosed ? high : (0, math_1.predecessor)(high); - // If the interval boundaries are more precise than the per quantity, the - // more precise values will be truncated to the precision specified by the - // per quantity. - low = truncateDecimal(low, decimalPrecision); - high = truncateDecimal(high, decimalPrecision); - if (low > high) { - return []; - } - if (low == null || high == null) { - return []; + return Lower; +}(expression_1.Expression)); +exports.Lower = Lower; +// Indexer is completely handled by overloaded#Indexer +var PositionOf = /** @class */ (function (_super) { + __extends(PositionOf, _super); + function PositionOf(json) { + var _this = _super.call(this, json) || this; + _this.pattern = (0, builder_1.build)(json.pattern); + _this.string = (0, builder_1.build)(json.string); + return _this; + } + PositionOf.prototype.exec = function (ctx) { + var pattern = this.pattern.execute(ctx); + var string = this.string.execute(ctx); + if (pattern == null || string == null) { + return null; } - var perUnitSize = perIsDecimal ? 0.00000001 : 1; - if (low === high && - Number.isInteger(low) && - Number.isInteger(high) && - !Number.isInteger(perValue)) { - high = parseFloat((high + 1).toFixed(decimalPrecision)); + else { + return string.indexOf(pattern); } - var current_low = low; - var results = []; - if (perValue > high - low + perUnitSize) { - return []; + }; + return PositionOf; +}(expression_1.Expression)); +exports.PositionOf = PositionOf; +var LastPositionOf = /** @class */ (function (_super) { + __extends(LastPositionOf, _super); + function LastPositionOf(json) { + var _this = _super.call(this, json) || this; + _this.pattern = (0, builder_1.build)(json.pattern); + _this.string = (0, builder_1.build)(json.string); + return _this; + } + LastPositionOf.prototype.exec = function (ctx) { + var pattern = this.pattern.execute(ctx); + var string = this.string.execute(ctx); + if (pattern == null || string == null) { + return null; } - var current_high = parseFloat((current_low + perValue - perUnitSize).toFixed(decimalPrecision)); - var intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); - while (intervalToAdd.high <= high) { - results.push(intervalToAdd); - current_low = parseFloat((current_low + perValue).toFixed(decimalPrecision)); - current_high = parseFloat((current_low + perValue - perUnitSize).toFixed(decimalPrecision)); - intervalToAdd = new dtivl.Interval(current_low, current_high, true, true); + else { + return string.lastIndexOf(pattern); } - return results; }; - return Expand; + return LastPositionOf; }(expression_1.Expression)); -exports.Expand = Expand; -var Collapse = /** @class */ (function (_super) { - __extends(Collapse, _super); - function Collapse(json) { +exports.LastPositionOf = LastPositionOf; +var Matches = /** @class */ (function (_super) { + __extends(Matches, _super); + function Matches(json) { return _super.call(this, json) || this; } - Collapse.prototype.exec = function (ctx) { - // collapse(argument List>, per Quantity) List> - var _a = this.execArgs(ctx), intervals = _a[0], perWidth = _a[1]; - return collapseIntervals(intervals, perWidth); + Matches.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), string = _a[0], pattern = _a[1]; + if (string == null || pattern == null) { + return null; + } + return new RegExp('^' + pattern + '$').test(string); }; - return Collapse; + return Matches; }(expression_1.Expression)); -exports.Collapse = Collapse; -function collapseIntervals(intervals, perWidth) { - // Clone intervals so this function remains idempotent - var intervalsClone = []; - for (var _i = 0, intervals_3 = intervals; _i < intervals_3.length; _i++) { - var interval = intervals_3[_i]; - // The spec says to ignore null intervals - if (interval != null) { - intervalsClone.push(interval.copy()); - } - } - // If the list is null, return null - if (intervals == null) { - return null; - } - else if (intervalsClone.length <= 1) { - return intervalsClone; - } - else { - // If the per argument is null, the default unit interval for the point type - // of the intervals involved will be used (i.e. the interval that has a - // width equal to the result of the successor function for the point type). - if (perWidth == null) { - perWidth = intervalsClone[0].getPointSize(); - } - // sort intervalsClone by start - intervalsClone.sort(function (a, b) { - if (a.low && typeof a.low.before === 'function') { - if (b.low != null && a.low.before(b.low)) { - return -1; - } - if (b.low == null || a.low.after(b.low)) { - return 1; - } - } - else if (a.low != null && b.low != null) { - if (a.low < b.low) { - return -1; - } - if (a.low > b.low) { - return 1; - } - } - else if (a.low != null && b.low == null) { - return 1; - } - else if (a.low == null && b.low != null) { - return -1; - } - // if both lows are undefined, sort by high - if (a.high && typeof a.high.before === 'function') { - if (b.high == null || a.high.before(b.high)) { - return -1; - } - if (a.high.after(b.high)) { - return 1; - } - } - else if (a.high != null && b.high != null) { - if (a.high < b.high) { - return -1; - } - if (a.high > b.high) { - return 1; - } - } - else if (a.high != null && b.high == null) { - return -1; - } - else if (a.high == null && b.high != null) { - return 1; - } - return 0; - }); - // collapse intervals as necessary - var collapsedIntervals = []; - var a = intervalsClone.shift(); - var b = intervalsClone.shift(); - while (b) { - if (b.low && typeof b.low.durationBetween === 'function') { - // handle DateTimes using durationBetween - if (a.high != null ? a.high.sameOrAfter(b.low) : undefined) { - // overlap - if (b.high == null || b.high.after(a.high)) { - a.high = b.high; - } - } - else if ((a.high != null ? a.high.durationBetween(b.low, perWidth.unit).high : undefined) <= - perWidth.value) { - a.high = b.high; - } - else { - collapsedIntervals.push(a); - a = b; - } - } - else if (b.low && typeof b.low.sameOrBefore === 'function') { - if (a.high != null && b.low.sameOrBefore((0, quantity_1.doAddition)(a.high, perWidth))) { - if (b.high == null || b.high.after(a.high)) { - a.high = b.high; - } - } - else { - collapsedIntervals.push(a); - a = b; - } - } - else { - if (b.low - a.high <= perWidth.value) { - if (b.high > a.high || b.high == null) { - a.high = b.high; - } - } - else { - collapsedIntervals.push(a); - a = b; - } - } - b = intervalsClone.shift(); - } - collapsedIntervals.push(a); - return collapsedIntervals; +exports.Matches = Matches; +var Substring = /** @class */ (function (_super) { + __extends(Substring, _super); + function Substring(json) { + var _this = _super.call(this, json) || this; + _this.stringToSub = (0, builder_1.build)(json.stringToSub); + _this.startIndex = (0, builder_1.build)(json.startIndex); + _this.length = (0, builder_1.build)(json['length']); + return _this; } -} -function truncateDecimal(decimal, decimalPlaces) { - // like parseFloat().toFixed() but floor rather than round - // Needed for when per precision is less than the interval input precision - var re = new RegExp('^-?\\d+(?:.\\d{0,' + (decimalPlaces || -1) + '})?'); - return parseFloat(decimal.toString().match(re)[0]); -} - -},{"../datatypes/interval":60,"../datatypes/quantity":62,"../util/math":104,"../util/units":105,"./builder":67,"./expression":73}],78:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Library = void 0; -var expressions_1 = require("./expressions"); -var Library = /** @class */ (function () { - function Library(json, libraryManager) { - this.source = json; - // usings - var usingDefs = (json.library.usings && json.library.usings.def) || []; - this.usings = usingDefs - .filter(function (u) { return u.localIdentifier !== 'System'; }) - .map(function (u) { - return { name: u.localIdentifier, version: u.version }; - }); - // parameters - var paramDefs = (json.library.parameters && json.library.parameters.def) || []; - this.parameters = {}; - for (var _i = 0, paramDefs_1 = paramDefs; _i < paramDefs_1.length; _i++) { - var param = paramDefs_1[_i]; - this.parameters[param.name] = new expressions_1.ParameterDef(param); - } - // code systems - var csDefs = (json.library.codeSystems && json.library.codeSystems.def) || []; - this.codesystems = {}; - for (var _a = 0, csDefs_1 = csDefs; _a < csDefs_1.length; _a++) { - var codesystem = csDefs_1[_a]; - this.codesystems[codesystem.name] = new expressions_1.CodeSystemDef(codesystem); - } - // value sets - var vsDefs = (json.library.valueSets && json.library.valueSets.def) || []; - this.valuesets = {}; - for (var _b = 0, vsDefs_1 = vsDefs; _b < vsDefs_1.length; _b++) { - var valueset = vsDefs_1[_b]; - this.valuesets[valueset.name] = new expressions_1.ValueSetDef(valueset); - } - // codes - var codeDefs = (json.library.codes && json.library.codes.def) || []; - this.codes = {}; - for (var _c = 0, codeDefs_1 = codeDefs; _c < codeDefs_1.length; _c++) { - var code = codeDefs_1[_c]; - this.codes[code.name] = new expressions_1.CodeDef(code); + Substring.prototype.exec = function (ctx) { + var stringToSub = this.stringToSub.execute(ctx); + var startIndex = this.startIndex.execute(ctx); + var length = this.length != null ? this.length.execute(ctx) : null; + // According to spec: If stringToSub or startIndex is null, or startIndex is out of range, the result is null. + if (stringToSub == null || + startIndex == null || + startIndex < 0 || + startIndex >= stringToSub.length) { + return null; } - // concepts - var conceptDefs = (json.library.concepts && json.library.concepts.def) || []; - this.concepts = {}; - for (var _d = 0, conceptDefs_1 = conceptDefs; _d < conceptDefs_1.length; _d++) { - var concept = conceptDefs_1[_d]; - this.concepts[concept.name] = new expressions_1.ConceptDef(concept); + else if (length != null) { + return stringToSub.substr(startIndex, length); } - // expressions - var exprDefs = (json.library.statements && json.library.statements.def) || []; - this.expressions = {}; - this.functions = {}; - for (var _e = 0, exprDefs_1 = exprDefs; _e < exprDefs_1.length; _e++) { - var expr = exprDefs_1[_e]; - if (expr.type === 'FunctionDef') { - if (!this.functions[expr.name]) { - this.functions[expr.name] = []; - } - this.functions[expr.name].push(new expressions_1.FunctionDef(expr)); - } - else { - this.expressions[expr.name] = new expressions_1.ExpressionDef(expr); - } + else { + return stringToSub.substr(startIndex); } - // includes - var inclDefs = (json.library.includes && json.library.includes.def) || []; - this.includes = {}; - for (var _f = 0, inclDefs_1 = inclDefs; _f < inclDefs_1.length; _f++) { - var incl = inclDefs_1[_f]; - if (libraryManager) { - this.includes[incl.localIdentifier] = libraryManager.resolve(incl.path, incl.version); - } + }; + return Substring; +}(expression_1.Expression)); +exports.Substring = Substring; +var StartsWith = /** @class */ (function (_super) { + __extends(StartsWith, _super); + function StartsWith(json) { + return _super.call(this, json) || this; + } + StartsWith.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args.some(function (x) { return x == null; })) { + return null; } - // Include codesystems from includes - for (var iProperty in this.includes) { - if (this.includes[iProperty] && this.includes[iProperty].codesystems) { - for (var csProperty in this.includes[iProperty].codesystems) { - this.codesystems[csProperty] = this.includes[iProperty].codesystems[csProperty]; - } - } + else { + return args[0].slice(0, args[1].length) === args[1]; } - } - Library.prototype.getFunction = function (identifier) { - return this.functions[identifier]; - }; - Library.prototype.get = function (identifier) { - return (this.expressions[identifier] || this.includes[identifier] || this.getFunction(identifier)); }; - Library.prototype.getValueSet = function (identifier, libraryName) { - if (this.valuesets[identifier] != null) { - return this.valuesets[identifier]; + return StartsWith; +}(expression_1.Expression)); +exports.StartsWith = StartsWith; +var EndsWith = /** @class */ (function (_super) { + __extends(EndsWith, _super); + function EndsWith(json) { + return _super.call(this, json) || this; + } + EndsWith.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args.some(function (x) { return x == null; })) { + return null; + } + else { + return args[1] === '' || args[0].slice(-args[1].length) === args[1]; } - return this.includes[libraryName] != null - ? this.includes[libraryName].valuesets[identifier] - : undefined; - }; - Library.prototype.getCodeSystem = function (identifier) { - return this.codesystems[identifier]; - }; - Library.prototype.getCode = function (identifier) { - return this.codes[identifier]; - }; - Library.prototype.getConcept = function (identifier) { - return this.concepts[identifier]; }; - Library.prototype.getParameter = function (name) { - return this.parameters[name]; + return EndsWith; +}(expression_1.Expression)); +exports.EndsWith = EndsWith; +var ReplaceMatches = /** @class */ (function (_super) { + __extends(ReplaceMatches, _super); + function ReplaceMatches(json) { + return _super.call(this, json) || this; + } + ReplaceMatches.prototype.exec = function (ctx) { + var args = this.execArgs(ctx); + if (args.some(function (x) { return x == null; })) { + return null; + } + else { + return args[0].replace(new RegExp(args[1], 'g'), args[2]); + } }; - return Library; -}()); -exports.Library = Library; + return ReplaceMatches; +}(expression_1.Expression)); +exports.ReplaceMatches = ReplaceMatches; -},{"./expressions":74}],79:[function(require,module,exports){ +},{"./builder":53,"./expression":59}],77:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -28594,663 +25638,857 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.Slice = exports.Last = exports.First = exports.Current = exports.Distinct = exports.Flatten = exports.ForEach = exports.doProperIncludes = exports.doIncludes = exports.doContains = exports.IndexOf = exports.ToList = exports.SingletonFrom = exports.Filter = exports.Times = exports.doIntersect = exports.doExcept = exports.doUnion = exports.Exists = exports.List = void 0; +exports.TupleElementDefinition = exports.TupleElement = exports.Tuple = exports.Property = void 0; var expression_1 = require("./expression"); var builder_1 = require("./builder"); -var util_1 = require("../util/util"); -var comparison_1 = require("../util/comparison"); -var List = /** @class */ (function (_super) { - __extends(List, _super); - function List(json) { +var Property = /** @class */ (function (_super) { + __extends(Property, _super); + function Property(json) { var _this = _super.call(this, json) || this; - _this.elements = (0, builder_1.build)(json.element) || []; + _this.scope = json.scope; + _this.source = (0, builder_1.build)(json.source); + _this.path = json.path; return _this; } - Object.defineProperty(List.prototype, "isList", { + Property.prototype.exec = function (ctx) { + var obj = this.scope != null ? ctx.get(this.scope) : this.source; + if (obj instanceof expression_1.Expression) { + obj = obj.execute(ctx); + } + var val = getPropertyFromObject(obj, this.path); + if (val == null) { + var parts = this.path.split('.'); + var curr_obj = obj; + for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) { + var part = parts_1[_i]; + var _obj = getPropertyFromObject(curr_obj, part); + curr_obj = _obj instanceof Function ? _obj.call(curr_obj) : _obj; + } + val = curr_obj != null ? curr_obj : null; // convert undefined to null + } + if (val instanceof Function) { + return val.call(obj); + } + else { + return val; + } + }; + return Property; +}(expression_1.Expression)); +exports.Property = Property; +function getPropertyFromObject(obj, path) { + var val; + if (obj != null) { + val = obj[path]; + if (val === undefined && typeof obj.get === 'function') { + val = obj.get(path); + } + } + return val; +} +var Tuple = /** @class */ (function (_super) { + __extends(Tuple, _super); + function Tuple(json) { + var _this = _super.call(this, json) || this; + var elements = json.element != null ? json.element : []; + _this.elements = elements.map(function (el) { + return { + name: el.name, + value: (0, builder_1.build)(el.value) + }; + }); + return _this; + } + Object.defineProperty(Tuple.prototype, "isTuple", { get: function () { return true; }, enumerable: false, configurable: true }); - List.prototype.exec = function (ctx) { - return this.elements.map(function (item) { return item.execute(ctx); }); - }; - return List; -}(expression_1.Expression)); -exports.List = List; -var Exists = /** @class */ (function (_super) { - __extends(Exists, _super); - function Exists(json) { - return _super.call(this, json) || this; - } - Exists.prototype.exec = function (ctx) { - var list = this.execArgs(ctx); - // if list exists and has non empty length we need to make sure it isnt just full of nulls - if (list) { - return list.some(function (item) { return item != null; }); + Tuple.prototype.exec = function (ctx) { + var val = {}; + for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { + var el = _a[_i]; + val[el.name] = el.value != null ? el.value.execute(ctx) : undefined; } - return false; + return val; }; - return Exists; + return Tuple; }(expression_1.Expression)); -exports.Exists = Exists; -// Equal is completely handled by overloaded#Equal -// NotEqual is completely handled by overloaded#Equal -// Delegated to by overloaded#Union -function doUnion(a, b) { - var distinct = doDistinct(a.concat(b)); - return removeDuplicateNulls(distinct); -} -exports.doUnion = doUnion; -// Delegated to by overloaded#Except -function doExcept(a, b) { - var distinct = doDistinct(a); - var setList = removeDuplicateNulls(distinct); - return setList.filter(function (item) { return !doContains(b, item, true); }); -} -exports.doExcept = doExcept; -// Delegated to by overloaded#Intersect -function doIntersect(a, b) { - var distinct = doDistinct(a); - var setList = removeDuplicateNulls(distinct); - return setList.filter(function (item) { return doContains(b, item, true); }); -} -exports.doIntersect = doIntersect; -// ELM-only, not a product of CQL -var Times = /** @class */ (function (_super) { - __extends(Times, _super); - function Times() { +exports.Tuple = Tuple; +var TupleElement = /** @class */ (function (_super) { + __extends(TupleElement, _super); + function TupleElement() { return _super !== null && _super.apply(this, arguments) || this; } - return Times; + return TupleElement; }(expression_1.UnimplementedExpression)); -exports.Times = Times; -// ELM-only, not a product of CQL -var Filter = /** @class */ (function (_super) { - __extends(Filter, _super); - function Filter() { +exports.TupleElement = TupleElement; +var TupleElementDefinition = /** @class */ (function (_super) { + __extends(TupleElementDefinition, _super); + function TupleElementDefinition() { return _super !== null && _super.apply(this, arguments) || this; } - return Filter; + return TupleElementDefinition; }(expression_1.UnimplementedExpression)); -exports.Filter = Filter; -var SingletonFrom = /** @class */ (function (_super) { - __extends(SingletonFrom, _super); - function SingletonFrom(json) { - return _super.call(this, json) || this; +exports.TupleElementDefinition = TupleElementDefinition; + +},{"./builder":53,"./expression":59}],78:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TupleTypeSpecifier = exports.NamedTypeSpecifier = exports.ListTypeSpecifier = exports.IntervalTypeSpecifier = exports.Is = exports.CanConvertQuantity = exports.ConvertQuantity = exports.ConvertsToTime = exports.ConvertsToString = exports.ConvertsToRatio = exports.ConvertsToQuantity = exports.ConvertsToInteger = exports.ConvertsToDecimal = exports.ConvertsToDateTime = exports.ConvertsToDate = exports.ConvertsToBoolean = exports.Convert = exports.ToTime = exports.ToString = exports.ToRatio = exports.ToQuantity = exports.ToInteger = exports.ToDecimal = exports.ToDateTime = exports.ToDate = exports.ToConcept = exports.ToBoolean = exports.As = void 0; +var expression_1 = require("./expression"); +var datetime_1 = require("../datatypes/datetime"); +var clinical_1 = require("../datatypes/clinical"); +var quantity_1 = require("../datatypes/quantity"); +var math_1 = require("../util/math"); +var util_1 = require("../util/util"); +var ratio_1 = require("../datatypes/ratio"); +var uncertainty_1 = require("../datatypes/uncertainty"); +// TODO: Casting and Conversion needs unit tests! +var As = /** @class */ (function (_super) { + __extends(As, _super); + function As(json) { + var _this = _super.call(this, json) || this; + if (json.asTypeSpecifier) { + _this.asTypeSpecifier = json.asTypeSpecifier; + } + else if (json.asType) { + // convert it to a NamedTypedSpecifier + _this.asTypeSpecifier = { + name: json.asType, + type: 'NamedTypeSpecifier' + }; + } + _this.strict = json.strict != null ? json.strict : false; + return _this; } - SingletonFrom.prototype.exec = function (ctx) { + As.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); - if (arg != null && arg.length > 1) { - throw new Error("IllegalArgument: 'SingletonFrom' requires a 0 or 1 arg array"); + // If it is null, return null + if (arg == null) { + return null; } - else if (arg != null && arg.length === 1) { - return arg[0]; + if (ctx.matchesTypeSpecifier(arg, this.asTypeSpecifier)) { + // TODO: request patient source to change type identification + return arg; + } + else if (this.strict) { + var argTypeString = specifierToString(guessSpecifierType(arg)); + var asTypeString = specifierToString(this.asTypeSpecifier); + throw new Error("Cannot cast ".concat(argTypeString, " as ").concat(asTypeString)); } else { return null; } }; - return SingletonFrom; + return As; }(expression_1.Expression)); -exports.SingletonFrom = SingletonFrom; -var ToList = /** @class */ (function (_super) { - __extends(ToList, _super); - function ToList(json) { +exports.As = As; +var ToBoolean = /** @class */ (function (_super) { + __extends(ToBoolean, _super); + function ToBoolean(json) { return _super.call(this, json) || this; } - ToList.prototype.exec = function (ctx) { + ToBoolean.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); if (arg != null) { - return [arg]; + var strArg = arg.toString().toLowerCase(); + if (['true', 't', 'yes', 'y', '1'].includes(strArg)) { + return true; + } + else if (['false', 'f', 'no', 'n', '0'].includes(strArg)) { + return false; + } + } + return null; + }; + return ToBoolean; +}(expression_1.Expression)); +exports.ToBoolean = ToBoolean; +var ToConcept = /** @class */ (function (_super) { + __extends(ToConcept, _super); + function ToConcept(json) { + return _super.call(this, json) || this; + } + ToConcept.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return new clinical_1.Concept([arg], arg.display); } else { - return []; + return null; } }; - return ToList; + return ToConcept; }(expression_1.Expression)); -exports.ToList = ToList; -var IndexOf = /** @class */ (function (_super) { - __extends(IndexOf, _super); - function IndexOf(json) { - var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - _this.element = (0, builder_1.build)(json.element); - return _this; +exports.ToConcept = ToConcept; +var ToDate = /** @class */ (function (_super) { + __extends(ToDate, _super); + function ToDate(json) { + return _super.call(this, json) || this; } - IndexOf.prototype.exec = function (ctx) { - var index; - var src = this.source.execute(ctx); - var el = this.element.execute(ctx); - if (src == null || el == null) { + ToDate.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg == null) { return null; } - for (var i = 0; i < src.length; i++) { - var itm = src[i]; - if ((0, comparison_1.equals)(itm, el)) { - index = i; - break; - } - } - if (index != null) { - return index; + else if (arg.isDateTime) { + return arg.getDate(); } else { - return -1; + return datetime_1.Date.parse(arg.toString()); } }; - return IndexOf; + return ToDate; }(expression_1.Expression)); -exports.IndexOf = IndexOf; -// Indexer is completely handled by overloaded#Indexer -// Delegated to by overloaded#Contains and overloaded#In -function doContains(container, item, nullEquivalence) { - if (nullEquivalence === void 0) { nullEquivalence = false; } - return container.some(function (element) { return (0, comparison_1.equals)(element, item) || (nullEquivalence && element == null && item == null); }); -} -exports.doContains = doContains; -// Delegated to by overloaded#Includes and overloaded@IncludedIn -function doIncludes(list, sublist) { - return sublist.every(function (x) { return doContains(list, x); }); -} -exports.doIncludes = doIncludes; -// Delegated to by overloaded#ProperIncludes and overloaded@ProperIncludedIn -function doProperIncludes(list, sublist) { - return list.length > sublist.length && doIncludes(list, sublist); -} -exports.doProperIncludes = doProperIncludes; -// ELM-only, not a product of CQL -var ForEach = /** @class */ (function (_super) { - __extends(ForEach, _super); - function ForEach() { - return _super !== null && _super.apply(this, arguments) || this; - } - return ForEach; -}(expression_1.UnimplementedExpression)); -exports.ForEach = ForEach; -var Flatten = /** @class */ (function (_super) { - __extends(Flatten, _super); - function Flatten(json) { +exports.ToDate = ToDate; +var ToDateTime = /** @class */ (function (_super) { + __extends(ToDateTime, _super); + function ToDateTime(json) { return _super.call(this, json) || this; } - Flatten.prototype.exec = function (ctx) { + ToDateTime.prototype.exec = function (ctx) { var arg = this.execArgs(ctx); - if ((0, util_1.typeIsArray)(arg) && arg.every(function (x) { return (0, util_1.typeIsArray)(x); })) { - return arg.reduce(function (x, y) { return x.concat(y); }, []); + if (arg == null) { + return null; + } + else if (arg.isDate) { + return arg.getDateTime(); } else { - return arg; + return datetime_1.DateTime.parse(arg.toString()); } }; - return Flatten; + return ToDateTime; }(expression_1.Expression)); -exports.Flatten = Flatten; -var Distinct = /** @class */ (function (_super) { - __extends(Distinct, _super); - function Distinct(json) { +exports.ToDateTime = ToDateTime; +var ToDecimal = /** @class */ (function (_super) { + __extends(ToDecimal, _super); + function ToDecimal(json) { return _super.call(this, json) || this; } - Distinct.prototype.exec = function (ctx) { - var result = this.execArgs(ctx); - if (result == null) { - return null; + ToDecimal.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + if (arg.isUncertainty) { + var low = (0, math_1.limitDecimalPrecision)(parseFloat(arg.low.toString())); + var high = (0, math_1.limitDecimalPrecision)(parseFloat(arg.high.toString())); + return new uncertainty_1.Uncertainty(low, high); + } + else { + var decimal = (0, math_1.limitDecimalPrecision)(parseFloat(arg.toString())); + if ((0, math_1.isValidDecimal)(decimal)) { + return decimal; + } + } } - return doDistinct(result); + return null; }; - return Distinct; + return ToDecimal; }(expression_1.Expression)); -exports.Distinct = Distinct; -function doDistinct(list) { - var distinct = []; - list.forEach(function (item) { - var isNew = distinct.every(function (seenItem) { return !(0, comparison_1.equals)(item, seenItem); }); - if (isNew) { - distinct.push(item); - } - }); - return removeDuplicateNulls(distinct); -} -function removeDuplicateNulls(list) { - // Remove duplicate null elements - var firstNullFound = false; - var setList = []; - for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { - var item = list_1[_i]; - if (item !== null) { - setList.push(item); +exports.ToDecimal = ToDecimal; +var ToInteger = /** @class */ (function (_super) { + __extends(ToInteger, _super); + function ToInteger(json) { + return _super.call(this, json) || this; + } + ToInteger.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (typeof arg === 'string') { + var integer = parseInt(arg); + if ((0, math_1.isValidInteger)(integer)) { + return integer; + } } - else if (item === null && !firstNullFound) { - setList.push(item); - firstNullFound = true; + else if (typeof arg === 'boolean') { + return arg ? 1 : 0; } + return null; + }; + return ToInteger; +}(expression_1.Expression)); +exports.ToInteger = ToInteger; +var ToQuantity = /** @class */ (function (_super) { + __extends(ToQuantity, _super); + function ToQuantity(json) { + return _super.call(this, json) || this; } - return setList; -} -// ELM-only, not a product of CQL -var Current = /** @class */ (function (_super) { - __extends(Current, _super); - function Current() { - return _super !== null && _super.apply(this, arguments) || this; - } - return Current; -}(expression_1.UnimplementedExpression)); -exports.Current = Current; -var First = /** @class */ (function (_super) { - __extends(First, _super); - function First(json) { - var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - return _this; + ToQuantity.prototype.exec = function (ctx) { + return this.convertValue(this.execArgs(ctx)); + }; + ToQuantity.prototype.convertValue = function (val) { + if (val == null) { + return null; + } + else if (typeof val === 'number') { + return new quantity_1.Quantity(val, '1'); + } + else if (val.isRatio) { + // numerator and denominator are guaranteed non-null + return val.numerator.dividedBy(val.denominator); + } + else if (val.isUncertainty) { + return new uncertainty_1.Uncertainty(this.convertValue(val.low), this.convertValue(val.high)); + } + else { + // it's a string or something else we'll try to parse as a string + return (0, quantity_1.parseQuantity)(val.toString()); + } + }; + return ToQuantity; +}(expression_1.Expression)); +exports.ToQuantity = ToQuantity; +var ToRatio = /** @class */ (function (_super) { + __extends(ToRatio, _super); + function ToRatio(json) { + return _super.call(this, json) || this; } - First.prototype.exec = function (ctx) { - var src = this.source.exec(ctx); - if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) { - return src[0]; + ToRatio.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + // Argument will be of form ':' + var denominator = void 0, numerator = void 0; + try { + // String will be split into an array. Numerator will be at index 1, Denominator will be at index 4 + var splitRatioString = arg + .toString() + .match(/^(\d+(\.\d+)?\s*('.+')?)\s*:\s*(\d+(\.\d+)?\s*('.+')?)$/); + if (splitRatioString == null) { + return null; + } + numerator = (0, quantity_1.parseQuantity)(splitRatioString[1]); + denominator = (0, quantity_1.parseQuantity)(splitRatioString[4]); + } + catch (error) { + // If the input string is not formatted correctly, or cannot be + // interpreted as a valid Quantity value, the result is null. + return null; + } + // The value element of a Quantity must be present. + if (numerator == null || denominator == null) { + return null; + } + return new ratio_1.Ratio(numerator, denominator); } else { return null; } }; - return First; + return ToRatio; }(expression_1.Expression)); -exports.First = First; -var Last = /** @class */ (function (_super) { - __extends(Last, _super); - function Last(json) { - var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - return _this; +exports.ToRatio = ToRatio; +var ToString = /** @class */ (function (_super) { + __extends(ToString, _super); + function ToString(json) { + return _super.call(this, json) || this; } - Last.prototype.exec = function (ctx) { - var src = this.source.exec(ctx); - if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) { - return src[src.length - 1]; + ToString.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + return arg.toString(); } else { return null; } }; - return Last; + return ToString; }(expression_1.Expression)); -exports.Last = Last; -var Slice = /** @class */ (function (_super) { - __extends(Slice, _super); - function Slice(json) { - var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - _this.startIndex = (0, builder_1.build)(json.startIndex); - _this.endIndex = (0, builder_1.build)(json.endIndex); - return _this; +exports.ToString = ToString; +var ToTime = /** @class */ (function (_super) { + __extends(ToTime, _super); + function ToTime(json) { + return _super.call(this, json) || this; } - Slice.prototype.exec = function (ctx) { - var src = this.source.exec(ctx); - if (src != null && (0, util_1.typeIsArray)(src)) { - var startIndex = this.startIndex.exec(ctx); - var endIndex = this.endIndex.exec(ctx); - var start = startIndex != null ? startIndex : 0; - var end = endIndex != null ? endIndex : src.length; - if (src.length === 0 || start < 0 || end < 0 || end < start) { - return []; + ToTime.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg != null) { + var timeString = arg.toString(); + // Return null if string doesn't represent a valid ISO-8601 Time + // hh:mm:ss.fff or hh:mm:ss.fff + var matches = /^T?((\d{2})(:(\d{2})(:(\d{2})(\.(\d+))?)?)?)?(Z|(([+-])(\d{2})(:?(\d{2}))?))?$/.exec(timeString); + if (matches == null) { + return null; } - return src.slice(start, end); + var hours = matches[2]; + var minutes = matches[4]; + var seconds = matches[6]; + // Validate h/m/s if they exist, but allow null + if (hours != null) { + if (hours < 0 || hours > 23) { + return null; + } + hours = parseInt(hours, 10); + } + if (minutes != null) { + if (minutes < 0 || minutes > 59) { + return null; + } + minutes = parseInt(minutes, 10); + } + if (seconds != null) { + if (seconds < 0 || seconds > 59) { + return null; + } + seconds = parseInt(seconds, 10); + } + var milliseconds = matches[8]; + if (milliseconds != null) { + milliseconds = parseInt((0, util_1.normalizeMillisecondsField)(milliseconds)); + } + // Time is implemented as Datetime with year 0, month 1, day 1 and null timezoneOffset + return new datetime_1.DateTime(0, 1, 1, hours, minutes, seconds, milliseconds, null); + } + else { + return null; } - return null; }; - return Slice; + return ToTime; }(expression_1.Expression)); -exports.Slice = Slice; -// Length is completely handled by overloaded#Length - -},{"../util/comparison":103,"../util/util":106,"./builder":67,"./expression":73}],80:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.StringLiteral = exports.DecimalLiteral = exports.IntegerLiteral = exports.BooleanLiteral = exports.Literal = void 0; -var expression_1 = require("./expression"); -var Literal = /** @class */ (function (_super) { - __extends(Literal, _super); - function Literal(json) { +exports.ToTime = ToTime; +var Convert = /** @class */ (function (_super) { + __extends(Convert, _super); + function Convert(json) { var _this = _super.call(this, json) || this; - _this.valueType = json.valueType; - _this.value = json.value; + _this.operand = json.operand; + _this.toType = json.toType; return _this; } - Literal.from = function (json) { - switch (json.valueType) { + Convert.prototype.exec = function (ctx) { + switch (this.toType) { case '{urn:hl7-org:elm-types:r1}Boolean': - return new BooleanLiteral(json); - case '{urn:hl7-org:elm-types:r1}Integer': - return new IntegerLiteral(json); + return new ToBoolean({ type: 'ToBoolean', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}Concept': + return new ToConcept({ type: 'ToConcept', operand: this.operand }).execute(ctx); case '{urn:hl7-org:elm-types:r1}Decimal': - return new DecimalLiteral(json); + return new ToDecimal({ type: 'ToDecimal', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}Integer': + return new ToInteger({ type: 'ToInteger', operand: this.operand }).execute(ctx); case '{urn:hl7-org:elm-types:r1}String': - return new StringLiteral(json); + return new ToString({ type: 'ToString', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}Quantity': + return new ToQuantity({ type: 'ToQuantity', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}DateTime': + return new ToDateTime({ type: 'ToDateTime', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}Date': + return new ToDate({ type: 'ToDate', operand: this.operand }).execute(ctx); + case '{urn:hl7-org:elm-types:r1}Time': + return new ToTime({ type: 'ToTime', operand: this.operand }).execute(ctx); default: - return new Literal(json); + return this.execArgs(ctx); } }; - Literal.prototype.exec = function (_ctx) { - return this.value; - }; - return Literal; + return Convert; }(expression_1.Expression)); -exports.Literal = Literal; -// The following are not defined in ELM, but helpful for execution -var BooleanLiteral = /** @class */ (function (_super) { - __extends(BooleanLiteral, _super); - function BooleanLiteral(json) { +exports.Convert = Convert; +var ConvertsToBoolean = /** @class */ (function (_super) { + __extends(ConvertsToBoolean, _super); + function ConvertsToBoolean(json) { var _this = _super.call(this, json) || this; - _this.value = _this.value === 'true'; + _this.operand = json.operand; return _this; } - Object.defineProperty(BooleanLiteral.prototype, "isBooleanLiteral", { - // Define a simple getter to allow type-checking of this class without instanceof - // and in a way that survives minification (as opposed to checking constructor.name) - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - BooleanLiteral.prototype.exec = function (_ctx) { - return this.value; + ConvertsToBoolean.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToBoolean, this.operand, ctx); + } }; - return BooleanLiteral; -}(Literal)); -exports.BooleanLiteral = BooleanLiteral; -var IntegerLiteral = /** @class */ (function (_super) { - __extends(IntegerLiteral, _super); - function IntegerLiteral(json) { + return ConvertsToBoolean; +}(expression_1.Expression)); +exports.ConvertsToBoolean = ConvertsToBoolean; +var ConvertsToDate = /** @class */ (function (_super) { + __extends(ConvertsToDate, _super); + function ConvertsToDate(json) { var _this = _super.call(this, json) || this; - _this.value = parseInt(_this.value, 10); + _this.operand = json.operand; return _this; } - Object.defineProperty(IntegerLiteral.prototype, "isIntegerLiteral", { - // Define a simple getter to allow type-checking of this class without instanceof - // and in a way that survives minification (as opposed to checking constructor.name) - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - IntegerLiteral.prototype.exec = function (_ctx) { - return this.value; + ConvertsToDate.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToDate, this.operand, ctx); + } }; - return IntegerLiteral; -}(Literal)); -exports.IntegerLiteral = IntegerLiteral; -var DecimalLiteral = /** @class */ (function (_super) { - __extends(DecimalLiteral, _super); - function DecimalLiteral(json) { + return ConvertsToDate; +}(expression_1.Expression)); +exports.ConvertsToDate = ConvertsToDate; +var ConvertsToDateTime = /** @class */ (function (_super) { + __extends(ConvertsToDateTime, _super); + function ConvertsToDateTime(json) { var _this = _super.call(this, json) || this; - _this.value = parseFloat(_this.value); + _this.operand = json.operand; return _this; } - Object.defineProperty(DecimalLiteral.prototype, "isDecimalLiteral", { - // Define a simple getter to allow type-checking of this class without instanceof - // and in a way that survives minification (as opposed to checking constructor.name) - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - DecimalLiteral.prototype.exec = function (_ctx) { - return this.value; - }; - return DecimalLiteral; -}(Literal)); -exports.DecimalLiteral = DecimalLiteral; -var StringLiteral = /** @class */ (function (_super) { - __extends(StringLiteral, _super); - function StringLiteral(json) { - return _super.call(this, json) || this; - } - Object.defineProperty(StringLiteral.prototype, "isStringLiteral", { - // Define a simple getter to allow type-checking of this class without instanceof - // and in a way that survives minification (as opposed to checking constructor.name) - get: function () { - return true; - }, - enumerable: false, - configurable: true - }); - StringLiteral.prototype.exec = function (_ctx) { - // TODO: Remove these replacements when CQL-to-ELM fixes bug: https://github.com/cqframework/clinical_quality_language/issues/82 - return this.value.replace(/\\'/g, "'").replace(/\\"/g, '"'); - }; - return StringLiteral; -}(Literal)); -exports.StringLiteral = StringLiteral; - -},{"./expression":73}],81:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IsFalse = exports.IsTrue = exports.Xor = exports.Not = exports.Or = exports.And = void 0; -var expression_1 = require("./expression"); -var datatypes_1 = require("../datatypes/datatypes"); -var And = /** @class */ (function (_super) { - __extends(And, _super); - function And(json) { - return _super.call(this, json) || this; - } - And.prototype.exec = function (ctx) { - return datatypes_1.ThreeValuedLogic.and.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); - }; - return And; -}(expression_1.Expression)); -exports.And = And; -var Or = /** @class */ (function (_super) { - __extends(Or, _super); - function Or(json) { - return _super.call(this, json) || this; - } - Or.prototype.exec = function (ctx) { - return datatypes_1.ThreeValuedLogic.or.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); - }; - return Or; -}(expression_1.Expression)); -exports.Or = Or; -var Not = /** @class */ (function (_super) { - __extends(Not, _super); - function Not(json) { - return _super.call(this, json) || this; - } - Not.prototype.exec = function (ctx) { - return datatypes_1.ThreeValuedLogic.not(this.execArgs(ctx)); + ConvertsToDateTime.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToDateTime, this.operand, ctx); + } }; - return Not; + return ConvertsToDateTime; }(expression_1.Expression)); -exports.Not = Not; -var Xor = /** @class */ (function (_super) { - __extends(Xor, _super); - function Xor(json) { - return _super.call(this, json) || this; +exports.ConvertsToDateTime = ConvertsToDateTime; +var ConvertsToDecimal = /** @class */ (function (_super) { + __extends(ConvertsToDecimal, _super); + function ConvertsToDecimal(json) { + var _this = _super.call(this, json) || this; + _this.operand = json.operand; + return _this; } - Xor.prototype.exec = function (ctx) { - return datatypes_1.ThreeValuedLogic.xor.apply(datatypes_1.ThreeValuedLogic, this.execArgs(ctx)); + ConvertsToDecimal.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToDecimal, this.operand, ctx); + } }; - return Xor; + return ConvertsToDecimal; }(expression_1.Expression)); -exports.Xor = Xor; -var IsTrue = /** @class */ (function (_super) { - __extends(IsTrue, _super); - function IsTrue(json) { - return _super.call(this, json) || this; +exports.ConvertsToDecimal = ConvertsToDecimal; +var ConvertsToInteger = /** @class */ (function (_super) { + __extends(ConvertsToInteger, _super); + function ConvertsToInteger(json) { + var _this = _super.call(this, json) || this; + _this.operand = json.operand; + return _this; } - IsTrue.prototype.exec = function (ctx) { - return true === this.execArgs(ctx); + ConvertsToInteger.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToInteger, this.operand, ctx); + } }; - return IsTrue; + return ConvertsToInteger; }(expression_1.Expression)); -exports.IsTrue = IsTrue; -var IsFalse = /** @class */ (function (_super) { - __extends(IsFalse, _super); - function IsFalse(json) { - return _super.call(this, json) || this; +exports.ConvertsToInteger = ConvertsToInteger; +var ConvertsToQuantity = /** @class */ (function (_super) { + __extends(ConvertsToQuantity, _super); + function ConvertsToQuantity(json) { + var _this = _super.call(this, json) || this; + _this.operand = json.operand; + return _this; } - IsFalse.prototype.exec = function (ctx) { - return false === this.execArgs(ctx); + ConvertsToQuantity.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToQuantity, this.operand, ctx); + } }; - return IsFalse; + return ConvertsToQuantity; }(expression_1.Expression)); -exports.IsFalse = IsFalse; - -},{"../datatypes/datatypes":57,"./expression":73}],82:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Message = void 0; -var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var Message = /** @class */ (function (_super) { - __extends(Message, _super); - function Message(json) { +exports.ConvertsToQuantity = ConvertsToQuantity; +var ConvertsToRatio = /** @class */ (function (_super) { + __extends(ConvertsToRatio, _super); + function ConvertsToRatio(json) { var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - _this.condition = (0, builder_1.build)(json.condition); - _this.code = (0, builder_1.build)(json.code); - _this.severity = (0, builder_1.build)(json.severity); - _this.message = (0, builder_1.build)(json.message); + _this.operand = json.operand; return _this; } - Message.prototype.exec = function (ctx) { - var source = this.source.execute(ctx); - var condition = this.condition.execute(ctx); - if (condition) { - var code = this.code.execute(ctx); - var severity = this.severity.execute(ctx); - var message = this.message.execute(ctx); - var listener = ctx.getMessageListener(); - if (listener && typeof listener.onMessage === 'function') { - listener.onMessage(source, code, severity, message); - } + ConvertsToRatio.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToRatio, this.operand, ctx); } - return source; }; - return Message; + return ConvertsToRatio; }(expression_1.Expression)); -exports.Message = Message; - -},{"./builder":67,"./expression":73}],83:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +exports.ConvertsToRatio = ConvertsToRatio; +var ConvertsToString = /** @class */ (function (_super) { + __extends(ConvertsToString, _super); + function ConvertsToString(json) { + var _this = _super.call(this, json) || this; + _this.operand = json.operand; + return _this; + } + ConvertsToString.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToString, this.operand, ctx); + } }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Coalesce = exports.IsNull = exports.Null = void 0; -var expression_1 = require("./expression"); -var Null = /** @class */ (function (_super) { - __extends(Null, _super); - function Null(json) { - return _super.call(this, json) || this; + return ConvertsToString; +}(expression_1.Expression)); +exports.ConvertsToString = ConvertsToString; +var ConvertsToTime = /** @class */ (function (_super) { + __extends(ConvertsToTime, _super); + function ConvertsToTime(json) { + var _this = _super.call(this, json) || this; + _this.operand = json.operand; + return _this; } - Null.prototype.exec = function (_ctx) { - return null; + ConvertsToTime.prototype.exec = function (ctx) { + var operatorValue = this.execArgs(ctx); + if (operatorValue === null) { + return null; + } + else { + return canConvertToType(ToTime, this.operand, ctx); + } }; - return Null; + return ConvertsToTime; }(expression_1.Expression)); -exports.Null = Null; -var IsNull = /** @class */ (function (_super) { - __extends(IsNull, _super); - function IsNull(json) { +exports.ConvertsToTime = ConvertsToTime; +function canConvertToType(toFunction, operand, ctx) { + try { + var value = new toFunction({ type: toFunction.name, operand: operand }).execute(ctx); + if (value != null) { + return true; + } + else { + return false; + } + } + catch (error) { + return false; + } +} +var ConvertQuantity = /** @class */ (function (_super) { + __extends(ConvertQuantity, _super); + function ConvertQuantity(json) { return _super.call(this, json) || this; } - IsNull.prototype.exec = function (ctx) { - return this.execArgs(ctx) == null; + ConvertQuantity.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), quantity = _a[0], newUnit = _a[1]; + if (quantity != null && newUnit != null) { + try { + return quantity.convertUnit(newUnit); + } + catch (error) { + // Cannot convert input to target unit, spec says to return null + return null; + } + } }; - return IsNull; + return ConvertQuantity; }(expression_1.Expression)); -exports.IsNull = IsNull; -var Coalesce = /** @class */ (function (_super) { - __extends(Coalesce, _super); - function Coalesce(json) { +exports.ConvertQuantity = ConvertQuantity; +var CanConvertQuantity = /** @class */ (function (_super) { + __extends(CanConvertQuantity, _super); + function CanConvertQuantity(json) { return _super.call(this, json) || this; } - Coalesce.prototype.exec = function (ctx) { - if (this.args) { - for (var _i = 0, _a = this.args; _i < _a.length; _i++) { - var arg = _a[_i]; - var result = arg.execute(ctx); - // if a single arg that's a list, coalesce over the list - if (this.args.length === 1 && Array.isArray(result)) { - var item = result.find(function (item) { return item != null; }); - if (item != null) { - return item; - } - } - else { - if (result != null) { - return result; - } - } + CanConvertQuantity.prototype.exec = function (ctx) { + var _a = this.execArgs(ctx), quantity = _a[0], newUnit = _a[1]; + if (quantity != null && newUnit != null) { + try { + quantity.convertUnit(newUnit); + return true; + } + catch (error) { + return false; } } return null; }; - return Coalesce; + return CanConvertQuantity; }(expression_1.Expression)); -exports.Coalesce = Coalesce; +exports.CanConvertQuantity = CanConvertQuantity; +var Is = /** @class */ (function (_super) { + __extends(Is, _super); + function Is(json) { + var _this = _super.call(this, json) || this; + if (json.isTypeSpecifier) { + _this.isTypeSpecifier = json.isTypeSpecifier; + } + else if (json.isType) { + // Convert it to a NamedTypeSpecifier + _this.isTypeSpecifier = { + name: json.isType, + type: 'NamedTypeSpecifier' + }; + } + return _this; + } + Is.prototype.exec = function (ctx) { + var arg = this.execArgs(ctx); + if (arg === null) { + return false; + } + if (typeof arg._is !== 'function' && !isSystemType(this.isTypeSpecifier)) { + // We need an _is implementation in order to check non System types + throw new Error("Patient Source does not support Is operation for localId: ".concat(this.localId)); + } + return ctx.matchesTypeSpecifier(arg, this.isTypeSpecifier); + }; + return Is; +}(expression_1.Expression)); +exports.Is = Is; +function isSystemType(spec) { + switch (spec.type) { + case 'NamedTypeSpecifier': + return spec.name.startsWith('{urn:hl7-org:elm-types:r1}'); + case 'ListTypeSpecifier': + return isSystemType(spec.elementType); + case 'TupleTypeSpecifier': + return spec.element.every(function (e) { return isSystemType(e.elementType); }); + case 'IntervalTypeSpecifier': + return isSystemType(spec.pointType); + case 'ChoiceTypeSpecifier': + return spec.choice.every(function (c) { return isSystemType(c); }); + default: + return false; + } +} +function specifierToString(spec) { + if (typeof spec === 'string') { + return spec; + } + else if (spec == null || spec.type == null) { + return ''; + } + switch (spec.type) { + case 'NamedTypeSpecifier': + return spec.name; + case 'ListTypeSpecifier': + return "List<".concat(specifierToString(spec.elementType), ">"); + case 'TupleTypeSpecifier': + return "Tuple<".concat(spec.element + .map(function (e) { return "".concat(e.name, " ").concat(specifierToString(e.elementType)); }) + .join(', '), ">"); + case 'IntervalTypeSpecifier': + return "Interval<".concat(specifierToString(spec.pointType), ">"); + case 'ChoiceTypeSpecifier': + return "Choice<".concat(spec.choice.map(function (c) { return specifierToString(c); }).join(', '), ">"); + default: + return JSON.stringify(spec); + } +} +function guessSpecifierType(val) { + if (val == null) { + return 'Null'; + } + var typeHierarchy = typeof val._typeHierarchy === 'function' && val._typeHierarchy(); + if (typeHierarchy && typeHierarchy.length > 0) { + return typeHierarchy[0]; + } + else if (typeof val === 'boolean') { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Boolean' }; + } + else if (typeof val === 'number' && Math.floor(val) === val) { + // it could still be a decimal, but we have to just take our best guess! + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Integer' }; + } + else if (typeof val === 'number') { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Decimal' }; + } + else if (typeof val === 'string') { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}String' }; + } + else if (val.isConcept) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Concept' }; + } + else if (val.isCode) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Code' }; + } + else if (val.isDate) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Date' }; + } + else if (val.isTime && val.isTime()) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Time' }; + } + else if (val.isDateTime) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}DateTime' }; + } + else if (val.isQuantity) { + return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}DateTime' }; + } + else if (Array.isArray(val)) { + // Get unique types from the array (by converting to string and putting in a Set) + var typesAsStrings = Array.from(new Set(val.map(function (v) { return JSON.stringify(guessSpecifierType(v)); }))); + var types = typesAsStrings.map(function (ts) { return (/^{/.test(ts) ? JSON.parse(ts) : ts); }); + return { + type: 'ListTypeSpecifier', + elementType: types.length == 1 ? types[0] : { type: 'ChoiceTypeSpecifier', choice: types } + }; + } + else if (val.isInterval) { + return { + type: 'IntervalTypeSpecifier', + pointType: val.pointType + }; + } + else if (typeof val === 'object' && Object.keys(val).length > 0) { + return { + type: 'TupleTypeSpecifier', + element: Object.keys(val).map(function (k) { return ({ name: k, elementType: guessSpecifierType(val[k]) }); }) + }; + } + return 'Unknown'; +} +var IntervalTypeSpecifier = /** @class */ (function (_super) { + __extends(IntervalTypeSpecifier, _super); + function IntervalTypeSpecifier() { + return _super !== null && _super.apply(this, arguments) || this; + } + return IntervalTypeSpecifier; +}(expression_1.UnimplementedExpression)); +exports.IntervalTypeSpecifier = IntervalTypeSpecifier; +var ListTypeSpecifier = /** @class */ (function (_super) { + __extends(ListTypeSpecifier, _super); + function ListTypeSpecifier() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ListTypeSpecifier; +}(expression_1.UnimplementedExpression)); +exports.ListTypeSpecifier = ListTypeSpecifier; +var NamedTypeSpecifier = /** @class */ (function (_super) { + __extends(NamedTypeSpecifier, _super); + function NamedTypeSpecifier() { + return _super !== null && _super.apply(this, arguments) || this; + } + return NamedTypeSpecifier; +}(expression_1.UnimplementedExpression)); +exports.NamedTypeSpecifier = NamedTypeSpecifier; +var TupleTypeSpecifier = /** @class */ (function (_super) { + __extends(TupleTypeSpecifier, _super); + function TupleTypeSpecifier() { + return _super !== null && _super.apply(this, arguments) || this; + } + return TupleTypeSpecifier; +}(expression_1.UnimplementedExpression)); +exports.TupleTypeSpecifier = TupleTypeSpecifier; -},{"./expression":73}],84:[function(require,module,exports){ +},{"../datatypes/clinical":42,"../datatypes/datetime":44,"../datatypes/quantity":48,"../datatypes/ratio":49,"../datatypes/uncertainty":50,"../util/math":90,"../util/util":92,"./expression":59}],79:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -29287,483 +26525,654 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Precision = exports.SameOrBefore = exports.SameOrAfter = exports.SameAs = exports.Before = exports.After = exports.Length = exports.ProperIncludedIn = exports.ProperIncludes = exports.IncludedIn = exports.Includes = exports.Contains = exports.In = exports.Indexer = exports.Intersect = exports.Except = exports.Union = exports.NotEqual = exports.Equivalent = exports.Equal = void 0; -/* eslint-disable @typescript-eslint/ban-ts-comment */ -var expression_1 = require("./expression"); -var logic_1 = require("../datatypes/logic"); -var datetime_1 = require("../datatypes/datetime"); +exports.UnfilteredContext = exports.PatientContext = exports.Context = void 0; +var exception_1 = require("../datatypes/exception"); var util_1 = require("../util/util"); -var comparison_1 = require("../util/comparison"); -var DT = __importStar(require("./datetime")); -var LIST = __importStar(require("./list")); -var IVL = __importStar(require("./interval")); -var Equal = /** @class */ (function (_super) { - __extends(Equal, _super); - function Equal(json) { - return _super.call(this, json) || this; +var dt = __importStar(require("../datatypes/datatypes")); +var messageListeners_1 = require("./messageListeners"); +var Context = /** @class */ (function () { + function Context(parent, _codeService, _parameters, executionDateTime, messageListener) { + this.parent = parent; + this._codeService = _codeService; + this.context_values = {}; + this.library_context = {}; + this.localId_context = {}; + this.evaluatedRecords = []; + // TODO: If there is an issue with number of parameters look into cql4browsers fix: 387ea77538182833283af65e6341e7a05192304c + this.checkParameters(_parameters !== null && _parameters !== void 0 ? _parameters : {}); // not crazy about possibly throwing an error in a constructor, but... + this._parameters = _parameters || {}; + this.executionDateTime = executionDateTime; + this.messageListener = messageListener; } - Equal.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args[0] == null || args[1] == null) { - return null; + Object.defineProperty(Context.prototype, "parameters", { + get: function () { + return this._parameters || (this.parent && this.parent.parameters); + }, + set: function (params) { + this.checkParameters(params); + this._parameters = params; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Context.prototype, "codeService", { + get: function () { + return this._codeService || (this.parent && this.parent.codeService); + }, + set: function (cs) { + this._codeService = cs; + }, + enumerable: false, + configurable: true + }); + Context.prototype.withParameters = function (params) { + this.parameters = params || {}; + return this; + }; + Context.prototype.withCodeService = function (cs) { + this.codeService = cs; + return this; + }; + Context.prototype.rootContext = function () { + if (this.parent) { + return this.parent.rootContext(); + } + else { + return this; + } + }; + Context.prototype.findRecords = function (profile, retrieveDetails) { + return this.parent && this.parent.findRecords(profile, retrieveDetails); + }; + Context.prototype.childContext = function (context_values) { + if (context_values === void 0) { context_values = {}; } + var ctx = new Context(this); + ctx.context_values = context_values; + return ctx; + }; + Context.prototype.getLibraryContext = function (library) { + return this.parent && this.parent.getLibraryContext(library); + }; + Context.prototype.getLocalIdContext = function (localId) { + return this.parent && this.parent.getLocalIdContext(localId); + }; + Context.prototype.getParameter = function (name) { + return this.parent && this.parent.getParameter(name); + }; + Context.prototype.getParentParameter = function (name) { + if (this.parent) { + if (this.parent.parameters[name] != null) { + return this.parent.parameters[name]; + } + else { + return this.parent.getParentParameter(name); + } + } + }; + Context.prototype.getTimezoneOffset = function () { + if (this.executionDateTime != null) { + return this.executionDateTime.timezoneOffset; + } + else if (this.parent && this.parent.getTimezoneOffset != null) { + return this.parent.getTimezoneOffset(); + } + else { + throw new exception_1.Exception('No Timezone Offset has been set'); + } + }; + Context.prototype.getExecutionDateTime = function () { + if (this.executionDateTime != null) { + return this.executionDateTime; + } + else if (this.parent && this.parent.getExecutionDateTime != null) { + return this.parent.getExecutionDateTime(); + } + else { + throw new exception_1.Exception('No Execution DateTime has been set'); + } + }; + Context.prototype.getMessageListener = function () { + if (this.messageListener != null) { + return this.messageListener; + } + else if (this.parent && this.parent.getMessageListener != null) { + return this.parent.getMessageListener(); + } + else { + return new messageListeners_1.NullMessageListener(); + } + }; + Context.prototype.getValueSet = function (name, library) { + return this.parent && this.parent.getValueSet(name, library); + }; + Context.prototype.getCodeSystem = function (name) { + return this.parent && this.parent.getCodeSystem(name); + }; + Context.prototype.getCode = function (name) { + return this.parent && this.parent.getCode(name); + }; + Context.prototype.getConcept = function (name) { + return this.parent && this.parent.getConcept(name); + }; + Context.prototype.get = function (identifier) { + // Check for undefined because if its null, we actually *do* want to return null (rather than + // looking at parent), but if it's really undefined, *then* look at the parent + if (typeof this.context_values[identifier] !== 'undefined') { + return this.context_values[identifier]; + } + else if (identifier === '$this') { + return this.context_values; + } + else { + return this.parent != null && this.parent.get(identifier); + } + }; + Context.prototype.set = function (identifier, value) { + this.context_values[identifier] = value; + }; + Context.prototype.setLocalIdWithResult = function (localId, value) { + // Temporary fix. Real fix will be to return a list of all result values for a given localId. + var ctx = this.localId_context[localId]; + if (ctx === false || ctx === null || ctx === undefined || ctx.length === 0) { + this.localId_context[localId] = value; + } + }; + Context.prototype.getLocalIdResult = function (localId) { + return this.localId_context[localId]; + }; + // Returns an object of objects containing each library name + // with the localIds and result values + Context.prototype.getAllLocalIds = function () { + var localIdResults = {}; + // Add the localIds and result values from the main library + localIdResults[this.parent.source.library.identifier.id] = {}; + localIdResults[this.parent.source.library.identifier.id] = this.localId_context; + // Iterate over support libraries and store localIds + for (var libName in this.library_context) { + var lib = this.library_context[libName]; + this.supportLibraryLocalIds(lib, localIdResults); + } + return localIdResults; + }; + // Recursive function that will grab nested support library localId results + Context.prototype.supportLibraryLocalIds = function (lib, localIdResults) { + var _this = this; + // Set library identifier name as the key and the object of localIds with their results as the value + // if it already exists then we need to merge the results instead of overwriting + if (localIdResults[lib.library.source.library.identifier.id] != null) { + this.mergeLibraryLocalIdResults(localIdResults, lib.library.source.library.identifier.id, lib.localId_context); + } + else { + localIdResults[lib.library.source.library.identifier.id] = lib.localId_context; + } + // Iterate over any support libraries in the current support library + Object.values(lib.library_context).forEach(function (supportLib) { + _this.supportLibraryLocalIds(supportLib, localIdResults); + }); + }; + // Merges the localId results for a library into the already collected results. The logic used for which result + // to keep is the same as the logic used above in setLocalIdWithResult, "falsey" results are always replaced. + Context.prototype.mergeLibraryLocalIdResults = function (localIdResults, libraryId, libraryResults) { + for (var localId in libraryResults) { + var localIdResult = libraryResults[localId]; + var existingResult = localIdResults[libraryId][localId]; + // overwite this localid result if the existing result is "falsey". future work could track all results for each localid + if (existingResult === false || + existingResult === null || + existingResult === undefined || + existingResult.length === 0) { + localIdResults[libraryId][localId] = localIdResult; + } + } + }; + Context.prototype.checkParameters = function (params) { + for (var pName in params) { + var pVal = params[pName]; + var pDef = this.getParameter(pName); + if (pVal == null) { + return; // Null can theoretically be any type + } + if (typeof pDef === 'undefined') { + return; // This will happen if the parameter is declared in a different (included) library + } + else if (pDef.parameterTypeSpecifier != null && + !this.matchesTypeSpecifier(pVal, pDef.parameterTypeSpecifier)) { + throw new Error("Passed in parameter '".concat(pName, "' is wrong type")); + } + else if (pDef['default'] != null && !this.matchesInstanceType(pVal, pDef['default'])) { + throw new Error("Passed in parameter '".concat(pName, "' is wrong type")); + } + } + return true; + }; + Context.prototype.matchesTypeSpecifier = function (val, spec) { + switch (spec.type) { + case 'NamedTypeSpecifier': + return this.matchesNamedTypeSpecifier(val, spec); + case 'ListTypeSpecifier': + return this.matchesListTypeSpecifier(val, spec); + case 'TupleTypeSpecifier': + return this.matchesTupleTypeSpecifier(val, spec); + case 'IntervalTypeSpecifier': + return this.matchesIntervalTypeSpecifier(val, spec); + case 'ChoiceTypeSpecifier': + return this.matchesChoiceTypeSpecifier(val, spec); + default: + return true; // default to true when we don't know } - // @ts-ignore - return comparison_1.equals.apply(void 0, args); }; - return Equal; -}(expression_1.Expression)); -exports.Equal = Equal; -var Equivalent = /** @class */ (function (_super) { - __extends(Equivalent, _super); - function Equivalent(json) { - return _super.call(this, json) || this; - } - Equivalent.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null && b == null) { + Context.prototype.matchesListTypeSpecifier = function (val, spec) { + var _this = this; + return ((0, util_1.typeIsArray)(val) && val.every(function (x) { return _this.matchesTypeSpecifier(x, spec.elementType); })); + }; + Context.prototype.matchesTupleTypeSpecifier = function (val, spec) { + var _this = this; + // TODO: Spec is not clear about exactly how tuples should be matched + return (val != null && + typeof val === 'object' && + !(0, util_1.typeIsArray)(val) && + !val.isInterval && + !val.isConcept && + !val.isCode && + !val.isDateTime && + !val.isDate && + !val.isQuantity && + spec.element.every(function (x) { + return typeof val[x.name] === 'undefined' || + _this.matchesTypeSpecifier(val[x.name], x.elementType); + })); + }; + Context.prototype.matchesIntervalTypeSpecifier = function (val, spec) { + return (val.isInterval && + (val.low == null || this.matchesTypeSpecifier(val.low, spec.pointType)) && + (val.high == null || this.matchesTypeSpecifier(val.high, spec.pointType))); + }; + Context.prototype.matchesChoiceTypeSpecifier = function (val, spec) { + var _this = this; + return spec.choice.some(function (c) { return _this.matchesTypeSpecifier(val, c); }); + }; + Context.prototype.matchesNamedTypeSpecifier = function (val, spec) { + if (val == null) { return true; } - else if (a == null || b == null) { - return false; - } - else { - return (0, comparison_1.equivalent)(a, b); + switch (spec.name) { + case '{urn:hl7-org:elm-types:r1}Boolean': + return typeof val === 'boolean'; + case '{urn:hl7-org:elm-types:r1}Decimal': + return typeof val === 'number'; + case '{urn:hl7-org:elm-types:r1}Integer': + return typeof val === 'number' && Math.floor(val) === val; + case '{urn:hl7-org:elm-types:r1}String': + return typeof val === 'string'; + case '{urn:hl7-org:elm-types:r1}Concept': + return val && val.isConcept; + case '{urn:hl7-org:elm-types:r1}Code': + return val && val.isCode; + case '{urn:hl7-org:elm-types:r1}DateTime': + return val && val.isDateTime; + case '{urn:hl7-org:elm-types:r1}Date': + return val && val.isDate; + case '{urn:hl7-org:elm-types:r1}Quantity': + return val && val.isQuantity; + case '{urn:hl7-org:elm-types:r1}Time': + return val && val.isTime && val.isTime(); + default: + // Use the data model's implementation of _is, if it is available + if (typeof val._is === 'function') { + return val._is(spec); + } + // If the value is an array or interval, then we assume it cannot be cast to a + // named type. Technically, this is not 100% true because a modelinfo can define + // a named type whose base type is a list or interval. But none of our models + // (FHIR, QDM, QICore) do that, so for those models, this approach will always be + // correct. + if (Array.isArray(val) || val.isInterval) { + return false; + } + // Otherwise just default to true to match legacy behavior. + // + // NOTE: This is also where arbitrary tuples land because they will not have + // an "is" function and we don't encode the type information into the runtime + // objects so we can't easily determine their type. We can't reject them, + // else things like `Encounter{ id: "1" } is Encounter` would return false. + // So for now we allow false positives in order to avoid false negatives. + return true; } }; - return Equivalent; -}(expression_1.Expression)); -exports.Equivalent = Equivalent; -var NotEqual = /** @class */ (function (_super) { - __extends(NotEqual, _super); - function NotEqual(json) { - return _super.call(this, json) || this; - } - NotEqual.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args[0] == null || args[1] == null) { - return null; + Context.prototype.matchesInstanceType = function (val, inst) { + if (inst.isBooleanLiteral) { + return typeof val === 'boolean'; } - // @ts-ignore - return logic_1.ThreeValuedLogic.not(comparison_1.equals.apply(void 0, this.execArgs(ctx))); - }; - return NotEqual; -}(expression_1.Expression)); -exports.NotEqual = NotEqual; -var Union = /** @class */ (function (_super) { - __extends(Union, _super); - function Union(json) { - return _super.call(this, json) || this; - } - Union.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null && b == null) { - return this.listTypeArgs() ? [] : null; + else if (inst.isDecimalLiteral) { + return typeof val === 'number'; } - if (a == null || b == null) { - var notNull = a || b; - if ((0, util_1.typeIsArray)(notNull)) { - return notNull; - } - else { - return null; - } + else if (inst.isIntegerLiteral) { + return typeof val === 'number' && Math.floor(val) === val; } - var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; - return lib.doUnion(a, b); - }; - Union.prototype.listTypeArgs = function () { - var _a; - return (_a = this.args) === null || _a === void 0 ? void 0 : _a.some(function (arg) { - return arg.asTypeSpecifier != null && arg.asTypeSpecifier.type === 'ListTypeSpecifier'; - }); - }; - return Union; -}(expression_1.Expression)); -exports.Union = Union; -var Except = /** @class */ (function (_super) { - __extends(Except, _super); - function Except(json) { - return _super.call(this, json) || this; - } - Except.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null) { - return null; + else if (inst.isStringLiteral) { + return typeof val === 'string'; } - if (b == null) { - return (0, util_1.typeIsArray)(a) ? a : null; + else if (inst.isCode) { + return val && val.isCode; } - var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; - return lib.doExcept(a, b); - }; - return Except; -}(expression_1.Expression)); -exports.Except = Except; -var Intersect = /** @class */ (function (_super) { - __extends(Intersect, _super); - function Intersect(json) { - return _super.call(this, json) || this; - } - Intersect.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null || b == null) { - return null; + else if (inst.isConcept) { + return val && val.isConcept; } - var lib = (0, util_1.typeIsArray)(a) ? LIST : IVL; - return lib.doIntersect(a, b); - }; - return Intersect; -}(expression_1.Expression)); -exports.Intersect = Intersect; -var Indexer = /** @class */ (function (_super) { - __extends(Indexer, _super); - function Indexer(json) { - return _super.call(this, json) || this; - } - Indexer.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), operand = _a[0], index = _a[1]; - if (operand == null || index == null) { - return null; + else if (inst.isTime && inst.isTime()) { + return val && val.isTime && val.isTime(); } - if (index < 0 || index >= operand.length) { - return null; + else if (inst.isDate) { + return val && val.isDate; } - return operand[index]; - }; - return Indexer; -}(expression_1.Expression)); -exports.Indexer = Indexer; -var In = /** @class */ (function (_super) { - __extends(In, _super); - function In(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - In.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), item = _a[0], container = _a[1]; - if (item == null) { - return null; + else if (inst.isDateTime) { + return val && val.isDateTime; } - if (container == null) { - return false; + else if (inst.isQuantity) { + return val && val.isQuantity; } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doContains(container, item, this.precision); - }; - return In; -}(expression_1.Expression)); -exports.In = In; -var Contains = /** @class */ (function (_super) { - __extends(Contains, _super); - function Contains(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - Contains.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), container = _a[0], item = _a[1]; - if (container == null) { - return false; + else if (inst.isList) { + return this.matchesListInstanceType(val, inst); } - if (item == null) { - return null; + else if (inst.isTuple) { + return this.matchesTupleInstanceType(val, inst); } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doContains(container, item, this.precision); - }; - return Contains; -}(expression_1.Expression)); -exports.Contains = Contains; -var Includes = /** @class */ (function (_super) { - __extends(Includes, _super); - function Includes(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - Includes.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), container = _a[0], contained = _a[1]; - if (container == null || contained == null) { - return null; + else if (inst.isInterval) { + return this.matchesIntervalInstanceType(val, inst); } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doIncludes(container, contained, this.precision); + return true; // default to true when we don't know for sure }; - return Includes; -}(expression_1.Expression)); -exports.Includes = Includes; -var IncludedIn = /** @class */ (function (_super) { - __extends(IncludedIn, _super); - function IncludedIn(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + Context.prototype.matchesListInstanceType = function (val, list) { + var _this = this; + return ((0, util_1.typeIsArray)(val) && val.every(function (x) { return _this.matchesInstanceType(x, list.elements[0]); })); + }; + Context.prototype.matchesTupleInstanceType = function (val, tpl) { + var _this = this; + return (typeof val === 'object' && + !(0, util_1.typeIsArray)(val) && + tpl.elements.every(function (x) { + return typeof val[x.name] === 'undefined' || _this.matchesInstanceType(val[x.name], x.value); + })); + }; + Context.prototype.matchesIntervalInstanceType = function (val, ivl) { + var pointType = ivl.low != null ? ivl.low : ivl.high; + return (val.isInterval && + (val.low == null || this.matchesInstanceType(val.low, pointType)) && + (val.high == null || this.matchesInstanceType(val.high, pointType))); + }; + return Context; +}()); +exports.Context = Context; +var PatientContext = /** @class */ (function (_super) { + __extends(PatientContext, _super); + function PatientContext(library, patient, codeService, parameters, executionDateTime, messageListener) { + if (executionDateTime === void 0) { executionDateTime = dt.DateTime.fromJSDate(new Date()); } + if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } + var _this = _super.call(this, library, codeService, parameters, executionDateTime, messageListener) || this; + _this.library = library; + _this.patient = patient; return _this; } - IncludedIn.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), contained = _a[0], container = _a[1]; - if (container == null || contained == null) { - return null; + PatientContext.prototype.rootContext = function () { + return this; + }; + PatientContext.prototype.getLibraryContext = function (library) { + if (this.library_context[library] == null) { + this.library_context[library] = new PatientContext(this.get(library), this.patient, this.codeService, this.parameters, this.executionDateTime); } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doIncludes(container, contained, this.precision); + return this.library_context[library]; }; - return IncludedIn; -}(expression_1.Expression)); -exports.IncludedIn = IncludedIn; -var ProperIncludes = /** @class */ (function (_super) { - __extends(ProperIncludes, _super); - function ProperIncludes(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - ProperIncludes.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), container = _a[0], contained = _a[1]; - if (container == null || contained == null) { - return null; + PatientContext.prototype.getLocalIdContext = function (localId) { + if (this.localId_context[localId] == null) { + this.localId_context[localId] = new PatientContext(this.get(localId), this.patient, this.codeService, this.parameters, this.executionDateTime); } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doProperIncludes(container, contained, this.precision); + return this.localId_context[localId]; }; - return ProperIncludes; -}(expression_1.Expression)); -exports.ProperIncludes = ProperIncludes; -var ProperIncludedIn = /** @class */ (function (_super) { - __extends(ProperIncludedIn, _super); - function ProperIncludedIn(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; + PatientContext.prototype.findRecords = function (profile, retrieveDetails) { + return this.patient && this.patient.findRecords(profile, retrieveDetails); + }; + return PatientContext; +}(Context)); +exports.PatientContext = PatientContext; +var UnfilteredContext = /** @class */ (function (_super) { + __extends(UnfilteredContext, _super); + function UnfilteredContext(library, results, codeService, parameters, executionDateTime, messageListener) { + if (executionDateTime === void 0) { executionDateTime = dt.DateTime.fromJSDate(new Date()); } + if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } + var _this = _super.call(this, library, codeService, parameters, executionDateTime, messageListener) || this; + _this.library = library; + _this.results = results; return _this; } - ProperIncludedIn.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), contained = _a[0], container = _a[1]; - if (container == null || contained == null) { - return null; - } - var lib = (0, util_1.typeIsArray)(container) ? LIST : IVL; - return lib.doProperIncludes(container, contained, this.precision); + UnfilteredContext.prototype.rootContext = function () { + return this; }; - return ProperIncludedIn; -}(expression_1.Expression)); -exports.ProperIncludedIn = ProperIncludedIn; -var Length = /** @class */ (function (_super) { - __extends(Length, _super); - function Length(json) { - return _super.call(this, json) || this; - } - Length.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return arg.length; - } - else if (this.arg.asTypeSpecifier.type === 'ListTypeSpecifier') { - return 0; + UnfilteredContext.prototype.findRecords = function (_template) { + throw new exception_1.Exception('Retreives are not currently supported in Unfiltered Context'); + }; + UnfilteredContext.prototype.getLibraryContext = function (_library) { + throw new exception_1.Exception('Library expressions are not currently supported in Unfiltered Context'); + }; + UnfilteredContext.prototype.get = function (identifier) { + //First check to see if the identifier is a unfiltered context expression that has already been cached + if (this.context_values[identifier]) { + return this.context_values[identifier]; } - else { - return null; + //if not look to see if the library has a unfiltered expression of that identifier + if (this.library[identifier] && this.library[identifier].context === 'Unfiltered') { + return this.library.expressions[identifier]; } + //lastley attempt to gather all patient level results that have that identifier + // should this compact null values before return ? + return Object.values(this.results.patientResults).map(function (pr) { return pr[identifier]; }); }; - return Length; -}(expression_1.Expression)); -exports.Length = Length; -var After = /** @class */ (function (_super) { - __extends(After, _super); - function After(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; + return UnfilteredContext; +}(Context)); +exports.UnfilteredContext = UnfilteredContext; + +},{"../datatypes/datatypes":43,"../datatypes/exception":45,"../util/util":92,"./messageListeners":81}],80:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Executor = void 0; +var messageListeners_1 = require("./messageListeners"); +var results_1 = require("./results"); +var context_1 = require("./context"); +var Executor = /** @class */ (function () { + function Executor(library, codeService, parameters, messageListener) { + if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } + this.library = library; + this.codeService = codeService; + this.parameters = parameters; + this.messageListener = messageListener; } - After.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null || b == null) { - return null; - } - var lib = a instanceof datetime_1.DateTime ? DT : IVL; - return lib.doAfter(a, b, this.precision); + Executor.prototype.withLibrary = function (lib) { + this.library = lib; + return this; }; - return After; -}(expression_1.Expression)); -exports.After = After; -var Before = /** @class */ (function (_super) { - __extends(Before, _super); - function Before(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision != null ? json.precision.toLowerCase() : undefined; - return _this; - } - Before.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a == null || b == null) { - return null; - } - var lib = a instanceof datetime_1.DateTime ? DT : IVL; - return lib.doBefore(a, b, this.precision); + Executor.prototype.withParameters = function (params) { + this.parameters = params != null ? params : {}; + return this; }; - return Before; -}(expression_1.Expression)); -exports.Before = Before; -var SameAs = /** @class */ (function (_super) { - __extends(SameAs, _super); - function SameAs(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision; - return _this; - } - SameAs.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), a = _a[0], b = _a[1]; - if (a != null && b != null) { - return a.sameAs(b, this.precision != null ? this.precision.toLowerCase() : undefined); + Executor.prototype.withCodeService = function (cs) { + this.codeService = cs; + return this; + }; + Executor.prototype.withMessageListener = function (ml) { + this.messageListener = ml; + return this; + }; + Executor.prototype.exec_expression = function (expression, patientSource, executionDateTime) { + var _a; + var r = new results_1.Results(); + var expr = this.library.expressions[expression]; + if (expr != null) { + while (patientSource.currentPatient()) { + var patient_ctx = new context_1.PatientContext(this.library, patientSource.currentPatient(), this.codeService, this.parameters, executionDateTime, this.messageListener); + r.recordPatientResults(patient_ctx, (_a = {}, _a[expression] = expr.execute(patient_ctx), _a)); + patientSource.nextPatient(); + } } - else { - return null; + return r; + }; + Executor.prototype.exec = function (patientSource, executionDateTime) { + var r = this.exec_patient_context(patientSource, executionDateTime); + var unfilteredContext = new context_1.UnfilteredContext(this.library, r, this.codeService, this.parameters, executionDateTime, this.messageListener); + var resultMap = {}; + for (var key in this.library.expressions) { + var expr = this.library.expressions[key]; + if (expr.context === 'Unfiltered') { + resultMap[key] = expr.exec(unfilteredContext); + } } + r.recordUnfilteredResults(resultMap); + return r; }; - return SameAs; -}(expression_1.Expression)); -exports.SameAs = SameAs; -var SameOrAfter = /** @class */ (function (_super) { - __extends(SameOrAfter, _super); - function SameOrAfter(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision; - return _this; - } - SameOrAfter.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), d1 = _a[0], d2 = _a[1]; - if (d1 != null && d2 != null) { - return d1.sameOrAfter(d2, this.precision != null ? this.precision.toLowerCase() : undefined); - } - else { - return null; + Executor.prototype.exec_patient_context = function (patientSource, executionDateTime) { + var r = new results_1.Results(); + while (patientSource.currentPatient()) { + var patient_ctx = new context_1.PatientContext(this.library, patientSource.currentPatient(), this.codeService, this.parameters, executionDateTime, this.messageListener); + var resultMap = {}; + for (var key in this.library.expressions) { + var expr = this.library.expressions[key]; + if (expr.context === 'Patient') { + resultMap[key] = expr.execute(patient_ctx); + } + } + r.recordPatientResults(patient_ctx, resultMap); + patientSource.nextPatient(); } + return r; }; - return SameOrAfter; -}(expression_1.Expression)); -exports.SameOrAfter = SameOrAfter; -var SameOrBefore = /** @class */ (function (_super) { - __extends(SameOrBefore, _super); - function SameOrBefore(json) { - var _this = _super.call(this, json) || this; - _this.precision = json.precision; - return _this; + return Executor; +}()); +exports.Executor = Executor; + +},{"./context":79,"./messageListeners":81,"./results":83}],81:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ConsoleMessageListener = exports.NullMessageListener = void 0; +var NullMessageListener = /** @class */ (function () { + function NullMessageListener() { } - SameOrBefore.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), d1 = _a[0], d2 = _a[1]; - if (d1 != null && d2 != null) { - return d1.sameOrBefore(d2, this.precision != null ? this.precision.toLowerCase() : undefined); - } - else { - return null; - } + NullMessageListener.prototype.onMessage = function (_source, _code, _severity, _message) { + // do nothing }; - return SameOrBefore; -}(expression_1.Expression)); -exports.SameOrBefore = SameOrBefore; -// Implemented for DateTime, Date, and Time but not for Decimal yet -var Precision = /** @class */ (function (_super) { - __extends(Precision, _super); - function Precision(json) { - return _super.call(this, json) || this; + return NullMessageListener; +}()); +exports.NullMessageListener = NullMessageListener; +var ConsoleMessageListener = /** @class */ (function () { + function ConsoleMessageListener(logSourceOnTrace) { + if (logSourceOnTrace === void 0) { logSourceOnTrace = false; } + this.logSourceOnTrace = logSourceOnTrace; } - Precision.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - // Since we can't extend UnimplementedExpression directly for this overloaded function, - // we have to copy the error to throw here if we are not using the correct type - if (!arg.getPrecisionValue) { - throw new Error("Unimplemented Expression: Precision"); + ConsoleMessageListener.prototype.onMessage = function (source, code, severity, message) { + // eslint-disable-next-line no-console + var print = severity === 'Error' ? console.error : console.log; + var content = "".concat(severity, ": [").concat(code, "] ").concat(message); + if (severity === 'Trace' && this.logSourceOnTrace) { + content += "\n<<<<< SOURCE:\n".concat(JSON.stringify(source), "\n>>>>>"); } - return arg.getPrecisionValue(); + print(content); }; - return Precision; -}(expression_1.Expression)); -exports.Precision = Precision; + return ConsoleMessageListener; +}()); +exports.ConsoleMessageListener = ConsoleMessageListener; -},{"../datatypes/datetime":58,"../datatypes/logic":61,"../util/comparison":103,"../util/util":106,"./datetime":71,"./expression":73,"./interval":77,"./list":79}],85:[function(require,module,exports){ +},{}],82:[function(require,module,exports){ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.ParameterRef = exports.ParameterDef = void 0; -var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var ParameterDef = /** @class */ (function (_super) { - __extends(ParameterDef, _super); - function ParameterDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.default = (0, builder_1.build)(json.default); - _this.parameterTypeSpecifier = json.parameterTypeSpecifier; - return _this; +exports.Repository = void 0; +var library_1 = require("../elm/library"); +var Repository = /** @class */ (function () { + function Repository(data) { + this.data = data; + this.libraries = Array.from(Object.values(data)); } - ParameterDef.prototype.exec = function (ctx) { - // If context parameters contains the name, return value. - if (ctx && ctx.parameters[this.name] !== undefined) { - return ctx.parameters[this.name]; - // If the parent context contains the name, return that - } - else if (ctx.getParentParameter(this.name) !== undefined) { - var parentParam = ctx.getParentParameter(this.name); - return parentParam.default != null ? parentParam.default.execute(ctx) : parentParam; - // If default type exists, execute the default type - } - else if (this.default != null) { - this.default.execute(ctx); + Repository.prototype.resolve = function (path, version) { + for (var _i = 0, _a = this.libraries; _i < _a.length; _i++) { + var lib = _a[_i]; + if (lib.library && lib.library.identifier) { + var _b = lib.library.identifier, id = _b.id, system = _b.system, libraryVersion = _b.version; + var libraryUri = "".concat(system, "/").concat(id); + if (path === libraryUri || path === id) { + if (version) { + if (libraryVersion === version) { + return new library_1.Library(lib, this); + } + } + else { + return new library_1.Library(lib, this); + } + } + } } }; - return ParameterDef; -}(expression_1.Expression)); -exports.ParameterDef = ParameterDef; -var ParameterRef = /** @class */ (function (_super) { - __extends(ParameterRef, _super); - function ParameterRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.library = json.libraryName; - return _this; - } - ParameterRef.prototype.exec = function (ctx) { - ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; - var param = ctx.getParameter(this.name); - return param != null ? param.execute(ctx) : undefined; - }; - return ParameterRef; -}(expression_1.Expression)); -exports.ParameterRef = ParameterRef; + return Repository; +}()); +exports.Repository = Repository; -},{"./builder":67,"./expression":73}],86:[function(require,module,exports){ +},{"../elm/library":64}],83:[function(require,module,exports){ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Results = void 0; +var Results = /** @class */ (function () { + function Results() { + this.patientResults = {}; + this.unfilteredResults = {}; + this.localIdPatientResultsMap = {}; + this.patientEvaluatedRecords = {}; + } + Object.defineProperty(Results.prototype, "evaluatedRecords", { + // Expose an evaluatedRecords array for backwards compatibility + get: function () { + return [].concat.apply([], Object.values(this.patientEvaluatedRecords)); + }, + enumerable: false, + configurable: true + }); + Results.prototype.recordPatientResults = function (patient_ctx, resultMap) { + var _this = this; + var p = patient_ctx.patient; + // NOTE: From now on prefer getId() over id() because some data models may have an id property + // that is not a string (e.g., FHIR) -- so reserve getId() for the API (and expect a string + // representation) but leave id() for data-model specific formats. + var patientId = typeof p.getId === 'function' ? p.getId() : p.id(); + // Record the results + this.patientResults[patientId] = resultMap; + // Record the local IDs + this.localIdPatientResultsMap[patientId] = patient_ctx.getAllLocalIds(); + // Record the evaluatedRecords, merging with an aggregated array across all libraries + this.patientEvaluatedRecords[patientId] = __spreadArray([], patient_ctx.evaluatedRecords, true); + Object.values(patient_ctx.library_context).forEach(function (ctx) { + var _a; + (_a = _this.patientEvaluatedRecords[patientId]).push.apply(_a, ctx.evaluatedRecords); + }); }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + Results.prototype.recordUnfilteredResults = function (resultMap) { + this.unfilteredResults = resultMap; }; -})(); + return Results; +}()); +exports.Results = Results; + +},{}],84:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +},{}],85:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +},{}],86:[function(require,module,exports){ +"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -29771,40 +27180,269 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi if (k2 === undefined) k2 = k; o[k2] = m[k]; })); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Quantity = void 0; -var expression_1 = require("./expression"); -var DT = __importStar(require("../datatypes/datatypes")); -// Unit conversation is currently implemented on for time duration comparison operations -// TODO: Implement unit conversation for time duration mathematical operations -var Quantity = /** @class */ (function (_super) { - __extends(Quantity, _super); - function Quantity(json) { - var _this = _super.call(this, json) || this; - _this.value = parseFloat(json.value); - _this.unit = json.unit; - return _this; +__exportStar(require("./cql-code-service.interfaces"), exports); +__exportStar(require("./cql-patient.interfaces"), exports); +__exportStar(require("./runtime.types"), exports); +__exportStar(require("./type-specifiers.interfaces"), exports); + +},{"./cql-code-service.interfaces":84,"./cql-patient.interfaces":85,"./runtime.types":87,"./type-specifiers.interfaces":88}],87:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +},{}],88:[function(require,module,exports){ +"use strict"; +// Types derived from http://cql.hl7.org/04-logicalspecification.html#typespecifier +Object.defineProperty(exports, "__esModule", { value: true }); + +},{}],89:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.equals = exports.equivalent = exports.greaterThanOrEquals = exports.greaterThan = exports.lessThanOrEquals = exports.lessThan = void 0; +var datatypes_1 = require("../datatypes/datatypes"); +function areNumbers(a, b) { + return typeof a === 'number' && typeof b === 'number'; +} +function areStrings(a, b) { + return typeof a === 'string' && typeof b === 'string'; +} +function areDateTimesOrQuantities(a, b) { + return ((a && a.isDateTime && b && b.isDateTime) || + (a && a.isDate && b && b.isDate) || + (a && a.isQuantity && b && b.isQuantity)); +} +function isUncertainty(x) { + return x instanceof datatypes_1.Uncertainty; +} +function lessThan(a, b, precision) { + if (areNumbers(a, b) || areStrings(a, b)) { + return a < b; + } + else if (areDateTimesOrQuantities(a, b)) { + return a.before(b, precision); + } + else if (isUncertainty(a)) { + return a.lessThan(b); + } + else if (isUncertainty(b)) { + return datatypes_1.Uncertainty.from(a).lessThan(b); + } + else { + return null; + } +} +exports.lessThan = lessThan; +function lessThanOrEquals(a, b, precision) { + if (areNumbers(a, b) || areStrings(a, b)) { + return a <= b; + } + else if (areDateTimesOrQuantities(a, b)) { + return a.sameOrBefore(b, precision); + } + else if (isUncertainty(a)) { + return a.lessThanOrEquals(b); + } + else if (isUncertainty(b)) { + return datatypes_1.Uncertainty.from(a).lessThanOrEquals(b); + } + else { + return null; + } +} +exports.lessThanOrEquals = lessThanOrEquals; +function greaterThan(a, b, precision) { + if (areNumbers(a, b) || areStrings(a, b)) { + return a > b; + } + else if (areDateTimesOrQuantities(a, b)) { + return a.after(b, precision); + } + else if (isUncertainty(a)) { + return a.greaterThan(b); + } + else if (isUncertainty(b)) { + return datatypes_1.Uncertainty.from(a).greaterThan(b); + } + else { + return null; + } +} +exports.greaterThan = greaterThan; +function greaterThanOrEquals(a, b, precision) { + if (areNumbers(a, b) || areStrings(a, b)) { + return a >= b; + } + else if (areDateTimesOrQuantities(a, b)) { + return a.sameOrAfter(b, precision); + } + else if (isUncertainty(a)) { + return a.greaterThanOrEquals(b); + } + else if (isUncertainty(b)) { + return datatypes_1.Uncertainty.from(a).greaterThanOrEquals(b); + } + else { + return null; + } +} +exports.greaterThanOrEquals = greaterThanOrEquals; +function equivalent(a, b) { + if (a == null && b == null) { + return true; + } + if (a == null || b == null) { + return false; + } + if (isCode(a)) { + return codesAreEquivalent(a, b); + } + // Quantity equivalence is the same as Quantity equality + if (a.isQuantity) { + return a.equals(b); + } + // Use overloaded 'equivalent' function if it is available + if (typeof a.equivalent === 'function') { + return a.equivalent(b); + } + var _a = getClassOfObjects(a, b), aClass = _a[0], bClass = _a[1]; + switch (aClass) { + case '[object Array]': + return compareEveryItemInArrays(a, b, equivalent); + case '[object Object]': + return compareObjects(a, b, equivalent); + case '[object String]': + // Make sure b is also a string + if (bClass === '[object String]') { + // String equivalence is case- and locale insensitive + a = a.replace(/\s/g, ' '); + b = b.replace(/\s/g, ' '); + return a.localeCompare(b, 'en', { sensitivity: 'base' }) === 0; + } + break; + } + return equals(a, b); +} +exports.equivalent = equivalent; +function isCode(object) { + return object.hasMatch && typeof object.hasMatch === 'function'; +} +function codesAreEquivalent(code1, code2) { + return code1.hasMatch(code2); +} +function getClassOfObjects(object1, object2) { + return [object1, object2].map(function (obj) { return ({}.toString.call(obj)); }); +} +function compareEveryItemInArrays(array1, array2, comparisonFunction) { + return (array1.length === array2.length && + array1.every(function (item, i) { return comparisonFunction(item, array2[i]); })); +} +function compareObjects(a, b, comparisonFunction) { + if (!classesEqual(a, b)) { + return false; + } + return deepCompareKeysAndValues(a, b, comparisonFunction); +} +function classesEqual(object1, object2) { + return object2 instanceof object1.constructor && object1 instanceof object2.constructor; +} +function deepCompareKeysAndValues(a, b, comparisonFunction) { + var finalComparisonResult; + var aKeys = getKeysFromObject(a).sort(); + var bKeys = getKeysFromObject(b).sort(); + // Array.every() will only return true or false, so set a flag for if we should return null + var shouldReturnNull = false; + // Check if both arrays of keys are the same length and key names match + if (aKeys.length === bKeys.length && aKeys.every(function (value, index) { return value === bKeys[index]; })) { + finalComparisonResult = aKeys.every(function (key) { + // if both are null we should return true to satisfy ignoring empty values in tuples + if (a[key] == null && b[key] == null) { + return true; + } + var comparisonResult = comparisonFunction(a[key], b[key]); + if (comparisonResult === null) { + shouldReturnNull = true; + } + return comparisonResult; + }); + } + else { + finalComparisonResult = false; + } + if (shouldReturnNull) { + return null; + } + return finalComparisonResult; +} +function getKeysFromObject(object) { + return Object.keys(object).filter(function (k) { return !isFunction(object[k]); }); +} +function isFunction(input) { + return input instanceof Function || {}.toString.call(input) === '[object Function]'; +} +function equals(a, b) { + // Handle null cases first: spec says if either is null, return null + if (a == null || b == null) { + return null; + } + // If one is a Quantity, use the Quantity equals function + if (a && a.isQuantity) { + return a.equals(b); + } + // If one is a Ratio, use the ratio equals function + if (a && a.isRatio) { + return a.equals(b); + } + // If one is an Uncertainty, convert the other to an Uncertainty + if (a instanceof datatypes_1.Uncertainty) { + b = datatypes_1.Uncertainty.from(b); + } + else if (b instanceof datatypes_1.Uncertainty) { + a = datatypes_1.Uncertainty.from(a); + } + // Use overloaded 'equals' function if it is available + if (typeof a.equals === 'function') { + return a.equals(b); + } + // Return true of the objects are primitives and are strictly equal + if ((typeof a === typeof b && typeof a === 'string') || + typeof a === 'number' || + typeof a === 'boolean') { + return a === b; + } + // Return false if they are instances of different classes + var _a = getClassOfObjects(a, b), aClass = _a[0], bClass = _a[1]; + if (aClass !== bClass) { + return false; + } + switch (aClass) { + case '[object Date]': + // Compare the ms since epoch + return a.getTime() === b.getTime(); + case '[object RegExp]': + // Compare the components of the regular expression + return ['source', 'global', 'ignoreCase', 'multiline'].every(function (p) { return a[p] === b[p]; }); + case '[object Array]': + if (a.indexOf(null) >= 0 || + a.indexOf(undefined) >= 0 || + b.indexOf(null) >= 0 || + b.indexOf(undefined) >= 0) { + return null; + } + return compareEveryItemInArrays(a, b, equals); + case '[object Object]': + return compareObjects(a, b, equals); + case '[object Function]': + return a.toString() === b.toString(); } - Quantity.prototype.exec = function (_ctx) { - return new DT.Quantity(this.value, this.unit); - }; - return Quantity; -}(expression_1.Expression)); -exports.Quantity = Quantity; + // If we made it this far, we can't handle it + return false; +} +exports.equals = equals; -},{"../datatypes/datatypes":57,"./expression":73}],87:[function(require,module,exports){ +},{"../datatypes/datatypes":43}],90:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -29822,363 +27460,385 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.QueryLetRef = exports.AliasRef = exports.Query = exports.SortClause = exports.ReturnClause = exports.ByColumn = exports.ByExpression = exports.ByDirection = exports.Sort = exports.Without = exports.With = exports.LetClause = exports.AliasedQuerySource = void 0; -var expression_1 = require("./expression"); -var context_1 = require("../runtime/context"); -var util_1 = require("../util/util"); -var comparison_1 = require("../util/comparison"); -var builder_1 = require("./builder"); -var AliasedQuerySource = /** @class */ (function () { - function AliasedQuerySource(json) { - this.alias = json.alias; - this.expression = (0, builder_1.build)(json.expression); +exports.decimalOrNull = exports.decimalAdjust = exports.minValueForType = exports.minValueForInstance = exports.maxValueForType = exports.maxValueForInstance = exports.predecessor = exports.successor = exports.OverFlowException = exports.limitDecimalPrecision = exports.isValidDecimal = exports.isValidInteger = exports.overflowsOrUnderflows = exports.MAX_TIME_VALUE = exports.MIN_TIME_VALUE = exports.MAX_DATE_VALUE = exports.MIN_DATE_VALUE = exports.MAX_DATETIME_VALUE = exports.MIN_DATETIME_VALUE = exports.MIN_FLOAT_PRECISION_VALUE = exports.MIN_FLOAT_VALUE = exports.MAX_FLOAT_VALUE = exports.MIN_INT_VALUE = exports.MAX_INT_VALUE = void 0; +/* eslint-disable @typescript-eslint/no-loss-of-precision */ +var exception_1 = require("../datatypes/exception"); +var datetime_1 = require("../datatypes/datetime"); +var uncertainty_1 = require("../datatypes/uncertainty"); +exports.MAX_INT_VALUE = Math.pow(2, 31) - 1; +exports.MIN_INT_VALUE = Math.pow(-2, 31); +exports.MAX_FLOAT_VALUE = 99999999999999999999.99999999; +exports.MIN_FLOAT_VALUE = -99999999999999999999.99999999; +exports.MIN_FLOAT_PRECISION_VALUE = Math.pow(10, -8); +exports.MIN_DATETIME_VALUE = datetime_1.MIN_DATETIME_VALUE; +exports.MAX_DATETIME_VALUE = datetime_1.MAX_DATETIME_VALUE; +exports.MIN_DATE_VALUE = datetime_1.MIN_DATE_VALUE; +exports.MAX_DATE_VALUE = datetime_1.MAX_DATE_VALUE; +exports.MIN_TIME_VALUE = datetime_1.MIN_TIME_VALUE; +exports.MAX_TIME_VALUE = datetime_1.MAX_TIME_VALUE; +function overflowsOrUnderflows(value) { + if (value == null) { + return false; } - return AliasedQuerySource; -}()); -exports.AliasedQuerySource = AliasedQuerySource; -var LetClause = /** @class */ (function () { - function LetClause(json) { - this.identifier = json.identifier; - this.expression = (0, builder_1.build)(json.expression); + if (value.isQuantity) { + if (!isValidDecimal(value.value)) { + return true; + } } - return LetClause; -}()); -exports.LetClause = LetClause; -var With = /** @class */ (function (_super) { - __extends(With, _super); - function With(json) { - var _this = _super.call(this, json) || this; - _this.alias = json.alias; - _this.expression = (0, builder_1.build)(json.expression); - _this.suchThat = (0, builder_1.build)(json.suchThat); - return _this; + else if (value.isTime && value.isTime()) { + if (value.after(exports.MAX_TIME_VALUE)) { + return true; + } + if (value.before(exports.MIN_TIME_VALUE)) { + return true; + } } - With.prototype.exec = function (ctx) { - var _this = this; - var records = this.expression.execute(ctx); - if (!(0, util_1.typeIsArray)(records)) { - records = [records]; + else if (value.isDateTime) { + if (value.after(exports.MAX_DATETIME_VALUE)) { + return true; + } + if (value.before(exports.MIN_DATETIME_VALUE)) { + return true; } - var returns = records.map(function (rec) { - var childCtx = ctx.childContext(); - childCtx.set(_this.alias, rec); - return _this.suchThat.execute(childCtx); - }); - return returns.some(function (x) { return x; }); - }; - return With; -}(expression_1.Expression)); -exports.With = With; -var Without = /** @class */ (function (_super) { - __extends(Without, _super); - function Without(json) { - return _super.call(this, json) || this; } - Without.prototype.exec = function (ctx) { - return !_super.prototype.exec.call(this, ctx); - }; - return Without; -}(With)); -exports.Without = Without; -// ELM-only, not a product of CQL -var Sort = /** @class */ (function (_super) { - __extends(Sort, _super); - function Sort() { - return _super !== null && _super.apply(this, arguments) || this; + else if (value.isDate) { + if (value.after(exports.MAX_DATE_VALUE)) { + return true; + } + if (value.before(exports.MIN_DATE_VALUE)) { + return true; + } } - return Sort; -}(expression_1.UnimplementedExpression)); -exports.Sort = Sort; -var ByDirection = /** @class */ (function (_super) { - __extends(ByDirection, _super); - function ByDirection(json) { - var _this = _super.call(this, json) || this; - _this.direction = json.direction; - _this.low_order = _this.direction === 'asc' || _this.direction === 'ascending' ? -1 : 1; - _this.high_order = _this.low_order * -1; - return _this; + else if (Number.isInteger(value)) { + if (!isValidInteger(value)) { + return true; + } } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ByDirection.prototype.exec = function (ctx, a, b) { - if (a === b) { - return 0; + else if (value.isUncertainty) { + return overflowsOrUnderflows(value.low) || overflowsOrUnderflows(value.high); + } + else { + if (!isValidDecimal(value)) { + return true; } - else if (a.isQuantity && b.isQuantity) { - if (a.before(b)) { - return this.low_order; + } + return false; +} +exports.overflowsOrUnderflows = overflowsOrUnderflows; +function isValidInteger(integer) { + if (isNaN(integer)) { + return false; + } + if (integer > exports.MAX_INT_VALUE) { + return false; + } + if (integer < exports.MIN_INT_VALUE) { + return false; + } + return true; +} +exports.isValidInteger = isValidInteger; +function isValidDecimal(decimal) { + if (isNaN(decimal)) { + return false; + } + if (decimal > exports.MAX_FLOAT_VALUE) { + return false; + } + if (decimal < exports.MIN_FLOAT_VALUE) { + return false; + } + return true; +} +exports.isValidDecimal = isValidDecimal; +function limitDecimalPrecision(decimal) { + var decimalString = decimal.toString(); + // For decimals so large that they are represented in scientific notation, javascript has already limited + // the decimal to its own constraints, so we can't determine the original precision. Leave as-is unless + // this becomes problematic, in which case we would need our own parseFloat. + if (decimalString.indexOf('e') !== -1) { + return decimal; + } + var splitDecimalString = decimalString.split('.'); + var decimalPoints = splitDecimalString[1]; + if (decimalPoints != null && decimalPoints.length > 8) { + decimalString = splitDecimalString[0] + '.' + splitDecimalString[1].substring(0, 8); + } + return parseFloat(decimalString); +} +exports.limitDecimalPrecision = limitDecimalPrecision; +var OverFlowException = /** @class */ (function (_super) { + __extends(OverFlowException, _super); + function OverFlowException() { + return _super !== null && _super.apply(this, arguments) || this; + } + return OverFlowException; +}(exception_1.Exception)); +exports.OverFlowException = OverFlowException; +function successor(val) { + if (typeof val === 'number') { + if (Number.isInteger(val)) { + if (val >= exports.MAX_INT_VALUE) { + throw new OverFlowException(); } else { - return this.high_order; + return val + 1; } } - else if (a < b) { - return this.low_order; + else { + if (val >= exports.MAX_FLOAT_VALUE) { + throw new OverFlowException(); + } + else { + return val + exports.MIN_FLOAT_PRECISION_VALUE; + } + } + } + else if (val && val.isTime && val.isTime()) { + if (val.sameAs(exports.MAX_TIME_VALUE)) { + throw new OverFlowException(); } else { - return this.high_order; + return val.successor(); } - }; - return ByDirection; -}(expression_1.Expression)); -exports.ByDirection = ByDirection; -var ByExpression = /** @class */ (function (_super) { - __extends(ByExpression, _super); - function ByExpression(json) { - var _this = _super.call(this, json) || this; - _this.expression = (0, builder_1.build)(json.expression); - _this.direction = json.direction; - _this.low_order = _this.direction === 'asc' || _this.direction === 'ascending' ? -1 : 1; - _this.high_order = _this.low_order * -1; - return _this; } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ByExpression.prototype.exec = function (ctx, a, b) { - var sctx = ctx.childContext(a); - var a_val = this.expression.execute(sctx); - sctx = ctx.childContext(b); - var b_val = this.expression.execute(sctx); - if (a_val === b_val || (a_val == null && b_val == null)) { - return 0; + else if (val && val.isDateTime) { + if (val.sameAs(exports.MAX_DATETIME_VALUE)) { + throw new OverFlowException(); } - else if (a_val == null || b_val == null) { - return a_val == null ? this.low_order : this.high_order; + else { + return val.successor(); } - else if (a_val.isQuantity && b_val.isQuantity) { - return a_val.before(b_val) ? this.low_order : this.high_order; + } + else if (val && val.isDate) { + if (val.sameAs(exports.MAX_DATE_VALUE)) { + throw new OverFlowException(); } else { - return a_val < b_val ? this.low_order : this.high_order; + return val.successor(); } - }; - return ByExpression; -}(expression_1.Expression)); -exports.ByExpression = ByExpression; -var ByColumn = /** @class */ (function (_super) { - __extends(ByColumn, _super); - function ByColumn(json) { - var _this = _super.call(this, json) || this; - _this.expression = (0, builder_1.build)({ - name: json.path, - type: 'IdentifierRef' - }); - return _this; } - return ByColumn; -}(ByExpression)); -exports.ByColumn = ByColumn; -var ReturnClause = /** @class */ (function () { - function ReturnClause(json) { - this.expression = (0, builder_1.build)(json.expression); - this.distinct = json.distinct != null ? json.distinct : true; + else if (val && val.isUncertainty) { + // For uncertainties, if the high is the max val, don't increment it + var high = (function () { + try { + return successor(val.high); + } + catch (e) { + return val.high; + } + })(); + return new uncertainty_1.Uncertainty(successor(val.low), high); } - return ReturnClause; -}()); -exports.ReturnClause = ReturnClause; -var SortClause = /** @class */ (function () { - function SortClause(json) { - this.by = (0, builder_1.build)(json != null ? json.by : undefined); + else if (val && val.isQuantity) { + var succ = val.clone(); + succ.value = successor(val.value); + return succ; } - SortClause.prototype.sort = function (ctx, values) { - var _this = this; - if (this.by) { - return values.sort(function (a, b) { - var order = 0; - for (var _i = 0, _a = _this.by; _i < _a.length; _i++) { - var item = _a[_i]; - // Do not use execute here because the value of the sort order is not important. - order = item.exec(ctx, a, b); - if (order !== 0) { - break; - } - } - return order; - }); + else if (val == null) { + return null; + } +} +exports.successor = successor; +function predecessor(val) { + if (typeof val === 'number') { + if (Number.isInteger(val)) { + if (val <= exports.MIN_INT_VALUE) { + throw new OverFlowException(); + } + else { + return val - 1; + } } - }; - return SortClause; -}()); -exports.SortClause = SortClause; -var toDistinctList = function (xList) { - var yList = []; - xList.forEach(function (x) { - if (!yList.some(function (y) { return (0, comparison_1.equals)(x, y); })) { - yList.push(x); + else { + if (val <= exports.MIN_FLOAT_VALUE) { + throw new OverFlowException(); + } + else { + return val - exports.MIN_FLOAT_PRECISION_VALUE; + } } - }); - return yList; -}; -var AggregateClause = /** @class */ (function (_super) { - __extends(AggregateClause, _super); - function AggregateClause(json) { - var _this = _super.call(this, json) || this; - _this.identifier = json.identifier; - _this.expression = (0, builder_1.build)(json.expression); - _this.starting = json.starting ? (0, builder_1.build)(json.starting) : null; - _this.distinct = json.distinct != null ? json.distinct : true; - return _this; } - AggregateClause.prototype.aggregate = function (returnedValues, ctx) { - var _this = this; - var aggregateValue = this.starting != null ? this.starting.exec(ctx) : null; - returnedValues.forEach(function (contextValues) { - var childContext = ctx.childContext(contextValues); - childContext.set(_this.identifier, aggregateValue); - aggregateValue = _this.expression.exec(childContext); - }); - return aggregateValue; - }; - return AggregateClause; -}(expression_1.Expression)); -var Query = /** @class */ (function (_super) { - __extends(Query, _super); - function Query(json) { - var _this = _super.call(this, json) || this; - _this.sources = new MultiSource(json.source.map(function (s) { return new AliasedQuerySource(s); })); - _this.letClauses = json.let != null ? json.let.map(function (d) { return new LetClause(d); }) : []; - _this.relationship = json.relationship != null ? (0, builder_1.build)(json.relationship) : []; - _this.where = (0, builder_1.build)(json.where); - _this.returnClause = json.return != null ? new ReturnClause(json.return) : null; - _this.aggregateClause = json.aggregate != null ? new AggregateClause(json.aggregate) : null; - _this.aliases = _this.sources.aliases(); - _this.sortClause = json.sort != null ? new SortClause(json.sort) : null; - return _this; + else if (val && val.isTime && val.isTime()) { + if (val.sameAs(exports.MIN_TIME_VALUE)) { + throw new OverFlowException(); + } + else { + return val.predecessor(); + } } - Query.prototype.isDistinct = function () { - if (this.aggregateClause != null && this.aggregateClause.distinct != null) { - return this.aggregateClause.distinct; + else if (val && val.isDateTime) { + if (val.sameAs(exports.MIN_DATETIME_VALUE)) { + throw new OverFlowException(); } - else if (this.returnClause != null && this.returnClause.distinct != null) { - return this.returnClause.distinct; + else { + return val.predecessor(); } - return true; - }; - Query.prototype.exec = function (ctx) { - var _this = this; - var returnedValues = []; - this.sources.forEach(ctx, function (rctx) { - for (var _i = 0, _a = _this.letClauses; _i < _a.length; _i++) { - var def = _a[_i]; - rctx.set(def.identifier, def.expression.execute(rctx)); + } + else if (val && val.isDate) { + if (val.sameAs(exports.MIN_DATE_VALUE)) { + throw new OverFlowException(); + } + else { + return val.predecessor(); + } + } + else if (val && val.isUncertainty) { + // For uncertainties, if the low is the min val, don't decrement it + var low = (function () { + try { + return predecessor(val.low); } - var relations = _this.relationship.map(function (rel) { - var child_ctx = rctx.childContext(); - return rel.execute(child_ctx); - }); - var passed = (0, util_1.allTrue)(relations) && (_this.where ? _this.where.execute(rctx) : true); - if (passed) { - if (_this.returnClause != null) { - var val = _this.returnClause.expression.execute(rctx); - returnedValues.push(val); - } - else { - if (_this.aliases.length === 1 && _this.aggregateClause == null) { - returnedValues.push(rctx.get(_this.aliases[0])); - } - else { - returnedValues.push(rctx.context_values); - } - } + catch (e) { + return val.low; } - }); - if (this.isDistinct()) { - returnedValues = toDistinctList(returnedValues); + })(); + return new uncertainty_1.Uncertainty(low, predecessor(val.high)); + } + else if (val && val.isQuantity) { + var pred = val.clone(); + pred.value = predecessor(val.value); + return pred; + } + else if (val == null) { + return null; + } +} +exports.predecessor = predecessor; +function maxValueForInstance(val) { + if (typeof val === 'number') { + if (Number.isInteger(val)) { + return exports.MAX_INT_VALUE; } - if (this.aggregateClause != null) { - returnedValues = this.aggregateClause.aggregate(returnedValues, ctx); + else { + return exports.MAX_FLOAT_VALUE; } - if (this.sortClause != null) { - this.sortClause.sort(ctx, returnedValues); + } + else if (val && val.isTime && val.isTime()) { + return exports.MAX_TIME_VALUE === null || exports.MAX_TIME_VALUE === void 0 ? void 0 : exports.MAX_TIME_VALUE.copy(); + } + else if (val && val.isDateTime) { + return exports.MAX_DATETIME_VALUE === null || exports.MAX_DATETIME_VALUE === void 0 ? void 0 : exports.MAX_DATETIME_VALUE.copy(); + } + else if (val && val.isDate) { + return exports.MAX_DATE_VALUE === null || exports.MAX_DATE_VALUE === void 0 ? void 0 : exports.MAX_DATE_VALUE.copy(); + } + else if (val && val.isQuantity) { + var val2 = val.clone(); + val2.value = maxValueForInstance(val2.value); + return val2; + } + else { + return null; + } +} +exports.maxValueForInstance = maxValueForInstance; +function maxValueForType(type, quantityInstance) { + switch (type) { + case '{urn:hl7-org:elm-types:r1}Integer': + return exports.MAX_INT_VALUE; + case '{urn:hl7-org:elm-types:r1}Decimal': + return exports.MAX_FLOAT_VALUE; + case '{urn:hl7-org:elm-types:r1}DateTime': + return exports.MAX_DATETIME_VALUE === null || exports.MAX_DATETIME_VALUE === void 0 ? void 0 : exports.MAX_DATETIME_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Date': + return exports.MAX_DATE_VALUE === null || exports.MAX_DATE_VALUE === void 0 ? void 0 : exports.MAX_DATE_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Time': + return exports.MAX_TIME_VALUE === null || exports.MAX_TIME_VALUE === void 0 ? void 0 : exports.MAX_TIME_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Quantity': { + if (quantityInstance == null) { + // can't infer a quantity unit type from nothing] + return null; + } + var maxQty = quantityInstance.clone(); + maxQty.value = maxValueForInstance(maxQty.value); + return maxQty; } - if (this.sources.returnsList() || this.aggregateClause != null) { - return returnedValues; + } + return null; +} +exports.maxValueForType = maxValueForType; +function minValueForInstance(val) { + if (typeof val === 'number') { + if (Number.isInteger(val)) { + return exports.MIN_INT_VALUE; } else { - return returnedValues[0]; + return exports.MIN_FLOAT_VALUE; } - }; - return Query; -}(expression_1.Expression)); -exports.Query = Query; -var AliasRef = /** @class */ (function (_super) { - __extends(AliasRef, _super); - function AliasRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - return _this; } - AliasRef.prototype.exec = function (ctx) { - return ctx != null ? ctx.get(this.name) : undefined; - }; - return AliasRef; -}(expression_1.Expression)); -exports.AliasRef = AliasRef; -var QueryLetRef = /** @class */ (function (_super) { - __extends(QueryLetRef, _super); - function QueryLetRef(json) { - return _super.call(this, json) || this; + else if (val && val.isTime && val.isTime()) { + return exports.MIN_TIME_VALUE === null || exports.MIN_TIME_VALUE === void 0 ? void 0 : exports.MIN_TIME_VALUE.copy(); } - return QueryLetRef; -}(AliasRef)); -exports.QueryLetRef = QueryLetRef; -// The following is not defined by ELM but is helpful for execution -var MultiSource = /** @class */ (function () { - function MultiSource(sources) { - this.sources = sources; - this.alias = this.sources[0].alias; - this.expression = this.sources[0].expression; - this.isList = true; - if (this.sources.length > 1) { - this.rest = new MultiSource(this.sources.slice(1)); - } + else if (val && val.isDateTime) { + return exports.MIN_DATETIME_VALUE === null || exports.MIN_DATETIME_VALUE === void 0 ? void 0 : exports.MIN_DATETIME_VALUE.copy(); } - MultiSource.prototype.aliases = function () { - var a = [this.alias]; - if (this.rest) { - a = a.concat(this.rest.aliases()); - } - return a; - }; - MultiSource.prototype.returnsList = function () { - return this.isList || (this.rest && this.rest.returnsList()); - }; - MultiSource.prototype.forEach = function (ctx, func) { - var _this = this; - var records = this.expression.execute(ctx); - this.isList = (0, util_1.typeIsArray)(records); - records = this.isList ? records : [records]; - return records.map(function (rec) { - var rctx = new context_1.Context(ctx); - rctx.set(_this.alias, rec); - if (_this.rest) { - return _this.rest.forEach(rctx, func); - } - else { - return func(rctx); + else if (val && val.isDate) { + return exports.MIN_DATE_VALUE === null || exports.MIN_DATE_VALUE === void 0 ? void 0 : exports.MIN_DATE_VALUE.copy(); + } + else if (val && val.isQuantity) { + var val2 = val.clone(); + val2.value = minValueForInstance(val2.value); + return val2; + } + else { + return null; + } +} +exports.minValueForInstance = minValueForInstance; +function minValueForType(type, quantityInstance) { + switch (type) { + case '{urn:hl7-org:elm-types:r1}Integer': + return exports.MIN_INT_VALUE; + case '{urn:hl7-org:elm-types:r1}Decimal': + return exports.MIN_FLOAT_VALUE; + case '{urn:hl7-org:elm-types:r1}DateTime': + return exports.MIN_DATETIME_VALUE === null || exports.MIN_DATETIME_VALUE === void 0 ? void 0 : exports.MIN_DATETIME_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Date': + return exports.MIN_DATE_VALUE === null || exports.MIN_DATE_VALUE === void 0 ? void 0 : exports.MIN_DATE_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Time': + return exports.MIN_TIME_VALUE === null || exports.MIN_TIME_VALUE === void 0 ? void 0 : exports.MIN_TIME_VALUE.copy(); + case '{urn:hl7-org:elm-types:r1}Quantity': { + if (quantityInstance == null) { + // can't infer a quantity unit type from nothing] + return null; } - }); - }; - return MultiSource; -}()); + var minQty = quantityInstance.clone(); + minQty.value = minValueForInstance(minQty.value); + return minQty; + } + } + return null; +} +exports.minValueForType = minValueForType; +function decimalAdjust(type, value, exp) { + //If the exp is undefined or zero... + if (typeof exp === 'undefined' || +exp === 0) { + return Math[type](value); + } + value = +value; + exp = +exp; + //If the value is not a number or the exp is not an integer... + if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) { + return NaN; + } + //Shift + value = value.toString().split('e'); + var v = value[1] ? +value[1] - exp : -exp; + value = Math[type](+(value[0] + 'e' + v)); + //Shift back + value = value.toString().split('e'); + v = value[1] ? +value[1] + exp : exp; + return +(value[0] + 'e' + v); +} +exports.decimalAdjust = decimalAdjust; +function decimalOrNull(value) { + return isValidDecimal(value) ? value : null; +} +exports.decimalOrNull = decimalOrNull; -},{"../runtime/context":93,"../util/comparison":103,"../util/util":106,"./builder":67,"./expression":73}],88:[function(require,module,exports){ +},{"../datatypes/datetime":44,"../datatypes/exception":45,"../datatypes/uncertainty":50}],91:[function(require,module,exports){ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -30198,35432 +27858,37870 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Ratio = void 0; -var expression_1 = require("./expression"); -var quantity_1 = require("../datatypes/quantity"); -var DT = __importStar(require("../datatypes/datatypes")); -var Ratio = /** @class */ (function (_super) { - __extends(Ratio, _super); - function Ratio(json) { - var _this = _super.call(this, json) || this; - if (json.numerator == null) { - throw new Error('Cannot create a ratio with an undefined numerator value'); +exports.getQuotientOfUnits = exports.getProductOfUnits = exports.compareUnits = exports.convertToCQLDateUnit = exports.normalizeUnitsWhenPossible = exports.convertUnit = exports.checkUnit = void 0; +var ucum = __importStar(require("@lhncbc/ucum-lhc")); +var math_1 = require("./math"); +var utils = ucum.UcumLhcUtils.getInstance(); +// The CQL specification says that dates are based on the Gregorian calendar, so CQL-based year and month +// identifiers will be matched to the UCUM gregorian units. See http://unitsofmeasure.org/ucum.html#para-31 +var CQL_TO_UCUM_DATE_UNITS = { + years: 'a_g', + year: 'a_g', + months: 'mo_g', + month: 'mo_g', + weeks: 'wk', + week: 'wk', + days: 'd', + day: 'd', + hours: 'h', + hour: 'h', + minutes: 'min', + minute: 'min', + seconds: 's', + second: 's', + milliseconds: 'ms', + millisecond: 'ms' +}; +var UCUM_TO_CQL_DATE_UNITS = { + a: 'year', + a_j: 'year', + a_g: 'year', + mo: 'month', + mo_j: 'month', + mo_g: 'month', + wk: 'week', + d: 'day', + h: 'hour', + min: 'minute', + s: 'second', + ms: 'millisecond' +}; +// Cache Map for unit validity results so we dont have to go to ucum-lhc for every check. +var unitValidityCache = new Map(); +function checkUnit(unit, allowEmptyUnits, allowCQLDateUnits) { + if (allowEmptyUnits === void 0) { allowEmptyUnits = true; } + if (allowCQLDateUnits === void 0) { allowCQLDateUnits = true; } + if (allowEmptyUnits) { + unit = fixEmptyUnit(unit); + } + if (allowCQLDateUnits) { + unit = fixCQLDateUnit(unit); + } + if (!unitValidityCache.has(unit)) { + var result = utils.validateUnitString(unit, true); + if (result.status === 'valid') { + unitValidityCache.set(unit, { valid: true }); } else { - _this.numerator = new quantity_1.Quantity(json.numerator.value, json.numerator.unit); + var msg = "Invalid UCUM unit: '".concat(unit, "'."); + if (result.ucumCode != null) { + msg += " Did you mean '".concat(result.ucumCode, "'?"); + } + unitValidityCache.set(unit, { valid: false, message: msg }); } - if (json.denominator == null) { - throw new Error('Cannot create a ratio with an undefined denominator value'); + } + return unitValidityCache.get(unit); +} +exports.checkUnit = checkUnit; +function convertUnit(fromVal, fromUnit, toUnit, adjustPrecision) { + var _a; + if (adjustPrecision === void 0) { adjustPrecision = true; } + _a = [fromUnit, toUnit].map(fixUnit), fromUnit = _a[0], toUnit = _a[1]; + var result = utils.convertUnitTo(fixUnit(fromUnit), fromVal, fixUnit(toUnit)); + if (result.status !== 'succeeded') { + return; + } + return adjustPrecision ? (0, math_1.decimalAdjust)('round', result.toVal, -8) : result.toVal; +} +exports.convertUnit = convertUnit; +function normalizeUnitsWhenPossible(val1, unit1, val2, unit2) { + var _a; + // If both units are CQL date units, return CQL date units + var useCQLDateUnits = unit1 in CQL_TO_UCUM_DATE_UNITS && unit2 in CQL_TO_UCUM_DATE_UNITS; + var resultConverter = function (unit) { + return useCQLDateUnits ? convertToCQLDateUnit(unit) : unit; + }; + _a = [unit1, unit2].map(function (u) { return fixUnit(u); }), unit1 = _a[0], unit2 = _a[1]; + if (unit1 === unit2) { + return [val1, unit1, val2, unit2]; + } + var baseUnit1 = getBaseUnitAndPower(unit1)[0]; + var baseUnit2 = getBaseUnitAndPower(unit2)[0]; + var _b = convertToBaseUnit(val2, unit2, baseUnit1), newVal2 = _b[0], newUnit2 = _b[1]; + if (newVal2 == null) { + // it was not convertible, so just return the quantities as-is + return [val1, resultConverter(unit1), val2, resultConverter(unit2)]; + } + // If the new val2 > old val2, return since we prefer conversion to smaller units + if (newVal2 >= val2) { + return [val1, resultConverter(unit1), newVal2, resultConverter(newUnit2)]; + } + // else it was a conversion to a larger unit, so go the other way around + var _c = convertToBaseUnit(val1, unit1, baseUnit2), newVal1 = _c[0], newUnit1 = _c[1]; + if (newVal1 == null) { + // this should not happen since we established they are convertible, but just in case... + return [val1, resultConverter(unit1), newVal2, resultConverter(newUnit2)]; + } + return [newVal1, resultConverter(newUnit1), val2, resultConverter(unit2)]; +} +exports.normalizeUnitsWhenPossible = normalizeUnitsWhenPossible; +function convertToCQLDateUnit(unit) { + var dateUnit; + if (unit in CQL_TO_UCUM_DATE_UNITS) { + // it's already a CQL unit, so return it as-is, removing trailing 's' if necessary (e.g., years -> year) + dateUnit = unit.replace(/s$/, ''); + } + else if (unit in UCUM_TO_CQL_DATE_UNITS) { + dateUnit = UCUM_TO_CQL_DATE_UNITS[unit]; + } + return dateUnit; +} +exports.convertToCQLDateUnit = convertToCQLDateUnit; +function compareUnits(unit1, unit2) { + try { + var c = convertUnit(1, unit1, unit2); + if (c && c > 1) { + // unit1 is bigger (less precise) + return 1; } - else { - _this.denominator = new quantity_1.Quantity(json.denominator.value, json.denominator.unit); + else if (c && c < 1) { + // unit1 is smaller + return -1; } - return _this; + //units are the same + return 0; } - Ratio.prototype.exec = function (_ctx) { - return new DT.Ratio(this.numerator, this.denominator); - }; - return Ratio; -}(expression_1.Expression)); -exports.Ratio = Ratio; - -},{"../datatypes/datatypes":57,"../datatypes/quantity":62,"./expression":73}],89:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IdentifierRef = exports.OperandRef = exports.FunctionRef = exports.FunctionDef = exports.ExpressionRef = exports.ExpressionDef = void 0; -var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var ExpressionDef = /** @class */ (function (_super) { - __extends(ExpressionDef, _super); - function ExpressionDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.context = json.context; - _this.expression = (0, builder_1.build)(json.expression); - return _this; + catch (e) { + return null; } - ExpressionDef.prototype.exec = function (ctx) { - var value = this.expression != null ? this.expression.execute(ctx) : undefined; - ctx.rootContext().set(this.name, value); - return value; - }; - return ExpressionDef; -}(expression_1.Expression)); -exports.ExpressionDef = ExpressionDef; -var ExpressionRef = /** @class */ (function (_super) { - __extends(ExpressionRef, _super); - function ExpressionRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.library = json.libraryName; - return _this; +} +exports.compareUnits = compareUnits; +function getProductOfUnits(unit1, unit2) { + var _a; + _a = [unit1, unit2].map(fixEmptyUnit), unit1 = _a[0], unit2 = _a[1]; + if (!checkUnit(unit1).valid || !checkUnit(unit2).valid) { + return null; } - ExpressionRef.prototype.exec = function (ctx) { - ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; - var value = ctx.get(this.name); - if (value instanceof expression_1.Expression) { - value = value.execute(ctx); + // If either unit contains a divisor,combine the numerators and denominators, then divide + if (unit1.indexOf('/') >= 0 || unit2.indexOf('/') >= 0) { + // NOTE: We're not trying to get perfection on unit simplification, but doing what is reasonable + var match1 = unit1.match(/([^/]*)(\/(.*))?/); + var match2 = unit2.match(/([^/]*)(\/(.*))?/); + // In the previous regexes, numerator is match[1], denominator is match[3] + var newNum = getProductOfUnits(match1[1], match2[1]); + var newDen = getProductOfUnits(match1[3], match2[3]); + return getQuotientOfUnits(newNum, newDen); + } + // Get all the individual units being combined, accounting for multipliers (e.g., 'm.L'), + // and then group like base units to combine powers (and remove '1's since they are no-ops) + // e.g., 'm.L' * 'm' ==> { m: 2, L: 1}; 'm.L' * '1' ==> { m: 1, L: 1 }; '1' : '1' ==> { } + var factorPowerMap = new Map(); + var factors = __spreadArray(__spreadArray([], unit1.split('.'), true), unit2.split('.'), true); + factors.forEach(function (factor) { + var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; + if (baseUnit === '1' || power === 0) { + // skip factors that are 1 since 1 * N is N. + return; } - return value; - }; - return ExpressionRef; -}(expression_1.Expression)); -exports.ExpressionRef = ExpressionRef; -var FunctionDef = /** @class */ (function (_super) { - __extends(FunctionDef, _super); - function FunctionDef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.expression = (0, builder_1.build)(json.expression); - _this.parameters = json.operand; - return _this; + var accumulatedPower = (factorPowerMap.get(baseUnit) || 0) + power; + factorPowerMap.set(baseUnit, accumulatedPower); + }); + // Loop through the factor map, rebuilding each factor w/ combined power and join them all + // back via the multiplier '.', treating a final '' (no non-1 units) as '1' + // e.g., { m: 2, L: 1 } ==> 'm2.L' + return fixUnit(Array.from(factorPowerMap.entries()) + .map(function (_a) { + var base = _a[0], power = _a[1]; + return "".concat(base).concat(power > 1 ? power : ''); + }) + .join('.')); +} +exports.getProductOfUnits = getProductOfUnits; +function getQuotientOfUnits(unit1, unit2) { + var _a; + _a = [unit1, unit2].map(fixEmptyUnit), unit1 = _a[0], unit2 = _a[1]; + if (!checkUnit(unit1).valid || !checkUnit(unit2).valid) { + return null; + } + // Try to simplify division when neither unit contains a divisor itself + if (unit1.indexOf('/') === -1 && unit2.indexOf('/') === -1) { + // Get all the individual units in numerator and denominator accounting for multipliers + // (e.g., 'm.L'), and then group like base units to combine powers, inversing denominator + // powers since they are being divided. + // e.g., 'm3.L' / 'm' ==> { m: 2, L: -1}; 'm.L' / '1' ==> { m: 1, L: 1 }; '1' / '1' ==> { 1: 0 } + var factorPowerMap_1 = new Map(); + unit1.split('.').forEach(function (factor) { + var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; + var accumulatedPower = (factorPowerMap_1.get(baseUnit) || 0) + power; + factorPowerMap_1.set(baseUnit, accumulatedPower); + }); + unit2.split('.').forEach(function (factor) { + var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; + var accumulatedPower = (factorPowerMap_1.get(baseUnit) || 0) - power; + factorPowerMap_1.set(baseUnit, accumulatedPower); + }); + // Construct the numerator from factors with positive power, and denominator from factors + // with negative power, filtering out base `1` and power 0 (which is also 1). + // e.g. numerator: { m: 2, L: -2 } ==> 'm2'; { 1: 1, L: -1 } => '' + // e.g. denominator: { m: 2, L: -2 } ==> 'L2'; { 1: 1, L: -1 } => 'L' + var numerator = Array.from(factorPowerMap_1.entries()) + .filter(function (_a) { + var base = _a[0], power = _a[1]; + return base !== '1' && power > 0; + }) + .map(function (_a) { + var base = _a[0], power = _a[1]; + return "".concat(base).concat(power > 1 ? power : ''); + }) + .join('.'); + var denominator = Array.from(factorPowerMap_1.entries()) + .filter(function (_a) { + var base = _a[0], power = _a[1]; + return base !== '1' && power < 0; + }) + .map(function (_a) { + var base = _a[0], power = _a[1]; + return "".concat(base).concat(power < -1 ? power * -1 : ''); + }) + .join('.'); + // wrap the denominator in parentheses if necessary + denominator = /[.]/.test(denominator) ? "(".concat(denominator, ")") : denominator; + return fixUnit("".concat(numerator).concat(denominator !== '' ? '/' + denominator : '')); + } + // One of the units had a divisor, so don't try to be too smart; just construct it from the parts + if (unit1 === unit2) { + // e.g. 'm/g' / 'm/g' ==> '1' + return '1'; + } + else if (unit2 === '1') { + // e.g., 'm/g' / '1' ==> 'm/g/' + return unit1; + } + else { + // denominator is unit2, wrapped in parentheses if necessary + var denominator = /[./]/.test(unit2) ? "(".concat(unit2, ")") : unit2; + if (unit1 === '1') { + // e.g., '1' / 'm' ==> '/m'; '1' / 'm.g' ==> '/(m.g)' + return "/".concat(denominator); + } + // e.g., 'L' / 'm' ==> 'L/m'; 'L' / 'm.g' ==> 'L/(m.g)' + return "".concat(unit1, "/").concat(denominator); + } +} +exports.getQuotientOfUnits = getQuotientOfUnits; +// UNEXPORTED FUNCTIONS +function convertToBaseUnit(fromVal, fromUnit, toBaseUnit) { + var fromPower = getBaseUnitAndPower(fromUnit)[1]; + var toUnit = fromPower === 1 ? toBaseUnit : "".concat(toBaseUnit).concat(fromPower); + var newVal = convertUnit(fromVal, fromUnit, toUnit); + return newVal != null ? [newVal, toUnit] : []; +} +function getBaseUnitAndPower(unit) { + // don't try to extract power from complex units (containing multipliers or divisors) + if (/[./]/.test(unit)) { + return [unit, 1]; + } + unit = fixUnit(unit); + var _a = unit.match(/^(.*[^-\d])?([-]?\d*)$/).slice(1), term = _a[0], power = _a[1]; + if (term == null || term === '') { + term = power; + power = '1'; } - FunctionDef.prototype.exec = function (_ctx) { - return this; - }; - return FunctionDef; -}(expression_1.Expression)); -exports.FunctionDef = FunctionDef; -var FunctionRef = /** @class */ (function (_super) { - __extends(FunctionRef, _super); - function FunctionRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.library = json.libraryName; - return _this; + else if (power == null || power === '') { + power = '1'; } - FunctionRef.prototype.exec = function (ctx) { - var functionDefs, child_ctx; - if (this.library) { - var lib = ctx.get(this.library); - functionDefs = lib ? lib.getFunction(this.name) : undefined; - var libCtx = ctx.getLibraryContext(this.library); - child_ctx = libCtx ? libCtx.childContext() : undefined; + return [term, parseInt(power)]; +} +function fixEmptyUnit(unit) { + if (unit == null || (unit.trim && unit.trim() === '')) { + return '1'; + } + return unit; +} +function fixCQLDateUnit(unit) { + return CQL_TO_UCUM_DATE_UNITS[unit] || unit; +} +function fixUnit(unit) { + return fixCQLDateUnit(fixEmptyUnit(unit)); +} + +},{"./math":90,"@lhncbc/ucum-lhc":103}],92:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getTimezoneSeparatorFromString = exports.normalizeMillisecondsField = exports.normalizeMillisecondsFieldInString = exports.jsDate = exports.anyTrue = exports.allTrue = exports.typeIsArray = exports.isNull = exports.numerical_sort = exports.removeNulls = void 0; +function removeNulls(things) { + return things.filter(function (x) { return x != null; }); +} +exports.removeNulls = removeNulls; +function numerical_sort(things, direction) { + return things.sort(function (a, b) { + if (direction == null || direction === 'asc' || direction === 'ascending') { + return a - b; } else { - functionDefs = ctx.get(this.name); - child_ctx = ctx.childContext(); - } - var args = this.execArgs(ctx); - // Filter out functions w/ wrong number of arguments. - functionDefs = functionDefs.filter(function (f) { return f.parameters.length === args.length; }); - // If there is still > 1 matching function, filter by argument types - if (functionDefs.length > 1) { - functionDefs = functionDefs.filter(function (f) { - var match = true; - for (var i = 0; i < args.length && match; i++) { - if (args[i] !== null) { - var operandTypeSpecifier = f.parameters[i].operandTypeSpecifier; - if (operandTypeSpecifier == null && f.parameters[i].operandType != null) { - // convert it to a NamedTypedSpecifier - operandTypeSpecifier = { - name: f.parameters[i].operandType, - type: 'NamedTypeSpecifier' - }; - } - match = ctx.matchesTypeSpecifier(args[i], operandTypeSpecifier); - } - } - return match; - }); - } - // If there is still > 1 matching function, calculate a score based on quality of matches - if (functionDefs.length > 1) { - // TODO - } - if (functionDefs.length === 0) { - throw new Error('no function with matching signature could be found'); - } - // By this point, we should have only one function, but until implementation is completed, - // use the last one (no matter how many still remain) - var functionDef = functionDefs[functionDefs.length - 1]; - for (var i = 0; i < functionDef.parameters.length; i++) { - child_ctx.set(functionDef.parameters[i].name, args[i]); + return b - a; } - return functionDef.expression.execute(child_ctx); - }; - return FunctionRef; -}(expression_1.Expression)); -exports.FunctionRef = FunctionRef; -var OperandRef = /** @class */ (function (_super) { - __extends(OperandRef, _super); - function OperandRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - return _this; + }); +} +exports.numerical_sort = numerical_sort; +function isNull(value) { + return value === null; +} +exports.isNull = isNull; +exports.typeIsArray = Array.isArray || (function (value) { return ({}.toString.call(value) === '[object Array]'); }); +function allTrue(things) { + if ((0, exports.typeIsArray)(things)) { + return things.every(function (x) { return x; }); } - OperandRef.prototype.exec = function (ctx) { - return ctx.get(this.name); - }; - return OperandRef; -}(expression_1.Expression)); -exports.OperandRef = OperandRef; -var IdentifierRef = /** @class */ (function (_super) { - __extends(IdentifierRef, _super); - function IdentifierRef(json) { - var _this = _super.call(this, json) || this; - _this.name = json.name; - _this.library = json.libraryName; - return _this; + else { + return things; } - IdentifierRef.prototype.exec = function (ctx) { - // TODO: Technically, the ELM Translator should never output one of these - // but this code is needed since it does, as a work-around to get queries - // to work properly when sorting by a field in a tuple - var lib = this.library ? ctx.get(this.library) : undefined; - var val = lib ? lib.get(this.name) : ctx.get(this.name); - if (val == null) { - var parts = this.name.split('.'); - val = ctx.get(parts[0]); - if (val != null && parts.length > 1) { - var curr_obj = val; - for (var _i = 0, _a = parts.slice(1); _i < _a.length; _i++) { - var part = _a[_i]; - // _obj = curr_obj?[part] ? curr_obj?.get?(part) - // curr_obj = if _obj instanceof Function then _obj.call(curr_obj) else _obj - var _obj = void 0; - if (curr_obj != null) { - _obj = curr_obj[part]; - if (_obj === undefined && typeof curr_obj.get === 'function') { - _obj = curr_obj.get(part); - } - } - curr_obj = _obj instanceof Function ? _obj.call(curr_obj) : _obj; - } - val = curr_obj; - } - } - if (val instanceof Function) { - return val.call(ctx.context_values); +} +exports.allTrue = allTrue; +function anyTrue(things) { + if ((0, exports.typeIsArray)(things)) { + return things.some(function (x) { return x; }); + } + else { + return things; + } +} +exports.anyTrue = anyTrue; +//The export below is to make it easier if js Date is overwritten with CQL Date +exports.jsDate = Date; +function normalizeMillisecondsFieldInString(string, msString) { + // TODO: verify we are only removing numeral digits + var timezoneField; + msString = normalizeMillisecondsField(msString); + var _a = string.split('.'), beforeMs = _a[0], msAndAfter = _a[1]; + var timezoneSeparator = getTimezoneSeparatorFromString(msAndAfter); + if (timezoneSeparator) { + timezoneField = msAndAfter != null ? msAndAfter.split(timezoneSeparator)[1] : undefined; + } + if (timezoneField == null) { + timezoneField = ''; + } + return (string = beforeMs + '.' + msString + timezoneSeparator + timezoneField); +} +exports.normalizeMillisecondsFieldInString = normalizeMillisecondsFieldInString; +function normalizeMillisecondsField(msString) { + // fix up milliseconds by padding zeros and/or truncating (5 --> 500, 50 --> 500, 54321 --> 543, etc.) + return (msString = (msString + '00').substring(0, 3)); +} +exports.normalizeMillisecondsField = normalizeMillisecondsField; +function getTimezoneSeparatorFromString(string) { + if (string != null) { + var matches = string.match(/-/); + if (matches && matches.length === 1) { + return '-'; } - else { - return val; + matches = string.match(/\+/); + if (matches && matches.length === 1) { + return '+'; } - }; - return IdentifierRef; -}(expression_1.Expression)); -exports.IdentifierRef = IdentifierRef; + } + return ''; +} +exports.getTimezoneSeparatorFromString = getTimezoneSeparatorFromString; + +},{}],93:[function(require,module,exports){ +module.exports={"license":"The following data (prefixes and units) was generated by the UCUM LHC code from the UCUM data and selected LOINC combinations of UCUM units. The license for the UCUM LHC code (demo and library code as well as the combined units) is located at https://github.com/lhncbc/ucum-lhc/blob/LICENSE.md.","prefixes":{"config":["code_","ciCode_","name_","printSymbol_","value_","exp_"],"data":[["E","EX","exa","E",1000000000000000000,"18"],["G","GA","giga","G",1000000000,"9"],["Gi","GIB","gibi","Gi",1073741824,null],["Ki","KIB","kibi","Ki",1024,null],["M","MA","mega","M",1000000,"6"],["Mi","MIB","mebi","Mi",1048576,null],["P","PT","peta","P",1000000000000000,"15"],["T","TR","tera","T",1000000000000,"12"],["Ti","TIB","tebi","Ti",1099511627776,null],["Y","YA","yotta","Y",1e+24,"24"],["Z","ZA","zetta","Z",1e+21,"21"],["a","A","atto","a",1e-18,"-18"],["c","C","centi","c",0.01,"-2"],["d","D","deci","d",0.1,"-1"],["da","DA","deka","da",10,"1"],["f","F","femto","f",1e-15,"-15"],["h","H","hecto","h",100,"2"],["k","K","kilo","k",1000,"3"],["m","M","milli","m",0.001,"-3"],["n","N","nano","n",1e-9,"-9"],["p","P","pico","p",1e-12,"-12"],["u","U","micro","μ",0.000001,"-6"],["y","YO","yocto","y",1.0000000000000001e-24,"-24"],["z","ZO","zepto","z",1e-21,"-21"]]},"units":{"config":["isBase_","name_","csCode_","ciCode_","property_","magnitude_",["dim_","dimVec_"],"printSymbol_","class_","isMetric_","variable_","cnv_","cnvPfx_","isSpecial_","isArbitrary_","moleExp_","synonyms_","source_","loincProperty_","category_","guidance_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_"],"data":[[true,"meter","m","M","length",1,[1,0,0,0,0,0,0],"m",null,false,"L",null,1,false,false,0,"meters; metres; distance","UCUM","Len","Clinical","unit of length = 1.09361 yards",null,null,null,null,false],[true,"second - time","s","S","time",1,[0,1,0,0,0,0,0],"s",null,false,"T",null,1,false,false,0,"seconds","UCUM","Time","Clinical","",null,null,null,null,false],[true,"gram","g","G","mass",1,[0,0,1,0,0,0,0],"g",null,false,"M",null,1,false,false,0,"grams; gm","UCUM","Mass","Clinical","",null,null,null,null,false],[true,"radian","rad","RAD","plane angle",1,[0,0,0,1,0,0,0],"rad",null,false,"A",null,1,false,false,0,"radians","UCUM","Angle","Clinical","unit of angular measure where 1 radian = 1/2π turn = 57.296 degrees. ",null,null,null,null,false],[true,"degree Kelvin","K","K","temperature",1,[0,0,0,0,1,0,0],"K",null,false,"C",null,1,false,false,0,"Kelvin; degrees","UCUM","Temp","Clinical","absolute, thermodynamic temperature scale ",null,null,null,null,false],[true,"coulomb","C","C","electric charge",1,[0,0,0,0,0,1,0],"C",null,false,"Q",null,1,false,false,0,"coulombs","UCUM","","Clinical","defined as amount of 1 electron charge = 6.2415093×10^18 e, and equivalent to 1 Ampere-second",null,null,null,null,false],[true,"candela","cd","CD","luminous intensity",1,[0,0,0,0,0,0,1],"cd",null,false,"F",null,1,false,false,0,"candelas","UCUM","","Clinical","SI base unit of luminous intensity",null,null,null,null,false],[false,"the number ten for arbitrary powers","10*","10*","number",10,[0,0,0,0,0,0,0],"10","dimless",false,null,null,1,false,false,0,"10^; 10 to the arbitrary powers","UCUM","Num","Clinical","10* by itself is the same as 10, but users can add digits after the *. For example, 10*3 = 1000.","1","1","10",10,false],[false,"the number ten for arbitrary powers","10^","10^","number",10,[0,0,0,0,0,0,0],"10","dimless",false,null,null,1,false,false,0,"10*; 10 to the arbitrary power","UCUM","Num","Clinical","10* by itself is the same as 10, but users can add digits after the *. For example, 10*3 = 1000.","1","1","10",10,false],[false,"the number pi","[pi]","[PI]","number",3.141592653589793,[0,0,0,0,0,0,0],"π","dimless",false,null,null,1,false,false,0,"π","UCUM","","Constant","a mathematical constant; the ratio of a circle's circumference to its diameter ≈ 3.14159","1","1","3.1415926535897932384626433832795028841971693993751058209749445923",3.141592653589793,false],[false,"","%","%","fraction",0.01,[0,0,0,0,0,0,0],"%","dimless",false,null,null,1,false,false,0,"percents","UCUM","FR; NFR; MFR; CFR; SFR Rto; etc. ","Clinical","","10*-2","10*-2","1",1,false],[false,"parts per thousand","[ppth]","[PPTH]","fraction",0.001,[0,0,0,0,0,0,0],"ppth","dimless",false,null,null,1,false,false,0,"ppth; 10^-3","UCUM","MCnc; MCnt","Clinical","[ppth] is often used in solution concentrations as 1 g/L or 1 g/kg.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-3","10*-3","1",1,false],[false,"parts per million","[ppm]","[PPM]","fraction",0.000001,[0,0,0,0,0,0,0],"ppm","dimless",false,null,null,1,false,false,0,"ppm; 10^-6","UCUM","MCnt; MCnc; SFr","Clinical","[ppm] is often used in solution concentrations as 1 mg/L or 1 mg/kg. Also used to express mole fractions as 1 mmol/mol.\n\n[ppm] is also used in nuclear magnetic resonance (NMR) to represent chemical shift - the difference of a measured frequency in parts per million from the reference frequency.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-6","10*-6","1",1,false],[false,"parts per billion","[ppb]","[PPB]","fraction",1e-9,[0,0,0,0,0,0,0],"ppb","dimless",false,null,null,1,false,false,0,"ppb; 10^-9","UCUM","MCnt; MCnc; SFr","Clinical","[ppb] is often used in solution concentrations as 1 ug/L or 1 ug/kg. Also used to express mole fractions as 1 umol/mol.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-9","10*-9","1",1,false],[false,"parts per trillion","[pptr]","[PPTR]","fraction",1e-12,[0,0,0,0,0,0,0],"pptr","dimless",false,null,null,1,false,false,0,"pptr; 10^-12","UCUM","MCnt; MCnc; SFr","Clinical","[pptr] is often used in solution concentrations as 1 ng/L or 1 ng/kg. Also used to express mole fractions as 1 nmol/mol.\n\nCan be ambigous and would be better if the metric units was used directly. ","10*-12","10*-12","1",1,false],[false,"mole","mol","MOL","amount of substance",6.0221367e+23,[0,0,0,0,0,0,0],"mol","si",true,null,null,1,false,false,1,"moles","UCUM","Sub","Clinical","Measure the number of molecules ","10*23","10*23","6.0221367",6.0221367,false],[false,"steradian - solid angle","sr","SR","solid angle",1,[0,0,0,2,0,0,0],"sr","si",true,null,null,1,false,false,0,"square radian; rad2; rad^2","UCUM","Angle","Clinical","unit of solid angle in three-dimensional geometry analagous to radian; used in photometry which measures the perceived brightness of object by human eye (e.g. radiant intensity = watt/steradian)","rad2","RAD2","1",1,false],[false,"hertz","Hz","HZ","frequency",1,[0,-1,0,0,0,0,0],"Hz","si",true,null,null,1,false,false,0,"Herz; frequency; frequencies","UCUM","Freq; Num","Clinical","equal to one cycle per second","s-1","S-1","1",1,false],[false,"newton","N","N","force",1000,[1,-2,1,0,0,0,0],"N","si",true,null,null,1,false,false,0,"Newtons","UCUM","Force","Clinical","unit of force with base units kg.m/s2","kg.m/s2","KG.M/S2","1",1,false],[false,"pascal","Pa","PAL","pressure",1000,[-1,-2,1,0,0,0,0],"Pa","si",true,null,null,1,false,false,0,"pascals","UCUM","Pres","Clinical","standard unit of pressure equal to 1 newton per square meter (N/m2)","N/m2","N/M2","1",1,false],[false,"joule","J","J","energy",1000,[2,-2,1,0,0,0,0],"J","si",true,null,null,1,false,false,0,"joules","UCUM","Enrg","Clinical","unit of energy defined as the work required to move an object 1 m with a force of 1 N (N.m) or an electric charge of 1 C through 1 V (C.V), or to produce 1 W for 1 s (W.s) ","N.m","N.M","1",1,false],[false,"watt","W","W","power",1000,[2,-3,1,0,0,0,0],"W","si",true,null,null,1,false,false,0,"watts","UCUM","EngRat","Clinical","unit of power equal to 1 Joule per second (J/s) = kg⋅m2⋅s−3","J/s","J/S","1",1,false],[false,"Ampere","A","A","electric current",1,[0,-1,0,0,0,1,0],"A","si",true,null,null,1,false,false,0,"Amperes","UCUM","ElpotRat","Clinical","unit of electric current equal to flow rate of electrons equal to 16.2415×10^18 elementary charges moving past a boundary in one second or 1 Coulomb/second","C/s","C/S","1",1,false],[false,"volt","V","V","electric potential",1000,[2,-2,1,0,0,-1,0],"V","si",true,null,null,1,false,false,0,"volts","UCUM","Elpot","Clinical","unit of electric potential (voltage) = 1 Joule per Coulomb (J/C)","J/C","J/C","1",1,false],[false,"farad","F","F","electric capacitance",0.001,[-2,2,-1,0,0,2,0],"F","si",true,null,null,1,false,false,0,"farads; electric capacitance","UCUM","","Clinical","CGS unit of electric capacitance with base units C/V (Coulomb per Volt)","C/V","C/V","1",1,false],[false,"ohm","Ohm","OHM","electric resistance",1000,[2,-1,1,0,0,-2,0],"Ω","si",true,null,null,1,false,false,0,"Ω; resistance; ohms","UCUM","","Clinical","unit of electrical resistance with units of Volt per Ampere","V/A","V/A","1",1,false],[false,"siemens","S","SIE","electric conductance",0.001,[-2,1,-1,0,0,2,0],"S","si",true,null,null,1,false,false,0,"Reciprocal ohm; mho; Ω−1; conductance","UCUM","","Clinical","unit of electric conductance (the inverse of electrical resistance) equal to ohm^-1","Ohm-1","OHM-1","1",1,false],[false,"weber","Wb","WB","magnetic flux",1000,[2,-1,1,0,0,-1,0],"Wb","si",true,null,null,1,false,false,0,"magnetic flux; webers","UCUM","","Clinical","unit of magnetic flux equal to Volt second","V.s","V.S","1",1,false],[false,"degree Celsius","Cel","CEL","temperature",1,[0,0,0,0,1,0,0],"°C","si",true,null,"Cel",1,true,false,0,"°C; degrees","UCUM","Temp","Clinical","","K",null,null,1,false],[false,"tesla","T","T","magnetic flux density",1000,[0,-1,1,0,0,-1,0],"T","si",true,null,null,1,false,false,0,"Teslas; magnetic field","UCUM","","Clinical","SI unit of magnetic field strength for magnetic field B equal to 1 Weber/square meter = 1 kg/(s2*A)","Wb/m2","WB/M2","1",1,false],[false,"henry","H","H","inductance",1000,[2,0,1,0,0,-2,0],"H","si",true,null,null,1,false,false,0,"henries; inductance","UCUM","","Clinical","unit of electrical inductance; usually expressed in millihenrys (mH) or microhenrys (uH).","Wb/A","WB/A","1",1,false],[false,"lumen","lm","LM","luminous flux",1,[0,0,0,2,0,0,1],"lm","si",true,null,null,1,false,false,0,"luminous flux; lumens","UCUM","","Clinical","unit of luminous flux defined as 1 lm = 1 cd⋅sr (candela times sphere)","cd.sr","CD.SR","1",1,false],[false,"lux","lx","LX","illuminance",1,[-2,0,0,2,0,0,1],"lx","si",true,null,null,1,false,false,0,"illuminance; luxes","UCUM","","Clinical","unit of illuminance equal to one lumen per square meter. ","lm/m2","LM/M2","1",1,false],[false,"becquerel","Bq","BQ","radioactivity",1,[0,-1,0,0,0,0,0],"Bq","si",true,null,null,1,false,false,0,"activity; radiation; becquerels","UCUM","","Clinical","measure of the atomic radiation rate with units s^-1","s-1","S-1","1",1,false],[false,"gray","Gy","GY","energy dose",1,[2,-2,0,0,0,0,0],"Gy","si",true,null,null,1,false,false,0,"absorbed doses; ionizing radiation doses; kerma; grays","UCUM","EngCnt","Clinical","unit of ionizing radiation dose with base units of 1 joule of radiation energy per kilogram of matter","J/kg","J/KG","1",1,false],[false,"sievert","Sv","SV","dose equivalent",1,[2,-2,0,0,0,0,0],"Sv","si",true,null,null,1,false,false,0,"sieverts; radiation dose quantities; equivalent doses; effective dose; operational dose; committed dose","UCUM","","Clinical","SI unit for radiation dose equivalent equal to 1 Joule/kilogram.","J/kg","J/KG","1",1,false],[false,"degree - plane angle","deg","DEG","plane angle",0.017453292519943295,[0,0,0,1,0,0,0],"°","iso1000",false,null,null,1,false,false,0,"°; degree of arc; arc degree; arcdegree; angle","UCUM","Angle","Clinical","one degree is equivalent to π/180 radians.","[pi].rad/360","[PI].RAD/360","2",2,false],[false,"gon","gon","GON","plane angle",0.015707963267948967,[0,0,0,1,0,0,0],"□g","iso1000",false,null,null,1,false,false,0,"gon (grade); gons","UCUM","Angle","Nonclinical","unit of plane angle measurement equal to 1/400 circle","deg","DEG","0.9",0.9,false],[false,"arc minute","'","'","plane angle",0.0002908882086657216,[0,0,0,1,0,0,0],"'","iso1000",false,null,null,1,false,false,0,"arcminutes; arcmin; arc minutes; arc mins","UCUM","Angle","Clinical","equal to 1/60 degree; used in optometry and opthamology (e.g. visual acuity tests)","deg/60","DEG/60","1",1,false],[false,"arc second","''","''","plane angle",0.00000484813681109536,[0,0,0,1,0,0,0],"''","iso1000",false,null,null,1,false,false,0,"arcseconds; arcsecs","UCUM","Angle","Clinical","equal to 1/60 arcminute = 1/3600 degree; used in optometry and opthamology (e.g. visual acuity tests)","'/60","'/60","1",1,false],[false,"Liters","l","L","volume",0.001,[3,0,0,0,0,0,0],"l","iso1000",true,null,null,1,false,false,0,"cubic decimeters; decimeters cubed; decimetres; dm3; dm^3; litres; liters, LT ","UCUM","Vol","Clinical","Because lower case \"l\" can be read as the number \"1\", though this is a valid UCUM units. UCUM strongly reccomends using \"L\"","dm3","DM3","1",1,false],[false,"Liters","L","L","volume",0.001,[3,0,0,0,0,0,0],"L","iso1000",true,null,null,1,false,false,0,"cubic decimeters; decimeters cubed; decimetres; dm3; dm^3; litres; liters, LT ","UCUM","Vol","Clinical","Because lower case \"l\" can be read as the number \"1\", though this is a valid UCUM units. UCUM strongly reccomends using \"L\"","l",null,"1",1,false],[false,"are","ar","AR","area",100,[2,0,0,0,0,0,0],"a","iso1000",true,null,null,1,false,false,0,"100 m2; 100 m^2; 100 square meter; meters squared; metres","UCUM","Area","Clinical","metric base unit for area defined as 100 m^2","m2","M2","100",100,false],[false,"minute","min","MIN","time",60,[0,1,0,0,0,0,0],"min","iso1000",false,null,null,1,false,false,0,"minutes","UCUM","Time","Clinical","","s","S","60",60,false],[false,"hour","h","HR","time",3600,[0,1,0,0,0,0,0],"h","iso1000",false,null,null,1,false,false,0,"hours; hrs; age","UCUM","Time","Clinical","","min","MIN","60",60,false],[false,"day","d","D","time",86400,[0,1,0,0,0,0,0],"d","iso1000",false,null,null,1,false,false,0,"days; age; dy; 24 hours; 24 hrs","UCUM","Time","Clinical","","h","HR","24",24,false],[false,"tropical year","a_t","ANN_T","time",31556925.216,[0,1,0,0,0,0,0],"at","iso1000",false,null,null,1,false,false,0,"solar years; a tropical; years","UCUM","Time","Clinical","has an average of 365.242181 days but is constantly changing.","d","D","365.24219",365.24219,false],[false,"mean Julian year","a_j","ANN_J","time",31557600,[0,1,0,0,0,0,0],"aj","iso1000",false,null,null,1,false,false,0,"mean Julian yr; a julian; years","UCUM","Time","Clinical","has an average of 365.25 days, and in everyday use, has been replaced by the Gregorian year. However, this unit is used in astronomy to calculate light year. ","d","D","365.25",365.25,false],[false,"mean Gregorian year","a_g","ANN_G","time",31556952,[0,1,0,0,0,0,0],"ag","iso1000",false,null,null,1,false,false,0,"mean Gregorian yr; a gregorian; years","UCUM","Time","Clinical","has an average of 365.2425 days and is the most internationally used civil calendar.","d","D","365.2425",365.2425,false],[false,"year","a","ANN","time",31557600,[0,1,0,0,0,0,0],"a","iso1000",false,null,null,1,false,false,0,"years; a; yr, yrs; annum","UCUM","Time","Clinical","","a_j","ANN_J","1",1,false],[false,"week","wk","WK","time",604800,[0,1,0,0,0,0,0],"wk","iso1000",false,null,null,1,false,false,0,"weeks; wks","UCUM","Time","Clinical","","d","D","7",7,false],[false,"synodal month","mo_s","MO_S","time",2551442.976,[0,1,0,0,0,0,0],"mos","iso1000",false,null,null,1,false,false,0,"Moon; synodic month; lunar month; mo-s; mo s; months; moons","UCUM","Time","Nonclinical","has an average of 29.53 days per month, unit used in astronomy","d","D","29.53059",29.53059,false],[false,"mean Julian month","mo_j","MO_J","time",2629800,[0,1,0,0,0,0,0],"moj","iso1000",false,null,null,1,false,false,0,"mo-julian; mo Julian; months","UCUM","Time","Clinical","has an average of 30.435 days per month","a_j/12","ANN_J/12","1",1,false],[false,"mean Gregorian month","mo_g","MO_G","time",2629746,[0,1,0,0,0,0,0],"mog","iso1000",false,null,null,1,false,false,0,"months; month-gregorian; mo-gregorian","UCUM","Time","Clinical","has an average 30.436875 days per month and is from the most internationally used civil calendar.","a_g/12","ANN_G/12","1",1,false],[false,"month","mo","MO","time",2629800,[0,1,0,0,0,0,0],"mo","iso1000",false,null,null,1,false,false,0,"months; duration","UCUM","Time","Clinical","based on Julian calendar which has an average of 30.435 days per month (this unit is used in astronomy but not in everyday life - see mo_g)","mo_j","MO_J","1",1,false],[false,"metric ton","t","TNE","mass",1000000,[0,0,1,0,0,0,0],"t","iso1000",true,null,null,1,false,false,0,"tonnes; megagrams; tons","UCUM","Mass","Nonclinical","equal to 1000 kg used in the US (recognized by NIST as metric ton), and internationally (recognized as tonne)","kg","KG","1e3",1000,false],[false,"bar","bar","BAR","pressure",100000000,[-1,-2,1,0,0,0,0],"bar","iso1000",true,null,null,1,false,false,0,"bars","UCUM","Pres","Nonclinical","unit of pressure equal to 10^5 Pascals, primarily used by meteorologists and in weather forecasting","Pa","PAL","1e5",100000,false],[false,"unified atomic mass unit","u","AMU","mass",1.6605402e-24,[0,0,1,0,0,0,0],"u","iso1000",true,null,null,1,false,false,0,"unified atomic mass units; amu; Dalton; Da","UCUM","Mass","Clinical","the mass of 1/12 of an unbound Carbon-12 atom nuclide equal to 1.6606x10^-27 kg ","g","G","1.6605402e-24",1.6605402e-24,false],[false,"astronomic unit","AU","ASU","length",149597870691,[1,0,0,0,0,0,0],"AU","iso1000",false,null,null,1,false,false,0,"AU; units","UCUM","Len","Clinical","unit of length used in astronomy for measuring distance in Solar system","Mm","MAM","149597.870691",149597.870691,false],[false,"parsec","pc","PRS","length",30856780000000000,[1,0,0,0,0,0,0],"pc","iso1000",true,null,null,1,false,false,0,"parsecs","UCUM","Len","Clinical","unit of length equal to 3.26 light years, nad used to measure large distances to objects outside our Solar System","m","M","3.085678e16",30856780000000000,false],[false,"velocity of light in a vacuum","[c]","[C]","velocity",299792458,[1,-1,0,0,0,0,0],"c","const",true,null,null,1,false,false,0,"speed of light","UCUM","Vel","Constant","equal to 299792458 m/s (approximately 3 x 10^8 m/s)","m/s","M/S","299792458",299792458,false],[false,"Planck constant","[h]","[H]","action",6.6260755e-31,[2,-1,1,0,0,0,0],"h","const",true,null,null,1,false,false,0,"Planck's constant","UCUM","","Constant","constant = 6.62607004 × 10-34 m2.kg/s; defined as quantum of action","J.s","J.S","6.6260755e-34",6.6260755e-34,false],[false,"Boltzmann constant","[k]","[K]","(unclassified)",1.380658e-20,[2,-2,1,0,-1,0,0],"k","const",true,null,null,1,false,false,0,"k; kB","UCUM","","Constant","physical constant relating energy at the individual particle level with temperature = 1.38064852 ×10^−23 J/K","J/K","J/K","1.380658e-23",1.380658e-23,false],[false,"permittivity of vacuum - electric","[eps_0]","[EPS_0]","electric permittivity",8.854187817000001e-15,[-3,2,-1,0,0,2,0],"ε0","const",true,null,null,1,false,false,0,"ε0; Electric Constant; vacuum permittivity; permittivity of free space ","UCUM","","Constant","approximately equal to 8.854 × 10^−12 F/m (farads per meter)","F/m","F/M","8.854187817e-12",8.854187817e-12,false],[false,"permeability of vacuum - magnetic","[mu_0]","[MU_0]","magnetic permeability",0.0012566370614359172,[1,0,1,0,0,-2,0],"μ0","const",true,null,null,1,false,false,0,"μ0; vacuum permeability; permeability of free space; magnetic constant","UCUM","","Constant","equal to 4π×10^−7 N/A2 (Newtons per square ampere) ≈ 1.2566×10^−6 H/m (Henry per meter)","N/A2","4.[PI].10*-7.N/A2","1",0.0000012566370614359173,false],[false,"elementary charge","[e]","[E]","electric charge",1.60217733e-19,[0,0,0,0,0,1,0],"e","const",true,null,null,1,false,false,0,"e; q; electric charges","UCUM","","Constant","the magnitude of the electric charge carried by a single electron or proton ≈ 1.60217×10^-19 Coulombs","C","C","1.60217733e-19",1.60217733e-19,false],[false,"electronvolt","eV","EV","energy",1.60217733e-16,[2,-2,1,0,0,0,0],"eV","iso1000",true,null,null,1,false,false,0,"Electron Volts; electronvolts","UCUM","Eng","Clinical","unit of kinetic energy = 1 V * 1.602×10^−19 C = 1.6×10−19 Joules","[e].V","[E].V","1",1,false],[false,"electron mass","[m_e]","[M_E]","mass",9.1093897e-28,[0,0,1,0,0,0,0],"me","const",true,null,null,1,false,false,0,"electron rest mass; me","UCUM","Mass","Constant","approximately equal to 9.10938356 × 10-31 kg; defined as the mass of a stationary electron","g","g","9.1093897e-28",9.1093897e-28,false],[false,"proton mass","[m_p]","[M_P]","mass",1.6726231e-24,[0,0,1,0,0,0,0],"mp","const",true,null,null,1,false,false,0,"mp; masses","UCUM","Mass","Constant","approximately equal to 1.672622×10−27 kg","g","g","1.6726231e-24",1.6726231e-24,false],[false,"Newtonian constant of gravitation","[G]","[GC]","(unclassified)",6.67259e-14,[3,-2,-1,0,0,0,0],"G","const",true,null,null,1,false,false,0,"G; gravitational constant; Newton's constant","UCUM","","Constant","gravitational constant = 6.674×10−11 N⋅m2/kg2","m3.kg-1.s-2","M3.KG-1.S-2","6.67259e-11",6.67259e-11,false],[false,"standard acceleration of free fall","[g]","[G]","acceleration",9.80665,[1,-2,0,0,0,0,0],"gn","const",true,null,null,1,false,false,0,"standard gravity; g; ɡ0; ɡn","UCUM","Accel","Constant","defined by standard = 9.80665 m/s2","m/s2","M/S2","980665e-5",9.80665,false],[false,"Torr","Torr","Torr","pressure",133322,[-1,-2,1,0,0,0,0],"Torr","const",false,null,null,1,false,false,0,"torrs","UCUM","Pres","Clinical","1 torr = 1 mmHg; unit used to measure blood pressure","Pa","PAL","133.322",133.322,false],[false,"standard atmosphere","atm","ATM","pressure",101325000,[-1,-2,1,0,0,0,0],"atm","const",false,null,null,1,false,false,0,"reference pressure; atmos; std atmosphere","UCUM","Pres","Clinical","defined as being precisely equal to 101,325 Pa","Pa","PAL","101325",101325,false],[false,"light-year","[ly]","[LY]","length",9460730472580800,[1,0,0,0,0,0,0],"l.y.","const",true,null,null,1,false,false,0,"light years; ly","UCUM","Len","Constant","unit of astronomal distance = 5.88×10^12 mi","[c].a_j","[C].ANN_J","1",1,false],[false,"gram-force","gf","GF","force",9.80665,[1,-2,1,0,0,0,0],"gf","const",true,null,null,1,false,false,0,"Newtons; gram forces","UCUM","Force","Clinical","May be specific to unit related to cardiac output","g.[g]","G.[G]","1",1,false],[false,"Kayser","Ky","KY","lineic number",100,[-1,0,0,0,0,0,0],"K","cgs",true,null,null,1,false,false,0,"wavenumbers; kaysers","UCUM","InvLen","Clinical","unit of wavelength equal to cm^-1","cm-1","CM-1","1",1,false],[false,"Gal","Gal","GL","acceleration",0.01,[1,-2,0,0,0,0,0],"Gal","cgs",true,null,null,1,false,false,0,"galileos; Gals","UCUM","Accel","Clinical","unit of acceleration used in gravimetry; equivalent to cm/s2 ","cm/s2","CM/S2","1",1,false],[false,"dyne","dyn","DYN","force",0.01,[1,-2,1,0,0,0,0],"dyn","cgs",true,null,null,1,false,false,0,"dynes","UCUM","Force","Clinical","unit of force equal to 10^-5 Newtons","g.cm/s2","G.CM/S2","1",1,false],[false,"erg","erg","ERG","energy",0.0001,[2,-2,1,0,0,0,0],"erg","cgs",true,null,null,1,false,false,0,"10^-7 Joules, 10-7 Joules; 100 nJ; 100 nanoJoules; 1 dyne cm; 1 g.cm2/s2","UCUM","Eng","Clinical","unit of energy = 1 dyne centimeter = 10^-7 Joules","dyn.cm","DYN.CM","1",1,false],[false,"Poise","P","P","dynamic viscosity",100,[-1,-1,1,0,0,0,0],"P","cgs",true,null,null,1,false,false,0,"dynamic viscosity; poises","UCUM","Visc","Clinical","unit of dynamic viscosity where 1 Poise = 1/10 Pascal second","dyn.s/cm2","DYN.S/CM2","1",1,false],[false,"Biot","Bi","BI","electric current",10,[0,-1,0,0,0,1,0],"Bi","cgs",true,null,null,1,false,false,0,"Bi; abamperes; abA","UCUM","ElpotRat","Clinical","equal to 10 amperes","A","A","10",10,false],[false,"Stokes","St","ST","kinematic viscosity",0.0001,[2,-1,0,0,0,0,0],"St","cgs",true,null,null,1,false,false,0,"kinematic viscosity","UCUM","Visc","Clinical","unit of kimematic viscosity with units cm2/s","cm2/s","CM2/S","1",1,false],[false,"Maxwell","Mx","MX","flux of magnetic induction",0.00001,[2,-1,1,0,0,-1,0],"Mx","cgs",true,null,null,1,false,false,0,"magnetix flux; Maxwells","UCUM","","Clinical","unit of magnetic flux","Wb","WB","1e-8",1e-8,false],[false,"Gauss","G","GS","magnetic flux density",0.1,[0,-1,1,0,0,-1,0],"Gs","cgs",true,null,null,1,false,false,0,"magnetic fields; magnetic flux density; induction; B","UCUM","magnetic","Clinical","CGS unit of magnetic flux density, known as magnetic field B; defined as one maxwell unit per square centimeter (see Oersted for CGS unit for H field)","T","T","1e-4",0.0001,false],[false,"Oersted","Oe","OE","magnetic field intensity",79.57747154594767,[-1,-1,0,0,0,1,0],"Oe","cgs",true,null,null,1,false,false,0,"H magnetic B field; Oersteds","UCUM","","Clinical","CGS unit of the auxiliary magnetic field H defined as 1 dyne per unit pole = 1000/4π amperes per meter (see Gauss for CGS unit for B field)","A/m","/[PI].A/M","250",79.57747154594767,false],[false,"Gilbert","Gb","GB","magnetic tension",0.7957747154594768,[0,-1,0,0,0,1,0],"Gb","cgs",true,null,null,1,false,false,0,"Gi; magnetomotive force; Gilberts","UCUM","","Clinical","unit of magnetomotive force (magnetic potential)","Oe.cm","OE.CM","1",1,false],[false,"stilb","sb","SB","lum. intensity density",10000,[-2,0,0,0,0,0,1],"sb","cgs",true,null,null,1,false,false,0,"stilbs","UCUM","","Obsolete","unit of luminance; equal to and replaced by unit candela per square centimeter (cd/cm2)","cd/cm2","CD/CM2","1",1,false],[false,"Lambert","Lmb","LMB","brightness",3183.098861837907,[-2,0,0,0,0,0,1],"L","cgs",true,null,null,1,false,false,0,"luminance; lamberts","UCUM","","Clinical","unit of luminance defined as 1 lambert = 1/ π candela per square meter","cd/cm2/[pi]","CD/CM2/[PI]","1",1,false],[false,"phot","ph","PHT","illuminance",0.0001,[-2,0,0,2,0,0,1],"ph","cgs",true,null,null,1,false,false,0,"phots","UCUM","","Clinical","CGS photometric unit of illuminance, or luminous flux through an area equal to 10000 lumens per square meter = 10000 lux","lx","LX","1e-4",0.0001,false],[false,"Curie","Ci","CI","radioactivity",37000000000,[0,-1,0,0,0,0,0],"Ci","cgs",true,null,null,1,false,false,0,"curies","UCUM","","Obsolete","unit for measuring atomic disintegration rate; replaced by the Bequerel (Bq) unit","Bq","BQ","37e9",37000000000,false],[false,"Roentgen","R","ROE","ion dose",2.58e-7,[0,0,-1,0,0,1,0],"R","cgs",true,null,null,1,false,false,0,"röntgen; Roentgens","UCUM","","Clinical","unit of exposure of X-rays and gamma rays in air; unit used primarily in the US but strongly discouraged by NIST","C/kg","C/KG","2.58e-4",0.000258,false],[false,"radiation absorbed dose","RAD","[RAD]","energy dose",0.01,[2,-2,0,0,0,0,0],"RAD","cgs",true,null,null,1,false,false,0,"doses","UCUM","","Clinical","unit of radiation absorbed dose used primarily in the US with base units 100 ergs per gram of material. Also see the SI unit Gray (Gy).","erg/g","ERG/G","100",100,false],[false,"radiation equivalent man","REM","[REM]","dose equivalent",0.01,[2,-2,0,0,0,0,0],"REM","cgs",true,null,null,1,false,false,0,"Roentgen Equivalent in Man; rems; dose equivalents","UCUM","","Clinical","unit of equivalent dose which measures the effect of radiation on humans equal to 0.01 sievert. Used primarily in the US. Also see SI unit Sievert (Sv)","RAD","[RAD]","1",1,false],[false,"inch","[in_i]","[IN_I]","length",0.025400000000000002,[1,0,0,0,0,0,0],"in","intcust",false,null,null,1,false,false,0,"inches; in; international inch; body height","UCUM","Len","Clinical","standard unit for inch in the US and internationally","cm","CM","254e-2",2.54,false],[false,"foot","[ft_i]","[FT_I]","length",0.3048,[1,0,0,0,0,0,0],"ft","intcust",false,null,null,1,false,false,0,"ft; fts; foot; international foot; feet; international feet; height","UCUM","Len","Clinical","unit used in the US and internationally","[in_i]","[IN_I]","12",12,false],[false,"yard","[yd_i]","[YD_I]","length",0.9144000000000001,[1,0,0,0,0,0,0],"yd","intcust",false,null,null,1,false,false,0,"international yards; yds; distance","UCUM","Len","Clinical","standard unit used in the US and internationally","[ft_i]","[FT_I]","3",3,false],[false,"mile","[mi_i]","[MI_I]","length",1609.344,[1,0,0,0,0,0,0],"mi","intcust",false,null,null,1,false,false,0,"international miles; mi I; statute mile","UCUM","Len","Clinical","standard unit used in the US and internationally","[ft_i]","[FT_I]","5280",5280,false],[false,"fathom","[fth_i]","[FTH_I]","depth of water",1.8288000000000002,[1,0,0,0,0,0,0],"fth","intcust",false,null,null,1,false,false,0,"international fathoms","UCUM","Len","Nonclinical","unit used in the US and internationally to measure depth of water; same length as the US fathom","[ft_i]","[FT_I]","6",6,false],[false,"nautical mile","[nmi_i]","[NMI_I]","length",1852,[1,0,0,0,0,0,0],"n.mi","intcust",false,null,null,1,false,false,0,"nautical mile; nautical miles; international nautical mile; international nautical miles; nm; n.m.; nmi","UCUM","Len","Nonclinical","standard unit used in the US and internationally","m","M","1852",1852,false],[false,"knot","[kn_i]","[KN_I]","velocity",0.5144444444444445,[1,-1,0,0,0,0,0],"knot","intcust",false,null,null,1,false,false,0,"kn; kt; international knots","UCUM","Vel","Nonclinical","defined as equal to one nautical mile (1.852 km) per hour","[nmi_i]/h","[NMI_I]/H","1",1,false],[false,"square inch","[sin_i]","[SIN_I]","area",0.0006451600000000001,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"in2; in^2; inches squared; sq inch; inches squared; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[in_i]2","[IN_I]2","1",1,false],[false,"square foot","[sft_i]","[SFT_I]","area",0.09290304,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"ft2; ft^2; ft squared; sq ft; feet; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[ft_i]2","[FT_I]2","1",1,false],[false,"square yard","[syd_i]","[SYD_I]","area",0.8361273600000002,[2,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"yd2; yd^2; sq. yds; yards squared; international","UCUM","Area","Clinical","standard unit used in the US and internationally","[yd_i]2","[YD_I]2","1",1,false],[false,"cubic inch","[cin_i]","[CIN_I]","volume",0.000016387064000000003,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"in3; in^3; in*3; inches^3; inches*3; cu. in; cu in; cubic inches; inches cubed; cin","UCUM","Vol","Clinical","standard unit used in the US and internationally","[in_i]3","[IN_I]3","1",1,false],[false,"cubic foot","[cft_i]","[CFT_I]","volume",0.028316846592000004,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"ft3; ft^3; ft*3; cu. ft; cubic feet; cubed; [ft_i]3; international","UCUM","Vol","Clinical","","[ft_i]3","[FT_I]3","1",1,false],[false,"cubic yard","[cyd_i]","[CYD_I]","volume",0.7645548579840002,[3,0,0,0,0,0,0],"cu.yd","intcust",false,null,null,1,false,false,0,"cubic yards; cubic yds; cu yards; CYs; yards^3; yd^3; yds^3; yd3; yds3","UCUM","Vol","Nonclinical","standard unit used in the US and internationally","[yd_i]3","[YD_I]3","1",1,false],[false,"board foot","[bf_i]","[BF_I]","volume",0.002359737216,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"BDFT; FBM; BF; board feet; international","UCUM","Vol","Nonclinical","unit of volume used to measure lumber","[in_i]3","[IN_I]3","144",144,false],[false,"cord","[cr_i]","[CR_I]","volume",3.6245563637760005,[3,0,0,0,0,0,0],null,"intcust",false,null,null,1,false,false,0,"crd I; international cords","UCUM","Vol","Nonclinical","unit of measure of dry volume used to measure firewood equal 128 ft3","[ft_i]3","[FT_I]3","128",128,false],[false,"mil","[mil_i]","[MIL_I]","length",0.000025400000000000004,[1,0,0,0,0,0,0],"mil","intcust",false,null,null,1,false,false,0,"thou, thousandth; mils; international","UCUM","Len","Clinical","equal to 0.001 international inch","[in_i]","[IN_I]","1e-3",0.001,false],[false,"circular mil","[cml_i]","[CML_I]","area",5.067074790974979e-10,[2,0,0,0,0,0,0],"circ.mil","intcust",false,null,null,1,false,false,0,"circular mils; cml I; international","UCUM","Area","Clinical","","[pi]/4.[mil_i]2","[PI]/4.[MIL_I]2","1",1,false],[false,"hand","[hd_i]","[HD_I]","height of horses",0.10160000000000001,[1,0,0,0,0,0,0],"hd","intcust",false,null,null,1,false,false,0,"hands; international","UCUM","Len","Nonclinical","used to measure horse height","[in_i]","[IN_I]","4",4,false],[false,"foot - US","[ft_us]","[FT_US]","length",0.3048006096012192,[1,0,0,0,0,0,0],"ftus","us-lengths",false,null,null,1,false,false,0,"US foot; foot US; us ft; ft us; height; visual distance; feet","UCUM","Len","Obsolete","Better to use [ft_i] which refers to the length used worldwide, including in the US; [ft_us] may be confused with land survey units. ","m/3937","M/3937","1200",1200,false],[false,"yard - US","[yd_us]","[YD_US]","length",0.9144018288036575,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US yards; us yds; distance","UCUM","Len; Nrat","Obsolete","Better to use [yd_i] which refers to the length used worldwide, including in the US; [yd_us] refers to unit used in land surveys in the US","[ft_us]","[FT_US]","3",3,false],[false,"inch - US","[in_us]","[IN_US]","length",0.0254000508001016,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US inches; in us; us in; inch US","UCUM","Len","Obsolete","Better to use [in_i] which refers to the length used worldwide, including in the US","[ft_us]/12","[FT_US]/12","1",1,false],[false,"rod - US","[rd_us]","[RD_US]","length",5.029210058420117,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US rod; US rods; rd US; US rd","UCUM","Len","Obsolete","","[ft_us]","[FT_US]","16.5",16.5,false],[false,"Gunter's chain - US","[ch_us]","[CH_US]","length",20.116840233680467,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"surveyor's chain; Surveyor's chain USA; Gunter’s measurement; surveyor’s measurement; Gunter's Chain USA","UCUM","Len","Obsolete","historical unit used for land survey used only in the US","[rd_us]","[RD_US]","4",4,false],[false,"link for Gunter's chain - US","[lk_us]","[LK_US]","length",0.20116840233680466,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Links for Gunter's Chain USA","UCUM","Len","Obsolete","","[ch_us]/100","[CH_US]/100","1",1,false],[false,"Ramden's chain - US","[rch_us]","[RCH_US]","length",30.480060960121918,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Ramsden's chain; engineer's chains","UCUM","Len","Obsolete","distance measuring device used for land survey","[ft_us]","[FT_US]","100",100,false],[false,"link for Ramden's chain - US","[rlk_us]","[RLK_US]","length",0.3048006096012192,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"links for Ramsden's chain","UCUM","Len","Obsolete","","[rch_us]/100","[RCH_US]/100","1",1,false],[false,"fathom - US","[fth_us]","[FTH_US]","length",1.828803657607315,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US fathoms; fathom USA; fth us","UCUM","Len","Obsolete","same length as the international fathom - better to use international fathom ([fth_i])","[ft_us]","[FT_US]","6",6,false],[false,"furlong - US","[fur_us]","[FUR_US]","length",201.16840233680466,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"US furlongs; fur us","UCUM","Len","Nonclinical","distance unit in horse racing","[rd_us]","[RD_US]","40",40,false],[false,"mile - US","[mi_us]","[MI_US]","length",1609.3472186944373,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"U.S. Survey Miles; US statute miles; survey mi; US mi; distance","UCUM","Len","Nonclinical","Better to use [mi_i] which refers to the length used worldwide, including in the US","[fur_us]","[FUR_US]","8",8,false],[false,"acre - US","[acr_us]","[ACR_US]","area",4046.872609874252,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"Acre USA Survey; Acre USA; survey acres","UCUM","Area","Nonclinical","an older unit based on pre 1959 US statute lengths that is still sometimes used in the US only for land survey purposes. ","[rd_us]2","[RD_US]2","160",160,false],[false,"square rod - US","[srd_us]","[SRD_US]","area",25.292953811714074,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"rod2; rod^2; sq. rod; rods squared","UCUM","Area","Nonclinical","Used only in the US to measure land area, based on US statute land survey length units","[rd_us]2","[RD_US]2","1",1,false],[false,"square mile - US","[smi_us]","[SMI_US]","area",2589998.470319521,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"mi2; mi^2; sq mi; miles squared","UCUM","Area","Nonclinical","historical unit used only in the US for land survey purposes (based on the US survey mile), not the internationally recognized [mi_i]","[mi_us]2","[MI_US]2","1",1,false],[false,"section","[sct]","[SCT]","area",2589998.470319521,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"sct; sections","UCUM","Area","Nonclinical","tract of land approximately equal to 1 mile square containing 640 acres","[mi_us]2","[MI_US]2","1",1,false],[false,"township","[twp]","[TWP]","area",93239944.93150276,[2,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"twp; townships","UCUM","Area","Nonclinical","land measurement equal to 6 mile square","[sct]","[SCT]","36",36,false],[false,"mil - US","[mil_us]","[MIL_US]","length",0.0000254000508001016,[1,0,0,0,0,0,0],null,"us-lengths",false,null,null,1,false,false,0,"thou, thousandth; mils","UCUM","Len","Obsolete","better to use [mil_i] which is based on the internationally recognized inch","[in_us]","[IN_US]","1e-3",0.001,false],[false,"inch - British","[in_br]","[IN_BR]","length",0.025399980000000003,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"imperial inches; imp in; br in; british inches","UCUM","Len","Obsolete","","cm","CM","2.539998",2.539998,false],[false,"foot - British","[ft_br]","[FT_BR]","length",0.30479976000000003,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British Foot; Imperial Foot; feet; imp fts; br fts","UCUM","Len","Obsolete","","[in_br]","[IN_BR]","12",12,false],[false,"rod - British","[rd_br]","[RD_BR]","length",5.02919604,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British rods; br rd","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","16.5",16.5,false],[false,"Gunter's chain - British","[ch_br]","[CH_BR]","length",20.11678416,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Gunter's Chain British; Gunters Chain British; Surveyor's Chain British","UCUM","Len","Obsolete","historical unit used for land survey used only in Great Britain","[rd_br]","[RD_BR]","4",4,false],[false,"link for Gunter's chain - British","[lk_br]","[LK_BR]","length",0.2011678416,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Links for Gunter's Chain British","UCUM","Len","Obsolete","","[ch_br]/100","[CH_BR]/100","1",1,false],[false,"fathom - British","[fth_br]","[FTH_BR]","length",1.82879856,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British fathoms; imperial fathoms; br fth; imp fth","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","6",6,false],[false,"pace - British","[pc_br]","[PC_BR]","length",0.7619994000000001,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British paces; br pc","UCUM","Len","Nonclinical","traditional unit of length equal to 152.4 centimeters, or 1.52 meter. ","[ft_br]","[FT_BR]","2.5",2.5,false],[false,"yard - British","[yd_br]","[YD_BR]","length",0.91439928,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British yards; Br yds; distance","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","3",3,false],[false,"mile - British","[mi_br]","[MI_BR]","length",1609.3427328000002,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"imperial miles; British miles; English statute miles; imp mi, br mi","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","5280",5280,false],[false,"nautical mile - British","[nmi_br]","[NMI_BR]","length",1853.1825408000002,[1,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British nautical miles; Imperial nautical miles; Admiralty miles; n.m. br; imp nm","UCUM","Len","Obsolete","","[ft_br]","[FT_BR]","6080",6080,false],[false,"knot - British","[kn_br]","[KN_BR]","velocity",0.5147729280000001,[1,-1,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"British knots; kn br; kt","UCUM","Vel","Obsolete","based on obsolete British nautical mile ","[nmi_br]/h","[NMI_BR]/H","1",1,false],[false,"acre","[acr_br]","[ACR_BR]","area",4046.850049400269,[2,0,0,0,0,0,0],null,"brit-length",false,null,null,1,false,false,0,"Imperial acres; British; a; ac; ar; acr","UCUM","Area","Nonclinical","the standard unit for acre used in the US and internationally","[yd_br]2","[YD_BR]2","4840",4840,false],[false,"gallon - US","[gal_us]","[GAL_US]","fluid volume",0.0037854117840000006,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US gallons; US liquid gallon; gal us; Queen Anne's wine gallon","UCUM","Vol","Nonclinical","only gallon unit used in the US; [gal_us] is only used in some other countries in South American and Africa to measure gasoline volume","[in_i]3","[IN_I]3","231",231,false],[false,"barrel - US","[bbl_us]","[BBL_US]","fluid volume",0.158987294928,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"bbl","UCUM","Vol","Nonclinical","[bbl_us] is the standard unit for oil barrel, which is a unit only used in the US to measure the volume oil. ","[gal_us]","[GAL_US]","42",42,false],[false,"quart - US","[qt_us]","[QT_US]","fluid volume",0.0009463529460000001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US quarts; us qts","UCUM","Vol","Clinical","Used only in the US","[gal_us]/4","[GAL_US]/4","1",1,false],[false,"pint - US","[pt_us]","[PT_US]","fluid volume",0.00047317647300000007,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US pints; pint US; liquid pint; pt us; us pt","UCUM","Vol","Clinical","Used only in the US","[qt_us]/2","[QT_US]/2","1",1,false],[false,"gill - US","[gil_us]","[GIL_US]","fluid volume",0.00011829411825000002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US gills; gil us","UCUM","Vol","Nonclinical","only used in the context of alcohol volume in the US","[pt_us]/4","[PT_US]/4","1",1,false],[false,"fluid ounce - US","[foz_us]","[FOZ_US]","fluid volume",0.000029573529562500005,[3,0,0,0,0,0,0],"oz fl","us-volumes",false,null,null,1,false,false,0,"US fluid ounces; fl ozs; FO; fl. oz.; foz us","UCUM","Vol","Clinical","unit used only in the US","[gil_us]/4","[GIL_US]/4","1",1,false],[false,"fluid dram - US","[fdr_us]","[FDR_US]","fluid volume",0.0000036966911953125006,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US fluid drams; fdr us","UCUM","Vol","Nonclinical","equal to 1/8 US fluid ounce = 3.69 mL; used informally to mean small amount of liquor, especially Scotch whiskey","[foz_us]/8","[FOZ_US]/8","1",1,false],[false,"minim - US","[min_us]","[MIN_US]","fluid volume",6.1611519921875e-8,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"min US; US min; ♏ US","UCUM","Vol","Obsolete","","[fdr_us]/60","[FDR_US]/60","1",1,false],[false,"cord - US","[crd_us]","[CRD_US]","fluid volume",3.6245563637760005,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US cord; US cords; crd us; us crd","UCUM","Vol","Nonclinical","unit of measure of dry volume used to measure firewood equal 128 ft3 (the same as international cord [cr_i])","[ft_i]3","[FT_I]3","128",128,false],[false,"bushel - US","[bu_us]","[BU_US]","dry volume",0.03523907016688001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US bushels; US bsh; US bu","UCUM","Vol","Obsolete","Historical unit of dry volume that is rarely used today","[in_i]3","[IN_I]3","2150.42",2150.42,false],[false,"gallon - historical","[gal_wi]","[GAL_WI]","dry volume",0.004404883770860001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"Corn Gallon British; Dry Gallon US; Gallons Historical; Grain Gallon British; Winchester Corn Gallon; historical winchester gallons; wi gal","UCUM","Vol","Obsolete","historical unit of dry volume no longer used","[bu_us]/8","[BU_US]/8","1",1,false],[false,"peck - US","[pk_us]","[PK_US]","dry volume",0.008809767541720002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"US pecks; US pk","UCUM","Vol","Nonclinical","unit of dry volume rarely used today (can be used to measure volume of apples)","[bu_us]/4","[BU_US]/4","1",1,false],[false,"dry quart - US","[dqt_us]","[DQT_US]","dry volume",0.0011012209427150002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"dry quarts; dry quart US; US dry quart; dry qt; us dry qt; dqt; dqt us","UCUM","Vol","Nonclinical","historical unit of dry volume only in the US, but is rarely used today","[pk_us]/8","[PK_US]/8","1",1,false],[false,"dry pint - US","[dpt_us]","[DPT_US]","dry volume",0.0005506104713575001,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"dry pints; dry pint US; US dry pint; dry pt; dpt; dpt us","UCUM","Vol","Nonclinical","historical unit of dry volume only in the US, but is rarely used today","[dqt_us]/2","[DQT_US]/2","1",1,false],[false,"tablespoon - US","[tbs_us]","[TBS_US]","volume",0.000014786764781250002,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"Tbs; tbsp; tbs us; US tablespoons","UCUM","Vol","Clinical","unit defined as 0.5 US fluid ounces or 3 teaspoons - used only in the US. See [tbs_m] for the unit used internationally and in the US for nutrional labelling. ","[foz_us]/2","[FOZ_US]/2","1",1,false],[false,"teaspoon - US","[tsp_us]","[TSP_US]","volume",0.0000049289215937500005,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"tsp; t; US teaspoons","UCUM","Vol","Nonclinical","unit defined as 1/6 US fluid ounces - used only in the US. See [tsp_m] for the unit used internationally and in the US for nutrional labelling. ","[tbs_us]/3","[TBS_US]/3","1",1,false],[false,"cup - US customary","[cup_us]","[CUP_US]","volume",0.00023658823650000004,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"cup us; us cups","UCUM","Vol","Nonclinical","Unit defined as 1/2 US pint or 16 US tablespoons ≈ 236.59 mL, which is not the standard unit defined by the FDA of 240 mL - see [cup_m] (metric cup)","[tbs_us]","[TBS_US]","16",16,false],[false,"fluid ounce - metric","[foz_m]","[FOZ_M]","fluid volume",0.000029999999999999997,[3,0,0,0,0,0,0],"oz fl","us-volumes",false,null,null,1,false,false,0,"metric fluid ounces; fozs m; fl ozs m","UCUM","Vol","Clinical","unit used only in the US for nutritional labelling, as set by the FDA","mL","ML","30",30,false],[false,"cup - US legal","[cup_m]","[CUP_M]","volume",0.00023999999999999998,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"cup m; metric cups","UCUM","Vol","Clinical","standard unit equal to 240 mL used in the US for nutritional labelling, as defined by the FDA. Note that this is different from the US customary cup (236.59 mL) and the metric cup used in Commonwealth nations (250 mL).","mL","ML","240",240,false],[false,"teaspoon - metric","[tsp_m]","[TSP_M]","volume",0.0000049999999999999996,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"tsp; t; metric teaspoons","UCUM","Vol","Clinical","standard unit used in the US and internationally","mL","mL","5",5,false],[false,"tablespoon - metric","[tbs_m]","[TBS_M]","volume",0.000014999999999999999,[3,0,0,0,0,0,0],null,"us-volumes",false,null,null,1,false,false,0,"metric tablespoons; Tbs; tbsp; T; tbs m","UCUM","Vol","Clinical","standard unit used in the US and internationally","mL","mL","15",15,false],[false,"gallon- British","[gal_br]","[GAL_BR]","volume",0.004546090000000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial gallons, UK gallons; British gallons; br gal; imp gal","UCUM","Vol","Nonclinical","Used only in Great Britain and other Commonwealth countries","l","L","4.54609",4.54609,false],[false,"peck - British","[pk_br]","[PK_BR]","volume",0.009092180000000002,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial pecks; British pecks; br pk; imp pk","UCUM","Vol","Nonclinical","unit of dry volume rarely used today (can be used to measure volume of apples)","[gal_br]","[GAL_BR]","2",2,false],[false,"bushel - British","[bu_br]","[BU_BR]","volume",0.03636872000000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British bushels; imperial; br bsh; br bu; imp","UCUM","Vol","Obsolete","Historical unit of dry volume that is rarely used today","[pk_br]","[PK_BR]","4",4,false],[false,"quart - British","[qt_br]","[QT_BR]","volume",0.0011365225000000002,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British quarts; imperial quarts; br qts","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[gal_br]/4","[GAL_BR]/4","1",1,false],[false,"pint - British","[pt_br]","[PT_BR]","volume",0.0005682612500000001,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British pints; imperial pints; pt br; br pt; imp pt; pt imp","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[qt_br]/2","[QT_BR]/2","1",1,false],[false,"gill - British","[gil_br]","[GIL_BR]","volume",0.00014206531250000003,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"imperial gills; British gills; imp gill, br gill","UCUM","Vol","Nonclinical","only used in the context of alcohol volume in Great Britain","[pt_br]/4","[PT_BR]/4","1",1,false],[false,"fluid ounce - British","[foz_br]","[FOZ_BR]","volume",0.000028413062500000005,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British fluid ounces; Imperial fluid ounces; br fozs; imp fozs; br fl ozs","UCUM","Vol","Clinical","Used only in Great Britain and other Commonwealth countries","[gil_br]/5","[GIL_BR]/5","1",1,false],[false,"fluid dram - British","[fdr_br]","[FDR_BR]","volume",0.0000035516328125000006,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"British fluid drams; fdr br","UCUM","Vol","Nonclinical","equal to 1/8 Imperial fluid ounce = 3.55 mL; used informally to mean small amount of liquor, especially Scotch whiskey","[foz_br]/8","[FOZ_BR]/8","1",1,false],[false,"minim - British","[min_br]","[MIN_BR]","volume",5.919388020833334e-8,[3,0,0,0,0,0,0],null,"brit-volumes",false,null,null,1,false,false,0,"min br; br min; ♏ br","UCUM","Vol","Obsolete","","[fdr_br]/60","[FDR_BR]/60","1",1,false],[false,"grain","[gr]","[GR]","mass",0.06479891,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"gr; grains","UCUM","Mass","Nonclinical","an apothecary measure of mass rarely used today","mg","MG","64.79891",64.79891,false],[false,"pound","[lb_av]","[LB_AV]","mass",453.59237,[0,0,1,0,0,0,0],"lb","avoirdupois",false,null,null,1,false,false,0,"avoirdupois pounds, international pounds; av lbs; pounds","UCUM","Mass","Clinical","standard unit used in the US and internationally","[gr]","[GR]","7000",7000,false],[false,"pound force - US","[lbf_av]","[LBF_AV]","force",4448.2216152605,[1,-2,1,0,0,0,0],"lbf","const",false,null,null,1,false,false,0,"lbfs; US lbf; US pound forces","UCUM","Force","Clinical","only rarely needed in health care - see [lb_av] which is the more common unit to express weight","[lb_av].[g]","[LB_AV].[G]","1",1,false],[false,"ounce","[oz_av]","[OZ_AV]","mass",28.349523125,[0,0,1,0,0,0,0],"oz","avoirdupois",false,null,null,1,false,false,0,"ounces; international ounces; avoirdupois ounces; av ozs","UCUM","Mass","Clinical","standard unit used in the US and internationally","[lb_av]/16","[LB_AV]/16","1",1,false],[false,"Dram mass unit","[dr_av]","[DR_AV]","mass",1.7718451953125,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"Dram; drams avoirdupois; avoidupois dram; international dram","UCUM","Mass","Clinical","unit from the avoirdupois system, which is used in the US and internationally","[oz_av]/16","[OZ_AV]/16","1",1,false],[false,"short hundredweight","[scwt_av]","[SCWT_AV]","mass",45359.237,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"hundredweights; s cwt; scwt; avoirdupois","UCUM","Mass","Nonclinical","Used only in the US to equal 100 pounds","[lb_av]","[LB_AV]","100",100,false],[false,"long hundredweight","[lcwt_av]","[LCWT_AV]","mass",50802.345440000005,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"imperial hundredweights; imp cwt; lcwt; avoirdupois","UCUM","Mass","Obsolete","","[lb_av]","[LB_AV]","112",112,false],[false,"short ton - US","[ston_av]","[STON_AV]","mass",907184.74,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"ton; US tons; avoirdupois tons","UCUM","Mass","Clinical","Used only in the US","[scwt_av]","[SCWT_AV]","20",20,false],[false,"long ton - British","[lton_av]","[LTON_AV]","mass",1016046.9088000001,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"imperial tons; weight tons; British long tons; long ton avoirdupois","UCUM","Mass","Nonclinical","Used only in Great Britain and other Commonwealth countries","[lcwt_av]","[LCWT_AV]","20",20,false],[false,"stone - British","[stone_av]","[STONE_AV]","mass",6350.293180000001,[0,0,1,0,0,0,0],null,"avoirdupois",false,null,null,1,false,false,0,"British stones; avoirdupois","UCUM","Mass","Nonclinical","Used primarily in the UK and Ireland to measure body weight","[lb_av]","[LB_AV]","14",14,false],[false,"pennyweight - troy","[pwt_tr]","[PWT_TR]","mass",1.5551738400000001,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"dwt; denarius weights","UCUM","Mass","Obsolete","historical unit used to measure mass and cost of precious metals","[gr]","[GR]","24",24,false],[false,"ounce - troy","[oz_tr]","[OZ_TR]","mass",31.103476800000003,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"troy ounces; tr ozs","UCUM","Mass","Nonclinical","unit of mass for precious metals and gemstones only","[pwt_tr]","[PWT_TR]","20",20,false],[false,"pound - troy","[lb_tr]","[LB_TR]","mass",373.2417216,[0,0,1,0,0,0,0],null,"troy",false,null,null,1,false,false,0,"troy pounds; tr lbs","UCUM","Mass","Nonclinical","only used for weighing precious metals","[oz_tr]","[OZ_TR]","12",12,false],[false,"scruple","[sc_ap]","[SC_AP]","mass",1.2959782,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"scruples; sc ap","UCUM","Mass","Obsolete","","[gr]","[GR]","20",20,false],[false,"dram - apothecary","[dr_ap]","[DR_AP]","mass",3.8879346,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"ʒ; drachm; apothecaries drams; dr ap; dram ap","UCUM","Mass","Nonclinical","unit still used in the US occasionally to measure amount of drugs in pharmacies","[sc_ap]","[SC_AP]","3",3,false],[false,"ounce - apothecary","[oz_ap]","[OZ_AP]","mass",31.1034768,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"apothecary ounces; oz ap; ap ozs; ozs ap","UCUM","Mass","Obsolete","","[dr_ap]","[DR_AP]","8",8,false],[false,"pound - apothecary","[lb_ap]","[LB_AP]","mass",373.2417216,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"apothecary pounds; apothecaries pounds; ap lb; lb ap; ap lbs; lbs ap","UCUM","Mass","Obsolete","","[oz_ap]","[OZ_AP]","12",12,false],[false,"ounce - metric","[oz_m]","[OZ_M]","mass",28,[0,0,1,0,0,0,0],null,"apoth",false,null,null,1,false,false,0,"metric ounces; m ozs","UCUM","Mass","Clinical","see [oz_av] (the avoirdupois ounce) for the standard ounce used internationally; [oz_m] is equal to 28 grams and is based on the apothecaries' system of mass units which is used in some US pharmacies. ","g","g","28",28,false],[false,"line","[lne]","[LNE]","length",0.002116666666666667,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"British lines; br L; L; l","UCUM","Len","Obsolete","","[in_i]/12","[IN_I]/12","1",1,false],[false,"point (typography)","[pnt]","[PNT]","length",0.0003527777777777778,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"DTP points; desktop publishing point; pt; pnt","UCUM","Len","Nonclinical","typography unit for typesetter's length","[lne]/6","[LNE]/6","1",1,false],[false,"pica (typography)","[pca]","[PCA]","length",0.004233333333333334,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"picas","UCUM","Len","Nonclinical","typography unit for typesetter's length","[pnt]","[PNT]","12",12,false],[false,"Printer's point (typography)","[pnt_pr]","[PNT_PR]","length",0.00035145980000000004,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pnt pr","UCUM","Len","Nonclinical","typography unit for typesetter's length","[in_i]","[IN_I]","0.013837",0.013837,false],[false,"Printer's pica (typography)","[pca_pr]","[PCA_PR]","length",0.004217517600000001,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pca pr; Printer's picas","UCUM","Len","Nonclinical","typography unit for typesetter's length","[pnt_pr]","[PNT_PR]","12",12,false],[false,"pied","[pied]","[PIED]","length",0.3248,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"pieds du roi; Paris foot; royal; French; feet","UCUM","Len","Obsolete","","cm","CM","32.48",32.48,false],[false,"pouce","[pouce]","[POUCE]","length",0.027066666666666666,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"historical French inches; French royal inches","UCUM","Len","Obsolete","","[pied]/12","[PIED]/12","1",1,false],[false,"ligne","[ligne]","[LIGNE]","length",0.0022555555555555554,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Paris lines; lignes","UCUM","Len","Obsolete","","[pouce]/12","[POUCE]/12","1",1,false],[false,"didot","[didot]","[DIDOT]","length",0.0003759259259259259,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Didot point; dd; Didots Point; didots; points","UCUM","Len","Obsolete","typography unit for typesetter's length","[ligne]/6","[LIGNE]/6","1",1,false],[false,"cicero","[cicero]","[CICERO]","length",0.004511111111111111,[1,0,0,0,0,0,0],null,"typeset",false,null,null,1,false,false,0,"Didot's pica; ciceros; picas","UCUM","Len","Obsolete","typography unit for typesetter's length","[didot]","[DIDOT]","12",12,false],[false,"degrees Fahrenheit","[degF]","[DEGF]","temperature",0.5555555555555556,[0,0,0,0,1,0,0],"°F","heat",false,null,"degF",1,true,false,0,"°F; deg F","UCUM","Temp","Clinical","","K",null,null,0.5555555555555556,false],[false,"degrees Rankine","[degR]","[degR]","temperature",0.5555555555555556,[0,0,0,0,1,0,0],"°R","heat",false,null,null,1,false,false,0,"°R; °Ra; Rankine","UCUM","Temp","Obsolete","Replaced by Kelvin","K/9","K/9","5",5,false],[false,"degrees Réaumur","[degRe]","[degRe]","temperature",1.25,[0,0,0,0,1,0,0],"°Ré","heat",false,null,"degRe",1,true,false,0,"°Ré, °Re, °r; Réaumur; degree Reaumur; Reaumur","UCUM","Temp","Obsolete","replaced by Celsius","K",null,null,1.25,false],[false,"calorie at 15°C","cal_[15]","CAL_[15]","energy",4185.8,[2,-2,1,0,0,0,0],"cal15°C","heat",true,null,null,1,false,false,0,"calorie 15 C; cals 15 C; calories at 15 C","UCUM","Enrg","Nonclinical","equal to 4.1855 joules; calorie most often used in engineering","J","J","4.18580",4.1858,false],[false,"calorie at 20°C","cal_[20]","CAL_[20]","energy",4181.9,[2,-2,1,0,0,0,0],"cal20°C","heat",true,null,null,1,false,false,0,"calorie 20 C; cal 20 C; calories at 20 C","UCUM","Enrg","Clinical","equal to 4.18190 joules. ","J","J","4.18190",4.1819,false],[false,"mean calorie","cal_m","CAL_M","energy",4190.0199999999995,[2,-2,1,0,0,0,0],"calm","heat",true,null,null,1,false,false,0,"mean cals; mean calories","UCUM","Enrg","Clinical","equal to 4.19002 joules. ","J","J","4.19002",4.19002,false],[false,"international table calorie","cal_IT","CAL_IT","energy",4186.8,[2,-2,1,0,0,0,0],"calIT","heat",true,null,null,1,false,false,0,"calories IT; IT cals; international steam table calories","UCUM","Enrg","Nonclinical","used in engineering steam tables and defined as 1/860 international watt-hour; equal to 4.1868 joules","J","J","4.1868",4.1868,false],[false,"thermochemical calorie","cal_th","CAL_TH","energy",4184,[2,-2,1,0,0,0,0],"calth","heat",true,null,null,1,false,false,0,"thermochemical calories; th cals","UCUM","Enrg","Clinical","equal to 4.184 joules; used as the unit in medicine and biochemistry (equal to cal)","J","J","4.184",4.184,false],[false,"calorie","cal","CAL","energy",4184,[2,-2,1,0,0,0,0],"cal","heat",true,null,null,1,false,false,0,"gram calories; small calories","UCUM","Enrg","Clinical","equal to 4.184 joules (the same value as the thermochemical calorie, which is the most common calorie used in medicine and biochemistry)","cal_th","CAL_TH","1",1,false],[false,"nutrition label Calories","[Cal]","[CAL]","energy",4184000,[2,-2,1,0,0,0,0],"Cal","heat",false,null,null,1,false,false,0,"food calories; Cal; kcal","UCUM","Eng","Clinical","","kcal_th","KCAL_TH","1",1,false],[false,"British thermal unit at 39°F","[Btu_39]","[BTU_39]","energy",1059670,[2,-2,1,0,0,0,0],"Btu39°F","heat",false,null,null,1,false,false,0,"BTU 39F; BTU 39 F; B.T.U. 39 F; B.Th.U. 39 F; BThU 39 F; British thermal units","UCUM","Eng","Nonclinical","equal to 1.05967 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05967",1.05967,false],[false,"British thermal unit at 59°F","[Btu_59]","[BTU_59]","energy",1054800,[2,-2,1,0,0,0,0],"Btu59°F","heat",false,null,null,1,false,false,0,"BTU 59 F; BTU 59F; B.T.U. 59 F; B.Th.U. 59 F; BThU 59F; British thermal units","UCUM","Eng","Nonclinical","equal to 1.05480 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05480",1.0548,false],[false,"British thermal unit at 60°F","[Btu_60]","[BTU_60]","energy",1054680,[2,-2,1,0,0,0,0],"Btu60°F","heat",false,null,null,1,false,false,0,"BTU 60 F; BTU 60F; B.T.U. 60 F; B.Th.U. 60 F; BThU 60 F; British thermal units 60 F","UCUM","Eng","Nonclinical","equal to 1.05468 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05468",1.05468,false],[false,"mean British thermal unit","[Btu_m]","[BTU_M]","energy",1055870,[2,-2,1,0,0,0,0],"Btum","heat",false,null,null,1,false,false,0,"BTU mean; B.T.U. mean; B.Th.U. mean; BThU mean; British thermal units mean; ","UCUM","Eng","Nonclinical","equal to 1.05587 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05587",1.05587,false],[false,"international table British thermal unit","[Btu_IT]","[BTU_IT]","energy",1055055.85262,[2,-2,1,0,0,0,0],"BtuIT","heat",false,null,null,1,false,false,0,"BTU IT; B.T.U. IT; B.Th.U. IT; BThU IT; British thermal units IT","UCUM","Eng","Nonclinical","equal to 1.055 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.05505585262",1.05505585262,false],[false,"thermochemical British thermal unit","[Btu_th]","[BTU_TH]","energy",1054350,[2,-2,1,0,0,0,0],"Btuth","heat",false,null,null,1,false,false,0,"BTU Th; B.T.U. Th; B.Th.U. Th; BThU Th; thermochemical British thermal units","UCUM","Eng","Nonclinical","equal to 1.054350 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","kJ","kJ","1.054350",1.05435,false],[false,"British thermal unit","[Btu]","[BTU]","energy",1054350,[2,-2,1,0,0,0,0],"btu","heat",false,null,null,1,false,false,0,"BTU; B.T.U. ; B.Th.U.; BThU; British thermal units","UCUM","Eng","Nonclinical","equal to the thermochemical British thermal unit equal to 1.054350 kJ; used as a measure of power in the electric power, steam generation, heating, and air conditioning industries","[Btu_th]","[BTU_TH]","1",1,false],[false,"horsepower - mechanical","[HP]","[HP]","power",745699.8715822703,[2,-3,1,0,0,0,0],null,"heat",false,null,null,1,false,false,0,"imperial horsepowers","UCUM","EngRat","Nonclinical","refers to mechanical horsepower, which is unit used to measure engine power primarily in the US. ","[ft_i].[lbf_av]/s","[FT_I].[LBF_AV]/S","550",550,false],[false,"tex","tex","TEX","linear mass density (of textile thread)",0.001,[-1,0,1,0,0,0,0],"tex","heat",true,null,null,1,false,false,0,"linear mass density; texes","UCUM","","Clinical","unit of linear mass density for fibers equal to gram per 1000 meters","g/km","G/KM","1",1,false],[false,"Denier (linear mass density)","[den]","[DEN]","linear mass density (of textile thread)",0.0001111111111111111,[-1,0,1,0,0,0,0],"den","heat",false,null,null,1,false,false,0,"den; deniers","UCUM","","Nonclinical","equal to the mass in grams per 9000 meters of the fiber (1 denier = 1 strand of silk)","g/9/km","G/9/KM","1",1,false],[false,"meter of water column","m[H2O]","M[H2O]","pressure",9806650,[-1,-2,1,0,0,0,0],"m HO2","clinical",true,null,null,1,false,false,0,"mH2O; m H2O; meters of water column; metres; pressure","UCUM","Pres","Clinical","","kPa","KPAL","980665e-5",9.80665,false],[false,"meter of mercury column","m[Hg]","M[HG]","pressure",133322000,[-1,-2,1,0,0,0,0],"m Hg","clinical",true,null,null,1,false,false,0,"mHg; m Hg; meters of mercury column; metres; pressure","UCUM","Pres","Clinical","","kPa","KPAL","133.3220",133.322,false],[false,"inch of water column","[in_i'H2O]","[IN_I'H2O]","pressure",249088.91000000003,[-1,-2,1,0,0,0,0],"in HO2","clinical",false,null,null,1,false,false,0,"inches WC; inAq; in H2O; inch of water gauge; iwg; pressure","UCUM","Pres","Clinical","unit of pressure, especially in respiratory and ventilation care","m[H2O].[in_i]/m","M[H2O].[IN_I]/M","1",1,false],[false,"inch of mercury column","[in_i'Hg]","[IN_I'HG]","pressure",3386378.8000000003,[-1,-2,1,0,0,0,0],"in Hg","clinical",false,null,null,1,false,false,0,"inHg; in Hg; pressure; inches","UCUM","Pres","Clinical","unit of pressure used in US to measure barometric pressure and occasionally blood pressure (see mm[Hg] for unit used internationally)","m[Hg].[in_i]/m","M[HG].[IN_I]/M","1",1,false],[false,"peripheral vascular resistance unit","[PRU]","[PRU]","fluid resistance",133322000000,[-4,-1,1,0,0,0,0],"P.R.U.","clinical",false,null,null,1,false,false,0,"peripheral vascular resistance units; peripheral resistance unit; peripheral resistance units; PRU","UCUM","FldResist","Clinical","used to assess blood flow in the capillaries; equal to 1 mmH.min/mL = 133.3 Pa·min/mL","mm[Hg].s/ml","MM[HG].S/ML","1",1,false],[false,"Wood unit","[wood'U]","[WOOD'U]","fluid resistance",7999320000,[-4,-1,1,0,0,0,0],"Wood U.","clinical",false,null,null,1,false,false,0,"hybrid reference units; HRU; mmHg.min/L; vascular resistance","UCUM","Pres","Clinical","simplified unit of measurement for for measuring pulmonary vascular resistance that uses pressure; equal to mmHg.min/L","mm[Hg].min/L","MM[HG].MIN/L","1",1,false],[false,"diopter (lens)","[diop]","[DIOP]","refraction of a lens",1,[1,0,0,0,0,0,0],"dpt","clinical",false,null,"inv",1,false,false,0,"diopters; diop; dioptre; dpt; refractive power","UCUM","InvLen","Clinical","unit of optical power of lens represented by inverse meters (m^-1)","m","/M","1",1,false],[false,"prism diopter (magnifying power)","[p'diop]","[P'DIOP]","refraction of a prism",1,[0,0,0,1,0,0,0],"PD","clinical",false,null,"tanTimes100",1,true,false,0,"diopters; dioptres; p diops; pdiop; dpt; pdptr; Δ; cm/m; centimeter per meter; centimetre; metre","UCUM","Angle","Clinical","unit for prism correction in eyeglass prescriptions","rad",null,null,1,false],[false,"percent of slope","%[slope]","%[SLOPE]","slope",0.017453292519943295,[0,0,0,1,0,0,0],"%","clinical",false,null,"100tan",1,true,false,0,"% slope; %slope; percents slopes","UCUM","VelFr; ElpotRatFr; VelRtoFr; AccelFr","Clinical","","deg",null,null,1,false],[false,"mesh","[mesh_i]","[MESH_I]","lineic number",0.025400000000000002,[1,0,0,0,0,0,0],null,"clinical",false,null,"inv",1,false,false,0,"meshes","UCUM","NLen (lineic number)","Clinical","traditional unit of length defined as the number of strands or particles per inch","[in_i]","/[IN_I]","1",1,false],[false,"French (catheter gauge) ","[Ch]","[CH]","gauge of catheters",0.0003333333333333333,[1,0,0,0,0,0,0],"Ch","clinical",false,null,null,1,false,false,0,"Charrières, French scales; French gauges; Fr, Fg, Ga, FR, Ch","UCUM","Len; Circ; Diam","Clinical","","mm/3","MM/3","1",1,false],[false,"drop - metric (1/20 mL)","[drp]","[DRP]","volume",5e-8,[3,0,0,0,0,0,0],"drp","clinical",false,null,null,1,false,false,0,"drop dosing units; metric drops; gtt","UCUM","Vol","Clinical","standard unit used in the US and internationally for clinical medicine but note that although [drp] is defined as 1/20 milliliter, in practice, drop sizes will vary due to external factors","ml/20","ML/20","1",1,false],[false,"Hounsfield unit","[hnsf'U]","[HNSF'U]","x-ray attenuation",1,[0,0,0,0,0,0,0],"HF","clinical",false,null,null,1,false,false,0,"HU; units","UCUM","","Clinical","used to measure X-ray attenuation, especially in CT scans.","1","1","1",1,false],[false,"Metabolic Equivalent of Task ","[MET]","[MET]","metabolic cost of physical activity",5.833333333333334e-11,[3,-1,-1,0,0,0,0],"MET","clinical",false,null,null,1,false,false,0,"metabolic equivalents","UCUM","RelEngRat","Clinical","unit used to measure rate of energy expenditure per power in treadmill and other functional tests","mL/min/kg","ML/MIN/KG","3.5",3.5,false],[false,"homeopathic potency of decimal series (retired)","[hp'_X]","[HP'_X]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,"hpX",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of centesimal series (retired)","[hp'_C]","[HP'_C]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,"hpC",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of millesimal series (retired)","[hp'_M]","[HP'_M]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,"hpM",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of quintamillesimal series (retired)","[hp'_Q]","[HP'_Q]","homeopathic potency (retired)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,"hpQ",1,true,false,0,null,"UCUM",null,null,null,"1",null,null,1,false],[false,"homeopathic potency of decimal hahnemannian series","[hp_X]","[HP_X]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of centesimal hahnemannian series","[hp_C]","[HP_C]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of millesimal hahnemannian series","[hp_M]","[HP_M]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of quintamillesimal hahnemannian series","[hp_Q]","[HP_Q]","homeopathic potency (Hahnemann)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of decimal korsakovian series","[kp_X]","[KP_X]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"X","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of centesimal korsakovian series","[kp_C]","[KP_C]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"C","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of millesimal korsakovian series","[kp_M]","[KP_M]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"M","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"homeopathic potency of quintamillesimal korsakovian series","[kp_Q]","[KP_Q]","homeopathic potency (Korsakov)",1,[0,0,0,0,0,0,0],"Q","clinical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"equivalent","eq","EQ","amount of substance",6.0221367e+23,[0,0,0,0,0,0,0],"eq","chemical",true,null,null,1,false,false,1,"equivalents","UCUM","Sub","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"osmole","osm","OSM","amount of substance (dissolved particles)",6.0221367e+23,[0,0,0,0,0,0,0],"osm","chemical",true,null,null,1,false,false,1,"osmoles; osmols","UCUM","Osmol","Clinical","the number of moles of solute that contribute to the osmotic pressure of a solution","mol","MOL","1",1,false],[false,"pH","[pH]","[PH]","acidity",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"pH","chemical",false,null,"pH",1,true,false,0,"pH scale","UCUM","LogCnc","Clinical","Log concentration of H+","mol/l",null,null,1,false],[false,"gram percent","g%","G%","mass concentration",10000,[-3,0,1,0,0,0,0],"g%","chemical",true,null,null,1,false,false,0,"gram %; gram%; grams per deciliter; g/dL; gm per dL; gram percents","UCUM","MCnc","Clinical","equivalent to unit gram per deciliter (g/dL), a unit often used in medical tests to represent solution concentrations","g/dl","G/DL","1",1,false],[false,"Svedberg unit","[S]","[S]","sedimentation coefficient",1e-13,[0,1,0,0,0,0,0],"S","chemical",false,null,null,1,false,false,0,"Sv; 10^-13 seconds; 100 fs; 100 femtoseconds","UCUM","Time","Clinical","unit of time used in measuring particle's sedimentation rate, usually after centrifugation. ","s","10*-13.S","1",1e-13,false],[false,"high power field (microscope)","[HPF]","[HPF]","view area in microscope",1,[0,0,0,0,0,0,0],"HPF","chemical",false,null,null,1,false,false,0,"HPF","UCUM","Area","Clinical","area visible under the maximum magnification power of the objective in microscopy (usually 400x)\n","1","1","1",1,false],[false,"low power field (microscope)","[LPF]","[LPF]","view area in microscope",1,[0,0,0,0,0,0,0],"LPF","chemical",false,null,null,1,false,false,0,"LPF; fields","UCUM","Area","Clinical","area visible under the low magnification of the objective in microscopy (usually 100 x)\n","1","1","100",100,false],[false,"katal","kat","KAT","catalytic activity",6.0221367e+23,[0,-1,0,0,0,0,0],"kat","chemical",true,null,null,1,false,false,1,"mol/secs; moles per second; mol*sec-1; mol*s-1; mol.s-1; katals; catalytic activity; enzymatic; enzyme units; activities","UCUM","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"enzyme unit","U","U","catalytic activity",10036894500000000,[0,-1,0,0,0,0,0],"U","chemical",true,null,null,1,false,false,1,"micromoles per minute; umol/min; umol per minute; umol min-1; enzymatic activity; enzyme activity","UCUM","CAct","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"international unit - arbitrary","[iU]","[IU]","arbitrary",1,[0,0,0,0,0,0,0],"IU","chemical",true,null,null,1,false,true,0,"international units; IE; F2","UCUM","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","1","1","1",1,false],[false,"international unit - arbitrary","[IU]","[IU]","arbitrary",1,[0,0,0,0,0,0,0],"i.U.","chemical",true,null,null,1,false,true,0,"international units; IE; F2","UCUM","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"arbitary unit","[arb'U]","[ARB'U]","arbitrary",1,[0,0,0,0,0,0,0],"arb. U","chemical",false,null,null,1,false,true,0,"arbitary units; arb units; arbU","UCUM","Arb","Clinical","relative unit of measurement to show the ratio of test measurement to reference measurement","1","1","1",1,false],[false,"United States Pharmacopeia unit","[USP'U]","[USP'U]","arbitrary",1,[0,0,0,0,0,0,0],"U.S.P.","chemical",false,null,null,1,false,true,0,"USP U; USP'U","UCUM","Arb","Clinical","a dose unit to express potency of drugs and vitamins defined by the United States Pharmacopoeia; usually 1 USP = 1 IU","1","1","1",1,false],[false,"GPL unit","[GPL'U]","[GPL'U]","biologic activity of anticardiolipin IgG",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"GPL Units; GPL U; IgG anticardiolipin units; IgG Phospholipid","UCUM","ACnc; AMass","Clinical","Units for an antiphospholipid test","1","1","1",1,false],[false,"MPL unit","[MPL'U]","[MPL'U]","biologic activity of anticardiolipin IgM",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"MPL units; MPL U; MPL'U; IgM anticardiolipin units; IgM Phospholipid Units ","UCUM","ACnc","Clinical","units for antiphospholipid test","1","1","1",1,false],[false,"APL unit","[APL'U]","[APL'U]","biologic activity of anticardiolipin IgA",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"APL units; APL U; IgA anticardiolipin; IgA Phospholipid; biologic activity of","UCUM","AMass; ACnc","Clinical","Units for an anti phospholipid syndrome test","1","1","1",1,false],[false,"Bethesda unit","[beth'U]","[BETH'U]","biologic activity of factor VIII inhibitor",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"BU","UCUM","ACnc","Clinical","measures of blood coagulation inhibitior for many blood factors","1","1","1",1,false],[false,"anti factor Xa unit","[anti'Xa'U]","[ANTI'XA'U]","biologic activity of factor Xa inhibitor (heparin)",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","ACnc","Clinical","[anti'Xa'U] unit is equivalent to and can be converted to IU/mL. ","1","1","1",1,false],[false,"Todd unit","[todd'U]","[TODD'U]","biologic activity antistreptolysin O",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","InvThres; RtoThres","Clinical","the unit for the results of the testing for antistreptolysin O (ASO)","1","1","1",1,false],[false,"Dye unit","[dye'U]","[DYE'U]","biologic activity of amylase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"units","UCUM","CCnc","Obsolete","equivalent to the Somogyi unit, which is an enzyme unit for amylase but better to use U, the standard enzyme unit for measuring catalytic activity","1","1","1",1,false],[false,"Somogyi unit","[smgy'U]","[SMGY'U]","biologic activity of amylase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"Somogyi units; smgy U","UCUM","CAct","Clinical","measures the enzymatic activity of amylase in blood serum - better to use base units mg/mL ","1","1","1",1,false],[false,"Bodansky unit","[bdsk'U]","[BDSK'U]","biologic activity of phosphatase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"","UCUM","ACnc","Obsolete","Enzyme unit specific to alkaline phosphatase - better to use standard enzyme unit of U","1","1","1",1,false],[false,"King-Armstrong unit","[ka'U]","[KA'U]","biologic activity of phosphatase",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"King-Armstrong Units; King units","UCUM","AMass","Obsolete","enzyme units for acid phosphatase - better to use enzyme unit [U]","1","1","1",1,false],[false,"Kunkel unit","[knk'U]","[KNK'U]","arbitrary biologic activity",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,null,"UCUM",null,null,null,"1","1","1",1,false],[false,"Mac Lagan unit","[mclg'U]","[MCLG'U]","arbitrary biologic activity",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"galactose index; galactose tolerance test; thymol turbidity test unit; mclg U; units; indexes","UCUM","ACnc","Obsolete","unit for liver tests - previously used in thymol turbidity tests for liver disease diagnoses, and now is sometimes referred to in the oral galactose tolerance test","1","1","1",1,false],[false,"tuberculin unit","[tb'U]","[TB'U]","biologic activity of tuberculin",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"TU; units","UCUM","Arb","Clinical","amount of tuberculin antigen -usually in reference to a TB skin test ","1","1","1",1,false],[false,"50% cell culture infectious dose","[CCID_50]","[CCID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"CCID50","chemical",false,null,null,1,false,true,0,"CCID50; 50% cell culture infective doses","UCUM","NumThres","Clinical","","1","1","1",1,false],[false,"50% tissue culture infectious dose","[TCID_50]","[TCID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"TCID50","chemical",false,null,null,1,false,true,0,"TCID50; 50% tissue culture infective dose","UCUM","NumThres","Clinical","","1","1","1",1,false],[false,"50% embryo infectious dose","[EID_50]","[EID_50]","biologic activity (infectivity) of an infectious agent preparation",1,[0,0,0,0,0,0,0],"EID50","chemical",false,null,null,1,false,true,0,"EID50; 50% embryo infective doses; EID50 Egg Infective Dosage","UCUM","thresNum","Clinical","","1","1","1",1,false],[false,"plaque forming units","[PFU]","[PFU]","amount of an infectious agent",1,[0,0,0,0,0,0,0],"PFU","chemical",false,null,null,1,false,true,0,"PFU","UCUM","ACnc","Clinical","tests usually report unit as number of PFU per unit volume","1","1","1",1,false],[false,"focus forming units (cells)","[FFU]","[FFU]","amount of an infectious agent",1,[0,0,0,0,0,0,0],"FFU","chemical",false,null,null,1,false,true,0,"FFU","UCUM","EntNum","Clinical","","1","1","1",1,false],[false,"colony forming units","[CFU]","[CFU]","amount of a proliferating organism",1,[0,0,0,0,0,0,0],"CFU","chemical",false,null,null,1,false,true,0,"CFU","UCUM","Num","Clinical","","1","1","1",1,false],[false,"index of reactivity (allergen)","[IR]","[IR]","amount of an allergen callibrated through in-vivo testing using the Stallergenes® method.",1,[0,0,0,0,0,0,0],"IR","chemical",false,null,null,1,false,true,0,"IR; indexes","UCUM","Acnc","Clinical","amount of an allergen callibrated through in-vivo testing using the Stallergenes method. Usually reported in tests as IR/mL","1","1","1",1,false],[false,"bioequivalent allergen unit","[BAU]","[BAU]","amount of an allergen callibrated through in-vivo testing based on the ID50EAL method of (intradermal dilution for 50mm sum of erythema diameters",1,[0,0,0,0,0,0,0],"BAU","chemical",false,null,null,1,false,true,0,"BAU; Bioequivalent Allergy Units; bioequivalent allergen units","UCUM","Arb","Clinical","","1","1","1",1,false],[false,"allergy unit","[AU]","[AU]","procedure defined amount of an allergen using some reference standard",1,[0,0,0,0,0,0,0],"AU","chemical",false,null,null,1,false,true,0,"allergy units; allergen units; AU","UCUM","Arb","Clinical","Most standard test allergy units are reported as [IU] or as %. ","1","1","1",1,false],[false,"allergen unit for Ambrosia artemisiifolia","[Amb'a'1'U]","[AMB'A'1'U]","procedure defined amount of the major allergen of ragweed.",1,[0,0,0,0,0,0,0],"Amb a 1 U","chemical",false,null,null,1,false,true,0,"Amb a 1 unit; Antigen E; AgE U; allergen units","UCUM","Arb","Clinical","Amb a 1 is the major allergen in short ragweed, and can be converted Bioequivalent allergen units (BAU) where 350 Amb a 1 U/mL = 100,000 BAU/mL","1","1","1",1,false],[false,"protein nitrogen unit (allergen testing)","[PNU]","[PNU]","procedure defined amount of a protein substance",1,[0,0,0,0,0,0,0],"PNU","chemical",false,null,null,1,false,true,0,"protein nitrogen units; PNU","UCUM","Mass","Clinical","defined as 0.01 ug of phosphotungstic acid-precipitable protein nitrogen. Being replaced by bioequivalent allergy units (BAU).","1","1","1",1,false],[false,"Limit of flocculation","[Lf]","[LF]","procedure defined amount of an antigen substance",1,[0,0,0,0,0,0,0],"Lf","chemical",false,null,null,1,false,true,0,"Lf doses","UCUM","Arb","Clinical","the antigen content forming 1:1 ratio against 1 unit of antitoxin","1","1","1",1,false],[false,"D-antigen unit (polio)","[D'ag'U]","[D'AG'U]","procedure defined amount of a poliomyelitis d-antigen substance",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"DAgU; units","UCUM","Acnc","Clinical","unit of potency of poliovirus vaccine used for poliomyelitis prevention reported as D antigen units/mL. The unit is poliovirus type-specific.","1","1","1",1,false],[false,"fibrinogen equivalent units","[FEU]","[FEU]","amount of fibrinogen broken down into the measured d-dimers",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"FEU","UCUM","MCnc","Clinical","Note both the FEU and DDU units are used to report D-dimer measurements. 1 DDU = 1/2 FFU","1","1","1",1,false],[false,"ELISA unit","[ELU]","[ELU]","arbitrary ELISA unit",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"Enzyme-Linked Immunosorbent Assay Units; ELU; EL. U","UCUM","ACnc","Clinical","","1","1","1",1,false],[false,"Ehrlich units (urobilinogen)","[EU]","[EU]","Ehrlich unit",1,[0,0,0,0,0,0,0],null,"chemical",false,null,null,1,false,true,0,"EU/dL; mg{urobilinogen}/dL","UCUM","ACnc","Clinical","","1","1","1",1,false],[false,"neper","Np","NEP","level",1,[0,0,0,0,0,0,0],"Np","levels",true,null,"ln",1,true,false,0,"nepers","UCUM","LogRto","Clinical","logarithmic unit for ratios of measurements of physical field and power quantities, such as gain and loss of electronic signals","1",null,null,1,false],[false,"bel","B","B","level",1,[0,0,0,0,0,0,0],"B","levels",true,null,"lg",1,true,false,0,"bels","UCUM","LogRto","Clinical","Logarithm of the ratio of power- or field-type quantities; usually expressed in decibels ","1",null,null,1,false],[false,"bel sound pressure","B[SPL]","B[SPL]","pressure level",0.02,[-1,-2,1,0,0,0,0],"B(SPL)","levels",true,null,"lgTimes2",1,true,false,0,"bel SPL; B SPL; sound pressure bels","UCUM","LogRto","Clinical","used to measure sound level in acoustics","Pa",null,null,0.00002,false],[false,"bel volt","B[V]","B[V]","electric potential level",1000,[2,-2,1,0,0,-1,0],"B(V)","levels",true,null,"lgTimes2",1,true,false,0,"bel V; B V; volts bels","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","V",null,null,1,false],[false,"bel millivolt","B[mV]","B[MV]","electric potential level",1,[2,-2,1,0,0,-1,0],"B(mV)","levels",true,null,"lgTimes2",1,true,false,0,"bel mV; B mV; millivolt bels; 10^-3V bels; 10*-3V ","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","mV",null,null,1,false],[false,"bel microvolt","B[uV]","B[UV]","electric potential level",0.001,[2,-2,1,0,0,-1,0],"B(μV)","levels",true,null,"lgTimes2",1,true,false,0,"bel uV; B uV; microvolts bels; 10^-6V bel; 10*-6V bel","UCUM","LogRto","Clinical","used to express power gain in electrical circuits","uV",null,null,1,false],[false,"bel 10 nanovolt","B[10.nV]","B[10.NV]","electric potential level",0.000010000000000000003,[2,-2,1,0,0,-1,0],"B(10 nV)","levels",true,null,"lgTimes2",1,true,false,0,"bel 10 nV; B 10 nV; 10 nanovolts bels","UCUM","LogRtoElp","Clinical","used to express power gain in electrical circuits","nV",null,null,10,false],[false,"bel watt","B[W]","B[W]","power level",1000,[2,-3,1,0,0,0,0],"B(W)","levels",true,null,"lg",1,true,false,0,"bel W; b W; b Watt; Watts bels","UCUM","LogRto","Clinical","used to express power","W",null,null,1,false],[false,"bel kilowatt","B[kW]","B[KW]","power level",1000000,[2,-3,1,0,0,0,0],"B(kW)","levels",true,null,"lg",1,true,false,0,"bel kW; B kW; kilowatt bel; kW bel; kW B","UCUM","LogRto","Clinical","used to express power","kW",null,null,1,false],[false,"stere","st","STR","volume",1,[3,0,0,0,0,0,0],"st","misc",true,null,null,1,false,false,0,"stère; m3; cubic meter; m^3; meters cubed; metre","UCUM","Vol","Nonclinical","equal to one cubic meter, usually used for measuring firewoord","m3","M3","1",1,false],[false,"Ångström","Ao","AO","length",1.0000000000000002e-10,[1,0,0,0,0,0,0],"Å","misc",false,null,null,1,false,false,0,"Å; Angstroms; Ao; Ångströms","UCUM","Len","Clinical","equal to 10^-10 meters; used to express wave lengths and atom scaled differences ","nm","NM","0.1",0.1,false],[false,"barn","b","BRN","action area",9.999999999999999e-29,[2,0,0,0,0,0,0],"b","misc",false,null,null,1,false,false,0,"barns","UCUM","Area","Clinical","used in high-energy physics to express cross-sectional areas","fm2","FM2","100",100,false],[false,"technical atmosphere","att","ATT","pressure",98066499.99999999,[-1,-2,1,0,0,0,0],"at","misc",false,null,null,1,false,false,0,"at; tech atm; tech atmosphere; kgf/cm2; atms; atmospheres","UCUM","Pres","Obsolete","non-SI unit of pressure equal to one kilogram-force per square centimeter","kgf/cm2","KGF/CM2","1",1,false],[false,"mho","mho","MHO","electric conductance",0.001,[-2,1,-1,0,0,2,0],"mho","misc",true,null,null,1,false,false,0,"siemens; ohm reciprocals; Ω^−1; Ω-1 ","UCUM","","Obsolete","unit of electric conductance (the inverse of electrical resistance) equal to ohm^-1","S","S","1",1,false],[false,"pound per square inch","[psi]","[PSI]","pressure",6894757.293168359,[-1,-2,1,0,0,0,0],"psi","misc",false,null,null,1,false,false,0,"psi; lb/in2; lb per in2","UCUM","Pres","Clinical","","[lbf_av]/[in_i]2","[LBF_AV]/[IN_I]2","1",1,false],[false,"circle - plane angle","circ","CIRC","plane angle",6.283185307179586,[0,0,0,1,0,0,0],"circ","misc",false,null,null,1,false,false,0,"angles; circles","UCUM","Angle","Clinical","","[pi].rad","[PI].RAD","2",2,false],[false,"spere - solid angle","sph","SPH","solid angle",12.566370614359172,[0,0,0,2,0,0,0],"sph","misc",false,null,null,1,false,false,0,"speres","UCUM","Angle","Clinical","equal to the solid angle of an entire sphere = 4πsr (sr = steradian) ","[pi].sr","[PI].SR","4",4,false],[false,"metric carat","[car_m]","[CAR_M]","mass",0.2,[0,0,1,0,0,0,0],"ctm","misc",false,null,null,1,false,false,0,"carats; ct; car m","UCUM","Mass","Nonclinical","unit of mass for gemstones","g","G","2e-1",0.2,false],[false,"carat of gold alloys","[car_Au]","[CAR_AU]","mass fraction",0.041666666666666664,[0,0,0,0,0,0,0],"ctAu","misc",false,null,null,1,false,false,0,"karats; k; kt; car au; carats","UCUM","MFr","Nonclinical","unit of purity for gold alloys","/24","/24","1",1,false],[false,"Smoot","[smoot]","[SMOOT]","length",1.7018000000000002,[1,0,0,0,0,0,0],null,"misc",false,null,null,1,false,false,0,"","UCUM","Len","Nonclinical","prank unit of length from MIT","[in_i]","[IN_I]","67",67,false],[false,"meter per square seconds per square root of hertz","[m/s2/Hz^(1/2)]","[M/S2/HZ^(1/2)]","amplitude spectral density",1,[2,-3,0,0,0,0,0],null,"misc",false,null,"sqrt",1,true,false,0,"m/s2/(Hz^.5); m/s2/(Hz^(1/2)); m per s2 per Hz^1/2","UCUM","","Constant","measures amplitude spectral density, and is equal to the square root of power spectral density\n ","m2/s4/Hz",null,null,1,false],[false,"bit - logarithmic","bit_s","BIT_S","amount of information",1,[0,0,0,0,0,0,0],"bits","infotech",false,null,"ld",1,true,false,0,"bit-s; bit s; bit logarithmic","UCUM","LogA","Nonclinical","defined as the log base 2 of the number of distinct signals; cannot practically be used to express more than 1000 bits\n\nIn information theory, the definition of the amount of self-information and information entropy is often expressed with the binary logarithm (log base 2)","1",null,null,1,false],[false,"bit","bit","BIT","amount of information",1,[0,0,0,0,0,0,0],"bit","infotech",true,null,null,1,false,false,0,"bits","UCUM","","Nonclinical","dimensionless information unit of 1 used in computing and digital communications","1","1","1",1,false],[false,"byte","By","BY","amount of information",8,[0,0,0,0,0,0,0],"B","infotech",true,null,null,1,false,false,0,"bytes","UCUM","","Nonclinical","equal to 8 bits","bit","bit","8",8,false],[false,"baud","Bd","BD","signal transmission rate",1,[0,1,0,0,0,0,0],"Bd","infotech",true,null,"inv",1,false,false,0,"Bd; bauds","UCUM","Freq","Nonclinical","unit to express rate in symbols per second or pulses per second. ","s","/s","1",1,false],[false,"per twelve hour","/(12.h)","/HR","",0.000023148148148148147,[0,-1,0,0,0,0,0],"/h",null,false,null,null,1,false,false,0,"per 12 hours; 12hrs; 12 hrs; /12hrs","LOINC","Rat","Clinical","",null,null,null,null,false],[false,"per arbitrary unit","/[arb'U]","/[ARB'U]","",1,[0,0,0,0,0,0,0],"/arb/ U",null,false,null,null,1,false,true,0,"/arbU","LOINC","InvA ","Clinical","",null,null,null,null,false],[false,"per high power field","/[HPF]","/[HPF]","",1,[0,0,0,0,0,0,0],"/HPF",null,false,null,null,1,false,false,0,"/HPF; per HPF","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per international unit","/[IU]","/[IU]","",1,[0,0,0,0,0,0,0],"/i/U.",null,false,null,null,1,false,true,0,"international units; /IU; per IU","LOINC","InvA","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)",null,null,null,null,false],[false,"per low power field","/[LPF]","/[LPF]","",1,[0,0,0,0,0,0,0],"/LPF",null,false,null,null,1,false,false,0,"/LPF; per LPF","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per 10 billion ","/10*10","/10*10","",1e-10,[0,0,0,0,0,0,0],"/1010<.sup>",null,false,null,null,1,false,false,0,"/10^10; per 10*10","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per trillion ","/10*12","/10*12","",1e-12,[0,0,0,0,0,0,0],"/1012<.sup>",null,false,null,null,1,false,false,0,"/10^12; per 10*12","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per thousand","/10*3","/10*3","",0.001,[0,0,0,0,0,0,0],"/103<.sup>",null,false,null,null,1,false,false,0,"/10^3; per 10*3","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per million","/10*6","/10*6","",0.000001,[0,0,0,0,0,0,0],"/106<.sup>",null,false,null,null,1,false,false,0,"/10^6; per 10*6;","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per billion","/10*9","/10*9","",1e-9,[0,0,0,0,0,0,0],"/109<.sup>",null,false,null,null,1,false,false,0,"/10^9; per 10*9","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per 100","/100","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"per hundred; 10^2; 10*2","LOINC","NFr","Clinical","used for counting entities, e.g. blood cells; usually these kinds of terms have numerators such as moles or milligrams, and counting that amount per the number in the denominator",null,null,null,null,false],[false,"per 100 cells","/100{cells}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 cells; /100cells; per hundred","LOINC","EntMass; EntNum; NFr","Clinical","",null,null,null,null,false],[false,"per 100 neutrophils","/100{neutrophils}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 neutrophils; /100neutrophils; per hundred","LOINC","EntMass; EntNum; NFr","Clinical","",null,null,null,null,false],[false,"per 100 spermatozoa","/100{spermatozoa}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 spermatozoa; /100spermatozoa; per hundred","LOINC","NFr","Clinical","",null,null,null,null,false],[false,"per 100 white blood cells","/100{WBCs}","","",0.01,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"/100 WBCs; /100WBCs; per hundred","LOINC","Ratio; NFr","Clinical","",null,null,null,null,false],[false,"per year","/a","/ANN","",3.168808781402895e-8,[0,-1,0,0,0,0,0],"/a",null,false,null,null,1,false,false,0,"/Years; /yrs; yearly","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per centimeter of water","/cm[H2O]","/CM[H2O]","",0.000010197162129779282,[1,2,-1,0,0,0,0],"/cm HO2<.r>",null,false,null,null,1,false,false,0,"/cmH2O; /cm H2O; centimeters; centimetres","LOINC","InvPress","Clinical","",null,null,null,null,false],[false,"per day","/d","/D","",0.000011574074074074073,[0,-1,0,0,0,0,0],"/d",null,false,null,null,1,false,false,0,"/dy; per day","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per deciliter","/dL","/DL","",10000,[-3,0,0,0,0,0,0],"/dL",null,false,null,null,1,false,false,0,"per dL; /deciliter; decilitre","LOINC","NCnc","Clinical","",null,null,null,null,false],[false,"per gram","/g","/G","",1,[0,0,-1,0,0,0,0],"/g",null,false,null,null,1,false,false,0,"/gm; /gram; per g","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per hour","/h","/HR","",0.0002777777777777778,[0,-1,0,0,0,0,0],"/h",null,false,null,null,1,false,false,0,"/hr; /hour; per hr","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per kilogram","/kg","/KG","",0.001,[0,0,-1,0,0,0,0],"/kg",null,false,null,null,1,false,false,0,"per kg; per kilogram","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per liter","/L","/L","",1000,[-3,0,0,0,0,0,0],"/L",null,false,null,null,1,false,false,0,"/liter; litre","LOINC","NCnc","Clinical","",null,null,null,null,false],[false,"per square meter","/m2","/M2","",1,[-2,0,0,0,0,0,0],"/m2<.sup>",null,false,null,null,1,false,false,0,"/m^2; /m*2; /sq. m; per square meter; meter squared; metre","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"per cubic meter","/m3","/M3","",1,[-3,0,0,0,0,0,0],"/m3<.sup>",null,false,null,null,1,false,false,0,"/m^3; /m*3; /cu. m; per cubic meter; meter cubed; per m3; metre","LOINC","NCncn","Clinical","",null,null,null,null,false],[false,"per milligram","/mg","/MG","",1000,[0,0,-1,0,0,0,0],"/mg",null,false,null,null,1,false,false,0,"/milligram; per mg","LOINC","NCnt","Clinical","",null,null,null,null,false],[false,"per minute","/min","/MIN","",0.016666666666666666,[0,-1,0,0,0,0,0],"/min",null,false,null,null,1,false,false,0,"/minute; per mins; breaths beats per minute","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per milliliter","/mL","/ML","",1000000,[-3,0,0,0,0,0,0],"/mL",null,false,null,null,1,false,false,0,"/milliliter; per mL; millilitre","LOINC","NCncn","Clinical","",null,null,null,null,false],[false,"per millimeter","/mm","/MM","",1000,[-1,0,0,0,0,0,0],"/mm",null,false,null,null,1,false,false,0,"/millimeter; per mm; millimetre","LOINC","InvLen","Clinical","",null,null,null,null,false],[false,"per month","/mo","/MO","",3.802570537683474e-7,[0,-1,0,0,0,0,0],"/mo",null,false,null,null,1,false,false,0,"/month; per mo; monthly; month","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per second","/s","/S","",1,[0,-1,0,0,0,0,0],"/s",null,false,null,null,1,false,false,0,"/second; /sec; per sec; frequency; Hertz; Herz; Hz; becquerels; Bq; s-1; s^-1","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"per enzyme unit","/U","/U","",9.963241120049633e-17,[0,1,0,0,0,0,0],"/U",null,false,null,null,1,false,false,-1,"/enzyme units; per U","LOINC","InvC; NCat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)",null,null,null,null,false],[false,"per microliter","/uL","/UL","",999999999.9999999,[-3,0,0,0,0,0,0],"/μL",null,false,null,null,1,false,false,0,"/microliter; microlitre; /mcl; per uL","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"per week","/wk","/WK","",0.0000016534391534391535,[0,-1,0,0,0,0,0],"/wk",null,false,null,null,1,false,false,0,"/week; per wk; weekly, weeks","LOINC","NRat","Clinical","",null,null,null,null,false],[false,"APL unit per milliliter","[APL'U]/mL","[APL'U]/ML","biologic activity of anticardiolipin IgA",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"APL/mL; APL'U/mL; APL U/mL; APL/milliliter; IgA anticardiolipin units per milliliter; IgA Phospholipid Units; millilitre; biologic activity of","LOINC","ACnc","Clinical","Units for an anti phospholipid syndrome test","1","1","1",1,false],[false,"arbitrary unit per milliliter","[arb'U]/mL","[ARB'U]/ML","arbitrary",1000000,[-3,0,0,0,0,0,0],"(arb. U)/mL","chemical",false,null,null,1,false,true,0,"arb'U/mL; arbU/mL; arb U/mL; arbitrary units per milliliter; millilitre","LOINC","ACnc","Clinical","relative unit of measurement to show the ratio of test measurement to reference measurement","1","1","1",1,false],[false,"colony forming units per liter","[CFU]/L","[CFU]/L","amount of a proliferating organism",1000,[-3,0,0,0,0,0,0],"CFU/L","chemical",false,null,null,1,false,true,0,"CFU per Liter; CFU/L","LOINC","NCnc","Clinical","","1","1","1",1,false],[false,"colony forming units per milliliter","[CFU]/mL","[CFU]/ML","amount of a proliferating organism",1000000,[-3,0,0,0,0,0,0],"CFU/mL","chemical",false,null,null,1,false,true,0,"CFU per mL; CFU/mL","LOINC","NCnc","Clinical","","1","1","1",1,false],[false,"foot per foot - US","[ft_us]/[ft_us]","[FT_US]/[FT_US]","length",1,[0,0,0,0,0,0,0],"(ftus)/(ftus)","us-lengths",false,null,null,1,false,false,0,"ft/ft; ft per ft; feet per feet; visual acuity","","LenRto","Clinical","distance ratio to measure 20:20 vision","m/3937","M/3937","1200",1200,false],[false,"GPL unit per milliliter","[GPL'U]/mL","[GPL'U]/ML","biologic activity of anticardiolipin IgG",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"GPL U/mL; GPL'U/mL; GPL/mL; GPL U per mL; IgG Phospholipid Units per milliliters; IgG anticardiolipin units; millilitres ","LOINC","ACnc; AMass","Clinical","Units for an antiphospholipid test","1","1","1",1,false],[false,"international unit per 2 hour","[IU]/(2.h)","[IU]/HR","arbitrary",0.0001388888888888889,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/2hrs; IU/2 hours; IU per 2 hrs; international units per 2 hours","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per 24 hour","[IU]/(24.h)","[IU]/HR","arbitrary",0.000011574074074074073,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/24hr; IU/24 hours; IU per 24 hrs; international units per 24 hours","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per day","[IU]/d","[IU]/D","arbitrary",0.000011574074074074073,[0,-1,0,0,0,0,0],"(i.U.)/d","chemical",true,null,null,1,false,true,0,"IU/dy; IU/days; IU per dys; international units per day","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per deciliter","[IU]/dL","[IU]/DL","arbitrary",10000,[-3,0,0,0,0,0,0],"(i.U.)/dL","chemical",true,null,null,1,false,true,0,"IU/dL; IU per dL; international units per deciliters; decilitres","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per gram","[IU]/g","[IU]/G","arbitrary",1,[0,0,-1,0,0,0,0],"(i.U.)/g","chemical",true,null,null,1,false,true,0,"IU/gm; IU/gram; IU per gm; IU per g; international units per gram","LOINC","ACnt","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per hour","[IU]/h","[IU]/HR","arbitrary",0.0002777777777777778,[0,-1,0,0,0,0,0],"(i.U.)/h","chemical",true,null,null,1,false,true,0,"IU/hrs; IU per hours; international units per hour","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per kilogram","[IU]/kg","[IU]/KG","arbitrary",0.001,[0,0,-1,0,0,0,0],"(i.U.)/kg","chemical",true,null,null,1,false,true,0,"IU/kg; IU/kilogram; IU per kg; units","LOINC","ACnt","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per kilogram per day","[IU]/kg/d","([IU]/KG)/D","arbitrary",1.1574074074074074e-8,[0,-1,-1,0,0,0,0],"((i.U.)/kg)/d","chemical",true,null,null,1,false,true,0,"IU/kg/dy; IU/kg/day; IU/kilogram/day; IU per kg per day; units","LOINC","ACntRat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per liter","[IU]/L","[IU]/L","arbitrary",1000,[-3,0,0,0,0,0,0],"(i.U.)/L","chemical",true,null,null,1,false,true,0,"IU/L; IU/liter; IU per liter; units; litre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per minute","[IU]/min","[IU]/MIN","arbitrary",0.016666666666666666,[0,-1,0,0,0,0,0],"(i.U.)/min","chemical",true,null,null,1,false,true,0,"IU/min; IU/minute; IU per minute; international units","LOINC","ARat","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"international unit per milliliter","[IU]/mL","[IU]/ML","arbitrary",1000000,[-3,0,0,0,0,0,0],"(i.U.)/mL","chemical",true,null,null,1,false,true,0,"IU/mL; IU per mL; international units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"MPL unit per milliliter","[MPL'U]/mL","[MPL'U]/ML","biologic activity of anticardiolipin IgM",1000000,[-3,0,0,0,0,0,0],"/mL","chemical",false,null,null,1,false,true,0,"MPL/mL; MPL U/mL; MPL'U/mL; IgM anticardiolipin units; IgM Phospholipid Units; millilitre ","LOINC","ACnc","Clinical","units for antiphospholipid test\n","1","1","1",1,false],[false,"number per high power field","{#}/[HPF]","/[HPF]","",1,[0,0,0,0,0,0,0],"/HPF",null,false,null,null,1,false,false,0,"#/HPF; # per HPF; number/HPF; numbers per high power field","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"number per low power field","{#}/[LPF]","/[LPF]","",1,[0,0,0,0,0,0,0],"/LPF",null,false,null,null,1,false,false,0,"#/LPF; # per LPF; number/LPF; numbers per low power field","LOINC","Naric","Clinical","",null,null,null,null,false],[false,"IgA antiphosphatidylserine unit ","{APS'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"APS Unit; Phosphatidylserine Antibody IgA Units","LOINC","ACnc","Clinical","unit for antiphospholipid test",null,null,null,null,false],[false,"EIA index","{EIA_index}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"enzyme immunoassay index","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"kaolin clotting time","{KCT'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"KCT","LOINC","Time","Clinical","sensitive test to detect lupus anticoagulants; measured in seconds",null,null,null,null,false],[false,"IgM antiphosphatidylserine unit","{MPS'U}","","",1,[0,0,0,0,0,0,0],null,null,false,null,null,1,false,false,0,"Phosphatidylserine Antibody IgM Measurement ","LOINC","ACnc","Clinical","",null,null,null,null,false],[false,"trillion per liter","10*12/L","(10*12)/L","number",1000000000000000,[-3,0,0,0,0,0,0],"(1012)/L","dimless",false,null,null,1,false,false,0,"10^12/L; 10*12 per Liter; trillion per liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^3 (used for cell count)","10*3","10*3","number",1000,[0,0,0,0,0,0,0],"103","dimless",false,null,null,1,false,false,0,"10^3; thousand","LOINC","Num","Clinical","usually used for counting entities (e.g. blood cells) per volume","1","1","10",10,false],[false,"thousand per liter","10*3/L","(10*3)/L","number",1000000,[-3,0,0,0,0,0,0],"(103)/L","dimless",false,null,null,1,false,false,0,"10^3/L; 10*3 per liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"thousand per milliliter","10*3/mL","(10*3)/ML","number",1000000000,[-3,0,0,0,0,0,0],"(103)/mL","dimless",false,null,null,1,false,false,0,"10^3/mL; 10*3 per mL; thousand per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"thousand per microliter","10*3/uL","(10*3)/UL","number",999999999999.9999,[-3,0,0,0,0,0,0],"(103)/μL","dimless",false,null,null,1,false,false,0,"10^3/uL; 10*3 per uL; thousand per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10 thousand per microliter","10*4/uL","(10*4)/UL","number",10000000000000,[-3,0,0,0,0,0,0],"(104)/μL","dimless",false,null,null,1,false,false,0,"10^4/uL; 10*4 per uL; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^5 ","10*5","10*5","number",100000,[0,0,0,0,0,0,0],"105","dimless",false,null,null,1,false,false,0,"one hundred thousand","LOINC","Num","Clinical","","1","1","10",10,false],[false,"10^6","10*6","10*6","number",1000000,[0,0,0,0,0,0,0],"106","dimless",false,null,null,1,false,false,0,"","LOINC","Num","Clinical","","1","1","10",10,false],[false,"million colony forming unit per liter","10*6.[CFU]/L","((10*6).[CFU])/L","number",1000000000,[-3,0,0,0,0,0,0],"((106).CFU)/L","dimless",false,null,null,1,false,true,0,"10*6 CFU/L; 10^6 CFU/L; 10^6CFU; 10^6 CFU per liter; million colony forming units; litre","LOINC","ACnc","Clinical","","1","1","10",10,false],[false,"million international unit","10*6.[IU]","(10*6).[IU]","number",1000000,[0,0,0,0,0,0,0],"(106).(i.U.)","dimless",false,null,null,1,false,true,0,"10*6 IU; 10^6 IU; international units","LOINC","arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","1","1","10",10,false],[false,"million per 24 hour","10*6/(24.h)","(10*6)/HR","number",11.574074074074074,[0,-1,0,0,0,0,0],"(106)/h","dimless",false,null,null,1,false,false,0,"10*6/24hrs; 10^6/24 hrs; 10*6 per 24 hrs; 10^6 per 24 hours","LOINC","NRat","Clinical","","1","1","10",10,false],[false,"million per kilogram","10*6/kg","(10*6)/KG","number",1000,[0,0,-1,0,0,0,0],"(106)/kg","dimless",false,null,null,1,false,false,0,"10^6/kg; 10*6 per kg; 10*6 per kilogram; millions","LOINC","NCnt","Clinical","","1","1","10",10,false],[false,"million per liter","10*6/L","(10*6)/L","number",1000000000,[-3,0,0,0,0,0,0],"(106)/L","dimless",false,null,null,1,false,false,0,"10^6/L; 10*6 per Liter; 10^6 per Liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"million per milliliter","10*6/mL","(10*6)/ML","number",1000000000000,[-3,0,0,0,0,0,0],"(106)/mL","dimless",false,null,null,1,false,false,0,"10^6/mL; 10*6 per mL; 10*6 per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"million per microliter","10*6/uL","(10*6)/UL","number",1000000000000000,[-3,0,0,0,0,0,0],"(106)/μL","dimless",false,null,null,1,false,false,0,"10^6/uL; 10^6 per uL; 10^6/mcl; 10^6 per mcl; 10^6 per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10^8","10*8","10*8","number",100000000,[0,0,0,0,0,0,0],"108","dimless",false,null,null,1,false,false,0,"100 million; one hundred million; 10^8","LOINC","Num","Clinical","","1","1","10",10,false],[false,"billion per liter","10*9/L","(10*9)/L","number",1000000000000,[-3,0,0,0,0,0,0],"(109)/L","dimless",false,null,null,1,false,false,0,"10^9/L; 10*9 per Liter; litre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"billion per milliliter","10*9/mL","(10*9)/ML","number",1000000000000000,[-3,0,0,0,0,0,0],"(109)/mL","dimless",false,null,null,1,false,false,0,"10^9/mL; 10*9 per mL; 10^9 per mL; 10*9 per milliliter; millilitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"billion per microliter","10*9/uL","(10*9)/UL","number",1000000000000000000,[-3,0,0,0,0,0,0],"(109)/μL","dimless",false,null,null,1,false,false,0,"10^9/uL; 10^9 per uL; 10^9/mcl; 10^9 per mcl; 10*9 per uL; 10*9 per mcl; 10*9/mcl; 10^9 per microliter; microlitre","LOINC","NCncn","Clinical","","1","1","10",10,false],[false,"10 liter per minute per square meter","10.L/(min.m2)","L/(MIN.M2)","",0.00016666666666666666,[1,-1,0,0,0,0,0],"L/(min.(m2))",null,false,null,null,1,false,false,0,"10 liters per minutes per square meter; 10 L per min per m2; m^2; 10 L/(min*m2); 10L/(min*m^2); litres; sq. meter; metre; meters squared","LOINC","ArVRat","Clinical","",null,null,null,null,false],[false,"10 liter per minute","10.L/min","L/MIN","",0.00016666666666666666,[3,-1,0,0,0,0,0],"L/min",null,false,null,null,1,false,false,0,"10 liters per minute; 10 L per min; 10L; 10 L/min; litre","LOINC","VRat","Clinical","",null,null,null,null,false],[false,"10 micronewton second per centimeter to the fifth power per square meter","10.uN.s/(cm5.m2)","(UN.S)/(CM5.M2)","",100000000,[-6,-1,1,0,0,0,0],"(μN.s)/(cm5).(m2)",null,false,null,null,1,false,false,0,"dyne seconds per centimeter5 and square meter; dyn.s/(cm5.m2); dyn.s/cm5/m2; cm^5; m^2","LOINC","","Clinical","unit to measure systemic vascular resistance per body surface area",null,null,null,null,false],[false,"24 hour","24.h","HR","",86400,[0,1,0,0,0,0,0],"h",null,false,null,null,1,false,false,0,"24hrs; 24 hrs; 24 hours; days; dy","LOINC","Time","Clinical","",null,null,null,null,false],[false,"ampere per meter","A/m","A/M","electric current",1,[-1,-1,0,0,0,1,0],"A/m","si",true,null,null,1,false,false,0,"A/m; amp/meter; magnetic field strength; H; B; amperes per meter; metre","LOINC","","Clinical","unit of magnetic field strength","C/s","C/S","1",1,false],[false,"centigram","cg","CG","mass",0.01,[0,0,1,0,0,0,0],"cg",null,false,"M",null,1,false,false,0,"centigrams; cg; cgm","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"centiliter","cL","CL","volume",0.00001,[3,0,0,0,0,0,0],"cL","iso1000",true,null,null,1,false,false,0,"centiliters; centilitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"centimeter","cm","CM","length",0.01,[1,0,0,0,0,0,0],"cm",null,false,"L",null,1,false,false,0,"centimeters; centimetres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"centimeter of water","cm[H2O]","CM[H2O]","pressure",98066.5,[-1,-2,1,0,0,0,0],"cm HO2","clinical",true,null,null,1,false,false,0,"cm H2O; cmH2O; centimetres; pressure","LOINC","Pres","Clinical","unit of pressure mostly applies to blood pressure","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of water per liter per second","cm[H2O]/L/s","(CM[H2O]/L)/S","pressure",98066500,[-4,-3,1,0,0,0,0],"((cm HO2)/L)/s","clinical",true,null,null,1,false,false,0,"cm[H2O]/(L/s); cm[H2O].s/L; cm H2O/L/sec; cmH2O/L/sec; cmH2O/Liter; cmH2O per L per secs; centimeters of water per liters per second; centimetres; litres; cm[H2O]/(L/s)","LOINC","PresRat","Clinical","unit used to measure mean pulmonary resistance","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of water per second per meter","cm[H2O]/s/m","(CM[H2O]/S)/M","pressure",98066.5,[-2,-3,1,0,0,0,0],"((cm HO2)/s)/m","clinical",true,null,null,1,false,false,0,"cm[H2O]/(s.m); cm H2O/s/m; cmH2O; cmH2O/sec/m; cmH2O per secs per meters; centimeters of water per seconds per meter; centimetres; metre","LOINC","PresRat","Clinical","unit used to measure pulmonary pressure time product","kPa","KPAL","980665e-5",9.80665,false],[false,"centimeter of mercury","cm[Hg]","CM[HG]","pressure",1333220,[-1,-2,1,0,0,0,0],"cm Hg","clinical",true,null,null,1,false,false,0,"centimeters of mercury; centimetres; cmHg; cm Hg","LOINC","Pres","Clinical","unit of pressure where 1 cmHg = 10 torr","kPa","KPAL","133.3220",133.322,false],[false,"square centimeter","cm2","CM2","length",0.0001,[2,0,0,0,0,0,0],"cm2",null,false,"L",null,1,false,false,0,"cm^2; sq cm; centimeters squared; square centimeters; centimetre; area","LOINC","Area","Clinical","",null,null,null,null,false],[false,"square centimeter per second","cm2/s","CM2/S","length",0.0001,[2,-1,0,0,0,0,0],"(cm2)/s",null,false,"L",null,1,false,false,0,"cm^2/sec; square centimeters per second; sq cm per sec; cm2; centimeters squared; centimetres","LOINC","AreaRat","Clinical","",null,null,null,null,false],[false,"centipoise","cP","CP","dynamic viscosity",1,[-1,-1,1,0,0,0,0],"cP","cgs",true,null,null,1,false,false,0,"cps; centiposes","LOINC","Visc","Clinical","unit of dynamic viscosity in the CGS system with base units: 10^−3 Pa.s = 1 mPa·.s (1 millipascal second)","dyn.s/cm2","DYN.S/CM2","1",1,false],[false,"centistoke","cSt","CST","kinematic viscosity",0.0000010000000000000002,[2,-1,0,0,0,0,0],"cSt","cgs",true,null,null,1,false,false,0,"centistokes","LOINC","Visc","Clinical","unit for kinematic viscosity with base units of mm^2/s (square millimeter per second)","cm2/s","CM2/S","1",1,false],[false,"dekaliter per minute","daL/min","DAL/MIN","volume",0.00016666666666666666,[3,-1,0,0,0,0,0],"daL/min","iso1000",true,null,null,1,false,false,0,"dekalitres; dekaliters per minute; per min","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"dekaliter per minute per square meter","daL/min/m2","(DAL/MIN)/M2","volume",0.00016666666666666666,[1,-1,0,0,0,0,0],"(daL/min)/(m2)","iso1000",true,null,null,1,false,false,0,"daL/min/m^2; daL/minute/m2; sq. meter; dekaliters per minutes per square meter; meter squared; dekalitres; metre","LOINC","ArVRat","Clinical","The area usually is the body surface area used to normalize cardiovascular measures for patient's size","l",null,"1",1,false],[false,"decibel","dB","DB","level",1,[0,0,0,0,0,0,0],"dB","levels",true,null,"lg",0.1,true,false,0,"decibels","LOINC","LogRto","Clinical","unit most commonly used in acoustics as unit of sound pressure level. (also see B[SPL] or bel sound pressure level). ","1",null,null,1,false],[false,"degree per second","deg/s","DEG/S","plane angle",0.017453292519943295,[0,-1,0,1,0,0,0],"°/s","iso1000",false,null,null,1,false,false,0,"deg/sec; deg per sec; °/sec; twist rate; angular speed; rotational speed","LOINC","ARat","Clinical","unit of angular (rotational) speed used to express turning rate","[pi].rad/360","[PI].RAD/360","2",2,false],[false,"decigram","dg","DG","mass",0.1,[0,0,1,0,0,0,0],"dg",null,false,"M",null,1,false,false,0,"decigrams; dgm; 0.1 grams; 1/10 gm","LOINC","Mass","Clinical","equal to 1/10 gram",null,null,null,null,false],[false,"deciliter","dL","DL","volume",0.0001,[3,0,0,0,0,0,0],"dL","iso1000",true,null,null,1,false,false,0,"deciliters; decilitres; 0.1 liters; 1/10 L","LOINC","Vol","Clinical","equal to 1/10 liter","l",null,"1",1,false],[false,"decimeter","dm","DM","length",0.1,[1,0,0,0,0,0,0],"dm",null,false,"L",null,1,false,false,0,"decimeters; decimetres; 0.1 meters; 1/10 m; 10 cm; centimeters","LOINC","Len","Clinical","equal to 1/10 meter or 10 centimeters",null,null,null,null,false],[false,"square decimeter per square second","dm2/s2","DM2/S2","length",0.010000000000000002,[2,-2,0,0,0,0,0],"(dm2)/(s2)",null,false,"L",null,1,false,false,0,"dm2 per s2; dm^2/s^2; decimeters squared per second squared; sq dm; sq sec","LOINC","EngMass (massic energy)","Clinical","units for energy per unit mass or Joules per kilogram (J/kg = kg.m2/s2/kg = m2/s2) ",null,null,null,null,false],[false,"dyne second per centimeter per square meter","dyn.s/(cm.m2)","(DYN.S)/(CM.M2)","force",1,[-2,-1,1,0,0,0,0],"(dyn.s)/(cm.(m2))","cgs",true,null,null,1,false,false,0,"(dyn*s)/(cm*m2); (dyn*s)/(cm*m^2); dyn s per cm per m2; m^2; dyne seconds per centimeters per square meter; centimetres; sq. meter; squared","LOINC","","Clinical","","g.cm/s2","G.CM/S2","1",1,false],[false,"dyne second per centimeter","dyn.s/cm","(DYN.S)/CM","force",1,[0,-1,1,0,0,0,0],"(dyn.s)/cm","cgs",true,null,null,1,false,false,0,"(dyn*s)/cm; dyn sec per cm; seconds; centimetre; dyne seconds","LOINC","","Clinical","","g.cm/s2","G.CM/S2","1",1,false],[false,"equivalent per liter","eq/L","EQ/L","amount of substance",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"eq/L","chemical",true,null,null,1,false,false,1,"eq/liter; eq/litre; eqs; equivalents per liter; litre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per milliliter","eq/mL","EQ/ML","amount of substance",6.0221367e+29,[-3,0,0,0,0,0,0],"eq/mL","chemical",true,null,null,1,false,false,1,"equivalent/milliliter; equivalents per milliliter; eq per mL; millilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per millimole","eq/mmol","EQ/MMOL","amount of substance",1000,[0,0,0,0,0,0,0],"eq/mmol","chemical",true,null,null,1,false,false,0,"equivalent/millimole; equivalents per millimole; eq per mmol","LOINC","SRto","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"equivalent per micromole","eq/umol","EQ/UMOL","amount of substance",1000000,[0,0,0,0,0,0,0],"eq/μmol","chemical",true,null,null,1,false,false,0,"equivalent/micromole; equivalents per micromole; eq per umol","LOINC","SRto","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"femtogram","fg","FG","mass",1e-15,[0,0,1,0,0,0,0],"fg",null,false,"M",null,1,false,false,0,"fg; fgm; femtograms; weight","LOINC","Mass","Clinical","equal to 10^-15 grams",null,null,null,null,false],[false,"femtoliter","fL","FL","volume",1e-18,[3,0,0,0,0,0,0],"fL","iso1000",true,null,null,1,false,false,0,"femtolitres; femtoliters","LOINC","Vol; EntVol","Clinical","equal to 10^-15 liters","l",null,"1",1,false],[false,"femtometer","fm","FM","length",1e-15,[1,0,0,0,0,0,0],"fm",null,false,"L",null,1,false,false,0,"femtometres; femtometers","LOINC","Len","Clinical","equal to 10^-15 meters",null,null,null,null,false],[false,"femtomole","fmol","FMOL","amount of substance",602213670,[0,0,0,0,0,0,0],"fmol","si",true,null,null,1,false,false,1,"femtomoles","LOINC","EntSub","Clinical","equal to 10^-15 moles","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per gram","fmol/g","FMOL/G","amount of substance",602213670,[0,0,-1,0,0,0,0],"fmol/g","si",true,null,null,1,false,false,1,"femtomoles; fmol/gm; fmol per gm","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per liter","fmol/L","FMOL/L","amount of substance",602213670000,[-3,0,0,0,0,0,0],"fmol/L","si",true,null,null,1,false,false,1,"femtomoles; fmol per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per milligram","fmol/mg","FMOL/MG","amount of substance",602213670000,[0,0,-1,0,0,0,0],"fmol/mg","si",true,null,null,1,false,false,1,"fmol per mg; femtomoles","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"femtomole per milliliter","fmol/mL","FMOL/ML","amount of substance",602213670000000,[-3,0,0,0,0,0,0],"fmol/mL","si",true,null,null,1,false,false,1,"femtomoles; millilitre; fmol per mL; fmol per milliliter","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"gram meter","g.m","G.M","mass",1,[1,0,1,0,0,0,0],"g.m",null,false,"M",null,1,false,false,0,"g*m; gxm; meters; metres","LOINC","Enrg","Clinical","Unit for measuring stroke work (heart work)",null,null,null,null,false],[false,"gram per 100 gram","g/(100.g)","G/G","mass",0.01,[0,0,0,0,0,0,0],"g/g",null,false,"M",null,1,false,false,0,"g/100 gm; 100gm; grams per 100 grams; gm per 100 gm","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"gram per 12 hour","g/(12.h)","G/HR","mass",0.000023148148148148147,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/12hrs; 12 hrs; gm per 12 hrs; 12hrs; grams per 12 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 24 hour","g/(24.h)","G/HR","mass",0.000011574074074074073,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/24hrs; gm/24 hrs; gm per 24 hrs; 24hrs; grams per 24 hours; gm/dy; gm per dy; grams per day","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 3 days","g/(3.d)","G/D","mass",0.000003858024691358025,[0,-1,1,0,0,0,0],"g/d",null,false,"M",null,1,false,false,0,"gm/3dy; gm/3 dy; gm per 3 days; grams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 4 hour","g/(4.h)","G/HR","mass",0.00006944444444444444,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/4hrs; gm/4 hrs; gm per 4 hrs; 4hrs; grams per 4 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 48 hour","g/(48.h)","G/HR","mass",0.000005787037037037037,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/48hrs; gm/48 hrs; gm per 48 hrs; 48hrs; grams per 48 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 5 hour","g/(5.h)","G/HR","mass",0.00005555555555555556,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/5hrs; gm/5 hrs; gm per 5 hrs; 5hrs; grams per 5 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 6 hour","g/(6.h)","G/HR","mass",0.000046296296296296294,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/6hrs; gm/6 hrs; gm per 6 hrs; 6hrs; grams per 6 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per 72 hour","g/(72.h)","G/HR","mass",0.000003858024691358025,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/72hrs; gm/72 hrs; gm per 72 hrs; 72hrs; grams per 72 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per cubic centimeter","g/cm3","G/CM3","mass",999999.9999999999,[-3,0,1,0,0,0,0],"g/(cm3)",null,false,"M",null,1,false,false,0,"g/cm^3; gm per cm3; g per cm^3; grams per centimeter cubed; cu. cm; centimetre; g/mL; gram per milliliter; millilitre","LOINC","MCnc","Clinical","g/cm3 = g/mL",null,null,null,null,false],[false,"gram per day","g/d","G/D","mass",0.000011574074074074073,[0,-1,1,0,0,0,0],"g/d",null,false,"M",null,1,false,false,0,"gm/dy; gm per dy; grams per day; gm/24hrs; gm/24 hrs; gm per 24 hrs; 24hrs; grams per 24 hours; serving","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per deciliter","g/dL","G/DL","mass",10000,[-3,0,1,0,0,0,0],"g/dL",null,false,"M",null,1,false,false,0,"gm/dL; gm per dL; grams per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per gram","g/g","G/G","mass",1,[0,0,0,0,0,0,0],"g/g",null,false,"M",null,1,false,false,0,"gm; grams","LOINC","MRto ","Clinical","",null,null,null,null,false],[false,"gram per hour","g/h","G/HR","mass",0.0002777777777777778,[0,-1,1,0,0,0,0],"g/h",null,false,"M",null,1,false,false,0,"gm/hr; gm per hr; grams; intake; output","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per hour per square meter","g/h/m2","(G/HR)/M2","mass",0.0002777777777777778,[-2,-1,1,0,0,0,0],"(g/h)/(m2)",null,false,"M",null,1,false,false,0,"gm/hr/m2; gm/h/m2; /m^2; sq. m; g per hr per m2; grams per hours per square meter; meter squared; metre","LOINC","ArMRat","Clinical","",null,null,null,null,false],[false,"gram per kilogram","g/kg ","G/KG","mass",0.001,[0,0,0,0,0,0,0],"g/kg",null,false,"M",null,1,false,false,0,"g per kg; gram per kilograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"gram per kilogram per 8 hour ","g/kg/(8.h)","(G/KG)/HR","mass",3.472222222222222e-8,[0,-1,0,0,0,0,0],"(g/kg)/h",null,false,"M",null,1,false,false,0,"g/(8.kg.h); gm/kg/8hrs; 8 hrs; g per kg per 8 hrs; 8hrs; grams per kilograms per 8 hours; shift","LOINC","MCntRat; RelMRat","Clinical","unit often used to describe mass in grams of protein consumed in a 8 hours, divided by the subject's body weight in kilograms. Also used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per day","g/kg/d","(G/KG)/D","mass",1.1574074074074074e-8,[0,-1,0,0,0,0,0],"(g/kg)/d",null,false,"M",null,1,false,false,0,"g/(kg.d); gm/kg/dy; gm per kg per dy; grams per kilograms per day","LOINC","RelMRat","Clinical","unit often used to describe mass in grams of protein consumed in a day, divided by the subject's body weight in kilograms. Also used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per hour","g/kg/h","(G/KG)/HR","mass",2.7777777777777776e-7,[0,-1,0,0,0,0,0],"(g/kg)/h",null,false,"M",null,1,false,false,0,"g/(kg.h); g/kg/hr; g per kg per hrs; grams per kilograms per hour","LOINC","MCntRat; RelMRat","Clinical","unit used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per kilogram per minute","g/kg/min","(G/KG)/MIN","mass",0.000016666666666666667,[0,-1,0,0,0,0,0],"(g/kg)/min",null,false,"M",null,1,false,false,0,"g/(kg.min); g/kg/min; g per kg per min; grams per kilograms per minute","LOINC","MCntRat; RelMRat","Clinical","unit used to measure mass dose rate per body mass",null,null,null,null,false],[false,"gram per liter","g/L","G/L","mass",1000,[-3,0,1,0,0,0,0],"g/L",null,false,"M",null,1,false,false,0,"gm per liter; g/liter; grams per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per square meter","g/m2","G/M2","mass",1,[-2,0,1,0,0,0,0],"g/(m2)",null,false,"M",null,1,false,false,0,"g/m^2; gram/square meter; g/sq m; g per m2; g per m^2; grams per square meter; meters squared; metre","LOINC","ArMass","Clinical","Tests measure myocardial mass (heart ventricle system) per body surface area; unit used to measure mass dose per body surface area",null,null,null,null,false],[false,"gram per milligram","g/mg","G/MG","mass",1000,[0,0,0,0,0,0,0],"g/mg",null,false,"M",null,1,false,false,0,"g per mg; grams per milligram","LOINC","MCnt; MRto","Clinical","",null,null,null,null,false],[false,"gram per minute","g/min","G/MIN","mass",0.016666666666666666,[0,-1,1,0,0,0,0],"g/min",null,false,"M",null,1,false,false,0,"g per min; grams per minute; gram/minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"gram per milliliter","g/mL","G/ML","mass",1000000,[-3,0,1,0,0,0,0],"g/mL",null,false,"M",null,1,false,false,0,"g per mL; grams per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"gram per millimole","g/mmol","G/MMOL","mass",1.6605401866749388e-21,[0,0,1,0,0,0,0],"g/mmol",null,false,"M",null,1,false,false,-1,"grams per millimole; g per mmol","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"joule per liter","J/L","J/L","energy",1000000,[-1,-2,1,0,0,0,0],"J/L","si",true,null,null,1,false,false,0,"joules per liter; litre; J per L","LOINC","EngCnc","Clinical","","N.m","N.M","1",1,false],[false,"degree Kelvin per Watt","K/W","K/W","temperature",0.001,[-2,3,-1,0,1,0,0],"K/W",null,false,"C",null,1,false,false,0,"degree Kelvin/Watt; K per W; thermal ohm; thermal resistance; degrees","LOINC","TempEngRat","Clinical","unit for absolute thermal resistance equal to the reciprocal of thermal conductance. Unit used for tests to measure work of breathing",null,null,null,null,false],[false,"kilo international unit per liter","k[IU]/L","K[IU]/L","arbitrary",1000000,[-3,0,0,0,0,0,0],"(ki.U.)/L","chemical",true,null,null,1,false,true,0,"kIU/L; kIU per L; kIU per liter; kilo international units; litre; allergens; allergy units","LOINC","ACnc","Clinical","IgE has an WHO reference standard so IgE allergen testing can be reported as k[IU]/L","[iU]","[IU]","1",1,false],[false,"kilo international unit per milliliter","k[IU]/mL","K[IU]/ML","arbitrary",1000000000,[-3,0,0,0,0,0,0],"(ki.U.)/mL","chemical",true,null,null,1,false,true,0,"kIU/mL; kIU per mL; kIU per milliliter; kilo international units; millilitre; allergens; allergy units","LOINC","ACnc","Clinical","IgE has an WHO reference standard so IgE allergen testing can be reported as k[IU]/mL","[iU]","[IU]","1",1,false],[false,"katal per kilogram","kat/kg","KAT/KG","catalytic activity",602213670000000000000,[0,-1,-1,0,0,0,0],"kat/kg","chemical",true,null,null,1,false,false,1,"kat per kg; katals per kilogram; mol/s/kg; moles per seconds per kilogram","LOINC","CCnt","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"katal per liter","kat/L","KAT/L","catalytic activity",6.0221366999999994e+26,[-3,-1,0,0,0,0,0],"kat/L","chemical",true,null,null,1,false,false,1,"kat per L; katals per liter; litre; mol/s/L; moles per seconds per liter","LOINC","CCnc","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"kilocalorie","kcal","KCAL","energy",4184000,[2,-2,1,0,0,0,0],"kcal","heat",true,null,null,1,false,false,0,"kilogram calories; large calories; food calories; kcals","LOINC","EngRat","Clinical","It is equal to 1000 calories (equal to 4.184 kJ). But in practical usage, kcal refers to food calories which excludes caloric content in fiber and other constitutes that is not digestible by humans. Also see nutrition label Calories ([Cal])","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per 24 hour","kcal/(24.h)","KCAL/HR","energy",48.425925925925924,[2,-3,1,0,0,0,0],"kcal/h","heat",true,null,null,1,false,false,0,"kcal/24hrs; kcal/24 hrs; kcal per 24hrs; kilocalories per 24 hours; kilojoules; kJ/24hr; kJ/(24.h); kJ/dy; kilojoules per days; intake; calories burned; metabolic rate; food calories","","EngRat","Clinical","","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per ounce","kcal/[oz_av]","KCAL/[OZ_AV]","energy",147586.25679704445,[2,-2,0,0,0,0,0],"kcal/oz","heat",true,null,null,1,false,false,0,"kcal/oz; kcal per ozs; large calories per ounces; food calories; servings; international","LOINC","EngCnt","Clinical","used in nutrition to represent calorie of food","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per day","kcal/d","KCAL/D","energy",48.425925925925924,[2,-3,1,0,0,0,0],"kcal/d","heat",true,null,null,1,false,false,0,"kcal/dy; kcal per day; kilocalories per days; kilojoules; kJ/dy; kilojoules per days; intake; calories burned; metabolic rate; food calories","LOINC","EngRat","Clinical","unit in nutrition for food intake (measured in calories) in a day","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per hour","kcal/h","KCAL/HR","energy",1162.2222222222222,[2,-3,1,0,0,0,0],"kcal/h","heat",true,null,null,1,false,false,0,"kcal/hrs; kcals per hr; intake; kilocalories per hours; kilojoules","LOINC","EngRat","Clinical","used in nutrition to represent caloric requirement or consumption","cal_th","CAL_TH","1",1,false],[false,"kilocalorie per kilogram per 24 hour","kcal/kg/(24.h)","(KCAL/KG)/HR","energy",0.04842592592592593,[2,-3,0,0,0,0,0],"(kcal/kg)/h","heat",true,null,null,1,false,false,0,"kcal/kg/24hrs; 24 hrs; kcal per kg per 24hrs; kilocalories per kilograms per 24 hours; kilojoules","LOINC","EngCntRat","Clinical","used in nutrition to represent caloric requirement per day based on subject's body weight in kilograms","cal_th","CAL_TH","1",1,false],[false,"kilogram","kg","KG","mass",1000,[0,0,1,0,0,0,0],"kg",null,false,"M",null,1,false,false,0,"kilograms; kgs","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"kilogram meter per second","kg.m/s","(KG.M)/S","mass",1000,[1,-1,1,0,0,0,0],"(kg.m)/s",null,false,"M",null,1,false,false,0,"kg*m/s; kg.m per sec; kg*m per sec; p; momentum","LOINC","","Clinical","unit for momentum = mass times velocity",null,null,null,null,false],[false,"kilogram per second per square meter","kg/(s.m2)","KG/(S.M2)","mass",1000,[-2,-1,1,0,0,0,0],"kg/(s.(m2))",null,false,"M",null,1,false,false,0,"kg/(s*m2); kg/(s*m^2); kg per s per m2; per sec; per m^2; kilograms per seconds per square meter; meter squared; metre","LOINC","ArMRat","Clinical","",null,null,null,null,false],[false,"kilogram per hour","kg/h","KG/HR","mass",0.2777777777777778,[0,-1,1,0,0,0,0],"kg/h",null,false,"M",null,1,false,false,0,"kg/hr; kg per hr; kilograms per hour","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kilogram per liter","kg/L","KG/L","mass",1000000,[-3,0,1,0,0,0,0],"kg/L",null,false,"M",null,1,false,false,0,"kg per liter; litre; kilograms","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"kilogram per square meter","kg/m2","KG/M2","mass",1000,[-2,0,1,0,0,0,0],"kg/(m2)",null,false,"M",null,1,false,false,0,"kg/m^2; kg/sq. m; kg per m2; per m^2; per sq. m; kilograms; meter squared; metre; BMI","LOINC","Ratio","Clinical","units for body mass index (BMI)",null,null,null,null,false],[false,"kilogram per cubic meter","kg/m3","KG/M3","mass",1000,[-3,0,1,0,0,0,0],"kg/(m3)",null,false,"M",null,1,false,false,0,"kg/m^3; kg/cu. m; kg per m3; per m^3; per cu. m; kilograms; meters cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"kilogram per minute","kg/min","KG/MIN","mass",16.666666666666668,[0,-1,1,0,0,0,0],"kg/min",null,false,"M",null,1,false,false,0,"kilogram/minute; kg per min; kilograms per minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kilogram per mole","kg/mol","KG/MOL","mass",1.6605401866749388e-21,[0,0,1,0,0,0,0],"kg/mol",null,false,"M",null,1,false,false,-1,"kilogram/mole; kg per mol; kilograms per mole","LOINC","SCnt","Clinical","",null,null,null,null,false],[false,"kilogram per second","kg/s","KG/S","mass",1000,[0,-1,1,0,0,0,0],"kg/s",null,false,"M",null,1,false,false,0,"kg/sec; kilogram/second; kg per sec; kilograms; second","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"kiloliter","kL","KL","volume",1,[3,0,0,0,0,0,0],"kL","iso1000",true,null,null,1,false,false,0,"kiloliters; kilolitres; m3; m^3; meters cubed; metre","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"kilometer","km","KM","length",1000,[1,0,0,0,0,0,0],"km",null,false,"L",null,1,false,false,0,"kilometers; kilometres; distance","LOINC","Len","Clinical","",null,null,null,null,false],[false,"kilopascal","kPa","KPAL","pressure",1000000,[-1,-2,1,0,0,0,0],"kPa","si",true,null,null,1,false,false,0,"kilopascals; pressure","LOINC","Pres; PPresDiff","Clinical","","N/m2","N/M2","1",1,false],[false,"kilosecond","ks","KS","time",1000,[0,1,0,0,0,0,0],"ks",null,false,"T",null,1,false,false,0,"kiloseconds; ksec","LOINC","Time","Clinical","",null,null,null,null,false],[false,"kilo enzyme unit","kU","KU","catalytic activity",10036894500000000000,[0,-1,0,0,0,0,0],"kU","chemical",true,null,null,1,false,false,1,"units; mmol/min; millimoles per minute","LOINC","CAct","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per gram","kU/g","KU/G","catalytic activity",10036894500000000000,[0,-1,-1,0,0,0,0],"kU/g","chemical",true,null,null,1,false,false,1,"units per grams; kU per gm","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per liter","kU/L","KU/L","catalytic activity",1.00368945e+22,[-3,-1,0,0,0,0,0],"kU/L","chemical",true,null,null,1,false,false,1,"units per liter; litre; enzymatic activity; enzyme activity per volume; activities","LOINC","ACnc; CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"kilo enzyme unit per milliliter","kU/mL","KU/ML","catalytic activity",1.00368945e+25,[-3,-1,0,0,0,0,0],"kU/mL","chemical",true,null,null,1,false,false,1,"kU per mL; units per milliliter; millilitre; enzymatic activity per volume; enzyme activities","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 kU = 1 mmol/min","umol/min","UMOL/MIN","1",1,false],[false,"Liters per 24 hour","L/(24.h)","L/HR","volume",1.1574074074074074e-8,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/24hrs; L/24 hrs; L per 24hrs; liters per 24 hours; day; dy; litres; volume flow rate","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per 8 hour","L/(8.h)","L/HR","volume",3.472222222222222e-8,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/8hrs; L/8 hrs; L per 8hrs; liters per 8 hours; litres; volume flow rate; shift","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per minute per square meter","L/(min.m2) ","L/(MIN.M2)","volume",0.000016666666666666667,[1,-1,0,0,0,0,0],"L/(min.(m2))","iso1000",true,null,null,1,false,false,0,"L/(min.m2); L/min/m^2; L/min/sq. meter; L per min per m2; m^2; liters per minutes per square meter; meter squared; litres; metre ","LOINC","ArVRat","Clinical","unit for tests that measure cardiac output per body surface area (cardiac index)","l",null,"1",1,false],[false,"Liters per day","L/d","L/D","volume",1.1574074074074074e-8,[3,-1,0,0,0,0,0],"L/d","iso1000",true,null,null,1,false,false,0,"L/dy; L per day; 24hrs; 24 hrs; 24 hours; liters; litres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per hour","L/h","L/HR","volume",2.7777777777777776e-7,[3,-1,0,0,0,0,0],"L/h","iso1000",true,null,null,1,false,false,0,"L/hr; L per hr; litres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per kilogram","L/kg","L/KG","volume",0.000001,[3,0,-1,0,0,0,0],"L/kg","iso1000",true,null,null,1,false,false,0,"L per kg; litre","LOINC","VCnt","Clinical","","l",null,"1",1,false],[false,"Liters per liter","L/L","L/L","volume",1,[0,0,0,0,0,0,0],"L/L","iso1000",true,null,null,1,false,false,0,"L per L; liter/liter; litre","LOINC","VFr","Clinical","","l",null,"1",1,false],[false,"Liters per minute","L/min","L/MIN","volume",0.000016666666666666667,[3,-1,0,0,0,0,0],"L/min","iso1000",true,null,null,1,false,false,0,"liters per minute; litre","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"Liters per minute per square meter","L/min/m2","(L/MIN)/M2","volume",0.000016666666666666667,[1,-1,0,0,0,0,0],"(L/min)/(m2)","iso1000",true,null,null,1,false,false,0,"L/(min.m2); L/min/m^2; L/min/sq. meter; L per min per m2; m^2; liters per minutes per square meter; meter squared; litres; metre ","","ArVRat","Clinical","unit for tests that measure cardiac output per body surface area (cardiac index)","l",null,"1",1,false],[false,"Liters per second","L/s","L/S","volume",0.001,[3,-1,0,0,0,0,0],"L/s","iso1000",true,null,null,1,false,false,0,"L per sec; litres","LOINC","VRat","Clinical","unit used often to measure gas flow and peak expiratory flow","l",null,"1",1,false],[false,"Liters per second per square second","L/s/s2","(L/S)/S2","volume",0.001,[3,-3,0,0,0,0,0],"(L/s)/(s2)","iso1000",true,null,null,1,false,false,0,"L/s/s^2; L/sec/sec2; L/sec/sec^2; L/sec/sq. sec; L per s per s2; L per sec per sec2; s^2; sec^2; liters per seconds per square second; second squared; litres ","LOINC","ArVRat","Clinical","unit for tests that measure cardiac output/body surface area","l",null,"1",1,false],[false,"lumen square meter","lm.m2","LM.M2","luminous flux",1,[2,0,0,2,0,0,1],"lm.(m2)","si",true,null,null,1,false,false,0,"lm*m2; lm*m^2; lumen meters squared; lumen sq. meters; metres","LOINC","","Clinical","","cd.sr","CD.SR","1",1,false],[false,"meter per second","m/s","M/S","length",1,[1,-1,0,0,0,0,0],"m/s",null,false,"L",null,1,false,false,0,"meter/second; m per sec; meters per second; metres; velocity; speed","LOINC","Vel","Clinical","unit of velocity",null,null,null,null,false],[false,"meter per square second","m/s2","M/S2","length",1,[1,-2,0,0,0,0,0],"m/(s2)",null,false,"L",null,1,false,false,0,"m/s^2; m/sq. sec; m per s2; per s^2; meters per square second; second squared; sq second; metres; acceleration","LOINC","Accel","Clinical","unit of acceleration",null,null,null,null,false],[false,"milli international unit per liter","m[IU]/L","M[IU]/L","arbitrary",1,[-3,0,0,0,0,0,0],"(mi.U.)/L","chemical",true,null,null,1,false,true,0,"mIU/L; m IU/L; mIU per liter; units; litre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"milli international unit per milliliter","m[IU]/mL","M[IU]/ML","arbitrary",1000.0000000000001,[-3,0,0,0,0,0,0],"(mi.U.)/mL","chemical",true,null,null,1,false,true,0,"mIU/mL; m IU/mL; mIU per mL; milli international units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"square meter","m2","M2","length",1,[2,0,0,0,0,0,0],"m2",null,false,"L",null,1,false,false,0,"m^2; sq m; square meters; meters squared; metres","LOINC","Area","Clinical","unit often used to represent body surface area",null,null,null,null,false],[false,"square meter per second","m2/s","M2/S","length",1,[2,-1,0,0,0,0,0],"(m2)/s",null,false,"L",null,1,false,false,0,"m^2/sec; m2 per sec; m^2 per sec; sq m/sec; meters squared/seconds; sq m per sec; meters squared; metres","LOINC","ArRat","Clinical","",null,null,null,null,false],[false,"cubic meter per second","m3/s","M3/S","length",1,[3,-1,0,0,0,0,0],"(m3)/s",null,false,"L",null,1,false,false,0,"m^3/sec; m3 per sec; m^3 per sec; cu m/sec; cubic meters per seconds; meters cubed; metres","LOINC","VRat","Clinical","",null,null,null,null,false],[false,"milliampere","mA","MA","electric current",0.001,[0,-1,0,0,0,1,0],"mA","si",true,null,null,1,false,false,0,"mamp; milliamperes","LOINC","ElpotRat","Clinical","unit of electric current","C/s","C/S","1",1,false],[false,"millibar","mbar","MBAR","pressure",100000,[-1,-2,1,0,0,0,0],"mbar","iso1000",true,null,null,1,false,false,0,"millibars","LOINC","Pres","Clinical","unit of pressure","Pa","PAL","1e5",100000,false],[false,"millibar second per liter","mbar.s/L","(MBAR.S)/L","pressure",100000000,[-4,-1,1,0,0,0,0],"(mbar.s)/L","iso1000",true,null,null,1,false,false,0,"mbar*s/L; mbar.s per L; mbar*s per L; millibar seconds per liter; millibar second per litre","LOINC","","Clinical","unit to measure expiratory resistance","Pa","PAL","1e5",100000,false],[false,"millibar per liter per second","mbar/L/s","(MBAR/L)/S","pressure",100000000,[-4,-3,1,0,0,0,0],"(mbar/L)/s","iso1000",true,null,null,1,false,false,0,"mbar/(L.s); mbar/L/sec; mbar/liter/second; mbar per L per sec; mbar per liter per second; millibars per liters per seconds; litres","LOINC","PresCncRat","Clinical","unit to measure expiratory resistance","Pa","PAL","1e5",100000,false],[false,"milliequivalent","meq","MEQ","amount of substance",602213670000000000000,[0,0,0,0,0,0,0],"meq","chemical",true,null,null,1,false,false,1,"milliequivalents; meqs","LOINC","Sub","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 2 hour","meq/(2.h)","MEQ/HR","amount of substance",83640787500000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/2hrs; meq/2 hrs; meq per 2 hrs; milliequivalents per 2 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 24 hour","meq/(24.h)","MEQ/HR","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/24hrs; meq/24 hrs; meq per 24 hrs; milliequivalents per 24 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per 8 hour","meq/(8.h)","MEQ/HR","amount of substance",20910196875000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/8hrs; meq/8 hrs; meq per 8 hrs; milliequivalents per 8 hours; shift","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per day","meq/d","MEQ/D","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"meq/d","chemical",true,null,null,1,false,false,1,"meq/dy; meq per day; milliquivalents per days; meq/24hrs; meq/24 hrs; meq per 24 hrs; milliequivalents per 24 hours","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per deciliter","meq/dL","MEQ/DL","amount of substance",6.022136699999999e+24,[-3,0,0,0,0,0,0],"meq/dL","chemical",true,null,null,1,false,false,1,"meq per dL; milliequivalents per deciliter; decilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per gram","meq/g","MEQ/G","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"meq/g","chemical",true,null,null,1,false,false,1,"mgq/gm; meq per gm; milliequivalents per gram","LOINC","MCnt","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per hour","meq/h","MEQ/HR","amount of substance",167281575000000000,[0,-1,0,0,0,0,0],"meq/h","chemical",true,null,null,1,false,false,1,"meq/hrs; meq per hrs; milliequivalents per hour","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per kilogram","meq/kg","MEQ/KG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"meq/kg","chemical",true,null,null,1,false,false,1,"meq per kg; milliequivalents per kilogram","LOINC","SCnt","Clinical","equivalence equals moles per valence; used to measure dose per patient body mass","mol","MOL","1",1,false],[false,"milliequivalent per kilogram per hour","meq/kg/h","(MEQ/KG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(meq/kg)/h","chemical",true,null,null,1,false,false,1,"meq/(kg.h); meq/kg/hr; meq per kg per hr; milliequivalents per kilograms per hour","LOINC","SCntRat","Clinical","equivalence equals moles per valence; unit used to measure dose rate per patient body mass","mol","MOL","1",1,false],[false,"milliequivalent per liter","meq/L","MEQ/L","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"meq/L","chemical",true,null,null,1,false,false,1,"milliequivalents per liter; litre; meq per l; acidity","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per square meter","meq/m2","MEQ/M2","amount of substance",602213670000000000000,[-2,0,0,0,0,0,0],"meq/(m2)","chemical",true,null,null,1,false,false,1,"meq/m^2; meq/sq. m; milliequivalents per square meter; meter squared; metre","LOINC","ArSub","Clinical","equivalence equals moles per valence; note that the use of m2 in clinical units ofter refers to body surface area","mol","MOL","1",1,false],[false,"milliequivalent per minute","meq/min","MEQ/MIN","amount of substance",10036894500000000000,[0,-1,0,0,0,0,0],"meq/min","chemical",true,null,null,1,false,false,1,"meq per min; milliequivalents per minute","LOINC","SRat","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milliequivalent per milliliter","meq/mL","MEQ/ML","amount of substance",6.0221367e+26,[-3,0,0,0,0,0,0],"meq/mL","chemical",true,null,null,1,false,false,1,"meq per mL; milliequivalents per milliliter; millilitre","LOINC","SCnc","Clinical","equivalence equals moles per valence","mol","MOL","1",1,false],[false,"milligram","mg","MG","mass",0.001,[0,0,1,0,0,0,0],"mg",null,false,"M",null,1,false,false,0,"milligrams","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"milligram per 10 hour","mg/(10.h)","MG/HR","mass",2.7777777777777777e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/10hrs; mg/10 hrs; mg per 10 hrs; milligrams per 10 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 12 hour","mg/(12.h)","MG/HR","mass",2.3148148148148148e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/12hrs; mg/12 hrs; per 12 hrs; 12hrs; milligrams per 12 hours","LOINC","MRat","Clinical","units used for tests in urine",null,null,null,null,false],[false,"milligram per 2 hour","mg/(2.h)","MG/HR","mass",1.3888888888888888e-7,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/2hrs; mg/2 hrs; mg per 2 hrs; 2hrs; milligrams per 2 hours","LOINC","MRat","Clinical","units used for tests in urine",null,null,null,null,false],[false,"milligram per 24 hour","mg/(24.h)","MG/HR","mass",1.1574074074074074e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/24hrs; mg/24 hrs; milligrams per 24 hours; mg/kg/dy; mg per kg per day; milligrams per kilograms per days","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 6 hour","mg/(6.h)","MG/HR","mass",4.6296296296296295e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/6hrs; mg/6 hrs; mg per 6 hrs; 6hrs; milligrams per 6 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 72 hour","mg/(72.h)","MG/HR","mass",3.858024691358025e-9,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/72hrs; mg/72 hrs; 72 hrs; 72hrs; milligrams per 72 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per 8 hour","mg/(8.h)","MG/HR","mass",3.472222222222222e-8,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/8hrs; mg/8 hrs; milligrams per 8 hours; shift","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per day","mg/d","MG/D","mass",1.1574074074074074e-8,[0,-1,1,0,0,0,0],"mg/d",null,false,"M",null,1,false,false,0,"mg/24hrs; mg/24 hrs; milligrams per 24 hours; mg/dy; mg per day; milligrams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per deciliter","mg/dL","MG/DL","mass",10,[-3,0,1,0,0,0,0],"mg/dL",null,false,"M",null,1,false,false,0,"mg per dL; milligrams per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per gram","mg/g","MG/G","mass",0.001,[0,0,0,0,0,0,0],"mg/g",null,false,"M",null,1,false,false,0,"mg per gm; milligrams per gram","LOINC","MCnt; MRto","Clinical","",null,null,null,null,false],[false,"milligram per hour","mg/h","MG/HR","mass",2.7777777777777776e-7,[0,-1,1,0,0,0,0],"mg/h",null,false,"M",null,1,false,false,0,"mg/hr; mg per hr; milligrams","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per kilogram","mg/kg","MG/KG","mass",0.000001,[0,0,0,0,0,0,0],"mg/kg",null,false,"M",null,1,false,false,0,"mg per kg; milligrams per kilograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"milligram per kilogram per 8 hour","mg/kg/(8.h)","(MG/KG)/HR","mass",3.472222222222222e-11,[0,-1,0,0,0,0,0],"(mg/kg)/h",null,false,"M",null,1,false,false,0,"mg/(8.h.kg); mg/kg/8hrs; mg/kg/8 hrs; mg per kg per 8hrs; 8 hrs; milligrams per kilograms per 8 hours; shift","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per day","mg/kg/d","(MG/KG)/D","mass",1.1574074074074074e-11,[0,-1,0,0,0,0,0],"(mg/kg)/d",null,false,"M",null,1,false,false,0,"mg/(kg.d); mg/(kg.24.h)mg/kg/dy; mg per kg per day; milligrams per kilograms per days; mg/kg/(24.h); mg/kg/24hrs; 24 hrs; 24 hours","LOINC","RelMRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per hour","mg/kg/h","(MG/KG)/HR","mass",2.7777777777777777e-10,[0,-1,0,0,0,0,0],"(mg/kg)/h",null,false,"M",null,1,false,false,0,"mg/(kg.h); mg/kg/hr; mg per kg per hr; milligrams per kilograms per hour","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per kilogram per minute","mg/kg/min","(MG/KG)/MIN","mass",1.6666666666666667e-8,[0,-1,0,0,0,0,0],"(mg/kg)/min",null,false,"M",null,1,false,false,0,"mg/(kg.min); mg per kg per min; milligrams per kilograms per minute","LOINC","RelMRat; MCntRat","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"milligram per liter","mg/L","MG/L","mass",1,[-3,0,1,0,0,0,0],"mg/L",null,false,"M",null,1,false,false,0,"mg per l; milligrams per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per square meter","mg/m2","MG/M2","mass",0.001,[-2,0,1,0,0,0,0],"mg/(m2)",null,false,"M",null,1,false,false,0,"mg/m^2; mg/sq. m; mg per m2; mg per m^2; mg per sq. milligrams; meter squared; metre","LOINC","ArMass","Clinical","",null,null,null,null,false],[false,"milligram per cubic meter","mg/m3","MG/M3","mass",0.001,[-3,0,1,0,0,0,0],"mg/(m3)",null,false,"M",null,1,false,false,0,"mg/m^3; mg/cu. m; mg per m3; milligrams per cubic meter; meter cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per milligram","mg/mg","MG/MG","mass",1,[0,0,0,0,0,0,0],"mg/mg",null,false,"M",null,1,false,false,0,"mg per mg; milligrams; milligram/milligram","LOINC","MRto","Clinical","",null,null,null,null,false],[false,"milligram per minute","mg/min","MG/MIN","mass",0.000016666666666666667,[0,-1,1,0,0,0,0],"mg/min",null,false,"M",null,1,false,false,0,"mg per min; milligrams per minutes; milligram/minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"milligram per milliliter","mg/mL","MG/ML","mass",1000.0000000000001,[-3,0,1,0,0,0,0],"mg/mL",null,false,"M",null,1,false,false,0,"mg per mL; milligrams per milliliters; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"milligram per millimole","mg/mmol","MG/MMOL","mass",1.660540186674939e-24,[0,0,1,0,0,0,0],"mg/mmol",null,false,"M",null,1,false,false,-1,"mg per mmol; milligrams per millimole; ","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"milligram per week","mg/wk","MG/WK","mass",1.6534391534391535e-9,[0,-1,1,0,0,0,0],"mg/wk",null,false,"M",null,1,false,false,0,"mg/week; mg per wk; milligrams per weeks; milligram/week","LOINC","Mrat","Clinical","",null,null,null,null,false],[false,"milliliter","mL","ML","volume",0.000001,[3,0,0,0,0,0,0],"mL","iso1000",true,null,null,1,false,false,0,"milliliters; millilitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"milliliter per 10 hour","mL/(10.h)","ML/HR","volume",2.7777777777777777e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/10hrs; ml/10 hrs; mL per 10hrs; 10 hrs; milliliters per 10 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 12 hour","mL/(12.h)","ML/HR","volume",2.3148148148148147e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/12hrs; ml/12 hrs; mL per 12hrs; 12 hrs; milliliters per 12 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 2 hour","mL/(2.h)","ML/HR","volume",1.3888888888888888e-10,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/2hrs; ml/2 hrs; mL per 2hrs; 2 hrs; milliliters per 2 hours; millilitres ","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 24 hour","mL/(24.h)","ML/HR","volume",1.1574074074074074e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/24hrs; ml/24 hrs; mL per 24hrs; 24 hrs; milliliters per 24 hours; millilitres; ml/dy; /day; ml per dy; days; fluid outputs; fluid inputs; flow rate","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 4 hour","mL/(4.h)","ML/HR","volume",6.944444444444444e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/4hrs; ml/4 hrs; mL per 4hrs; 4 hrs; milliliters per 4 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 5 hour","mL/(5.h)","ML/HR","volume",5.5555555555555553e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/5hrs; ml/5 hrs; mL per 5hrs; 5 hrs; milliliters per 5 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 6 hour","mL/(6.h)","ML/HR","volume",4.6296296296296294e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/6hrs; ml/6 hrs; mL per 6hrs; 6 hrs; milliliters per 6 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 72 hour","mL/(72.h)","ML/HR","volume",3.8580246913580245e-12,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/72hrs; ml/72 hrs; mL per 72hrs; 72 hrs; milliliters per 72 hours; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 8 hour","mL/(8.h)","ML/HR","volume",3.472222222222222e-11,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"ml/8hrs; ml/8 hrs; mL per 8hrs; 8 hrs; milliliters per 8 hours; millilitres; shift","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per 8 hour per kilogram","mL/(8.h)/kg","(ML/HR)/KG","volume",3.472222222222222e-14,[3,-1,-1,0,0,0,0],"(mL/h)/kg","iso1000",true,null,null,1,false,false,0,"mL/kg/(8.h); ml/8h/kg; ml/8 h/kg; ml/8hr/kg; ml/8 hr/kgr; mL per 8h per kg; 8 h; 8hr; 8 hr; milliliters per 8 hours per kilogram; millilitres; shift","LOINC","VRatCnt","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per square inch (international)","mL/[sin_i]","ML/[SIN_I]","volume",0.0015500031000061998,[1,0,0,0,0,0,0],"mL","iso1000",true,null,null,1,false,false,0,"mL/sin; mL/in2; mL/in^2; mL per sin; in2; in^2; sq. in; milliliters per square inch; inch squared","LOINC","ArVol","Clinical","","l",null,"1",1,false],[false,"milliliter per centimeter of water","mL/cm[H2O]","ML/CM[H2O]","volume",1.0197162129779282e-11,[4,2,-1,0,0,0,0],"mL/(cm HO2)","iso1000",true,null,null,1,false,false,0,"milliliters per centimeter of water; millilitre per centimetre of water; millilitres per centimetre of water; mL/cmH2O; mL/cm H2O; mL per cmH2O; mL per cm H2O","LOINC","Compli","Clinical","unit used to measure dynamic lung compliance","l",null,"1",1,false],[false,"milliliter per day","mL/d","ML/D","volume",1.1574074074074074e-11,[3,-1,0,0,0,0,0],"mL/d","iso1000",true,null,null,1,false,false,0,"ml/day; ml per day; milliliters per day; 24 hours; 24hrs; millilitre;","LOINC","VRat","Clinical","usually used to measure fluid output or input; flow rate","l",null,"1",1,false],[false,"milliliter per deciliter","mL/dL","ML/DL","volume",0.009999999999999998,[0,0,0,0,0,0,0],"mL/dL","iso1000",true,null,null,1,false,false,0,"mL per dL; millilitres; decilitre; milliliters","LOINC","VFr; VFrDiff","Clinical","","l",null,"1",1,false],[false,"milliliter per hour","mL/h","ML/HR","volume",2.7777777777777777e-10,[3,-1,0,0,0,0,0],"mL/h","iso1000",true,null,null,1,false,false,0,"mL/hr; mL per hr; milliliters per hour; millilitres; fluid intake; fluid output","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per kilogram","mL/kg","ML/KG","volume",9.999999999999999e-10,[3,0,-1,0,0,0,0],"mL/kg","iso1000",true,null,null,1,false,false,0,"mL per kg; milliliters per kilogram; millilitres","LOINC","VCnt","Clinical","","l",null,"1",1,false],[false,"milliliter per kilogram per 8 hour","mL/kg/(8.h)","(ML/KG)/HR","volume",3.472222222222222e-14,[3,-1,-1,0,0,0,0],"(mL/kg)/h","iso1000",true,null,null,1,false,false,0,"mL/(8.h.kg); mL/kg/8hrs; mL/kg/8 hrs; mL per kg per 8hrs; 8 hrs; milliliters per kilograms per 8 hours; millilitres; shift","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per day","mL/kg/d","(ML/KG)/D","volume",1.1574074074074072e-14,[3,-1,-1,0,0,0,0],"(mL/kg)/d","iso1000",true,null,null,1,false,false,0,"mL/(kg.d); mL/kg/dy; mL per kg per day; milliliters per kilograms per day; mg/kg/24hrs; 24 hrs; per 24 hours millilitres","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per hour","mL/kg/h","(ML/KG)/HR","volume",2.7777777777777774e-13,[3,-1,-1,0,0,0,0],"(mL/kg)/h","iso1000",true,null,null,1,false,false,0,"mL/(kg.h); mL/kg/hr; mL per kg per hr; milliliters per kilograms per hour; millilitres","LOINC","VCntRat; RelEngRat","Clinical","unit used to measure renal excretion volume rate per body mass","l",null,"1",1,false],[false,"milliliter per kilogram per minute","mL/kg/min","(ML/KG)/MIN","volume",1.6666666666666664e-11,[3,-1,-1,0,0,0,0],"(mL/kg)/min","iso1000",true,null,null,1,false,false,0,"mL/(kg.min); mL/kg/dy; mL per kg per day; milliliters per kilograms per day; millilitres","LOINC","RelEngRat","Clinical","used for tests that measure activity metabolic rate compared to standard resting metabolic rate ","l",null,"1",1,false],[false,"milliliter per square meter","mL/m2","ML/M2","volume",0.000001,[1,0,0,0,0,0,0],"mL/(m2)","iso1000",true,null,null,1,false,false,0,"mL/m^2; mL/sq. meter; mL per m2; m^2; sq. meter; milliliters per square meter; millilitres; meter squared","LOINC","ArVol","Clinical","used for tests that relate to heart work - e.g. ventricular stroke volume; atrial volume per body surface area","l",null,"1",1,false],[false,"milliliter per millibar","mL/mbar","ML/MBAR","volume",1e-11,[4,2,-1,0,0,0,0],"mL/mbar","iso1000",true,null,null,1,false,false,0,"mL per mbar; milliliters per millibar; millilitres","LOINC","","Clinical","unit used to measure dynamic lung compliance","l",null,"1",1,false],[false,"milliliter per minute","mL/min","ML/MIN","volume",1.6666666666666667e-8,[3,-1,0,0,0,0,0],"mL/min","iso1000",true,null,null,1,false,false,0,"mL per min; milliliters; millilitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"milliliter per minute per square meter","mL/min/m2","(ML/MIN)/M2","volume",1.6666666666666667e-8,[1,-1,0,0,0,0,0],"(mL/min)/(m2)","iso1000",true,null,null,1,false,false,0,"ml/min/m^2; ml/min/sq. meter; mL per min per m2; m^2; sq. meter; milliliters per minutes per square meter; millilitres; metre; meter squared","LOINC","ArVRat","Clinical","unit used to measure volume per body surface area; oxygen consumption index","l",null,"1",1,false],[false,"milliliter per millimeter","mL/mm","ML/MM","volume",0.001,[2,0,0,0,0,0,0],"mL/mm","iso1000",true,null,null,1,false,false,0,"mL per mm; milliliters per millimeter; millilitres; millimetre","LOINC","Lineic Volume","Clinical","","l",null,"1",1,false],[false,"milliliter per second","mL/s","ML/S","volume",0.000001,[3,-1,0,0,0,0,0],"mL/s","iso1000",true,null,null,1,false,false,0,"ml/sec; mL per sec; milliliters per second; millilitres","LOINC","Vel; VelRat; VRat","Clinical","","l",null,"1",1,false],[false,"millimeter","mm","MM","length",0.001,[1,0,0,0,0,0,0],"mm",null,false,"L",null,1,false,false,0,"millimeters; millimetres; height; length; diameter; thickness; axis; curvature; size","LOINC","Len","Clinical","",null,null,null,null,false],[false,"millimeter per hour","mm/h","MM/HR","length",2.7777777777777776e-7,[1,-1,0,0,0,0,0],"mm/h",null,false,"L",null,1,false,false,0,"mm/hr; mm per hr; millimeters per hour; millimetres","LOINC","Vel","Clinical","unit to measure sedimentation rate",null,null,null,null,false],[false,"millimeter per minute","mm/min","MM/MIN","length",0.000016666666666666667,[1,-1,0,0,0,0,0],"mm/min",null,false,"L",null,1,false,false,0,"mm per min; millimeters per minute; millimetres","LOINC","Vel","Clinical","",null,null,null,null,false],[false,"millimeter of water","mm[H2O]","MM[H2O]","pressure",9806.65,[-1,-2,1,0,0,0,0],"mm HO2","clinical",true,null,null,1,false,false,0,"mmH2O; mm H2O; millimeters of water; millimetres","LOINC","Pres","Clinical","","kPa","KPAL","980665e-5",9.80665,false],[false,"millimeter of mercury","mm[Hg]","MM[HG]","pressure",133322,[-1,-2,1,0,0,0,0],"mm Hg","clinical",true,null,null,1,false,false,0,"mmHg; mm Hg; millimeters of mercury; millimetres","LOINC","Pres; PPres; Ratio","Clinical","1 mm[Hg] = 1 torr; unit to measure blood pressure","kPa","KPAL","133.3220",133.322,false],[false,"square millimeter","mm2","MM2","length",0.000001,[2,0,0,0,0,0,0],"mm2",null,false,"L",null,1,false,false,0,"mm^2; sq. mm.; sq. millimeters; millimeters squared; millimetres","LOINC","Area","Clinical","",null,null,null,null,false],[false,"millimole","mmol","MMOL","amount of substance",602213670000000000000,[0,0,0,0,0,0,0],"mmol","si",true,null,null,1,false,false,1,"millimoles","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 12 hour","mmol/(12.h)","MMOL/HR","amount of substance",13940131250000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/12hrs; mmol/12 hrs; mmol per 12 hrs; 12hrs; millimoles per 12 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 2 hour","mmol/(2.h)","MMOL/HR","amount of substance",83640787500000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/2hrs; mmol/2 hrs; mmol per 2 hrs; 2hrs; millimoles per 2 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 24 hour","mmol/(24.h)","MMOL/HR","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/24hrs; mmol/24 hrs; mmol per 24 hrs; 24hrs; millimoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 5 hour","mmol/(5.h)","MMOL/HR","amount of substance",33456315000000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/5hrs; mmol/5 hrs; mmol per 5 hrs; 5hrs; millimoles per 5 hours","LOINC","SRat","Clinical","unit for tests related to doses","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 6 hour","mmol/(6.h)","MMOL/HR","amount of substance",27880262500000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/6hrs; mmol/6 hrs; mmol per 6 hrs; 6hrs; millimoles per 6 hours","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per 8 hour","mmol/(8.h)","MMOL/HR","amount of substance",20910196875000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/8hrs; mmol/8 hrs; mmol per 8 hrs; 8hrs; millimoles per 8 hours; shift","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per day","mmol/d","MMOL/D","amount of substance",6970065625000000,[0,-1,0,0,0,0,0],"mmol/d","si",true,null,null,1,false,false,1,"mmol/24hrs; mmol/24 hrs; mmol per 24 hrs; 24hrs; millimoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per deciliter","mmol/dL","MMOL/DL","amount of substance",6.022136699999999e+24,[-3,0,0,0,0,0,0],"mmol/dL","si",true,null,null,1,false,false,1,"mmol per dL; millimoles; decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per gram","mmol/g","MMOL/G","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"mmol/g","si",true,null,null,1,false,false,1,"mmol per gram; millimoles","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per hour","mmol/h","MMOL/HR","amount of substance",167281575000000000,[0,-1,0,0,0,0,0],"mmol/h","si",true,null,null,1,false,false,1,"mmol/hr; mmol per hr; millimoles per hour","LOINC","SRat","Clinical","unit for tests related to urine","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram","mmol/kg","MMOL/KG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"mmol/kg","si",true,null,null,1,false,false,1,"mmol per kg; millimoles per kilogram","LOINC","SCnt","Clinical","unit for tests related to stool","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per 8 hour","mmol/kg/(8.h)","(MMOL/KG)/HR","amount of substance",20910196875000,[0,-1,-1,0,0,0,0],"(mmol/kg)/h","si",true,null,null,1,false,false,1,"mmol/(8.h.kg); mmol/kg/8hrs; mmol/kg/8 hrs; mmol per kg per 8hrs; 8 hrs; millimoles per kilograms per 8 hours; shift","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per day","mmol/kg/d","(MMOL/KG)/D","amount of substance",6970065625000,[0,-1,-1,0,0,0,0],"(mmol/kg)/d","si",true,null,null,1,false,false,1,"mmol/kg/dy; mmol/kg/day; mmol per kg per dy; millimoles per kilograms per day","LOINC","RelSRat","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per hour","mmol/kg/h","(MMOL/KG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(mmol/kg)/h","si",true,null,null,1,false,false,1,"mmol/kg/hr; mmol per kg per hr; millimoles per kilograms per hour","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per kilogram per minute","mmol/kg/min","(MMOL/KG)/MIN","amount of substance",10036894500000000,[0,-1,-1,0,0,0,0],"(mmol/kg)/min","si",true,null,null,1,false,false,1,"mmol/(kg.min); mmol/kg/min; mmol per kg per min; millimoles per kilograms per minute","LOINC","CCnt","Clinical","unit used to measure molar dose rate per patient body mass; note that the unit for the enzyme unit U = umol/min. mmol/kg/min = kU/kg; ","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per liter","mmol/L","MMOL/L","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"mmol/L","si",true,null,null,1,false,false,1,"mmol per L; millimoles per liter; litre","LOINC","SCnc","Clinical","unit for tests related to doses","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per square meter","mmol/m2","MMOL/M2","amount of substance",602213670000000000000,[-2,0,0,0,0,0,0],"mmol/(m2)","si",true,null,null,1,false,false,1,"mmol/m^2; mmol/sq. meter; mmol per m2; m^2; sq. meter; millimoles; meter squared; metre","LOINC","ArSub","Clinical","unit used to measure molar dose per patient body surface area","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per minute","mmol/min","MMOL/MIN","amount of substance",10036894500000000000,[0,-1,0,0,0,0,0],"mmol/min","si",true,null,null,1,false,false,1,"mmol per min; millimoles per minute","LOINC","Srat; CAct","Clinical","unit for the enzyme unit U = umol/min. mmol/min = kU","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per millimole","mmol/mmol","MMOL/MMOL","amount of substance",1,[0,0,0,0,0,0,0],"mmol/mmol","si",true,null,null,1,false,false,0,"mmol per mmol; millimoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per mole","mmol/mol","MMOL/MOL","amount of substance",0.001,[0,0,0,0,0,0,0],"mmol/mol","si",true,null,null,1,false,false,0,"mmol per mol; millimoles per mole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"millimole per second per liter","mmol/s/L","(MMOL/S)/L","amount of substance",6.0221367e+23,[-3,-1,0,0,0,0,0],"(mmol/s)/L","si",true,null,null,1,false,false,1,"mmol/sec/L; mmol per s per L; per sec; millimoles per seconds per liter; litre","LOINC","CCnc ","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per kilogram","mol/kg","MOL/KG","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"mol/kg","si",true,null,null,1,false,false,1,"mol per kg; moles; mols","LOINC","SCnt","Clinical","unit for tests related to stool","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per kilogram per second","mol/kg/s","(MOL/KG)/S","amount of substance",602213670000000000000,[0,-1,-1,0,0,0,0],"(mol/kg)/s","si",true,null,null,1,false,false,1,"mol/kg/sec; mol per kg per sec; moles per kilograms per second; mols","LOINC","CCnt","Clinical","unit of catalytic activity (mol/s) per mass (kg)","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per liter","mol/L","MOL/L","amount of substance",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"mol/L","si",true,null,null,1,false,false,1,"mol per L; moles per liter; litre; moles; mols","LOINC","SCnc","Clinical","unit often used in tests measuring oxygen content","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per cubic meter","mol/m3","MOL/M3","amount of substance",6.0221367e+23,[-3,0,0,0,0,0,0],"mol/(m3)","si",true,null,null,1,false,false,1,"mol/m^3; mol/cu. m; mol per m3; m^3; cu. meter; mols; moles; meters cubed; metre; mole per kiloliter; kilolitre; mol/kL","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per milliliter","mol/mL","MOL/ML","amount of substance",6.0221367e+29,[-3,0,0,0,0,0,0],"mol/mL","si",true,null,null,1,false,false,1,"mol per mL; moles; millilitre; mols","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per mole","mol/mol","MOL/MOL","amount of substance",1,[0,0,0,0,0,0,0],"mol/mol","si",true,null,null,1,false,false,0,"mol per mol; moles per mol; mols","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"mole per second","mol/s","MOL/S","amount of substance",6.0221367e+23,[0,-1,0,0,0,0,0],"mol/s","si",true,null,null,1,false,false,1,"mol per sec; moles per second; mols","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"milliosmole","mosm","MOSM","amount of substance (dissolved particles)",602213670000000000000,[0,0,0,0,0,0,0],"mosm","chemical",true,null,null,1,false,false,1,"milliosmoles","LOINC","Osmol","Clinical","equal to 1/1000 of an osmole","mol","MOL","1",1,false],[false,"milliosmole per kilogram","mosm/kg","MOSM/KG","amount of substance (dissolved particles)",602213670000000000,[0,0,-1,0,0,0,0],"mosm/kg","chemical",true,null,null,1,false,false,1,"mosm per kg; milliosmoles per kilogram","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"milliosmole per liter","mosm/L","MOSM/L","amount of substance (dissolved particles)",6.0221367e+23,[-3,0,0,0,0,0,0],"mosm/L","chemical",true,null,null,1,false,false,1,"mosm per liter; litre; milliosmoles","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"millipascal","mPa","MPAL","pressure",1,[-1,-2,1,0,0,0,0],"mPa","si",true,null,null,1,false,false,0,"millipascals","LOINC","Pres","Clinical","unit of pressure","N/m2","N/M2","1",1,false],[false,"millipascal second","mPa.s","MPAL.S","pressure",1,[-1,-1,1,0,0,0,0],"mPa.s","si",true,null,null,1,false,false,0,"mPa*s; millipoise; mP; dynamic viscosity","LOINC","Visc","Clinical","base units for millipoise, a measurement of dynamic viscosity","N/m2","N/M2","1",1,false],[false,"megasecond","Ms","MAS","time",1000000,[0,1,0,0,0,0,0],"Ms",null,false,"T",null,1,false,false,0,"megaseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"millisecond","ms","MS","time",0.001,[0,1,0,0,0,0,0],"ms",null,false,"T",null,1,false,false,0,"milliseconds; duration","LOINC","Time","Clinical","",null,null,null,null,false],[false,"milli enzyme unit per gram","mU/g","MU/G","catalytic activity",10036894500000,[0,-1,-1,0,0,0,0],"mU/g","chemical",true,null,null,1,false,false,1,"mU per gm; milli enzyme units per gram; enzyme activity; enzymatic activity per mass","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per liter","mU/L","MU/L","catalytic activity",10036894500000000,[-3,-1,0,0,0,0,0],"mU/L","chemical",true,null,null,1,false,false,1,"mU per liter; litre; milli enzyme units enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milligram","mU/mg","MU/MG","catalytic activity",10036894500000000,[0,-1,-1,0,0,0,0],"mU/mg","chemical",true,null,null,1,false,false,1,"mU per mg; milli enzyme units per milligram","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milliliter","mU/mL","MU/ML","catalytic activity",10036894500000000000,[-3,-1,0,0,0,0,0],"mU/mL","chemical",true,null,null,1,false,false,1,"mU per mL; milli enzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"milli enzyme unit per milliliter per minute","mU/mL/min","(MU/ML)/MIN","catalytic activity",167281575000000000,[-3,-2,0,0,0,0,0],"(mU/mL)/min","chemical",true,null,null,1,false,false,1,"mU per mL per min; mU per milliliters per minute; millilitres; milli enzyme units; enzymatic activity; enzyme activity","LOINC","CCncRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 mU = 1 nmol/min","umol/min","UMOL/MIN","1",1,false],[false,"millivolt","mV","MV","electric potential",1,[2,-2,1,0,0,-1,0],"mV","si",true,null,null,1,false,false,0,"millivolts","LOINC","Elpot","Clinical","unit of electric potential (voltage)","J/C","J/C","1",1,false],[false,"Newton centimeter","N.cm","N.CM","force",10,[2,-2,1,0,0,0,0],"N.cm","si",true,null,null,1,false,false,0,"N*cm; Ncm; N cm; Newton*centimeters; Newton* centimetres; torque; work","LOINC","","Clinical","as a measurement of work, N.cm = 1/100 Joules;\nnote that N.m is the standard unit of measurement for torque (although dimensionally equivalent to Joule), and N.cm can also be thought of as a torqe unit","kg.m/s2","KG.M/S2","1",1,false],[false,"Newton second","N.s","N.S","force",1000,[1,-1,1,0,0,0,0],"N.s","si",true,null,null,1,false,false,0,"Newton*seconds; N*s; N s; Ns; impulse; imp","LOINC","","Clinical","standard unit of impulse","kg.m/s2","KG.M/S2","1",1,false],[false,"nanogram","ng","NG","mass",1e-9,[0,0,1,0,0,0,0],"ng",null,false,"M",null,1,false,false,0,"nanograms","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"nanogram per 24 hour","ng/(24.h)","NG/HR","mass",1.1574074074074075e-14,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/24hrs; ng/24 hrs; nanograms per 24 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per 8 hour","ng/(8.h)","NG/HR","mass",3.4722222222222224e-14,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/8hrs; ng/8 hrs; nanograms per 8 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per million","ng/10*6","NG/(10*6)","mass",1e-15,[0,0,1,0,0,0,0],"ng/(106)",null,false,"M",null,1,false,false,0,"ng/10^6; ng per 10*6; 10^6; nanograms","LOINC","MNum","Clinical","",null,null,null,null,false],[false,"nanogram per day","ng/d","NG/D","mass",1.1574074074074075e-14,[0,-1,1,0,0,0,0],"ng/d",null,false,"M",null,1,false,false,0,"ng/dy; ng per day; nanograms ","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per deciliter","ng/dL","NG/DL","mass",0.00001,[-3,0,1,0,0,0,0],"ng/dL",null,false,"M",null,1,false,false,0,"ng per dL; nanograms per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per gram","ng/g","NG/G","mass",1e-9,[0,0,0,0,0,0,0],"ng/g",null,false,"M",null,1,false,false,0,"ng/gm; ng per gm; nanograms per gram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per hour","ng/h","NG/HR","mass",2.777777777777778e-13,[0,-1,1,0,0,0,0],"ng/h",null,false,"M",null,1,false,false,0,"ng/hr; ng per hr; nanograms per hour","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per kilogram","ng/kg","NG/KG","mass",1e-12,[0,0,0,0,0,0,0],"ng/kg",null,false,"M",null,1,false,false,0,"ng per kg; nanograms per kilogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per kilogram per 8 hour","ng/kg/(8.h)","(NG/KG)/HR","mass",3.472222222222222e-17,[0,-1,0,0,0,0,0],"(ng/kg)/h",null,false,"M",null,1,false,false,0,"ng/(8.h.kg); ng/kg/8hrs; ng/kg/8 hrs; ng per kg per 8hrs; 8 hrs; nanograms per kilograms per 8 hours; shift","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per kilogram per hour","ng/kg/h","(NG/KG)/HR","mass",2.7777777777777775e-16,[0,-1,0,0,0,0,0],"(ng/kg)/h",null,false,"M",null,1,false,false,0,"ng/(kg.h); ng/kg/hr; ng per kg per hr; nanograms per kilograms per hour","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per kilogram per minute","ng/kg/min","(NG/KG)/MIN","mass",1.6666666666666667e-14,[0,-1,0,0,0,0,0],"(ng/kg)/min",null,false,"M",null,1,false,false,0,"ng/(kg.min); ng per kg per min; nanograms per kilograms per minute","LOINC","MRtoRat ","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"nanogram per liter","ng/L","NG/L","mass",0.000001,[-3,0,1,0,0,0,0],"ng/L",null,false,"M",null,1,false,false,0,"ng per L; nanograms per liter; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per square meter","ng/m2","NG/M2","mass",1e-9,[-2,0,1,0,0,0,0],"ng/(m2)",null,false,"M",null,1,false,false,0,"ng/m^2; ng/sq. m; ng per m2; m^2; sq. meter; nanograms; meter squared; metre","LOINC","ArMass","Clinical","unit used to measure mass dose per patient body surface area",null,null,null,null,false],[false,"nanogram per milligram","ng/mg","NG/MG","mass",0.000001,[0,0,0,0,0,0,0],"ng/mg",null,false,"M",null,1,false,false,0,"ng per mg; nanograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"nanogram per milligram per hour","ng/mg/h","(NG/MG)/HR","mass",2.7777777777777777e-10,[0,-1,0,0,0,0,0],"(ng/mg)/h",null,false,"M",null,1,false,false,0,"ng/mg/hr; ng per mg per hr; nanograms per milligrams per hour","LOINC","MRtoRat ","Clinical","",null,null,null,null,false],[false,"nanogram per minute","ng/min","NG/MIN","mass",1.6666666666666667e-11,[0,-1,1,0,0,0,0],"ng/min",null,false,"M",null,1,false,false,0,"ng per min; nanograms","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per millliiter","ng/mL","NG/ML","mass",0.001,[-3,0,1,0,0,0,0],"ng/mL",null,false,"M",null,1,false,false,0,"ng per mL; nanograms; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"nanogram per milliliter per hour","ng/mL/h","(NG/ML)/HR","mass",2.7777777777777776e-7,[-3,-1,1,0,0,0,0],"(ng/mL)/h",null,false,"M",null,1,false,false,0,"ng/mL/hr; ng per mL per mL; nanograms per milliliter per hour; nanogram per millilitre per hour; nanograms per millilitre per hour; enzymatic activity per volume; enzyme activity per milliliters","LOINC","CCnc","Clinical","tests that measure enzymatic activity",null,null,null,null,false],[false,"nanogram per second","ng/s","NG/S","mass",1e-9,[0,-1,1,0,0,0,0],"ng/s",null,false,"M",null,1,false,false,0,"ng/sec; ng per sec; nanograms per second","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"nanogram per enzyme unit","ng/U","NG/U","mass",9.963241120049634e-26,[0,1,1,0,0,0,0],"ng/U",null,false,"M",null,1,false,false,-1,"ng per U; nanograms per enzyme unit","LOINC","CMass","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)",null,null,null,null,false],[false,"nanokatal","nkat","NKAT","catalytic activity",602213670000000,[0,-1,0,0,0,0,0],"nkat","chemical",true,null,null,1,false,false,1,"nanokatals","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"nanoliter","nL","NL","volume",1.0000000000000002e-12,[3,0,0,0,0,0,0],"nL","iso1000",true,null,null,1,false,false,0,"nanoliters; nanolitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"nanometer","nm","NM","length",1e-9,[1,0,0,0,0,0,0],"nm",null,false,"L",null,1,false,false,0,"nanometers; nanometres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"nanometer per second per liter","nm/s/L","(NM/S)/L","length",0.000001,[-2,-1,0,0,0,0,0],"(nm/s)/L",null,false,"L",null,1,false,false,0,"nm/sec/liter; nm/sec/litre; nm per s per l; nm per sec per l; nanometers per second per liter; nanometre per second per litre; nanometres per second per litre","LOINC","VelCnc","Clinical","",null,null,null,null,false],[false,"nanomole","nmol","NMOL","amount of substance",602213670000000,[0,0,0,0,0,0,0],"nmol","si",true,null,null,1,false,false,1,"nanomoles","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per 24 hour","nmol/(24.h)","NMOL/HR","amount of substance",6970065625,[0,-1,0,0,0,0,0],"nmol/h","si",true,null,null,1,false,false,1,"nmol/24hr; nmol/24 hr; nanomoles per 24 hours; nmol/day; nanomoles per day; nmol per day; nanomole/day; nanomol/day","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per day","nmol/d","NMOL/D","amount of substance",6970065625,[0,-1,0,0,0,0,0],"nmol/d","si",true,null,null,1,false,false,1,"nmol/day; nanomoles per day; nmol per day; nanomole/day; nanomol/day; nmol/24hr; nmol/24 hr; nanomoles per 24 hours; ","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per deciliter","nmol/dL","NMOL/DL","amount of substance",6022136700000000000,[-3,0,0,0,0,0,0],"nmol/dL","si",true,null,null,1,false,false,1,"nmol per dL; nanomoles per deciliter; nanomole per decilitre; nanomoles per decilitre; nanomole/deciliter; nanomole/decilitre; nanomol/deciliter; nanomol/decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per gram","nmol/g","NMOL/G","amount of substance",602213670000000,[0,0,-1,0,0,0,0],"nmol/g","si",true,null,null,1,false,false,1,"nmol per gram; nanomoles per gram; nanomole/gram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per hour per liter","nmol/h/L","(NMOL/HR)/L","amount of substance",167281575000000,[-3,-1,0,0,0,0,0],"(nmol/h)/L","si",true,null,null,1,false,false,1,"nmol/hrs/L; nmol per hrs per L; nanomoles per hours per liter; litre; enzymatic activity per volume; enzyme activities","LOINC","CCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per liter","nmol/L","NMOL/L","amount of substance",602213670000000000,[-3,0,0,0,0,0,0],"nmol/L","si",true,null,null,1,false,false,1,"nmol per L; nanomoles per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram","nmol/mg","NMOL/MG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"nmol/mg","si",true,null,null,1,false,false,1,"nmol per mg; nanomoles per milligram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram per hour","nmol/mg/h","(NMOL/MG)/HR","amount of substance",167281575000000,[0,-1,-1,0,0,0,0],"(nmol/mg)/h","si",true,null,null,1,false,false,1,"nmol/mg/hr; nmol per mg per hr; nanomoles per milligrams per hour","LOINC","SCntRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milligram of protein","nmol/mg{prot}","NMOL/MG","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"nmol/mg","si",true,null,null,1,false,false,1,"nanomoles; nmol/mg prot; nmol per mg prot","LOINC","Ratio; CCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per minute","nmol/min","NMOL/MIN","amount of substance",10036894500000,[0,-1,0,0,0,0,0],"nmol/min","si",true,null,null,1,false,false,1,"nmol per min; nanomoles per minute; milli enzyme units; enzyme activity per volume; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/min = mU (milli enzyme unit)","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per minute per milliliter","nmol/min/mL","(NMOL/MIN)/ML","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(nmol/min)/mL","si",true,null,null,1,false,false,1,"nmol per min per mL; nanomoles per minutes per milliliter; millilitre; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/mL/min = mU/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter","nmol/mL","NMOL/ML","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"nmol/mL","si",true,null,null,1,false,false,1,"nmol per mL; nanomoles per milliliter; millilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter per hour","nmol/mL/h","(NMOL/ML)/HR","amount of substance",167281575000000000,[-3,-1,0,0,0,0,0],"(nmol/mL)/h","si",true,null,null,1,false,false,1,"nmol/mL/hr; nmol per mL per hr; nanomoles per milliliters per hour; millilitres; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per milliliter per minute","nmol/mL/min","(NMOL/ML)/MIN","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(nmol/mL)/min","si",true,null,null,1,false,false,1,"nmol per mL per min; nanomoles per milliliters per min; millilitres; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. nmol/mL/min = mU/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per millimole","nmol/mmol","NMOL/MMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"nmol/mmol","si",true,null,null,1,false,false,0,"nmol per mmol; nanomoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per millimole of creatinine","nmol/mmol{creat}","NMOL/MMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"nmol/mmol","si",true,null,null,1,false,false,0,"nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per mole","nmol/mol","NMOL/MOL","amount of substance",1e-9,[0,0,0,0,0,0,0],"nmol/mol","si",true,null,null,1,false,false,0,"nmol per mole; nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per nanomole","nmol/nmol","NMOL/NMOL","amount of substance",1,[0,0,0,0,0,0,0],"nmol/nmol","si",true,null,null,1,false,false,0,"nmol per nmol; nanomoles","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per second","nmol/s","NMOL/S","amount of substance",602213670000000,[0,-1,0,0,0,0,0],"nmol/s","si",true,null,null,1,false,false,1,"nmol/sec; nmol per sec; nanomoles per sercond; milli enzyme units; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanomole per second per liter","nmol/s/L","(NMOL/S)/L","amount of substance",602213670000000000,[-3,-1,0,0,0,0,0],"(nmol/s)/L","si",true,null,null,1,false,false,1,"nmol/sec/L; nmol per s per L; nmol per sec per L; nanomoles per seconds per liter; litre; milli enzyme units per volume; enzyme activity; enzymatic activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min.","10*23","10*23","6.0221367",6.0221367,false],[false,"nanosecond","ns","NS","time",1e-9,[0,1,0,0,0,0,0],"ns",null,false,"T",null,1,false,false,0,"nanoseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"nanoenzyme unit per milliliter","nU/mL","NU/ML","catalytic activity",10036894500000,[-3,-1,0,0,0,0,0],"nU/mL","chemical",true,null,null,1,false,false,1,"nU per mL; nanoenzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 fU = pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"Ohm meter","Ohm.m","OHM.M","electric resistance",1000,[3,-1,1,0,0,-2,0],"Ω.m","si",true,null,null,1,false,false,0,"electric resistivity; meters; metres","LOINC","","Clinical","unit of electric resistivity","V/A","V/A","1",1,false],[false,"osmole per kilogram","osm/kg","OSM/KG","amount of substance (dissolved particles)",602213670000000000000,[0,0,-1,0,0,0,0],"osm/kg","chemical",true,null,null,1,false,false,1,"osm per kg; osmoles per kilogram; osmols","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"osmole per liter","osm/L","OSM/L","amount of substance (dissolved particles)",6.0221366999999994e+26,[-3,0,0,0,0,0,0],"osm/L","chemical",true,null,null,1,false,false,1,"osm per L; osmoles per liter; litre; osmols","LOINC","Osmol","Clinical","","mol","MOL","1",1,false],[false,"picoampere","pA","PA","electric current",1e-12,[0,-1,0,0,0,1,0],"pA","si",true,null,null,1,false,false,0,"picoamperes","LOINC","","Clinical","equal to 10^-12 amperes","C/s","C/S","1",1,false],[false,"picogram","pg","PG","mass",1e-12,[0,0,1,0,0,0,0],"pg",null,false,"M",null,1,false,false,0,"picograms","LOINC","Mass; EntMass","Clinical","",null,null,null,null,false],[false,"picogram per deciliter","pg/dL","PG/DL","mass",9.999999999999999e-9,[-3,0,1,0,0,0,0],"pg/dL",null,false,"M",null,1,false,false,0,"pg per dL; picograms; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per liter","pg/L","PG/L","mass",1e-9,[-3,0,1,0,0,0,0],"pg/L",null,false,"M",null,1,false,false,0,"pg per L; picograms; litre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per milligram","pg/mg","PG/MG","mass",1e-9,[0,0,0,0,0,0,0],"pg/mg",null,false,"M",null,1,false,false,0,"pg per mg; picograms","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"picogram per milliliter","pg/mL","PG/ML","mass",0.000001,[-3,0,1,0,0,0,0],"pg/mL",null,false,"M",null,1,false,false,0,"pg per mL; picograms per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"picogram per millimeter","pg/mm","PG/MM","mass",1e-9,[-1,0,1,0,0,0,0],"pg/mm",null,false,"M",null,1,false,false,0,"pg per mm; picogram/millimeter; picogram/millimetre; picograms per millimeter; millimetre","LOINC","Lineic Mass","Clinical","",null,null,null,null,false],[false,"picokatal","pkat","PKAT","catalytic activity",602213670000,[0,-1,0,0,0,0,0],"pkat","chemical",true,null,null,1,false,false,1,"pkats; picokatals","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"picoliter","pL","PL","volume",1e-15,[3,0,0,0,0,0,0],"pL","iso1000",true,null,null,1,false,false,0,"picoliters; picolitres","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"picometer","pm","PM","length",1e-12,[1,0,0,0,0,0,0],"pm",null,false,"L",null,1,false,false,0,"picometers; picometres","LOINC","Len","Clinical","",null,null,null,null,false],[false,"picomole","pmol","PMOL","amount of substance",602213670000,[0,0,0,0,0,0,0],"pmol","si",true,null,null,1,false,false,1,"picomoles; pmols","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per 24 hour","pmol/(24.h)","PMOL/HR","amount of substance",6970065.625,[0,-1,0,0,0,0,0],"pmol/h","si",true,null,null,1,false,false,1,"pmol/24hrs; pmol/24 hrs; pmol per 24 hrs; 24hrs; days; dy; picomoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per day","pmol/d","PMOL/D","amount of substance",6970065.625,[0,-1,0,0,0,0,0],"pmol/d","si",true,null,null,1,false,false,1,"pmol/dy; pmol per day; 24 hours; 24hrs; 24 hrs; picomoles","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per deciliter","pmol/dL","PMOL/DL","amount of substance",6022136700000000,[-3,0,0,0,0,0,0],"pmol/dL","si",true,null,null,1,false,false,1,"pmol per dL; picomoles per deciliter; decilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per gram","pmol/g","PMOL/G","amount of substance",602213670000,[0,0,-1,0,0,0,0],"pmol/g","si",true,null,null,1,false,false,1,"pmol per gm; picomoles per gram; picomole/gram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per hour per milliliter ","pmol/h/mL","(PMOL/HR)/ML","amount of substance",167281575000000,[-3,-1,0,0,0,0,0],"(pmol/h)/mL","si",true,null,null,1,false,false,1,"pmol/hrs/mL; pmol per hrs per mL; picomoles per hour per milliliter; millilitre; micro enzyme units per volume; enzymatic activity; enzyme activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. ","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per liter","pmol/L","PMOL/L","amount of substance",602213670000000,[-3,0,0,0,0,0,0],"pmol/L","si",true,null,null,1,false,false,1,"picomole/liter; pmol per L; picomoles; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per minute","pmol/min","PMOL/MIN","amount of substance",10036894500,[0,-1,0,0,0,0,0],"pmol/min","si",true,null,null,1,false,false,1,"picomole/minute; pmol per min; picomoles per minute; micro enzyme units; enzymatic activity; enzyme activity","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. pmol/min = uU (micro enzyme unit)","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per milliliter","pmol/mL","PMOL/ML","amount of substance",602213670000000000,[-3,0,0,0,0,0,0],"pmol/mL","si",true,null,null,1,false,false,1,"picomole/milliliter; picomole/millilitre; pmol per mL; picomoles; millilitre; picomols; pmols","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picomole per micromole","pmol/umol","PMOL/UMOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"pmol/μmol","si",true,null,null,1,false,false,0,"pmol/mcgmol; picomole/micromole; pmol per umol; pmol per mcgmol; picomoles ","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"picosecond","ps","PS","time",1e-12,[0,1,0,0,0,0,0],"ps",null,false,"T",null,1,false,false,0,"picoseconds; psec","LOINC","Time","Clinical","",null,null,null,null,false],[false,"picotesla","pT","PT","magnetic flux density",1e-9,[0,-1,1,0,0,-1,0],"pT","si",true,null,null,1,false,false,0,"picoteslas","LOINC","","Clinical","SI unit of magnetic field strength for magnetic field B","Wb/m2","WB/M2","1",1,false],[false,"enzyme unit per 12 hour","U/(12.h)","U/HR","catalytic activity",232335520833.33334,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/12hrs; U/ 12hrs; U per 12 hrs; 12hrs; enzyme units per 12 hours; enzyme activity; enzymatic activity per time; umol per min per 12 hours; micromoles per minute per 12 hours; umol/min/12hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 2 hour","U/(2.h)","U/HR","catalytic activity",1394013125000,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/2hrs; U/ 2hrs; U per 2 hrs; 2hrs; enzyme units per 2 hours; enzyme activity; enzymatic activity per time; umol per minute per 2 hours; micromoles per minute; umol/min/2hr; umol per min per 2hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 24 hour","U/(24.h)","U/HR","catalytic activity",116167760416.66667,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/24hrs; U/ 24hrs; U per 24 hrs; 24hrs; enzyme units per 24 hours; enzyme activity; enzymatic activity per time; micromoles per minute per 24 hours; umol/min/24hr; umol per min per 24hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 10","U/10","U","catalytic activity",1003689450000000,[0,-1,0,0,0,0,0],"U","chemical",true,null,null,1,false,false,1,"enzyme unit/10; U per 10; enzyme units per 10; enzymatic activity; enzyme activity; micromoles per minute; umol/min/10","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per 10 billion","U/10*10","U/(10*10)","catalytic activity",1003689.45,[0,-1,0,0,0,0,0],"U/(1010)","chemical",true,null,null,1,false,false,1,"U per 10*10; enzyme units per 10*10; U per 10 billion; enzyme units; enzymatic activity; micromoles per minute per 10 billion; umol/min/10*10","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per trillion","U/10*12","U/(10*12)","catalytic activity",10036.8945,[0,-1,0,0,0,0,0],"U/(1012)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*12; U per 10*12; enzyme units per 10*12; enzyme units per trillion; enzymatic activity; micromoles per minute per trillion; umol/min/10*12; umol per min per 10*12","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per million","U/10*6","U/(10*6)","catalytic activity",10036894500,[0,-1,0,0,0,0,0],"U/(106)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*6; U per 10*6; enzyme units per 10*6; enzyme units; enzymatic activity per volume; micromoles per minute per million; umol/min/10*6; umol per min per 10*6","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per billion","U/10*9","U/(10*9)","catalytic activity",10036894.5,[0,-1,0,0,0,0,0],"U/(109)","chemical",true,null,null,1,false,false,1,"enzyme unit/10*9; U per 10*9; enzyme units per 10*9; enzymatic activity per volume; micromoles per minute per billion; umol/min/10*9; umol per min per 10*9","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per day","U/d","U/D","catalytic activity",116167760416.66667,[0,-2,0,0,0,0,0],"U/d","chemical",true,null,null,1,false,false,1,"U/dy; enzyme units per day; enzyme units; enzyme activity; enzymatic activity per time; micromoles per minute per day; umol/min/day; umol per min per day","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per deciliter","U/dL","U/DL","catalytic activity",100368945000000000000,[-3,-1,0,0,0,0,0],"U/dL","chemical",true,null,null,1,false,false,1,"U per dL; enzyme units per deciliter; decilitre; micromoles per minute per deciliter; umol/min/dL; umol per min per dL","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per gram","U/g","U/G","catalytic activity",10036894500000000,[0,-1,-1,0,0,0,0],"U/g","chemical",true,null,null,1,false,false,1,"U/gm; U per gm; enzyme units per gram; micromoles per minute per gram; umol/min/g; umol per min per g","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per hour","U/h","U/HR","catalytic activity",2788026250000,[0,-2,0,0,0,0,0],"U/h","chemical",true,null,null,1,false,false,1,"U/hr; U per hr; enzyme units per hour; micromoles per minute per hour; umol/min/hr; umol per min per hr","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per liter","U/L","U/L","catalytic activity",10036894500000000000,[-3,-1,0,0,0,0,0],"U/L","chemical",true,null,null,1,false,false,1,"enzyme unit/liter; enzyme unit/litre; U per L; enzyme units per liter; enzyme unit per litre; micromoles per minute per liter; umol/min/L; umol per min per L","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per minute","U/min","U/MIN","catalytic activity",167281575000000,[0,-2,0,0,0,0,0],"U/min","chemical",true,null,null,1,false,false,1,"enzyme unit/minute; U per min; enzyme units; umol/min/min; micromoles per minute per minute; micromoles per min per min; umol","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per milliliter","U/mL","U/ML","catalytic activity",1.00368945e+22,[-3,-1,0,0,0,0,0],"U/mL","chemical",true,null,null,1,false,false,1,"U per mL; enzyme units per milliliter; millilitre; micromoles per minute per milliliter; umol/min/mL; umol per min per mL","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"enzyme unit per second","U/s","U/S","catalytic activity",10036894500000000,[0,-2,0,0,0,0,0],"U/s","chemical",true,null,null,1,false,false,1,"U/sec; U per second; enzyme units per second; micromoles per minute per second; umol/min/sec; umol per min per sec","LOINC","CRat","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min)","umol/min","UMOL/MIN","1",1,false],[false,"micro international unit","u[IU]","U[IU]","arbitrary",0.000001,[0,0,0,0,0,0,0],"μi.U.","chemical",true,null,null,1,false,true,0,"uIU; u IU; microinternational units","LOINC","Arb","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"micro international unit per liter","u[IU]/L","U[IU]/L","arbitrary",0.001,[-3,0,0,0,0,0,0],"(μi.U.)/L","chemical",true,null,null,1,false,true,0,"uIU/L; u IU/L; uIU per L; microinternational units per liter; litre; ","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"micro international unit per milliliter","u[IU]/mL","U[IU]/ML","arbitrary",1,[-3,0,0,0,0,0,0],"(μi.U.)/mL","chemical",true,null,null,1,false,true,0,"uIU/mL; u IU/mL; uIU per mL; microinternational units per milliliter; millilitre","LOINC","ACnc","Clinical","International units (IU) are analyte and reference specimen specific arbitrary units (held at WHO)","[iU]","[IU]","1",1,false],[false,"microequivalent","ueq","UEQ","amount of substance",602213670000000000,[0,0,0,0,0,0,0],"μeq","chemical",true,null,null,1,false,false,1,"microequivalents; 10^-6 equivalents; 10-6 equivalents","LOINC","Sub","Clinical","","mol","MOL","1",1,false],[false,"microequivalent per liter","ueq/L","UEQ/L","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"μeq/L","chemical",true,null,null,1,false,false,1,"ueq per liter; litre; microequivalents","LOINC","MCnc","Clinical","","mol","MOL","1",1,false],[false,"microequivalent per milliliter","ueq/mL","UEQ/ML","amount of substance",6.0221367000000003e+23,[-3,0,0,0,0,0,0],"μeq/mL","chemical",true,null,null,1,false,false,1,"ueq per milliliter; millilitre; microequivalents","LOINC","MCnc","Clinical","","mol","MOL","1",1,false],[false,"microgram","ug","UG","mass",0.000001,[0,0,1,0,0,0,0],"μg",null,false,"M",null,1,false,false,0,"mcg; micrograms; 10^-6 grams; 10-6 grams","LOINC","Mass","Clinical","",null,null,null,null,false],[false,"microgram per 100 gram","ug/(100.g)","UG/G","mass",1e-8,[0,0,0,0,0,0,0],"μg/g",null,false,"M",null,1,false,false,0,"ug/100gm; ug/100 gm; mcg; ug per 100g; 100 gm; mcg per 100g; micrograms per 100 grams","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per 24 hour","ug/(24.h)","UG/HR","mass",1.1574074074074074e-11,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/24hrs; ug/24 hrs; mcg/24hrs; ug per 24hrs; mcg per 24hrs; 24 hrs; micrograms per 24 hours","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per 8 hour","ug/(8.h)","UG/HR","mass",3.472222222222222e-11,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/8hrs; ug/8 hrs; mcg/8hrs; ug per 8hrs; mcg per 8hrs; 8 hrs; micrograms per 8 hours; shift","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per square foot (international)","ug/[sft_i]","UG/[SFT_I]","mass",0.000010763910416709721,[-2,0,1,0,0,0,0],"μg",null,false,"M",null,1,false,false,0,"ug/sft; ug/ft2; ug/ft^2; ug/sq. ft; micrograms; sq. foot; foot squared","LOINC","ArMass","Clinical","",null,null,null,null,false],[false,"microgram per day","ug/d","UG/D","mass",1.1574074074074074e-11,[0,-1,1,0,0,0,0],"μg/d",null,false,"M",null,1,false,false,0,"ug/dy; mcg/dy; ug per day; mcg; micrograms per day","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per deciliter","ug/dL","UG/DL","mass",0.009999999999999998,[-3,0,1,0,0,0,0],"μg/dL",null,false,"M",null,1,false,false,0,"ug per dL; mcg/dl; mcg per dl; micrograms per deciliter; decilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per gram","ug/g","UG/G","mass",0.000001,[0,0,0,0,0,0,0],"μg/g",null,false,"M",null,1,false,false,0,"ug per gm; mcg/gm; mcg per g; micrograms per gram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per hour","ug/h","UG/HR","mass",2.7777777777777777e-10,[0,-1,1,0,0,0,0],"μg/h",null,false,"M",null,1,false,false,0,"ug/hr; mcg/hr; mcg per hr; ug per hr; ug per hour; micrograms","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per kilogram","ug/kg","UG/KG","mass",9.999999999999999e-10,[0,0,0,0,0,0,0],"μg/kg",null,false,"M",null,1,false,false,0,"ug per kg; mcg/kg; mcg per kg; micrograms per kilogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per kilogram per 8 hour","ug/kg/(8.h)","(UG/KG)/HR","mass",3.472222222222222e-14,[0,-1,0,0,0,0,0],"(μg/kg)/h",null,false,"M",null,1,false,false,0,"ug/kg/8hrs; mcg/kg/8hrs; ug/kg/8 hrs; mcg/kg/8 hrs; ug per kg per 8hrs; 8 hrs; mcg per kg per 8hrs; micrograms per kilograms per 8 hours; shift","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per day","ug/kg/d","(UG/KG)/D","mass",1.1574074074074072e-14,[0,-1,0,0,0,0,0],"(μg/kg)/d",null,false,"M",null,1,false,false,0,"ug/(kg.d); ug/kg/dy; mcg/kg/day; ug per kg per dy; 24 hours; 24hrs; mcg; kilograms; microgram per kilogram and day","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per hour","ug/kg/h","(UG/KG)/HR","mass",2.7777777777777774e-13,[0,-1,0,0,0,0,0],"(μg/kg)/h",null,false,"M",null,1,false,false,0,"ug/(kg.h); ug/kg/hr; mcg/kg/hr; ug per kg per hr; mcg per kg per hr; kilograms","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per kilogram per minute","ug/kg/min","(UG/KG)/MIN","mass",1.6666666666666664e-11,[0,-1,0,0,0,0,0],"(μg/kg)/min",null,false,"M",null,1,false,false,0,"ug/kg/min; ug/kg/min; mcg/kg/min; ug per kg per min; mcg; micrograms per kilograms per minute ","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per liter","ug/L","UG/L","mass",0.001,[-3,0,1,0,0,0,0],"μg/L",null,false,"M",null,1,false,false,0,"mcg/L; ug per L; mcg; micrograms per liter; litre ","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per liter per 24 hour","ug/L/(24.h)","(UG/L)/HR","mass",1.1574074074074074e-8,[-3,-1,1,0,0,0,0],"(μg/L)/h",null,false,"M",null,1,false,false,0,"ug/L/24hrs; ug/L/24 hrs; mcg/L/24hrs; ug per L per 24hrs; 24 hrs; day; dy mcg; micrograms per liters per 24 hours; litres","LOINC","","Clinical","unit used to measure mass dose rate per patient body mass",null,null,null,null,false],[false,"microgram per square meter","ug/m2","UG/M2","mass",0.000001,[-2,0,1,0,0,0,0],"μg/(m2)",null,false,"M",null,1,false,false,0,"ug/m^2; ug/sq. m; mcg/m2; mcg/m^2; mcg/sq. m; ug per m2; m^2; sq. meter; mcg; micrograms per square meter; meter squared; metre","LOINC","ArMass","Clinical","unit used to measure mass dose per patient body surface area",null,null,null,null,false],[false,"microgram per cubic meter","ug/m3","UG/M3","mass",0.000001,[-3,0,1,0,0,0,0],"μg/(m3)",null,false,"M",null,1,false,false,0,"ug/m^3; ug/cu. m; mcg/m3; mcg/m^3; mcg/cu. m; ug per m3; ug per m^3; ug per cu. m; mcg; micrograms per cubic meter; meter cubed; metre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per milligram","ug/mg","UG/MG","mass",0.001,[0,0,0,0,0,0,0],"μg/mg",null,false,"M",null,1,false,false,0,"ug per mg; mcg/mg; mcg per mg; micromilligrams per milligram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microgram per minute","ug/min","UG/MIN","mass",1.6666666666666667e-8,[0,-1,1,0,0,0,0],"μg/min",null,false,"M",null,1,false,false,0,"ug per min; mcg/min; mcg per min; microminutes per minute","LOINC","MRat","Clinical","",null,null,null,null,false],[false,"microgram per milliliter","ug/mL","UG/ML","mass",1,[-3,0,1,0,0,0,0],"μg/mL",null,false,"M",null,1,false,false,0,"ug per mL; mcg/mL; mcg per mL; micrograms per milliliter; millilitre","LOINC","MCnc","Clinical","",null,null,null,null,false],[false,"microgram per millimole","ug/mmol","UG/MMOL","mass",1.660540186674939e-27,[0,0,1,0,0,0,0],"μg/mmol",null,false,"M",null,1,false,false,-1,"ug per mmol; mcg/mmol; mcg per mmol; micrograms per millimole","LOINC","Ratio","Clinical","",null,null,null,null,false],[false,"microgram per nanogram","ug/ng","UG/NG","mass",999.9999999999999,[0,0,0,0,0,0,0],"μg/ng",null,false,"M",null,1,false,false,0,"ug per ng; mcg/ng; mcg per ng; micrograms per nanogram","LOINC","MCnt","Clinical","",null,null,null,null,false],[false,"microkatal","ukat","UKAT","catalytic activity",602213670000000000,[0,-1,0,0,0,0,0],"μkat","chemical",true,null,null,1,false,false,1,"microkatals; ukats","LOINC","CAct","Clinical","kat is a unit of catalytic activity with base units = mol/s. Rarely used because its units are too large to practically express catalytic activity. See enzyme unit [U] which is the standard unit for catalytic activity.","mol/s","MOL/S","1",1,false],[false,"microliter","uL","UL","volume",1e-9,[3,0,0,0,0,0,0],"μL","iso1000",true,null,null,1,false,false,0,"microliters; microlitres; mcl","LOINC","Vol","Clinical","","l",null,"1",1,false],[false,"microliter per 2 hour","uL/(2.h)","UL/HR","volume",1.388888888888889e-13,[3,-1,0,0,0,0,0],"μL/h","iso1000",true,null,null,1,false,false,0,"uL/2hrs; uL/2 hrs; mcg/2hr; mcg per 2hr; uL per 2hr; uL per 2 hrs; microliters per 2 hours; microlitres ","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"microliter per hour","uL/h","UL/HR","volume",2.777777777777778e-13,[3,-1,0,0,0,0,0],"μL/h","iso1000",true,null,null,1,false,false,0,"uL/hr; mcg/hr; mcg per hr; uL per hr; microliters per hour; microlitres","LOINC","VRat","Clinical","","l",null,"1",1,false],[false,"micrometer","um","UM","length",0.000001,[1,0,0,0,0,0,0],"μm",null,false,"L",null,1,false,false,0,"micrometers; micrometres; μm; microns","LOINC","Len","Clinical","Unit of length that is usually used in tests related to the eye",null,null,null,null,false],[false,"microns per second","um/s","UM/S","length",0.000001,[1,-1,0,0,0,0,0],"μm/s",null,false,"L",null,1,false,false,0,"um/sec; micron/second; microns/second; um per sec; micrometers per second; micrometres","LOINC","Vel","Clinical","",null,null,null,null,false],[false,"micromole","umol","UMOL","amount of substance",602213670000000000,[0,0,0,0,0,0,0],"μmol","si",true,null,null,1,false,false,1,"micromoles; umols","LOINC","Sub","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 2 hour","umol/(2.h)","UMOL/HR","amount of substance",83640787500000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/2hrs; umol/2 hrs; umol per 2 hrs; 2hrs; micromoles per 2 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 24 hour","umol/(24.h)","UMOL/HR","amount of substance",6970065625000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/24hrs; umol/24 hrs; umol per 24 hrs; per 24hrs; micromoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per 8 hour","umol/(8.h)","UMOL/HR","amount of substance",20910196875000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/8hr; umol/8 hr; umol per 8 hr; umol per 8hr; umols per 8hr; umol per 8 hours; micromoles per 8 hours; shift","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per day","umol/d","UMOL/D","amount of substance",6970065625000,[0,-1,0,0,0,0,0],"μmol/d","si",true,null,null,1,false,false,1,"umol/day; umol per day; umols per day; umol per days; micromoles per days; umol/24hr; umol/24 hr; umol per 24 hr; umol per 24hr; umols per 24hr; umol per 24 hours; micromoles per 24 hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per deciliter","umol/dL","UMOL/DL","amount of substance",6.0221367e+21,[-3,0,0,0,0,0,0],"μmol/dL","si",true,null,null,1,false,false,1,"micromole/deciliter; micromole/decilitre; umol per dL; micromoles per deciliters; micromole per decilitres","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per gram","umol/g","UMOL/G","amount of substance",602213670000000000,[0,0,-1,0,0,0,0],"μmol/g","si",true,null,null,1,false,false,1,"micromole/gram; umol per g; micromoles per gram","LOINC","SCnt; Ratio","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per hour","umol/h","UMOL/HR","amount of substance",167281575000000,[0,-1,0,0,0,0,0],"μmol/h","si",true,null,null,1,false,false,1,"umol/hr; umol per hr; umol per hour; micromoles per hours","LOINC","SRat","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per kilogram","umol/kg","UMOL/KG","amount of substance",602213670000000,[0,0,-1,0,0,0,0],"μmol/kg","si",true,null,null,1,false,false,1,"umol per kg; micromoles per kilogram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per liter","umol/L","UMOL/L","amount of substance",602213670000000000000,[-3,0,0,0,0,0,0],"μmol/L","si",true,null,null,1,false,false,1,"micromole/liter; micromole/litre; umol per liter; micromoles per liter; litre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per liter per hour","umol/L/h","(UMOL/L)/HR","amount of substance",167281575000000000,[-3,-1,0,0,0,0,0],"(μmol/L)/h","si",true,null,null,1,false,false,1,"umol/liter/hr; umol/litre/hr; umol per L per hr; umol per liter per hour; micromoles per liters per hour; litre","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min; umol/L/h is a derived unit of enzyme units","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milligram","umol/mg","UMOL/MG","amount of substance",602213670000000000000,[0,0,-1,0,0,0,0],"μmol/mg","si",true,null,null,1,false,false,1,"micromole/milligram; umol per mg; micromoles per milligram","LOINC","SCnt","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute","umol/min","UMOL/MIN","amount of substance",10036894500000000,[0,-1,0,0,0,0,0],"μmol/min","si",true,null,null,1,false,false,1,"micromole/minute; umol per min; micromoles per minute; enzyme units","LOINC","CAct","Clinical","unit for the enzyme unit U = umol/min","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute per gram","umol/min/g","(UMOL/MIN)/G","amount of substance",10036894500000000,[0,-1,-1,0,0,0,0],"(μmol/min)/g","si",true,null,null,1,false,false,1,"umol/min/gm; umol per min per gm; micromoles per minutes per gram; U/g; enzyme units","LOINC","CCnt","Clinical","unit for the enzyme unit U = umol/min. umol/min/g = U/g","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per minute per liter","umol/min/L","(UMOL/MIN)/L","amount of substance",10036894500000000000,[-3,-1,0,0,0,0,0],"(μmol/min)/L","si",true,null,null,1,false,false,1,"umol/min/liter; umol/minute/liter; micromoles per minutes per liter; litre; enzyme units; U/L","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. umol/min/L = U/L","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milliliter","umol/mL","UMOL/ML","amount of substance",6.0221367000000003e+23,[-3,0,0,0,0,0,0],"μmol/mL","si",true,null,null,1,false,false,1,"umol per mL; micromoles per milliliter; millilitre","LOINC","SCnc","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per milliliter per minute","umol/mL/min","(UMOL/ML)/MIN","amount of substance",1.00368945e+22,[-3,-1,0,0,0,0,0],"(μmol/mL)/min","si",true,null,null,1,false,false,1,"umol per mL per min; micromoles per milliliters per minute; millilitres","LOINC","CCnc","Clinical","unit for the enzyme unit U = umol/min. umol/mL/min = U/mL","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per millimole","umol/mmol","UMOL/MMOL","amount of substance",0.001,[0,0,0,0,0,0,0],"μmol/mmol","si",true,null,null,1,false,false,0,"umol per mmol; micromoles per millimole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per mole","umol/mol","UMOL/MOL","amount of substance",0.000001,[0,0,0,0,0,0,0],"μmol/mol","si",true,null,null,1,false,false,0,"umol per mol; micromoles per mole","LOINC","SRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"micromole per micromole","umol/umol","UMOL/UMOL","amount of substance",1,[0,0,0,0,0,0,0],"μmol/μmol","si",true,null,null,1,false,false,0,"umol per umol; micromoles per micromole","LOINC","Srto; SFr; EntSRto","Clinical","","10*23","10*23","6.0221367",6.0221367,false],[false,"microOhm","uOhm","UOHM","electric resistance",0.001,[2,-1,1,0,0,-2,0],"μΩ","si",true,null,null,1,false,false,0,"microOhms; µΩ","LOINC","","Clinical","unit of electric resistance","V/A","V/A","1",1,false],[false,"microsecond","us","US","time",0.000001,[0,1,0,0,0,0,0],"μs",null,false,"T",null,1,false,false,0,"microseconds","LOINC","Time","Clinical","",null,null,null,null,false],[false,"micro enzyme unit per gram","uU/g","UU/G","catalytic activity",10036894500,[0,-1,-1,0,0,0,0],"μU/g","chemical",true,null,null,1,false,false,1,"uU per gm; micro enzyme units per gram; micro enzymatic activity per mass; enzyme activity","LOINC","CCnt","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"micro enzyme unit per liter","uU/L","UU/L","catalytic activity",10036894500000,[-3,-1,0,0,0,0,0],"μU/L","chemical",true,null,null,1,false,false,1,"uU per L; micro enzyme units per liter; litre; enzymatic activity per volume; enzyme activity ","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"micro enzyme unit per milliliter","uU/mL","UU/ML","catalytic activity",10036894500000000,[-3,-1,0,0,0,0,0],"μU/mL","chemical",true,null,null,1,false,false,1,"uU per mL; micro enzyme units per milliliter; millilitre; enzymatic activity per volume; enzyme activity","LOINC","CCnc","Clinical","1 U is the standard enzyme unit which equals 1 micromole substrate catalyzed per minute (1 umol/min); 1 uU = 1pmol/min","umol/min","UMOL/MIN","1",1,false],[false,"microvolt","uV","UV","electric potential",0.001,[2,-2,1,0,0,-1,0],"μV","si",true,null,null,1,false,false,0,"microvolts","LOINC","Elpot","Clinical","unit of electric potential (voltage)","J/C","J/C","1",1,false]]}} -},{"./builder":67,"./expression":73}],90:[function(require,module,exports){ +},{}],94:[function(require,module,exports){ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ReplaceMatches = exports.EndsWith = exports.StartsWith = exports.Substring = exports.Matches = exports.LastPositionOf = exports.PositionOf = exports.Lower = exports.Upper = exports.SplitOnMatches = exports.Split = exports.Combine = exports.Concatenate = void 0; -var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var Concatenate = /** @class */ (function (_super) { - __extends(Concatenate, _super); - function Concatenate(json) { - return _super.call(this, json) || this; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Ucum = void 0; + +/* + * This defines the namespace for the UCUM classes and provides + * a place for the definition of global variables and constants. + * + * The javascript for this UCUM implementation uses syntax as + * defined by the ECMAScript 6 standard + */ +var Ucum = { + /** + * Flag indicating whether or not we're using case sensitive labels + * I don't think we need this. I think we're just going with + * case sensitive, per Clem. Gunther's code has this flag, but I + * am removing it, at least for now. lm, 6/2016 + */ + //caseSensitive_: true , + + /** + * The number of elements in a Dimension array. Currently this + * is set as a configuration variable, but when we get to the point + * of loading the unit definitions from a file, this value will be + * set from that. + */ + dimLen_: 7, + + /** + * The characters used as valid operators in a UCUM unit expression, + * where '.' is for multiplication and '/' is for division. + */ + validOps_: ['.', '/'], + + /** + * The string used to separate a unit code and unit name when they + * are displayed together + */ + codeSep_: ': ', + // Message text variations for validation methods and conversion methods + valMsgStart_: 'Did you mean ', + valMsgEnd_: '?', + cnvMsgStart_: 'We assumed you meant ', + cnvMsgEnd_: '.', + + /** + * Default opening string used to emphasize portions of error messages. + * Used when NOT displaying messages on a web site, i.e., for output + * from the library methods or to a file. + */ + openEmph_: ' ->', + + /** + * Default closing string used to emphasize portions of error messages. + * Used when NOT displaying messages on a web site, i.e., for output + * from the library methods or to a file. + */ + closeEmph_: '<- ', + + /** + * Opening HTML used to emphasize portions of error messages. Used when + * displaying messages on a web site; should be blank when output is + * to a file. + */ + openEmphHTML_: ' ', + + /** + * Closing HTML used to emphasize portions of error messages. Used when + * displaying messages on a web site; should be blank when output is + * to a file. + */ + closeEmphHTML_: ' ', + + /** + * Message that is displayed when annotations are included in a unit + * string, to let the user know how they are interpreted. + */ + bracesMsg_: 'FYI - annotations (text in curly braces {}) are ignored, ' + 'except that an annotation without a leading symbol implies ' + 'the default unit 1 (the unity).', + + /** + * Message that is displayed or returned when a conversion is requested + * for two units where (only) a mass<->moles conversion is appropriate + * but no molecular weight was specified. + */ + needMoleWeightMsg_: 'Did you wish to convert between mass and moles? The ' + 'molecular weight of the substance represented by the ' + 'units is required to perform the conversion.', + + /** + * Hash that matches unit column names to names used in the csv file + * that is submitted to the data updater. + */ + csvCols_: { + 'case-sensitive code': 'csCode_', + 'LOINC property': 'loincProperty_', + 'name (display)': 'name_', + 'synonyms': 'synonyms_', + 'source': 'source_', + 'category': 'category_', + 'Guidance': 'guidance_' + }, + + /** + * Name of the column in the csv file that serves as the key + */ + inputKey_: 'case-sensitive code', + + /** + * Special codes that contain operators within brackets. The operator + * within these codes causes them to parse incorrectly if they are preceded + * by a prefix, because the parsing algorithm splits them up on the operator. + * So we use this object to identify them and substitute placeholders to + * avoid that. + */ + specUnits_: { + 'B[10.nV]': 'specialUnitOne', + '[m/s2/Hz^(1/2)]': 'specialUnitTwo' + } +}; +exports.Ucum = Ucum; + + +},{}],95:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Dimension = void 0; + +/** + * This class implements an object containing the vector of exponents for + * a unit and its operations for addition, subtraction, and multiplication + * with a scalar. + * + * This object should exist for each unit that can be expressed as a + * vector of numbers. This excludes arbitrary units, e.g., (10*23), and + * units that are not numbers but are an expression based solely on numbers, + * e.g., mol (mole) which is based on 10*23. + * + * @author Lee Mericle, based on java version by Gunther Schadow + */ +var UC = require('./config.js'); + +var isInteger = require("is-integer"); + +class Dimension { + /** + * Constructor. + * + * @param dimSetting an optional parameter that may be: + * null, which means that the dimVec_ attribute for this object will be null; or + * an array, which must be the length defined by Ucum.dimLen_, and + * whose contents will be copied to this new object's vector; or + * an integer, which must be between 0 and 1 less than the vector length + * defined by Ucum.dimLen_. This new object's vector will be + * initialized to zero for all elements except the one whose index + * matches the number passed in. That element will be set to one. + * @throws an error if the dimSetting parameter does not meet the types + * listed above. + * An error will also be thrown if Ucum.dimLen_ has not been set yet, + * i.e., is still zero. Currently that won't happen, because the + * value is set in the config.js file. But further down the road + * the setting will come from a definitions input file, so we check + * here anyway. + * + */ + constructor(dimSetting) { + if (UC.Ucum.dimLen_ === 0) { + throw new Error('Dimension.setDimensionLen must be called before ' + 'Dimension constructor'); + } + + if (dimSetting === undefined || dimSetting === null) { + this.assignZero(); + } else if (dimSetting instanceof Array) { + if (dimSetting.length !== UC.Ucum.dimLen_) { + throw new Error('Parameter error, incorrect length of vector passed to ' + `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`); + } + + this.dimVec_ = []; + + for (let d = 0; d < UC.Ucum.dimLen_; d++) this.dimVec_.push(dimSetting[d]); + } // In es6 this should be Number.isInteger(dimSetting). But Babel + // doesn't transpile that correctly, so we need to use the isInteger + // module. :0 + else if (isInteger(dimSetting)) { + if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) { + throw new Error('Parameter error, invalid element number specified for ' + 'Dimension constructor'); + } + + this.assignZero(); + this.dimVec_[dimSetting] = 1; + } + } // end constructor + + /** + * Sets the element at the specified position to a specified value. The + * default value is 1. If the dimension vector is null when this is called + * a zero-filled vector is created and then the indicated position is set. + * + * @param indexPos the index of the element to be set + * @param value the value to assign to the specified element; optional, + * default value is 1 + * @throws an exception if the specified position is invalid, i.e., not a + * number or is less than 0 or greater than Ucum.dimLen_ + **/ + + + setElementAt(indexPos, value) { + if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) { + throw new Error(`Dimension.setElementAt called with an invalid index ` + `position (${indexPos})`); + } + + if (!this.dimVec_) { + this.assignZero(); + } + + if (value === undefined || value === null) value = 1; + this.dimVec_[indexPos] = value; + } + /** + * Gets the value of the element at the specified position + * + * @param indexPos the index of the element whose value is to be returned + * @return the value of the element at indexPos, or null if the dimension + * vector is null + * @throws an exception if the specified position is invalid, i.e., not a + * number or is less than 0 or greater than Ucum.dimLen_ + **/ + + + getElementAt(indexPos) { + if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) { + throw new Error(`Dimension.getElementAt called with an invalid index ` + `position (${indexPos})`); + } + + let ret = null; + if (this.dimVec_) ret = this.dimVec_[indexPos]; + return ret; + } + /** + * This returns the value of the property named by the parameter + * passed in. Although we currently only have one property, dimVec_, + * that this will get, it's possible that we'll have additional + * properties. If we don't this could just be replaced by a + * getVector function. + * + * @param propertyName name of the property to be returned, with + * or without the trailing underscore. + * @return the requested property, if found for this Dimension + * @throws an error if the property is not found for this Dimension + */ + + + getProperty(propertyName) { + let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_'; + return this[uProp]; + } // end getProperty + + /** + * Return a string that represents the dimension vector. Returns null if + * the dimension vector is null. + * + * @return the string that represents the dimension vector. The + * values are enclosed in square brackets, each separated + * by a comma and a space + **/ + + + toString() { + let ret = null; + if (this.dimVec_) ret = '[' + this.dimVec_.join(', ') + ']'; + return ret; + } + /** + * Adds the vector of the dimension object passed in to this + * dimension object's vector. This object's vector is changed. + * If either dimension vector is null, no changes are made to this object. + * + * + * @param dim2 the dimension whose vector is to be added to this one + * @return this object + * @throws an exception if dim2 is not a Dimension object + **/ + + + add(dim2) { + if (!dim2 instanceof Dimension) { + throw new Error(`Dimension.add called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); } - Concatenate.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args.some(function (x) { return x == null; })) { - return null; - } - else { - return args.reduce(function (x, y) { return x + y; }); - } - }; - return Concatenate; -}(expression_1.Expression)); -exports.Concatenate = Concatenate; -var Combine = /** @class */ (function (_super) { - __extends(Combine, _super); - function Combine(json) { - var _this = _super.call(this, json) || this; - _this.source = (0, builder_1.build)(json.source); - _this.separator = (0, builder_1.build)(json.separator); - return _this; + + if (this.dimVec_ && dim2.dimVec_) { + for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] += dim2.dimVec_[i]; } - Combine.prototype.exec = function (ctx) { - var source = this.source.execute(ctx); - var separator = this.separator != null ? this.separator.execute(ctx) : ''; - if (source == null) { - return null; - } - else { - var filteredArray = source.filter(function (x) { return x != null; }); - if (filteredArray.length === 0) { - return null; - } - else { - return filteredArray.join(separator); - } - } - }; - return Combine; -}(expression_1.Expression)); -exports.Combine = Combine; -var Split = /** @class */ (function (_super) { - __extends(Split, _super); - function Split(json) { - var _this = _super.call(this, json) || this; - _this.stringToSplit = (0, builder_1.build)(json.stringToSplit); - _this.separator = (0, builder_1.build)(json.separator); - return _this; + + return this; + } + /** + * Subtracts the vector of the dimension object passed in from this + * dimension object's vector. This object's vector is changed. + * If either dimension vector is null, no changes are made to this object. + * + * @param dim2 the dimension whose vector is to be subtracted from this one + * @return this object + * @throws an exception if dim2 is not a Dimension object + **/ + + + sub(dim2) { + if (!dim2 instanceof Dimension) { + throw new Error(`Dimension.sub called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); } - Split.prototype.exec = function (ctx) { - var stringToSplit = this.stringToSplit.execute(ctx); - var separator = this.separator.execute(ctx); - if (stringToSplit && separator) { - return stringToSplit.split(separator); - } - return stringToSplit ? [stringToSplit] : null; - }; - return Split; -}(expression_1.Expression)); -exports.Split = Split; -var SplitOnMatches = /** @class */ (function (_super) { - __extends(SplitOnMatches, _super); - function SplitOnMatches(json) { - var _this = _super.call(this, json) || this; - _this.stringToSplit = (0, builder_1.build)(json.stringToSplit); - _this.separatorPattern = (0, builder_1.build)(json.separatorPattern); - return _this; + + if (this.dimVec_ && dim2.dimVec_) { + for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] -= dim2.dimVec_[i]; } - SplitOnMatches.prototype.exec = function (ctx) { - var stringToSplit = this.stringToSplit.execute(ctx); - var separatorPattern = this.separatorPattern.execute(ctx); - if (stringToSplit && separatorPattern) { - return stringToSplit.split(new RegExp(separatorPattern)); - } - return stringToSplit ? [stringToSplit] : null; - }; - return SplitOnMatches; -}(expression_1.Expression)); -exports.SplitOnMatches = SplitOnMatches; -// Length is completely handled by overloaded#Length -var Upper = /** @class */ (function (_super) { - __extends(Upper, _super); - function Upper(json) { - return _super.call(this, json) || this; + + return this; + } + /** + * Inverts this dimension object's vector (by multiplying each element + * by negative 1). This object's vector is changed - unless it is null, + * in which case it stays that way. + * + * @return this object + **/ + + + minus() { + if (this.dimVec_) { + for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] = -this.dimVec_[i]; } - Upper.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return arg.toUpperCase(); - } - else { - return null; - } - }; - return Upper; -}(expression_1.Expression)); -exports.Upper = Upper; -var Lower = /** @class */ (function (_super) { - __extends(Lower, _super); - function Lower(json) { - return _super.call(this, json) || this; + + return this; + } + /** + * Multiplies this dimension object's vector with a scalar. This is used + * when a unit is raised to a power. This object's vector is changed unless + * the vector is null, in which case it stays that way. + * + * @param s the scalar to use + * @return this object + * @throws an exception if s is not a number + */ + + + mul(s) { + if (!isInteger(s)) { + throw new Error(`Dimension.sub called with an invalid parameter - ` + `${typeof dim2} instead of a number`); } - Lower.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return arg.toLowerCase(); - } - else { - return null; - } - }; - return Lower; -}(expression_1.Expression)); -exports.Lower = Lower; -// Indexer is completely handled by overloaded#Indexer -var PositionOf = /** @class */ (function (_super) { - __extends(PositionOf, _super); - function PositionOf(json) { - var _this = _super.call(this, json) || this; - _this.pattern = (0, builder_1.build)(json.pattern); - _this.string = (0, builder_1.build)(json.string); - return _this; + + if (this.dimVec_) { + for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] *= s; } - PositionOf.prototype.exec = function (ctx) { - var pattern = this.pattern.execute(ctx); - var string = this.string.execute(ctx); - if (pattern == null || string == null) { - return null; - } - else { - return string.indexOf(pattern); - } - }; - return PositionOf; -}(expression_1.Expression)); -exports.PositionOf = PositionOf; -var LastPositionOf = /** @class */ (function (_super) { - __extends(LastPositionOf, _super); - function LastPositionOf(json) { - var _this = _super.call(this, json) || this; - _this.pattern = (0, builder_1.build)(json.pattern); - _this.string = (0, builder_1.build)(json.string); - return _this; + + return this; + } + /** + * Tests for equality of this dimension object's vector and that of + * the dimension object passed in. If the dimension vector for one of + * the objects is null, the dimension vector for the other object must + * also be null for the two to be equal. (I know - duh. still) + * + * @param dim2 the dimension object whose vector is to be compared to this one + * @return true if the two vectors are equal; false otherwise. + * @throws an exception if dim2 is not a Dimension object + */ + + + equals(dim2) { + if (!dim2 instanceof Dimension) { + throw new Error(`Dimension.equals called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); } - LastPositionOf.prototype.exec = function (ctx) { - var pattern = this.pattern.execute(ctx); - var string = this.string.execute(ctx); - if (pattern == null || string == null) { - return null; - } - else { - return string.lastIndexOf(pattern); - } - }; - return LastPositionOf; -}(expression_1.Expression)); -exports.LastPositionOf = LastPositionOf; -var Matches = /** @class */ (function (_super) { - __extends(Matches, _super); - function Matches(json) { - return _super.call(this, json) || this; + + let isEqual = true; + let dimVec2 = dim2.dimVec_; + + if (this.dimVec_ && dimVec2) { + for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++) isEqual = this.dimVec_[i] === dimVec2[i]; + } else { + isEqual = this.dimVec_ === null && dimVec2 === null; } - Matches.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), string = _a[0], pattern = _a[1]; - if (string == null || pattern == null) { - return null; - } - return new RegExp('^' + pattern + '$').test(string); - }; - return Matches; -}(expression_1.Expression)); -exports.Matches = Matches; -var Substring = /** @class */ (function (_super) { - __extends(Substring, _super); - function Substring(json) { - var _this = _super.call(this, json) || this; - _this.stringToSub = (0, builder_1.build)(json.stringToSub); - _this.startIndex = (0, builder_1.build)(json.startIndex); - _this.length = (0, builder_1.build)(json['length']); - return _this; + + return isEqual; + } + /** + * Assigns the contents of the vector belonging to the dimension object + * passed in to this dimension's vector. If this dimension vector is null + * and the other is not, this one will get the contents of the other. If + * this dimension vector is not null but the one passed in is null, this + * one will be set to null. + * + * @param dim2 the dimension object with the vector whose contents are + * to be assigned to this dimension's vector + * @return this object (not sure why) + * @throws an exception if dim2 is not a Dimension object + */ + + + assignDim(dim2) { + if (!dim2 instanceof Dimension) { + throw new Error(`Dimension.assignDim called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`); } - Substring.prototype.exec = function (ctx) { - var stringToSub = this.stringToSub.execute(ctx); - var startIndex = this.startIndex.execute(ctx); - var length = this.length != null ? this.length.execute(ctx) : null; - // According to spec: If stringToSub or startIndex is null, or startIndex is out of range, the result is null. - if (stringToSub == null || - startIndex == null || - startIndex < 0 || - startIndex >= stringToSub.length) { - return null; - } - else if (length != null) { - return stringToSub.substr(startIndex, length); - } - else { - return stringToSub.substr(startIndex); - } - }; - return Substring; -}(expression_1.Expression)); -exports.Substring = Substring; -var StartsWith = /** @class */ (function (_super) { - __extends(StartsWith, _super); - function StartsWith(json) { - return _super.call(this, json) || this; + + if (dim2.dimVec_ === null) this.dimVec_ = null;else { + if (this.dimVec_ === null) { + this.dimVec_ = []; + } + + for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] = dim2.dimVec_[i]; } - StartsWith.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args.some(function (x) { return x == null; })) { - return null; - } - else { - return args[0].slice(0, args[1].length) === args[1]; - } - }; - return StartsWith; -}(expression_1.Expression)); -exports.StartsWith = StartsWith; -var EndsWith = /** @class */ (function (_super) { - __extends(EndsWith, _super); - function EndsWith(json) { - return _super.call(this, json) || this; + return this; + } + /** + * Sets all elements of this dimension object's vector to zero. + * If this object's vector is null, it is created as a zero-filled vector. + * + * @return this object (not sure why) + */ + + + assignZero() { + if (this.dimVec_ === null || this.dimVec_ === undefined) this.dimVec_ = []; + + for (let i = 0; i < UC.Ucum.dimLen_; i++) { + this.dimVec_.push(0); } - EndsWith.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args.some(function (x) { return x == null; })) { - return null; - } - else { - return args[1] === '' || args[0].slice(-args[1].length) === args[1]; - } - }; - return EndsWith; -}(expression_1.Expression)); -exports.EndsWith = EndsWith; -var ReplaceMatches = /** @class */ (function (_super) { - __extends(ReplaceMatches, _super); - function ReplaceMatches(json) { - return _super.call(this, json) || this; + + return this; + } + /** + * Tests for a dimension vector set to all zeroes. + * + * @return true if exponents (elements) of this dimension's vector are all + * zero; false otherwise (including if the current vector is null). + * + */ + + + isZero() { + let allZero = this.dimVec_ !== null; + + if (this.dimVec_) { + for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++) allZero = this.dimVec_[i] === 0; } - ReplaceMatches.prototype.exec = function (ctx) { - var args = this.execArgs(ctx); - if (args.some(function (x) { return x == null; })) { - return null; - } - else { - return args[0].replace(new RegExp(args[1], 'g'), args[2]); - } - }; - return ReplaceMatches; -}(expression_1.Expression)); -exports.ReplaceMatches = ReplaceMatches; -},{"./builder":67,"./expression":73}],91:[function(require,module,exports){ + return allZero; + } + /** + * Tests for a Dimension object with no dimension vector (dimVec_ is null). + * + * @return true the dimension vector is null; false if it is not + * + */ + + + isNull() { + return this.dimVec_ === null; + } + /** + * Creates and returns a clone of this Dimension object + * + * @return the clone + */ + + + clone() { + let that = new Dimension(); + that.assignDim(this); + return that; + } + +} // end Dimension class + + +exports.Dimension = Dimension; + + +},{"./config.js":94,"is-integer":108}],96:[function(require,module,exports){ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TupleElementDefinition = exports.TupleElement = exports.Tuple = exports.Property = void 0; -var expression_1 = require("./expression"); -var builder_1 = require("./builder"); -var Property = /** @class */ (function (_super) { - __extends(Property, _super); - function Property(json) { - var _this = _super.call(this, json) || this; - _this.scope = json.scope; - _this.source = (0, builder_1.build)(json.source); - _this.path = json.path; - return _this; - } - Property.prototype.exec = function (ctx) { - var obj = this.scope != null ? ctx.get(this.scope) : this.source; - if (obj instanceof expression_1.Expression) { - obj = obj.execute(ctx); - } - var val = getPropertyFromObject(obj, this.path); - if (val == null) { - var parts = this.path.split('.'); - var curr_obj = obj; - for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) { - var part = parts_1[_i]; - var _obj = getPropertyFromObject(curr_obj, part); - curr_obj = _obj instanceof Function ? _obj.call(curr_obj) : _obj; - } - val = curr_obj != null ? curr_obj : null; // convert undefined to null - } - if (val instanceof Function) { - return val.call(obj); - } - else { - return val; - } - }; - return Property; -}(expression_1.Expression)); -exports.Property = Property; -function getPropertyFromObject(obj, path) { - var val; - if (obj != null) { - val = obj[path]; - if (val === undefined && typeof obj.get === 'function') { - val = obj.get(path); - } - } - return val; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.packArray = packArray; +exports.unpackArray = unpackArray; + +/** + * This file provides functions to reduce the size of an array of objects of the same structure in JSON. + */ +const pushFn = Array.prototype.push; + +function isObject(value) { + return Object.prototype.toString.call(value) === '[object Object]'; } -var Tuple = /** @class */ (function (_super) { - __extends(Tuple, _super); - function Tuple(json) { - var _this = _super.call(this, json) || this; - var elements = json.element != null ? json.element : []; - _this.elements = elements.map(function (el) { - return { - name: el.name, - value: (0, builder_1.build)(el.value) - }; - }); - return _this; +/** + * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data. + * @param {Object} refObj - reference item of array of objects of the same structure + * @returns {Array} + */ + + +function createConfig(refObj) { + return Object.keys(refObj).reduce((config, key) => { + if (isObject(refObj[key])) { + pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)])); + } else { + config.push(key); } - Object.defineProperty(Tuple.prototype, "isTuple", { - get: function () { - return true; - }, - enumerable: false, - configurable: true + + return config; + }, []); +} +/** + * Prepares config created with createConfig function to use in packItem/unpackItem functions. + * @param {Array} config + * @returns {Array} + */ + + +function prepareConfig(config) { + return config.map(key => Array.isArray(key) ? key : [key]); +} +/** + * Converts an object to an array of values in the order of keys from configuration array. + * @param {Array} config - configuration array + * @param {Object} item - input object + * @returns {Array} + */ + + +function packItem(config, item) { + if (config.join() !== prepareConfig(createConfig(item)).join()) { + throw new Error('Object of unusual structure'); + } + + return config.map(keyArr => { + let place = item; + keyArr.forEach(key => { + place = place[key]; + + if (place === undefined) { + throw new Error('Object of unusual structure'); + } }); - Tuple.prototype.exec = function (ctx) { - var val = {}; - for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { - var el = _a[_i]; - val[el.name] = el.value != null ? el.value.execute(ctx) : undefined; - } - return val; - }; - return Tuple; -}(expression_1.Expression)); -exports.Tuple = Tuple; -var TupleElement = /** @class */ (function (_super) { - __extends(TupleElement, _super); - function TupleElement() { - return _super !== null && _super.apply(this, arguments) || this; - } - return TupleElement; -}(expression_1.UnimplementedExpression)); -exports.TupleElement = TupleElement; -var TupleElementDefinition = /** @class */ (function (_super) { - __extends(TupleElementDefinition, _super); - function TupleElementDefinition() { - return _super !== null && _super.apply(this, arguments) || this; - } - return TupleElementDefinition; -}(expression_1.UnimplementedExpression)); -exports.TupleElementDefinition = TupleElementDefinition; + return place; + }); +} +/** + * Performs the reverse of packItem function. + * @param {Array} config - configuration array + * @param {Array} item - input object + * @returns {Object} + */ -},{"./builder":67,"./expression":73}],92:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TupleTypeSpecifier = exports.NamedTypeSpecifier = exports.ListTypeSpecifier = exports.IntervalTypeSpecifier = exports.Is = exports.CanConvertQuantity = exports.ConvertQuantity = exports.ConvertsToTime = exports.ConvertsToString = exports.ConvertsToRatio = exports.ConvertsToQuantity = exports.ConvertsToInteger = exports.ConvertsToDecimal = exports.ConvertsToDateTime = exports.ConvertsToDate = exports.ConvertsToBoolean = exports.Convert = exports.ToTime = exports.ToString = exports.ToRatio = exports.ToQuantity = exports.ToInteger = exports.ToDecimal = exports.ToDateTime = exports.ToDate = exports.ToConcept = exports.ToBoolean = exports.As = void 0; -var expression_1 = require("./expression"); -var datetime_1 = require("../datatypes/datetime"); -var clinical_1 = require("../datatypes/clinical"); -var quantity_1 = require("../datatypes/quantity"); -var math_1 = require("../util/math"); -var util_1 = require("../util/util"); -var ratio_1 = require("../datatypes/ratio"); -var uncertainty_1 = require("../datatypes/uncertainty"); -// TODO: Casting and Conversion needs unit tests! -var As = /** @class */ (function (_super) { - __extends(As, _super); - function As(json) { - var _this = _super.call(this, json) || this; - if (json.asTypeSpecifier) { - _this.asTypeSpecifier = json.asTypeSpecifier; - } - else if (json.asType) { - // convert it to a NamedTypedSpecifier - _this.asTypeSpecifier = { - name: json.asType, - type: 'NamedTypeSpecifier' - }; - } - _this.strict = json.strict != null ? json.strict : false; - return _this; + +function unpackItem(config, item) { + let result = {}; + config.forEach((keyArr, i) => { + let place = result; + + for (let i = 0; i < keyArr.length - 1; i++) { + place = place[keyArr[i]] = place[keyArr[i]] || {}; } - As.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - // If it is null, return null - if (arg == null) { - return null; - } - if (ctx.matchesTypeSpecifier(arg, this.asTypeSpecifier)) { - // TODO: request patient source to change type identification - return arg; - } - else if (this.strict) { - var argTypeString = specifierToString(guessSpecifierType(arg)); - var asTypeString = specifierToString(this.asTypeSpecifier); - throw new Error("Cannot cast ".concat(argTypeString, " as ").concat(asTypeString)); - } - else { - return null; - } - }; - return As; -}(expression_1.Expression)); -exports.As = As; -var ToBoolean = /** @class */ (function (_super) { - __extends(ToBoolean, _super); - function ToBoolean(json) { - return _super.call(this, json) || this; + + place[keyArr[keyArr.length - 1]] = item[i]; + }); + return result; +} +/** + * Reduces size of an array of objects of the same structure before serialize it to JSON + * @param {Array} arr + * @returns {Object} + */ + + +function packArray(arr) { + if (arr && arr.length) { + const config = createConfig(arr[0]), + _config = prepareConfig(config); + + if (config.length) { + return { + config: config, + data: arr.map(packItem.bind(null, _config)) + }; } - ToBoolean.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - var strArg = arg.toString().toLowerCase(); - if (['true', 't', 'yes', 'y', '1'].includes(strArg)) { - return true; - } - else if (['false', 'f', 'no', 'n', '0'].includes(strArg)) { - return false; - } - } - return null; - }; - return ToBoolean; -}(expression_1.Expression)); -exports.ToBoolean = ToBoolean; -var ToConcept = /** @class */ (function (_super) { - __extends(ToConcept, _super); - function ToConcept(json) { - return _super.call(this, json) || this; + } + + return { + config: [], + data: arr + }; +} +/** + * Restores an array of objects of the same structure after deserializing this object from JSON + * @param {Object} obj + * @returns {Array} + */ + + +function unpackArray(obj) { + const config = obj && obj.config; + + if (config) { + if (config.length && obj.data) { + const _config = prepareConfig(config); + + return obj.data.map(unpackItem.bind(null, _config)); + } else { + return obj.data; } - ToConcept.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return new clinical_1.Concept([arg], arg.display); - } - else { - return null; - } - }; - return ToConcept; -}(expression_1.Expression)); -exports.ToConcept = ToConcept; -var ToDate = /** @class */ (function (_super) { - __extends(ToDate, _super); - function ToDate(json) { - return _super.call(this, json) || this; + } + + return obj; +} + + +},{}],97:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Prefix = void 0; + +/** + * Prefix objects are defined in this file. + */ + +/** + * This class implements the prefix object. Prefixes are used as multipliers + * for units, e.g., km for kilometers + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +var Ucum = require('./config.js'); + +class Prefix { + /** + * Creates a single prefix object. + * + * @param attrs a hash of the values to use in creating the prefix object. + * They should be: + * code_ - which is the case-sensitive code used for the prefix, + * e.g., k for kilo + * ciCode_ - which is the case-insensitive code used for the prefix, + * e.g., K for kilo + * name_ - which is the name of the prefix, e.g., kilo + * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo + * value_ - which is teh value to use in multiplying the magnitude of + * a unit, e.g., for a prefix of c the value will be .01. + * exp_ - which is the exponent used to get the value. For decimal based + * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a + * prefix of c, the exponent will be -2. For prefixes that are not + * decimal based, this will be null (but must not be undefined). + * + * @throws an error if the not all required parameters are provided + */ + constructor(attrs) { + if (attrs['code_'] === undefined || attrs['code_'] === null || attrs['name_'] === undefined || attrs['name_'] === null || attrs['value_'] === undefined || attrs['value_'] === null || attrs['exp_'] === undefined) { + throw new Error('Prefix constructor called missing one or more parameters. ' + 'Prefix codes (cs or ci), name, value and exponent must all be specified ' + 'and all but the exponent must not be null.'); } - ToDate.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - else if (arg.isDateTime) { - return arg.getDate(); - } - else { - return datetime_1.Date.parse(arg.toString()); - } - }; - return ToDate; -}(expression_1.Expression)); -exports.ToDate = ToDate; -var ToDateTime = /** @class */ (function (_super) { - __extends(ToDateTime, _super); - function ToDateTime(json) { - return _super.call(this, json) || this; + /** + * The prefix code, e.g., k for kilo. This should be the case-sensitive + * code. Since there's no way to check to see if it's the case-sensitive + * one as opposed to the case-insensitive one (because although + * case-insensitive codes all seem to be uppercase, some case-sensitive + * codes are also all uppercase), we'll just have to believe that the + * right one was passed in. + */ + + + this.code_ = attrs['code_']; + /** + * The case-insensitive code, e.g., K for kilo + */ + + this.ciCode_ = attrs['ciCode_']; + /** + * The prefix name, e.g., kilo + */ + + this.name_ = attrs['name_']; + /** + * The printSymbol for the prefix, e.g., k for kilo + */ + + this.printSymbol_ = attrs['printSymbol_']; + /** + * The value to use in multiplying the magnitude of a unit + */ + + if (typeof attrs['value_'] === 'string') this.value_ = parseFloat(attrs['value_']);else this.value_ = attrs['value_']; + /** + * The exponent used to create the value from 10. For prefixes that are + * not based on 10, this will be null. + */ + + this.exp_ = attrs['exp_']; + } // end constructor + + /** + * Returns the value for the current prefix object + * @return the value for the prefix object with the specified code + * */ + + + getValue() { + return this.value_; + } + /** + * Returns the prefix code for the current prefix object + * @return the code for the current prefix object + */ + + + getCode() { + return this.code_; + } + /** + * Returns the case-insensitive code for the current prefix object + * @return the case_insensitive code for the current prefix object + */ + + + getCiCode() { + return this.ciCode_; + } + /** + * Returns the prefix name for the current prefix object + * @return the name for the current prefix object + */ + + + getName() { + return this.name_; + } + /** + * Returns the print symbol for the current prefix object + * @return the print symbol for the current prefix object + */ + + + getPrintSymbol() { + return this.printSymbol_; + } + /** + * Returns the exponent for the current prefix object + * @return the exponent for the current prefix object + */ + + + getExp() { + return this.exp_; + } + /** + * Provides way to tell if one prefix equals another. The second prefix + * must match all attribute values. + * + * @param prefix2 prefix object to check for a match + * @return true for a match; false if one or more attributes don't match + */ + + + equals(prefix2) { + return this.code_ === prefix2.code_ && this.ciCode_ === prefix2.ciCode_ && this.name_ === prefix2.name_ && this.printSymbol_ === prefix2.printSymbol_ && this.value_ === prefix2.value_ && this.exp_ === prefix2.exp_; + } + +} // end Prefix class + + +exports.Prefix = Prefix; + + +},{"./config.js":94}],98:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PrefixTables = exports.PrefixTablesFactory = void 0; + +/** + * The tables of defined prefixes is defined in this file. + */ + +/** + * This class implements the table of multiplier prefixes. + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +class PrefixTablesFactory { + /** + * Constructor. This creates the empty PrefixTable hashes once. + * There is one hash whose key is the prefix code and one whose + * key is the prefix value. + * + * Implementation of this as a singleton is based on the UnitTables + * implementation. See that class for details. + */ + constructor() { + this.byCode_ = {}; + this.byValue_ = {}; + } + /** + * Provides the number of prefix objects in each table + * @returns count of the number of prefix objects in each table + */ + + + prefixCount() { + return Object.keys(this.byCode_).length; + } + /** + * This is used to get all prefix objects by value. Currently it is used + * to create a csv file with all prefixes and units. + * @returns csv string containing all prefix objects, ordered by value. + */ + + + allPrefixesByValue() { + let prefixBuff = ''; + let pList = Object.keys(this.byValue_); //pList.sort() ; + + let pLen = pList.length; + + for (let p = 0; p < pLen; p++) { + let pfx = this.getPrefixByValue(pList[p]); + prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\r\n'; } - ToDateTime.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg == null) { - return null; - } - else if (arg.isDate) { - return arg.getDateTime(); - } - else { - return datetime_1.DateTime.parse(arg.toString()); - } - }; - return ToDateTime; -}(expression_1.Expression)); -exports.ToDateTime = ToDateTime; -var ToDecimal = /** @class */ (function (_super) { - __extends(ToDecimal, _super); - function ToDecimal(json) { - return _super.call(this, json) || this; + + return prefixBuff; + } + /** + * This is used to get all prefix objects. Currently it is used + * to get the objects to write to the json ucum definitions file + * that is used to provide prefix and unit definition objects for + * conversions and validations. + * + * @returns an array containing all prefix objects, ordered by code. + */ + + + allPrefixesByCode() { + let prefixList = []; + let pList = Object.keys(this.byCode_); + pList.sort(); + let pLen = pList.length; + + for (let p = 0; p < pLen; p++) { + prefixList.push(this.getPrefixByCode(pList[p])); } - ToDecimal.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - if (arg.isUncertainty) { - var low = (0, math_1.limitDecimalPrecision)(parseFloat(arg.low.toString())); - var high = (0, math_1.limitDecimalPrecision)(parseFloat(arg.high.toString())); - return new uncertainty_1.Uncertainty(low, high); - } - else { - var decimal = (0, math_1.limitDecimalPrecision)(parseFloat(arg.toString())); - if ((0, math_1.isValidDecimal)(decimal)) { - return decimal; - } - } - } - return null; + + return prefixList; + } + /** + * Adds a prefix object to the tables + * + * @param prefixObj the object to be added to the tables + */ + + + add(prefixObj) { + this.byCode_[prefixObj.getCode()] = prefixObj; + this.byValue_[prefixObj.getValue()] = prefixObj; + } + /** + * Tests whether a prefix object is found for a specified code. This + * is used to determine whether or not a prefix object has been created + * for the code. + * + * @param code the code to be used to find the prefix object + * @return boolean indicating whether or not a prefix object was found + * for the specified code + */ + + + isDefined(code) { + return this.byCode_[code] !== null && this.byCode_[code] !== undefined; + } + /** + * Obtains a prefix object for a specified code. + * + * @param code the code to be used to find the prefix object + * @return the prefix object found, or null if nothing was found + */ + + + getPrefixByCode(code) { + return this.byCode_[code]; + } + /** + * Obtains a prefix object for a specified value. + * + * @param value the value to be used to find the prefix object + * @return the prefix object found, or null if nothing was found + */ + + + getPrefixByValue(value) { + return this.byValue_[value]; + } + +} // end PrefixTablesFactory class +// Create a singleton instance and (to preserve the existing API) an object that +// provides that instance via getInstance(). + + +exports.PrefixTablesFactory = PrefixTablesFactory; +var prefixTablesInstance = new PrefixTablesFactory(); +const PrefixTables = { + getInstance: function () { + return prefixTablesInstance; + } +}; +exports.PrefixTables = PrefixTables; + + +},{}],99:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; + +/* + * This class manages the special functions used by some units. + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +class UcumFunctions { + /** + * Constructor + * + * Creates the singleton object that contains the list of functions used + * to convert special units. + */ + constructor() { + // Create the hash containing the function pairs + this.funcs = {}; // Celsius - convert to Celsius from kelvin and from Celsius to kelvin + // where kelvin is the base unit for temperature + + this.funcs['cel'] = { + cnvTo: function (x) { + return x - 273.15; + }, + cnvFrom: function (x) { + return x + 273.15; + } + }; // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to + // kelvin - which is the base unit for temperature + + this.funcs['degf'] = { + cnvTo: function (x) { + return x - 459.67; + }, + cnvFrom: function (x) { + return x + 459.67; + } + }; // Reaumur - convert between Reaumur and Kelvin. Because of the way the + // calling code in the Units class is set up (in the convertFrom method), + // what is given here as the convertTo function is actually the convert + // from method and vice versa. + //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;}, + // cnvFrom : function(x){return x - 273.15;}}; + + this.funcs['degre'] = { + cnvTo: function (x) { + return x - 273.15; + }, + cnvFrom: function (x) { + return x + 273.15; + } + }; // pH - convert to pH from moles per liter and from moles per liter to pH + // where a mole is an amount of a substance (a count of particles) + + this.funcs['ph'] = { + cnvTo: function (x) { + return -Math.log(x) / Math.LN10; + }, + cnvFrom: function (x) { + return Math.pow(10, -x); + } + }; // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom) + // and 2ln - two times the natural logarithm + + this.funcs['ln'] = { + cnvTo: function (x) { + return Math.log(x); + }, + cnvFrom: function (x) { + return Math.exp(x); + } }; - return ToDecimal; -}(expression_1.Expression)); -exports.ToDecimal = ToDecimal; -var ToInteger = /** @class */ (function (_super) { - __extends(ToInteger, _super); - function ToInteger(json) { - return _super.call(this, json) || this; - } - ToInteger.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (typeof arg === 'string') { - var integer = parseInt(arg); - if ((0, math_1.isValidInteger)(integer)) { - return integer; - } - } - else if (typeof arg === 'boolean') { - return arg ? 1 : 0; - } - return null; + this.funcs['2ln'] = { + cnvTo: function (x) { + return 2 * Math.log(x); + }, + cnvFrom: function (x) { + return Math.exp(x / 2); + } + }; // lg - the decadic logarithm (base 10) + + this.funcs['lg'] = { + cnvTo: function (x) { + return Math.log(x) / Math.LN10; + }, + cnvFrom: function (x) { + return Math.pow(10, x); + } }; - return ToInteger; -}(expression_1.Expression)); -exports.ToInteger = ToInteger; -var ToQuantity = /** @class */ (function (_super) { - __extends(ToQuantity, _super); - function ToQuantity(json) { - return _super.call(this, json) || this; - } - ToQuantity.prototype.exec = function (ctx) { - return this.convertValue(this.execArgs(ctx)); + this.funcs['10lg'] = { + cnvTo: function (x) { + return 10 * Math.log(x) / Math.LN10; + }, + cnvFrom: function (x) { + return Math.pow(10, x / 10); + } }; - ToQuantity.prototype.convertValue = function (val) { - if (val == null) { - return null; - } - else if (typeof val === 'number') { - return new quantity_1.Quantity(val, '1'); - } - else if (val.isRatio) { - // numerator and denominator are guaranteed non-null - return val.numerator.dividedBy(val.denominator); - } - else if (val.isUncertainty) { - return new uncertainty_1.Uncertainty(this.convertValue(val.low), this.convertValue(val.high)); - } - else { - // it's a string or something else we'll try to parse as a string - return (0, quantity_1.parseQuantity)(val.toString()); - } + this.funcs['20lg'] = { + cnvTo: function (x) { + return 20 * Math.log(x) / Math.LN10; + }, + cnvFrom: function (x) { + return Math.pow(10, x / 20); + } + }; // The plain text ucum units file uses '2lg' + + this.funcs['2lg'] = { + cnvTo: function (x) { + return 2 * Math.log(x) / Math.LN10; + }, + cnvFrom: function (x) { + return Math.pow(10, x / 2); + } + }; // The xml essence ucum file uses lgTimes2 + + this.funcs['lgtimes2'] = this.funcs['2lg']; // ld - dual logarithm (base 2) + + this.funcs['ld'] = { + cnvTo: function (x) { + return Math.log(x) / Math.LN2; + }, + cnvFrom: function (x) { + return Math.pow(2, x); + } + }; // tan - tangent + + this.funcs['100tan'] = { + cnvTo: function (x) { + return Math.tan(x) * 100; + }, + cnvFrom: function (x) { + return Math.atan(x / 100); + } + }; // the xml essence ucum file uses both 100tan and tanTimes100 + + this.funcs['tanTimes100'] = this.funcs['100tan']; // sqrt - square root + + this.funcs['sqrt'] = { + cnvTo: function (x) { + return Math.sqrt(x); + }, + cnvFrom: function (x) { + return x * x; + } + }; // inv - inverse + + this.funcs['inv'] = { + cnvTo: function (x) { + return 1.0 / x; + }, + cnvFrom: function (x) { + return 1.0 / x; + } + }; // homeopathic potency functions + + this.funcs['hpX'] = { + cnvTo: function (x) { + return -this.funcs['lg'](x); + }, + cnvFrom: function (x) { + return Math.pow(10, -x); + } }; - return ToQuantity; -}(expression_1.Expression)); -exports.ToQuantity = ToQuantity; -var ToRatio = /** @class */ (function (_super) { - __extends(ToRatio, _super); - function ToRatio(json) { - return _super.call(this, json) || this; - } - ToRatio.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - // Argument will be of form ':' - var denominator = void 0, numerator = void 0; - try { - // String will be split into an array. Numerator will be at index 1, Denominator will be at index 4 - var splitRatioString = arg - .toString() - .match(/^(\d+(\.\d+)?\s*('.+')?)\s*:\s*(\d+(\.\d+)?\s*('.+')?)$/); - if (splitRatioString == null) { - return null; - } - numerator = (0, quantity_1.parseQuantity)(splitRatioString[1]); - denominator = (0, quantity_1.parseQuantity)(splitRatioString[4]); - } - catch (error) { - // If the input string is not formatted correctly, or cannot be - // interpreted as a valid Quantity value, the result is null. - return null; - } - // The value element of a Quantity must be present. - if (numerator == null || denominator == null) { - return null; - } - return new ratio_1.Ratio(numerator, denominator); - } - else { - return null; - } + this.funcs['hpC'] = { + cnvTo: function (x) { + return -this.func['ln'](x) / this.funcs['ln'](100); + }, + cnvFrom: function (x) { + return Math.pow(100, -x); + } }; - return ToRatio; -}(expression_1.Expression)); -exports.ToRatio = ToRatio; -var ToString = /** @class */ (function (_super) { - __extends(ToString, _super); - function ToString(json) { - return _super.call(this, json) || this; - } - ToString.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - return arg.toString(); - } - else { - return null; - } + this.funcs['hpM'] = { + cnvTo: function (x) { + return -this.funcs['ln'](x) / this.funcs['ln'](1000); + }, + cnvFrom: function (x) { + return Math.pow(1000, -x); + } }; - return ToString; -}(expression_1.Expression)); -exports.ToString = ToString; -var ToTime = /** @class */ (function (_super) { - __extends(ToTime, _super); - function ToTime(json) { - return _super.call(this, json) || this; - } - ToTime.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg != null) { - var timeString = arg.toString(); - // Return null if string doesn't represent a valid ISO-8601 Time - // hh:mm:ss.fff or hh:mm:ss.fff - var matches = /^T?((\d{2})(:(\d{2})(:(\d{2})(\.(\d+))?)?)?)?(Z|(([+-])(\d{2})(:?(\d{2}))?))?$/.exec(timeString); - if (matches == null) { - return null; - } - var hours = matches[2]; - var minutes = matches[4]; - var seconds = matches[6]; - // Validate h/m/s if they exist, but allow null - if (hours != null) { - if (hours < 0 || hours > 23) { - return null; - } - hours = parseInt(hours, 10); - } - if (minutes != null) { - if (minutes < 0 || minutes > 59) { - return null; - } - minutes = parseInt(minutes, 10); - } - if (seconds != null) { - if (seconds < 0 || seconds > 59) { - return null; - } - seconds = parseInt(seconds, 10); - } - var milliseconds = matches[8]; - if (milliseconds != null) { - milliseconds = parseInt((0, util_1.normalizeMillisecondsField)(milliseconds)); - } - // Time is implemented as Datetime with year 0, month 1, day 1 and null timezoneOffset - return new datetime_1.DateTime(0, 1, 1, hours, minutes, seconds, milliseconds, null); - } - else { - return null; + this.funcs['hpQ'] = { + cnvTo: function (x) { + return -this.funcs['ln'](x) / this.funcs['ln'](50000); + }, + cnvFrom: function (x) { + return Math.pow(50000, -x); + } + }; + } // end of constructor + + /** + * Returns the function with the name specified + * + * @param fname name of the function to be returned + * @return the function with the specified name + * @throws an error message if the function is not found + */ + + + forName(fname) { + fname = fname.toLowerCase(); + let f = this.funcs[fname]; + if (f === null) throw new Error(`Requested function ${fname} is not defined`); + return f; + } + /** + * Returns a flag indicating whether or not the function has been + * defined. + * + * @param fname name of the function in question + * @return true if it has been defined; false if not + */ + + + isDefined(fname) { + fname = fname.toLowerCase(); + return this.funcs[fname] !== null; + } + +} // end of UcumFunctions class + + +var _default = new UcumFunctions(); // one singleton instance + + +exports.default = _default; + + +},{}],100:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.isNumericString = isNumericString; +exports.isIntegerUnit = isIntegerUnit; +exports.getSynonyms = getSynonyms; + +/** + * Internal utilities used by multiple UCUM classes. For example, + * isNumericString is used by both the UnitString and UcumLhcUtils + * classes. If it's in the UnitString class the UcumLhcUtils class + * needs to require the UnitString class. But the checkSynonyms + * class is used by the UnitString class - but was in the UcumLhcUtils + * class. Requiring the UcumLhcUtils class from the UnitString class + * made everything break (cyclical requires). + * + * So now they're here. + */ + +/** + * This module implements internal ucum utilities. + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +var UnitTables = require('./unitTables.js').UnitTables; +/** + * This function tests a string to see if it contains only numbers (digits, + * a period, leading - or +). This code was taken from a stackoverflow + * solution: + * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340 + * + * @params theString + * @returns true if the string contains only numbers; false otherwise + */ + + +function isNumericString(theString) { + let num = "" + theString; //coerce num to be a string + + return !isNaN(num) && !isNaN(parseFloat(num)); +} // end isNumericString + +/** + * Checks whether a string qualifies as an integer unit. Section 2.2.8 ("integer + * numbers", says, "A positive integer number may appear in place of a simple + * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is + * interpreted as a number." + * Note: This leaves open the question of whether "0" is a valid unit, since + * it is positive, but you can't measure anything in units of zero. + * @param str the string to check + */ + + +function isIntegerUnit(str) { + return /^\d+$/.test(str); +} +/** + * This method accepts a term and looks for units that include it as + * a synonym - or that include the term in its name. + * + * @param theSyn the term to search for. This is assumed to be + * a string and not undefined. The calling method should do any + * necessary checking before calling this. + * @returns a hash with up to three elements: + * 'status' contains the status of the request, which can be 'error', + * 'failed' or succeeded'; + * 'msg' which contains a message for an error or if no units were found; and + * 'units' which is an array that contains one array for each unit found: + * the unit's csCode_, the unit's name_, and the unit's guidance_ + * + */ + + +function getSynonyms(theSyn) { + let retObj = {}; + let utab = UnitTables.getInstance(); + let resp = {}; + resp = utab.getUnitBySynonym(theSyn); // If we didn't get any units, transfer the status and message + + if (!resp['units']) { + retObj['status'] = resp['status']; + retObj['msg'] = resp['msg']; + } else { + retObj['status'] = 'succeeded'; + let aLen = resp['units'].length; + retObj['units'] = []; + + for (let a = 0; a < aLen; a++) { + let theUnit = resp['units'][a]; + retObj['units'][a] = { + 'code': theUnit.csCode_, + 'name': theUnit.name_, + 'guidance': theUnit.guidance_ + }; + } // end do for all units returned + + } // end if we got a units list + + + return retObj; +} // end getSynonyms + + +},{"./unitTables.js":106}],101:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ucumJsonDefs = exports.UcumJsonDefs = void 0; + +/** + * This class handles opening, reading and loading the JSON file of ucum + * definitions (prefixes, base units, and unit atoms). + * + * @author Lee Mericle + * + */ +var Pfx = require("./prefix.js"); + +var PfxT = require("./prefixTables.js"); + +var Un = require("./unit.js"); + +var Utab = require('./unitTables.js'); + +var unpackArray = require('./jsonArrayPack.js').unpackArray; + +class UcumJsonDefs { + /** + * This method loads the JSON prefix and unit objects into the prefix and + * unit tables. + * + * @returns nothing + */ + loadJsonDefs() { + // requiring the file will take care of opening it for use + const jsonDefs = require('../data/ucumDefs.min.json'); + + jsonDefs.prefixes = unpackArray(jsonDefs.prefixes); + jsonDefs.units = unpackArray(jsonDefs.units); + + if (Utab.UnitTables.getInstance().unitsCount() === 0) { + let pTab = PfxT.PrefixTables.getInstance(); + let prefixes = jsonDefs["prefixes"]; + let plen = prefixes.length; + + for (let p = 0; p < plen; p++) { + let newPref = new Pfx.Prefix(prefixes[p]); + pTab.add(newPref); + } + + let uTab = Utab.UnitTables.getInstance(); + let units = jsonDefs["units"]; + let ulen = units.length; + + for (let u = 0; u < ulen; u++) { + let newUnit = new Un.Unit(units[u]); + uTab.addUnit(newUnit); + } + } // end if the data has not already been loaded + + } // end loadJsonDefs + + +} // end UcumJsonDefs class + + +exports.UcumJsonDefs = UcumJsonDefs; +var ucumJsonDefs = new UcumJsonDefs(); +exports.ucumJsonDefs = ucumJsonDefs; + + +},{"../data/ucumDefs.min.json":93,"./jsonArrayPack.js":96,"./prefix.js":97,"./prefixTables.js":98,"./unit.js":104,"./unitTables.js":106}],102:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.UcumLhcUtils = void 0; + +var _ucumJsonDefs = require("./ucumJsonDefs.js"); + +var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); + +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } + +/** + * This class provides a single point of access to the LHC UCUM utilities + * + * @author Lee Mericle + * + */ +var Ucum = require('./config.js').Ucum; + +var UnitTables = require('./unitTables.js').UnitTables; + +var UnitString = require('./unitString.js').UnitString; + +/** + * UCUM external utilities class + */ +class UcumLhcUtils { + /** + * Constructor. This loads the json prefix and unit definitions if + * they haven't been loaded already and creates itself as a singleton object. + * + */ + constructor() { + if (UnitTables.getInstance().unitsCount() === 0) { + // Load the prefix and unit objects + _ucumJsonDefs.ucumJsonDefs.loadJsonDefs(); + } // Get the UnitString parser that will be used with this instance + // of the LHC Utilities + + + this.uStrParser_ = UnitString.getInstance(); + } // end constructor + + /** + * This method calls the useHTMLInMessages method on the UnitString + * object. It should be called by web applications that use + * these utilities. + * + * @param use flag indicating whether or not to use the braces message; + * defaults to true + */ + + + useHTMLInMessages(use) { + if (use === undefined) use = true; + this.uStrParser_.useHTMLInMessages(use); + } + /** + * This method calls the useBraceMsgForEachString method on the UnitString + * object. It should be called by web applications where unit + * strings are validated individually (as opposed to validating a whole + * file of unit strings). + * + * @param use flag indicating whether or not to use the braces message; + * defaults to true + */ + + + useBraceMsgForEachString(use) { + if (use === undefined) use = true; + this.uStrParser_.useBraceMsgForEachString(use); + } + /** + * This method validates a unit string. It first checks to see if the + * string passed in is a unit code that is found in the unit codes table. + * If it is not found it parses the string to see if it resolves to a + * valid unit string. + * + * If a valid unit cannot be found, the string is tested for some common + * errors, such as missing brackets or a missing multiplication operator. + * If found, the error is reported in the messages array that is returned. + * + * If a valid unit cannot be found and an error cannot be discerned, this + * may return, if requested, a list of suggested units in the messages + * array that is returned. Suggestions are based on matching the expression + * with unit names and synonyms. + * + * @param uStr the string to be validated + * @param suggest a boolean to indicate whether or not suggestions are + * requested for a string that cannot be resolved to a valid unit; + * true indicates suggestions are wanted; false indicates they are not, + * and is the default if the parameter is not specified; + * @param valConv a string indicating if this validation request was initiated + * by a validation task ('validate') or a conversion task ('convert'), + * used only for the demo code, and the default is 'Validator' if the + * parameter is not specified; + * @returns an object with five properties: + * 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid' + * (the uStr is not a valid UCUM code, and substitutions or + * suggestions may or may not be returned, depending on what was + * requested and found); or 'error' (an input or programming error + * occurred); + * 'ucumCode' the valid ucum code, which may differ from what was passed + * in (e.g., if 'Gauss' is passed in, this will contain 'G') OR null if + * the string was flagged as invalid or an error occurred; + * 'msg' is an array of one or more messages, if the string is invalid or + * an error occurred, indicating the problem, or an explanation of a + * substitution such as the substitution of 'G' for 'Gauss', or + * an empty array if no messages were generated; + * 'unit' which is null if no unit is found, or a hash for a unit found: + * 'code' is the unit's ucum code (G in the above example; + * 'name' is the unit's name (Gauss in the above example); and + * 'guidance' is the unit's guidance/description data; and + * 'suggestions' if suggestions were requested and found, this is an array + * of one or more hash objects. Each hash contains three elements: + * 'msg' which is a message indicating what part of the uStr input + * parameter the suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions are + * for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + * If no suggestions were requested and found, this property is not + * returned. + */ + + + validateUnitString(uStr, suggest, valConv) { + if (suggest === undefined) suggest = false; + if (valConv === undefined) valConv = 'validate'; + let resp = this.getSpecifiedUnit(uStr, valConv, suggest); + let theUnit = resp['unit']; + let retObj = {}; + + if (!theUnit) { + retObj = { + 'status': !resp['origString'] || resp['origString'] === null ? 'error' : 'invalid', + 'ucumCode': null + }; + } else { + retObj = { + 'status': resp['origString'] === uStr ? 'valid' : 'invalid', + 'ucumCode': resp['origString'], + 'unit': { + 'code': theUnit.csCode_, + 'name': theUnit.name_, + 'guidance': theUnit.guidance_ } - }; - return ToTime; -}(expression_1.Expression)); -exports.ToTime = ToTime; -var Convert = /** @class */ (function (_super) { - __extends(Convert, _super); - function Convert(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - _this.toType = json.toType; - return _this; + }; } - Convert.prototype.exec = function (ctx) { - switch (this.toType) { - case '{urn:hl7-org:elm-types:r1}Boolean': - return new ToBoolean({ type: 'ToBoolean', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Concept': - return new ToConcept({ type: 'ToConcept', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Decimal': - return new ToDecimal({ type: 'ToDecimal', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Integer': - return new ToInteger({ type: 'ToInteger', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}String': - return new ToString({ type: 'ToString', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Quantity': - return new ToQuantity({ type: 'ToQuantity', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}DateTime': - return new ToDateTime({ type: 'ToDateTime', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Date': - return new ToDate({ type: 'ToDate', operand: this.operand }).execute(ctx); - case '{urn:hl7-org:elm-types:r1}Time': - return new ToTime({ type: 'ToTime', operand: this.operand }).execute(ctx); - default: - return this.execArgs(ctx); - } - }; - return Convert; -}(expression_1.Expression)); -exports.Convert = Convert; -var ConvertsToBoolean = /** @class */ (function (_super) { - __extends(ConvertsToBoolean, _super); - function ConvertsToBoolean(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (resp['suggestions']) { + retObj['suggestions'] = resp['suggestions']; } - ConvertsToBoolean.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToBoolean, this.operand, ctx); - } + + retObj['msg'] = resp['retMsg']; + return retObj; + } // end validateUnitString + + /** + * This method converts one unit to another + * + * @param fromUnitCode the unit code/expression/string of the unit to be converted + * @param fromVal the number of "from" units to be converted to "to" units + * @param toUnitCode the unit code/expression/string of the unit that the from + * field is to be converted to + * @param suggest a boolean to indicate whether or not suggestions are + * requested for a string that cannot be resolved to a valid unit; + * true indicates suggestions are wanted; false indicates they are not, + * and is the default if the parameter is not specified; + * @param molecularWeight the molecular weight of the substance in question + * when a conversion is being requested from mass to moles and vice versa. + * This is required when one of the units represents a value in moles. It is + * ignored if neither unit includes a measurement in moles. + * @returns a hash with six elements: + * 'status' that will be: 'succeeded' if the conversion was successfully + * calculated; 'failed' if the conversion could not be made, e.g., if + * the units are not commensurable; or 'error' if an error occurred; + * 'toVal' the numeric value indicating the conversion amount, or null + * if the conversion failed (e.g., if the units are not commensurable); + * 'msg' is an array message, if the string is invalid or an error occurred, + * indicating the problem, or an explanation of a substitution such as + * the substitution of 'G' for 'Gauss', or an empty array if no + * messages were generated; + * 'suggestions' if suggestions were requested and found, this is a hash + * that contains at most two elements: + * 'from' which, if the fromUnitCode input parameter or one or more of + * its components could not be found, is an array one or more hash + * objects. Each hash contains three elements: + * 'msg' which is a message indicating what unit expression the + * suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions + * are for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + * If no suggestions were found for the fromUnitCode this element + * will not be included. + * 'to' which, if the "to" unit expression or one or more of its + * components could not be found, is an array one or more hash objects. Each hash + * contains three elements: + * 'msg' which is a message indicating what toUnitCode input + * parameter the suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions + * are for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + * If no suggestions were found for the toUnitCode this element + * will not be included. + * No 'suggestions' element will be included in the returned hash + * object if none were found, whether or not they were requested. + * 'fromUnit' the unit object for the fromUnitCode passed in; returned + * in case it's needed for additional data from the object; and + * 'toUnit' the unit object for the toUnitCode passed in; returned + * in case it's needed for additional data from the object. + */ + + + convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) { + if (suggest === undefined) suggest = false; + if (molecularWeight === undefined) molecularWeight = null; + let returnObj = { + 'status': 'failed', + 'toVal': null, + 'msg': [] }; - return ConvertsToBoolean; -}(expression_1.Expression)); -exports.ConvertsToBoolean = ConvertsToBoolean; -var ConvertsToDate = /** @class */ (function (_super) { - __extends(ConvertsToDate, _super); - function ConvertsToDate(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (fromUnitCode) { + fromUnitCode = fromUnitCode.trim(); } - ConvertsToDate.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToDate, this.operand, ctx); - } - }; - return ConvertsToDate; -}(expression_1.Expression)); -exports.ConvertsToDate = ConvertsToDate; -var ConvertsToDateTime = /** @class */ (function (_super) { - __extends(ConvertsToDateTime, _super); - function ConvertsToDateTime(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (!fromUnitCode || fromUnitCode == '') { + returnObj['status'] = 'error'; + returnObj['msg'].push('No "from" unit expression specified.'); } - ConvertsToDateTime.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToDateTime, this.operand, ctx); - } - }; - return ConvertsToDateTime; -}(expression_1.Expression)); -exports.ConvertsToDateTime = ConvertsToDateTime; -var ConvertsToDecimal = /** @class */ (function (_super) { - __extends(ConvertsToDecimal, _super); - function ConvertsToDecimal(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (fromVal === null || isNaN(fromVal) || typeof fromVal !== 'number' && !intUtils_.isNumericString(fromVal)) { + returnObj['status'] = 'error'; + returnObj['msg'].push('No "from" value, or an invalid "from" value, ' + 'was specified.'); } - ConvertsToDecimal.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToDecimal, this.operand, ctx); - } - }; - return ConvertsToDecimal; -}(expression_1.Expression)); -exports.ConvertsToDecimal = ConvertsToDecimal; -var ConvertsToInteger = /** @class */ (function (_super) { - __extends(ConvertsToInteger, _super); - function ConvertsToInteger(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (toUnitCode) { + toUnitCode = toUnitCode.trim(); } - ConvertsToInteger.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToInteger, this.operand, ctx); - } - }; - return ConvertsToInteger; -}(expression_1.Expression)); -exports.ConvertsToInteger = ConvertsToInteger; -var ConvertsToQuantity = /** @class */ (function (_super) { - __extends(ConvertsToQuantity, _super); - function ConvertsToQuantity(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (!toUnitCode || toUnitCode == '') { + returnObj['status'] = 'error'; + returnObj['msg'].push('No "to" unit expression specified.'); } - ConvertsToQuantity.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; + + if (returnObj['status'] !== 'error') { + try { + let fromUnit = null; + let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest); + fromUnit = parseResp['unit']; + if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']); + + if (parseResp['suggestions']) { + returnObj['suggestions'] = {}; + returnObj['suggestions']['from'] = parseResp['suggestions']; } - else { - return canConvertToType(ToQuantity, this.operand, ctx); + + if (!fromUnit) { + returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` + `so no conversion could be performed.`); } - }; - return ConvertsToQuantity; -}(expression_1.Expression)); -exports.ConvertsToQuantity = ConvertsToQuantity; -var ConvertsToRatio = /** @class */ (function (_super) { - __extends(ConvertsToRatio, _super); - function ConvertsToRatio(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; - } - ConvertsToRatio.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; + + let toUnit = null; + parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest); + toUnit = parseResp['unit']; + if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']); + + if (parseResp['suggestions']) { + if (!returnObj['suggestions']) returnObj['suggestions'] = {}; + returnObj['suggestions']['to'] = parseResp['suggestions']; } - else { - return canConvertToType(ToRatio, this.operand, ctx); + + if (!toUnit) { + returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` + `so no conversion could be performed.`); } - }; - return ConvertsToRatio; -}(expression_1.Expression)); -exports.ConvertsToRatio = ConvertsToRatio; -var ConvertsToString = /** @class */ (function (_super) { - __extends(ConvertsToString, _super); - function ConvertsToString(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; + + if (fromUnit && toUnit) { + try { + // if no molecular weight was specified perform a normal conversion + if (!molecularWeight) { + returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit); + } else { + if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) { + throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed for two ' + 'mole-based units. No conversion was attempted.'); + } + + if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) { + throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed when ' + 'neither unit is mole-based. No conversion was attempted.'); + } + + if (!fromUnit.isMoleMassCommensurable(toUnit)) { + throw new Error(`Sorry. ${fromUnitCode} cannot be ` + `converted to ${toUnitCode}.`); + } // if the "from" unit is a mole-based unit, assume a mole to mass + // request + + + if (fromUnit.moleExp_ !== 0) { + returnObj['toVal'] = fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight); + } // else the "to" unit must be the mole-based unit, so assume a + // mass to mole request + else { + returnObj['toVal'] = fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight); + } + } // end if a molecular weight was specified + // if an error hasn't been thrown - either from convertFrom or here, + // set the return object to show success + + + returnObj['status'] = 'succeeded'; + returnObj['fromUnit'] = fromUnit; + returnObj['toUnit'] = toUnit; + } catch (err) { + returnObj['status'] = 'failed'; + returnObj['msg'].push(err.message); + } + } // end if we have the from and to units + + } catch (err) { + if (err.message == Ucum.needMoleWeightMsg_) returnObj['status'] = 'failed';else returnObj['status'] = 'error'; + returnObj['msg'].push(err.message); + } } - ConvertsToString.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; - } - else { - return canConvertToType(ToString, this.operand, ctx); + + return returnObj; + } // end convertUnitTo + + /** + * Converts the given unit string into its base units, their exponents, and + * a magnitude, and returns that data. + * @param fromUnit the unit string to be converted to base units information + * @param fromVal the number of "from" units to be converted + * @returns an object with the properties: + * 'msg': an array of one or more messages, if the string is invalid or + * an error occurred, indicating the problem, or a suggestion of a + * substitution such as the substitution of 'G' for 'Gauss', or + * an empty array if no messages were generated. If this is not empty, + * no other information will be returned. + * 'magnitude': the new value when fromVal units of fromUnits is expressed in the base units. + * 'fromUnitIsSpecial': whether the input unit fromUnit is a "special unit" + * as defined in UCUM. This means there is some function applied to convert + * between fromUnit and the base units, so the returned magnitude is likely not + * useful as a scale factor for other conversions (i.e., it only has validity + * and usefulness for the input values that produced it). + * 'unitToExp': a map of base units in uStr to their exponent + */ + + + convertToBaseUnits(fromUnit, fromVal) { + let inputUnitLookup = this.getSpecifiedUnit(fromUnit, 'validate'); + let retObj = {}; + let unit = inputUnitLookup.unit; + retObj.msg = inputUnitLookup.retMsg || []; + + if (!unit) { + if (inputUnitLookup.retMsg?.length == 0) retObj.msg.push('Could not find unit information for ' + fromUnit); + } else if (unit.isArbitrary_) { + retObj.msg.push('Arbitrary units cannot be converted to base units or other units.'); + } else if (retObj.msg.length == 0) { + let unitToExp = {}; + let dimVec = unit.dim_?.dimVec_; + let baseUnitString = '1'; + + if (dimVec) { + let dimVecIndexToBaseUnit = UnitTables.getInstance().dimVecIndexToBaseUnit_; + + for (let i = 0, len = dimVec.length; i < len; ++i) { + let exp = dimVec[i]; + + if (exp) { + unitToExp[dimVecIndexToBaseUnit[i]] = exp; + baseUnitString += '.' + dimVecIndexToBaseUnit[i] + exp; + } } - }; - return ConvertsToString; -}(expression_1.Expression)); -exports.ConvertsToString = ConvertsToString; -var ConvertsToTime = /** @class */ (function (_super) { - __extends(ConvertsToTime, _super); - function ConvertsToTime(json) { - var _this = _super.call(this, json) || this; - _this.operand = json.operand; - return _this; - } - ConvertsToTime.prototype.exec = function (ctx) { - var operatorValue = this.execArgs(ctx); - if (operatorValue === null) { - return null; + } // The unit might have a conversion function, which has to be applied; we + // cannot just assume unit_.magnitude_ is the magnitude in base units. + + + let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate'); // There should not be any error in retUnitLookup, unless there is a bug. + + let retUnit = retUnitLookup.unit; + if (!retUnit && retUnitLookup.retMsg?.length == 0) retObj.msg.push('Unable construct base unit string; tried ' + baseUnitString);else { + try { + retObj.magnitude = retUnit.convertFrom(fromVal, unit); + } catch (e) { + retObj.msg.push(e.toString()); } - else { - return canConvertToType(ToTime, this.operand, ctx); + + if (retObj.msg.length == 0) { + retObj.unitToExp = unitToExp; + retObj.fromUnitIsSpecial = unit.isSpecial_; } - }; - return ConvertsToTime; -}(expression_1.Expression)); -exports.ConvertsToTime = ConvertsToTime; -function canConvertToType(toFunction, operand, ctx) { - try { - var value = new toFunction({ type: toFunction.name, operand: operand }).execute(ctx); - if (value != null) { - return true; + } + } + + return retObj; + } + /** + * This method accepts a term and looks for units that include it as + * a synonym - or that include the term in its name. + * + * @param theSyn the term to search for + * @returns a hash with up to three elements: + * 'status' contains the status of the request, which can be 'error', + * 'failed' or succeeded'; + * 'msg' which contains a message for an error or if no units were found; and + * 'units' which is an array that contains one hash for each unit found: + * 'code' is the unit's csCode_ + * 'name' is the unit's name_ + * 'guidance' is the unit's guidance_ + * + */ + + + checkSynonyms(theSyn) { + let retObj = {}; + + if (theSyn === undefined || theSyn === null) { + retObj['status'] = 'error'; + retObj['msg'] = 'No term specified for synonym search.'; + } else { + retObj = intUtils_.getSynonyms(theSyn); + } // end if a search synonym was supplied + + + return retObj; + } // end checkSynonyms + + /** + * This method parses a unit string to get (or try to get) the unit + * represented by the string. It returns an error message if no string was specified + * or if any errors were encountered trying to get the unit. + * + * @param uName the expression/string representing the unit + * @param valConv indicates what type of request this is for - a request to + * validate (pass in 'validate') or a request to convert (pass in 'convert') + * @param suggest a boolean to indicate whether or not suggestions are + * requested for a string that cannot be resolved to a valid unit; + * true indicates suggestions are wanted; false indicates they are not, + * and is the default if the parameter is not specified; + * @returns a hash containing: + * 'unit' the unit object (or null if there were problems creating the + * unit); + * 'origString' the possibly updated unit string passed in; + * 'retMsg' an array of user messages (informational, error or warning) if + * any were generated (IF any were generated, otherwise will be an + * empty array); and + * 'suggestions' is an array of 1 or more hash objects. Each hash + * contains three elements: + * 'msg' which is a message indicating what unit expression the + * suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions are + * for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + * The return hash will not contain a suggestions array if a valid unit + * was found or if suggestions were not requested and found. + */ + + + getSpecifiedUnit(uName, valConv, suggest) { + if (suggest === undefined) suggest = false; + let retObj = {}; + retObj['retMsg'] = []; + + if (!uName) { + retObj['retMsg'].push('No unit string specified.'); + } else { + let utab = UnitTables.getInstance(); + uName = uName.trim(); // go ahead and just try using the name as the code. This may or may not + // work, but if it does, it cuts out a lot of parsing. + + let theUnit = utab.getUnitByCode(uName); // If we found it, set the returned unit string to what was passed in; + // otherwise try parsing as a unit string + + if (theUnit) { + retObj['unit'] = theUnit; + retObj['origString'] = uName; + } else { + try { + let resp = this.uStrParser_.parseString(uName, valConv, suggest); + retObj['unit'] = resp[0]; + retObj['origString'] = resp[1]; + if (resp[2]) retObj['retMsg'] = resp[2]; + retObj['suggestions'] = resp[3]; + } catch (err) { + console.log(`Unit requested for unit string ${uName}.` + 'request unsuccessful; error thrown = ' + err.message); + retObj['retMsg'].unshift(`${uName} is not a valid unit. ` + `${err.message}`); } - else { - return false; + } // end if the unit was not found as a unit name + + } // end if a unit expression was specified + + + return retObj; + } // end getSpecifiedUnit + + /** + * This method retrieves a list of units commensurable, i.e., that can be + * converted from and to, a specified unit. Returns an error if the "from" + * unit cannot be found. + * + * @param fromName the name/unit string of the "from" unit + * @returns an array containing two elements; + * first element is the list of commensurable units if any were found + * second element is an error message if the "from" unit is not found + */ + + + commensurablesList(fromName) { + let retMsg = []; + let commUnits = null; + let parseResp = this.getSpecifiedUnit(fromName, 'validate', false); + let fromUnit = parseResp['unit']; + if (parseResp['retMsg'].length > 0) retMsg = parseResp['retMsg']; + + if (!fromUnit) { + retMsg.push(`Could not find unit ${fromName}.`); + } else { + let dimVec = null; + let fromDim = fromUnit.getProperty('dim_'); + + if (!fromDim) { + retMsg.push('No commensurable units were found for ' + fromName); + } else { + try { + dimVec = fromDim.getProperty('dimVec_'); + } catch (err) { + retMsg.push(err.message); + if (err.message === "Dimension does not have requested property(dimVec_)") dimVec = null; } - } - catch (error) { - return false; - } -} -var ConvertQuantity = /** @class */ (function (_super) { - __extends(ConvertQuantity, _super); - function ConvertQuantity(json) { - return _super.call(this, json) || this; - } - ConvertQuantity.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), quantity = _a[0], newUnit = _a[1]; - if (quantity != null && newUnit != null) { - try { - return quantity.convertUnit(newUnit); - } - catch (error) { - // Cannot convert input to target unit, spec says to return null - return null; - } + + if (dimVec) { + let utab = UnitTables.getInstance(); + commUnits = utab.getUnitsByDimension(dimVec); } - }; - return ConvertQuantity; -}(expression_1.Expression)); -exports.ConvertQuantity = ConvertQuantity; -var CanConvertQuantity = /** @class */ (function (_super) { - __extends(CanConvertQuantity, _super); - function CanConvertQuantity(json) { - return _super.call(this, json) || this; + } // end if the from unit has a dimension vector + + } // end if we found a "from" unit + + + return [commUnits, retMsg]; + } // end commensurablesList + + +} // end UcumLhcUtils class + +/** + * This function exists ONLY until the original UcumLhcUtils constructor + * is called for the first time. It's defined here in case getInstance + * is called before the constructor. This calls the constructor. + * + * The constructor redefines the getInstance function to return the + * singleton UcumLhcUtils object. This is based on the UnitTables singleton + * implementation; see more detail in the UnitTables constructor description. + * + * NO LONGER TRUE - not implemented as a singleton. This method retained to + * avoid problems with calls to it that exist throughout the code. + * + * @return the (formerly singleton) UcumLhcUtils object. + */ + + +exports.UcumLhcUtils = UcumLhcUtils; + +UcumLhcUtils.getInstance = function () { + return new UcumLhcUtils(); +}; + + +},{"./config.js":94,"./ucumInternalUtils.js":100,"./ucumJsonDefs.js":101,"./unitString.js":105,"./unitTables.js":106}],103:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.UnitTables = exports.UcumLhcUtils = exports.Ucum = void 0; + +/** + * This exports definitions for ucum classes that need references to them + * available to the demo code. The actual code will be in the ucumPkg + * library found in the dist directory. This file provides the hooks to + * those classes within the library. + */ +var Ucum = require("./config.js").Ucum; + +exports.Ucum = Ucum; + +var UcumLhcUtils = require("./ucumLhcUtils.js").UcumLhcUtils; + +exports.UcumLhcUtils = UcumLhcUtils; + +var UnitTables = require("./unitTables.js").UnitTables; + +exports.UnitTables = UnitTables; + + +},{"./config.js":94,"./ucumLhcUtils.js":102,"./unitTables.js":106}],104:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Unit = void 0; + +var _ucumFunctions = _interopRequireDefault(require("./ucumFunctions.js")); + +var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); + +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * This class represents one unit of measure. It includes + * functions to cover constructor, accessor, and assignment tasks as + * well as operators to calculate multiplication, division and raising + * to a power. + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +var Ucum = require('./config.js').Ucum; + +var Dimension = require('./dimension.js').Dimension; + +var UnitTables; + +var isInteger = require("is-integer"); + +class Unit { + /** + * Constructor. + * + * @param attrs an optional parameter that may be: + * a string, which is parsed by the unit parser, which creates + * the unit from the parsed string; or + * a hash containing all or some values for the attributes of + * the unit, where the keys are the attribute names, without a + * trailing underscore, e.g., name instead of name_; or + * null, in which case an empty hash is created and used to + * set the values forthe attributes. + * If a hash (empty or not) is used, attributes for which no value + * is specified are assigned a default value. + * + */ + constructor(attrs = {}) { + // Process the attrs hash passed in, which may be empty. + // Create and assign values (from the attrs hash or defaults) to all + // attributes. From Class Declarations in Understanding ECMAScript, + // https://leanpub.com/understandinges6/read/#leanpub-auto-class-declarations, + // "Own properties, properties that occur on the instance rather than the + // prototype, can only be created inside of a class constructor or method. + // It's recommended to create all possible own properties inside of the + // constructor function so there's a single place that's responsible for + // all of them." + + /* + * Flag indicating whether or not this is a base unit + */ + this.isBase_ = attrs['isBase_'] || false; + /* + * The unit name, e.g., meter + */ + + this.name_ = attrs['name_'] || ''; + /* + * The unit's case-sensitive code, e.g., m + */ + + this.csCode_ = attrs['csCode_'] || ''; + /* + * The unit's case-insensitive code, e.g., M + */ + + this.ciCode_ = attrs['ciCode_'] || ''; + /* + * The unit's property, e.g., length + */ + + this.property_ = attrs['property_'] || ''; + /* + * The magnitude of the unit, e.g., 3600/3937 for a yard, + * where a yard - 3600/3973 * m(eter). The Dimension + * property specifies the meter - which is the unit on which + * a yard is based, and this magnitude specifies how to figure + * this unit based on the base unit. + */ + + this.magnitude_ = attrs['magnitude_'] || 1; + /* + * The Dimension object of the unit + */ + + if (attrs['dim_'] === undefined || attrs['dim_'] === null) { + this.dim_ = new Dimension(); + } // When the unit data stored in json format is reloaded, the dimension data + // is recognized as a a hash, not as a Dimension object. + else if (attrs['dim_']['dimVec_'] !== undefined) { + this.dim_ = new Dimension(attrs['dim_']['dimVec_']); + } else if (attrs['dim_'] instanceof Dimension) { + this.dim_ = attrs['dim_']; + } else if (attrs['dim_'] instanceof Array || isInteger(attrs['dim_'])) { + this.dim_ = new Dimension(attrs['dim_']); + } else { + this.dim_ = new Dimension(); + } + /* + * The print symbol of the unit, e.g., m + */ + + + this.printSymbol_ = attrs['printSymbol_'] || null; + /* + * The class of the unit, where given, e.g., dimless + */ + + this.class_ = attrs['class_'] || null; + /* + * A flag indicating whether or not the unit is metric + */ + + this.isMetric_ = attrs['isMetric_'] || false; + /* + * The "variable" - which I think is used only for base units + * The symbol for the variable as used in equations, e.g., s for distance + */ + + this.variable_ = attrs['variable_'] || null; // comes from 'dim' in XML + + /* + * The conversion function + */ + + this.cnv_ = attrs['cnv_'] || null; + /* + * The conversion prefix + */ + + this.cnvPfx_ = attrs['cnvPfx_'] || 1; + /* + * Flag indicating whether or not this is a "special" unit, i.e., is + * constructed using a function specific to the measurement, e.g., + * fahrenheit and celsius + */ + + this.isSpecial_ = attrs['isSpecial_'] || false; + /* + * Flag indicating whether or not this is an arbitrary unit + */ + + this.isArbitrary_ = attrs['isArbitrary_'] || false; + /* + * Integer indicating what level of exponent applies to a mole-based portion + * of the unit. So, for the unit "mol", this will be 1. For "mol2" this + * will be 2. For "1/mol" this will be -1. Any unit that does not include + * a mole will have a 0 in this field. This is used to determine + * commensurability for mole<->mass conversions. + */ + + this.moleExp_ = attrs['moleExp_'] || 0; + /* + * Added when added LOINC list of units + * synonyms are used by the autocompleter to enhance lookup capabilities + * while source says where the unit first shows up. Current sources are + * UCUM - which are units from the unitsofmeasure.org list and LOINC - + * which are units from the LOINC data. + */ + + this.synonyms_ = attrs['synonyms_'] || null; + this.source_ = attrs['source_'] || null; + this.loincProperty_ = attrs['loincProperty_'] || null; + this.category_ = attrs['category_'] || null; + this.guidance_ = attrs['guidance_'] || null; + /* + * Used to compute dimension; storing for now until I complete + * unit definition parsing + */ + + /* + * Case sensitive (cs) and case insensitive (ci) base unit strings, + * includes exponent and prefix if applicable - specified in + * nnn -- the unit part -- + * in the ucum-essence.xml file, and may be specified by a user + * when requesting conversion or validation of a unit string. The + * magnitude (base factor) is used with this to determine the new unit. + * For example, a Newton (unit code N) is created from the string + * kg.m/s2, and the value of 1 (base factor defined below). An hour + * (unit code h) is created from the unit min (minute) with a value + * of 60. + */ + + this.csUnitString_ = attrs['csUnitString_'] || null; + this.ciUnitString_ = attrs['ciUnitString_'] || null; + /* + * String and numeric versions of factor applied to unit specified in + * nnn -- the value part + */ + + this.baseFactorStr_ = attrs['baseFactorStr_'] || null; + this.baseFactor_ = attrs['baseFactor_'] || null; + /* + * Flag used to indicate units where the definition process failed + * when parsing units from the official units definitions file + * (currently using the ucum-essence.xml file). We keep these + * so that we can use them to at least validate them as valid + * units, but we don't try to convert them. This is temporary + * and only to account for instances where the code does not + * take into account various special cases in the xml file. + * + * This is NOT used when trying to validate a unit string + * submitted during a conversion or validation attempt. + */ + + this.defError_ = attrs['defError_'] || false; + } // end constructor + + /** + * Assign the unity (= dimensionless unit 1) to this unit. + * + * @return this unit + */ + + + assignUnity() { + this.name_ = ""; + this.magnitude_ = 1; + if (!this.dim_) this.dim_ = new Dimension(); + this.dim_.assignZero(); + this.cnv_ = null; + this.cnvPfx_ = 1; + return this; + } // end assignUnity + + /** + * This assigns one or more values, as provided in the hash passed in, + * to this unit. + * + * @param vals hash of values to be assigned to the attributes + * specified by the key(s), which should be the attribute + * name without the trailing underscore, e.g., name instead + * of name_. + * @return nothing + */ + + + assignVals(vals) { + for (let key in vals) { + let uKey = !key.charAt(key.length - 1) === '_' ? key + '_' : key; + if (this.hasOwnProperty(uKey)) this[uKey] = vals[key];else throw new Error(`Parameter error; ${key} is not a property of a Unit`); } - CanConvertQuantity.prototype.exec = function (ctx) { - var _a = this.execArgs(ctx), quantity = _a[0], newUnit = _a[1]; - if (quantity != null && newUnit != null) { - try { - quantity.convertUnit(newUnit); - return true; - } - catch (error) { - return false; - } - } - return null; - }; - return CanConvertQuantity; -}(expression_1.Expression)); -exports.CanConvertQuantity = CanConvertQuantity; -var Is = /** @class */ (function (_super) { - __extends(Is, _super); - function Is(json) { - var _this = _super.call(this, json) || this; - if (json.isTypeSpecifier) { - _this.isTypeSpecifier = json.isTypeSpecifier; - } - else if (json.isType) { - // Convert it to a NamedTypeSpecifier - _this.isTypeSpecifier = { - name: json.isType, - type: 'NamedTypeSpecifier' - }; - } - return _this; + } // end assignVals + + /** + * This creates a clone of this unit. + * + * @return the clone + */ + + + clone() { + let retUnit = new Unit(); + Object.getOwnPropertyNames(this).forEach(val => { + if (val === 'dim_') { + if (this['dim_']) retUnit['dim_'] = this['dim_'].clone();else retUnit['dim_'] = null; + } else retUnit[val] = this[val]; + }); + return retUnit; + } // end clone + + /** + * This assigns all properties of a unit passed to it to this unit. + * + * @param unit2 the unit whose properties are to be assigned to this one. + * @return nothing; this unit is updated + */ + + + assign(unit2) { + Object.getOwnPropertyNames(unit2).forEach(val => { + if (val === 'dim_') { + if (unit2['dim_']) this['dim_'] = unit2['dim_'].clone();else this['dim_'] = null; + } else { + this[val] = unit2[val]; + } + }); + } // end assign + + /** + * This determines whether or not object properties of the unit + * passed in are equal to the corresponding properties in this unit. + * The following properties are the only ones checked: + * magnitude_, dim_, cnv_ and cnvPfx_ + * + * @param unit2 the unit whose properties are to be checked. + * @return boolean indicating whether or not they match + */ + + + equals(unit2) { + return this.magnitude_ === unit2.magnitude_ && this.cnv_ === unit2.cnv_ && this.cnvPfx_ === unit2.cnvPfx_ && (this.dim_ === null && unit2.dim_ === null || this.dim_.equals(unit2.dim_)); + } // end equals + + /** + * This method compares every attribute of two objects to determine + * if they all match. + * + * @param unit2 the unit that is to be compared to this unit + * @return boolean indicating whether or not every attribute matches + */ + + + fullEquals(unit2) { + let thisAttr = Object.keys(this).sort(); + let u2Attr = Object.keys(unit2).sort(); + let keyLen = thisAttr.length; + let match = keyLen === u2Attr.length; // check each attribute. Dimension objects have to checked using + // the equals function of the Dimension class. + + for (let k = 0; k < keyLen && match; k++) { + if (thisAttr[k] === u2Attr[k]) { + if (thisAttr[k] === 'dim_') match = this.dim_.equals(unit2.dim_);else match = this[thisAttr[k]] === unit2[thisAttr[k]]; + } else match = false; + } // end do for each key and attribute + + + return match; + } // end of fullEquals + + /** + * This returns the value of the property named by the parameter + * passed in. + * + * @param propertyName name of the property to be returned, with + * or without the trailing underscore. + * @return the requested property, if found for this unit + * @throws an error if the property is not found for this unit + */ + + + getProperty(propertyName) { + let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_'; + return this[uProp]; + } // end getProperty + + /** + * Takes a measurement consisting of a number of units and a unit and returns + * the equivalent number of this unit. So, 15 mL would translate + * to 1 tablespoon if this object is a tablespoon. + * + * Note that the number returned may not be what is normally expected. + * For example, converting 10 Celsius units to Fahrenheit would "normally" + * return a value of 50. But in this case you'll get back something like + * 49.99999999999994. + * + * If either unit is an arbitrary unit an exception is raised. + * + * @param num the magnitude for the unit to be translated (e.g. 15 for 15 mL) + * @param fromUnit the unit to be translated to one of this type (e.g. a mL unit) + * + * @return the number of converted units (e.g. 1 for 1 tablespoon) + * @throws an error if the dimension of the fromUnit differs from this unit's + * dimension + */ + + + convertFrom(num, fromUnit) { + let newNum = 0.0; + if (this.isArbitrary_) throw new Error(`Attempt to convert to arbitrary unit "${this.csCode_}"`); + if (fromUnit.isArbitrary_) throw new Error(`Attempt to convert arbitrary unit "${fromUnit.csCode_}"`); // reject request if both units have dimensions that are not equal + + if (fromUnit.dim_ && this.dim_ && !fromUnit.dim_.equals(this.dim_)) { + // check first to see if a mole<->mass conversion is appropriate + if (this.isMoleMassCommensurable(fromUnit)) { + throw new Error(Ucum.needMoleWeightMsg_); + } else { + throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); + } + } // reject request if there is a "from" dimension but no "to" dimension + + + if (fromUnit.dim_ && (!this.dim_ || this.dim_.isNull())) { + throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); + } // reject request if there is a "to" dimension but no "from" dimension + + + if (this.dim_ && (!fromUnit.dim_ || fromUnit.dim_.isNull())) { + throw new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` + `to ${this.csCode_}.`); } - Is.prototype.exec = function (ctx) { - var arg = this.execArgs(ctx); - if (arg === null) { - return false; - } - if (typeof arg._is !== 'function' && !isSystemType(this.isTypeSpecifier)) { - // We need an _is implementation in order to check non System types - throw new Error("Patient Source does not support Is operation for localId: ".concat(this.localId)); - } - return ctx.matchesTypeSpecifier(arg, this.isTypeSpecifier); - }; - return Is; -}(expression_1.Expression)); -exports.Is = Is; -function isSystemType(spec) { - switch (spec.type) { - case 'NamedTypeSpecifier': - return spec.name.startsWith('{urn:hl7-org:elm-types:r1}'); - case 'ListTypeSpecifier': - return isSystemType(spec.elementType); - case 'TupleTypeSpecifier': - return spec.element.every(function (e) { return isSystemType(e.elementType); }); - case 'IntervalTypeSpecifier': - return isSystemType(spec.pointType); - case 'ChoiceTypeSpecifier': - return spec.choice.every(function (c) { return isSystemType(c); }); - default: - return false; + + let fromCnv = fromUnit.cnv_; + let fromMag = fromUnit.magnitude_; + let x; + + if (fromCnv != null) { + // turn num * fromUnit.magnitude into its ratio scale equivalent, + // e.g., convert Celsius to Kelvin + let fromFunc = _ucumFunctions.default.forName(fromCnv); + + x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag; //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_; + } else { + x = num * fromMag; } -} -function specifierToString(spec) { - if (typeof spec === 'string') { - return spec; + + if (this.cnv_ != null) { + // turn mag * origUnit on ratio scale into a non-ratio unit, + // e.g. convert Kelvin to Fahrenheit + let toFunc = _ucumFunctions.default.forName(this.cnv_); + + newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_; + } else { + newNum = x / this.magnitude_; } - else if (spec == null || spec.type == null) { - return ''; + + return newNum; + } // end convertFrom + + /** + * Takes a number and a target unit and returns the number for a measurement + * of this unit that corresponds to the number of the target unit passed in. + * So, 1 tablespoon (where this unit represents a tablespoon) would translate + * to 15 mL. + * + * See the note on convertFrom about return values. + * + * @param mag the magnitude for this unit (e.g. 1 for 1 tablespoon) + * @param toUnit the unit to which this unit is to be translated + * (e.g. an mL unit) + * + * @return the converted number value (e.g. 15 mL) + * @throws an error if the dimension of the toUnit differs from this unit's + * dimension + */ + + + convertTo(num, toUnit) { + return toUnit.convertFrom(num, this); + } // end convertTo + + /** + * Takes a given number of this unit returns the number of this unit + * if it is converted into a coherent unit. Does not change this unit. + * + * If this is a coherent unit already, just gives back the number + * passed in. + * + * @param num the number for the coherent version of this unit + * @return the number for the coherent version of this unit + */ + + + convertCoherent(num) { + // convert mag' * u' into canonical number * u on ratio scale + if (this.cnv_ !== null) num = this.cnv_.f_from(num / this.cnvPfx_) * this.magnitude_; + return num; + } // end convertCoherent + + /** + * Mutates this unit into a coherent unit and converts a given number of + * units to the appropriate value for this unit as a coherent unit + * + * @param num the number for this unit before conversion + * @return the number of this unit after conversion + * @throws an error if the dimensions differ + */ + + + mutateCoherent(num) { + // convert mu' * u' into canonical mu * u on ratio scale + num = this.convertCoherent(num); // mutate to coherent unit + + this.magnitude_ = 1; + this.cnv_ = null; + this.cnvPfx_ = 1; + this.name_ = ""; // build a name as a term of coherent base units + // This is probably ALL WRONG and a HORRIBLE MISTAKE + // but until we figure out what the heck the name being + // built here really is, it will have to stay. + + for (let i = 0, max = Dimension.getMax(); i < max; i++) { + let elem = this.dim_.getElementAt(i); + + let tabs = this._getUnitTables(); + + let uA = tabs.getUnitsByDimension(new Dimension(i)); + if (uA == null) throw new Error(`Can't find base unit for dimension ${i}`); + this.name_ = uA.name + elem; } - switch (spec.type) { - case 'NamedTypeSpecifier': - return spec.name; - case 'ListTypeSpecifier': - return "List<".concat(specifierToString(spec.elementType), ">"); - case 'TupleTypeSpecifier': - return "Tuple<".concat(spec.element - .map(function (e) { return "".concat(e.name, " ").concat(specifierToString(e.elementType)); }) - .join(', '), ">"); - case 'IntervalTypeSpecifier': - return "Interval<".concat(specifierToString(spec.pointType), ">"); - case 'ChoiceTypeSpecifier': - return "Choice<".concat(spec.choice.map(function (c) { return specifierToString(c); }).join(', '), ">"); + + return num; + } // end mutateCoherent + + /** + * Calculates the number of units that would result from converting a unit + * expressed in mass/grams to a unit expressed in moles. The "this" unit is + * the unit expressed in some form of mass (g, mg, mmg, kg, whatever) and the + * target or "to" unit - the molUnit parameter - is a unit expressed in moles + * - mol, umol, mmol, etc. The unit expressions surrounding the moles and + * mass must be convertible. No validation of this requirement is performed. + * + * @param amt the quantity of this unit to be converted + * @param molUnit the target/to unit for which the converted # is wanted + * @param molecularWeight the molecular weight of the substance for which the + * conversion is being made + * @return the equivalent amount in molUnit + */ + + + convertMassToMol(amt, molUnit, molecularWeight) { + // The prefix values that have been applied to this unit, which is the mass + // (grams) unit, are reflected in the magnitude. So the number of moles + // represented by this unit equals the number of grams -- amount * magnitude + // divided by the molecular Weight + let molAmt = this.magnitude_ * amt / molecularWeight; // The molUnit's basic magnitude, before prefixes are applied, + // is avogadro's number, get that and divide it out of the current magnitude. + + let tabs = this._getUnitTables(); + + let avoNum = tabs.getUnitByCode('mol').magnitude_; + let molesFactor = molUnit.magnitude_ / avoNum; // return the molAmt divided by the molesFactor as the number of moles + // for the molUnit + + return molAmt / molesFactor; + } + /** + * Calculates the number of units that would result from converting a unit + * expressed in moles to a unit expressed in mass (grams). The "this" unit + * is the unit expressed in some form of moles, e.g., mol, umol, mmol, etc., + * and the target or "to" unit is a unit expressed in some form of mass, e.g., + * g, mg, mmg, kg, etc. Any unit expressions surrounding the moles and mass + * must be convertible. No validation of this requirement is performed. + * + * @param amt the quantity of this unit to be converted + * @param massUnit the target/to unit for which the converted # is wanted + * @param molecularWeight the molecular weight of the substance for which the + * conversion is being made + * @return the equivalent amount in massUnit + */ + + + convertMolToMass(amt, massUnit, molecularWeight) { + // A simple mole unit has a magnitude of avogadro's number. Get that + // number now (since not everyone agrees on what it is, and what is + // being used in this system might change). + let tabs = this._getUnitTables(); + + let avoNum = tabs.getUnitByCode('mol').magnitude_; // Determine what prefix values (mg or mg/dL, etc.) have been applied to + // this unit by dividing the simple mole unit magnitude out of the + // current mole unit magnitude. + + let molesFactor = this.magnitude_ / avoNum; // The number of grams (mass) is equal to the number of moles (amt) + // times the molecular weight. We also multiply that by the prefix values + // applied to the current unit (molesFactor) to get the grams for this + // particular unit. + + let massAmt = molesFactor * amt * molecularWeight; // Finally, we return the mass amount/grams for this particular unit + // divided by any effects of prefixes applied to the "to" unit, which + // is assumed to be some form of a gram unit + + return massAmt / massUnit.magnitude_; + } + /** + * Mutates this unit into a unit on a ratio scale and converts a specified + * number of units to an appropriate value for this converted unit + * + * @param num the number of this unit before it's converted + * @return the magnitude of this unit after it's converted + * @throw an error if the dimensions differ + */ + + + mutateRatio(num) { + if (this.cnv_ == null) return this.mutateCoherent(num);else return num; + } // end mutateRatio + + /** + * Multiplies this unit with a scalar. Special meaning for + * special units so that (0.1*B) is 1 dB. + * + * This function DOES NOT modify this unit. + * + * @param s the value by which this unit is to be multiplied + * @return a copy this unit multiplied by s + * */ + + + multiplyThis(s) { + let retUnit = this.clone(); + if (retUnit.cnv_ != null) retUnit.cnvPfx_ *= s;else retUnit.magnitude_ *= s; + let mulVal = s.toString(); + retUnit.name_ = this._concatStrs(mulVal, '*', this.name_, '[', ']'); + retUnit.csCode_ = this._concatStrs(mulVal, '.', this.csCode_, '(', ')'); + retUnit.ciCode_ = this._concatStrs(mulVal, '.', this.ciCode_, '(', ')'); + retUnit.printSymbol_ = this._concatStrs(mulVal, '.', this.printSymbol_, '(', ')'); + return retUnit; + } // end multiplyThis + + /** + * Multiplies this unit with another unit. If one of the + * units is a non-ratio unit the other must be dimensionless or + * else an exception is thrown. + * + * This function does NOT modify this unit + * @param unit2 the unit to be multiplied with this one + * @return this unit after it is multiplied + * @throws an error if one of the units is not on a ratio-scale + * and the other is not dimensionless. + */ + + + multiplyThese(unit2) { + var retUnit = this.clone(); + + if (retUnit.cnv_ != null) { + if (unit2.cnv_ == null && (!unit2.dim_ || unit2.dim_.isZero())) retUnit.cnvPfx_ *= unit2.magnitude_;else throw new Error(`Attempt to multiply non-ratio unit ${retUnit.name_} ` + 'failed.'); + } // end if this unit has a conversion function + else if (unit2.cnv_ != null) { + if (!retUnit.dim_ || retUnit.dim_.isZero()) { + retUnit.cnvPfx_ = unit2.cnvPfx_ * retUnit.magnitude_; + retUnit.magnitude_ = unit2.magnitude_; + retUnit.cnv_ = unit2.cnv_; + } else throw new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`); + } // end if unit2 has a conversion function + // else neither unit has a conversion function + else { + retUnit.magnitude_ *= unit2.magnitude_; + } // end if unit2 does not have a conversion function + // If this.dim_ isn't there, clone the dimension in unit2 - if dimVec_ + // is a dimension in unit2.dim_; else just transfer it to this dimension + + + if (!retUnit.dim_ || retUnit.dim_ && !retUnit.dim_.dimVec_) { + if (unit2.dim_) retUnit.dim_ = unit2.dim_.clone();else retUnit.dim_ = unit2.dim_; + } // Else this.dim_ is there. If there is a dimension for unit2, + // add it to this one. + else if (unit2.dim_ && unit2.dim_ instanceof Dimension) { + retUnit.dim_.add(unit2.dim_); + } // Concatenate the unit info (name, code, etc) for all cases + // where the multiplication was performed (an error wasn't thrown) + + + retUnit.name_ = this._concatStrs(retUnit.name_, '*', unit2.name_, '[', ']'); + retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '.', unit2.csCode_, '(', ')'); + if (retUnit.ciCode_ && unit2.ciCode_) retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '.', unit2.ciCode_, '(', ')');else if (unit2.ciCode_) retUnit.ciCode_ = unit2.ciCode_; + retUnit.resetFieldsForDerivedUnit(); + if (retUnit.printSymbol_ && unit2.printSymbol_) retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.', unit2.printSymbol_, '(', ')');else if (unit2.printSymbol_) retUnit.printSymbol_ = unit2.printSymbol_; // Update the mole exponent count by adding the count for unit2 to the + // count for this unit. + + retUnit.moleExp_ = retUnit.moleExp_ + unit2.moleExp_; // A unit that has the arbitrary attribute taints any unit created from it + // via an arithmetic operation. Taint accordingly + // if (!retUnit.isMole_) + // retUnit.isMole_ = unit2.isMole_ ; + + if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_; // Likewise for special units + + if (!retUnit.isSpecial_) retUnit.isSpecial_ = unit2.isSpecial_; + return retUnit; + } // end multiplyThese + + /** + * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned + * from a known unit but it being used to construct a derived unit. + */ + + + resetFieldsForDerivedUnit() { + this.guidance_ = ''; + this.synonyms_ = null; + this.isBase_ = false; + } + /** + * Divides this unit by another unit. If this unit is not on a ratio + * scale an exception is raised. Mutating to a ratio scale unit + * is not possible for a unit, only for a measurement. + * + * This unit is NOT modified by this function. + * @param unit2 the unit by which to divide this one + * @return this unit after it is divided by unit2 + * @throws an error if either of the units is not on a ratio scale. + * */ + + + divide(unit2) { + var retUnit = this.clone(); + if (retUnit.cnv_ != null) throw new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`); + if (unit2.cnv_ != null) throw new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`); + if (retUnit.name_ && unit2.name_) retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');else if (unit2.name_) retUnit.name_ = unit2.invertString(unit2.name_); + retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_, '(', ')'); + if (retUnit.ciCode_ && unit2.ciCode_) retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_, '(', ')');else if (unit2.ciCode_) retUnit.ciCode_ = unit2.invertString(unit2.ciCode_); + retUnit.resetFieldsForDerivedUnit(); + retUnit.magnitude_ /= unit2.magnitude_; + if (retUnit.printSymbol_ && unit2.printSymbol_) retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/', unit2.printSymbol_, '(', ')');else if (unit2.printSymbol_) retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_); // Continue if unit2 has a dimension object. + // If this object has a dimension object, subtract unit2's dim_ object from + // this one. The sub method will take care of cases where the dimVec_ arrays + // are missing on one or both dim_ objects. + + if (unit2.dim_) { + if (retUnit.dim_) { + if (retUnit.dim_.isNull()) retUnit.dim_.assignZero(); + retUnit.dim_ = retUnit.dim_.sub(unit2.dim_); + } // end if this.dim_ exists + // Else if this dim_ object is missing, clone unit2's dim_ object + // and give the inverted clone to this unit. + else retUnit.dim_ = unit2.dim_.clone().minus(); + } // end if unit2 has a dimension object + // Update the mole exponent count by subtracting the count for unit2 from + // the // count for this unit. + + + retUnit.moleExp_ = retUnit.moleExp_ - unit2.moleExp_; // A unit that has the arbitrary attribute taints any unit created from + // it via an arithmetic operation. Taint accordingly + // if (!retUnit.isMole_) + // retUnit.isMole_ = unit2.isMole_ ; + + if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_; + return retUnit; + } // end divide + + /** + * Invert this unit with respect to multiplication. If this unit is not + * on a ratio scale an exception is thrown. Mutating to a ratio scale unit + * is not possible for a unit, only for a measurement (the magnitude and + * dimension). + * + * This unit is modified by this function. + * @return this unit after being inverted + * @throws and error if this unit is not on a ratio scale + */ + + + invert() { + if (this.cnv_ != null) throw new Error(`Attempt to invert a non-ratio unit - ${this.name_}`); + this.name_ = this.invertString(this.name_); + this.magnitude_ = 1 / this.magnitude_; + this.dim_.minus(); + return this; + } // end invert + + /** + * Inverts a string, where the string is assumed to be a code or a name + * of a division operation where the string is the divisor and the dividend + * is blank. + * + * @param the string to be inverted + * @return the inverted string + */ + + + invertString(theString) { + if (theString.length > 0) { + let stringRep = theString.replace('/', "!").replace('.', '/').replace("!", '.'); + + switch (stringRep.charAt(0)) { + case '.': + theString = stringRep.substr(1); + break; + + case '/': + theString = stringRep; + break; + default: - return JSON.stringify(spec); - } -} -function guessSpecifierType(val) { - if (val == null) { - return 'Null'; - } - var typeHierarchy = typeof val._typeHierarchy === 'function' && val._typeHierarchy(); - if (typeHierarchy && typeHierarchy.length > 0) { - return typeHierarchy[0]; - } - else if (typeof val === 'boolean') { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Boolean' }; - } - else if (typeof val === 'number' && Math.floor(val) === val) { - // it could still be a decimal, but we have to just take our best guess! - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Integer' }; - } - else if (typeof val === 'number') { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Decimal' }; - } - else if (typeof val === 'string') { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}String' }; - } - else if (val.isConcept) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Concept' }; - } - else if (val.isCode) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Code' }; - } - else if (val.isDate) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Date' }; - } - else if (val.isTime && val.isTime()) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}Time' }; - } - else if (val.isDateTime) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}DateTime' }; - } - else if (val.isQuantity) { - return { type: 'NamedTypeSpecifier', name: '{urn:hl7-org:elm-types:r1}DateTime' }; - } - else if (Array.isArray(val)) { - // Get unique types from the array (by converting to string and putting in a Set) - var typesAsStrings = Array.from(new Set(val.map(function (v) { return JSON.stringify(guessSpecifierType(v)); }))); - var types = typesAsStrings.map(function (ts) { return (/^{/.test(ts) ? JSON.parse(ts) : ts); }); - return { - type: 'ListTypeSpecifier', - elementType: types.length == 1 ? types[0] : { type: 'ChoiceTypeSpecifier', choice: types } - }; + theString = "/" + stringRep; + } } - else if (val.isInterval) { - return { - type: 'IntervalTypeSpecifier', - pointType: val.pointType - }; + + return theString; + } // end invertString + + /** + * This function handles concatenation of two strings and an operator. + * It's called to build unit data, e.g., unit name, unit code, etc., from + * two different units, joined by the specified operator. + * + * @param str1 the first string to appear in the result + * @param operator the operator ('*', '.' or '/') to appear between the strings + * @param str2 the second string to appear in the result + * @param startChar the starting character to be used, when needed, to + * enclose a string + * @param endChar the ending character to be used, when needed, to enclose + * a string + * @returns the built string + */ + + + _concatStrs(str1, operator, str2, startChar, endChar) { + return this._buildOneString(str1, startChar, endChar) + operator + this._buildOneString(str2, startChar, endChar); + } + /** + * This function handles creation of one string to be included in a + * concatenated string. Basically it checks to see if the string + * needs to be enclosed either in parentheses or square brackets. + * + * The string is enclosed if it is not a number, is not already enclosed in a pair of + * parentheses or square brackets, and includes a period, and asterisk, + * a slash or a blank space. + * + * @param str the string + * @param startChar starting enclosing character + * @param endChar ending enclosing character + * @returns the string + */ + + + _buildOneString(str, startChar, endChar) { + let ret = ''; + + if (intUtils_.isNumericString(str)) { + ret = str; + } else { + if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) { + ret = str; + } else if (/[./* ]/.test(str)) { + ret = startChar + str + endChar; + } else { + ret = str; + } } - else if (typeof val === 'object' && Object.keys(val).length > 0) { - return { - type: 'TupleTypeSpecifier', - element: Object.keys(val).map(function (k) { return ({ name: k, elementType: guessSpecifierType(val[k]) }); }) - }; + + return ret; + } + /** + * Raises the unit to a power. For example + * kg.m/s2 raised to the -2 power would be kg-2.m-2/s-4 + * + * If this unit is not on a ratio scale an error is thrown. Mutating + * to a ratio scale unit is not possible for a unit, only for a + * measurement (magnitude and dimension). + * + * This is based on the pow method in Gunter Schadow's java version, + * although it uses javascript capabilities to simplify the processing. + * + * This unit is modified by this function + * + * @param p the power to with this unit is to be raise + * @return this unit after it is raised + * @throws an error if this unit is not on a ratio scale. + */ + + + power(p) { + if (this.cnv_ != null) throw new Error(`Attempt to raise a non-ratio unit, ${this.name_}, ` + 'to a power.'); //this.name_ = UnitString.pow(this.name_, p); + // the above line is replaced with the code below, as the pow method + // never actually existing in the UnitString class. (Tried to use + // Schadow java code but this way ended up being a lot easier). + + let uStr = this.csCode_; + let uArray = uStr.match(/([./]|[^./]+)/g); + let arLen = uArray.length; + + for (let i = 0; i < arLen; i++) { + let un = uArray[i]; + + if (un !== '/' && un !== '.') { + let nun = parseInt(un); + if (isInteger(nun)) uArray[i] = Math.pow(nun, p).toString();else { + let uLen = un.length; + + for (let u = uLen - 1; u >= 0; u--) { + let uChar = parseInt(un[u]); + + if (!isInteger(uChar)) { + if (un[u] === '-' || un[u] === '+') { + u--; + } + + if (u < uLen - 1) { + let exp = parseInt(un.substr(u)); + exp = Math.pow(exp, p); + uArray[i] = un.substr(0, u) + exp.toString(); + u = -1; + } else { + uArray[i] += p.toString(); + u = -1; + } // end if there are/aren't some numbers at the end + + + u = -1; + } // end if this character is not a number + + } // end searching backwards for start of exponent + + } // end if this element is not a number + } // end if the current element is not an operator + + } // end do for each element of the units array + // reassemble the updated units array to a string + + + this.csCode_ = uArray.join(''); + this.magnitude_ = Math.pow(this.magnitude_, p); + + if (this.dim_) { + this.dim_.mul(p); } - return 'Unknown'; -} -var IntervalTypeSpecifier = /** @class */ (function (_super) { - __extends(IntervalTypeSpecifier, _super); - function IntervalTypeSpecifier() { - return _super !== null && _super.apply(this, arguments) || this; + + return this; + } // end power + + /* + * This function tests this unit against the unit passed in to see if the + * two are mole to mass commensurable. It assumes that one of the units + * is a mole-based unit and the other is a mass-based unit. It also assumes + * that the mole-based unit has a single mole unit in the numerator and that + * the mass-based unit has a single mass unit in the numerator. It does NOT + * check to validate those assumptions. + * + * The check is made by setting the dimension vector element corresponding + * to the base mass unit (gram) in the mole unit, and then comparing the + * two dimension vectors. If they match, the units are commensurable. + * Otherwise they are not. + * + * @param unit2 the unit to be compared to this one + * @returns boolean indicating commensurability + */ + + + isMoleMassCommensurable(unit2) { + let tabs = this._getUnitTables(); + + let d = tabs.getMassDimensionIndex(); + let commensurable = false; + + if (this.moleExp_ === 1 && unit2.moleExp_ === 0) { + let testDim = this.dim_.clone(); + let curVal = testDim.getElementAt(d); + testDim.setElementAt(d, curVal + this.moleExp_); + commensurable = testDim.equals(unit2.dim_); + } else if (unit2.moleExp_ === 1 && this.moleExp_ === 0) { + let testDim = unit2.dim_.clone(); + let curVal = testDim.getElementAt(d); + testDim.setElementAt(d, curVal + unit2.moleExp_); + commensurable = testDim.equals(this.dim_); } - return IntervalTypeSpecifier; -}(expression_1.UnimplementedExpression)); -exports.IntervalTypeSpecifier = IntervalTypeSpecifier; -var ListTypeSpecifier = /** @class */ (function (_super) { - __extends(ListTypeSpecifier, _super); - function ListTypeSpecifier() { - return _super !== null && _super.apply(this, arguments) || this; + + return commensurable; + } + /** + * This returns the UnitTables singleton object. Including the require + * statement included here causes a circular dependency condition that + * resulted in the UnitTables object not being defined for the Unit object. + * sigh. Thanks, Paul, for figuring this out. + * + * @private + */ + + + _getUnitTables() { + if (!UnitTables) UnitTables = require('./unitTables.js').UnitTables; + return UnitTables.getInstance(); + } + +} // end Unit class + + +exports.Unit = Unit; + + +},{"./config.js":94,"./dimension.js":95,"./ucumFunctions.js":99,"./ucumInternalUtils.js":100,"./unitTables.js":106,"is-integer":108}],105:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.UnitString = void 0; + +var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js")); + +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +/** + * This class handles the parsing of a unit string into a unit object + */ +var Ucum = require('./config.js').Ucum; + +var Unit = require('./unit.js').Unit; + +var UnitTables = require('./unitTables.js').UnitTables; + +var PrefixTables = require('./prefixTables.js').PrefixTables; + +class UnitString { + /** + * Constructor + */ + constructor() { + // Get instances of the unit and prefix tables and the utilities + this.utabs_ = UnitTables.getInstance(); + this.pfxTabs_ = PrefixTables.getInstance(); // Set emphasis characters to defaults. These are used to emphasize + // certain characters or strings in user messages. They can be reset in + // the useHTMLInMessages method. + + this.openEmph_ = Ucum.openEmph_; + this.closeEmph_ = Ucum.closeEmph_; // Set the braces message to blank. This message is displayed for each + // validation request on the web page, but is included separately as + // a note on the validation spreadsheet. The useBraceMsgForEachString + // method should be used to set the message to be displayed for each + // unit string. + + this.bracesMsg_ = ''; // Set the flags used, with indices, as place holders in unit strings + // for parenthetical strings and strings within braces. + + this.parensFlag_ = "parens_placeholder"; // in lieu of Jehoshaphat + + this.pFlagLen_ = this.parensFlag_.length; + this.braceFlag_ = "braces_placeholder"; // in lieu of Nebuchadnezzar + + this.bFlagLen_ = this.braceFlag_.length; // Initialize the message start/end strings, which will be set when + // parseString is called. + + this.vcMsgStart_ = null; + this.vcMsgEnd_ = null; // Arrays used by multiple methods within this class to hold persistent + // data. Just gets too bulky to pass these guys around. + // Messages to be returned to the calling function + + this.retMsg_ = []; // Units for parenthetical unit strings + + this.parensUnits_ = []; // annotation text for annotations found in unit strings + + this.annotations_ = []; // suggestions for unit strings that for which no unit was found + + this.suggestions = []; + } // end constructor + // The start of an error message about an invalid annotation character. + + + /** + * Sets the emphasis strings to the HTML used in the webpage display - or + * blanks them out, depending on the use parameter. + * + * @param use flag indicating whether or not to use the html message format; + * defaults to true + */ + useHTMLInMessages(use) { + if (use === undefined || use) { + this.openEmph_ = Ucum.openEmphHTML_; + this.closeEmph_ = Ucum.closeEmphHTML_; + } else { + this.openEmph_ = Ucum.openEmph_; + this.closeEmph_ = Ucum.closeEmph_; } - return ListTypeSpecifier; -}(expression_1.UnimplementedExpression)); -exports.ListTypeSpecifier = ListTypeSpecifier; -var NamedTypeSpecifier = /** @class */ (function (_super) { - __extends(NamedTypeSpecifier, _super); - function NamedTypeSpecifier() { - return _super !== null && _super.apply(this, arguments) || this; + } // end useHTMLInMessages + + /** + * Sets the braces message to be displayed for each unit string validation + * requested, as appropriate. + * + * @param use flag indicating whether or not to use the braces message; + * defaults to true + */ + + + useBraceMsgForEachString(use) { + if (use === undefined || use) this.bracesMsg_ = Ucum.bracesMsg_;else this.bracesMsg_ = ''; + } + /** + * Parses a unit string, returns a unit, a possibly updated version of + * the string passed in, and messages and suggestions where appropriate. + * + * The string returned may be updated if the input string contained unit + * names, e.g., "pound". The unit code ([lb_av] for pound) is placed in + * the string returned, a the returned messages array includes a note + * explaining the substitution. + * + * @param uStr the string defining the unit + * @param valConv indicates what type of request this is for - a request to + * validate (pass in 'validate') or a request to convert (pass in 'convert'); + * optional, defaults to 'validate' + * @param suggest a boolean to indicate whether or not suggestions are + * requested for a string that cannot be resolved to a valid unit; + * true indicates suggestions are wanted; false indicates they are not, + * and is the default if the parameter is not specified; + * @returns an array containing: + * the unit object or null if a unit could not be created. In cases where + * a fix was found for a problem string, .e.g., 2.mg for 2mg, a unit will + * be returned but an error message will also be returned, describing + * the substitution; + * the possibly updated unit string passed in; + * an array of any user messages (informational, error or warning) + * generated (or an empty array); and + * a suggestions array of hash objects (1 or more). Each hash contains + * three elements: + * 'msg' which is a message indicating what unit expression the + * suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions are + * for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + * The return array will not contain a suggestions array if a valid unit + * was found or if suggestions were not requested. + * @throws an error if nothing was specified. + */ + + + parseString(uStr, valConv, suggest) { + uStr = uStr.trim(); // Make sure we have something to work with + + if (uStr === '' || uStr === null) { + throw new Error('Please specify a unit expression to be validated.'); } - return NamedTypeSpecifier; -}(expression_1.UnimplementedExpression)); -exports.NamedTypeSpecifier = NamedTypeSpecifier; -var TupleTypeSpecifier = /** @class */ (function (_super) { - __extends(TupleTypeSpecifier, _super); - function TupleTypeSpecifier() { - return _super !== null && _super.apply(this, arguments) || this; + + if (valConv === 'validate') { + this.vcMsgStart_ = Ucum.valMsgStart_; + this.vcMsgEnd_ = Ucum.valMsgEnd_; + } else { + this.vcMsgStart_ = Ucum.cnvMsgStart_; + this.vcMsgEnd_ = Ucum.cnvMsgEnd_; } - return TupleTypeSpecifier; -}(expression_1.UnimplementedExpression)); -exports.TupleTypeSpecifier = TupleTypeSpecifier; -},{"../datatypes/clinical":56,"../datatypes/datetime":58,"../datatypes/quantity":62,"../datatypes/ratio":63,"../datatypes/uncertainty":64,"../util/math":104,"../util/util":106,"./expression":73}],93:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UnfilteredContext = exports.PatientContext = exports.Context = void 0; -var exception_1 = require("../datatypes/exception"); -var util_1 = require("../util/util"); -var dt = __importStar(require("../datatypes/datatypes")); -var messageListeners_1 = require("./messageListeners"); -var Context = /** @class */ (function () { - function Context(parent, _codeService, _parameters, executionDateTime, messageListener) { - this.parent = parent; - this._codeService = _codeService; - this.context_values = {}; - this.library_context = {}; - this.localId_context = {}; - this.evaluatedRecords = []; - // TODO: If there is an issue with number of parameters look into cql4browsers fix: 387ea77538182833283af65e6341e7a05192304c - this.checkParameters(_parameters !== null && _parameters !== void 0 ? _parameters : {}); // not crazy about possibly throwing an error in a constructor, but... - this._parameters = _parameters || {}; - this.executionDateTime = executionDateTime; - this.messageListener = messageListener; + if (suggest === undefined || suggest === false) { + this.suggestions_ = null; + } else { + this.suggestions_ = []; } - Object.defineProperty(Context.prototype, "parameters", { - get: function () { - return this._parameters || (this.parent && this.parent.parameters); - }, - set: function (params) { - this.checkParameters(params); - this._parameters = params; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(Context.prototype, "codeService", { - get: function () { - return this._codeService || (this.parent && this.parent.codeService); - }, - set: function (cs) { - this._codeService = cs; - }, - enumerable: false, - configurable: true - }); - Context.prototype.withParameters = function (params) { - this.parameters = params || {}; - return this; - }; - Context.prototype.withCodeService = function (cs) { - this.codeService = cs; - return this; - }; - Context.prototype.rootContext = function () { - if (this.parent) { - return this.parent.rootContext(); - } - else { - return this; - } - }; - Context.prototype.findRecords = function (profile, retrieveDetails) { - return this.parent && this.parent.findRecords(profile, retrieveDetails); - }; - Context.prototype.childContext = function (context_values) { - if (context_values === void 0) { context_values = {}; } - var ctx = new Context(this); - ctx.context_values = context_values; - return ctx; - }; - Context.prototype.getLibraryContext = function (library) { - return this.parent && this.parent.getLibraryContext(library); - }; - Context.prototype.getLocalIdContext = function (localId) { - return this.parent && this.parent.getLocalIdContext(localId); - }; - Context.prototype.getParameter = function (name) { - return this.parent && this.parent.getParameter(name); - }; - Context.prototype.getParentParameter = function (name) { - if (this.parent) { - if (this.parent.parameters[name] != null) { - return this.parent.parameters[name]; - } - else { - return this.parent.getParentParameter(name); - } - } - }; - Context.prototype.getTimezoneOffset = function () { - if (this.executionDateTime != null) { - return this.executionDateTime.timezoneOffset; - } - else if (this.parent && this.parent.getTimezoneOffset != null) { - return this.parent.getTimezoneOffset(); - } - else { - throw new exception_1.Exception('No Timezone Offset has been set'); - } - }; - Context.prototype.getExecutionDateTime = function () { - if (this.executionDateTime != null) { - return this.executionDateTime; - } - else if (this.parent && this.parent.getExecutionDateTime != null) { - return this.parent.getExecutionDateTime(); - } - else { - throw new exception_1.Exception('No Execution DateTime has been set'); - } - }; - Context.prototype.getMessageListener = function () { - if (this.messageListener != null) { - return this.messageListener; - } - else if (this.parent && this.parent.getMessageListener != null) { - return this.parent.getMessageListener(); - } - else { - return new messageListeners_1.NullMessageListener(); - } - }; - Context.prototype.getValueSet = function (name, library) { - return this.parent && this.parent.getValueSet(name, library); - }; - Context.prototype.getCodeSystem = function (name) { - return this.parent && this.parent.getCodeSystem(name); - }; - Context.prototype.getCode = function (name) { - return this.parent && this.parent.getCode(name); - }; - Context.prototype.getConcept = function (name) { - return this.parent && this.parent.getConcept(name); - }; - Context.prototype.get = function (identifier) { - // Check for undefined because if its null, we actually *do* want to return null (rather than - // looking at parent), but if it's really undefined, *then* look at the parent - if (typeof this.context_values[identifier] !== 'undefined') { - return this.context_values[identifier]; - } - else if (identifier === '$this') { - return this.context_values; - } - else { - return this.parent != null && this.parent.get(identifier); - } - }; - Context.prototype.set = function (identifier, value) { - this.context_values[identifier] = value; - }; - Context.prototype.setLocalIdWithResult = function (localId, value) { - // Temporary fix. Real fix will be to return a list of all result values for a given localId. - var ctx = this.localId_context[localId]; - if (ctx === false || ctx === null || ctx === undefined || ctx.length === 0) { - this.localId_context[localId] = value; - } - }; - Context.prototype.getLocalIdResult = function (localId) { - return this.localId_context[localId]; - }; - // Returns an object of objects containing each library name - // with the localIds and result values - Context.prototype.getAllLocalIds = function () { - var localIdResults = {}; - // Add the localIds and result values from the main library - localIdResults[this.parent.source.library.identifier.id] = {}; - localIdResults[this.parent.source.library.identifier.id] = this.localId_context; - // Iterate over support libraries and store localIds - for (var libName in this.library_context) { - var lib = this.library_context[libName]; - this.supportLibraryLocalIds(lib, localIdResults); - } - return localIdResults; - }; - // Recursive function that will grab nested support library localId results - Context.prototype.supportLibraryLocalIds = function (lib, localIdResults) { - var _this = this; - // Set library identifier name as the key and the object of localIds with their results as the value - // if it already exists then we need to merge the results instead of overwriting - if (localIdResults[lib.library.source.library.identifier.id] != null) { - this.mergeLibraryLocalIdResults(localIdResults, lib.library.source.library.identifier.id, lib.localId_context); - } - else { - localIdResults[lib.library.source.library.identifier.id] = lib.localId_context; - } - // Iterate over any support libraries in the current support library - Object.values(lib.library_context).forEach(function (supportLib) { - _this.supportLibraryLocalIds(supportLib, localIdResults); + + this.retMsg_ = []; + this.parensUnits_ = []; + this.annotations_ = []; + let origString = uStr; + let retObj = []; // Extract any annotations, i.e., text enclosed in braces ({}) from the + // string before further processing. Store each one in this.annotations_ + // array and put a placeholder in the string for the annotation. Do + // this before other processing in case an annotation contains characters + // that will be interpreted as parenthetical markers or operators in + // subsequent processing. + + uStr = this._getAnnotations(uStr); + + if (this.retMsg_.length > 0) { + retObj[0] = null; + retObj[1] = null; + } else { + // Flag used to block further processing on an unrecoverable error + let endProcessing = this.retMsg_.length > 0; // First check for one of the "special" units. If it's one of those, put + // in a substitution phrase for it to avoid having it separated on its + // embedded operator. This will only happen, by the way, if it is + // preceded by a prefix or followed by an operator and another unit. + + let sUnit = null; + + for (sUnit in Ucum.specUnits_) { + while (uStr.indexOf(sUnit) !== -1) uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]); + } // Check for spaces and throw an error if any are found. The spec + // explicitly forbids spaces except in annotations, which is why any + // annotations are extracted before this check is made. + + + if (uStr.indexOf(' ') > -1) { + throw new Error('Blank spaces are not allowed in unit expressions.'); + } // end if blanks were found in the string + // assign the array returned to retObj. It will contain 2 elements: + // the unit returned in position 0; and the origString (possibly + // modified) in position 1. The origString in position 1 will not + // be changed by subsequent processing. + + + retObj = this._parseTheString(uStr, origString); + let finalUnit = retObj[0]; // Do a final check to make sure that finalUnit is a unit and not + // just a number. Something like "8/{HCP}" will return a "unit" of 8 + // - which is not a unit. Hm - evidently it is. So just create a unit + // object for it. + + if (intUtils_.isIntegerUnit(finalUnit) || typeof finalUnit === 'number') { + finalUnit = new Unit({ + 'csCode_': origString, + 'ciCode_': origString, + 'magnitude_': finalUnit, + 'name_': origString }); - }; - // Merges the localId results for a library into the already collected results. The logic used for which result - // to keep is the same as the logic used above in setLocalIdWithResult, "falsey" results are always replaced. - Context.prototype.mergeLibraryLocalIdResults = function (localIdResults, libraryId, libraryResults) { - for (var localId in libraryResults) { - var localIdResult = libraryResults[localId]; - var existingResult = localIdResults[libraryId][localId]; - // overwite this localid result if the existing result is "falsey". future work could track all results for each localid - if (existingResult === false || - existingResult === null || - existingResult === undefined || - existingResult.length === 0) { - localIdResults[libraryId][localId] = localIdResult; - } - } - }; - Context.prototype.checkParameters = function (params) { - for (var pName in params) { - var pVal = params[pName]; - var pDef = this.getParameter(pName); - if (pVal == null) { - return; // Null can theoretically be any type - } - if (typeof pDef === 'undefined') { - return; // This will happen if the parameter is declared in a different (included) library - } - else if (pDef.parameterTypeSpecifier != null && - !this.matchesTypeSpecifier(pVal, pDef.parameterTypeSpecifier)) { - throw new Error("Passed in parameter '".concat(pName, "' is wrong type")); - } - else if (pDef['default'] != null && !this.matchesInstanceType(pVal, pDef['default'])) { - throw new Error("Passed in parameter '".concat(pName, "' is wrong type")); - } - } - return true; - }; - Context.prototype.matchesTypeSpecifier = function (val, spec) { - switch (spec.type) { - case 'NamedTypeSpecifier': - return this.matchesNamedTypeSpecifier(val, spec); - case 'ListTypeSpecifier': - return this.matchesListTypeSpecifier(val, spec); - case 'TupleTypeSpecifier': - return this.matchesTupleTypeSpecifier(val, spec); - case 'IntervalTypeSpecifier': - return this.matchesIntervalTypeSpecifier(val, spec); - case 'ChoiceTypeSpecifier': - return this.matchesChoiceTypeSpecifier(val, spec); - default: - return true; // default to true when we don't know - } - }; - Context.prototype.matchesListTypeSpecifier = function (val, spec) { - var _this = this; - return ((0, util_1.typeIsArray)(val) && val.every(function (x) { return _this.matchesTypeSpecifier(x, spec.elementType); })); - }; - Context.prototype.matchesTupleTypeSpecifier = function (val, spec) { - var _this = this; - // TODO: Spec is not clear about exactly how tuples should be matched - return (val != null && - typeof val === 'object' && - !(0, util_1.typeIsArray)(val) && - !val.isInterval && - !val.isConcept && - !val.isCode && - !val.isDateTime && - !val.isDate && - !val.isQuantity && - spec.element.every(function (x) { - return typeof val[x.name] === 'undefined' || - _this.matchesTypeSpecifier(val[x.name], x.elementType); - })); - }; - Context.prototype.matchesIntervalTypeSpecifier = function (val, spec) { - return (val.isInterval && - (val.low == null || this.matchesTypeSpecifier(val.low, spec.pointType)) && - (val.high == null || this.matchesTypeSpecifier(val.high, spec.pointType))); - }; - Context.prototype.matchesChoiceTypeSpecifier = function (val, spec) { - var _this = this; - return spec.choice.some(function (c) { return _this.matchesTypeSpecifier(val, c); }); - }; - Context.prototype.matchesNamedTypeSpecifier = function (val, spec) { - if (val == null) { - return true; - } - switch (spec.name) { - case '{urn:hl7-org:elm-types:r1}Boolean': - return typeof val === 'boolean'; - case '{urn:hl7-org:elm-types:r1}Decimal': - return typeof val === 'number'; - case '{urn:hl7-org:elm-types:r1}Integer': - return typeof val === 'number' && Math.floor(val) === val; - case '{urn:hl7-org:elm-types:r1}String': - return typeof val === 'string'; - case '{urn:hl7-org:elm-types:r1}Concept': - return val && val.isConcept; - case '{urn:hl7-org:elm-types:r1}Code': - return val && val.isCode; - case '{urn:hl7-org:elm-types:r1}DateTime': - return val && val.isDateTime; - case '{urn:hl7-org:elm-types:r1}Date': - return val && val.isDate; - case '{urn:hl7-org:elm-types:r1}Quantity': - return val && val.isQuantity; - case '{urn:hl7-org:elm-types:r1}Time': - return val && val.isTime && val.isTime(); - default: - // Use the data model's implementation of _is, if it is available - if (typeof val._is === 'function') { - return val._is(spec); - } - // If the value is an array or interval, then we assume it cannot be cast to a - // named type. Technically, this is not 100% true because a modelinfo can define - // a named type whose base type is a list or interval. But none of our models - // (FHIR, QDM, QICore) do that, so for those models, this approach will always be - // correct. - if (Array.isArray(val) || val.isInterval) { - return false; + retObj[0] = finalUnit; + } // end final check + + } // end if no annotation errors were found + + + retObj[2] = this.retMsg_; + if (this.suggestions_ && this.suggestions_.length > 0) retObj[3] = this.suggestions_; + return retObj; + } // end parseString + + /** + * Parses a unit string, returns a unit, a possibly updated version of + * the string passed in, and messages where appropriate. This should + * only be called from within this class (or by test code). + * + * The string returned may be updated if the input string contained unit + * names, e.g., "pound". The unit code ([lb_av] for pound) is placed in + * the string returned, a the returned messages array includes a note + * explaining the substitution. + * + * @param uStr the string defining the unit + * @param origString the original unit string passed in + * + * @returns + * an array containing: + * the unit object (or null if there were problems creating the unit); and + * the possibly updated unit string passed in. + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * the this.parensUnits_ array is referenced and possibly populated by + * methods called within this one + * the this.annotations_ array is referenced by methods called within + * this one + * the this.suggestions_ array may be populated by methods called within + * this one + */ + + + _parseTheString(uStr, origString) { + // Unit to be returned + let finalUnit = null; // Flag used to block further processing on an unrecoverable error + + let endProcessing = this.retMsg_.length > 0; // Call _processParens to search for and process any/all parenthetical + // strings in uStr. Units created for parenthetical strings will be + // stored in the this.parensUnits_ array. + + let parensResp = this._processParens(uStr, origString); + + endProcessing = parensResp[2]; // The array used to hold the units and their operators. + + let uArray = []; // Continue if we didn't hit a problem + + if (!endProcessing) { + uStr = parensResp[0]; + origString = parensResp[1]; // Call _makeUnitsArray to convert the string to an array of unit + // descriptors with operators. + + let mkUArray = this._makeUnitsArray(uStr, origString); + + endProcessing = mkUArray[2]; + + if (!endProcessing) { + uArray = mkUArray[0]; + origString = mkUArray[1]; // Create a unit object out of each un element + + let uLen = uArray.length; + + for (let u1 = 0; u1 < uLen; u1++) { + //for (let u1 = 0; u1 < uLen && !endProcessing; u1++) { + let curCode = uArray[u1]['un']; // Determine the type of the "un" attribute of the current array element + // Check to see if it's a number. If so write the number version of + // the number back to the "un" attribute and move on + + if (intUtils_.isIntegerUnit(curCode)) { + uArray[u1]['un'] = Number(curCode); + } else { + // The current unit array element is a string. Check now to see + // if it is or contains a parenthesized unit from this.parensUnits_. + // If so, call _getParens to process the string and get the unit. + if (curCode.indexOf(this.parensFlag_) >= 0) { + let parenUnit = this._getParensUnit(curCode, origString); // if we couldn't process the string, set the end flag and bypass + // further processing. + + + if (!endProcessing) endProcessing = parenUnit[1]; // If we're good, put the unit in the uArray and replace the + // curCode, which contains the parentheses placeholders, etc., + // with the unit's code - including any substitutions. + + if (!endProcessing) { + uArray[u1]['un'] = parenUnit[0]; + } + } // end if the curCode contains a parenthesized unit + // Else it's not a parenthetical unit and not a number. Call + // _makeUnit to create a unit for it. + else { + let uRet = this._makeUnit(curCode, origString); // If we didn't get a unit, set the endProcessing flag. + + + if (uRet[0] === null) { + endProcessing = true; + } else { + uArray[u1]['un'] = uRet[0]; + origString = uRet[1]; } - // Otherwise just default to true to match legacy behavior. - // - // NOTE: This is also where arbitrary tuples land because they will not have - // an "is" function and we don't encode the type information into the runtime - // objects so we can't easily determine their type. We can't reject them, - // else things like `Encounter{ id: "1" } is Encounter` would return false. - // So for now we allow false positives in order to avoid false negatives. - return true; - } - }; - Context.prototype.matchesInstanceType = function (val, inst) { - if (inst.isBooleanLiteral) { - return typeof val === 'boolean'; - } - else if (inst.isDecimalLiteral) { - return typeof val === 'number'; - } - else if (inst.isIntegerLiteral) { - return typeof val === 'number' && Math.floor(val) === val; - } - else if (inst.isStringLiteral) { - return typeof val === 'string'; - } - else if (inst.isCode) { - return val && val.isCode; - } - else if (inst.isConcept) { - return val && val.isConcept; - } - else if (inst.isTime && inst.isTime()) { - return val && val.isTime && val.isTime(); - } - else if (inst.isDate) { - return val && val.isDate; - } - else if (inst.isDateTime) { - return val && val.isDateTime; - } - else if (inst.isQuantity) { - return val && val.isQuantity; - } - else if (inst.isList) { - return this.matchesListInstanceType(val, inst); - } - else if (inst.isTuple) { - return this.matchesTupleInstanceType(val, inst); - } - else if (inst.isInterval) { - return this.matchesIntervalInstanceType(val, inst); - } - return true; // default to true when we don't know for sure - }; - Context.prototype.matchesListInstanceType = function (val, list) { - var _this = this; - return ((0, util_1.typeIsArray)(val) && val.every(function (x) { return _this.matchesInstanceType(x, list.elements[0]); })); - }; - Context.prototype.matchesTupleInstanceType = function (val, tpl) { - var _this = this; - return (typeof val === 'object' && - !(0, util_1.typeIsArray)(val) && - tpl.elements.every(function (x) { - return typeof val[x.name] === 'undefined' || _this.matchesInstanceType(val[x.name], x.value); - })); - }; - Context.prototype.matchesIntervalInstanceType = function (val, ivl) { - var pointType = ivl.low != null ? ivl.low : ivl.high; - return (val.isInterval && - (val.low == null || this.matchesInstanceType(val.low, pointType)) && - (val.high == null || this.matchesInstanceType(val.high, pointType))); - }; - return Context; -}()); -exports.Context = Context; -var PatientContext = /** @class */ (function (_super) { - __extends(PatientContext, _super); - function PatientContext(library, patient, codeService, parameters, executionDateTime, messageListener) { - if (executionDateTime === void 0) { executionDateTime = dt.DateTime.fromJSDate(new Date()); } - if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } - var _this = _super.call(this, library, codeService, parameters, executionDateTime, messageListener) || this; - _this.library = library; - _this.patient = patient; - return _this; + } // end if the curCode is not a parenthetical expression + + } // end if the "un" array is a not a number + + } // end do for each element in the units array + + } // end if _makeUnitsArray did not return an error + + } // end if _processParens did not find an error that causes a stop + // If we're still good, continue + + + if (!endProcessing) { + // Process the units (and numbers) to create one final unit object + if ((uArray[0] === null || uArray[0] === ' ' || uArray[0]['un'] === undefined || uArray[0]['un'] === null) && this.retMsg_.length === 0) { + // not sure what this might be, but this is a safeguard + this.retMsg_.push(`Unit string (${origString}) did not contain ` + `anything that could be used to create a unit, or else something ` + `that is not handled yet by this package. Sorry`); + endProcessing = true; + } } - PatientContext.prototype.rootContext = function () { - return this; - }; - PatientContext.prototype.getLibraryContext = function (library) { - if (this.library_context[library] == null) { - this.library_context[library] = new PatientContext(this.get(library), this.patient, this.codeService, this.parameters, this.executionDateTime); - } - return this.library_context[library]; - }; - PatientContext.prototype.getLocalIdContext = function (localId) { - if (this.localId_context[localId] == null) { - this.localId_context[localId] = new PatientContext(this.get(localId), this.patient, this.codeService, this.parameters, this.executionDateTime); - } - return this.localId_context[localId]; - }; - PatientContext.prototype.findRecords = function (profile, retrieveDetails) { - return this.patient && this.patient.findRecords(profile, retrieveDetails); - }; - return PatientContext; -}(Context)); -exports.PatientContext = PatientContext; -var UnfilteredContext = /** @class */ (function (_super) { - __extends(UnfilteredContext, _super); - function UnfilteredContext(library, results, codeService, parameters, executionDateTime, messageListener) { - if (executionDateTime === void 0) { executionDateTime = dt.DateTime.fromJSDate(new Date()); } - if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } - var _this = _super.call(this, library, codeService, parameters, executionDateTime, messageListener) || this; - _this.library = library; - _this.results = results; - return _this; + + if (!endProcessing) { + finalUnit = this._performUnitArithmetic(uArray, origString); } - UnfilteredContext.prototype.rootContext = function () { - return this; - }; - UnfilteredContext.prototype.findRecords = function (_template) { - throw new exception_1.Exception('Retreives are not currently supported in Unfiltered Context'); - }; - UnfilteredContext.prototype.getLibraryContext = function (_library) { - throw new exception_1.Exception('Library expressions are not currently supported in Unfiltered Context'); - }; - UnfilteredContext.prototype.get = function (identifier) { - //First check to see if the identifier is a unfiltered context expression that has already been cached - if (this.context_values[identifier]) { - return this.context_values[identifier]; - } - //if not look to see if the library has a unfiltered expression of that identifier - if (this.library[identifier] && this.library[identifier].context === 'Unfiltered') { - return this.library.expressions[identifier]; + + return [finalUnit, origString]; + } // end _parseTheString + + /** + * Extracts all annotations from a unit string, replacing them with + * placeholders for later evaluation. The annotations are stored in the + * this.annotations_ array. This should only be called from within this + * class (or by test code). + * + * @param uString the unit string being parsed + * @returns the string after the annotations are replaced with placeholders + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * the this.annotations_ array is populated by this method + */ + + + _getAnnotations(uString) { + let openBrace = uString.indexOf('{'); + + while (openBrace >= 0) { + let closeBrace = uString.indexOf('}'); + + if (closeBrace < 0) { + this.retMsg_.push('Missing closing brace for annotation starting at ' + this.openEmph_ + uString.substr(openBrace) + this.closeEmph_); + openBrace = -1; + } else { + let braceStr = uString.substring(openBrace, closeBrace + 1); // Check for valid characters in the annotation. + + if (!UnitString.VALID_ANNOTATION_REGEX.test(braceStr)) { + this.retMsg_.push(UnitString.INVALID_ANNOTATION_CHAR_MSG + this.openEmph_ + braceStr + this.closeEmph_); + openBrace = -1; // end search for annotations + } else { + let aIdx = this.annotations_.length.toString(); + uString = uString.replace(braceStr, this.braceFlag_ + aIdx + this.braceFlag_); + this.annotations_.push(braceStr); + openBrace = uString.indexOf('{'); } - //lastley attempt to gather all patient level results that have that identifier - // should this compact null values before return ? - return Object.values(this.results.patientResults).map(function (pr) { return pr[identifier]; }); - }; - return UnfilteredContext; -}(Context)); -exports.UnfilteredContext = UnfilteredContext; + } + } // end do while we have an opening brace + // check for a stray/unmatched closing brace -},{"../datatypes/datatypes":57,"../datatypes/exception":59,"../util/util":106,"./messageListeners":95}],94:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Executor = void 0; -var messageListeners_1 = require("./messageListeners"); -var results_1 = require("./results"); -var context_1 = require("./context"); -var Executor = /** @class */ (function () { - function Executor(library, codeService, parameters, messageListener) { - if (messageListener === void 0) { messageListener = new messageListeners_1.NullMessageListener(); } - this.library = library; - this.codeService = codeService; - this.parameters = parameters; - this.messageListener = messageListener; + + if (this.retMsg_.length == 0) { + // if there were no other errors above + let closeBrace = uString.indexOf('}'); + if (closeBrace >= 0) this.retMsg_.push('Missing opening brace for closing brace found at ' + this.openEmph_ + uString.substring(0, closeBrace + 1) + this.closeEmph_); } - Executor.prototype.withLibrary = function (lib) { - this.library = lib; - return this; - }; - Executor.prototype.withParameters = function (params) { - this.parameters = params != null ? params : {}; - return this; - }; - Executor.prototype.withCodeService = function (cs) { - this.codeService = cs; - return this; - }; - Executor.prototype.withMessageListener = function (ml) { - this.messageListener = ml; - return this; - }; - Executor.prototype.exec_expression = function (expression, patientSource, executionDateTime) { - var _a; - var r = new results_1.Results(); - var expr = this.library.expressions[expression]; - if (expr != null) { - while (patientSource.currentPatient()) { - var patient_ctx = new context_1.PatientContext(this.library, patientSource.currentPatient(), this.codeService, this.parameters, executionDateTime, this.messageListener); - r.recordPatientResults(patient_ctx, (_a = {}, _a[expression] = expr.execute(patient_ctx), _a)); - patientSource.nextPatient(); - } - } - return r; - }; - Executor.prototype.exec = function (patientSource, executionDateTime) { - var r = this.exec_patient_context(patientSource, executionDateTime); - var unfilteredContext = new context_1.UnfilteredContext(this.library, r, this.codeService, this.parameters, executionDateTime, this.messageListener); - var resultMap = {}; - for (var key in this.library.expressions) { - var expr = this.library.expressions[key]; - if (expr.context === 'Unfiltered') { - resultMap[key] = expr.exec(unfilteredContext); + + return uString; + } // end _getAnnotations + + /** + * Finds and processes any/all parenthesized unit strings. This should only + * be called from within this class (or by test code). + * + * Nested parenthesized strings are processed from the inside out. The + * parseString function is called from within this one for each parenthesized + * unit string, and the resulting unit object is stored in this.parensUnits_, + * to be processed after all strings are translated to units. + * + * A placeholder is placed in the unit string returned to indicate that the + * unit object should be obtained from the this.parensUnits_ array. The + * placeholder consists of the parenthesis flag (this.parensFlag_) followed + * by the index of the unit in this.parensUnits_ followed by this.parensFlag_. + * + * @param uString the unit string being parsed, where this will be the full + * string the first time this is called and parenthesized strings on any + * subsequent calls + * @param origString the original string first passed in to parseString + * @returns + * an array containing: + * the string after the parentheses are replaced; + * the original string; and + * a boolean flag indicating whether or not an error occurred that + * should stop processing. + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * this this.parensUnits_ array will be populated with units found for + * parenthetical unit strings + */ + + + _processParens(uString, origString) { + // Unit strings array and index + let uStrArray = []; + let uStrAryPos = 0; + let stopProcessing = false; + let pu = this.parensUnits_.length; // Count of characters trimmed off the beginning of the unit string (uString) + // as units are removed from it; used for error messages to provide + // context. + + let trimmedCt = 0; // Break the unit string into pieces that consist of text outside of + // parenthetical strings and placeholders for the parenthetical units. + // This method is called recursively for parenthetical strings and the units + // returned are stored in the this.parensUnits_ array. + + while (uString !== "" && !stopProcessing) { + let openCt = 0; + let closeCt = 0; + let openPos = uString.indexOf('('); // If an opening parenthesis was not found, check for an unmatched + // close parenthesis. If one was found report the error and end + // processing. + + if (openPos < 0) { + let closePos = uString.indexOf(')'); + + if (closePos >= 0) { + let theMsg = `Missing open parenthesis for close ` + `parenthesis at ${uString.substring(0, closePos + trimmedCt)}` + `${this.openEmph_}${uString.substr(closePos, 1)}${this.closeEmph_}`; + + if (closePos < uString.length - 1) { + theMsg += `${uString.substr(closePos + 1)}`; + } + + this.retMsg_.push(theMsg); + uStrArray[uStrAryPos] = uString; + stopProcessing = true; + } // end if a close parenthesis was found + // If no parentheses were found in the current unit string, transfer + // it to the units array and blank out the string, which will end + // the search for parenthetical units. + else { + uStrArray[uStrAryPos] = uString; + uString = ""; + } // end if no close parenthesis was found + + } // end if no open parenthesis was found + // Otherwise an open parenthesis was found. Process the string that + // includes the parenthetical group + else { + openCt += 1; // Write the text before the parentheses (if any) to the unit strings array + + let uLen = uString.length; + + if (openPos > 0) { + uStrArray[uStrAryPos++] = uString.substr(0, openPos); + } // Find the matching closePos, i.e., the one that closes the + // parenthetical group that this one opens. Look also for + // another open parenthesis, in case this includes nested parenthetical + // strings. This continues until it finds the same number of close + // parentheses as open parentheses, or runs out of string to check. + // In the case of nested parentheses this will identify the outer set + // of parentheses. + + + let closePos = 0; + let c = openPos + 1; + + for (; c < uLen && openCt != closeCt; c++) { + if (uString[c] === '(') openCt += 1;else if (uString[c] === ')') closeCt += 1; + } // Put a placeholder for the group in the unit strings array and recursively + // call this method for the parenthetical group. Put the unit returned + // in this.parensUnits_. Set the unit string to whatever follows + // the position of the closing parenthesis for this group, to be + // processed by the next iteration of this loop. If there's nothing + // left uString is set to "". + + + if (openCt === closeCt) { + closePos = c; + uStrArray[uStrAryPos++] = this.parensFlag_ + pu.toString() + this.parensFlag_; + + let parseResp = this._parseTheString(uString.substring(openPos + 1, closePos - 1), origString); + + if (parseResp[0] === null) stopProcessing = true;else { + origString = parseResp[1]; + this.parensUnits_[pu++] = parseResp[0]; + uString = uString.substr(closePos); + trimmedCt = closePos; } - } - r.recordUnfilteredResults(resultMap); - return r; - }; - Executor.prototype.exec_patient_context = function (patientSource, executionDateTime) { - var r = new results_1.Results(); - while (patientSource.currentPatient()) { - var patient_ctx = new context_1.PatientContext(this.library, patientSource.currentPatient(), this.codeService, this.parameters, executionDateTime, this.messageListener); - var resultMap = {}; - for (var key in this.library.expressions) { - var expr = this.library.expressions[key]; - if (expr.context === 'Patient') { - resultMap[key] = expr.execute(patient_ctx); - } + } // end if the number of open and close parentheses matched + // If the number of open and close parentheses doesn't match, indicate + // an error. + else { + uStrArray.push(origString.substr(openPos)); + this.retMsg_.push(`Missing close parenthesis for open parenthesis at ` + `${origString.substring(0, openPos + trimmedCt)}` + `${this.openEmph_}${origString.substr(openPos, 1)}` + `${this.closeEmph_}${origString.substr(openPos + 1)}`); + stopProcessing = true; } - r.recordPatientResults(patient_ctx, resultMap); - patientSource.nextPatient(); - } - return r; - }; - return Executor; -}()); -exports.Executor = Executor; + } // end if an open parenthesis was found + + } // end do while the input string is not empty + + + if (stopProcessing) this.parensUnits_ = []; + return [uStrArray.join(''), origString, stopProcessing]; + } // end _processParens + + /** + * Breaks the unit string into an array of unit descriptors and operators. + * If a unit descriptor consists of a number preceding a unit code, with + * no multiplication operator, e.g., 2mg instead of 2.mg, it is handled + * as if it were a parenthetical expression. + * + * This should only be called from within this class (or by test code). + * + * @param uStr the unit string being parsed + * @param origString the original string passed to parseString + * @returns + * an array containing: + * the array representing the unit string; + * the original string passed in, possibly updated with corrections; and + * and a flag indicating whether or not processing can continue. + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + */ + + + _makeUnitsArray(uStr, origString) { + // Separate the string into pieces based on delimiters / (division) and . + // (multiplication). The idea is to get an array of units on which we + // can then perform any operations (prefixes, multiplication, division). + let uArray1 = uStr.match(/([./]|[^./]+)/g); + let endProcessing = false; + let uArray = []; + let startNumCheck = /(^[0-9]+)(\[?[a-zA-Z\_0-9a-zA-Z\_]+\]?$)/; // If the first element in the array is the division operator (/), the + // string started with '/'. Add a first element containing 1 to the + // array, which will cause the correct computation to be performed (inversion). -},{"./context":93,"./messageListeners":95,"./results":97}],95:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ConsoleMessageListener = exports.NullMessageListener = void 0; -var NullMessageListener = /** @class */ (function () { - function NullMessageListener() { - } - NullMessageListener.prototype.onMessage = function (_source, _code, _severity, _message) { - // do nothing - }; - return NullMessageListener; -}()); -exports.NullMessageListener = NullMessageListener; -var ConsoleMessageListener = /** @class */ (function () { - function ConsoleMessageListener(logSourceOnTrace) { - if (logSourceOnTrace === void 0) { logSourceOnTrace = false; } - this.logSourceOnTrace = logSourceOnTrace; - } - ConsoleMessageListener.prototype.onMessage = function (source, code, severity, message) { - // eslint-disable-next-line no-console - var print = severity === 'Error' ? console.error : console.log; - var content = "".concat(severity, ": [").concat(code, "] ").concat(message); - if (severity === 'Trace' && this.logSourceOnTrace) { - content += "\n<<<<< SOURCE:\n".concat(JSON.stringify(source), "\n>>>>>"); + if (uArray1[0] === "/") { + uArray1.unshift("1"); + } // If the first element in the array is the multiplication operator (.) + // return an error. + else if (uArray1[0] === '.') { + this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `The multiplication operator at the beginning of the expression is ` + `not valid. A multiplication operator must appear only between ` + `two codes.`); + endProcessing = true; + } + + if (!endProcessing) { + // Check to see if there is a number preceding a unit code, e.g., 2mg + // If so, update the first element to remove the number (2mg -> mg) and + // add two elements to the beginning of the array - the number and the + // multiplication operator. + if (!intUtils_.isNumericString(uArray1[0])) { + let numRes = uArray1[0].match(startNumCheck); + + if (numRes && numRes.length === 3 && numRes[1] !== '' && numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) { + let dispVal = numRes[2]; + + if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) { + let parensback = this._getParensUnit(numRes[2], origString); + + numRes[2] = parensback[0]['csCode_']; + dispVal = `(${numRes[2]})`; + endProcessing = parensback[1]; + } + + if (!endProcessing) { + this.retMsg_.push(`${numRes[1]}${dispVal} is not a valid UCUM code.` + ` ${this.vcMsgStart_}${numRes[1]}.${dispVal}${this.vcMsgEnd_}`); + origString = origString.replace(`${numRes[1]}${dispVal}`, `${numRes[1]}.${dispVal}`); + uArray1[0] = numRes[2]; + uArray1.unshift(numRes[1], '.'); + } } - print(content); - }; - return ConsoleMessageListener; -}()); -exports.ConsoleMessageListener = ConsoleMessageListener; + } // end if the first element is not a number (only) + // Create an array of unit/operator objects. The unit is, for now, the + // string containing the unit code (e.g., Hz for hertz) including + // a possible prefix and exponent. The operator is the operator to be + // applied to that unit and the one preceding it. So, a.b would give + // us two objects. The first will have a unit of a, and a blank operator + // (because it's the first unit). The second would have a unit of b + // and the multiplication operator (.). -},{}],96:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Repository = void 0; -var library_1 = require("../elm/library"); -var Repository = /** @class */ (function () { - function Repository(data) { - this.data = data; - this.libraries = Array.from(Object.values(data)); - } - Repository.prototype.resolve = function (path, version) { - for (var _i = 0, _a = this.libraries; _i < _a.length; _i++) { - var lib = _a[_i]; - if (lib.library && lib.library.identifier) { - var _b = lib.library.identifier, id = _b.id, system = _b.system, libraryVersion = _b.version; - var libraryUri = "".concat(system, "/").concat(id); - if (path === libraryUri || path === id) { - if (version) { - if (libraryVersion === version) { - return new library_1.Library(lib, this); - } - } - else { - return new library_1.Library(lib, this); - } + + if (!endProcessing) { + let u1 = uArray1.length; + uArray = [{ + op: "", + un: uArray1[0] + }]; + + for (let n = 1; n < u1; n++) { + // check to make sure that we don't have two operators together, e.g., + // mg./K. If so, let the user know the problem. + let theOp = uArray1[n++]; // oh wait - check to make sure something is even there, that the + // user didn't end the expression with an operator. + + if (!uArray1[n]) { + this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `It is terminated with the operator ${this.openEmph_}` + `${theOp}${this.closeEmph_}.`); + n = u1; + endProcessing = true; + } else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) { + this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `A unit code is missing between${this.openEmph_}` + `${theOp}${this.closeEmph_}and${this.openEmph_}` + `${uArray1[n]}${this.closeEmph_}in${this.openEmph_}` + `${theOp}${uArray1[n]}${this.closeEmph_}.`); + n = u1; + endProcessing = true; + } else { + // Check to see if a number precedes a unit code. + // If so, send the element to _processParens, inserting the multiplication + // operator where it belongs. Treating it as parenthetical keeps it from + // being interpreted incorrectly because of operator parentheses. For + // example, if the whole string is mg/2kJ we don't want to rewrite it as + // mg/2.kJ - because mg/2 would be performed, followed by .kJ. Instead, + // handling 2kJ as a parenthesized unit will make sure mg is divided by + // 2.kJ. + if (!intUtils_.isNumericString(uArray1[n])) { + let numRes2 = uArray1[n].match(startNumCheck); + + if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' && numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) { + let invalidString = numRes2[0]; + + if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) { + let parensback = this._getParensUnit(numRes2[2], origString); + + numRes2[2] = parensback[0]['csCode_']; + invalidString = `(${numRes2[2]})`; + endProcessing = parensback[1]; + + if (!endProcessing) { + this.retMsg_.push(`${numRes2[1]}${invalidString} is not a ` + `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${invalidString}` + `${this.vcMsgEnd_}`); + let parensString = `(${numRes2[1]}.${invalidString})`; + origString = origString.replace(`${numRes2[1]}${invalidString}`, parensString); + + let nextParens = this._processParens(parensString, origString); + + endProcessing = nextParens[2]; + + if (!endProcessing) { + uArray.push({ + op: theOp, + un: nextParens[0] + }); + } //uArray.push({op: '.', un: numRes2[2]}); + + } + } // end if the string represents a parenthesized unit + else { + let parensStr = '(' + numRes2[1] + '.' + numRes2[2] + ')'; + + let parensResp = this._processParens(parensStr, origString); // if a "stop processing" flag was returned, set the n index to end + // the loop and set the endProcessing flag + + + if (parensResp[2]) { + n = u1; + endProcessing = true; + } else { + this.retMsg_.push(`${numRes2[0]} is not a ` + `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${numRes2[2]}` + `${this.vcMsgEnd_}`); + origString = origString.replace(numRes2[0], parensStr); + uArray.push({ + op: theOp, + un: parensResp[0] + }); + } // end if no error on the processParens call + + } // end if the string does not represent a parenthesized unit + + } // end if the string is a number followed by a string + else { + uArray.push({ + op: theOp, + un: uArray1[n] + }); } + } else { + uArray.push({ + op: theOp, + un: uArray1[n] + }); } - } - }; - return Repository; -}()); -exports.Repository = Repository; + } // end if there isn't a missing operator or unit code -},{"../elm/library":78}],97:[function(require,module,exports){ -"use strict"; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Results = void 0; -var Results = /** @class */ (function () { - function Results() { - this.patientResults = {}; - this.unfilteredResults = {}; - this.localIdPatientResultsMap = {}; - this.patientEvaluatedRecords = {}; + } // end do for each element in uArray1 + + } // end if a processing error didn't occur in getParensUnit + + } // end if the string did not begin with a '.' with no following digit + + + return [uArray, origString, endProcessing]; + } // end _makeUnitsArray + + /** + * Takes a unit string containing parentheses flags and returns the unit they + * represent. Any text found before and/or after the parenthetical + * expression is checked to see if we can tell what the user meant and + * let them know what it should have been. For example, 2(mg), which + * would resolve to 2mg, should be 2.mg. + * + * This should only be called from within this class (or by test code). + * + * @param pStr the string being parsed + * @param origString the original unit string passed in; passed through + * to _getAnnonText if annotation flags are found in any text preceding + * or following the parenthetical unit + * @returns + * an array containing + * the unit object; and + * a flag indicating whether or not processing should be ended. + * True indicates that the string was invalid and no corrections + * (substitutions or suggestions) could be found; + * False indicates that it was either valid or substitutions/suggestions + * were made. + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * this this.parensUnits_ array contains the units that are acquired by + * this method + * @throws an error if an invalid parensUnit index was found. This is + * a processing error. + */ + + + _getParensUnit(pStr, origString) { + let endProcessing = false; + let retAry = []; + let retUnit = null; + let befAnnoText = null; + let aftAnnoText = null; // Get the location of the flags. We're assuming there are only two + // because _processParens takes care of nesting. By the time we get + // here we should not be looking a nested parens. Also get any text + // before and after the parentheses. Once we get the unit we update + // the input string with the unit's csCode_, which will wipe out any + // before and after text + + let psIdx = pStr.indexOf(this.parensFlag_); + let befText = null; + + if (psIdx > 0) { + befText = pStr.substr(0, psIdx - 1); } - Object.defineProperty(Results.prototype, "evaluatedRecords", { - // Expose an evaluatedRecords array for backwards compatibility - get: function () { - return [].concat.apply([], Object.values(this.patientEvaluatedRecords)); - }, - enumerable: false, - configurable: true - }); - Results.prototype.recordPatientResults = function (patient_ctx, resultMap) { - var _this = this; - var p = patient_ctx.patient; - // NOTE: From now on prefer getId() over id() because some data models may have an id property - // that is not a string (e.g., FHIR) -- so reserve getId() for the API (and expect a string - // representation) but leave id() for data-model specific formats. - var patientId = typeof p.getId === 'function' ? p.getId() : p.id(); - // Record the results - this.patientResults[patientId] = resultMap; - // Record the local IDs - this.localIdPatientResultsMap[patientId] = patient_ctx.getAllLocalIds(); - // Record the evaluatedRecords, merging with an aggregated array across all libraries - this.patientEvaluatedRecords[patientId] = __spreadArray([], patient_ctx.evaluatedRecords, true); - Object.values(patient_ctx.library_context).forEach(function (ctx) { - var _a; - (_a = _this.patientEvaluatedRecords[patientId]).push.apply(_a, ctx.evaluatedRecords); + + let peIdx = pStr.lastIndexOf(this.parensFlag_); + let aftText = null; + + if (peIdx + this.pFlagLen_ < pStr.length) { + aftText = pStr.substr(peIdx + this.pFlagLen_); + } // Get the text between the flags + + + let pNumText = pStr.substring(psIdx + this.pFlagLen_, peIdx); // Make sure the index is a number, and if it is, get the unit from the + // this.parensUnits_ array + + if (intUtils_.isNumericString(pNumText)) { + retUnit = this.parensUnits_[Number(pNumText)]; + + if (!intUtils_.isIntegerUnit(retUnit)) { + pStr = retUnit.csCode_; + } else { + pStr = retUnit; + } + } // If it's not a number, it's a programming error. Throw a fit. + else { + throw new Error(`Processing error - invalid parens number ${pNumText} ` + `found in ${pStr}.`); + } // If there's something in front of the starting parentheses flag, check to + // see if it's a number or an annotation. + + + if (befText) { + // If it's a number, assume that multiplication was assumed + if (intUtils_.isNumericString(befText)) { + let nMag = retUnit.getProperty('magnitude_'); + nMag *= Number(befText); + retUnit.assignVals({ + 'magnitude_': nMag }); - }; - Results.prototype.recordUnfilteredResults = function (resultMap) { - this.unfilteredResults = resultMap; - }; - return Results; -}()); -exports.Results = Results; + pStr = `${befText}.${pStr}`; + this.retMsg_.push(`${befText}${pStr} is not a valid UCUM code.\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); + } else { + if (befText.indexOf(this.braceFlag_) >= 0) { + let annoRet = this._getAnnoText(befText, origString); // if we found not only an annotation, but text before or after + // the annotation (remembering that this is all before the + // parentheses) throw an error - because we don't know what + // to do with it. Could it be missing an operator? -},{}],98:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -},{}],99:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); + if (annoRet[1] || annoRet[2]) { + throw new Error(`Text found before the parentheses (` + `${befText}) included an annotation along with other text ` + `for parenthetical unit ${retUnit.csCode_}`); + } // Otherwise put the annotation after the unit string and note + // the misplacement. + + + pStr += annoRet[0]; + this.retMsg_.push(`The annotation ${annoRet[0]} before the unit ` + `code is invalid.\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); + } // else the text before the parentheses is neither a number nor + // an annotation. If suggestions were NOT requested, record an + // error. + else if (!this.suggestions_) { + this.retMsg_.push(`${befText} preceding the unit code ${pStr} ` + `is invalid. Unable to make a substitution.`); + endProcessing = true; + } // otherwise try for suggestions + else { + let suggestStat = this._getSuggestions(befText); + + endProcessing = suggestStat !== 'succeeded'; + } // end if a brace was found or, if not, suggestions were not or + // were requested + + } // end if text preceding the parentheses was not a number + + } // end if there was text before the parentheses + // Process any text after the parentheses + + + if (aftText) { + // if it's an annotation, get it and add it to the pStr + if (aftText.indexOf(this.braceFlag_) >= 0) { + let annoRet = this._getAnnoText(aftText, origString); // if we found not only an annotation, but text before or after + // the annotation (remembering that this is all after the + // parentheses) throw an error - because we don't know what + // to do with it. Could it be missing an operator? + + + if (annoRet[1] || annoRet[2]) { + throw new Error(`Text found after the parentheses (` + `${aftText}) included an annotation along with other text ` + `for parenthetical unit ${retUnit.csCode_}`); + } // Otherwise put the annotation after the unit string - no message + // needed. + + + pStr += annoRet[0]; + } // Otherwise check to see if it's an exponent. If so, warn the + // user that it's not valid - but try it anyway + else { + if (intUtils_.isNumericString(aftText)) { + pStr += aftText; + retUnit = retUnit.power(Number(aftText)); + this.retMsg_.push(`An exponent (${aftText}) following a parenthesis ` + `is invalid as of revision 1.9 of the UCUM Specification.\n ` + this.vcMsgStart_ + pStr + this.vcMsgEnd_); + } // else the text after the parentheses is neither a number nor + // an annotation. If suggestions were NOT requested, record an + // error. + else if (!this.suggestions_) { + this.retMsg_.push(`Text ${aftText} following the unit code ${pStr} ` + `is invalid. Unable to make a substitution.`); + endProcessing = true; + } // otherwise try for suggestions + else { + let suggestStat = this._getSuggestions(befText); + + endProcessing = suggestStat !== 'succeeded'; + } // end if text following the parentheses not an exponent + + } // end if text following the parentheses is not an annotation + + } // end if there is text following the parentheses + + + if (!endProcessing) { + if (!retUnit) { + retUnit = new Unit({ + 'csCode_': pStr, + 'magnitude_': 1, + 'name_': pStr + }); + } else if (intUtils_.isIntegerUnit(retUnit)) { + retUnit = new Unit({ + 'csCode_': retUnit, + 'magnitude_': retUnit, + 'name_': retUnit + }); + } else { + retUnit.csCode_ = pStr; + } + } + + return [retUnit, endProcessing]; + } // end _getParensUnit + + /** + * Takes a unit string containing annotation flags and returns the + * annotation they represent. This also returns any text found before + * the annotation and any found after the annotation. + * + * This should only be called from within this class (or by test code). + * NEEDS FIX in next branch to handle string with multiple annotations. + * + * @param pStr the string being parsed + * @param origString the original string being parsed; used in error msg + * thrown for an invalid index to the annotations array + * @returns + * an array containing + * the annotation for the pStr; + * any text found before the annotation; and + * any text found after the annotation. + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * the this.annotations_ array is used as the source for the annotations text + * @throws an error if for a processing error - an invalid annotation index. + */ + + + _getAnnoText(pStr, origString) { + // if the starting braces flag is not at index 0, get the starting + // text and the adjust the pStr to omit it. + let asIdx = pStr.indexOf(this.braceFlag_); + let startText = asIdx > 0 ? pStr.substring(0, asIdx) : null; + + if (asIdx !== 0) { + pStr = pStr.substr(asIdx); + } // Get the location of the end flag and, if text follows it, get the text + + + let aeIdx = pStr.indexOf(this.braceFlag_, 1); + let endText = aeIdx + this.bFlagLen_ < pStr.length ? pStr.substr(aeIdx + this.bFlagLen_) : null; // Get the index of the annotation in this.annotations_. + // Check it to make sure it's valid, and if not, throw an error + + let idx = pStr.substring(this.bFlagLen_, aeIdx); + let idxNum = Number(idx); + + if (!intUtils_.isNumericString(idx) || idxNum >= this.annotations_.length) { + throw new Error(`Processing Error - invalid annotation index ${idx} found ` + `in ${pStr} that was created from ${origString}`); + } // Replace the flags and annotation index with the annotation expression + + + pStr = this.annotations_[idxNum]; + return [pStr, startText, endText]; + } // end _getAnnoText + + /** + * Takes a unit string and looks for suggested units. This should be + * called for unit strings that cannot be resolved to unit codes. The + * string is searched for in the synonyms table found in the UnitTables + * class. That table includes all synonyms and unit names for the units + * in the unit data table. + * + * @param pStr the string being parsed + * @returns an object that contains an element named 'status', whose + * value indicates the status of the request: + * 'succeeded' indicates that synonyms were found; + * 'failed' indicates that no synonyms were found; or + * 'error' which indicates that an error occurred + * + * the this.retMsg_ array will be updated with a message indicating whether + * or not synonyms/suggestions were found + * the this.suggestions_ array will be updated with a hash (added to the + * array if it already contains others) that contains three elements: + * 'msg' which is a message indicating what unit expression the + * suggestions are for; + * 'invalidUnit' which is the unit expression the suggestions are for; and + * 'units' which is an array of data for each suggested unit found. + * Each array will contain the unit code, the unit name and the + * unit guidance (if any). + */ + -},{}],100:[function(require,module,exports){ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./cql-code-service.interfaces"), exports); -__exportStar(require("./cql-patient.interfaces"), exports); -__exportStar(require("./runtime.types"), exports); -__exportStar(require("./type-specifiers.interfaces"), exports); + _getSuggestions(pStr) { + let retObj = intUtils_.getSynonyms(pStr); -},{"./cql-code-service.interfaces":98,"./cql-patient.interfaces":99,"./runtime.types":101,"./type-specifiers.interfaces":102}],101:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); + if (retObj['status'] === 'succeeded') { + let suggSet = {}; + suggSet['msg'] = `${pStr} is not a valid UCUM code. We found possible ` + `units that might be what was meant:`; + suggSet['invalidUnit'] = pStr; + let synLen = retObj['units'].length; + suggSet['units'] = []; -},{}],102:[function(require,module,exports){ -"use strict"; -// Types derived from http://cql.hl7.org/04-logicalspecification.html#typespecifier -Object.defineProperty(exports, "__esModule", { value: true }); + for (let s = 0; s < synLen; s++) { + let unit = retObj['units'][s]; + let unitArray = [unit['code'], unit['name'], unit['guidance']]; + suggSet['units'].push(unitArray); + } -},{}],103:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.equals = exports.equivalent = exports.greaterThanOrEquals = exports.greaterThan = exports.lessThanOrEquals = exports.lessThan = void 0; -var datatypes_1 = require("../datatypes/datatypes"); -function areNumbers(a, b) { - return typeof a === 'number' && typeof b === 'number'; -} -function areStrings(a, b) { - return typeof a === 'string' && typeof b === 'string'; -} -function areDateTimesOrQuantities(a, b) { - return ((a && a.isDateTime && b && b.isDateTime) || - (a && a.isDate && b && b.isDate) || - (a && a.isQuantity && b && b.isQuantity)); -} -function isUncertainty(x) { - return x instanceof datatypes_1.Uncertainty; -} -function lessThan(a, b, precision) { - if (areNumbers(a, b) || areStrings(a, b)) { - return a < b; - } - else if (areDateTimesOrQuantities(a, b)) { - return a.before(b, precision); - } - else if (isUncertainty(a)) { - return a.lessThan(b); - } - else if (isUncertainty(b)) { - return datatypes_1.Uncertainty.from(a).lessThan(b); - } - else { - return null; - } -} -exports.lessThan = lessThan; -function lessThanOrEquals(a, b, precision) { - if (areNumbers(a, b) || areStrings(a, b)) { - return a <= b; - } - else if (areDateTimesOrQuantities(a, b)) { - return a.sameOrBefore(b, precision); - } - else if (isUncertainty(a)) { - return a.lessThanOrEquals(b); - } - else if (isUncertainty(b)) { - return datatypes_1.Uncertainty.from(a).lessThanOrEquals(b); - } - else { - return null; - } -} -exports.lessThanOrEquals = lessThanOrEquals; -function greaterThan(a, b, precision) { - if (areNumbers(a, b) || areStrings(a, b)) { - return a > b; - } - else if (areDateTimesOrQuantities(a, b)) { - return a.after(b, precision); - } - else if (isUncertainty(a)) { - return a.greaterThan(b); - } - else if (isUncertainty(b)) { - return datatypes_1.Uncertainty.from(a).greaterThan(b); - } - else { - return null; - } -} -exports.greaterThan = greaterThan; -function greaterThanOrEquals(a, b, precision) { - if (areNumbers(a, b) || areStrings(a, b)) { - return a >= b; - } - else if (areDateTimesOrQuantities(a, b)) { - return a.sameOrAfter(b, precision); - } - else if (isUncertainty(a)) { - return a.greaterThanOrEquals(b); - } - else if (isUncertainty(b)) { - return datatypes_1.Uncertainty.from(a).greaterThanOrEquals(b); - } - else { - return null; - } -} -exports.greaterThanOrEquals = greaterThanOrEquals; -function equivalent(a, b) { - if (a == null && b == null) { - return true; - } - if (a == null || b == null) { - return false; - } - if (isCode(a)) { - return codesAreEquivalent(a, b); - } - // Quantity equivalence is the same as Quantity equality - if (a.isQuantity) { - return a.equals(b); - } - // Use overloaded 'equivalent' function if it is available - if (typeof a.equivalent === 'function') { - return a.equivalent(b); - } - var _a = getClassOfObjects(a, b), aClass = _a[0], bClass = _a[1]; - switch (aClass) { - case '[object Array]': - return compareEveryItemInArrays(a, b, equivalent); - case '[object Object]': - return compareObjects(a, b, equivalent); - case '[object String]': - // Make sure b is also a string - if (bClass === '[object String]') { - // String equivalence is case- and locale insensitive - a = a.replace(/\s/g, ' '); - b = b.replace(/\s/g, ' '); - return a.localeCompare(b, 'en', { sensitivity: 'base' }) === 0; - } - break; - } - return equals(a, b); -} -exports.equivalent = equivalent; -function isCode(object) { - return object.hasMatch && typeof object.hasMatch === 'function'; -} -function codesAreEquivalent(code1, code2) { - return code1.hasMatch(code2); -} -function getClassOfObjects(object1, object2) { - return [object1, object2].map(function (obj) { return ({}.toString.call(obj)); }); -} -function compareEveryItemInArrays(array1, array2, comparisonFunction) { - return (array1.length === array2.length && - array1.every(function (item, i) { return comparisonFunction(item, array2[i]); })); -} -function compareObjects(a, b, comparisonFunction) { - if (!classesEqual(a, b)) { - return false; - } - return deepCompareKeysAndValues(a, b, comparisonFunction); -} -function classesEqual(object1, object2) { - return object2 instanceof object1.constructor && object1 instanceof object2.constructor; -} -function deepCompareKeysAndValues(a, b, comparisonFunction) { - var finalComparisonResult; - var aKeys = getKeysFromObject(a).sort(); - var bKeys = getKeysFromObject(b).sort(); - // Array.every() will only return true or false, so set a flag for if we should return null - var shouldReturnNull = false; - // Check if both arrays of keys are the same length and key names match - if (aKeys.length === bKeys.length && aKeys.every(function (value, index) { return value === bKeys[index]; })) { - finalComparisonResult = aKeys.every(function (key) { - // if both are null we should return true to satisfy ignoring empty values in tuples - if (a[key] == null && b[key] == null) { - return true; - } - var comparisonResult = comparisonFunction(a[key], b[key]); - if (comparisonResult === null) { - shouldReturnNull = true; - } - return comparisonResult; - }); - } - else { - finalComparisonResult = false; - } - if (shouldReturnNull) { - return null; - } - return finalComparisonResult; -} -function getKeysFromObject(object) { - return Object.keys(object).filter(function (k) { return !isFunction(object[k]); }); -} -function isFunction(input) { - return input instanceof Function || {}.toString.call(input) === '[object Function]'; -} -function equals(a, b) { - // Handle null cases first: spec says if either is null, return null - if (a == null || b == null) { - return null; - } - // If one is a Quantity, use the Quantity equals function - if (a && a.isQuantity) { - return a.equals(b); - } - // If one is a Ratio, use the ratio equals function - if (a && a.isRatio) { - return a.equals(b); - } - // If one is an Uncertainty, convert the other to an Uncertainty - if (a instanceof datatypes_1.Uncertainty) { - b = datatypes_1.Uncertainty.from(b); - } - else if (b instanceof datatypes_1.Uncertainty) { - a = datatypes_1.Uncertainty.from(a); - } - // Use overloaded 'equals' function if it is available - if (typeof a.equals === 'function') { - return a.equals(b); - } - // Return true of the objects are primitives and are strictly equal - if ((typeof a === typeof b && typeof a === 'string') || - typeof a === 'number' || - typeof a === 'boolean') { - return a === b; - } - // Return false if they are instances of different classes - var _a = getClassOfObjects(a, b), aClass = _a[0], bClass = _a[1]; - if (aClass !== bClass) { - return false; - } - switch (aClass) { - case '[object Date]': - // Compare the ms since epoch - return a.getTime() === b.getTime(); - case '[object RegExp]': - // Compare the components of the regular expression - return ['source', 'global', 'ignoreCase', 'multiline'].every(function (p) { return a[p] === b[p]; }); - case '[object Array]': - if (a.indexOf(null) >= 0 || - a.indexOf(undefined) >= 0 || - b.indexOf(null) >= 0 || - b.indexOf(undefined) >= 0) { - return null; - } - return compareEveryItemInArrays(a, b, equals); - case '[object Object]': - return compareObjects(a, b, equals); - case '[object Function]': - return a.toString() === b.toString(); + this.suggestions_.push(suggSet); + } else { + this.retMsg_.push(`${pStr} is not a valid UCUM code. No alternatives ` + `were found.`); } - // If we made it this far, we can't handle it - return false; -} -exports.equals = equals; -},{"../datatypes/datatypes":57}],104:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.decimalOrNull = exports.decimalAdjust = exports.minValueForType = exports.minValueForInstance = exports.maxValueForType = exports.maxValueForInstance = exports.predecessor = exports.successor = exports.OverFlowException = exports.limitDecimalPrecision = exports.isValidDecimal = exports.isValidInteger = exports.overflowsOrUnderflows = exports.MAX_TIME_VALUE = exports.MIN_TIME_VALUE = exports.MAX_DATE_VALUE = exports.MIN_DATE_VALUE = exports.MAX_DATETIME_VALUE = exports.MIN_DATETIME_VALUE = exports.MIN_FLOAT_PRECISION_VALUE = exports.MIN_FLOAT_VALUE = exports.MAX_FLOAT_VALUE = exports.MIN_INT_VALUE = exports.MAX_INT_VALUE = void 0; -/* eslint-disable @typescript-eslint/no-loss-of-precision */ -var exception_1 = require("../datatypes/exception"); -var datetime_1 = require("../datatypes/datetime"); -var uncertainty_1 = require("../datatypes/uncertainty"); -exports.MAX_INT_VALUE = Math.pow(2, 31) - 1; -exports.MIN_INT_VALUE = Math.pow(-2, 31); -exports.MAX_FLOAT_VALUE = 99999999999999999999.99999999; -exports.MIN_FLOAT_VALUE = -99999999999999999999.99999999; -exports.MIN_FLOAT_PRECISION_VALUE = Math.pow(10, -8); -exports.MIN_DATETIME_VALUE = datetime_1.MIN_DATETIME_VALUE; -exports.MAX_DATETIME_VALUE = datetime_1.MAX_DATETIME_VALUE; -exports.MIN_DATE_VALUE = datetime_1.MIN_DATE_VALUE; -exports.MAX_DATE_VALUE = datetime_1.MAX_DATE_VALUE; -exports.MIN_TIME_VALUE = datetime_1.MIN_TIME_VALUE; -exports.MAX_TIME_VALUE = datetime_1.MAX_TIME_VALUE; -function overflowsOrUnderflows(value) { - if (value == null) { - return false; - } - if (value.isQuantity) { - if (!isValidDecimal(value.value)) { - return true; - } - } - else if (value.isTime && value.isTime()) { - if (value.after(exports.MAX_TIME_VALUE)) { - return true; - } - if (value.before(exports.MIN_TIME_VALUE)) { - return true; - } - } - else if (value.isDateTime) { - if (value.after(exports.MAX_DATETIME_VALUE)) { - return true; - } - if (value.before(exports.MIN_DATETIME_VALUE)) { - return true; - } - } - else if (value.isDate) { - if (value.after(exports.MAX_DATE_VALUE)) { - return true; - } - if (value.before(exports.MIN_DATE_VALUE)) { - return true; - } - } - else if (Number.isInteger(value)) { - if (!isValidInteger(value)) { - return true; - } - } - else if (value.isUncertainty) { - return overflowsOrUnderflows(value.low) || overflowsOrUnderflows(value.high); - } - else { - if (!isValidDecimal(value)) { - return true; - } - } - return false; -} -exports.overflowsOrUnderflows = overflowsOrUnderflows; -function isValidInteger(integer) { - if (isNaN(integer)) { - return false; - } - if (integer > exports.MAX_INT_VALUE) { - return false; - } - if (integer < exports.MIN_INT_VALUE) { - return false; - } - return true; -} -exports.isValidInteger = isValidInteger; -function isValidDecimal(decimal) { - if (isNaN(decimal)) { - return false; - } - if (decimal > exports.MAX_FLOAT_VALUE) { - return false; - } - if (decimal < exports.MIN_FLOAT_VALUE) { - return false; - } - return true; -} -exports.isValidDecimal = isValidDecimal; -function limitDecimalPrecision(decimal) { - var decimalString = decimal.toString(); - // For decimals so large that they are represented in scientific notation, javascript has already limited - // the decimal to its own constraints, so we can't determine the original precision. Leave as-is unless - // this becomes problematic, in which case we would need our own parseFloat. - if (decimalString.indexOf('e') !== -1) { - return decimal; - } - var splitDecimalString = decimalString.split('.'); - var decimalPoints = splitDecimalString[1]; - if (decimalPoints != null && decimalPoints.length > 8) { - decimalString = splitDecimalString[0] + '.' + splitDecimalString[1].substring(0, 8); - } - return parseFloat(decimalString); -} -exports.limitDecimalPrecision = limitDecimalPrecision; -var OverFlowException = /** @class */ (function (_super) { - __extends(OverFlowException, _super); - function OverFlowException() { - return _super !== null && _super.apply(this, arguments) || this; - } - return OverFlowException; -}(exception_1.Exception)); -exports.OverFlowException = OverFlowException; -function successor(val) { - if (typeof val === 'number') { - if (Number.isInteger(val)) { - if (val >= exports.MAX_INT_VALUE) { - throw new OverFlowException(); - } - else { - return val + 1; - } - } - else { - if (val >= exports.MAX_FLOAT_VALUE) { - throw new OverFlowException(); - } - else { - return val + exports.MIN_FLOAT_PRECISION_VALUE; - } - } - } - else if (val && val.isTime && val.isTime()) { - if (val.sameAs(exports.MAX_TIME_VALUE)) { - throw new OverFlowException(); - } - else { - return val.successor(); - } - } - else if (val && val.isDateTime) { - if (val.sameAs(exports.MAX_DATETIME_VALUE)) { - throw new OverFlowException(); - } - else { - return val.successor(); - } - } - else if (val && val.isDate) { - if (val.sameAs(exports.MAX_DATE_VALUE)) { - throw new OverFlowException(); - } - else { - return val.successor(); - } - } - else if (val && val.isUncertainty) { - // For uncertainties, if the high is the max val, don't increment it - var high = (function () { - try { - return successor(val.high); - } - catch (e) { - return val.high; - } - })(); - return new uncertainty_1.Uncertainty(successor(val.low), high); - } - else if (val && val.isQuantity) { - var succ = val.clone(); - succ.value = successor(val.value); - return succ; - } - else if (val == null) { - return null; - } -} -exports.successor = successor; -function predecessor(val) { - if (typeof val === 'number') { - if (Number.isInteger(val)) { - if (val <= exports.MIN_INT_VALUE) { - throw new OverFlowException(); - } - else { - return val - 1; + return retObj['status']; + } // end getSuggestions + + /** + * Creates a unit object from a string defining one unit. The string + * should consist of a unit code for a unit already defined (base or + * otherwise). It may include a prefix and an exponent, e.g., cm2 + * (centimeter squared). This should only be called from within this + * class (or by test code). + * + * @params uCode the string defining the unit + * @param origString the original string to be parsed; used to provide + * context for messages + * @returns + * an array containing: + * a unit object, or null if there were problems creating the unit; and + * the origString passed in, which may be updated if a unit name was + * translated to a unit code. + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + * the this.suggestions_ array will be populated if no unit (with or without + * substitutions) could be found and suggestions were requested + */ + + + _makeUnit(uCode, origString) { + // First try the code just as is, without looking for annotations, + // prefixes, exponents, or elephants. + let retUnit = this.utabs_.getUnitByCode(uCode); + + if (retUnit) { + retUnit = retUnit.clone(); + } // If we found it, we're done. No need to parse for those elephants (or + // other stuff). + else if (uCode.indexOf(this.braceFlag_) >= 0) { + let getAnnoRet = this._getUnitWithAnnotation(uCode, origString); + + retUnit = getAnnoRet[0]; + + if (retUnit) { + origString = getAnnoRet[1]; + } // If a unit is not found, retUnit will be returned null and + // the this.retMsg_ array will contain a message describing the problem. + // If a unit is found, of course, all is good. So ... nothing left + // to see here, move along. + + } // end if the uCode includes an annotation + else { + // So we didn't find a unit for the full uCode or for one with + // annotations. Try looking for a unit that uses a carat (^) + // instead of an asterisk (*) + if (uCode.indexOf('^') > -1) { + let tryCode = uCode.replace('^', '*'); + retUnit = this.utabs_.getUnitByCode(tryCode); + + if (retUnit) { + retUnit = retUnit.clone(); + retUnit.csCode_ = retUnit.csCode_.replace('*', '^'); + retUnit.ciCode_ = retUnit.ciCode_.replace('*', '^'); } - } - else { - if (val <= exports.MIN_FLOAT_VALUE) { - throw new OverFlowException(); + } // If that didn't work, check to see if it should have brackets + // around it (uCode = degF when it should be [degF] + + + if (!retUnit) { + let addBrackets = '[' + uCode + ']'; + retUnit = this.utabs_.getUnitByCode(addBrackets); + + if (retUnit) { + retUnit = retUnit.clone(); + origString = origString.replace(uCode, addBrackets); + this.retMsg_.push(`${uCode} is not a valid unit expression, but ` + `${addBrackets} is.\n` + this.vcMsgStart_ + `${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`); + } // end if we found the unit after adding brackets + + } // end trying to add brackets + // If we didn't find it, try it as a name + + + if (!retUnit) { + let retUnitAry = this.utabs_.getUnitByName(uCode); + + if (retUnitAry && retUnitAry.length > 0) { + retUnit = retUnitAry[0].clone(); + let mString = 'The UCUM code for ' + uCode + ' is ' + retUnit.csCode_ + '.\n' + this.vcMsgStart_ + retUnit.csCode_ + this.vcMsgEnd_; + let dupMsg = false; + + for (let r = 0; r < this.retMsg_.length && !dupMsg; r++) dupMsg = this.retMsg_[r] === mString; + + if (!dupMsg) this.retMsg_.push(mString); + let rStr = new RegExp('(^|[.\/({])(' + uCode + ')($|[.\/)}])'); + let res = origString.match(rStr); + origString = origString.replace(rStr, res[1] + retUnit.csCode_ + res[3]); + uCode = retUnit.csCode_; } - else { - return val - exports.MIN_FLOAT_PRECISION_VALUE; + } // If we still don't have a unit, try assuming a modifier (prefix and/or + // exponent) and look for a unit without the modifier + + + if (!retUnit) { + // Well, first see if it's one of the special units. If so, + // replace the placeholder text with the actual unit string, keeping + // whatever text (probably a prefix) goes with the unit string. + let sUnit = null; + + for (sUnit in Ucum.specUnits_) { + if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1) uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit); } + + retUnit = this.utabs_.getUnitByCode(uCode); + if (retUnit) retUnit = retUnit.clone(); + } + + if (!retUnit) { + let origCode = uCode; + let origUnit = null; + let exp = null; + let pfxCode = null; + let pfxObj = null; + let pfxVal = null; + let pfxExp = null; // Look first for an exponent. If we got one, separate it out and + // try to get the unit again + + let codeAndExp = this._isCodeWithExponent(uCode); + + if (codeAndExp) { + uCode = codeAndExp[0]; + exp = codeAndExp[1]; + origUnit = this.utabs_.getUnitByCode(uCode); + } // If we still don't have a unit, separate out the prefix, if any, + // and try without it. + + + if (!origUnit) { + // Try for a single character prefix first. + pfxCode = uCode.charAt(0); + pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode); // if we got a prefix, get its info and remove it from the unit code + + if (pfxObj) { + pfxVal = pfxObj.getValue(); + pfxExp = pfxObj.getExp(); + let pCodeLen = pfxCode.length; + uCode = uCode.substr(pCodeLen); // try again for the unit + + origUnit = this.utabs_.getUnitByCode(uCode); // If we still don't have a unit, see if the prefix could be the + // two character "da" (deka) prefix. That's the only prefix with + // two characters, and without this check it's interpreted as "d" + // (deci) and the "a" is considered part of the unit code. + + if (!origUnit && pfxCode == 'd' && uCode.substr(0, 1) == 'a') { + pfxCode = 'da'; + pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode); + pfxVal = pfxObj.getValue(); + uCode = uCode.substr(1); // try one more time for the unit + + origUnit = this.utabs_.getUnitByCode(uCode); + } // Reject the unit we found if it might have another prefix. + // Such things are in our tables through the LOINC source_ + // (ucum.csv) which has guidance and synonyms. I think it should be + // safe to exclude anything whose source is LOINC from having a + // prefix. + + + if (origUnit && origUnit.source_ == 'LOINC') origUnit = null; + } // end if we found a prefix + + } // end if we didn't get a unit after removing an exponent + // If we still haven't found anything, we're done looking. + // (We tried with the full unit string, with the unit string + // without the exponent, the unit string without a prefix, + // common errors, etc. That's all we can try). + + + if (!origUnit) { + retUnit = null; // BUT if the user asked for suggestions, at least look for them + + if (this.suggestions_) { + let suggestStat = this._getSuggestions(origCode); + } else { + this.retMsg_.push(`${origCode} is not a valid UCUM code.`); + } + } else { + // Otherwise we found a unit object. Clone it and then apply the + // prefix and exponent, if any, to it. And remove the guidance. + retUnit = origUnit.clone(); // If we are here, this is only part of the full unit string, so it is + // not a base unit, and the synonyms will mostly likely not be correct for the full + // string. + + retUnit.resetFieldsForDerivedUnit(); + let theDim = retUnit.getProperty('dim_'); + let theMag = retUnit.getProperty('magnitude_'); + let theName = retUnit.getProperty('name_'); + let theCiCode = retUnit.getProperty('ciCode_'); + let thePrintSymbol = retUnit.getProperty('printSymbol_'); // If there is an exponent for the unit, apply it to the dimension + // and magnitude now + + if (exp) { + exp = parseInt(exp); + let expMul = exp; + if (theDim) theDim = theDim.mul(exp); + theMag = Math.pow(theMag, exp); + retUnit.assignVals({ + 'magnitude_': theMag + }); // If there is also a prefix, apply the exponent to the prefix. + + if (pfxObj) { + // if the prefix base is 10 it will have an exponent. Multiply + // the current prefix exponent by the exponent for the unit + // we're working with. Then raise the prefix value to the level + // defined by the exponent. + if (pfxExp) { + expMul *= pfxObj.getExp(); + pfxVal = Math.pow(10, expMul); + } // If the prefix base is not 10, it won't have an exponent. + // At the moment I don't see any units using the prefixes + // that aren't base 10. But if we get one the prefix value + // will be applied to the magnitude (below) if the unit does + // not have a conversion function, and to the conversion prefix + // if it does. + + } // end if there's a prefix as well as the exponent + + } // end if there's an exponent + // Now apply the prefix, if there is one, to the conversion + // prefix or the magnitude + + + if (pfxObj) { + if (retUnit.cnv_) { + retUnit.assignVals({ + 'cnvPfx_': pfxVal + }); + } else { + theMag *= pfxVal; + retUnit.assignVals({ + 'magnitude_': theMag + }); + } + } // if we have a prefix and/or an exponent, add them to the unit + // attributes - name, csCode, ciCode and print symbol + + + let theCode = retUnit.csCode_; + + if (pfxObj) { + theName = pfxObj.getName() + theName; + theCode = pfxCode + theCode; + theCiCode = pfxObj.getCiCode() + theCiCode; + thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol; + retUnit.assignVals({ + 'name_': theName, + 'csCode_': theCode, + 'ciCode_': theCiCode, + 'printSymbol_': thePrintSymbol + }); + } + + if (exp) { + let expStr = exp.toString(); + retUnit.assignVals({ + 'name_': theName + '' + expStr + '', + 'csCode_': theCode + expStr, + 'ciCode_': theCiCode + expStr, + 'printSymbol_': thePrintSymbol + '' + expStr + '' + }); + } + } // end if an original unit was found (without prefix and/or exponent) + + } // end if we didn't get a unit for the full unit code (w/out modifiers) + + } // end if we didn't find the unit on the first try, before parsing + + + return [retUnit, origString]; + } // end _makeUnit + + /** + * This method handles unit creation when an annotation is included + * in the unit string. This basically isolates and retrieves the + * annotation and then calls _makeUnit to try to get a unit from + * any text that precedes or follows the annotation. + * + * @param uCode the string defining the unit + * @param origString the original full string submitted to parseString + * @returns the unit object found, or null if one could not be found + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + */ + + + _getUnitWithAnnotation(uCode, origString) { + let retUnit = null; // Get the annotation and anything that precedes or follows it. + + let annoRet = this._getAnnoText(uCode, origString); + + let annoText = annoRet[0]; + let befAnnoText = annoRet[1]; + let aftAnnoText = annoRet[2]; // Add the warning about annotations - just once. + + if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1) this.retMsg_.push(this.bracesMsg_); // If there's no text before or after the annotation, it's probably + // something that should be interpreted as a 1, e.g., {KCT'U}. + // HOWEVER, it could also be a case where someone used braces instead + // of brackets, e.g., {degF} instead of [degF]. Check for that before + // we assume it should be a 1. + + let msgLen = this.retMsg_.length; + + if (!befAnnoText && !aftAnnoText) { + let tryBrackets = '[' + annoText.substring(1, annoText.length - 1) + ']'; + + let mkUnitRet = this._makeUnit(tryBrackets, origString); // If we got back a unit, assign it to the returned unit, and add + // a message to advise the user that brackets should enclose the code + + + if (mkUnitRet[0]) { + retUnit = mkUnitRet[0]; + origString = origString.replace(annoText, tryBrackets); + this.retMsg_.push(`${annoText} is not a valid unit expression, but ` + `${tryBrackets} is.\n` + this.vcMsgStart_ + `${tryBrackets} (${retUnit.name_})${this.vcMsgEnd_}`); + } // Otherwise assume that this should be interpreted as a 1 + else { + // remove error message generated for trybrackets + if (this.retMsg_.length > msgLen) { + this.retMsg_.pop(); + } + + uCode = 1; + retUnit = 1; } - } - else if (val && val.isTime && val.isTime()) { - if (val.sameAs(exports.MIN_TIME_VALUE)) { - throw new OverFlowException(); - } - else { - return val.predecessor(); - } - } - else if (val && val.isDateTime) { - if (val.sameAs(exports.MIN_DATETIME_VALUE)) { - throw new OverFlowException(); - } - else { - return val.predecessor(); - } - } - else if (val && val.isDate) { - if (val.sameAs(exports.MIN_DATE_VALUE)) { - throw new OverFlowException(); - } - else { - return val.predecessor(); - } - } - else if (val && val.isUncertainty) { - // For uncertainties, if the low is the min val, don't decrement it - var low = (function () { - try { - return predecessor(val.low); + } // end if it's only an annotation + else { + // if there's text before and no text after, assume the text before + // the annotation is the unit code (with an annotation following it). + // Call _makeUnit for the text before the annotation. + if (befAnnoText && !aftAnnoText) { + // make sure that what's before the annoText is not a number, e.g., + // /100{cells}. But f it is a number, just set the return unit to + // the number. + if (intUtils_.isIntegerUnit(befAnnoText)) { + retUnit = befAnnoText; + } // Otherwise try to find a unit + else { + let mkUnitRet = this._makeUnit(befAnnoText, origString); // if a unit was returned + + + if (mkUnitRet[0]) { + retUnit = mkUnitRet[0]; + retUnit.csCode_ += annoText; + origString = mkUnitRet[1]; + } // Otherwise add a not found message + else { + this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` + `precedes the annotation ${annoText}.`); + } } - catch (e) { - return val.low; + } // else if there's only text after the annotation, try for a unit + // from the after text and assume the user put the annotation in + // the wrong place (and tell them) + else if (!befAnnoText && aftAnnoText) { + // Again, test for a number and if it is a number, set the return + // unit to the number. + if (intUtils_.isIntegerUnit(aftAnnoText)) { + retUnit = aftAnnoText + annoText; + this.retMsg_.push(`The annotation ${annoText} before the ``${aftAnnoText} is invalid.\n` + this.vcMsgStart_ + retUnit + this.vcMsgEnd_); + } else { + let mkUnitRet = this._makeUnit(aftAnnoText, origString); + + if (mkUnitRet[0]) { + retUnit = mkUnitRet[0]; + retUnit.csCode_ += annoText; + origString = retUnit.csCode_; + this.retMsg_.push(`The annotation ${annoText} before the unit ` + `code is invalid.\n` + this.vcMsgStart_ + retUnit.csCode_ + this.vcMsgEnd_); + } // Otherwise add a not found message + else { + this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` + `follows the annotation ${annoText}.`); + } } - })(); - return new uncertainty_1.Uncertainty(low, predecessor(val.high)); - } - else if (val && val.isQuantity) { - var pred = val.clone(); - pred.value = predecessor(val.value); - return pred; - } - else if (val == null) { - return null; - } -} -exports.predecessor = predecessor; -function maxValueForInstance(val) { - if (typeof val === 'number') { - if (Number.isInteger(val)) { - return exports.MAX_INT_VALUE; - } - else { - return exports.MAX_FLOAT_VALUE; - } - } - else if (val && val.isTime && val.isTime()) { - return exports.MAX_TIME_VALUE === null || exports.MAX_TIME_VALUE === void 0 ? void 0 : exports.MAX_TIME_VALUE.copy(); - } - else if (val && val.isDateTime) { - return exports.MAX_DATETIME_VALUE === null || exports.MAX_DATETIME_VALUE === void 0 ? void 0 : exports.MAX_DATETIME_VALUE.copy(); - } - else if (val && val.isDate) { - return exports.MAX_DATE_VALUE === null || exports.MAX_DATE_VALUE === void 0 ? void 0 : exports.MAX_DATE_VALUE.copy(); - } - else if (val && val.isQuantity) { - var val2 = val.clone(); - val2.value = maxValueForInstance(val2.value); - return val2; - } - else { - return null; - } -} -exports.maxValueForInstance = maxValueForInstance; -function maxValueForType(type, quantityInstance) { - switch (type) { - case '{urn:hl7-org:elm-types:r1}Integer': - return exports.MAX_INT_VALUE; - case '{urn:hl7-org:elm-types:r1}Decimal': - return exports.MAX_FLOAT_VALUE; - case '{urn:hl7-org:elm-types:r1}DateTime': - return exports.MAX_DATETIME_VALUE === null || exports.MAX_DATETIME_VALUE === void 0 ? void 0 : exports.MAX_DATETIME_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Date': - return exports.MAX_DATE_VALUE === null || exports.MAX_DATE_VALUE === void 0 ? void 0 : exports.MAX_DATE_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Time': - return exports.MAX_TIME_VALUE === null || exports.MAX_TIME_VALUE === void 0 ? void 0 : exports.MAX_TIME_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Quantity': { - if (quantityInstance == null) { - // can't infer a quantity unit type from nothing] - return null; + } // else it's got text before AND after the annotation. Now what? + // For now this is an error. This may be a case of a missing + // operator but that is not handled yet. + else { + this.retMsg_.push(`Unable to find a unit for ${befAnnoText}${annoText}` + `${aftAnnoText}.\nWe are not sure how to interpret text both before ` + `and after the annotation. Sorry`); } - var maxQty = quantityInstance.clone(); - maxQty.value = maxValueForInstance(maxQty.value); - return maxQty; - } + } // else if there's text before/and or after the annotation + + + return [retUnit, origString]; + } // end _getUnitWithAnnotations + + /** + * Performs unit arithmetic for the units in the units array. That array + * contains units/numbers and the operators (division or multiplication) to + * be performed on each unit/unit or unit/number pair in the array. This + * should only be called from within this class (or by test code). + * + * @params uArray the array that contains the units, numbers and operators + * derived from the unit string passed in to parseString + * @param origString the original string to be parsed; used to provide + * context for messages + * + * @returns a single unit object that is the result of the unit arithmetic + * + * the this.retMsg_ array will be updated with any user messages + * (informational, error or warning) generated by this or called methods + */ + + + _performUnitArithmetic(uArray, origString) { + let finalUnit = uArray[0]['un']; + + if (intUtils_.isIntegerUnit(finalUnit)) { + finalUnit = new Unit({ + 'csCode_': finalUnit, + 'ciCode_': finalUnit, + 'magnitude_': Number(finalUnit), + 'name_': finalUnit + }); } - return null; -} -exports.maxValueForType = maxValueForType; -function minValueForInstance(val) { - if (typeof val === 'number') { - if (Number.isInteger(val)) { - return exports.MIN_INT_VALUE; + + let uLen = uArray.length; + let endProcessing = false; // Perform the arithmetic for the units, starting with the first 2 units. + // We only need to do the arithmetic if we have more than one unit. + + for (let u2 = 1; u2 < uLen && !endProcessing; u2++) { + let nextUnit = uArray[u2]['un']; + + if (intUtils_.isIntegerUnit(nextUnit)) { + nextUnit = new Unit({ + 'csCode_': nextUnit, + 'ciCode_': nextUnit, + 'magnitude_': Number(nextUnit), + 'name_': nextUnit + }); + } + + if (nextUnit === null || typeof nextUnit !== 'number' && !nextUnit.getProperty) { + let msgString = `Unit string (${origString}) contains unrecognized ` + 'element'; + + if (nextUnit) { + msgString += ` (${this.openEmph_}${nextUnit.toString()}` + `${this.closeEmph_})`; } - else { - return exports.MIN_FLOAT_VALUE; + + msgString += '; could not parse full string. Sorry'; + this.retMsg_.push(msgString); + endProcessing = true; + } else { + try { + // Is the operation division? + let thisOp = uArray[u2]['op']; + let isDiv = thisOp === '/'; // Perform the operation. Both the finalUnit and nextUnit + // are unit objects. + + isDiv ? finalUnit = finalUnit.divide(nextUnit) : finalUnit = finalUnit.multiplyThese(nextUnit); + } catch (err) { + this.retMsg_.unshift(err.message); + endProcessing = true; + finalUnit = null; } - } - else if (val && val.isTime && val.isTime()) { - return exports.MIN_TIME_VALUE === null || exports.MIN_TIME_VALUE === void 0 ? void 0 : exports.MIN_TIME_VALUE.copy(); - } - else if (val && val.isDateTime) { - return exports.MIN_DATETIME_VALUE === null || exports.MIN_DATETIME_VALUE === void 0 ? void 0 : exports.MIN_DATETIME_VALUE.copy(); - } - else if (val && val.isDate) { - return exports.MIN_DATE_VALUE === null || exports.MIN_DATE_VALUE === void 0 ? void 0 : exports.MIN_DATE_VALUE.copy(); - } - else if (val && val.isQuantity) { - var val2 = val.clone(); - val2.value = minValueForInstance(val2.value); - return val2; - } + } // end if we have another valid unit/number to process + + } // end do for each unit after the first one + + + return finalUnit; + } // end _performUnitArithmetic + + /** + * This tests a string to see if it starts with characters and ends with + * digits. This is used to test for an exponent on a UCUM code (or what + * we think might be a UCUM code). This is broken out to a separate + * function so that the regular expression can be verified to provide the + * results we expect, in case someone changes it. (Per Paul Lynch) + * See "Test _isCodeWithExponent method" in testUnitString.spec.js + * + * This particular regex has been tweaked several times. This one + * works with the following test strings: + * "m[H2O]-21 gives ["m[H2O]-21", "m[H2O]", "-21"] + * "m[H2O]+21 gives ["m[H2O]+21", "m[H2O]", "+21"] + * "m[H2O]21 gives ["m[H2O]-21", "m[H2O]", "21"] + * "s2" gives ["s2", "s, "2"] + * "kg" gives null + * "m[H2O]" gives null + * "m[H2O]23X" gives null + * + * @params uCode the code being tested + * @returns an array containing: (1) the code without the exponent (or + * trailing number); and (2) the exponent/trailing number. Returns null + * if there is no trailing number or something follows the trailing + * number, or if the first part is not characters. + */ + + + _isCodeWithExponent(uCode) { + let ret = []; + let res = uCode.match(/(^[^\-\+]+?)([\-\+\d]+)$/); // If we got a return with an exponent, separate the exponent from the + // unit and return both (as separate values) + + if (res && res[2] && res[2] !== "") { + ret.push(res[1]); + ret.push(res[2]); + } // end if we got an exponent else { - return null; - } -} -exports.minValueForInstance = minValueForInstance; -function minValueForType(type, quantityInstance) { - switch (type) { - case '{urn:hl7-org:elm-types:r1}Integer': - return exports.MIN_INT_VALUE; - case '{urn:hl7-org:elm-types:r1}Decimal': - return exports.MIN_FLOAT_VALUE; - case '{urn:hl7-org:elm-types:r1}DateTime': - return exports.MIN_DATETIME_VALUE === null || exports.MIN_DATETIME_VALUE === void 0 ? void 0 : exports.MIN_DATETIME_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Date': - return exports.MIN_DATE_VALUE === null || exports.MIN_DATE_VALUE === void 0 ? void 0 : exports.MIN_DATE_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Time': - return exports.MIN_TIME_VALUE === null || exports.MIN_TIME_VALUE === void 0 ? void 0 : exports.MIN_TIME_VALUE.copy(); - case '{urn:hl7-org:elm-types:r1}Quantity': { - if (quantityInstance == null) { - // can't infer a quantity unit type from nothing] - return null; - } - var minQty = quantityInstance.clone(); - minQty.value = minValueForInstance(minQty.value); - return minQty; - } - } - return null; -} -exports.minValueForType = minValueForType; -function decimalAdjust(type, value, exp) { - //If the exp is undefined or zero... - if (typeof exp === 'undefined' || +exp === 0) { - return Math[type](value); - } - value = +value; - exp = +exp; - //If the value is not a number or the exp is not an integer... - if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) { - return NaN; - } - //Shift - value = value.toString().split('e'); - var v = value[1] ? +value[1] - exp : -exp; - value = Math[type](+(value[0] + 'e' + v)); - //Shift back - value = value.toString().split('e'); - v = value[1] ? +value[1] + exp : exp; - return +(value[0] + 'e' + v); -} -exports.decimalAdjust = decimalAdjust; -function decimalOrNull(value) { - return isValidDecimal(value) ? value : null; -} -exports.decimalOrNull = decimalOrNull; + ret = null; + } + + return ret; + } // end _isCodeWithExponent + + +} // end class UnitString + +/** + * This function exists ONLY until the original UnitString constructor + * is called for the first time. It's defined here in case getInstance + * is called before the constructor. This calls the constructor. + * + * The constructor redefines the getInstance function to return the + * singleton UnitString object. This is based on the UnitTables singleton + * implementation; see more detail in the UnitTables constructor description. + * + * @return the singleton UnitString object. + */ + + +exports.UnitString = UnitString; -},{"../datatypes/datetime":58,"../datatypes/exception":59,"../datatypes/uncertainty":64}],105:[function(require,module,exports){ +_defineProperty(UnitString, "INVALID_ANNOTATION_CHAR_MSG", 'An invalid character was found in the annotation '); + +// A regular expression for validating annotation strings. +_defineProperty(UnitString, "VALID_ANNOTATION_REGEX", /^\{[!-z|~]*\}$/); + +UnitString.getInstance = function () { + return new UnitString(); +}; +/* +// Perform the first request for the object, to set the getInstance method. +UnitString.getInstance(); + +*/ + + +},{"./config.js":94,"./prefixTables.js":98,"./ucumInternalUtils.js":100,"./unit.js":104,"./unitTables.js":106}],106:[function(require,module,exports){ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; + +Object.defineProperty(exports, "__esModule", { + value: true }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } +exports.UnitTables = void 0; + +/** + * This class manages Hashtables that provide references to + * defined units. + * + * @author Lee Mericle, based on java version by Gunther Schadow + * + */ +var Ucum = require('./config.js').Ucum; + +class UnitTablesFactory { + /** + * Constructor. This creates the empty unit tables (hashes) once. After the + * tables are created, it redefines this constructor to throw an error + * stating that the constructor is no longer available and that the + * getInstance function must be used. Here's a description of the first + * and then all subsequent calls to this constructor. + * + * First call to constructor: + * 1. creates OBJECT1 + * 2. initializes attributes of OBJECT1 + * 3. stores reference to OBJECT1.prototype in holdthis local variable + * 4. redefines OBJECT1 as a function that throws an error + * 5. defines the getInstance function (which is also defined outside of + * the class definition - see below). + * + * All subsequent calls to constructor: + * 1. throw error message referring to getInstance + * 2. call getInstance, returns this - which is OBJECT1. + */ + constructor() { + /** + * Tracks units by name + * @type hash - key is the name; + * value is an array of references to the Unit objects + * with the name. More than one unit may have the same + * name, e.g., "second", which is shared by the base unit + * with the code = "s" and the unit with code = "'". + */ + this.unitNames_ = {}; + /** + * Tracks units by code using case-sensitive version. + * + * @type hash - key is the code; + * value is the reference to the Unit object. Codes must + * be unique. + */ + + this.unitCodes_ = {}; + /** + * Keeps track of the order in which units are defined. The order is + * important because unit definitions build on previous definitions. + * + * @type {Array} + */ + + this.codeOrder_ = []; + /** + * Tracks units by unit strings, e.g., cm-1 + * + * @type hash - key is the unit string + * value is an array of unit objects with that ciUnitString. + */ + + this.unitStrings_ = {}; + /** + * Tracks units by Dimension vector + * + * @type hash - key is the dimension vector (not the object, just the + * vector); + * value is an array of references to the Unit objects + * with that vector. More than one unit may have the same + * unit vector, and this can be used to provide a list + * of commensurable units. + */ + + this.unitDimensions_ = {}; + /** + * Maps synonyms to units. Not built until first requested. + * + * @type hash - key is the synonym + * value is an array of references to Unit objects that + * include that synonym. + */ + + this.unitSynonyms_ = {}; + /* + * Holds onto the index of the index of the dimension vector flag for + * the base mass unit (gram). This is set when the base unit (gram) is + * created, and is stored here so that it doesn't have to be found + * over and over again to try to determine whether or not a unit is + * mass-based (for mole<->mass conversions) + * + * @type integer + */ + + this.massDimIndex_ = 0; + /** + * Map of indices in the dimension vector to base unit symbols. + */ + + this.dimVecIndexToBaseUnit_ = {}; + } + /** + * Provides the number of unit objects written to the tables, using the + * codes table since codes must be unique. + * + * @returns count of the number of unit objects in the unitCodes_ table. + */ + + + unitsCount() { + return Object.keys(this.unitCodes_).length; + } + /** + * Adds a Unit object to the tables. + * + * @param theUnit the unit to be added + * @returns nothing + * @throws passes on an error if one is thrown by the called functions for + * a problem with the unit code or unit name + */ + + + addUnit(theUnit) { + let uName = theUnit['name_']; + + if (uName) { + this.addUnitName(theUnit); } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getQuotientOfUnits = exports.getProductOfUnits = exports.compareUnits = exports.convertToCQLDateUnit = exports.normalizeUnitsWhenPossible = exports.convertUnit = exports.checkUnit = void 0; -var ucum = __importStar(require("@lhncbc/ucum-lhc")); -var math_1 = require("./math"); -var utils = ucum.UcumLhcUtils.getInstance(); -// The CQL specification says that dates are based on the Gregorian calendar, so CQL-based year and month -// identifiers will be matched to the UCUM gregorian units. See http://unitsofmeasure.org/ucum.html#para-31 -var CQL_TO_UCUM_DATE_UNITS = { - years: 'a_g', - year: 'a_g', - months: 'mo_g', - month: 'mo_g', - weeks: 'wk', - week: 'wk', - days: 'd', - day: 'd', - hours: 'h', - hour: 'h', - minutes: 'min', - minute: 'min', - seconds: 's', - second: 's', - milliseconds: 'ms', - millisecond: 'ms' -}; -var UCUM_TO_CQL_DATE_UNITS = { - a: 'year', - a_j: 'year', - a_g: 'year', - mo: 'month', - mo_j: 'month', - mo_g: 'month', - wk: 'week', - d: 'day', - h: 'hour', - min: 'minute', - s: 'second', - ms: 'millisecond' -}; -// Cache Map for unit validity results so we dont have to go to ucum-lhc for every check. -var unitValidityCache = new Map(); -function checkUnit(unit, allowEmptyUnits, allowCQLDateUnits) { - if (allowEmptyUnits === void 0) { allowEmptyUnits = true; } - if (allowCQLDateUnits === void 0) { allowCQLDateUnits = true; } - if (allowEmptyUnits) { - unit = fixEmptyUnit(unit); + + this.addUnitCode(theUnit); + this.addUnitString(theUnit); + + try { + if (theUnit['dim_'].getProperty('dimVec_')) this.addUnitDimension(theUnit); + } catch (err) {// do nothing - throws error if the property is null + // and that's OK here. } - if (allowCQLDateUnits) { - unit = fixCQLDateUnit(unit); + + if (theUnit.isBase_) { + const dimVec = theUnit.dim_.dimVec_; + let nonZeroIndex; + + for (let i = 0, len = dimVec.length; nonZeroIndex == undefined && i < len; ++i) { + if (dimVec[i] != 0) nonZeroIndex = i; + } + + this.dimVecIndexToBaseUnit_[nonZeroIndex] = theUnit.csCode_; } - if (!unitValidityCache.has(unit)) { - var result = utils.validateUnitString(unit, true); - if (result.status === 'valid') { - unitValidityCache.set(unit, { valid: true }); - } - else { - var msg = "Invalid UCUM unit: '".concat(unit, "'."); - if (result.ucumCode != null) { - msg += " Did you mean '".concat(result.ucumCode, "'?"); - } - unitValidityCache.set(unit, { valid: false, message: msg }); + } // end addUnit + + /** + * Adds a Unit object to the unitNames_ table. More than one unit + * can have the same name, e.g., the two units with the name "second", + * where the code for one of them is 's' and the code for the other is + * "'". Because of this, an array of unit objects is stored for the + * name. In most cases it will be an array of one object, but this + * clarifies that there may be more than one. + * + * @param theUnit the unit to be added + * @returns nothing + * @throws an error if the unit has no name + */ + + + addUnitName(theUnit) { + let uName = theUnit['name_']; + + if (uName) { + if (this.unitNames_[uName]) this.unitNames_[uName].push(theUnit);else this.unitNames_[uName] = [theUnit]; + } else throw new Error('UnitTables.addUnitName called for a unit with no name. ' + `Unit code = ${theUnit['csCode_']}.`); + } // end addUnitName + + /** + * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and + * codeOrder_ tables. This also sets the mass dimension index when the + * base mass unit (gram) is read. + * + * @param theUnit the unit to be added + * @returns nothing + * @throws an error if the unitCodes_ table already contains a unit with + * the code + */ + + + addUnitCode(theUnit) { + let uCode = theUnit['csCode_']; + + if (uCode) { + if (this.unitCodes_[uCode]) throw new Error(`UnitTables.addUnitCode called, already contains entry for ` + `unit with code = ${uCode}`);else { + this.unitCodes_[uCode] = theUnit; + this.codeOrder_.push(uCode); + + if (uCode == 'g') { + let dimVec = theUnit.dim_.dimVec_; + let d = 0; + + for (; d < dimVec.length && dimVec[d] < 1; d++); + + this.massDimIndex_ = d; } + } + } else throw new Error('UnitTables.addUnitCode called for unit that has ' + 'no code.'); + } // end addUnitCode + + /** + * Adds a unit object to the unitStrings_ table. More than one unit + * can have the same string, so an array of unit objects is stored + * for the string. The unit string is the string that creates a non-base + * unit, e.g., a Newton has a unit code of N, a name of Newton, and a + * unitString of kg.m/s2. + * + * If the unit has no string, nothing is stored and no error is reported. + * + * @param theUnit the unit to be added + * @returns nothing + */ + + + addUnitString(theUnit) { + let uString = null; + if (Ucum.caseSensitive_ == true) uString = theUnit['csUnitString_'];else uString = theUnit['ciUnitString_']; + + if (uString) { + let uEntry = { + mag: theUnit['baseFactorStr_'], + unit: theUnit + }; + if (this.unitStrings_[uString]) this.unitStrings_[uString].push(uEntry);else this.unitStrings_[uString] = [uEntry]; } - return unitValidityCache.get(unit); -} -exports.checkUnit = checkUnit; -function convertUnit(fromVal, fromUnit, toUnit, adjustPrecision) { - var _a; - if (adjustPrecision === void 0) { adjustPrecision = true; } - _a = [fromUnit, toUnit].map(fixUnit), fromUnit = _a[0], toUnit = _a[1]; - var result = utils.convertUnitTo(fixUnit(fromUnit), fromVal, fixUnit(toUnit)); - if (result.status !== 'succeeded') { - return; - } - return adjustPrecision ? (0, math_1.decimalAdjust)('round', result.toVal, -8) : result.toVal; -} -exports.convertUnit = convertUnit; -function normalizeUnitsWhenPossible(val1, unit1, val2, unit2) { - var _a; - // If both units are CQL date units, return CQL date units - var useCQLDateUnits = unit1 in CQL_TO_UCUM_DATE_UNITS && unit2 in CQL_TO_UCUM_DATE_UNITS; - var resultConverter = function (unit) { - return useCQLDateUnits ? convertToCQLDateUnit(unit) : unit; - }; - _a = [unit1, unit2].map(function (u) { return fixUnit(u); }), unit1 = _a[0], unit2 = _a[1]; - if (unit1 === unit2) { - return [val1, unit1, val2, unit2]; - } - var baseUnit1 = getBaseUnitAndPower(unit1)[0]; - var baseUnit2 = getBaseUnitAndPower(unit2)[0]; - var _b = convertToBaseUnit(val2, unit2, baseUnit1), newVal2 = _b[0], newUnit2 = _b[1]; - if (newVal2 == null) { - // it was not convertible, so just return the quantities as-is - return [val1, resultConverter(unit1), val2, resultConverter(unit2)]; - } - // If the new val2 > old val2, return since we prefer conversion to smaller units - if (newVal2 >= val2) { - return [val1, resultConverter(unit1), newVal2, resultConverter(newUnit2)]; - } - // else it was a conversion to a larger unit, so go the other way around - var _c = convertToBaseUnit(val1, unit1, baseUnit2), newVal1 = _c[0], newUnit1 = _c[1]; - if (newVal1 == null) { - // this should not happen since we established they are convertible, but just in case... - return [val1, resultConverter(unit1), newVal2, resultConverter(newUnit2)]; - } - return [newVal1, resultConverter(newUnit1), val2, resultConverter(unit2)]; -} -exports.normalizeUnitsWhenPossible = normalizeUnitsWhenPossible; -function convertToCQLDateUnit(unit) { - var dateUnit; - if (unit in CQL_TO_UCUM_DATE_UNITS) { - // it's already a CQL unit, so return it as-is, removing trailing 's' if necessary (e.g., years -> year) - dateUnit = unit.replace(/s$/, ''); - } - else if (unit in UCUM_TO_CQL_DATE_UNITS) { - dateUnit = UCUM_TO_CQL_DATE_UNITS[unit]; - } - return dateUnit; -} -exports.convertToCQLDateUnit = convertToCQLDateUnit; -function compareUnits(unit1, unit2) { - try { - var c = convertUnit(1, unit1, unit2); - if (c && c > 1) { - // unit1 is bigger (less precise) - return 1; + } // end addUnitString + + /** + * Adds a Unit object to the unitDimensions_ table. More than one unit + * can have the same dimension (commensurable units have the same dimension). + * Because of this, an array of unit objects is stored for the + * dimension. + * + * @param theUnit the unit to be added + * @returns nothing + * @throws an error if the unit has no dimension + */ + + + addUnitDimension(theUnit) { + let uDim = theUnit['dim_'].getProperty('dimVec_'); + + if (uDim) { + if (this.unitDimensions_[uDim]) this.unitDimensions_[uDim].push(theUnit);else this.unitDimensions_[uDim] = [theUnit]; + } else throw new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' + `Unit code = ${theUnit['csCode_']}.`); + } // end addUnitDimension + + /** + * Builds the unitSynonyms_ table. This is called the first time the + * getUnitsBySynonym method is called. The table/hash contains each word + * (once) from each synonym as well as each word from each unit name. + * + * Hash keys are the words. Hash values are an array of unit codes for + * each unit that has that word in its synonyms or name. + * + * @returns nothing + */ + + + buildUnitSynonyms() { + for (let code in this.unitCodes_) { + let theUnit = this.unitCodes_[code]; + let uSyns = theUnit.synonyms_; // If the current unit has synonyms, process each synonym (often multiples) + + if (uSyns) { + let synsAry = uSyns.split(';'); + + if (synsAry[0] !== '') { + let aLen = synsAry.length; + + for (let a = 0; a < aLen; a++) { + let theSyn = synsAry[a].trim(); // call addSynonymCodes to process each word in the + // synonym, e.g., "British fluid ounces" + + this.addSynonymCodes(code, theSyn); + } // end do for each synonym + + } // end if the current unit has a non-null synonym attribute + + } // end if the unit has any synonyms + // Now call addSynonymCodes to process each word in the unit's name + + + this.addSynonymCodes(code, theUnit.name_); + } // end do for each unit + + } // end buildUnitSynonyms + + /** + * Adds unit code entries to the synonyms table for a string containing + * one or more words to be considered as synonyms. + * + * @param theCode the unit code to be connected to the synonyms + * @param theSynonyms a string containing one or more words to be + * considered synonyms (and thus to be added to the unitSynonyms hash). + */ + + + addSynonymCodes(theCode, theSynonyms) { + let words = theSynonyms.split(' '); + let wLen = words.length; + + for (let w = 0; w < wLen; w++) { + let word = words[w]; // if there is already a synonyms entry for the word, + // get the array of unit codes currently assigned to + // the word and add the code for the current word to + // the synonyms array if it's not already there. + + if (this.unitSynonyms_[word]) { + let synCodes = this.unitSynonyms_[word]; + + if (synCodes.indexOf(theCode) === -1) { + this.unitSynonyms_[word].push(theCode); } - else if (c && c < 1) { - // unit1 is smaller - return -1; + } // else there are no synonyms entry for the word. Create a + // synonyms array for the word, setting it to contain the unit code. + else { + this.unitSynonyms_[word] = [theCode]; } - //units are the same - return 0; - } - catch (e) { - return null; + } // end do for each word in the synonyms being processed + + } // end addSynonymCodes + + /** + * Returns a unit object with a case-sensitive code matching the + * uCode parameter, or null if no unit is found with that code. + * + * @param uCode the code of the unit to be returned + * @returns the unit object or null if it is not found + */ + + + getUnitByCode(uCode) { + let retUnit = null; + + if (uCode) { + retUnit = this.unitCodes_[uCode]; } -} -exports.compareUnits = compareUnits; -function getProductOfUnits(unit1, unit2) { - var _a; - _a = [unit1, unit2].map(fixEmptyUnit), unit1 = _a[0], unit2 = _a[1]; - if (!checkUnit(unit1).valid || !checkUnit(unit2).valid) { - return null; + + return retUnit; + } + /** + * Returns a array of unit objects based on the unit's name. Usually this + * will be an array of one, but there may be more, since unit names are + * not necessarily unique. + * + * @param uName the name of the unit to be returned. If more than one + * unit has the same name and you only want one specific unit, append the + * csCode of the unit you want to the end of the name, separated by the + * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us]. + * @returns null if no unit was found for the specified name OR an array of + * unit objects with the specified name. Normally this will be an array + * of one object. + * @throws an error if no name is provided to search on + */ + + + getUnitByName(uName) { + if (uName === null || uName === undefined) { + throw new Error('Unable to find unit by name because no name was provided.'); } - // If either unit contains a divisor,combine the numerators and denominators, then divide - if (unit1.indexOf('/') >= 0 || unit2.indexOf('/') >= 0) { - // NOTE: We're not trying to get perfection on unit simplification, but doing what is reasonable - var match1 = unit1.match(/([^/]*)(\/(.*))?/); - var match2 = unit2.match(/([^/]*)(\/(.*))?/); - // In the previous regexes, numerator is match[1], denominator is match[3] - var newNum = getProductOfUnits(match1[1], match2[1]); - var newDen = getProductOfUnits(match1[3], match2[3]); - return getQuotientOfUnits(newNum, newDen); + + let sepPos = uName.indexOf(Ucum.codeSep_); + let uCode = null; + + if (sepPos >= 1) { + uCode = uName.substr(sepPos + Ucum.codeSep_.length); + uName = uName.substr(0, sepPos); } - // Get all the individual units being combined, accounting for multipliers (e.g., 'm.L'), - // and then group like base units to combine powers (and remove '1's since they are no-ops) - // e.g., 'm.L' * 'm' ==> { m: 2, L: 1}; 'm.L' * '1' ==> { m: 1, L: 1 }; '1' : '1' ==> { } - var factorPowerMap = new Map(); - var factors = __spreadArray(__spreadArray([], unit1.split('.'), true), unit2.split('.'), true); - factors.forEach(function (factor) { - var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; - if (baseUnit === '1' || power === 0) { - // skip factors that are 1 since 1 * N is N. - return; + + let retUnits = this.unitNames_[uName]; + + if (retUnits) { + let uLen = retUnits.length; + + if (uCode && uLen > 1) { + let i = 0; + + for (; retUnits[i].csCode_ !== uCode && i < uLen; i++); + + if (i < uLen) retUnits = [retUnits[i]];else { + retUnits = null; } - var accumulatedPower = (factorPowerMap.get(baseUnit) || 0) + power; - factorPowerMap.set(baseUnit, accumulatedPower); - }); - // Loop through the factor map, rebuilding each factor w/ combined power and join them all - // back via the multiplier '.', treating a final '' (no non-1 units) as '1' - // e.g., { m: 2, L: 1 } ==> 'm2.L' - return fixUnit(Array.from(factorPowerMap.entries()) - .map(function (_a) { - var base = _a[0], power = _a[1]; - return "".concat(base).concat(power > 1 ? power : ''); - }) - .join('.')); -} -exports.getProductOfUnits = getProductOfUnits; -function getQuotientOfUnits(unit1, unit2) { - var _a; - _a = [unit1, unit2].map(fixEmptyUnit), unit1 = _a[0], unit2 = _a[1]; - if (!checkUnit(unit1).valid || !checkUnit(unit2).valid) { - return null; - } - // Try to simplify division when neither unit contains a divisor itself - if (unit1.indexOf('/') === -1 && unit2.indexOf('/') === -1) { - // Get all the individual units in numerator and denominator accounting for multipliers - // (e.g., 'm.L'), and then group like base units to combine powers, inversing denominator - // powers since they are being divided. - // e.g., 'm3.L' / 'm' ==> { m: 2, L: -1}; 'm.L' / '1' ==> { m: 1, L: 1 }; '1' / '1' ==> { 1: 0 } - var factorPowerMap_1 = new Map(); - unit1.split('.').forEach(function (factor) { - var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; - var accumulatedPower = (factorPowerMap_1.get(baseUnit) || 0) + power; - factorPowerMap_1.set(baseUnit, accumulatedPower); - }); - unit2.split('.').forEach(function (factor) { - var _a = getBaseUnitAndPower(factor), baseUnit = _a[0], power = _a[1]; - var accumulatedPower = (factorPowerMap_1.get(baseUnit) || 0) - power; - factorPowerMap_1.set(baseUnit, accumulatedPower); - }); - // Construct the numerator from factors with positive power, and denominator from factors - // with negative power, filtering out base `1` and power 0 (which is also 1). - // e.g. numerator: { m: 2, L: -2 } ==> 'm2'; { 1: 1, L: -1 } => '' - // e.g. denominator: { m: 2, L: -2 } ==> 'L2'; { 1: 1, L: -1 } => 'L' - var numerator = Array.from(factorPowerMap_1.entries()) - .filter(function (_a) { - var base = _a[0], power = _a[1]; - return base !== '1' && power > 0; - }) - .map(function (_a) { - var base = _a[0], power = _a[1]; - return "".concat(base).concat(power > 1 ? power : ''); - }) - .join('.'); - var denominator = Array.from(factorPowerMap_1.entries()) - .filter(function (_a) { - var base = _a[0], power = _a[1]; - return base !== '1' && power < 0; - }) - .map(function (_a) { - var base = _a[0], power = _a[1]; - return "".concat(base).concat(power < -1 ? power * -1 : ''); - }) - .join('.'); - // wrap the denominator in parentheses if necessary - denominator = /[.]/.test(denominator) ? "(".concat(denominator, ")") : denominator; - return fixUnit("".concat(numerator).concat(denominator !== '' ? '/' + denominator : '')); + } // end if we need to find both a name and a code + + } // end if we got an array of units + + + return retUnits; + } // end getUnitByName + + /** + * Returns an array of unit objects with the specified unit string. + * The array may contain one or more unit reference objects. + * Or none, if no units have a matching unit string (which is not + * considered an error) + * + * @param name the name of the unit to be returned + * @returns the array of unit references or null if none were found + */ + + + getUnitByString(uString) { + let retAry = null; + + if (uString) { + retAry = this.unitStrings_[uString]; + if (retAry === undefined) retAry = null; } - // One of the units had a divisor, so don't try to be too smart; just construct it from the parts - if (unit1 === unit2) { - // e.g. 'm/g' / 'm/g' ==> '1' - return '1'; + + return retAry; + } + /** + * Returns a array of unit objects based on the unit's dimension vector. + * + * @param uName the dimension vector of the units to be returned. + * + * @returns null if no unit was found for the specified vector OR an array of + * one or more unit objects with the specified vector. + * @throws an error if no vector is provided to search on + * logs an error to the console if no unit is found + */ + + + getUnitsByDimension(uDim) { + let unitsArray = null; + + if (uDim === null || uDim === undefined) { + throw new Error('Unable to find unit by because no dimension ' + 'vector was provided.'); } - else if (unit2 === '1') { - // e.g., 'm/g' / '1' ==> 'm/g/' - return unit1; + + unitsArray = this.unitDimensions_[uDim]; + + if (unitsArray === undefined || unitsArray === null) { + console.log(`Unable to find unit with dimension = ${uDim}`); } - else { - // denominator is unit2, wrapped in parentheses if necessary - var denominator = /[./]/.test(unit2) ? "(".concat(unit2, ")") : unit2; - if (unit1 === '1') { - // e.g., '1' / 'm' ==> '/m'; '1' / 'm.g' ==> '/(m.g)' - return "/".concat(denominator); + + return unitsArray; + } // end getUnitsByDimension + + /** + * Returns a array of unit objects that include the specified synonym. + * + * @param uSyn the synonym of the units to be returned. + * + * @returns an object with two of the following three elements: + * 'status' will be error, failed or succeeded + * 'msg' will be included for returns with status = error or failed and + * will explain why the request did not return any units + * 'units' any array of unit objects with the specified synonym will be + * returned for requests with status = succeeded + */ + + + getUnitBySynonym(uSyn) { + let retObj = {}; + let unitsArray = []; + + try { + if (uSyn === null || uSyn === undefined) { + retObj['status'] = 'error'; + throw new Error('Unable to find unit by synonym because no synonym ' + 'was provided.'); + } // If this is the first request for a unit by synonym, build the hash map + + + if (Object.keys(this.unitSynonyms_).length === 0) { + this.buildUnitSynonyms(); + } + + let foundCodes = []; + foundCodes = this.unitSynonyms_[uSyn]; + + if (foundCodes) { + retObj['status'] = 'succeeded'; + let fLen = foundCodes.length; + + for (let f = 0; f < fLen; f++) { + unitsArray.push(this.unitCodes_[foundCodes[f]]); } - // e.g., 'L' / 'm' ==> 'L/m'; 'L' / 'm.g' ==> 'L/(m.g)' - return "".concat(unit1, "/").concat(denominator); - } -} -exports.getQuotientOfUnits = getQuotientOfUnits; -// UNEXPORTED FUNCTIONS -function convertToBaseUnit(fromVal, fromUnit, toBaseUnit) { - var fromPower = getBaseUnitAndPower(fromUnit)[1]; - var toUnit = fromPower === 1 ? toBaseUnit : "".concat(toBaseUnit).concat(fromPower); - var newVal = convertUnit(fromVal, fromUnit, toUnit); - return newVal != null ? [newVal, toUnit] : []; -} -function getBaseUnitAndPower(unit) { - // don't try to extract power from complex units (containing multipliers or divisors) - if (/[./]/.test(unit)) { - return [unit, 1]; - } - unit = fixUnit(unit); - var _a = unit.match(/^(.*[^-\d])?([-]?\d*)$/).slice(1), term = _a[0], power = _a[1]; - if (term == null || term === '') { - term = power; - power = '1'; - } - else if (power == null || power === '') { - power = '1'; - } - return [term, parseInt(power)]; -} -function fixEmptyUnit(unit) { - if (unit == null || (unit.trim && unit.trim() === '')) { - return '1'; + + retObj['units'] = unitsArray; + } + + if (unitsArray.length === 0) { + retObj['status'] = 'failed'; + retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`; + } + } catch (err) { + retObj['msg'] = err.message; } - return unit; -} -function fixCQLDateUnit(unit) { - return CQL_TO_UCUM_DATE_UNITS[unit] || unit; -} -function fixUnit(unit) { - return fixCQLDateUnit(fixEmptyUnit(unit)); -} -},{"./math":104,"@lhncbc/ucum-lhc":18}],106:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getTimezoneSeparatorFromString = exports.normalizeMillisecondsField = exports.normalizeMillisecondsFieldInString = exports.jsDate = exports.anyTrue = exports.allTrue = exports.typeIsArray = exports.isNull = exports.numerical_sort = exports.removeNulls = void 0; -function removeNulls(things) { - return things.filter(function (x) { return x != null; }); -} -exports.removeNulls = removeNulls; -function numerical_sort(things, direction) { - return things.sort(function (a, b) { - if (direction == null || direction === 'asc' || direction === 'ascending') { - return a - b; - } - else { - return b - a; - } - }); -} -exports.numerical_sort = numerical_sort; -function isNull(value) { - return value === null; -} -exports.isNull = isNull; -exports.typeIsArray = Array.isArray || (function (value) { return ({}.toString.call(value) === '[object Array]'); }); -function allTrue(things) { - if ((0, exports.typeIsArray)(things)) { - return things.every(function (x) { return x; }); - } - else { - return things; - } -} -exports.allTrue = allTrue; -function anyTrue(things) { - if ((0, exports.typeIsArray)(things)) { - return things.some(function (x) { return x; }); - } - else { - return things; - } -} -exports.anyTrue = anyTrue; -//The export below is to make it easier if js Date is overwritten with CQL Date -exports.jsDate = Date; -function normalizeMillisecondsFieldInString(string, msString) { - // TODO: verify we are only removing numeral digits - var timezoneField; - msString = normalizeMillisecondsField(msString); - var _a = string.split('.'), beforeMs = _a[0], msAndAfter = _a[1]; - var timezoneSeparator = getTimezoneSeparatorFromString(msAndAfter); - if (timezoneSeparator) { - timezoneField = msAndAfter != null ? msAndAfter.split(timezoneSeparator)[1] : undefined; + return retObj; + } // end getUnitBySynonym + + /** + * Gets a list of all unit names in the Unit tables + * + * @returns an array of the unit names + */ + + + getAllUnitNames() { + return Object.keys(this.unitNames_); + } // end getAllUnitNames + + /** + * Gets a list of all unit names in the tables. Where more than one + * unit has the same name, the unit code, in parentheses, is appended + * to the end of the name. + * + * @returns {Array} + */ + + + getUnitNamesList() { + let nameList = []; + let codes = Object.keys(this.unitCodes_); + codes.sort(this.compareCodes); + let uLen = codes.length; + + for (let i = 0; i < uLen; i++) { + nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_; + } // end do for each code + + + return nameList; + } + /* + * Returns the mass dimension index + * @returns this.massDimIndex_ + */ + + + getMassDimensionIndex() { + return this.massDimIndex_; + } + /** + * This provides a sort function for unit codes so that sorting ignores + * square brackets and case. + * + * @param a first value + * @param b second value + * @returns -1 if a is should fall before b; otherwise 1. + */ + + + compareCodes(a, b) { + a = a.replace(/[\[\]]/g, ''); + a = a.toLowerCase(); + b = b.replace(/[\[\]]/g, ''); + b = b.toLowerCase(); + return a < b ? -1 : 1; + } + /** + * Gets a list of all unit codes in the Unit tables + * + * @returns an array of the unit names + */ + + + getAllUnitCodes() { + return Object.keys(this.unitCodes_); + } // end getAllUnitNames + + /** + * This is used to get all unit objects. Currently it is used + * to get the objects to write to the json ucum definitions file + * that is used to provide prefix and unit definition objects for + * conversions and validations. + * + * @returns an array containing all unit objects, ordered by definition + * order + */ + + + allUnitsByDef() { + let unitsList = []; + let uLen = this.codeOrder_.length; + + for (let u = 0; u < uLen; u++) { + unitsList.push(this.getUnitByCode(this.codeOrder_[u])); } - if (timezoneField == null) { - timezoneField = ''; + + return unitsList; + } // end allUnitsByDef + + /** + * This is used to get all unit objects, ordered by unit name. Currently it + * is used to create a csv list of all units. + * @param sep separator character (or string) to be used to separate each + * column in the output. Optional, defaults to '|' if not specified. + * (Used to use ; but the synonyms use that extensively). Don't use a + * comma or any other punctuation found in the output data. + * @returns a buffer containing all unit objects, ordered by name + * order + */ + + + allUnitsByName(cols, sep) { + if (sep === undefined || sep === null) sep = '|'; + let unitBuff = ''; + let unitsList = this.getAllUnitNames(); + let uLen = unitsList.length; + let cLen = cols.length; + + for (let i = 0; i < uLen; i++) { + let nameRecs = this.getUnitByName(unitsList[i]); + + for (let u = 0; u < nameRecs.length; u++) { + let rec = nameRecs[u]; + + for (let c = 0; c < cLen; c++) { + if (c > 0) unitBuff += sep; + + if (cols[c] === 'dim_') { + if (rec.dim_ !== null && rec.dim_ !== undefined && rec.dim_.dimVec_ instanceof Array) unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';else unitBuff += ''; + } else { + let cbuf = rec[cols[c]]; + if (typeof cbuf === 'string') unitBuff += cbuf.replace(/[\n\r]/g, ' ');else unitBuff += cbuf; + } + } // end do for each column requested + + + unitBuff += '\r\n'; + } // end do for each unit in the unit names array + } - return (string = beforeMs + '.' + msString + timezoneSeparator + timezoneField); -} -exports.normalizeMillisecondsFieldInString = normalizeMillisecondsFieldInString; -function normalizeMillisecondsField(msString) { - // fix up milliseconds by padding zeros and/or truncating (5 --> 500, 50 --> 500, 54321 --> 543, etc.) - return (msString = (msString + '00').substring(0, 3)); -} -exports.normalizeMillisecondsField = normalizeMillisecondsField; -function getTimezoneSeparatorFromString(string) { - if (string != null) { - var matches = string.match(/-/); - if (matches && matches.length === 1) { - return '-'; - } - matches = string.match(/\+/); - if (matches && matches.length === 1) { - return '+'; - } + + return unitBuff; + } // end allUnitsByName + + /** + * This creates a list of all units in the tables. It uses the byCode + * table, and uses the codeOrder_ array to determine the order in which + * the units are listed. + * + * @param doLong boolean indicating how much to output. If true, all data + * from the unit objects is included. If false, only a few major values + * are included. + * @param sep separator character (or string) to be used to separate each + * column in the output. Optional, defaults to '|' if not specified. + * (Used to use ; but the synonyms use that extensively). + * @returns {string} buffer containing all the listings + */ + + + printUnits(doLong, sep) { + if (doLong === undefined) doLong = false; + if (sep === undefined) sep = '|'; + let codeList = ''; + let uLen = this.codeOrder_.length; + let unitString = 'csCode' + sep; + + if (doLong) { + unitString += 'ciCode' + sep; } - return ''; -} -exports.getTimezoneSeparatorFromString = getTimezoneSeparatorFromString; -},{}],107:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + unitString += 'name' + sep; + if (doLong) unitString += 'isBase' + sep; + unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep + 'value' + sep + 'function' + sep; + if (doLong) unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep + 'source' + sep + 'class' + sep + 'isMetric' + sep + 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep; + unitString += 'comment'; + codeList = unitString + '\n'; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + for (let u = 0; u < uLen; u++) { + let curUnit = this.getUnitByCode(this.codeOrder_[u]); + unitString = this.codeOrder_[u] + sep; + if (doLong) { + unitString += curUnit.getProperty('ciCode_') + sep; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + unitString += curUnit.getProperty('name_') + sep; -const AdverseEventSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - severity: Code, - facilityLocation: FacilityLocationSchema, - type: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Adverse Event' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.120' }, - qdmCategory: { type: String, default: 'adverse_event' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::AdverseEvent' }, + if (doLong) { + if (curUnit.getProperty('isBase_')) unitString += 'true' + sep;else unitString += 'false' + sep; + } -}); + unitString += curUnit.getProperty('magnitude_') + sep; + let curDim = curUnit.getProperty('dim_'); -module.exports.AdverseEventSchema = AdverseEventSchema; -class AdverseEvent extends mongoose.Document { - constructor(object) { - super(object, AdverseEventSchema); - this._type = 'QDM::AdverseEvent'; + if (curDim) { + unitString += curDim.dimVec_ + sep; + } else { + unitString += 'null' + sep; + } + + if (curUnit.csUnitString_) unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep;else unitString += 'null' + sep + 'null' + sep; + if (curUnit.cnv_) unitString += curUnit.cnv_ + sep;else unitString += 'null' + sep; + + if (doLong) { + unitString += curUnit.getProperty('property_') + sep + curUnit.getProperty('printSymbol_') + sep + curUnit.getProperty('synonyms_') + sep + curUnit.getProperty('source_') + sep + curUnit.getProperty('class_') + sep + curUnit.getProperty('isMetric_') + sep + curUnit.getProperty('variable_') + sep + curUnit.getProperty('isSpecial_') + sep + curUnit.getProperty('isArbitrary_') + sep; + } + + if (curUnit.defError_) unitString += 'problem parsing this one, deferred to later.'; + codeList += unitString + '\n'; + } + + return codeList; } -} -module.exports.AdverseEvent = AdverseEvent; +} // end UnitTablesFactory +// Create a singleton instance and (to preserve the existing API) an object that +// provides that instance via getInstance(). -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],108:[function(require,module,exports){ -module.exports.Identifier = require('./attributes/Identifier.js').Identifier; -module.exports.IdentifierSchema = require('./attributes/Identifier.js').IdentifierSchema; -module.exports.Entity = require('./attributes/Entity.js').Entity; -module.exports.EntitySchema = require('./attributes/Entity.js').EntitySchema; -module.exports.PatientEntity = require('./attributes/PatientEntity.js').PatientEntity; -module.exports.PatientEntitySchema = require('./attributes/PatientEntity.js').PatientEntitySchema; -module.exports.CarePartner = require('./attributes/CarePartner.js').CarePartner; -module.exports.CarePartnerSchema = require('./attributes/CarePartner.js').CarePartnerSchema; -module.exports.RelatedPerson = require('./RelatedPerson.js').RelatedPerson; -module.exports.RelatedPersonSchema = require('./RelatedPerson.js').RelatedPersonSchema; -module.exports.Practitioner = require('./attributes/Practitioner.js').Practitioner; -module.exports.PractitionerSchema = require('./attributes/Practitioner.js').PractitionerSchema; -module.exports.Organization = require('./attributes/Organization.js').Organization; -module.exports.OrganizationSchema = require('./attributes/Organization.js').OrganizationSchema; -module.exports.Location = require('./attributes/Location.js').Location; -module.exports.LocationSchema = require('./attributes/Location.js').LocationSchema; -module.exports.PhysicalExamOrder = require('./PhysicalExamOrder.js').PhysicalExamOrder; -module.exports.PhysicalExamOrderSchema = require('./PhysicalExamOrder.js').PhysicalExamOrderSchema; -module.exports.Participation = require('./Participation.js').Participation; -module.exports.ParticipationSchema = require('./Participation.js').ParticipationSchema; -module.exports.PatientCharacteristicSex = require('./PatientCharacteristicSex.js').PatientCharacteristicSex; -module.exports.PatientCharacteristicSexSchema = require('./PatientCharacteristicSex.js').PatientCharacteristicSexSchema; -module.exports.CareGoal = require('./CareGoal.js').CareGoal; -module.exports.CareGoalSchema = require('./CareGoal.js').CareGoalSchema; -module.exports.PatientCharacteristic = require('./PatientCharacteristic.js').PatientCharacteristic; -module.exports.PatientCharacteristicSchema = require('./PatientCharacteristic.js').PatientCharacteristicSchema; -module.exports.PatientCharacteristicEthnicity = require('./PatientCharacteristicEthnicity.js').PatientCharacteristicEthnicity; -module.exports.PatientCharacteristicEthnicitySchema = require('./PatientCharacteristicEthnicity.js').PatientCharacteristicEthnicitySchema; -module.exports.PatientCharacteristicRace = require('./PatientCharacteristicRace.js').PatientCharacteristicRace; -module.exports.PatientCharacteristicRaceSchema = require('./PatientCharacteristicRace.js').PatientCharacteristicRaceSchema; -module.exports.LaboratoryTestPerformed = require('./LaboratoryTestPerformed.js').LaboratoryTestPerformed; -module.exports.LaboratoryTestPerformedSchema = require('./LaboratoryTestPerformed.js').LaboratoryTestPerformedSchema; -module.exports.Symptom = require('./Symptom.js').Symptom; -module.exports.SymptomSchema = require('./Symptom.js').SymptomSchema; -module.exports.MedicationAdministered = require('./MedicationAdministered.js').MedicationAdministered; -module.exports.MedicationAdministeredSchema = require('./MedicationAdministered.js').MedicationAdministeredSchema; -module.exports.ProcedureRecommended = require('./ProcedureRecommended.js').ProcedureRecommended; -module.exports.ProcedureRecommendedSchema = require('./ProcedureRecommended.js').ProcedureRecommendedSchema; -module.exports.EncounterPerformed = require('./EncounterPerformed.js').EncounterPerformed; -module.exports.EncounterPerformedSchema = require('./EncounterPerformed.js').EncounterPerformedSchema; -module.exports.Diagnosis = require('./Diagnosis.js').Diagnosis; -module.exports.DiagnosisSchema = require('./Diagnosis.js').DiagnosisSchema; -module.exports.CommunicationPerformed = require('./CommunicationPerformed.js').CommunicationPerformed; -module.exports.CommunicationPerformedSchema = require('./CommunicationPerformed.js').CommunicationPerformedSchema; -module.exports.AssessmentPerformed = require('./AssessmentPerformed.js').AssessmentPerformed; -module.exports.AssessmentPerformedSchema = require('./AssessmentPerformed.js').AssessmentPerformedSchema; -module.exports.PatientCharacteristicClinicalTrialParticipant = require('./PatientCharacteristicClinicalTrialParticipant.js').PatientCharacteristicClinicalTrialParticipant; -module.exports.PatientCharacteristicClinicalTrialParticipantSchema = require('./PatientCharacteristicClinicalTrialParticipant.js').PatientCharacteristicClinicalTrialParticipantSchema; -module.exports.DeviceOrder = require('./DeviceOrder.js').DeviceOrder; -module.exports.DeviceOrderSchema = require('./DeviceOrder.js').DeviceOrderSchema; -module.exports.DiagnosticStudyPerformed = require('./DiagnosticStudyPerformed.js').DiagnosticStudyPerformed; -module.exports.DiagnosticStudyPerformedSchema = require('./DiagnosticStudyPerformed.js').DiagnosticStudyPerformedSchema; -module.exports.InterventionOrder = require('./InterventionOrder.js').InterventionOrder; -module.exports.InterventionOrderSchema = require('./InterventionOrder.js').InterventionOrderSchema; -module.exports.FamilyHistory = require('./FamilyHistory.js').FamilyHistory; -module.exports.FamilyHistorySchema = require('./FamilyHistory.js').FamilyHistorySchema; -module.exports.Component = require('./attributes/Component.js').Component; -module.exports.ComponentSchema = require('./attributes/Component.js').ComponentSchema; -module.exports.DiagnosisComponent = require('./attributes/DiagnosisComponent.js').DiagnosisComponent; -module.exports.DiagnosisComponentSchema = require('./attributes/DiagnosisComponent.js').DiagnosisComponentSchema; -module.exports.ResultComponent = require('./attributes/ResultComponent.js').ResultComponent; -module.exports.ResultComponentSchema = require('./attributes/ResultComponent.js').ResultComponentSchema; -module.exports.FacilityLocation = require('./attributes/FacilityLocation.js').FacilityLocation; -module.exports.FacilityLocationSchema = require('./attributes/FacilityLocation.js').FacilityLocationSchema; -module.exports.MedicationActive = require('./MedicationActive.js').MedicationActive; -module.exports.MedicationActiveSchema = require('./MedicationActive.js').MedicationActiveSchema; -module.exports.LaboratoryTestOrder = require('./LaboratoryTestOrder.js').LaboratoryTestOrder; -module.exports.LaboratoryTestOrderSchema = require('./LaboratoryTestOrder.js').LaboratoryTestOrderSchema; -module.exports.DiagnosticStudyOrder = require('./DiagnosticStudyOrder.js').DiagnosticStudyOrder; -module.exports.DiagnosticStudyOrderSchema = require('./DiagnosticStudyOrder.js').DiagnosticStudyOrderSchema; -module.exports.SubstanceOrder = require('./SubstanceOrder.js').SubstanceOrder; -module.exports.SubstanceOrderSchema = require('./SubstanceOrder.js').SubstanceOrderSchema; -module.exports.PatientCharacteristicPayer = require('./PatientCharacteristicPayer.js').PatientCharacteristicPayer; -module.exports.PatientCharacteristicPayerSchema = require('./PatientCharacteristicPayer.js').PatientCharacteristicPayerSchema; -module.exports.PatientCharacteristicExpired = require('./PatientCharacteristicExpired.js').PatientCharacteristicExpired; -module.exports.PatientCharacteristicExpiredSchema = require('./PatientCharacteristicExpired.js').PatientCharacteristicExpiredSchema; -module.exports.AssessmentOrder = require('./AssessmentOrder.js').AssessmentOrder; -module.exports.AssessmentOrderSchema = require('./AssessmentOrder.js').AssessmentOrderSchema; -module.exports.AssessmentRecommended = require('./AssessmentRecommended.js').AssessmentRecommended; -module.exports.AssessmentRecommendedSchema = require('./AssessmentRecommended.js').AssessmentRecommendedSchema; -module.exports.ImmunizationAdministered = require('./ImmunizationAdministered.js').ImmunizationAdministered; -module.exports.ImmunizationAdministeredSchema = require('./ImmunizationAdministered.js').ImmunizationAdministeredSchema; -module.exports.SubstanceAdministered = require('./SubstanceAdministered.js').SubstanceAdministered; -module.exports.SubstanceAdministeredSchema = require('./SubstanceAdministered.js').SubstanceAdministeredSchema; -module.exports.EncounterOrder = require('./EncounterOrder.js').EncounterOrder; -module.exports.EncounterOrderSchema = require('./EncounterOrder.js').EncounterOrderSchema; -module.exports.EncounterRecommended = require('./EncounterRecommended.js').EncounterRecommended; -module.exports.EncounterRecommendedSchema = require('./EncounterRecommended.js').EncounterRecommendedSchema; -module.exports.ProcedurePerformed = require('./ProcedurePerformed.js').ProcedurePerformed; -module.exports.ProcedurePerformedSchema = require('./ProcedurePerformed.js').ProcedurePerformedSchema; -module.exports.AllergyIntolerance = require('./AllergyIntolerance.js').AllergyIntolerance; -module.exports.AllergyIntoleranceSchema = require('./AllergyIntolerance.js').AllergyIntoleranceSchema; -module.exports.PhysicalExamRecommended = require('./PhysicalExamRecommended.js').PhysicalExamRecommended; -module.exports.PhysicalExamRecommendedSchema = require('./PhysicalExamRecommended.js').PhysicalExamRecommendedSchema; -module.exports.PatientCharacteristicBirthdate = require('./PatientCharacteristicBirthdate.js').PatientCharacteristicBirthdate; -module.exports.PatientCharacteristicBirthdateSchema = require('./PatientCharacteristicBirthdate.js').PatientCharacteristicBirthdateSchema; -module.exports.AdverseEvent = require('./AdverseEvent.js').AdverseEvent; -module.exports.AdverseEventSchema = require('./AdverseEvent.js').AdverseEventSchema; -module.exports.DeviceRecommended = require('./DeviceRecommended.js').DeviceRecommended; -module.exports.DeviceRecommendedSchema = require('./DeviceRecommended.js').DeviceRecommendedSchema; -module.exports.MedicationDischarge = require('./MedicationDischarge.js').MedicationDischarge; -module.exports.MedicationDischargeSchema = require('./MedicationDischarge.js').MedicationDischargeSchema; -module.exports.InterventionPerformed = require('./InterventionPerformed.js').InterventionPerformed; -module.exports.InterventionPerformedSchema = require('./InterventionPerformed.js').InterventionPerformedSchema; -module.exports.LaboratoryTestRecommended = require('./LaboratoryTestRecommended.js').LaboratoryTestRecommended; -module.exports.LaboratoryTestRecommendedSchema = require('./LaboratoryTestRecommended.js').LaboratoryTestRecommendedSchema; -module.exports.MedicationDispensed = require('./MedicationDispensed.js').MedicationDispensed; -module.exports.MedicationDispensedSchema = require('./MedicationDispensed.js').MedicationDispensedSchema; -module.exports.DiagnosticStudyRecommended = require('./DiagnosticStudyRecommended.js').DiagnosticStudyRecommended; -module.exports.DiagnosticStudyRecommendedSchema = require('./DiagnosticStudyRecommended.js').DiagnosticStudyRecommendedSchema; -module.exports.ImmunizationOrder = require('./ImmunizationOrder.js').ImmunizationOrder; -module.exports.ImmunizationOrderSchema = require('./ImmunizationOrder.js').ImmunizationOrderSchema; -module.exports.PatientCareExperience = require('./PatientCareExperience.js').PatientCareExperience; -module.exports.PatientCareExperienceSchema = require('./PatientCareExperience.js').PatientCareExperienceSchema; -module.exports.ProviderCareExperience = require('./ProviderCareExperience.js').ProviderCareExperience; -module.exports.ProviderCareExperienceSchema = require('./ProviderCareExperience.js').ProviderCareExperienceSchema; -module.exports.ProcedureOrder = require('./ProcedureOrder.js').ProcedureOrder; -module.exports.ProcedureOrderSchema = require('./ProcedureOrder.js').ProcedureOrderSchema; -module.exports.MedicationOrder = require('./MedicationOrder.js').MedicationOrder; -module.exports.MedicationOrderSchema = require('./MedicationOrder.js').MedicationOrderSchema; -module.exports.SubstanceRecommended = require('./SubstanceRecommended.js').SubstanceRecommended; -module.exports.SubstanceRecommendedSchema = require('./SubstanceRecommended.js').SubstanceRecommendedSchema; -module.exports.InterventionRecommended = require('./InterventionRecommended.js').InterventionRecommended; -module.exports.InterventionRecommendedSchema = require('./InterventionRecommended.js').InterventionRecommendedSchema; -module.exports.PhysicalExamPerformed = require('./PhysicalExamPerformed.js').PhysicalExamPerformed; -module.exports.PhysicalExamPerformedSchema = require('./PhysicalExamPerformed.js').PhysicalExamPerformedSchema; -module.exports.QDMPatient = require('./QDMPatient.js').QDMPatient; -module.exports.QDMPatientSchema = require('./QDMPatient.js').QDMPatientSchema; +var unitTablesInstance = new UnitTablesFactory(); +const UnitTables = { + getInstance: function () { + return unitTablesInstance; + } +}; +exports.UnitTables = UnitTables; -},{"./AdverseEvent.js":107,"./AllergyIntolerance.js":109,"./AssessmentOrder.js":110,"./AssessmentPerformed.js":111,"./AssessmentRecommended.js":112,"./CareGoal.js":113,"./CommunicationPerformed.js":114,"./DeviceOrder.js":115,"./DeviceRecommended.js":116,"./Diagnosis.js":117,"./DiagnosticStudyOrder.js":118,"./DiagnosticStudyPerformed.js":119,"./DiagnosticStudyRecommended.js":120,"./EncounterOrder.js":121,"./EncounterPerformed.js":122,"./EncounterRecommended.js":123,"./FamilyHistory.js":124,"./ImmunizationAdministered.js":125,"./ImmunizationOrder.js":126,"./InterventionOrder.js":127,"./InterventionPerformed.js":128,"./InterventionRecommended.js":129,"./LaboratoryTestOrder.js":130,"./LaboratoryTestPerformed.js":131,"./LaboratoryTestRecommended.js":132,"./MedicationActive.js":133,"./MedicationAdministered.js":134,"./MedicationDischarge.js":135,"./MedicationDispensed.js":136,"./MedicationOrder.js":137,"./Participation.js":138,"./PatientCareExperience.js":139,"./PatientCharacteristic.js":140,"./PatientCharacteristicBirthdate.js":141,"./PatientCharacteristicClinicalTrialParticipant.js":142,"./PatientCharacteristicEthnicity.js":143,"./PatientCharacteristicExpired.js":144,"./PatientCharacteristicPayer.js":145,"./PatientCharacteristicRace.js":146,"./PatientCharacteristicSex.js":147,"./PhysicalExamOrder.js":148,"./PhysicalExamPerformed.js":149,"./PhysicalExamRecommended.js":150,"./ProcedureOrder.js":151,"./ProcedurePerformed.js":152,"./ProcedureRecommended.js":153,"./ProviderCareExperience.js":154,"./QDMPatient.js":155,"./RelatedPerson.js":156,"./SubstanceAdministered.js":158,"./SubstanceOrder.js":159,"./SubstanceRecommended.js":160,"./Symptom.js":161,"./attributes/CarePartner.js":162,"./attributes/Component.js":163,"./attributes/DiagnosisComponent.js":164,"./attributes/Entity.js":165,"./attributes/FacilityLocation.js":166,"./attributes/Identifier.js":167,"./attributes/Location.js":168,"./attributes/Organization.js":169,"./attributes/PatientEntity.js":170,"./attributes/Practitioner.js":171,"./attributes/ResultComponent.js":172}],109:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +},{"./config.js":94}],107:[function(require,module,exports){ +'use strict'; +module.exports = Number.isFinite || function (value) { + return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity); +}; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +},{}],108:[function(require,module,exports){ +// https://github.com/paulmillr/es6-shim +// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger +var isFinite = require("is-finite"); +module.exports = Number.isInteger || function(val) { + return typeof val === "number" && + isFinite(val) && + Math.floor(val) === val; +}; -const AllergyIntoleranceSchema = DataElementSchema({ - authorDatetime: DateTime, - prevalencePeriod: Interval, - type: Code, - severity: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Allergy/Intolerance' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.119' }, - qdmCategory: { type: String, default: 'allergy' }, - qdmStatus: { type: String, default: 'intolerance' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::AllergyIntolerance' }, +},{"is-finite":107}],109:[function(require,module,exports){ +'use strict'; -}); +Object.defineProperty(exports, '__esModule', { value: true }); -module.exports.AllergyIntoleranceSchema = AllergyIntoleranceSchema; -class AllergyIntolerance extends mongoose.Document { - constructor(object) { - super(object, AllergyIntoleranceSchema); - this._type = 'QDM::AllergyIntolerance'; +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); } } -module.exports.AllergyIntolerance = AllergyIntolerance; - +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],110:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +function _inheritsLoose(subClass, superClass) { + subClass.prototype = Object.create(superClass.prototype); + subClass.prototype.constructor = subClass; + subClass.__proto__ = superClass; +} -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return _setPrototypeOf(o, p); +} -const AssessmentOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - negationRationale: Code, - reason: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Assessment, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.131' }, - qdmCategory: { type: String, default: 'assessment' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::AssessmentOrder' }, +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; -}); + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } +} -module.exports.AssessmentOrderSchema = AssessmentOrderSchema; -class AssessmentOrder extends mongoose.Document { - constructor(object) { - super(object, AssessmentOrderSchema); - this._type = 'QDM::AssessmentOrder'; +function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; } + + return _construct.apply(null, arguments); } -module.exports.AssessmentOrder = AssessmentOrder; +function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; +} +function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],111:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _cache.set(Class, Wrapper); + } -const AssessmentPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - negationRationale: Code, - reason: Code, - method: Code, - result: Any, - interpretation: Code, - components: [ComponentSchema], - relatedTo: [String], - performer: [AnyEntity], - qdmTitle: { type: String, default: 'Assessment, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.117' }, - qdmCategory: { type: String, default: 'assessment' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::AssessmentPerformed' }, + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } -}); + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; -module.exports.AssessmentPerformedSchema = AssessmentPerformedSchema; -class AssessmentPerformed extends mongoose.Document { - constructor(object) { - super(object, AssessmentPerformedSchema); - this._type = 'QDM::AssessmentPerformed'; - } + return _wrapNativeSuper(Class); } -module.exports.AssessmentPerformed = AssessmentPerformed; +function _objectWithoutPropertiesLoose(source, excluded) { + if (source == null) return {}; + var target = {}; + var sourceKeys = Object.keys(source); + var key, i; + for (i = 0; i < sourceKeys.length; i++) { + key = sourceKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + target[key] = source[key]; + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],112:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return target; +} -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(n); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); +} +function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; -const AssessmentRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - negationRationale: Code, - reason: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Assessment, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.118' }, - qdmCategory: { type: String, default: 'assessment' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::AssessmentRecommended' }, + return arr2; +} -}); +function _createForOfIteratorHelperLoose(o) { + var i = 0; -module.exports.AssessmentRecommendedSchema = AssessmentRecommendedSchema; -class AssessmentRecommended extends mongoose.Document { - constructor(object) { - super(object, AssessmentRecommendedSchema); - this._type = 'QDM::AssessmentRecommended'; + if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { + if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) return function () { + if (i >= o.length) return { + done: true + }; + return { + done: false, + value: o[i++] + }; + }; + throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } -} - -module.exports.AssessmentRecommended = AssessmentRecommended; + i = o[Symbol.iterator](); + return i.next.bind(i); +} -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],113:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +// these aren't really private, but nor are they really useful to document -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +/** + * @private + */ +var LuxonError = /*#__PURE__*/function (_Error) { + _inheritsLoose(LuxonError, _Error); + function LuxonError() { + return _Error.apply(this, arguments) || this; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return LuxonError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); +/** + * @private + */ -const CareGoalSchema = DataElementSchema({ - statusDate: QDMDate, - relevantPeriod: Interval, - relatedTo: [String], - targetOutcome: Any, - performer: [AnyEntity], - qdmTitle: { type: String, default: 'Care Goal' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.7' }, - qdmCategory: { type: String, default: 'care_goal' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::CareGoal' }, -}); +var InvalidDateTimeError = /*#__PURE__*/function (_LuxonError) { + _inheritsLoose(InvalidDateTimeError, _LuxonError); -module.exports.CareGoalSchema = CareGoalSchema; -class CareGoal extends mongoose.Document { - constructor(object) { - super(object, CareGoalSchema); - this._type = 'QDM::CareGoal'; + function InvalidDateTimeError(reason) { + return _LuxonError.call(this, "Invalid DateTime: " + reason.toMessage()) || this; } -} -module.exports.CareGoal = CareGoal; + return InvalidDateTimeError; +}(LuxonError); +/** + * @private + */ +var InvalidIntervalError = /*#__PURE__*/function (_LuxonError2) { + _inheritsLoose(InvalidIntervalError, _LuxonError2); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],114:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + function InvalidIntervalError(reason) { + return _LuxonError2.call(this, "Invalid Interval: " + reason.toMessage()) || this; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + return InvalidIntervalError; +}(LuxonError); +/** + * @private + */ +var InvalidDurationError = /*#__PURE__*/function (_LuxonError3) { + _inheritsLoose(InvalidDurationError, _LuxonError3); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + function InvalidDurationError(reason) { + return _LuxonError3.call(this, "Invalid Duration: " + reason.toMessage()) || this; + } -const CommunicationPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - category: Code, - medium: Code, - sender: [AnyEntity], - recipient: [AnyEntity], - relatedTo: [String], - sentDatetime: DateTime, - receivedDatetime: DateTime, - negationRationale: Code, - qdmTitle: { type: String, default: 'Communication, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.132' }, - qdmCategory: { type: String, default: 'communication' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::CommunicationPerformed' }, + return InvalidDurationError; +}(LuxonError); +/** + * @private + */ -}); +var ConflictingSpecificationError = /*#__PURE__*/function (_LuxonError4) { + _inheritsLoose(ConflictingSpecificationError, _LuxonError4); -module.exports.CommunicationPerformedSchema = CommunicationPerformedSchema; -class CommunicationPerformed extends mongoose.Document { - constructor(object) { - super(object, CommunicationPerformedSchema); - this._type = 'QDM::CommunicationPerformed'; + function ConflictingSpecificationError() { + return _LuxonError4.apply(this, arguments) || this; } -} -module.exports.CommunicationPerformed = CommunicationPerformed; + return ConflictingSpecificationError; +}(LuxonError); +/** + * @private + */ +var InvalidUnitError = /*#__PURE__*/function (_LuxonError5) { + _inheritsLoose(InvalidUnitError, _LuxonError5); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],115:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + function InvalidUnitError(unit) { + return _LuxonError5.call(this, "Invalid unit " + unit) || this; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + return InvalidUnitError; +}(LuxonError); +/** + * @private + */ +var InvalidArgumentError = /*#__PURE__*/function (_LuxonError6) { + _inheritsLoose(InvalidArgumentError, _LuxonError6); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + function InvalidArgumentError() { + return _LuxonError6.apply(this, arguments) || this; + } -const DeviceOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - negationRationale: Code, - reason: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Device, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.15' }, - qdmCategory: { type: String, default: 'device' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DeviceOrder' }, + return InvalidArgumentError; +}(LuxonError); +/** + * @private + */ -}); +var ZoneIsAbstractError = /*#__PURE__*/function (_LuxonError7) { + _inheritsLoose(ZoneIsAbstractError, _LuxonError7); -module.exports.DeviceOrderSchema = DeviceOrderSchema; -class DeviceOrder extends mongoose.Document { - constructor(object) { - super(object, DeviceOrderSchema); - this._type = 'QDM::DeviceOrder'; + function ZoneIsAbstractError() { + return _LuxonError7.call(this, "Zone is an abstract class") || this; } -} -module.exports.DeviceOrder = DeviceOrder; + return ZoneIsAbstractError; +}(LuxonError); + +/** + * @private + */ +var n = "numeric", + s = "short", + l = "long"; +var DATE_SHORT = { + year: n, + month: n, + day: n +}; +var DATE_MED = { + year: n, + month: s, + day: n +}; +var DATE_MED_WITH_WEEKDAY = { + year: n, + month: s, + day: n, + weekday: s +}; +var DATE_FULL = { + year: n, + month: l, + day: n +}; +var DATE_HUGE = { + year: n, + month: l, + day: n, + weekday: l +}; +var TIME_SIMPLE = { + hour: n, + minute: n +}; +var TIME_WITH_SECONDS = { + hour: n, + minute: n, + second: n +}; +var TIME_WITH_SHORT_OFFSET = { + hour: n, + minute: n, + second: n, + timeZoneName: s +}; +var TIME_WITH_LONG_OFFSET = { + hour: n, + minute: n, + second: n, + timeZoneName: l +}; +var TIME_24_SIMPLE = { + hour: n, + minute: n, + hour12: false +}; +/** + * {@link toLocaleString}; format like '09:30:23', always 24-hour. + */ +var TIME_24_WITH_SECONDS = { + hour: n, + minute: n, + second: n, + hour12: false +}; +/** + * {@link toLocaleString}; format like '09:30:23 EDT', always 24-hour. + */ -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],116:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +var TIME_24_WITH_SHORT_OFFSET = { + hour: n, + minute: n, + second: n, + hour12: false, + timeZoneName: s +}; +/** + * {@link toLocaleString}; format like '09:30:23 Eastern Daylight Time', always 24-hour. + */ -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +var TIME_24_WITH_LONG_OFFSET = { + hour: n, + minute: n, + second: n, + hour12: false, + timeZoneName: l +}; +/** + * {@link toLocaleString}; format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is. + */ +var DATETIME_SHORT = { + year: n, + month: n, + day: n, + hour: n, + minute: n +}; +/** + * {@link toLocaleString}; format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is. + */ -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +var DATETIME_SHORT_WITH_SECONDS = { + year: n, + month: n, + day: n, + hour: n, + minute: n, + second: n +}; +var DATETIME_MED = { + year: n, + month: s, + day: n, + hour: n, + minute: n +}; +var DATETIME_MED_WITH_SECONDS = { + year: n, + month: s, + day: n, + hour: n, + minute: n, + second: n +}; +var DATETIME_MED_WITH_WEEKDAY = { + year: n, + month: s, + day: n, + weekday: s, + hour: n, + minute: n +}; +var DATETIME_FULL = { + year: n, + month: l, + day: n, + hour: n, + minute: n, + timeZoneName: s +}; +var DATETIME_FULL_WITH_SECONDS = { + year: n, + month: l, + day: n, + hour: n, + minute: n, + second: n, + timeZoneName: s +}; +var DATETIME_HUGE = { + year: n, + month: l, + day: n, + weekday: l, + hour: n, + minute: n, + timeZoneName: l +}; +var DATETIME_HUGE_WITH_SECONDS = { + year: n, + month: l, + day: n, + weekday: l, + hour: n, + minute: n, + second: n, + timeZoneName: l +}; -const DeviceRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - negationRationale: Code, - reason: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Device, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.16' }, - qdmCategory: { type: String, default: 'device' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DeviceRecommended' }, +/* + This is just a junk drawer, containing anything used across multiple classes. + Because Luxon is small(ish), this should stay small and we won't worry about splitting + it up into, say, parsingUtil.js and basicUtil.js and so on. But they are divided up by feature area. +*/ +/** + * @private + */ +// TYPES -}); +function isUndefined(o) { + return typeof o === "undefined"; +} +function isNumber(o) { + return typeof o === "number"; +} +function isInteger(o) { + return typeof o === "number" && o % 1 === 0; +} +function isString(o) { + return typeof o === "string"; +} +function isDate(o) { + return Object.prototype.toString.call(o) === "[object Date]"; +} // CAPABILITIES -module.exports.DeviceRecommendedSchema = DeviceRecommendedSchema; -class DeviceRecommended extends mongoose.Document { - constructor(object) { - super(object, DeviceRecommendedSchema); - this._type = 'QDM::DeviceRecommended'; +function hasIntl() { + try { + return typeof Intl !== "undefined" && Intl.DateTimeFormat; + } catch (e) { + return false; } } +function hasFormatToParts() { + return !isUndefined(Intl.DateTimeFormat.prototype.formatToParts); +} +function hasRelative() { + try { + return typeof Intl !== "undefined" && !!Intl.RelativeTimeFormat; + } catch (e) { + return false; + } +} // OBJECTS AND ARRAYS -module.exports.DeviceRecommended = DeviceRecommended; - +function maybeArray(thing) { + return Array.isArray(thing) ? thing : [thing]; +} +function bestBy(arr, by, compare) { + if (arr.length === 0) { + return undefined; + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],117:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return arr.reduce(function (best, next) { + var pair = [by(next), next]; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + if (!best) { + return pair; + } else if (compare(best[0], pair[0]) === best[0]) { + return best; + } else { + return pair; + } + }, null)[1]; +} +function pick(obj, keys) { + return keys.reduce(function (a, k) { + a[k] = obj[k]; + return a; + }, {}); +} +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} // NUMBERS AND STRINGS +function integerBetween(thing, bottom, top) { + return isInteger(thing) && thing >= bottom && thing <= top; +} // x % n but takes the sign of n instead of x -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +function floorMod(x, n) { + return x - n * Math.floor(x / n); +} +function padStart(input, n) { + if (n === void 0) { + n = 2; + } -const DiagnosisSchema = DataElementSchema({ - authorDatetime: DateTime, - prevalencePeriod: Interval, - anatomicalLocationSite: Code, - severity: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Diagnosis' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.110' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.135' }, - qdmCategory: { type: String, default: 'condition' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Diagnosis' }, + var minus = input < 0 ? "-" : ""; + var target = minus ? input * -1 : input; + var result; -}); + if (target.toString().length < n) { + result = ("0".repeat(n) + target).slice(-n); + } else { + result = target.toString(); + } -module.exports.DiagnosisSchema = DiagnosisSchema; -class Diagnosis extends mongoose.Document { - constructor(object) { - super(object, DiagnosisSchema); - this._type = 'QDM::Diagnosis'; + return "" + minus + result; +} +function parseInteger(string) { + if (isUndefined(string) || string === null || string === "") { + return undefined; + } else { + return parseInt(string, 10); } } - -module.exports.Diagnosis = Diagnosis; - - -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],118:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); - -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); - - -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; - -const DiagnosticStudyOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Diagnostic Study, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.22' }, - qdmCategory: { type: String, default: 'diagnostic_study' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DiagnosticStudyOrder' }, - -}); - -module.exports.DiagnosticStudyOrderSchema = DiagnosticStudyOrderSchema; -class DiagnosticStudyOrder extends mongoose.Document { - constructor(object) { - super(object, DiagnosticStudyOrderSchema); - this._type = 'QDM::DiagnosticStudyOrder'; +function parseMillis(fraction) { + // Return undefined (instead of 0) in these cases, where fraction is not set + if (isUndefined(fraction) || fraction === null || fraction === "") { + return undefined; + } else { + var f = parseFloat("0." + fraction) * 1000; + return Math.floor(f); } } +function roundTo(number, digits, towardZero) { + if (towardZero === void 0) { + towardZero = false; + } -module.exports.DiagnosticStudyOrder = DiagnosticStudyOrder; - - -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],119:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); - -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); - + var factor = Math.pow(10, digits), + rounder = towardZero ? Math.trunc : Math.round; + return rounder(number * factor) / factor; +} // DATE BASICS -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +function isLeapYear(year) { + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); +} +function daysInYear(year) { + return isLeapYear(year) ? 366 : 365; +} +function daysInMonth(year, month) { + var modMonth = floorMod(month - 1, 12) + 1, + modYear = year + (month - modMonth) / 12; -const DiagnosticStudyPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - reason: Code, - result: Any, - resultDatetime: DateTime, - interpretation: Code, - status: Code, - method: Code, - facilityLocation: FacilityLocationSchema, - negationRationale: Code, - components: [ComponentSchema], - performer: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Diagnostic Study, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.23' }, - qdmCategory: { type: String, default: 'diagnostic_study' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DiagnosticStudyPerformed' }, + if (modMonth === 2) { + return isLeapYear(modYear) ? 29 : 28; + } else { + return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1]; + } +} // covert a calendar object to a local timestamp (epoch, but with the offset baked in) -}); +function objToLocalTS(obj) { + var d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond); // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that -module.exports.DiagnosticStudyPerformedSchema = DiagnosticStudyPerformedSchema; -class DiagnosticStudyPerformed extends mongoose.Document { - constructor(object) { - super(object, DiagnosticStudyPerformedSchema); - this._type = 'QDM::DiagnosticStudyPerformed'; + if (obj.year < 100 && obj.year >= 0) { + d = new Date(d); + d.setUTCFullYear(d.getUTCFullYear() - 1900); } -} - -module.exports.DiagnosticStudyPerformed = DiagnosticStudyPerformed; + return +d; +} +function weeksInWeekYear(weekYear) { + var p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7, + last = weekYear - 1, + p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7; + return p1 === 4 || p2 === 3 ? 53 : 52; +} +function untruncateYear(year) { + if (year > 99) { + return year; + } else return year > 60 ? 1900 + year : 2000 + year; +} // PARSING -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],120:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +function parseZoneInfo(ts, offsetFormat, locale, timeZone) { + if (timeZone === void 0) { + timeZone = null; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var date = new Date(ts), + intlOpts = { + hour12: false, + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit" + }; + if (timeZone) { + intlOpts.timeZone = timeZone; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + var modified = Object.assign({ + timeZoneName: offsetFormat + }, intlOpts), + intl = hasIntl(); -const DiagnosticStudyRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Diagnostic Study, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.24' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.19' }, - qdmCategory: { type: String, default: 'diagnostic_study' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DiagnosticStudyRecommended' }, + if (intl && hasFormatToParts()) { + var parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find(function (m) { + return m.type.toLowerCase() === "timezonename"; + }); + return parsed ? parsed.value : null; + } else if (intl) { + // this probably doesn't work for all locales + var without = new Intl.DateTimeFormat(locale, intlOpts).format(date), + included = new Intl.DateTimeFormat(locale, modified).format(date), + diffed = included.substring(without.length), + trimmed = diffed.replace(/^[, \u200e]+/, ""); + return trimmed; + } else { + return null; + } +} // signedOffset('-5', '30') -> -330 -}); +function signedOffset(offHourStr, offMinuteStr) { + var offHour = parseInt(offHourStr, 10); // don't || this because we want to preserve -0 -module.exports.DiagnosticStudyRecommendedSchema = DiagnosticStudyRecommendedSchema; -class DiagnosticStudyRecommended extends mongoose.Document { - constructor(object) { - super(object, DiagnosticStudyRecommendedSchema); - this._type = 'QDM::DiagnosticStudyRecommended'; + if (Number.isNaN(offHour)) { + offHour = 0; } -} - -module.exports.DiagnosticStudyRecommended = DiagnosticStudyRecommended; + var offMin = parseInt(offMinuteStr, 10) || 0, + offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin; + return offHour * 60 + offMinSigned; +} // COERCION -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],121:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +function asNumber(value) { + var numericValue = Number(value); + if (typeof value === "boolean" || value === "" || Number.isNaN(numericValue)) throw new InvalidArgumentError("Invalid unit value " + value); + return numericValue; +} +function normalizeObject(obj, normalizer, nonUnitKeys) { + var normalized = {}; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + for (var u in obj) { + if (hasOwnProperty(obj, u)) { + if (nonUnitKeys.indexOf(u) >= 0) continue; + var v = obj[u]; + if (v === undefined || v === null) continue; + normalized[normalizer(u)] = asNumber(v); + } + } + return normalized; +} +function formatOffset(offset, format) { + var hours = Math.trunc(Math.abs(offset / 60)), + minutes = Math.trunc(Math.abs(offset % 60)), + sign = offset >= 0 ? "+" : "-"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + switch (format) { + case "short": + return "" + sign + padStart(hours, 2) + ":" + padStart(minutes, 2); -const EncounterOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - facilityLocation: FacilityLocationSchema, - negationRationale: Code, - requester: [AnyEntity], - priority: Code, - qdmTitle: { type: String, default: 'Encounter, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.27' }, - qdmCategory: { type: String, default: 'encounter' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::EncounterOrder' }, + case "narrow": + return "" + sign + hours + (minutes > 0 ? ":" + minutes : ""); -}); + case "techie": + return "" + sign + padStart(hours, 2) + padStart(minutes, 2); -module.exports.EncounterOrderSchema = EncounterOrderSchema; -class EncounterOrder extends mongoose.Document { - constructor(object) { - super(object, EncounterOrderSchema); - this._type = 'QDM::EncounterOrder'; + default: + throw new RangeError("Value format " + format + " is out of range for property format"); } } +function timeObject(obj) { + return pick(obj, ["hour", "minute", "second", "millisecond"]); +} +var ianaRegex = /[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?/; -module.exports.EncounterOrder = EncounterOrder; - - -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],122:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); - -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); -const { DiagnosisComponentSchema } = require('./attributes/DiagnosisComponent'); - -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; - -const EncounterPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - admissionSource: Code, - class: Code, - relevantPeriod: Interval, - dischargeDisposition: Code, - facilityLocations: [FacilityLocationSchema], - diagnoses: [DiagnosisComponentSchema], - lengthOfStay: Quantity, - priority: Code, - participant: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Encounter, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.5' }, - qdmCategory: { type: String, default: 'encounter' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::EncounterPerformed' }, - -}); - -module.exports.EncounterPerformedSchema = EncounterPerformedSchema; -class EncounterPerformed extends mongoose.Document { - constructor(object) { - super(object, EncounterPerformedSchema); - this._type = 'QDM::EncounterPerformed'; - if (object && object.clazz) { - this.class = object.clazz; - } - } +function stringify(obj) { + return JSON.stringify(obj, Object.keys(obj).sort()); } +/** + * @private + */ + -module.exports.EncounterPerformed = EncounterPerformed; +var monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; +var monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; +var monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"]; +function months(length) { + switch (length) { + case "narrow": + return [].concat(monthsNarrow); + case "short": + return [].concat(monthsShort); -},{"./attributes/Component":163,"./attributes/DiagnosisComponent":164,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],123:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "long": + return [].concat(monthsLong); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "numeric": + return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; + case "2-digit": + return ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + default: + return null; + } +} +var weekdaysLong = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; +var weekdaysShort = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; +var weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"]; +function weekdays(length) { + switch (length) { + case "narrow": + return [].concat(weekdaysNarrow); -const EncounterRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - facilityLocation: FacilityLocationSchema, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Encounter, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.28' }, - qdmCategory: { type: String, default: 'encounter' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::EncounterRecommended' }, + case "short": + return [].concat(weekdaysShort); -}); + case "long": + return [].concat(weekdaysLong); -module.exports.EncounterRecommendedSchema = EncounterRecommendedSchema; -class EncounterRecommended extends mongoose.Document { - constructor(object) { - super(object, EncounterRecommendedSchema); - this._type = 'QDM::EncounterRecommended'; + case "numeric": + return ["1", "2", "3", "4", "5", "6", "7"]; + + default: + return null; } } +var meridiems = ["AM", "PM"]; +var erasLong = ["Before Christ", "Anno Domini"]; +var erasShort = ["BC", "AD"]; +var erasNarrow = ["B", "A"]; +function eras(length) { + switch (length) { + case "narrow": + return [].concat(erasNarrow); -module.exports.EncounterRecommended = EncounterRecommended; + case "short": + return [].concat(erasShort); + case "long": + return [].concat(erasLong); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],124:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + default: + return null; + } +} +function meridiemForDateTime(dt) { + return meridiems[dt.hour < 12 ? 0 : 1]; +} +function weekdayForDateTime(dt, length) { + return weekdays(length)[dt.weekday - 1]; +} +function monthForDateTime(dt, length) { + return months(length)[dt.month - 1]; +} +function eraForDateTime(dt, length) { + return eras(length)[dt.year < 0 ? 0 : 1]; +} +function formatRelativeTime(unit, count, numeric, narrow) { + if (numeric === void 0) { + numeric = "always"; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + if (narrow === void 0) { + narrow = false; + } + + var units = { + years: ["year", "yr."], + quarters: ["quarter", "qtr."], + months: ["month", "mo."], + weeks: ["week", "wk."], + days: ["day", "day", "days"], + hours: ["hour", "hr."], + minutes: ["minute", "min."], + seconds: ["second", "sec."] + }; + var lastable = ["hours", "minutes", "seconds"].indexOf(unit) === -1; + if (numeric === "auto" && lastable) { + var isDay = unit === "days"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + switch (count) { + case 1: + return isDay ? "tomorrow" : "next " + units[unit][0]; -const FamilyHistorySchema = DataElementSchema({ - authorDatetime: DateTime, - relationship: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Family History' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.111' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.12' }, - qdmCategory: { type: String, default: 'family_history' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::FamilyHistory' }, + case -1: + return isDay ? "yesterday" : "last " + units[unit][0]; -}); + case 0: + return isDay ? "today" : "this " + units[unit][0]; -module.exports.FamilyHistorySchema = FamilyHistorySchema; -class FamilyHistory extends mongoose.Document { - constructor(object) { - super(object, FamilyHistorySchema); - this._type = 'QDM::FamilyHistory'; + } } -} -module.exports.FamilyHistory = FamilyHistory; + var isInPast = Object.is(count, -0) || count < 0, + fmtValue = Math.abs(count), + singular = fmtValue === 1, + lilUnits = units[unit], + fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit; + return isInPast ? fmtValue + " " + fmtUnit + " ago" : "in " + fmtValue + " " + fmtUnit; +} +function formatString(knownFormat) { + // these all have the offsets removed because we don't have access to them + // without all the intl stuff this is backfilling + var filtered = pick(knownFormat, ["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName", "hour12"]), + key = stringify(filtered), + dateTimeHuge = "EEEE, LLLL d, yyyy, h:mm a"; + switch (key) { + case stringify(DATE_SHORT): + return "M/d/yyyy"; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],125:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case stringify(DATE_MED): + return "LLL d, yyyy"; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case stringify(DATE_MED_WITH_WEEKDAY): + return "EEE, LLL d, yyyy"; + case stringify(DATE_FULL): + return "LLLL d, yyyy"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case stringify(DATE_HUGE): + return "EEEE, LLLL d, yyyy"; -const ImmunizationAdministeredSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - reason: Code, - dosage: Quantity, - route: Code, - negationRationale: Code, - performer: [AnyEntity], - qdmTitle: { type: String, default: 'Immunization, Administered' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.112' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.140' }, - qdmCategory: { type: String, default: 'immunization' }, - qdmStatus: { type: String, default: 'administered' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ImmunizationAdministered' }, + case stringify(TIME_SIMPLE): + return "h:mm a"; -}); + case stringify(TIME_WITH_SECONDS): + return "h:mm:ss a"; -module.exports.ImmunizationAdministeredSchema = ImmunizationAdministeredSchema; -class ImmunizationAdministered extends mongoose.Document { - constructor(object) { - super(object, ImmunizationAdministeredSchema); - this._type = 'QDM::ImmunizationAdministered'; - } -} + case stringify(TIME_WITH_SHORT_OFFSET): + return "h:mm a"; -module.exports.ImmunizationAdministered = ImmunizationAdministered; + case stringify(TIME_WITH_LONG_OFFSET): + return "h:mm a"; + case stringify(TIME_24_SIMPLE): + return "HH:mm"; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],126:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case stringify(TIME_24_WITH_SECONDS): + return "HH:mm:ss"; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case stringify(TIME_24_WITH_SHORT_OFFSET): + return "HH:mm"; + case stringify(TIME_24_WITH_LONG_OFFSET): + return "HH:mm"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case stringify(DATETIME_SHORT): + return "M/d/yyyy, h:mm a"; -const ImmunizationOrderSchema = DataElementSchema({ - activeDatetime: DateTime, - authorDatetime: DateTime, - dosage: Quantity, - supply: Quantity, - reason: Code, - route: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Immunization, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.113' }, - qdmCategory: { type: String, default: 'immunization' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ImmunizationOrder' }, + case stringify(DATETIME_MED): + return "LLL d, yyyy, h:mm a"; -}); + case stringify(DATETIME_FULL): + return "LLLL d, yyyy, h:mm a"; -module.exports.ImmunizationOrderSchema = ImmunizationOrderSchema; -class ImmunizationOrder extends mongoose.Document { - constructor(object) { - super(object, ImmunizationOrderSchema); - this._type = 'QDM::ImmunizationOrder'; - } -} + case stringify(DATETIME_HUGE): + return dateTimeHuge; -module.exports.ImmunizationOrder = ImmunizationOrder; + case stringify(DATETIME_SHORT_WITH_SECONDS): + return "M/d/yyyy, h:mm:ss a"; + case stringify(DATETIME_MED_WITH_SECONDS): + return "LLL d, yyyy, h:mm:ss a"; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],127:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case stringify(DATETIME_MED_WITH_WEEKDAY): + return "EEE, d LLL yyyy, h:mm a"; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case stringify(DATETIME_FULL_WITH_SECONDS): + return "LLLL d, yyyy, h:mm:ss a"; + case stringify(DATETIME_HUGE_WITH_SECONDS): + return "EEEE, LLLL d, yyyy, h:mm:ss a"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + default: + return dateTimeHuge; + } +} -const InterventionOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Intervention, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.35' }, - qdmCategory: { type: String, default: 'intervention' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::InterventionOrder' }, +function stringifyTokens(splits, tokenToString) { + var s = ""; -}); + for (var _iterator = _createForOfIteratorHelperLoose(splits), _step; !(_step = _iterator()).done;) { + var token = _step.value; -module.exports.InterventionOrderSchema = InterventionOrderSchema; -class InterventionOrder extends mongoose.Document { - constructor(object) { - super(object, InterventionOrderSchema); - this._type = 'QDM::InterventionOrder'; + if (token.literal) { + s += token.val; + } else { + s += tokenToString(token.val); + } } + + return s; } -module.exports.InterventionOrder = InterventionOrder; +var _macroTokenToFormatOpts = { + D: DATE_SHORT, + DD: DATE_MED, + DDD: DATE_FULL, + DDDD: DATE_HUGE, + t: TIME_SIMPLE, + tt: TIME_WITH_SECONDS, + ttt: TIME_WITH_SHORT_OFFSET, + tttt: TIME_WITH_LONG_OFFSET, + T: TIME_24_SIMPLE, + TT: TIME_24_WITH_SECONDS, + TTT: TIME_24_WITH_SHORT_OFFSET, + TTTT: TIME_24_WITH_LONG_OFFSET, + f: DATETIME_SHORT, + ff: DATETIME_MED, + fff: DATETIME_FULL, + ffff: DATETIME_HUGE, + F: DATETIME_SHORT_WITH_SECONDS, + FF: DATETIME_MED_WITH_SECONDS, + FFF: DATETIME_FULL_WITH_SECONDS, + FFFF: DATETIME_HUGE_WITH_SECONDS +}; +/** + * @private + */ + +var Formatter = /*#__PURE__*/function () { + Formatter.create = function create(locale, opts) { + if (opts === void 0) { + opts = {}; + } + return new Formatter(locale, opts); + }; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],128:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + Formatter.parseFormat = function parseFormat(fmt) { + var current = null, + currentFull = "", + bracketed = false; + var splits = []; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + for (var i = 0; i < fmt.length; i++) { + var c = fmt.charAt(i); + if (c === "'") { + if (currentFull.length > 0) { + splits.push({ + literal: bracketed, + val: currentFull + }); + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + current = null; + currentFull = ""; + bracketed = !bracketed; + } else if (bracketed) { + currentFull += c; + } else if (c === current) { + currentFull += c; + } else { + if (currentFull.length > 0) { + splits.push({ + literal: false, + val: currentFull + }); + } -const InterventionPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - reason: Code, - result: Any, - status: Code, - negationRationale: Code, - performer: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Intervention, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.36' }, - qdmCategory: { type: String, default: 'intervention' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::InterventionPerformed' }, + currentFull = c; + current = c; + } + } -}); + if (currentFull.length > 0) { + splits.push({ + literal: bracketed, + val: currentFull + }); + } -module.exports.InterventionPerformedSchema = InterventionPerformedSchema; -class InterventionPerformed extends mongoose.Document { - constructor(object) { - super(object, InterventionPerformedSchema); - this._type = 'QDM::InterventionPerformed'; + return splits; + }; + + Formatter.macroTokenToFormatOpts = function macroTokenToFormatOpts(token) { + return _macroTokenToFormatOpts[token]; + }; + + function Formatter(locale, formatOpts) { + this.opts = formatOpts; + this.loc = locale; + this.systemLoc = null; } -} -module.exports.InterventionPerformed = InterventionPerformed; + var _proto = Formatter.prototype; + + _proto.formatWithSystemDefault = function formatWithSystemDefault(dt, opts) { + if (this.systemLoc === null) { + this.systemLoc = this.loc.redefaultToSystem(); + } + var df = this.systemLoc.dtFormatter(dt, Object.assign({}, this.opts, opts)); + return df.format(); + }; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],129:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.formatDateTime = function formatDateTime(dt, opts) { + if (opts === void 0) { + opts = {}; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts)); + return df.format(); + }; + + _proto.formatDateTimeParts = function formatDateTimeParts(dt, opts) { + if (opts === void 0) { + opts = {}; + } + + var df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts)); + return df.formatToParts(); + }; + _proto.resolvedOptions = function resolvedOptions(dt, opts) { + if (opts === void 0) { + opts = {}; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + var df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts)); + return df.resolvedOptions(); + }; -const InterventionRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Intervention, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.37' }, - qdmCategory: { type: String, default: 'intervention' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::InterventionRecommended' }, + _proto.num = function num(n, p) { + if (p === void 0) { + p = 0; + } -}); + // we get some perf out of doing this here, annoyingly + if (this.opts.forceSimple) { + return padStart(n, p); + } -module.exports.InterventionRecommendedSchema = InterventionRecommendedSchema; -class InterventionRecommended extends mongoose.Document { - constructor(object) { - super(object, InterventionRecommendedSchema); - this._type = 'QDM::InterventionRecommended'; - } -} + var opts = Object.assign({}, this.opts); -module.exports.InterventionRecommended = InterventionRecommended; + if (p > 0) { + opts.padTo = p; + } + return this.loc.numberFormatter(opts).format(n); + }; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],130:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.formatDateTimeFromString = function formatDateTimeFromString(dt, fmt) { + var _this = this; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var knownEnglish = this.loc.listingMode() === "en", + useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory" && hasFormatToParts(), + string = function string(opts, extract) { + return _this.loc.extract(dt, opts, extract); + }, + formatOffset = function formatOffset(opts) { + if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) { + return "Z"; + } + return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : ""; + }, + meridiem = function meridiem() { + return knownEnglish ? meridiemForDateTime(dt) : string({ + hour: "numeric", + hour12: true + }, "dayperiod"); + }, + month = function month(length, standalone) { + return knownEnglish ? monthForDateTime(dt, length) : string(standalone ? { + month: length + } : { + month: length, + day: "numeric" + }, "month"); + }, + weekday = function weekday(length, standalone) { + return knownEnglish ? weekdayForDateTime(dt, length) : string(standalone ? { + weekday: length + } : { + weekday: length, + month: "long", + day: "numeric" + }, "weekday"); + }, + maybeMacro = function maybeMacro(token) { + var formatOpts = Formatter.macroTokenToFormatOpts(token); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + if (formatOpts) { + return _this.formatWithSystemDefault(dt, formatOpts); + } else { + return token; + } + }, + era = function era(length) { + return knownEnglish ? eraForDateTime(dt, length) : string({ + era: length + }, "era"); + }, + tokenToString = function tokenToString(token) { + // Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles + switch (token) { + // ms + case "S": + return _this.num(dt.millisecond); -const LaboratoryTestOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Laboratory Test, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.41' }, - qdmCategory: { type: String, default: 'laboratory_test' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::LaboratoryTestOrder' }, + case "u": // falls through -}); + case "SSS": + return _this.num(dt.millisecond, 3); + // seconds -module.exports.LaboratoryTestOrderSchema = LaboratoryTestOrderSchema; -class LaboratoryTestOrder extends mongoose.Document { - constructor(object) { - super(object, LaboratoryTestOrderSchema); - this._type = 'QDM::LaboratoryTestOrder'; - } -} + case "s": + return _this.num(dt.second); -module.exports.LaboratoryTestOrder = LaboratoryTestOrder; + case "ss": + return _this.num(dt.second, 2); + // minutes + case "m": + return _this.num(dt.minute); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],131:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "mm": + return _this.num(dt.minute, 2); + // hours -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "h": + return _this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12); + case "hh": + return _this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12, 2); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "H": + return _this.num(dt.hour); -const LaboratoryTestPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - status: Code, - method: Code, - result: Any, - resultDatetime: DateTime, - reason: Code, - referenceRange: Interval, - interpretation: Code, - negationRationale: Code, - components: [ComponentSchema], - performer: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Laboratory Test, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.42' }, - qdmCategory: { type: String, default: 'laboratory_test' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::LaboratoryTestPerformed' }, + case "HH": + return _this.num(dt.hour, 2); + // offset -}); + case "Z": + // like +6 + return formatOffset({ + format: "narrow", + allowZ: _this.opts.allowZ + }); -module.exports.LaboratoryTestPerformedSchema = LaboratoryTestPerformedSchema; -class LaboratoryTestPerformed extends mongoose.Document { - constructor(object) { - super(object, LaboratoryTestPerformedSchema); - this._type = 'QDM::LaboratoryTestPerformed'; - } -} + case "ZZ": + // like +06:00 + return formatOffset({ + format: "short", + allowZ: _this.opts.allowZ + }); -module.exports.LaboratoryTestPerformed = LaboratoryTestPerformed; + case "ZZZ": + // like +0600 + return formatOffset({ + format: "techie", + allowZ: _this.opts.allowZ + }); + case "ZZZZ": + // like EST + return dt.zone.offsetName(dt.ts, { + format: "short", + locale: _this.loc.locale + }); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],132:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "ZZZZZ": + // like Eastern Standard Time + return dt.zone.offsetName(dt.ts, { + format: "long", + locale: _this.loc.locale + }); + // zone -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "z": + // like America/New_York + return dt.zoneName; + // meridiems + case "a": + return meridiem(); + // dates -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "d": + return useDateTimeFormatter ? string({ + day: "numeric" + }, "day") : _this.num(dt.day); -const LaboratoryTestRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Laboratory Test, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.43' }, - qdmCategory: { type: String, default: 'laboratory_test' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::LaboratoryTestRecommended' }, + case "dd": + return useDateTimeFormatter ? string({ + day: "2-digit" + }, "day") : _this.num(dt.day, 2); + // weekdays - standalone -}); + case "c": + // like 1 + return _this.num(dt.weekday); -module.exports.LaboratoryTestRecommendedSchema = LaboratoryTestRecommendedSchema; -class LaboratoryTestRecommended extends mongoose.Document { - constructor(object) { - super(object, LaboratoryTestRecommendedSchema); - this._type = 'QDM::LaboratoryTestRecommended'; - } -} + case "ccc": + // like 'Tues' + return weekday("short", true); -module.exports.LaboratoryTestRecommended = LaboratoryTestRecommended; + case "cccc": + // like 'Tuesday' + return weekday("long", true); + case "ccccc": + // like 'T' + return weekday("narrow", true); + // weekdays - format -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],133:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "E": + // like 1 + return _this.num(dt.weekday); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "EEE": + // like 'Tues' + return weekday("short", false); + case "EEEE": + // like 'Tuesday' + return weekday("long", false); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "EEEEE": + // like 'T' + return weekday("narrow", false); + // months - standalone -const MedicationActiveSchema = DataElementSchema({ - relevantDatetime: DateTime, - relevantPeriod: Interval, - dosage: Quantity, - frequency: Code, - route: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Medication, Active' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.44' }, - qdmCategory: { type: String, default: 'medication' }, - qdmStatus: { type: String, default: 'active' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::MedicationActive' }, + case "L": + // like 1 + return useDateTimeFormatter ? string({ + month: "numeric", + day: "numeric" + }, "month") : _this.num(dt.month); -}); + case "LL": + // like 01, doesn't seem to work + return useDateTimeFormatter ? string({ + month: "2-digit", + day: "numeric" + }, "month") : _this.num(dt.month, 2); -module.exports.MedicationActiveSchema = MedicationActiveSchema; -class MedicationActive extends mongoose.Document { - constructor(object) { - super(object, MedicationActiveSchema); - this._type = 'QDM::MedicationActive'; - } -} + case "LLL": + // like Jan + return month("short", true); -module.exports.MedicationActive = MedicationActive; + case "LLLL": + // like January + return month("long", true); + case "LLLLL": + // like J + return month("narrow", true); + // months - format -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],134:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "M": + // like 1 + return useDateTimeFormatter ? string({ + month: "numeric" + }, "month") : _this.num(dt.month); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "MM": + // like 01 + return useDateTimeFormatter ? string({ + month: "2-digit" + }, "month") : _this.num(dt.month, 2); + case "MMM": + // like Jan + return month("short", false); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "MMMM": + // like January + return month("long", false); -const MedicationAdministeredSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - dosage: Quantity, - frequency: Code, - route: Code, - reason: Code, - negationRationale: Code, - performer: [AnyEntity], - qdmTitle: { type: String, default: 'Medication, Administered' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.45' }, - qdmCategory: { type: String, default: 'medication' }, - qdmStatus: { type: String, default: 'administered' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::MedicationAdministered' }, + case "MMMMM": + // like J + return month("narrow", false); + // years -}); + case "y": + // like 2014 + return useDateTimeFormatter ? string({ + year: "numeric" + }, "year") : _this.num(dt.year); -module.exports.MedicationAdministeredSchema = MedicationAdministeredSchema; -class MedicationAdministered extends mongoose.Document { - constructor(object) { - super(object, MedicationAdministeredSchema); - this._type = 'QDM::MedicationAdministered'; - } -} + case "yy": + // like 14 + return useDateTimeFormatter ? string({ + year: "2-digit" + }, "year") : _this.num(dt.year.toString().slice(-2), 2); -module.exports.MedicationAdministered = MedicationAdministered; + case "yyyy": + // like 0012 + return useDateTimeFormatter ? string({ + year: "numeric" + }, "year") : _this.num(dt.year, 4); + case "yyyyyy": + // like 000012 + return useDateTimeFormatter ? string({ + year: "numeric" + }, "year") : _this.num(dt.year, 6); + // eras -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],135:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "G": + // like AD + return era("short"); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "GG": + // like Anno Domini + return era("long"); + case "GGGGG": + return era("narrow"); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "kk": + return _this.num(dt.weekYear.toString().slice(-2), 2); -const MedicationDischargeSchema = DataElementSchema({ - authorDatetime: DateTime, - refills: Number, - dosage: Quantity, - supply: Quantity, - frequency: Code, - daysSupplied: Number, - route: Code, - negationRationale: Code, - prescriber: [AnyEntity], - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Medication, Discharge' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.48' }, - qdmCategory: { type: String, default: 'medication' }, - qdmStatus: { type: String, default: 'discharge' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::MedicationDischarge' }, + case "kkkk": + return _this.num(dt.weekYear, 4); + + case "W": + return _this.num(dt.weekNumber); -}); + case "WW": + return _this.num(dt.weekNumber, 2); -module.exports.MedicationDischargeSchema = MedicationDischargeSchema; -class MedicationDischarge extends mongoose.Document { - constructor(object) { - super(object, MedicationDischargeSchema); - this._type = 'QDM::MedicationDischarge'; - } -} + case "o": + return _this.num(dt.ordinal); -module.exports.MedicationDischarge = MedicationDischarge; + case "ooo": + return _this.num(dt.ordinal, 3); + case "q": + // like 1 + return _this.num(dt.quarter); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],136:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "qq": + // like 01 + return _this.num(dt.quarter, 2); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "X": + return _this.num(Math.floor(dt.ts / 1000)); + case "x": + return _this.num(dt.ts); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + default: + return maybeMacro(token); + } + }; -const MedicationDispensedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - refills: Number, - dosage: Quantity, - supply: Quantity, - frequency: Code, - daysSupplied: Number, - route: Code, - prescriber: [AnyEntity], - dispenser: [AnyEntity], - negationRationale: Code, - relatedTo: [String], - qdmTitle: { type: String, default: 'Medication, Dispensed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.49' }, - qdmCategory: { type: String, default: 'medication' }, - qdmStatus: { type: String, default: 'dispensed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::MedicationDispensed' }, + return stringifyTokens(Formatter.parseFormat(fmt), tokenToString); + }; -}); + _proto.formatDurationFromString = function formatDurationFromString(dur, fmt) { + var _this2 = this; -module.exports.MedicationDispensedSchema = MedicationDispensedSchema; -class MedicationDispensed extends mongoose.Document { - constructor(object) { - super(object, MedicationDispensedSchema); - this._type = 'QDM::MedicationDispensed'; - } -} + var tokenToField = function tokenToField(token) { + switch (token[0]) { + case "S": + return "millisecond"; -module.exports.MedicationDispensed = MedicationDispensed; + case "s": + return "second"; + case "m": + return "minute"; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],137:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + case "h": + return "hour"; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + case "d": + return "day"; + case "M": + return "month"; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + case "y": + return "year"; -const MedicationOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantPeriod: Interval, - refills: Number, - dosage: Quantity, - supply: Quantity, - frequency: Code, - daysSupplied: Number, - route: Code, - setting: Code, - reason: Code, - negationRationale: Code, - prescriber: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Medication, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.51' }, - qdmCategory: { type: String, default: 'medication' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::MedicationOrder' }, + default: + return null; + } + }, + tokenToString = function tokenToString(lildur) { + return function (token) { + var mapped = tokenToField(token); -}); + if (mapped) { + return _this2.num(lildur.get(mapped), token.length); + } else { + return token; + } + }; + }, + tokens = Formatter.parseFormat(fmt), + realTokens = tokens.reduce(function (found, _ref) { + var literal = _ref.literal, + val = _ref.val; + return literal ? found : found.concat(val); + }, []), + collapsed = dur.shiftTo.apply(dur, realTokens.map(tokenToField).filter(function (t) { + return t; + })); -module.exports.MedicationOrderSchema = MedicationOrderSchema; -class MedicationOrder extends mongoose.Document { - constructor(object) { - super(object, MedicationOrderSchema); - this._type = 'QDM::MedicationOrder'; + return stringifyTokens(tokens, tokenToString(collapsed)); + }; + + return Formatter; +}(); + +var Invalid = /*#__PURE__*/function () { + function Invalid(reason, explanation) { + this.reason = reason; + this.explanation = explanation; } -} -module.exports.MedicationOrder = MedicationOrder; + var _proto = Invalid.prototype; + _proto.toMessage = function toMessage() { + if (this.explanation) { + return this.reason + ": " + this.explanation; + } else { + return this.reason; + } + }; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],138:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return Invalid; +}(); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +/** + * @interface + */ +var Zone = /*#__PURE__*/function () { + function Zone() {} -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + var _proto = Zone.prototype; -const ParticipationSchema = DataElementSchema({ - participationPeriod: Interval, - qdmTitle: { type: String, default: 'Participation' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.130' }, - qdmCategory: { type: String, default: 'participation' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Participation' }, + /** + * Returns the offset's common name (such as EST) at the specified timestamp + * @abstract + * @param {number} ts - Epoch milliseconds for which to get the name + * @param {Object} opts - Options to affect the format + * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'. + * @param {string} opts.locale - What locale to return the offset name in. + * @return {string} + */ + _proto.offsetName = function offsetName(ts, opts) { + throw new ZoneIsAbstractError(); + } + /** + * Returns the offset's value as a string + * @abstract + * @param {number} ts - Epoch milliseconds for which to get the offset + * @param {string} format - What style of offset to return. + * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively + * @return {string} + */ + ; -}); + _proto.formatOffset = function formatOffset(ts, format) { + throw new ZoneIsAbstractError(); + } + /** + * Return the offset in minutes for this zone at the specified timestamp. + * @abstract + * @param {number} ts - Epoch milliseconds for which to compute the offset + * @return {number} + */ + ; -module.exports.ParticipationSchema = ParticipationSchema; -class Participation extends mongoose.Document { - constructor(object) { - super(object, ParticipationSchema); - this._type = 'QDM::Participation'; + _proto.offset = function offset(ts) { + throw new ZoneIsAbstractError(); } -} + /** + * Return whether this Zone is equal to another zone + * @abstract + * @param {Zone} otherZone - the zone to compare + * @return {boolean} + */ + ; -module.exports.Participation = Participation; + _proto.equals = function equals(otherZone) { + throw new ZoneIsAbstractError(); + } + /** + * Return whether this Zone is valid. + * @abstract + * @type {boolean} + */ + ; + _createClass(Zone, [{ + key: "type", -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],139:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** + * The type of zone + * @abstract + * @type {string} + */ + get: function get() { + throw new ZoneIsAbstractError(); + } + /** + * The name of this zone. + * @abstract + * @type {string} + */ -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + }, { + key: "name", + get: function get() { + throw new ZoneIsAbstractError(); + } + /** + * Returns whether the offset is known to be fixed for the whole year. + * @abstract + * @type {boolean} + */ + }, { + key: "universal", + get: function get() { + throw new ZoneIsAbstractError(); + } + }, { + key: "isValid", + get: function get() { + throw new ZoneIsAbstractError(); + } + }]); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return Zone; +}(); -const PatientCareExperienceSchema = DataElementSchema({ - authorDatetime: DateTime, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Patient Care Experience' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.52' }, - qdmCategory: { type: String, default: 'care_experience' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCareExperience' }, +var singleton = null; +/** + * Represents the local zone for this JavaScript environment. + * @implements {Zone} + */ -}); +var LocalZone = /*#__PURE__*/function (_Zone) { + _inheritsLoose(LocalZone, _Zone); -module.exports.PatientCareExperienceSchema = PatientCareExperienceSchema; -class PatientCareExperience extends mongoose.Document { - constructor(object) { - super(object, PatientCareExperienceSchema); - this._type = 'QDM::PatientCareExperience'; + function LocalZone() { + return _Zone.apply(this, arguments) || this; } -} - -module.exports.PatientCareExperience = PatientCareExperience; + var _proto = LocalZone.prototype; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],140:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** @override **/ + _proto.offsetName = function offsetName(ts, _ref) { + var format = _ref.format, + locale = _ref.locale; + return parseZoneInfo(ts, format, locale); + } + /** @override **/ + ; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + _proto.formatOffset = function formatOffset$1(ts, format) { + return formatOffset(this.offset(ts), format); + } + /** @override **/ + ; + _proto.offset = function offset(ts) { + return -new Date(ts).getTimezoneOffset(); + } + /** @override **/ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto.equals = function equals(otherZone) { + return otherZone.type === "local"; + } + /** @override **/ + ; -const PatientCharacteristicSchema = DataElementSchema({ - authorDatetime: DateTime, - qdmTitle: { type: String, default: 'Patient Characteristic' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.53' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristic' }, + _createClass(LocalZone, [{ + key: "type", -}); + /** @override **/ + get: function get() { + return "local"; + } + /** @override **/ -module.exports.PatientCharacteristicSchema = PatientCharacteristicSchema; -class PatientCharacteristic extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicSchema); - this._type = 'QDM::PatientCharacteristic'; - } -} + }, { + key: "name", + get: function get() { + if (hasIntl()) { + return new Intl.DateTimeFormat().resolvedOptions().timeZone; + } else return "local"; + } + /** @override **/ -module.exports.PatientCharacteristic = PatientCharacteristic; + }, { + key: "universal", + get: function get() { + return false; + } + }, { + key: "isValid", + get: function get() { + return true; + } + }], [{ + key: "instance", + /** + * Get a singleton instance of the local zone + * @return {LocalZone} + */ + get: function get() { + if (singleton === null) { + singleton = new LocalZone(); + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],141:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return singleton; + } + }]); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + return LocalZone; +}(Zone); +var matchingRegex = RegExp("^" + ianaRegex.source + "$"); +var dtfCache = {}; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +function makeDTF(zone) { + if (!dtfCache[zone]) { + dtfCache[zone] = new Intl.DateTimeFormat("en-US", { + hour12: false, + timeZone: zone, + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit" + }); + } -const PatientCharacteristicBirthdateSchema = DataElementSchema({ - birthDatetime: DateTime, - qdmTitle: { type: String, default: 'Patient Characteristic Birthdate' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.54' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'birthdate' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicBirthdate' }, + return dtfCache[zone]; +} -}); +var typeToPos = { + year: 0, + month: 1, + day: 2, + hour: 3, + minute: 4, + second: 5 +}; -module.exports.PatientCharacteristicBirthdateSchema = PatientCharacteristicBirthdateSchema; -class PatientCharacteristicBirthdate extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicBirthdateSchema); - this._type = 'QDM::PatientCharacteristicBirthdate'; - } +function hackyOffset(dtf, date) { + var formatted = dtf.format(date).replace(/\u200E/g, ""), + parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted), + fMonth = parsed[1], + fDay = parsed[2], + fYear = parsed[3], + fHour = parsed[4], + fMinute = parsed[5], + fSecond = parsed[6]; + return [fYear, fMonth, fDay, fHour, fMinute, fSecond]; } -module.exports.PatientCharacteristicBirthdate = PatientCharacteristicBirthdate; - +function partsOffset(dtf, date) { + var formatted = dtf.formatToParts(date), + filled = []; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],142:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + for (var i = 0; i < formatted.length; i++) { + var _formatted$i = formatted[i], + type = _formatted$i.type, + value = _formatted$i.value, + pos = typeToPos[type]; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + if (!isUndefined(pos)) { + filled[pos] = parseInt(value, 10); + } + } + return filled; +} -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +var ianaZoneCache = {}; +/** + * A zone identified by an IANA identifier, like America/New_York + * @implements {Zone} + */ -const PatientCharacteristicClinicalTrialParticipantSchema = DataElementSchema({ - reason: Code, - relevantPeriod: Interval, - qdmTitle: { type: String, default: 'Patient Characteristic Clinical Trial Participant' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.6' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.51' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'clinical_trial_participant' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicClinicalTrialParticipant' }, +var IANAZone = /*#__PURE__*/function (_Zone) { + _inheritsLoose(IANAZone, _Zone); -}); + /** + * @param {string} name - Zone name + * @return {IANAZone} + */ + IANAZone.create = function create(name) { + if (!ianaZoneCache[name]) { + ianaZoneCache[name] = new IANAZone(name); + } -module.exports.PatientCharacteristicClinicalTrialParticipantSchema = PatientCharacteristicClinicalTrialParticipantSchema; -class PatientCharacteristicClinicalTrialParticipant extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicClinicalTrialParticipantSchema); - this._type = 'QDM::PatientCharacteristicClinicalTrialParticipant'; + return ianaZoneCache[name]; } -} + /** + * Reset local caches. Should only be necessary in testing scenarios. + * @return {void} + */ + ; -module.exports.PatientCharacteristicClinicalTrialParticipant = PatientCharacteristicClinicalTrialParticipant; + IANAZone.resetCache = function resetCache() { + ianaZoneCache = {}; + dtfCache = {}; + } + /** + * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that. + * @param {string} s - The string to check validity on + * @example IANAZone.isValidSpecifier("America/New_York") //=> true + * @example IANAZone.isValidSpecifier("Fantasia/Castle") //=> true + * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false + * @return {boolean} + */ + ; + IANAZone.isValidSpecifier = function isValidSpecifier(s) { + return !!(s && s.match(matchingRegex)); + } + /** + * Returns whether the provided string identifies a real zone + * @param {string} zone - The string to check + * @example IANAZone.isValidZone("America/New_York") //=> true + * @example IANAZone.isValidZone("Fantasia/Castle") //=> false + * @example IANAZone.isValidZone("Sport~~blorp") //=> false + * @return {boolean} + */ + ; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],143:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + IANAZone.isValidZone = function isValidZone(zone) { + try { + new Intl.DateTimeFormat("en-US", { + timeZone: zone + }).format(); + return true; + } catch (e) { + return false; + } + } // Etc/GMT+8 -> -480 -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + /** @ignore */ + ; + IANAZone.parseGMTOffset = function parseGMTOffset(specifier) { + if (specifier) { + var match = specifier.match(/^Etc\/GMT(0|[+-]\d{1,2})$/i); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + if (match) { + return -60 * parseInt(match[1]); + } + } -const PatientCharacteristicEthnicitySchema = DataElementSchema({ - qdmTitle: { type: String, default: 'Patient Characteristic Ethnicity' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.56' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'ethnicity' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicEthnicity' }, + return null; + }; -}); + function IANAZone(name) { + var _this; -module.exports.PatientCharacteristicEthnicitySchema = PatientCharacteristicEthnicitySchema; -class PatientCharacteristicEthnicity extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicEthnicitySchema); - this._type = 'QDM::PatientCharacteristicEthnicity'; - } -} + _this = _Zone.call(this) || this; + /** @private **/ -module.exports.PatientCharacteristicEthnicity = PatientCharacteristicEthnicity; + _this.zoneName = name; + /** @private **/ + _this.valid = IANAZone.isValidZone(name); + return _this; + } + /** @override **/ -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],144:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var _proto = IANAZone.prototype; + /** @override **/ + _proto.offsetName = function offsetName(ts, _ref) { + var format = _ref.format, + locale = _ref.locale; + return parseZoneInfo(ts, format, locale, this.name); + } + /** @override **/ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto.formatOffset = function formatOffset$1(ts, format) { + return formatOffset(this.offset(ts), format); + } + /** @override **/ + ; -const PatientCharacteristicExpiredSchema = DataElementSchema({ - expiredDatetime: DateTime, - cause: Code, - qdmTitle: { type: String, default: 'Patient Characteristic Expired' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.57' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'expired' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicExpired' }, + _proto.offset = function offset(ts) { + var date = new Date(ts); + if (isNaN(date)) return NaN; -}); + var dtf = makeDTF(this.name), + _ref2 = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date), + year = _ref2[0], + month = _ref2[1], + day = _ref2[2], + hour = _ref2[3], + minute = _ref2[4], + second = _ref2[5], + adjustedHour = hour === 24 ? 0 : hour; -module.exports.PatientCharacteristicExpiredSchema = PatientCharacteristicExpiredSchema; -class PatientCharacteristicExpired extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicExpiredSchema); - this._type = 'QDM::PatientCharacteristicExpired'; + var asUTC = objToLocalTS({ + year: year, + month: month, + day: day, + hour: adjustedHour, + minute: minute, + second: second, + millisecond: 0 + }); + var asTS = +date; + var over = asTS % 1000; + asTS -= over >= 0 ? over : 1000 + over; + return (asUTC - asTS) / (60 * 1000); } -} - -module.exports.PatientCharacteristicExpired = PatientCharacteristicExpired; + /** @override **/ + ; + _proto.equals = function equals(otherZone) { + return otherZone.type === "iana" && otherZone.name === this.name; + } + /** @override **/ + ; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],145:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _createClass(IANAZone, [{ + key: "type", + get: function get() { + return "iana"; + } + /** @override **/ -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + }, { + key: "name", + get: function get() { + return this.zoneName; + } + /** @override **/ + }, { + key: "universal", + get: function get() { + return false; + } + }, { + key: "isValid", + get: function get() { + return this.valid; + } + }]); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return IANAZone; +}(Zone); -const PatientCharacteristicPayerSchema = DataElementSchema({ - relevantPeriod: Interval, - qdmTitle: { type: String, default: 'Patient Characteristic Payer' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.58' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'payer' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicPayer' }, +var singleton$1 = null; +/** + * A zone with a fixed offset (meaning no DST) + * @implements {Zone} + */ -}); +var FixedOffsetZone = /*#__PURE__*/function (_Zone) { + _inheritsLoose(FixedOffsetZone, _Zone); -module.exports.PatientCharacteristicPayerSchema = PatientCharacteristicPayerSchema; -class PatientCharacteristicPayer extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicPayerSchema); - this._type = 'QDM::PatientCharacteristicPayer'; + /** + * Get an instance with a specified offset + * @param {number} offset - The offset in minutes + * @return {FixedOffsetZone} + */ + FixedOffsetZone.instance = function instance(offset) { + return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset); } -} + /** + * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6" + * @param {string} s - The offset string to parse + * @example FixedOffsetZone.parseSpecifier("UTC+6") + * @example FixedOffsetZone.parseSpecifier("UTC+06") + * @example FixedOffsetZone.parseSpecifier("UTC-6:00") + * @return {FixedOffsetZone} + */ + ; -module.exports.PatientCharacteristicPayer = PatientCharacteristicPayer; + FixedOffsetZone.parseSpecifier = function parseSpecifier(s) { + if (s) { + var r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i); + if (r) { + return new FixedOffsetZone(signedOffset(r[1], r[2])); + } + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],146:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return null; + }; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + _createClass(FixedOffsetZone, null, [{ + key: "utcInstance", + /** + * Get a singleton instance of UTC + * @return {FixedOffsetZone} + */ + get: function get() { + if (singleton$1 === null) { + singleton$1 = new FixedOffsetZone(0); + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return singleton$1; + } + }]); -const PatientCharacteristicRaceSchema = DataElementSchema({ - qdmTitle: { type: String, default: 'Patient Characteristic Race' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.59' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'race' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicRace' }, + function FixedOffsetZone(offset) { + var _this; -}); + _this = _Zone.call(this) || this; + /** @private **/ -module.exports.PatientCharacteristicRaceSchema = PatientCharacteristicRaceSchema; -class PatientCharacteristicRace extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicRaceSchema); - this._type = 'QDM::PatientCharacteristicRace'; + _this.fixed = offset; + return _this; } -} - -module.exports.PatientCharacteristicRace = PatientCharacteristicRace; - - -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],147:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** @override **/ -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var _proto = FixedOffsetZone.prototype; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + /** @override **/ + _proto.offsetName = function offsetName() { + return this.name; + } + /** @override **/ + ; -const PatientCharacteristicSexSchema = DataElementSchema({ - qdmTitle: { type: String, default: 'Patient Characteristic Sex' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.55' }, - qdmCategory: { type: String, default: 'patient_characteristic' }, - qdmStatus: { type: String, default: 'gender' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PatientCharacteristicSex' }, + _proto.formatOffset = function formatOffset$1(ts, format) { + return formatOffset(this.fixed, format); + } + /** @override **/ + ; -}); + /** @override **/ + _proto.offset = function offset() { + return this.fixed; + } + /** @override **/ + ; -module.exports.PatientCharacteristicSexSchema = PatientCharacteristicSexSchema; -class PatientCharacteristicSex extends mongoose.Document { - constructor(object) { - super(object, PatientCharacteristicSexSchema); - this._type = 'QDM::PatientCharacteristicSex'; + _proto.equals = function equals(otherZone) { + return otherZone.type === "fixed" && otherZone.fixed === this.fixed; } -} + /** @override **/ + ; -module.exports.PatientCharacteristicSex = PatientCharacteristicSex; + _createClass(FixedOffsetZone, [{ + key: "type", + get: function get() { + return "fixed"; + } + /** @override **/ + }, { + key: "name", + get: function get() { + return this.fixed === 0 ? "UTC" : "UTC" + formatOffset(this.fixed, "narrow"); + } + }, { + key: "universal", + get: function get() { + return true; + } + }, { + key: "isValid", + get: function get() { + return true; + } + }]); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],148:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return FixedOffsetZone; +}(Zone); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +/** + * A zone that failed to parse. You should never need to instantiate this. + * @implements {Zone} + */ +var InvalidZone = /*#__PURE__*/function (_Zone) { + _inheritsLoose(InvalidZone, _Zone); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + function InvalidZone(zoneName) { + var _this; -const PhysicalExamOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - anatomicalLocationSite: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Physical Exam, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.61' }, - qdmCategory: { type: String, default: 'physical_exam' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PhysicalExamOrder' }, + _this = _Zone.call(this) || this; + /** @private */ + + _this.zoneName = zoneName; + return _this; + } + /** @override **/ -}); -module.exports.PhysicalExamOrderSchema = PhysicalExamOrderSchema; -class PhysicalExamOrder extends mongoose.Document { - constructor(object) { - super(object, PhysicalExamOrderSchema); - this._type = 'QDM::PhysicalExamOrder'; + var _proto = InvalidZone.prototype; + + /** @override **/ + _proto.offsetName = function offsetName() { + return null; } -} + /** @override **/ + ; -module.exports.PhysicalExamOrder = PhysicalExamOrder; + _proto.formatOffset = function formatOffset() { + return ""; + } + /** @override **/ + ; + _proto.offset = function offset() { + return NaN; + } + /** @override **/ + ; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],149:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.equals = function equals() { + return false; + } + /** @override **/ + ; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + _createClass(InvalidZone, [{ + key: "type", + get: function get() { + return "invalid"; + } + /** @override **/ + }, { + key: "name", + get: function get() { + return this.zoneName; + } + /** @override **/ -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + }, { + key: "universal", + get: function get() { + return false; + } + }, { + key: "isValid", + get: function get() { + return false; + } + }]); -const PhysicalExamPerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - reason: Code, - method: Code, - result: Any, - anatomicalLocationSite: Code, - negationRationale: Code, - components: [ComponentSchema], - performer: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Physical Exam, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.62' }, - qdmCategory: { type: String, default: 'physical_exam' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PhysicalExamPerformed' }, + return InvalidZone; +}(Zone); -}); +/** + * @private + */ +function normalizeZone(input, defaultZone) { + var offset; -module.exports.PhysicalExamPerformedSchema = PhysicalExamPerformedSchema; -class PhysicalExamPerformed extends mongoose.Document { - constructor(object) { - super(object, PhysicalExamPerformedSchema); - this._type = 'QDM::PhysicalExamPerformed'; + if (isUndefined(input) || input === null) { + return defaultZone; + } else if (input instanceof Zone) { + return input; + } else if (isString(input)) { + var lowered = input.toLowerCase(); + if (lowered === "local") return defaultZone;else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;else if ((offset = IANAZone.parseGMTOffset(input)) != null) { + // handle Etc/GMT-4, which V8 chokes on + return FixedOffsetZone.instance(offset); + } else if (IANAZone.isValidSpecifier(lowered)) return IANAZone.create(input);else return FixedOffsetZone.parseSpecifier(lowered) || new InvalidZone(input); + } else if (isNumber(input)) { + return FixedOffsetZone.instance(input); + } else if (typeof input === "object" && input.offset && typeof input.offset === "number") { + // This is dumb, but the instanceof check above doesn't seem to really work + // so we're duck checking it + return input; + } else { + return new InvalidZone(input); } } -module.exports.PhysicalExamPerformed = PhysicalExamPerformed; - +var now = function now() { + return Date.now(); +}, + defaultZone = null, + // not setting this directly to LocalZone.instance bc loading order issues +defaultLocale = null, + defaultNumberingSystem = null, + defaultOutputCalendar = null, + throwOnInvalid = false; +/** + * Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here. + */ -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],150:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +var Settings = /*#__PURE__*/function () { + function Settings() {} + /** + * Reset Luxon's global caches. Should only be necessary in testing scenarios. + * @return {void} + */ + Settings.resetCaches = function resetCaches() { + Locale.resetCache(); + IANAZone.resetCache(); + }; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _createClass(Settings, null, [{ + key: "now", -const PhysicalExamRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - anatomicalLocationSite: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Physical Exam, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.63' }, - qdmCategory: { type: String, default: 'physical_exam' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::PhysicalExamRecommended' }, + /** + * Get the callback for returning the current timestamp. + * @type {function} + */ + get: function get() { + return now; + } + /** + * Set the callback for returning the current timestamp. + * The function should return a number, which will be interpreted as an Epoch millisecond count + * @type {function} + * @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future + * @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time + */ + , + set: function set(n) { + now = n; + } + /** + * Get the default time zone to create DateTimes in. + * @type {string} + */ -}); + }, { + key: "defaultZoneName", + get: function get() { + return Settings.defaultZone.name; + } + /** + * Set the default time zone to create DateTimes in. Does not affect existing instances. + * @type {string} + */ + , + set: function set(z) { + if (!z) { + defaultZone = null; + } else { + defaultZone = normalizeZone(z); + } + } + /** + * Get the default time zone object to create DateTimes in. Does not affect existing instances. + * @type {Zone} + */ -module.exports.PhysicalExamRecommendedSchema = PhysicalExamRecommendedSchema; -class PhysicalExamRecommended extends mongoose.Document { - constructor(object) { - super(object, PhysicalExamRecommendedSchema); - this._type = 'QDM::PhysicalExamRecommended'; - } -} + }, { + key: "defaultZone", + get: function get() { + return defaultZone || LocalZone.instance; + } + /** + * Get the default locale to create DateTimes with. Does not affect existing instances. + * @type {string} + */ -module.exports.PhysicalExamRecommended = PhysicalExamRecommended; + }, { + key: "defaultLocale", + get: function get() { + return defaultLocale; + } + /** + * Set the default locale to create DateTimes with. Does not affect existing instances. + * @type {string} + */ + , + set: function set(locale) { + defaultLocale = locale; + } + /** + * Get the default numbering system to create DateTimes with. Does not affect existing instances. + * @type {string} + */ + }, { + key: "defaultNumberingSystem", + get: function get() { + return defaultNumberingSystem; + } + /** + * Set the default numbering system to create DateTimes with. Does not affect existing instances. + * @type {string} + */ + , + set: function set(numberingSystem) { + defaultNumberingSystem = numberingSystem; + } + /** + * Get the default output calendar to create DateTimes with. Does not affect existing instances. + * @type {string} + */ -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],151:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + }, { + key: "defaultOutputCalendar", + get: function get() { + return defaultOutputCalendar; + } + /** + * Set the default output calendar to create DateTimes with. Does not affect existing instances. + * @type {string} + */ + , + set: function set(outputCalendar) { + defaultOutputCalendar = outputCalendar; + } + /** + * Get whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals + * @type {boolean} + */ -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + }, { + key: "throwOnInvalid", + get: function get() { + return throwOnInvalid; + } + /** + * Set whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals + * @type {boolean} + */ + , + set: function set(t) { + throwOnInvalid = t; + } + }]); + return Settings; +}(); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +var intlDTCache = {}; -const ProcedureOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - anatomicalLocationSite: Code, - rank: Number, - priority: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Procedure, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.66' }, - qdmCategory: { type: String, default: 'procedure' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ProcedureOrder' }, +function getCachedDTF(locString, opts) { + if (opts === void 0) { + opts = {}; + } -}); + var key = JSON.stringify([locString, opts]); + var dtf = intlDTCache[key]; -module.exports.ProcedureOrderSchema = ProcedureOrderSchema; -class ProcedureOrder extends mongoose.Document { - constructor(object) { - super(object, ProcedureOrderSchema); - this._type = 'QDM::ProcedureOrder'; + if (!dtf) { + dtf = new Intl.DateTimeFormat(locString, opts); + intlDTCache[key] = dtf; } + + return dtf; } -module.exports.ProcedureOrder = ProcedureOrder; +var intlNumCache = {}; +function getCachedINF(locString, opts) { + if (opts === void 0) { + opts = {}; + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],152:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + var key = JSON.stringify([locString, opts]); + var inf = intlNumCache[key]; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + if (!inf) { + inf = new Intl.NumberFormat(locString, opts); + intlNumCache[key] = inf; + } + return inf; +} -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +var intlRelCache = {}; -const ProcedurePerformedSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - reason: Code, - method: Code, - result: Any, - status: Code, - anatomicalLocationSite: Code, - rank: Number, - incisionDatetime: DateTime, - negationRationale: Code, - components: [ComponentSchema], - performer: [AnyEntity], - relatedTo: [String], - qdmTitle: { type: String, default: 'Procedure, Performed' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.67' }, - qdmCategory: { type: String, default: 'procedure' }, - qdmStatus: { type: String, default: 'performed' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ProcedurePerformed' }, +function getCachedRTF(locString, opts) { + if (opts === void 0) { + opts = {}; + } -}); + var _opts = opts, + base = _opts.base, + cacheKeyOpts = _objectWithoutPropertiesLoose(_opts, ["base"]); // exclude `base` from the options -module.exports.ProcedurePerformedSchema = ProcedurePerformedSchema; -class ProcedurePerformed extends mongoose.Document { - constructor(object) { - super(object, ProcedurePerformedSchema); - this._type = 'QDM::ProcedurePerformed'; + + var key = JSON.stringify([locString, cacheKeyOpts]); + var inf = intlRelCache[key]; + + if (!inf) { + inf = new Intl.RelativeTimeFormat(locString, opts); + intlRelCache[key] = inf; } + + return inf; } -module.exports.ProcedurePerformed = ProcedurePerformed; +var sysLocaleCache = null; +function systemLocale() { + if (sysLocaleCache) { + return sysLocaleCache; + } else if (hasIntl()) { + var computedSys = new Intl.DateTimeFormat().resolvedOptions().locale; // node sometimes defaults to "und". Override that because that is dumb -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],153:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + sysLocaleCache = !computedSys || computedSys === "und" ? "en-US" : computedSys; + return sysLocaleCache; + } else { + sysLocaleCache = "en-US"; + return sysLocaleCache; + } +} -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +function parseLocaleString(localeStr) { + // I really want to avoid writing a BCP 47 parser + // see, e.g. https://github.com/wooorm/bcp-47 + // Instead, we'll do this: + // a) if the string has no -u extensions, just leave it alone + // b) if it does, use Intl to resolve everything + // c) if Intl fails, try again without the -u + var uIndex = localeStr.indexOf("-u-"); + if (uIndex === -1) { + return [localeStr]; + } else { + var options; + var smaller = localeStr.substring(0, uIndex); -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + try { + options = getCachedDTF(localeStr).resolvedOptions(); + } catch (e) { + options = getCachedDTF(smaller).resolvedOptions(); + } -const ProcedureRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - anatomicalLocationSite: Code, - rank: Number, - requester: [AnyEntity], - negationRationale: Code, - qdmTitle: { type: String, default: 'Procedure, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.68' }, - qdmCategory: { type: String, default: 'procedure' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ProcedureRecommended' }, + var _options = options, + numberingSystem = _options.numberingSystem, + calendar = _options.calendar; // return the smaller one so that we can append the calendar and numbering overrides to it -}); + return [smaller, numberingSystem, calendar]; + } +} -module.exports.ProcedureRecommendedSchema = ProcedureRecommendedSchema; -class ProcedureRecommended extends mongoose.Document { - constructor(object) { - super(object, ProcedureRecommendedSchema); - this._type = 'QDM::ProcedureRecommended'; +function intlConfigString(localeStr, numberingSystem, outputCalendar) { + if (hasIntl()) { + if (outputCalendar || numberingSystem) { + localeStr += "-u"; + + if (outputCalendar) { + localeStr += "-ca-" + outputCalendar; + } + + if (numberingSystem) { + localeStr += "-nu-" + numberingSystem; + } + + return localeStr; + } else { + return localeStr; + } + } else { + return []; } } -module.exports.ProcedureRecommended = ProcedureRecommended; +function mapMonths(f) { + var ms = []; + for (var i = 1; i <= 12; i++) { + var dt = DateTime.utc(2016, i, 1); + ms.push(f(dt)); + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],154:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return ms; +} -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +function mapWeekdays(f) { + var ms = []; + for (var i = 1; i <= 7; i++) { + var dt = DateTime.utc(2016, 11, 13 + i); + ms.push(f(dt)); + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return ms; +} -const ProviderCareExperienceSchema = DataElementSchema({ - authorDatetime: DateTime, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Provider Care Experience' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.70' }, - qdmCategory: { type: String, default: 'care_experience' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::ProviderCareExperience' }, +function listStuff(loc, length, defaultOK, englishFn, intlFn) { + var mode = loc.listingMode(defaultOK); -}); + if (mode === "error") { + return null; + } else if (mode === "en") { + return englishFn(length); + } else { + return intlFn(length); + } +} -module.exports.ProviderCareExperienceSchema = ProviderCareExperienceSchema; -class ProviderCareExperience extends mongoose.Document { - constructor(object) { - super(object, ProviderCareExperienceSchema); - this._type = 'QDM::ProviderCareExperience'; +function supportsFastNumbers(loc) { + if (loc.numberingSystem && loc.numberingSystem !== "latn") { + return false; + } else { + return loc.numberingSystem === "latn" || !loc.locale || loc.locale.startsWith("en") || hasIntl() && new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn"; } } +/** + * @private + */ -module.exports.ProviderCareExperience = ProviderCareExperience; +var PolyNumberFormatter = /*#__PURE__*/function () { + function PolyNumberFormatter(intl, forceSimple, opts) { + this.padTo = opts.padTo || 0; + this.floor = opts.floor || false; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],155:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const AnyEntity = require('./basetypes/AnyEntity'); -const AllDataElements = require('./AllDataElements'); + if (!forceSimple && hasIntl()) { + var intlOpts = { + useGrouping: false + }; + if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo; + this.inf = getCachedINF(intl, intlOpts); + } + } -const [Schema, Number, String, Mixed] = [ - mongoose.Schema, - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, - mongoose.Schema.Types.Mixed, -]; + var _proto = PolyNumberFormatter.prototype; -const QDMPatientSchema = new Schema({ - birthDatetime: DateTime, - qdmVersion: { type: String, default: '5.6' }, + _proto.format = function format(i) { + if (this.inf) { + var fixed = this.floor ? Math.floor(i) : i; + return this.inf.format(fixed); + } else { + // to match the browser's numberformatter defaults + var _fixed = this.floor ? Math.floor(i) : roundTo(i, 3); - // These are the "data criteria", or QDM datatype elements that exist on a - // patient. - dataElements: [], - // This field is for application specific information only. If both Bonnie - // Cypress use a common field, it should be made a field on this model, - // and not put into extendedData. - extendedData: { - type: Mixed, - default: {}, - }, -}, { id: false }); + return padStart(_fixed, this.padTo); + } + }; -// After initialization of a Patient model, initialize every individual data element -// to its respective Mongoose Model -QDMPatientSchema.methods.initializeDataElements = function initializeDataElements() { - let typeStripped; - const dataElementsInit = []; - this.dataElements.forEach((element) => { - typeStripped = element._type.replace(/QDM::/, ''); - dataElementsInit.push(new AllDataElements[typeStripped](element)); - }); - this.set({ dataElements: dataElementsInit }); -}; + return PolyNumberFormatter; +}(); +/** + * @private + */ -QDMPatientSchema.methods.id = function id() { - return this._id; -}; -// Returns an array of elements that exist on this patient, that -// match the given HQMF data criteria OID. -QDMPatientSchema.methods.getByHqmfOid = function getByHqmfOid(hqmfOid) { - return this.dataElements.filter(element => element.hqmfOid === hqmfOid); -}; +var PolyDateFormatter = /*#__PURE__*/function () { + function PolyDateFormatter(dt, intl, opts) { + this.opts = opts; + this.hasIntl = hasIntl(); + var z; -// Returns an array of elements that exist on this patient, that -// match the given QRDA data criteria OID. -QDMPatientSchema.methods.getByQrdaOid = function getByQrdaOid(qrdaOid) { - return this.dataElements.filter(element => element.qrdaOid === qrdaOid); -}; + if (dt.zone.universal && this.hasIntl) { + // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like. + // That is why fixed-offset TZ is set to that unless it is: + // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT. + // 2. Unsupported by the browser: + // - some do not support Etc/ + // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata + var gmtOffset = -1 * (dt.offset / 60); + var offsetZ = gmtOffset >= 0 ? "Etc/GMT+" + gmtOffset : "Etc/GMT" + gmtOffset; + var isOffsetZoneSupported = IANAZone.isValidZone(offsetZ); -// cql-execution prefers getId() over id() because some data models may have an id property -QDMPatientSchema.methods.getId = function getId() { - return this._id; -}; + if (dt.offset !== 0 && isOffsetZoneSupported) { + z = offsetZ; + this.dt = dt; + } else { + // Not all fixed-offset zones like Etc/+4:30 are present in tzdata. + // So we have to make do. Two cases: + // 1. The format options tell us to show the zone. We can't do that, so the best + // we can do is format the date in UTC. + // 2. The format options don't tell us to show the zone. Then we can adjust them + // the time and tell the formatter to show it to us in UTC, so that the time is right + // and the bad zone doesn't show up. + z = "UTC"; -/* eslint no-underscore-dangle: 0 */ -QDMPatientSchema.methods._is = function _is(typeSpecifier) { - return this._typeHierarchy().some( - t => t.type === typeSpecifier.type && t.name === typeSpecifier.name - ); -}; + if (opts.timeZoneName) { + this.dt = dt; + } else { + this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000); + } + } + } else if (dt.zone.type === "local") { + this.dt = dt; + } else { + this.dt = dt; + z = dt.zone.name; + } -/* eslint no-underscore-dangle: 0 */ -QDMPatientSchema.methods._typeHierarchy = function _typeHierarchy() { - const ver = this.qdmVersion.replace('.', '_'); - return [ - { - name: `{urn:healthit-gov:qdm:v${ver}}Patient`, - type: 'NamedTypeSpecifier', - }, - { name: '{urn:hl7-org:elm-types:r1}Tuple', type: 'NamedTypeSpecifier' }, - { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' }, - ]; -}; + if (this.hasIntl) { + var intlOpts = Object.assign({}, this.opts); -// Returns an array of elements that exist on this patient. Optionally -// takes a qdmCategory, which returns all elements of that QDM qdmCategory. -// Example: patient.getDataElements({qdmCategory: 'encounters'}) will return -// all Encounter QDM data types active on the patient. -QDMPatientSchema.methods.getDataElements = function getDataElements(params) { - if (params !== undefined && params.qdmCategory !== undefined && params.qdmStatus !== undefined) { - return this.dataElements.filter(element => (element.qdmCategory === params.qdmCategory) && (element.qdmStatus === params.qdmStatus)); - } else if (params !== undefined && params.qdmCategory !== undefined) { - return this.dataElements.filter(element => element.qdmCategory === params.qdmCategory); + if (z) { + intlOpts.timeZone = z; + } + + this.dtf = getCachedDTF(intl, intlOpts); + } } - return this.dataElements; -}; -QDMPatientSchema.methods.addMethodsTo = function addMethodsTo(obj, methods) { - Object.entries(methods).forEach(([method_name, method]) => { - obj[method_name] = method; - }); -}; + var _proto2 = PolyDateFormatter.prototype; -// Returns an array of dataElements that exist on the patient, queried by -// QDM profile -// @param {string} profile - the data criteria requested by the execution engine -// @param {boolean} isNegated - whether dataElements should be returned based on their negation status -// @returns {DataElement[]} -QDMPatientSchema.methods.getByProfile = function getByProfile(profile, isNegated = null) { - // If isNegated == true, only return data elements with a negationRationale that is not null. - // If isNegated == false, only return data elements with a null negationRationale. - // If isNegated == null, return all matching data elements by type, regardless of negationRationale. - const results = this.dataElements.filter(element => (element._type === `QDM::${profile}` || element._type === profile) && (isNegated === null || !!element.negationRationale === isNegated)); - return results.map((result) => { - // we need to convert mongoose document to an object. - // This is required for comparing the two objects(in cql-execution) as we can't compare two mongoose documents. - const removedMongooseItems = new AllDataElements[profile](result).toObject({ virtuals: true }); - // toObject() will remove all mongoose functions but also remove the schema methods, so we add them back - this.addMethodsTo(removedMongooseItems, result.schema.methods); - // add methods to entities - Object.entries(result).forEach(([key, values]) => { - // entities are always an array - if (Array.isArray(values)) { - try { - // check if the attribute is of Entity - if (AnyEntity.prototype.cast(values[0])) { - values.forEach((value, index) => { - const entity = removedMongooseItems[key][index]; - this.addMethodsTo(entity, value.schema.methods); - }); - } - // eslint-disable-next-line no-empty - } catch (e) {} - } - }); - return removedMongooseItems; - }); -}; + _proto2.format = function format() { + if (this.hasIntl) { + return this.dtf.format(this.dt.toJSDate()); + } else { + var tokenFormat = formatString(this.opts), + loc = Locale.create("en-US"); + return Formatter.create(loc).formatDateTimeFromString(this.dt, tokenFormat); + } + }; -// This method is called by the CQL execution engine on a CQLPatient when -// the execution engine wants information on a record. A record could be patient -// characteristic information about the patient, or it could be data criteria -// that currently exist on this patient (data criteria you drag on a patient -// in Bonnie patient builder). -// @param {String} profile - the data criteria requested by the execution engine -// @returns {Object} -QDMPatientSchema.methods.findRecords = function findRecords(profile) { - // Clear profile cache for this patient if there is no cache or the patient has changed - if (QDMPatientSchema.dataElementCache == null - || QDMPatientSchema.dataElementCachePatientId !== this._id) { - QDMPatientSchema.dataElementCache = {}; - QDMPatientSchema.dataElementCachePatientId = this._id; - } - // If there is a cache 'hit', return it - if (Object.prototype.hasOwnProperty.call(QDMPatientSchema.dataElementCache, profile)) { - return QDMPatientSchema.dataElementCache[profile]; - } - let profileStripped; - if (profile === 'Patient') { - // Requested generic patient info - const info = { birthDatetime: this.birthDatetime }; - QDMPatientSchema.dataElementCache[profile] = [info]; - return [info]; - } else if (/PatientCharacteristic/.test(profile)) { - // Requested a patient characteristic - profileStripped = profile.replace(/ *\{[^)]*\} */g, ''); - QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped); - return QDMPatientSchema.dataElementCache[profile]; - } else if (profile != null) { - // Requested something else (probably a QDM data type). + _proto2.formatToParts = function formatToParts() { + if (this.hasIntl && hasFormatToParts()) { + return this.dtf.formatToParts(this.dt.toJSDate()); + } else { + // This is kind of a cop out. We actually could do this for English. However, we couldn't do it for intl strings + // and IMO it's too weird to have an uncanny valley like that + return []; + } + }; - // Strip model details from request. The requested profile string contains - // a lot of things we do not need or care about. Example, we might see - // something like: - // "{urn:healthit-gov:qdm:v5_0_draft}PatientCharacteristicEthnicity" - // Where we only care about: "PatientCharacteristicEthnicity". - profileStripped = profile.replace(/ *\{[^)]*\} */g, ''); + _proto2.resolvedOptions = function resolvedOptions() { + if (this.hasIntl) { + return this.dtf.resolvedOptions(); + } else { + return { + locale: "en-US", + numberingSystem: "latn", + outputCalendar: "gregory" + }; + } + }; - // Check and handle negation status - if (/Positive/.test(profileStripped)) { - profileStripped = profileStripped.replace(/Positive/, ''); - // Since the data criteria is 'Positive', it is not negated. - QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped, false); - return QDMPatientSchema.dataElementCache[profile]; - } else if (/Negative/.test(profileStripped)) { - profileStripped = profileStripped.replace(/Negative/, ''); - // Since the data criteria is 'Negative', it is negated. - QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped, true); - return QDMPatientSchema.dataElementCache[profile]; + return PolyDateFormatter; +}(); +/** + * @private + */ + + +var PolyRelFormatter = /*#__PURE__*/function () { + function PolyRelFormatter(intl, isEnglish, opts) { + this.opts = Object.assign({ + style: "long" + }, opts); + + if (!isEnglish && hasRelative()) { + this.rtf = getCachedRTF(intl, opts); } - // No negation status, proceed normally - QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped); - return QDMPatientSchema.dataElementCache[profile]; } - return []; -}; -QDMPatientSchema.methods.adverse_events = function adverse_events() { - return this.getDataElements({ qdmCategory: 'adverse_event' }); -}; + var _proto3 = PolyRelFormatter.prototype; -QDMPatientSchema.methods.allergies = function allergies() { - return this.getDataElements({ qdmCategory: 'allergy' }); -}; + _proto3.format = function format(count, unit) { + if (this.rtf) { + return this.rtf.format(count, unit); + } else { + return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long"); + } + }; -QDMPatientSchema.methods.assessments = function assessments() { - return this.getDataElements({ qdmCategory: 'assessment' }); -}; + _proto3.formatToParts = function formatToParts(count, unit) { + if (this.rtf) { + return this.rtf.formatToParts(count, unit); + } else { + return []; + } + }; -QDMPatientSchema.methods.care_experiences = function care_experiences() { - return this.getDataElements({ qdmCategory: 'care_experience' }); -}; + return PolyRelFormatter; +}(); +/** + * @private + */ -QDMPatientSchema.methods.care_goals = function care_goals() { - return this.getDataElements({ qdmCategory: 'care_goal' }); -}; -QDMPatientSchema.methods.communications = function communications() { - return this.getDataElements({ qdmCategory: 'communication' }); -}; +var Locale = /*#__PURE__*/function () { + Locale.fromOpts = function fromOpts(opts) { + return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN); + }; -QDMPatientSchema.methods.conditions = function conditions() { - return this.getDataElements({ qdmCategory: 'condition' }); -}; + Locale.create = function create(locale, numberingSystem, outputCalendar, defaultToEN) { + if (defaultToEN === void 0) { + defaultToEN = false; + } -QDMPatientSchema.methods.devices = function devices() { - return this.getDataElements({ qdmCategory: 'device' }); -}; + var specifiedLocale = locale || Settings.defaultLocale, + // the system locale is useful for human readable strings but annoying for parsing/formatting known formats + localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale()), + numberingSystemR = numberingSystem || Settings.defaultNumberingSystem, + outputCalendarR = outputCalendar || Settings.defaultOutputCalendar; + return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale); + }; -QDMPatientSchema.methods.diagnostic_studies = function diagnostic_studies() { - return this.getDataElements({ qdmCategory: 'diagnostic_study' }); -}; + Locale.resetCache = function resetCache() { + sysLocaleCache = null; + intlDTCache = {}; + intlNumCache = {}; + intlRelCache = {}; + }; -QDMPatientSchema.methods.encounters = function encounters() { - return this.getDataElements({ qdmCategory: 'encounter' }); -}; + Locale.fromObject = function fromObject(_temp) { + var _ref = _temp === void 0 ? {} : _temp, + locale = _ref.locale, + numberingSystem = _ref.numberingSystem, + outputCalendar = _ref.outputCalendar; -QDMPatientSchema.methods.family_history = function family_history() { - return this.getDataElements({ qdmCategory: 'family_history' }); -}; + return Locale.create(locale, numberingSystem, outputCalendar); + }; -QDMPatientSchema.methods.functional_statuses = function functional_statuses() { - return this.getDataElements({ qdmCategory: 'functional_status' }); -}; + function Locale(locale, numbering, outputCalendar, specifiedLocale) { + var _parseLocaleString = parseLocaleString(locale), + parsedLocale = _parseLocaleString[0], + parsedNumberingSystem = _parseLocaleString[1], + parsedOutputCalendar = _parseLocaleString[2]; -QDMPatientSchema.methods.immunizations = function immunizations() { - return this.getDataElements({ qdmCategory: 'immunization' }); -}; + this.locale = parsedLocale; + this.numberingSystem = numbering || parsedNumberingSystem || null; + this.outputCalendar = outputCalendar || parsedOutputCalendar || null; + this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar); + this.weekdaysCache = { + format: {}, + standalone: {} + }; + this.monthsCache = { + format: {}, + standalone: {} + }; + this.meridiemCache = null; + this.eraCache = {}; + this.specifiedLocale = specifiedLocale; + this.fastNumbersCached = null; + } -QDMPatientSchema.methods.interventions = function interventions() { - return this.getDataElements({ qdmCategory: 'intervention' }); -}; + var _proto4 = Locale.prototype; + + _proto4.listingMode = function listingMode(defaultOK) { + if (defaultOK === void 0) { + defaultOK = true; + } + + var intl = hasIntl(), + hasFTP = intl && hasFormatToParts(), + isActuallyEn = this.isEnglish(), + hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory"); + + if (!hasFTP && !(isActuallyEn && hasNoWeirdness) && !defaultOK) { + return "error"; + } else if (!hasFTP || isActuallyEn && hasNoWeirdness) { + return "en"; + } else { + return "intl"; + } + }; + + _proto4.clone = function clone(alts) { + if (!alts || Object.getOwnPropertyNames(alts).length === 0) { + return this; + } else { + return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false); + } + }; -QDMPatientSchema.methods.laboratory_tests = function laboratory_tests() { - return this.getDataElements({ qdmCategory: 'laboratory_test' }); -}; + _proto4.redefaultToEN = function redefaultToEN(alts) { + if (alts === void 0) { + alts = {}; + } -QDMPatientSchema.methods.medical_equipment = function medical_equipment() { - return this.getDataElements({ qdmCategory: 'medical_equipment' }); -}; + return this.clone(Object.assign({}, alts, { + defaultToEN: true + })); + }; -QDMPatientSchema.methods.medications = function medications() { - return this.getDataElements({ qdmCategory: 'medication' }); -}; + _proto4.redefaultToSystem = function redefaultToSystem(alts) { + if (alts === void 0) { + alts = {}; + } -QDMPatientSchema.methods.patient_characteristics = function patient_characteristics() { - return this.getDataElements({ qdmCategory: 'patient_characteristic' }); -}; + return this.clone(Object.assign({}, alts, { + defaultToEN: false + })); + }; -QDMPatientSchema.methods.physical_exams = function physical_exams() { - return this.getDataElements({ qdmCategory: 'physical_exam' }); -}; + _proto4.months = function months$1(length, format, defaultOK) { + var _this = this; -QDMPatientSchema.methods.preferences = function preferences() { - return this.getDataElements({ qdmCategory: 'preference' }); -}; + if (format === void 0) { + format = false; + } -QDMPatientSchema.methods.procedures = function procedures() { - return this.getDataElements({ qdmCategory: 'procedure' }); -}; + if (defaultOK === void 0) { + defaultOK = true; + } -QDMPatientSchema.methods.results = function results() { - return this.getDataElements({ qdmCategory: 'result' }); -}; + return listStuff(this, length, defaultOK, months, function () { + var intl = format ? { + month: length, + day: "numeric" + } : { + month: length + }, + formatStr = format ? "format" : "standalone"; -QDMPatientSchema.methods.risk_category_assessments = function risk_category_assessments() { - return this.getDataElements({ qdmCategory: 'risk_category_assessment' }); -}; + if (!_this.monthsCache[formatStr][length]) { + _this.monthsCache[formatStr][length] = mapMonths(function (dt) { + return _this.extract(dt, intl, "month"); + }); + } -QDMPatientSchema.methods.social_history = function social_history() { - return this.getDataElements({ qdmCategory: 'social_history' }); -}; + return _this.monthsCache[formatStr][length]; + }); + }; -QDMPatientSchema.methods.substances = function substances() { - return this.getDataElements({ qdmCategory: 'substance' }); -}; + _proto4.weekdays = function weekdays$1(length, format, defaultOK) { + var _this2 = this; -QDMPatientSchema.methods.symptoms = function symptoms() { - return this.getDataElements({ qdmCategory: 'symptom' }); -}; + if (format === void 0) { + format = false; + } -QDMPatientSchema.methods.system_characteristics = function system_characteristics() { - return this.getDataElements({ qdmCategory: 'system_characteristic' }); -}; + if (defaultOK === void 0) { + defaultOK = true; + } -QDMPatientSchema.methods.transfers = function transfers() { - return this.getDataElements({ qdmCategory: 'transfer' }); -}; + return listStuff(this, length, defaultOK, weekdays, function () { + var intl = format ? { + weekday: length, + year: "numeric", + month: "long", + day: "numeric" + } : { + weekday: length + }, + formatStr = format ? "format" : "standalone"; -QDMPatientSchema.methods.vital_signs = function vital_signs() { - return this.getDataElements({ qdmCategory: 'vital_sign' }); -}; + if (!_this2.weekdaysCache[formatStr][length]) { + _this2.weekdaysCache[formatStr][length] = mapWeekdays(function (dt) { + return _this2.extract(dt, intl, "weekday"); + }); + } -QDMPatientSchema.clearDataElementCache = function clearDataElementCache() { - QDMPatientSchema.dataElementCachePatientId = null; - QDMPatientSchema.dataElementCache = null; -}; + return _this2.weekdaysCache[formatStr][length]; + }); + }; -module.exports.QDMPatientSchema = QDMPatientSchema; -class QDMPatient extends mongoose.Document { - constructor(object) { - super(object, QDMPatientSchema); - this.initializeDataElements(); - } -} -module.exports.QDMPatient = QDMPatient; + _proto4.meridiems = function meridiems$1(defaultOK) { + var _this3 = this; -},{"./AllDataElements":108,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/Quantity":180,"mongoose/browser":226}],156:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + if (defaultOK === void 0) { + defaultOK = true; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + return listStuff(this, undefined, defaultOK, function () { + return meridiems; + }, function () { + // In theory there could be aribitrary day periods. We're gonna assume there are exactly two + // for AM and PM. This is probably wrong, but it's makes parsing way easier. + if (!_this3.meridiemCache) { + var intl = { + hour: "numeric", + hour12: true + }; + _this3.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(function (dt) { + return _this3.extract(dt, intl, "dayperiod"); + }); + } + return _this3.meridiemCache; + }); + }; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto4.eras = function eras$1(length, defaultOK) { + var _this4 = this; -const RelatedPersonSchema = DataElementSchema({ - identifier: IdentifierSchema, - linkedPatientId: String, - qdmTitle: { type: String, default: 'Related Person' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.141' }, - qdmCategory: { type: String, default: 'related_person' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::RelatedPerson' }, + if (defaultOK === void 0) { + defaultOK = true; + } -}); + return listStuff(this, length, defaultOK, eras, function () { + var intl = { + era: length + }; // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates + // to definitely enumerate them. -module.exports.RelatedPersonSchema = RelatedPersonSchema; -class RelatedPerson extends mongoose.Document { - constructor(object) { - super(object, RelatedPersonSchema); - this._type = 'QDM::RelatedPerson'; - } -} + if (!_this4.eraCache[length]) { + _this4.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(function (dt) { + return _this4.extract(dt, intl, "era"); + }); + } -module.exports.RelatedPerson = RelatedPerson; + return _this4.eraCache[length]; + }); + }; + _proto4.extract = function extract(dt, intlOpts, field) { + var df = this.dtFormatter(dt, intlOpts), + results = df.formatToParts(), + matching = results.find(function (m) { + return m.type.toLowerCase() === field; + }); + return matching ? matching.value : null; + }; -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],157:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto4.numberFormatter = function numberFormatter(opts) { + if (opts === void 0) { + opts = {}; + } -const PlaceholderResultSchema = mongoose.Schema({ - cache_id: String, - measure_id: String, - sub_id: String, - test_id: String, - effective_date: Number, - filters: Object, - prefilter: Object, - calculation_time: Date, - status: Object, - population_ids: Object, - STRAT: Number, - IPP: Number, - DENOM: Number, - NUMER: Number, - NUMEX: Number, - DENEX: Number, - DENEXCEP: Number, - MSRPOPL: Number, - OBSERV: Number, - MSRPOPLEX: Number, - supplemental_data: Object, -}); + // this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave) + // (in contrast, the rest of the condition is used heavily) + return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts); + }; -module.exports.ResultSchema = PlaceholderResultSchema; -class PlaceholderResult extends mongoose.Document { - constructor(object) { - super(object, PlaceholderResultSchema); - } -} -module.exports.PlaceholderResult = PlaceholderResult; + _proto4.dtFormatter = function dtFormatter(dt, intlOpts) { + if (intlOpts === void 0) { + intlOpts = {}; + } -},{"mongoose/browser":226}],158:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return new PolyDateFormatter(dt, this.intl, intlOpts); + }; -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + _proto4.relFormatter = function relFormatter(opts) { + if (opts === void 0) { + opts = {}; + } + return new PolyRelFormatter(this.intl, this.isEnglish(), opts); + }; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto4.isEnglish = function isEnglish() { + return this.locale === "en" || this.locale.toLowerCase() === "en-us" || hasIntl() && new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us"); + }; -const SubstanceAdministeredSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantDatetime: DateTime, - relevantPeriod: Interval, - dosage: Quantity, - frequency: Code, - route: Code, - negationRationale: Code, - performer: [AnyEntity], - qdmTitle: { type: String, default: 'Substance, Administered' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.73' }, - qdmCategory: { type: String, default: 'substance' }, - qdmStatus: { type: String, default: 'administered' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::SubstanceAdministered' }, + _proto4.equals = function equals(other) { + return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar; + }; -}); + _createClass(Locale, [{ + key: "fastNumbers", + get: function get() { + if (this.fastNumbersCached == null) { + this.fastNumbersCached = supportsFastNumbers(this); + } -module.exports.SubstanceAdministeredSchema = SubstanceAdministeredSchema; -class SubstanceAdministered extends mongoose.Document { - constructor(object) { - super(object, SubstanceAdministeredSchema); - this._type = 'QDM::SubstanceAdministered'; - } -} + return this.fastNumbersCached; + } + }]); -module.exports.SubstanceAdministered = SubstanceAdministered; + return Locale; +}(); +/* + * This file handles parsing for well-specified formats. Here's how it works: + * Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match. + * An extractor is just a function that takes a regex match array and returns a { year: ..., month: ... } object + * parse() does the work of executing the regex and applying the extractor. It takes multiple regex/extractor pairs to try in sequence. + * Extractors can take a "cursor" representing the offset in the match to look at. This makes it easy to combine extractors. + * combineExtractors() does the work of combining them, keeping track of the cursor through multiple extractions. + * Some extractions are super dumb and simpleParse and fromStrings help DRY them. + */ -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],159:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +function combineRegexes() { + for (var _len = arguments.length, regexes = new Array(_len), _key = 0; _key < _len; _key++) { + regexes[_key] = arguments[_key]; + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + var full = regexes.reduce(function (f, r) { + return f + r.source; + }, ""); + return RegExp("^" + full + "$"); +} +function combineExtractors() { + for (var _len2 = arguments.length, extractors = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + extractors[_key2] = arguments[_key2]; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return function (m) { + return extractors.reduce(function (_ref, ex) { + var mergedVals = _ref[0], + mergedZone = _ref[1], + cursor = _ref[2]; -const SubstanceOrderSchema = DataElementSchema({ - authorDatetime: DateTime, - relevantPeriod: Interval, - reason: Code, - dosage: Quantity, - supply: Quantity, - frequency: Code, - refills: Number, - route: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Substance, Order' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.77' }, - qdmCategory: { type: String, default: 'substance' }, - qdmStatus: { type: String, default: 'order' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::SubstanceOrder' }, + var _ex = ex(m, cursor), + val = _ex[0], + zone = _ex[1], + next = _ex[2]; -}); + return [Object.assign(mergedVals, val), mergedZone || zone, next]; + }, [{}, null, 1]).slice(0, 2); + }; +} -module.exports.SubstanceOrderSchema = SubstanceOrderSchema; -class SubstanceOrder extends mongoose.Document { - constructor(object) { - super(object, SubstanceOrderSchema); - this._type = 'QDM::SubstanceOrder'; +function parse(s) { + if (s == null) { + return [null, null]; } -} -module.exports.SubstanceOrder = SubstanceOrder; + for (var _len3 = arguments.length, patterns = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + patterns[_key3 - 1] = arguments[_key3]; + } + for (var _i = 0, _patterns = patterns; _i < _patterns.length; _i++) { + var _patterns$_i = _patterns[_i], + regex = _patterns$_i[0], + extractor = _patterns$_i[1]; + var m = regex.exec(s); -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],160:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + if (m) { + return extractor(m); + } + } -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); + return [null, null]; +} +function simpleParse() { + for (var _len4 = arguments.length, keys = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + keys[_key4] = arguments[_key4]; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return function (match, cursor) { + var ret = {}; + var i; -const SubstanceRecommendedSchema = DataElementSchema({ - authorDatetime: DateTime, - reason: Code, - dosage: Quantity, - frequency: Code, - refills: Number, - route: Code, - negationRationale: Code, - requester: [AnyEntity], - qdmTitle: { type: String, default: 'Substance, Recommended' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.78' }, - qdmCategory: { type: String, default: 'substance' }, - qdmStatus: { type: String, default: 'recommended' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::SubstanceRecommended' }, + for (i = 0; i < keys.length; i++) { + ret[keys[i]] = parseInteger(match[cursor + i]); + } -}); + return [ret, null, cursor + i]; + }; +} // ISO and SQL parsing -module.exports.SubstanceRecommendedSchema = SubstanceRecommendedSchema; -class SubstanceRecommended extends mongoose.Document { - constructor(object) { - super(object, SubstanceRecommendedSchema); - this._type = 'QDM::SubstanceRecommended'; - } -} -module.exports.SubstanceRecommended = SubstanceRecommended; +var offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/, + isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/, + isoTimeRegex = RegExp("" + isoTimeBaseRegex.source + offsetRegex.source + "?"), + isoTimeExtensionRegex = RegExp("(?:T" + isoTimeRegex.source + ")?"), + isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/, + isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/, + isoOrdinalRegex = /(\d{4})-?(\d{3})/, + extractISOWeekData = simpleParse("weekYear", "weekNumber", "weekDay"), + extractISOOrdinalData = simpleParse("year", "ordinal"), + sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/, + // dumbed-down version of the ISO one +sqlTimeRegex = RegExp(isoTimeBaseRegex.source + " ?(?:" + offsetRegex.source + "|(" + ianaRegex.source + "))?"), + sqlTimeExtensionRegex = RegExp("(?: " + sqlTimeRegex.source + ")?"); +function int(match, pos, fallback) { + var m = match[pos]; + return isUndefined(m) ? fallback : parseInteger(m); +} -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],161:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +function extractISOYmd(match, cursor) { + var item = { + year: int(match, cursor), + month: int(match, cursor + 1, 1), + day: int(match, cursor + 2, 1) + }; + return [item, null, cursor + 3]; +} -const { IdentifierSchema } = require('./attributes/Identifier'); -const { DataElementSchema } = require('./basetypes/DataElement'); -const Code = require('./basetypes/Code'); -const Interval = require('./basetypes/Interval'); -const Quantity = require('./basetypes/Quantity'); -const DateTime = require('./basetypes/DateTime'); -const QDMDate = require('./basetypes/QDMDate'); -const Any = require('./basetypes/Any'); -const AnyEntity = require('./basetypes/AnyEntity'); -const { ComponentSchema } = require('./attributes/Component'); -const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); -const { EntitySchema } = require('./attributes/Entity'); +function extractISOTime(match, cursor) { + var item = { + hours: int(match, cursor, 0), + minutes: int(match, cursor + 1, 0), + seconds: int(match, cursor + 2, 0), + milliseconds: parseMillis(match[cursor + 3]) + }; + return [item, null, cursor + 4]; +} +function extractISOOffset(match, cursor) { + var local = !match[cursor] && !match[cursor + 1], + fullOffset = signedOffset(match[cursor + 1], match[cursor + 2]), + zone = local ? null : FixedOffsetZone.instance(fullOffset); + return [{}, zone, cursor + 3]; +} -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +function extractIANAZone(match, cursor) { + var zone = match[cursor] ? IANAZone.create(match[cursor]) : null; + return [{}, zone, cursor + 1]; +} // ISO time parsing -const SymptomSchema = DataElementSchema({ - prevalencePeriod: Interval, - severity: Code, - recorder: [AnyEntity], - qdmTitle: { type: String, default: 'Symptom' }, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.116' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.136' }, - qdmCategory: { type: String, default: 'symptom' }, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Symptom' }, -}); +var isoTimeOnly = RegExp("^T?" + isoTimeBaseRegex.source + "$"); // ISO duration parsing -module.exports.SymptomSchema = SymptomSchema; -class Symptom extends mongoose.Document { - constructor(object) { - super(object, SymptomSchema); - this._type = 'QDM::Symptom'; - } -} +var isoDuration = /^-?P(?:(?:(-?\d{1,9})Y)?(?:(-?\d{1,9})M)?(?:(-?\d{1,9})W)?(?:(-?\d{1,9})D)?(?:T(?:(-?\d{1,9})H)?(?:(-?\d{1,9})M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,9}))?S)?)?)$/; -module.exports.Symptom = Symptom; +function extractISODuration(match) { + var s = match[0], + yearStr = match[1], + monthStr = match[2], + weekStr = match[3], + dayStr = match[4], + hourStr = match[5], + minuteStr = match[6], + secondStr = match[7], + millisecondsStr = match[8]; + var hasNegativePrefix = s[0] === "-"; + var negativeSeconds = secondStr && secondStr[0] === "-"; + var maybeNegate = function maybeNegate(num, force) { + if (force === void 0) { + force = false; + } -},{"./attributes/Component":163,"./attributes/Entity":165,"./attributes/FacilityLocation":166,"./attributes/Identifier":167,"./basetypes/Any":173,"./basetypes/AnyEntity":174,"./basetypes/Code":175,"./basetypes/DataElement":176,"./basetypes/DateTime":177,"./basetypes/Interval":178,"./basetypes/QDMDate":179,"./basetypes/Quantity":180,"mongoose/browser":226}],162:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return num !== undefined && (force || num && hasNegativePrefix) ? -num : num; + }; -const { EntitySchemaFunction } = require('./Entity'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + return [{ + years: maybeNegate(parseInteger(yearStr)), + months: maybeNegate(parseInteger(monthStr)), + weeks: maybeNegate(parseInteger(weekStr)), + days: maybeNegate(parseInteger(dayStr)), + hours: maybeNegate(parseInteger(hourStr)), + minutes: maybeNegate(parseInteger(minuteStr)), + seconds: maybeNegate(parseInteger(secondStr), secondStr === "-0"), + milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds) + }]; +} // These are a little braindead. EDT *should* tell us that we're in, say, America/New_York +// and not just that we're in -240 *right now*. But since I don't think these are used that often +// I'm just going to ignore that -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; -const CarePartnerSchema = EntitySchemaFunction({ - relationship: Code, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.134' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.160' }, - _type: { type: String, default: 'QDM::CarePartner' }, +var obsOffsets = { + GMT: 0, + EDT: -4 * 60, + EST: -5 * 60, + CDT: -5 * 60, + CST: -6 * 60, + MDT: -6 * 60, + MST: -7 * 60, + PDT: -7 * 60, + PST: -8 * 60 +}; -}); +function fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) { + var result = { + year: yearStr.length === 2 ? untruncateYear(parseInteger(yearStr)) : parseInteger(yearStr), + month: monthsShort.indexOf(monthStr) + 1, + day: parseInteger(dayStr), + hour: parseInteger(hourStr), + minute: parseInteger(minuteStr) + }; + if (secondStr) result.second = parseInteger(secondStr); -module.exports.CarePartnerSchema = CarePartnerSchema; -class CarePartner extends mongoose.Document { - constructor(object) { - super(object, CarePartnerSchema); - this._type = 'QDM::CarePartner'; + if (weekdayStr) { + result.weekday = weekdayStr.length > 3 ? weekdaysLong.indexOf(weekdayStr) + 1 : weekdaysShort.indexOf(weekdayStr) + 1; } -} -module.exports.CarePartner = CarePartner; + return result; +} // RFC 2822/5322 -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Entity":165,"mongoose/browser":226}],163:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/; -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); +function extractRFC2822(match) { + var weekdayStr = match[1], + dayStr = match[2], + monthStr = match[3], + yearStr = match[4], + hourStr = match[5], + minuteStr = match[6], + secondStr = match[7], + obsOffset = match[8], + milOffset = match[9], + offHourStr = match[10], + offMinuteStr = match[11], + result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); + var offset; -const [Schema] = [mongoose.Schema]; + if (obsOffset) { + offset = obsOffsets[obsOffset]; + } else if (milOffset) { + offset = 0; + } else { + offset = signedOffset(offHourStr, offMinuteStr); + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + return [result, new FixedOffsetZone(offset)]; +} -const ComponentSchema = new mongoose.Schema({ - code: Code, - result: Any, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Component' }, +function preprocessRFC2822(s) { + // Remove comments and folding whitespace and replace multiple-spaces with a single space + return s.replace(/\([^()]*\)|[\n\t]/g, " ").replace(/(\s\s+)/g, " ").trim(); +} // http date -}); -module.exports.ComponentSchema = ComponentSchema; -class Component extends mongoose.Document { - constructor(object) { - super(object, ComponentSchema); - this._type = 'QDM::Component'; - } +var rfc1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/, + rfc850 = /^(Monday|Tuesday|Wedsday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/, + ascii = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/; + +function extractRFC1123Or850(match) { + var weekdayStr = match[1], + dayStr = match[2], + monthStr = match[3], + yearStr = match[4], + hourStr = match[5], + minuteStr = match[6], + secondStr = match[7], + result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); + return [result, FixedOffsetZone.utcInstance]; } -function ComponentSchemaFunction(add, options) { - const extended = new Schema({ - code: Code, - result: Any, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Component' }, +function extractASCII(match) { + var weekdayStr = match[1], + monthStr = match[2], + dayStr = match[3], + hourStr = match[4], + minuteStr = match[5], + secondStr = match[6], + yearStr = match[7], + result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); + return [result, FixedOffsetZone.utcInstance]; +} +var isoYmdWithTimeExtensionRegex = combineRegexes(isoYmdRegex, isoTimeExtensionRegex); +var isoWeekWithTimeExtensionRegex = combineRegexes(isoWeekRegex, isoTimeExtensionRegex); +var isoOrdinalWithTimeExtensionRegex = combineRegexes(isoOrdinalRegex, isoTimeExtensionRegex); +var isoTimeCombinedRegex = combineRegexes(isoTimeRegex); +var extractISOYmdTimeAndOffset = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset); +var extractISOWeekTimeAndOffset = combineExtractors(extractISOWeekData, extractISOTime, extractISOOffset); +var extractISOOrdinalDateAndTime = combineExtractors(extractISOOrdinalData, extractISOTime, extractISOOffset); +var extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset); +/** + * @private + */ - }, options); +function parseISODate(s) { + return parse(s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset]); +} +function parseRFC2822Date(s) { + return parse(preprocessRFC2822(s), [rfc2822, extractRFC2822]); +} +function parseHTTPDate(s) { + return parse(s, [rfc1123, extractRFC1123Or850], [rfc850, extractRFC1123Or850], [ascii, extractASCII]); +} +function parseISODuration(s) { + return parse(s, [isoDuration, extractISODuration]); +} +var extractISOTimeOnly = combineExtractors(extractISOTime); +function parseISOTimeOnly(s) { + return parse(s, [isoTimeOnly, extractISOTimeOnly]); +} +var sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex); +var sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex); +var extractISOYmdTimeOffsetAndIANAZone = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset, extractIANAZone); +var extractISOTimeOffsetAndIANAZone = combineExtractors(extractISOTime, extractISOOffset, extractIANAZone); +function parseSQL(s) { + return parse(s, [sqlYmdWithTimeExtensionRegex, extractISOYmdTimeOffsetAndIANAZone], [sqlTimeCombinedRegex, extractISOTimeOffsetAndIANAZone]); +} - if (add) { - extended.add(add); +var INVALID = "Invalid Duration"; // unit conversion constants + +var lowOrderMatrix = { + weeks: { + days: 7, + hours: 7 * 24, + minutes: 7 * 24 * 60, + seconds: 7 * 24 * 60 * 60, + milliseconds: 7 * 24 * 60 * 60 * 1000 + }, + days: { + hours: 24, + minutes: 24 * 60, + seconds: 24 * 60 * 60, + milliseconds: 24 * 60 * 60 * 1000 + }, + hours: { + minutes: 60, + seconds: 60 * 60, + milliseconds: 60 * 60 * 1000 + }, + minutes: { + seconds: 60, + milliseconds: 60 * 1000 + }, + seconds: { + milliseconds: 1000 + } +}, + casualMatrix = Object.assign({ + years: { + quarters: 4, + months: 12, + weeks: 52, + days: 365, + hours: 365 * 24, + minutes: 365 * 24 * 60, + seconds: 365 * 24 * 60 * 60, + milliseconds: 365 * 24 * 60 * 60 * 1000 + }, + quarters: { + months: 3, + weeks: 13, + days: 91, + hours: 91 * 24, + minutes: 91 * 24 * 60, + seconds: 91 * 24 * 60 * 60, + milliseconds: 91 * 24 * 60 * 60 * 1000 + }, + months: { + weeks: 4, + days: 30, + hours: 30 * 24, + minutes: 30 * 24 * 60, + seconds: 30 * 24 * 60 * 60, + milliseconds: 30 * 24 * 60 * 60 * 1000 } +}, lowOrderMatrix), + daysInYearAccurate = 146097.0 / 400, + daysInMonthAccurate = 146097.0 / 4800, + accurateMatrix = Object.assign({ + years: { + quarters: 4, + months: 12, + weeks: daysInYearAccurate / 7, + days: daysInYearAccurate, + hours: daysInYearAccurate * 24, + minutes: daysInYearAccurate * 24 * 60, + seconds: daysInYearAccurate * 24 * 60 * 60, + milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000 + }, + quarters: { + months: 3, + weeks: daysInYearAccurate / 28, + days: daysInYearAccurate / 4, + hours: daysInYearAccurate * 24 / 4, + minutes: daysInYearAccurate * 24 * 60 / 4, + seconds: daysInYearAccurate * 24 * 60 * 60 / 4, + milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000 / 4 + }, + months: { + weeks: daysInMonthAccurate / 7, + days: daysInMonthAccurate, + hours: daysInMonthAccurate * 24, + minutes: daysInMonthAccurate * 24 * 60, + seconds: daysInMonthAccurate * 24 * 60 * 60, + milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000 + } +}, lowOrderMatrix); // units ordered by size - /* eslint no-underscore-dangle: 0 */ - extended.methods._is = function _is(typeSpecifier) { - return this._typeHierarchy().some( - t => t.type === typeSpecifier.type && t.name === typeSpecifier.name - ); - }; +var orderedUnits = ["years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"]; +var reverseUnits = orderedUnits.slice(0).reverse(); // clone really means "create another instance just like this one, but with these changes" - extended.methods._typeHierarchy = function _typeHierarchy() { - const typeName = this._type.replace(/QDM::/, ''); - const ver = this.qdmVersion.replace('.', '_'); - return [ - { - name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, - type: 'NamedTypeSpecifier', - }, - ]; +function clone(dur, alts, clear) { + if (clear === void 0) { + clear = false; + } + + // deep merge for vals + var conf = { + values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}), + loc: dur.loc.clone(alts.loc), + conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy }; - return extended; + return new Duration(conf); } -module.exports.Component = Component; -module.exports.ComponentSchemaFunction = ComponentSchemaFunction; - -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"mongoose/browser":226}],164:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); - -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); +function antiTrunc(n) { + return n < 0 ? Math.floor(n) : Math.ceil(n); +} // NB: mutates parameters -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; +function convert(matrix, fromMap, fromUnit, toMap, toUnit) { + var conv = matrix[toUnit][fromUnit], + raw = fromMap[fromUnit] / conv, + sameSign = Math.sign(raw) === Math.sign(toMap[toUnit]), + // ok, so this is wild, but see the matrix in the tests + added = !sameSign && toMap[toUnit] !== 0 && Math.abs(raw) <= 1 ? antiTrunc(raw) : Math.trunc(raw); + toMap[toUnit] += added; + fromMap[fromUnit] -= added * conv; +} // NB: mutates parameters -const DiagnosisComponentSchema = new mongoose.Schema({ - code: Code, - presentOnAdmissionIndicator: Code, - rank: Number, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::DiagnosisComponent' }, -}); +function normalizeValues(matrix, vals) { + reverseUnits.reduce(function (previous, current) { + if (!isUndefined(vals[current])) { + if (previous) { + convert(matrix, vals, previous, vals, current); + } -module.exports.DiagnosisComponentSchema = DiagnosisComponentSchema; -class DiagnosisComponent extends mongoose.Document { - constructor(object) { - super(object, DiagnosisComponentSchema); - this._type = 'QDM::DiagnosisComponent'; - } + return current; + } else { + return previous; + } + }, null); } - -module.exports.DiagnosisComponent = DiagnosisComponent; +/** + * A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime.plus} to add a Duration object to a DateTime, producing another DateTime. + * + * Here is a brief overview of commonly used methods and getters in Duration: + * + * * **Creation** To create a Duration, use {@link Duration.fromMillis}, {@link Duration.fromObject}, or {@link Duration.fromISO}. + * * **Unit values** See the {@link Duration.years}, {@link Duration.months}, {@link Duration.weeks}, {@link Duration.days}, {@link Duration.hours}, {@link Duration.minutes}, {@link Duration.seconds}, {@link Duration.milliseconds} accessors. + * * **Configuration** See {@link Duration.locale} and {@link Duration.numberingSystem} accessors. + * * **Transformation** To create new Durations out of old ones use {@link Duration.plus}, {@link Duration.minus}, {@link Duration.normalize}, {@link Duration.set}, {@link Duration.reconfigure}, {@link Duration.shiftTo}, and {@link Duration.negate}. + * * **Output** To convert the Duration into other representations, see {@link Duration.as}, {@link Duration.toISO}, {@link Duration.toFormat}, and {@link Duration.toJSON} + * + * There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation. + */ -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"mongoose/browser":226}],165:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +var Duration = /*#__PURE__*/function () { + /** + * @private + */ + function Duration(config) { + var accurate = config.conversionAccuracy === "longterm" || false; + /** + * @access private + */ -const { IdentifierSchema } = require('./Identifier'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + this.values = config.values; + /** + * @access private + */ -const [Schema] = [mongoose.Schema]; + this.loc = config.loc || Locale.create(); + /** + * @access private + */ -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + this.conversionAccuracy = accurate ? "longterm" : "casual"; + /** + * @access private + */ -const EntitySchema = new mongoose.Schema({ - id: String, - identifier: IdentifierSchema, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Entity' }, + this.invalid = config.invalid || null; + /** + * @access private + */ -}); + this.matrix = accurate ? accurateMatrix : casualMatrix; + /** + * @access private + */ -module.exports.EntitySchema = EntitySchema; -class Entity extends mongoose.Document { - constructor(object) { - super(object, EntitySchema); - this._type = 'QDM::Entity'; + this.isLuxonDuration = true; } -} - -function EntitySchemaFunction(add, options) { - const extended = new Schema({ - identifier: IdentifierSchema, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Entity' }, + /** + * Create Duration from a number of milliseconds. + * @param {number} count of milliseconds + * @param {Object} opts - options for parsing + * @param {string} [opts.locale='en-US'] - the locale to use + * @param {string} opts.numberingSystem - the numbering system to use + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @return {Duration} + */ - id: { - type: String, - default() { - return this._id ? this._id.toString() : mongoose.Types.ObjectId().toString(); - }, - }, + Duration.fromMillis = function fromMillis(count, opts) { + return Duration.fromObject(Object.assign({ + milliseconds: count + }, opts)); + } + /** + * Create a Duration from a JavaScript object with keys like 'years' and 'hours'. + * If this object is empty then a zero milliseconds duration is returned. + * @param {Object} obj - the object to create the DateTime from + * @param {number} obj.years + * @param {number} obj.quarters + * @param {number} obj.months + * @param {number} obj.weeks + * @param {number} obj.days + * @param {number} obj.hours + * @param {number} obj.minutes + * @param {number} obj.seconds + * @param {number} obj.milliseconds + * @param {string} [obj.locale='en-US'] - the locale to use + * @param {string} obj.numberingSystem - the numbering system to use + * @param {string} [obj.conversionAccuracy='casual'] - the conversion system to use + * @return {Duration} + */ + ; - }, options); + Duration.fromObject = function fromObject(obj) { + if (obj == null || typeof obj !== "object") { + throw new InvalidArgumentError("Duration.fromObject: argument expected to be an object, got " + (obj === null ? "null" : typeof obj)); + } - if (add) { - extended.add(add); + return new Duration({ + values: normalizeObject(obj, Duration.normalizeUnit, ["locale", "numberingSystem", "conversionAccuracy", "zone" // a bit of debt; it's super inconvenient internally not to be able to blindly pass this + ]), + loc: Locale.fromObject(obj), + conversionAccuracy: obj.conversionAccuracy + }); } + /** + * Create a Duration from an ISO 8601 duration string. + * @param {string} text - text to parse + * @param {Object} opts - options for parsing + * @param {string} [opts.locale='en-US'] - the locale to use + * @param {string} opts.numberingSystem - the numbering system to use + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @see https://en.wikipedia.org/wiki/ISO_8601#Durations + * @example Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject() //=> { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 } + * @example Duration.fromISO('PT23H').toObject() //=> { hours: 23 } + * @example Duration.fromISO('P5Y3M').toObject() //=> { years: 5, months: 3 } + * @return {Duration} + */ + ; - /* eslint no-underscore-dangle: 0 */ - extended.methods._is = function _is(typeSpecifier) { - return this._typeHierarchy().some( - t => t.type === typeSpecifier.type && t.name === typeSpecifier.name - ); - }; - - extended.methods._typeHierarchy = function _typeHierarchy() { - const typeName = this._type.replace(/QDM::/, ''); - const ver = this.qdmVersion.replace('.', '_'); - return [ - { - name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, - type: 'NamedTypeSpecifier', - }, - ]; - }; - return extended; -} - -module.exports.Entity = Entity; -module.exports.EntitySchemaFunction = EntitySchemaFunction; + Duration.fromISO = function fromISO(text, opts) { + var _parseISODuration = parseISODuration(text), + parsed = _parseISODuration[0]; -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Identifier":167,"mongoose/browser":226}],166:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + if (parsed) { + var obj = Object.assign(parsed, opts); + return Duration.fromObject(obj); + } else { + return Duration.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601"); + } + } + /** + * Create a Duration from an ISO 8601 time string. + * @param {string} text - text to parse + * @param {Object} opts - options for parsing + * @param {string} [opts.locale='en-US'] - the locale to use + * @param {string} opts.numberingSystem - the numbering system to use + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @see https://en.wikipedia.org/wiki/ISO_8601#Times + * @example Duration.fromISOTime('11:22:33.444').toObject() //=> { hours: 11, minutes: 22, seconds: 33, milliseconds: 444 } + * @example Duration.fromISOTime('11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } + * @example Duration.fromISOTime('T11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } + * @example Duration.fromISOTime('1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } + * @example Duration.fromISOTime('T1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } + * @return {Duration} + */ + ; -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + Duration.fromISOTime = function fromISOTime(text, opts) { + var _parseISOTimeOnly = parseISOTimeOnly(text), + parsed = _parseISOTimeOnly[0]; + if (parsed) { + var obj = Object.assign(parsed, opts); + return Duration.fromObject(obj); + } else { + return Duration.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601"); + } + } + /** + * Create an invalid Duration. + * @param {string} reason - simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent + * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information + * @return {Duration} + */ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + Duration.invalid = function invalid(reason, explanation) { + if (explanation === void 0) { + explanation = null; + } -const FacilityLocationSchema = new mongoose.Schema({ - code: Code, - locationPeriod: Interval, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::FacilityLocation' }, + if (!reason) { + throw new InvalidArgumentError("need to specify a reason the Duration is invalid"); + } -}); + var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); -module.exports.FacilityLocationSchema = FacilityLocationSchema; -class FacilityLocation extends mongoose.Document { - constructor(object) { - super(object, FacilityLocationSchema); - this._type = 'QDM::FacilityLocation'; + if (Settings.throwOnInvalid) { + throw new InvalidDurationError(invalid); + } else { + return new Duration({ + invalid: invalid + }); + } } -} - -module.exports.FacilityLocation = FacilityLocation; - + /** + * @private + */ + ; -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"mongoose/browser":226}],167:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + Duration.normalizeUnit = function normalizeUnit(unit) { + var normalized = { + year: "years", + years: "years", + quarter: "quarters", + quarters: "quarters", + month: "months", + months: "months", + week: "weeks", + weeks: "weeks", + day: "days", + days: "days", + hour: "hours", + hours: "hours", + minute: "minutes", + minutes: "minutes", + second: "seconds", + seconds: "seconds", + millisecond: "milliseconds", + milliseconds: "milliseconds" + }[unit ? unit.toLowerCase() : unit]; + if (!normalized) throw new InvalidUnitError(unit); + return normalized; + } + /** + * Check if an object is a Duration. Works across context boundaries + * @param {object} o + * @return {boolean} + */ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + Duration.isDuration = function isDuration(o) { + return o && o.isLuxonDuration || false; + } + /** + * Get the locale of a Duration, such 'en-GB' + * @type {string} + */ + ; -const IdentifierSchema = mongoose.Schema({ - namingSystem: String, - value: String, - qdmVersion: { type: String, default: '5.6' }, - _type: { type: String, default: 'QDM::Identifier' }, + var _proto = Duration.prototype; -}, { _id: false, id: false }); + /** + * Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens: + * * `S` for milliseconds + * * `s` for seconds + * * `m` for minutes + * * `h` for hours + * * `d` for days + * * `M` for months + * * `y` for years + * Notes: + * * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits + * * The duration will be converted to the set of units in the format string using {@link Duration.shiftTo} and the Durations's conversion accuracy setting. + * @param {string} fmt - the format string + * @param {Object} opts - options + * @param {boolean} [opts.floor=true] - floor numerical values + * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2" + * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002" + * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000" + * @return {string} + */ + _proto.toFormat = function toFormat(fmt, opts) { + if (opts === void 0) { + opts = {}; + } -module.exports.IdentifierSchema = IdentifierSchema; -class Identifier extends mongoose.Document { - constructor(object) { - super(object, IdentifierSchema); - this._type = 'QDM::Identifier'; + // reverse-compat since 1.2; we always round down now, never up, and we do it by default + var fmtOpts = Object.assign({}, opts, { + floor: opts.round !== false && opts.floor !== false + }); + return this.isValid ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID; } -} -module.exports.Identifier = Identifier; - -},{"mongoose/browser":226}],168:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** + * Returns a JavaScript object with this Duration's values. + * @param opts - options for generating the object + * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output + * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 } + * @return {Object} + */ + ; -const { EntitySchemaFunction } = require('./Entity'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + _proto.toObject = function toObject(opts) { + if (opts === void 0) { + opts = {}; + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + if (!this.isValid) return {}; + var base = Object.assign({}, this.values); -const LocationSchema = EntitySchemaFunction({ - locationType: Code, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.142' }, - _type: { type: String, default: 'QDM::Location' }, + if (opts.includeConfig) { + base.conversionAccuracy = this.conversionAccuracy; + base.numberingSystem = this.loc.numberingSystem; + base.locale = this.loc.locale; + } -}); + return base; + } + /** + * Returns an ISO 8601-compliant string representation of this Duration. + * @see https://en.wikipedia.org/wiki/ISO_8601#Durations + * @example Duration.fromObject({ years: 3, seconds: 45 }).toISO() //=> 'P3YT45S' + * @example Duration.fromObject({ months: 4, seconds: 45 }).toISO() //=> 'P4MT45S' + * @example Duration.fromObject({ months: 5 }).toISO() //=> 'P5M' + * @example Duration.fromObject({ minutes: 5 }).toISO() //=> 'PT5M' + * @example Duration.fromObject({ milliseconds: 6 }).toISO() //=> 'PT0.006S' + * @return {string} + */ + ; -module.exports.LocationSchema = LocationSchema; -class Location extends mongoose.Document { - constructor(object) { - super(object, LocationSchema); - this._type = 'QDM::Location'; + _proto.toISO = function toISO() { + // we could use the formatter, but this is an easier way to get the minimum string + if (!this.isValid) return null; + var s = "P"; + if (this.years !== 0) s += this.years + "Y"; + if (this.months !== 0 || this.quarters !== 0) s += this.months + this.quarters * 3 + "M"; + if (this.weeks !== 0) s += this.weeks + "W"; + if (this.days !== 0) s += this.days + "D"; + if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0) s += "T"; + if (this.hours !== 0) s += this.hours + "H"; + if (this.minutes !== 0) s += this.minutes + "M"; + if (this.seconds !== 0 || this.milliseconds !== 0) // this will handle "floating point madness" by removing extra decimal places + // https://stackoverflow.com/questions/588004/is-floating-point-math-broken + s += roundTo(this.seconds + this.milliseconds / 1000, 3) + "S"; + if (s === "P") s += "T0S"; + return s; } -} + /** + * Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day. + * Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours. + * @see https://en.wikipedia.org/wiki/ISO_8601#Times + * @param {Object} opts - options + * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 + * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 + * @param {boolean} [opts.includePrefix=false] - include the `T` prefix + * @param {string} [opts.format='extended'] - choose between the basic and extended format + * @example Duration.fromObject({ hours: 11 }).toISOTime() //=> '11:00:00.000' + * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressMilliseconds: true }) //=> '11:00:00' + * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressSeconds: true }) //=> '11:00' + * @example Duration.fromObject({ hours: 11 }).toISOTime({ includePrefix: true }) //=> 'T11:00:00.000' + * @example Duration.fromObject({ hours: 11 }).toISOTime({ format: 'basic' }) //=> '110000.000' + * @return {string} + */ + ; -module.exports.Location = Location; + _proto.toISOTime = function toISOTime(opts) { + if (opts === void 0) { + opts = {}; + } + if (!this.isValid) return null; + var millis = this.toMillis(); + if (millis < 0 || millis >= 86400000) return null; + opts = Object.assign({ + suppressMilliseconds: false, + suppressSeconds: false, + includePrefix: false, + format: "extended" + }, opts); + var value = this.shiftTo("hours", "minutes", "seconds", "milliseconds"); + var fmt = opts.format === "basic" ? "hhmm" : "hh:mm"; -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Entity":165,"mongoose/browser":226}],169:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + if (!opts.suppressSeconds || value.seconds !== 0 || value.milliseconds !== 0) { + fmt += opts.format === "basic" ? "ss" : ":ss"; -const { EntitySchemaFunction } = require('./Entity'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + if (!opts.suppressMilliseconds || value.milliseconds !== 0) { + fmt += ".SSS"; + } + } -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + var str = value.toFormat(fmt); -const OrganizationSchema = EntitySchemaFunction({ - organizationType: Code, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.135' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.163' }, - _type: { type: String, default: 'QDM::Organization' }, + if (opts.includePrefix) { + str = "T" + str; + } -}); + return str; + } + /** + * Returns an ISO 8601 representation of this Duration appropriate for use in JSON. + * @return {string} + */ + ; -module.exports.OrganizationSchema = OrganizationSchema; -class Organization extends mongoose.Document { - constructor(object) { - super(object, OrganizationSchema); - this._type = 'QDM::Organization'; + _proto.toJSON = function toJSON() { + return this.toISO(); } -} + /** + * Returns an ISO 8601 representation of this Duration appropriate for use in debugging. + * @return {string} + */ + ; -module.exports.Organization = Organization; + _proto.toString = function toString() { + return this.toISO(); + } + /** + * Returns an milliseconds value of this Duration. + * @return {number} + */ + ; + _proto.toMillis = function toMillis() { + return this.as("milliseconds"); + } + /** + * Returns an milliseconds value of this Duration. Alias of {@link toMillis} + * @return {number} + */ + ; -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Entity":165,"mongoose/browser":226}],170:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.valueOf = function valueOf() { + return this.toMillis(); + } + /** + * Make this Duration longer by the specified amount. Return a newly-constructed Duration. + * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() + * @return {Duration} + */ + ; -const { EntitySchemaFunction } = require('./Entity'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + _proto.plus = function plus(duration) { + if (!this.isValid) return this; + var dur = friendlyDuration(duration), + result = {}; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + for (var _iterator = _createForOfIteratorHelperLoose(orderedUnits), _step; !(_step = _iterator()).done;) { + var k = _step.value; -const PatientEntitySchema = EntitySchemaFunction({ - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.136' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.161' }, - _type: { type: String, default: 'QDM::PatientEntity' }, + if (hasOwnProperty(dur.values, k) || hasOwnProperty(this.values, k)) { + result[k] = dur.get(k) + this.get(k); + } + } -}); + return clone(this, { + values: result + }, true); + } + /** + * Make this Duration shorter by the specified amount. Return a newly-constructed Duration. + * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() + * @return {Duration} + */ + ; -module.exports.PatientEntitySchema = PatientEntitySchema; -class PatientEntity extends mongoose.Document { - constructor(object) { - super(object, PatientEntitySchema); - this._type = 'QDM::PatientEntity'; + _proto.minus = function minus(duration) { + if (!this.isValid) return this; + var dur = friendlyDuration(duration); + return this.plus(dur.negate()); } -} + /** + * Scale this Duration by the specified amount. Return a newly-constructed Duration. + * @param {function} fn - The function to apply to each unit. Arity is 1 or 2: the value of the unit and, optionally, the unit name. Must return a number. + * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit(x => x * 2) //=> { hours: 2, minutes: 60 } + * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit((x, u) => u === "hour" ? x * 2 : x) //=> { hours: 2, minutes: 30 } + * @return {Duration} + */ + ; -module.exports.PatientEntity = PatientEntity; + _proto.mapUnits = function mapUnits(fn) { + if (!this.isValid) return this; + var result = {}; + for (var _i = 0, _Object$keys = Object.keys(this.values); _i < _Object$keys.length; _i++) { + var k = _Object$keys[_i]; + result[k] = asNumber(fn(this.values[k], k)); + } -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Entity":165,"mongoose/browser":226}],171:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + return clone(this, { + values: result + }, true); + } + /** + * Get the value of unit. + * @param {string} unit - a unit such as 'minute' or 'day' + * @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2 + * @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0 + * @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3 + * @return {number} + */ + ; -const { EntitySchemaFunction } = require('./Entity'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + _proto.get = function get(unit) { + return this[Duration.normalizeUnit(unit)]; + } + /** + * "Set" the values of specified units. Return a newly-constructed Duration. + * @param {Object} values - a mapping of units to numbers + * @example dur.set({ years: 2017 }) + * @example dur.set({ hours: 8, minutes: 30 }) + * @return {Duration} + */ + ; + + _proto.set = function set(values) { + if (!this.isValid) return this; + var mixed = Object.assign(this.values, normalizeObject(values, Duration.normalizeUnit, [])); + return clone(this, { + values: mixed + }); + } + /** + * "Set" the locale and/or numberingSystem. Returns a newly-constructed Duration. + * @example dur.reconfigure({ locale: 'en-GB' }) + * @return {Duration} + */ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto.reconfigure = function reconfigure(_temp) { + var _ref = _temp === void 0 ? {} : _temp, + locale = _ref.locale, + numberingSystem = _ref.numberingSystem, + conversionAccuracy = _ref.conversionAccuracy; -const PractitionerSchema = EntitySchemaFunction({ - role: Code, - specialty: Code, - qualification: Code, - hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.137' }, - qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.162' }, - _type: { type: String, default: 'QDM::Practitioner' }, + var loc = this.loc.clone({ + locale: locale, + numberingSystem: numberingSystem + }), + opts = { + loc: loc + }; -}); + if (conversionAccuracy) { + opts.conversionAccuracy = conversionAccuracy; + } -module.exports.PractitionerSchema = PractitionerSchema; -class Practitioner extends mongoose.Document { - constructor(object) { - super(object, PractitionerSchema); - this._type = 'QDM::Practitioner'; + return clone(this, opts); } -} - -module.exports.Practitioner = Practitioner; - + /** + * Return the length of the duration in the specified unit. + * @param {string} unit - a unit such as 'minutes' or 'days' + * @example Duration.fromObject({years: 1}).as('days') //=> 365 + * @example Duration.fromObject({years: 1}).as('months') //=> 12 + * @example Duration.fromObject({hours: 60}).as('days') //=> 2.5 + * @return {number} + */ + ; -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Entity":165,"mongoose/browser":226}],172:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.as = function as(unit) { + return this.isValid ? this.shiftTo(unit).get(unit) : NaN; + } + /** + * Reduce this Duration to its canonical representation in its current units. + * @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 } + * @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 } + * @return {Duration} + */ + ; -const { ComponentSchemaFunction } = require('./Component'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const QDMDate = require('../basetypes/QDMDate'); -const Any = require('../basetypes/Any'); + _proto.normalize = function normalize() { + if (!this.isValid) return this; + var vals = this.toObject(); + normalizeValues(this.matrix, vals); + return clone(this, { + values: vals + }, true); + } + /** + * Convert this Duration into its representation in a different set of units. + * @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 } + * @return {Duration} + */ + ; -const [Number, String] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, -]; + _proto.shiftTo = function shiftTo() { + for (var _len = arguments.length, units = new Array(_len), _key = 0; _key < _len; _key++) { + units[_key] = arguments[_key]; + } -const ResultComponentSchema = ComponentSchemaFunction({ - referenceRange: Interval, - _type: { type: String, default: 'QDM::ResultComponent' }, + if (!this.isValid) return this; -}); + if (units.length === 0) { + return this; + } -module.exports.ResultComponentSchema = ResultComponentSchema; -class ResultComponent extends mongoose.Document { - constructor(object) { - super(object, ResultComponentSchema); - this._type = 'QDM::ResultComponent'; - } -} + units = units.map(function (u) { + return Duration.normalizeUnit(u); + }); + var built = {}, + accumulated = {}, + vals = this.toObject(); + var lastUnit; -module.exports.ResultComponent = ResultComponent; + for (var _iterator2 = _createForOfIteratorHelperLoose(orderedUnits), _step2; !(_step2 = _iterator2()).done;) { + var k = _step2.value; + if (units.indexOf(k) >= 0) { + lastUnit = k; + var own = 0; // anything we haven't boiled down yet should get boiled to this unit -},{"../basetypes/Any":173,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/QDMDate":179,"../basetypes/Quantity":180,"./Component":163,"mongoose/browser":226}],173:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); + for (var ak in accumulated) { + own += this.matrix[ak][k] * accumulated[ak]; + accumulated[ak] = 0; + } // plus anything that's already in this unit -function Any(key, options) { - mongoose.SchemaType.call(this, key, options, 'Any'); -} -Any.prototype = Object.create(mongoose.SchemaType.prototype); -function RecursiveCast(any) { - if (any && any.value !== undefined && any.unit) { - return new cql.Quantity(any.value, any.unit); - } + if (isNumber(vals[k])) { + own += vals[k]; + } - if (any && any.numerator && any.denominator) { - const numerator = new cql.Quantity(any.numerator.value, any.numerator.unit); - const denominator = new cql.Quantity(any.denominator.value, any.denominator.unit); - return new cql.Ratio(numerator, denominator); - } + var i = Math.trunc(own); + built[k] = i; + accumulated[k] = own - i; // we'd like to absorb these fractions in another unit + // plus anything further down the chain that should be rolled up in to this - if (any.isCode || any.isConcept || any.isValueSet || any.isList || - any.isDateTime || any.isDate || any.isRatio || any.isQuantiy || - any.isInterval || any.isBooleanLiteral || any.isIntegerLiteral || - any.isDecimalLiteral || any.isStringLiteral || any.isTuple) { - return any; - } + for (var down in vals) { + if (orderedUnits.indexOf(down) > orderedUnits.indexOf(k)) { + convert(this.matrix, vals, down, built, k); + } + } // otherwise, keep it in the wings to boil it later - if (any && any.code && any.system) { - const val = { code: any.code, system: any.system }; - val.display = (typeof any.display !== 'undefined') ? any.display : null; - val.version = (typeof any.version !== 'undefined') ? any.version : null; + } else if (isNumber(vals[k])) { + accumulated[k] = vals[k]; + } + } // anything leftover becomes the decimal for the last unit + // lastUnit must be defined since units is not empty - return new cql.Code(val.code, val.system, val.version, val.display); - } - if (any && any.low) { - const casted = new cql.Interval(any.low, any.high, any.lowClosed, any.highClosed); - // Cast Low and High values to Quantities if it is a quantity - if (casted.low && casted.low.unit && casted.low.value) { - casted.low = new cql.Quantity(casted.low.value, casted.low.unit); - if (casted.high && casted.high.unit && casted.high.value) { - casted.high = new cql.Quantity(casted.high.value, casted.high.unit); + for (var key in accumulated) { + if (accumulated[key] !== 0) { + built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key]; } - return casted; } - // Cast to DateTime if it is a string representing a DateTime - if (casted.low && Date.parse(casted.low)) { - casted.low = cql.DateTime.fromJSDate(new Date(casted.low), 0); - } - if (casted.high && Date.parse(casted.high)) { - casted.high = cql.DateTime.fromJSDate(new Date(casted.high), 0); - } - return casted; - } - if (Array.isArray(any)) { - const casted = []; - any.forEach((val) => { - casted.push(RecursiveCast(val)); - }); - return casted; - } - if (Number.isFinite(any)) { - return any; - } - if (Date.parse(any) || Date.parse(`1984-01-01T${any}`)) { - if (any.match(/T/) || any.match(/\+/)) { - // If it has a T or a timezoneoffset, it must be a DateTime - return cql.DateTime.fromJSDate(new Date(any), 0); - } - if (any.match(/:/)) { - // If it has a : but no T or timezoneoffset, it must be a Time - return cql.DateTime.fromJSDate(new Date(`1984-01-01T${any}`), 0).getTime(); - } - // Must be a Date - return cql.DateTime.fromJSDate(new Date(any), 0).getDate(); + return clone(this, { + values: built + }, true).normalize(); } - return any; -} - -Any.prototype.cast = any => RecursiveCast(any); - -mongoose.Schema.Types.Any = Any; -module.exports = Any; + /** + * Return the negative of this Duration. + * @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 } + * @return {Duration} + */ + ; -},{"cql-execution":55,"mongoose/browser":226}],174:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { PatientEntity } = require('../attributes/PatientEntity'); -const { Practitioner } = require('../attributes/Practitioner'); -const { CarePartner } = require('../attributes/CarePartner'); -const { Organization } = require('../attributes/Organization'); -const { Location } = require('../attributes/Location'); + _proto.negate = function negate() { + if (!this.isValid) return this; + var negated = {}; -function AnyEntity(key, options) { - mongoose.SchemaType.call(this, key, options, 'AnyEntity'); -} -AnyEntity.prototype = Object.create(mongoose.SchemaType.prototype); + for (var _i2 = 0, _Object$keys2 = Object.keys(this.values); _i2 < _Object$keys2.length; _i2++) { + var k = _Object$keys2[_i2]; + negated[k] = -this.values[k]; + } -AnyEntity.prototype.cast = (entity) => { - if (entity == null) { - return null; + return clone(this, { + values: negated + }, true); } + /** + * Get the years. + * @type {number} + */ + ; - if (entity instanceof PatientEntity || entity instanceof Practitioner || entity instanceof CarePartner || entity instanceof Organization || entity instanceof Location) { - return entity; - } + /** + * Equality check + * Two Durations are equal iff they have the same units and the same values for each unit. + * @param {Duration} other + * @return {boolean} + */ + _proto.equals = function equals(other) { + if (!this.isValid || !other.isValid) { + return false; + } - if (entity._type != null) { - // copy _id to id if it isn't defined - if (entity.id == null && entity._id != null) { - entity.id = entity._id; + if (!this.loc.equals(other.loc)) { + return false; } - switch (entity._type) { - case 'QDM::PatientEntity': - return new PatientEntity(entity); - case 'QDM::Practitioner': - return new Practitioner(entity); - case 'QDM::CarePartner': - return new CarePartner(entity); - case 'QDM::Organization': - return new Organization(entity); - case 'QDM::Location': - return new Location(entity); - default: - throw new Error(`Could not find entity type "${entity._type}".`); + + function eq(v1, v2) { + // Consider 0 and undefined as equal + if (v1 === undefined || v1 === 0) return v2 === undefined || v2 === 0; + return v1 === v2; } - } else { - throw new Error('Could not find _type indicator for entity.'); - } -}; -mongoose.Schema.Types.AnyEntity = AnyEntity; -module.exports = AnyEntity; + for (var _iterator3 = _createForOfIteratorHelperLoose(orderedUnits), _step3; !(_step3 = _iterator3()).done;) { + var u = _step3.value; -},{"../attributes/CarePartner":162,"../attributes/Location":168,"../attributes/Organization":169,"../attributes/PatientEntity":170,"../attributes/Practitioner":171,"mongoose/browser":226}],175:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); + if (!eq(this.values[u], other.values[u])) { + return false; + } + } -function Code(key, options) { - mongoose.SchemaType.call(this, key, options, 'Code'); -} -Code.prototype = Object.create(mongoose.SchemaType.prototype); + return true; + }; -Code.prototype.cast = (code) => { - if (code != null) { - // return code if it doesn't even need casting - if (code.isCode) { - return code; + _createClass(Duration, [{ + key: "locale", + get: function get() { + return this.isValid ? this.loc.locale : null; } - // handles codes that have not yet been cast to a code and those that have already been cast to a code - if (code.code && code.system) { - const val = { code: code.code, system: code.system }; - val.display = (typeof code.display !== 'undefined') ? code.display : null; - val.version = (typeof code.version !== 'undefined') ? code.version : null; + /** + * Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration + * + * @type {string} + */ - return new cql.Code(val.code, val.system, val.version, val.display); + }, { + key: "numberingSystem", + get: function get() { + return this.isValid ? this.loc.numberingSystem : null; } - throw new Error(`Expected a code. Received ${code}.`); - } else { - // returns a null or undefined if what is passed in is null or undefined - return code; - } -}; - -mongoose.Schema.Types.Code = Code; -module.exports = Code; - -},{"cql-execution":55,"mongoose/browser":226}],176:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); -const Code = require('./Code.js'); -const Identifier = require('../attributes/Identifier'); + }, { + key: "years", + get: function get() { + return this.isValid ? this.values.years || 0 : NaN; + } + /** + * Get the quarters. + * @type {number} + */ -const [Schema] = [mongoose.Schema]; + }, { + key: "quarters", + get: function get() { + return this.isValid ? this.values.quarters || 0 : NaN; + } + /** + * Get the months. + * @type {number} + */ -function DataElementSchema(add, options) { - const extended = new Schema({ - dataElementCodes: { type: [Code] }, - description: { type: String }, - codeListId: { type: String }, - id: { - type: String, - default() { - return this._id ? this._id.toString() : mongoose.Types.ObjectId().toString(); - }, - }, - }, options); + }, { + key: "months", + get: function get() { + return this.isValid ? this.values.months || 0 : NaN; + } + /** + * Get the weeks + * @type {number} + */ - if (add) { - extended.add(add); - } + }, { + key: "weeks", + get: function get() { + return this.isValid ? this.values.weeks || 0 : NaN; + } + /** + * Get the days. + * @type {number} + */ - // Returns all of the codes on this data element in a format usable by - // the cql-execution framework. - extended.methods.getCode = function getCode() { - if (this.dataElementCodes) { - return this.dataElementCodes.map((code) => { - if (code.isCode) { - return code; - } - return new cql.Code(code.code, code.system, code.version, code.display); - }); + }, { + key: "days", + get: function get() { + return this.isValid ? this.values.days || 0 : NaN; } - return null; - }; + /** + * Get the hours. + * @type {number} + */ - // Return the first code on this data element in a format usable by - // the cql-execution framework. - extended.methods.code = function code() { - if (this.dataElementCodes && this.dataElementCodes[0]) { - const qdmCode = this.dataElementCodes[0]; - if (qdmCode.isCode) { - return qdmCode; - } - return new cql.Code(qdmCode.code, qdmCode.system, qdmCode.version, qdmCode.display); + }, { + key: "hours", + get: function get() { + return this.isValid ? this.values.hours || 0 : NaN; } - return null; - }; + /** + * Get the minutes. + * @type {number} + */ - /* eslint no-underscore-dangle: 0 */ - extended.methods._is = function _is(typeSpecifier) { - return this._typeHierarchy().some( - t => t.type === typeSpecifier.type && t.name === typeSpecifier.name - ); - }; + }, { + key: "minutes", + get: function get() { + return this.isValid ? this.values.minutes || 0 : NaN; + } + /** + * Get the seconds. + * @return {number} + */ - /* eslint no-underscore-dangle: 0 */ - extended.methods._typeHierarchy = function _typeHierarchy() { - const typeName = this._type.replace(/QDM::/, ''); - const prefix = this.negationRationale ? 'Negative' : 'Positive'; - const ver = this.qdmVersion.replace('.', '_'); - return [ - { - name: `{urn:healthit-gov:qdm:v${ver}}${prefix}${typeName}`, - type: 'NamedTypeSpecifier', - }, - { - name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, - type: 'NamedTypeSpecifier', - }, - { name: '{urn:hl7-org:elm-types:r1}Tuple', type: 'NamedTypeSpecifier' }, - { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' }, - ]; - }; - return extended; -} + }, { + key: "seconds", + get: function get() { + return this.isValid ? this.values.seconds || 0 : NaN; + } + /** + * Get the milliseconds. + * @return {number} + */ -module.exports.DataElementSchema = DataElementSchema; + }, { + key: "milliseconds", + get: function get() { + return this.isValid ? this.values.milliseconds || 0 : NaN; + } + /** + * Returns whether the Duration is invalid. Invalid durations are returned by diff operations + * on invalid DateTimes or Intervals. + * @return {boolean} + */ -},{"../attributes/Identifier":167,"./Code.js":175,"cql-execution":55,"mongoose/browser":226}],177:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); + }, { + key: "isValid", + get: function get() { + return this.invalid === null; + } + /** + * Returns an error code if this Duration became invalid, or null if the Duration is valid + * @return {string} + */ -function DateTime(key, options) { - mongoose.SchemaType.call(this, key, options, 'DateTime'); -} -DateTime.prototype = Object.create(mongoose.SchemaType.prototype); + }, { + key: "invalidReason", + get: function get() { + return this.invalid ? this.invalid.reason : null; + } + /** + * Returns an explanation of why this Duration became invalid, or null if the Duration is valid + * @type {string} + */ -DateTime.prototype.cast = (dateTime) => { - if (dateTime.isDateTime) { - return dateTime; - } + }, { + key: "invalidExplanation", + get: function get() { + return this.invalid ? this.invalid.explanation : null; + } + }]); - if (!Date.parse(dateTime)) { - throw new Error(`DateTime: ${dateTime} is not a valid DateTime`); + return Duration; +}(); +function friendlyDuration(durationish) { + if (isNumber(durationish)) { + return Duration.fromMillis(durationish); + } else if (Duration.isDuration(durationish)) { + return durationish; + } else if (typeof durationish === "object") { + return Duration.fromObject(durationish); + } else { + throw new InvalidArgumentError("Unknown duration argument " + durationish + " of type " + typeof durationish); } +} - return cql.DateTime.fromJSDate(new Date(dateTime), 0); -}; +var INVALID$1 = "Invalid Interval"; // checks if the start is equal to or before the end -mongoose.Schema.Types.DateTime = DateTime; -module.exports = DateTime; +function validateStartEnd(start, end) { + if (!start || !start.isValid) { + return Interval.invalid("missing or invalid start"); + } else if (!end || !end.isValid) { + return Interval.invalid("missing or invalid end"); + } else if (end < start) { + return Interval.invalid("end before start", "The end of an interval must be after its start, but you had start=" + start.toISO() + " and end=" + end.toISO()); + } else { + return null; + } +} +/** + * An Interval object represents a half-open interval of time, where each endpoint is a {@link DateTime}. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them. + * + * Here is a brief overview of the most commonly used methods and getters in Interval: + * + * * **Creation** To create an Interval, use {@link fromDateTimes}, {@link after}, {@link before}, or {@link fromISO}. + * * **Accessors** Use {@link start} and {@link end} to get the start and end. + * * **Interrogation** To analyze the Interval, use {@link count}, {@link length}, {@link hasSame}, {@link contains}, {@link isAfter}, or {@link isBefore}. + * * **Transformation** To create other Intervals out of this one, use {@link set}, {@link splitAt}, {@link splitBy}, {@link divideEqually}, {@link merge}, {@link xor}, {@link union}, {@link intersection}, or {@link difference}. + * * **Comparison** To compare this Interval to another one, use {@link equals}, {@link overlaps}, {@link abutsStart}, {@link abutsEnd}, {@link engulfs}. + * * **Output** To convert the Interval into other representations, see {@link toString}, {@link toISO}, {@link toISODate}, {@link toISOTime}, {@link toFormat}, and {@link toDuration}. + */ -},{"cql-execution":55,"mongoose/browser":226}],178:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); -const DateTime = require('./DateTime'); -function Interval(key, options) { - mongoose.SchemaType.call(this, key, options, 'Interval'); -} -Interval.prototype = Object.create(mongoose.SchemaType.prototype); +var Interval = /*#__PURE__*/function () { + /** + * @private + */ + function Interval(config) { + /** + * @access private + */ + this.s = config.start; + /** + * @access private + */ -Interval.prototype.cast = (interval) => { - if (interval.isInterval) { - return interval; - } - const casted = new cql.Interval(interval.low, interval.high, interval.lowClosed, interval.highClosed); + this.e = config.end; + /** + * @access private + */ - // Cast Low and High values to Quantities if it is a quantity - if (casted.low && casted.low.unit && casted.low.value) { - casted.low = new cql.Quantity(casted.low.value, casted.low.unit); - if (casted.high && casted.high.unit && casted.high.value) { - casted.high = new cql.Quantity(casted.high.value, casted.high.unit); - } - return casted; - } + this.invalid = config.invalid || null; + /** + * @access private + */ - // Cast to DateTime if it is a string representing a DateTime - if (casted.low) { - casted.low = DateTime.prototype.cast(casted.low); + this.isLuxonInterval = true; } + /** + * Create an invalid Interval. + * @param {string} reason - simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent + * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information + * @return {Interval} + */ - if (casted.high) { - casted.high = DateTime.prototype.cast(casted.high); - } - return casted; -}; -mongoose.Schema.Types.Interval = Interval; -module.exports = Interval; + Interval.invalid = function invalid(reason, explanation) { + if (explanation === void 0) { + explanation = null; + } -},{"./DateTime":177,"cql-execution":55,"mongoose/browser":226}],179:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); + if (!reason) { + throw new InvalidArgumentError("need to specify a reason the Interval is invalid"); + } -function QDMDate(key, options) { - mongoose.SchemaType.call(this, key, options, 'Date'); -} -QDMDate.prototype = Object.create(mongoose.SchemaType.prototype); + var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); -QDMDate.prototype.cast = (date) => { - if (date == null) { - return date; + if (Settings.throwOnInvalid) { + throw new InvalidIntervalError(invalid); + } else { + return new Interval({ + invalid: invalid + }); + } } + /** + * Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end. + * @param {DateTime|Date|Object} start + * @param {DateTime|Date|Object} end + * @return {Interval} + */ + ; - // Already a CQL Date - if (date.isDate) { - return date; - } + Interval.fromDateTimes = function fromDateTimes(start, end) { + var builtStart = friendlyDateTime(start), + builtEnd = friendlyDateTime(end); + var validateError = validateStartEnd(builtStart, builtEnd); - // Object - if (typeof date === 'object') { - const keys = Object.keys(date); - if (keys.includes('year') && keys.includes('month') && keys.includes('day')) { - return new cql.Date(date.year, date.month, date.day); + if (validateError == null) { + return new Interval({ + start: builtStart, + end: builtEnd + }); + } else { + return validateError; } } + /** + * Create an Interval from a start DateTime and a Duration to extend to. + * @param {DateTime|Date|Object} start + * @param {Duration|Object|number} duration - the length of the Interval. + * @return {Interval} + */ + ; - // Date String - if (!cql.Date.parse(date)) { - throw new Error(`Date: ${date} is not a valid Date`); - } else { - return cql.Date.parse(date); + Interval.after = function after(start, duration) { + var dur = friendlyDuration(duration), + dt = friendlyDateTime(start); + return Interval.fromDateTimes(dt, dt.plus(dur)); } -}; - -mongoose.Schema.Types.QDMDate = QDMDate; -module.exports = QDMDate; - -},{"cql-execution":55,"mongoose/browser":226}],180:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const cql = require('cql-execution'); - -function Quantity(key, options) { - mongoose.SchemaType.call(this, key, options, 'Quantity'); -} -Quantity.prototype = Object.create(mongoose.SchemaType.prototype); + /** + * Create an Interval from an end DateTime and a Duration to extend backwards to. + * @param {DateTime|Date|Object} end + * @param {Duration|Object|number} duration - the length of the Interval. + * @return {Interval} + */ + ; -Quantity.prototype.cast = (quantity) => { - if (typeof quantity.value === 'undefined') { - throw new Error(`Quantity: ${quantity} does not have a value`); - } else if (typeof quantity.unit === 'undefined') { - throw new Error(`Quantity: ${quantity} does not have a unit`); + Interval.before = function before(end, duration) { + var dur = friendlyDuration(duration), + dt = friendlyDateTime(end); + return Interval.fromDateTimes(dt.minus(dur), dt); } + /** + * Create an Interval from an ISO 8601 string. + * Accepts `/`, `/`, and `/` formats. + * @param {string} text - the ISO string to parse + * @param {Object} [opts] - options to pass {@link DateTime.fromISO} and optionally {@link Duration.fromISO} + * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals + * @return {Interval} + */ + ; - return new cql.Quantity(quantity.value, quantity.unit); -}; + Interval.fromISO = function fromISO(text, opts) { + var _split = (text || "").split("/", 2), + s = _split[0], + e = _split[1]; -mongoose.Schema.Types.Quantity = Quantity; -module.exports = Quantity; + if (s && e) { + var start, startIsValid; -},{"cql-execution":55,"mongoose/browser":226}],181:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { StatementDependencySchema } = require('./CQLStatementDependency'); + try { + start = DateTime.fromISO(s, opts); + startIsValid = start.isValid; + } catch (e) { + startIsValid = false; + } -const [Mixed, mDate] = [ - mongoose.Schema.Types.Mixed, - mongoose.Schema.Types.Date, -]; + var end, endIsValid; -const CQLLibrarySchema = new mongoose.Schema( - { - library_name: String, - library_version: String, - cql: String, - elm: Mixed, - elm_annotations: Mixed, - is_main_library: { type: Boolean, default: false }, - is_top_level: { type: Boolean, default: true }, - statement_dependencies: [StatementDependencySchema], - }, - // Options - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps - } -); + try { + end = DateTime.fromISO(e, opts); + endIsValid = end.isValid; + } catch (e) { + endIsValid = false; + } -module.exports.CQLLibrarySchema = CQLLibrarySchema; -class CQLLibrary extends mongoose.Document { - constructor(object) { - super(object, CQLLibrarySchema); - } -} -module.exports.CQLLibrary = CQLLibrary; + if (startIsValid && endIsValid) { + return Interval.fromDateTimes(start, end); + } -},{"./CQLStatementDependency":182,"mongoose/browser":226}],182:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + if (startIsValid) { + var dur = Duration.fromISO(e, opts); -const StatementReferenceSchema = new mongoose.Schema({ - library_name: String, - statement_name: String, - hqmf_id: String, -}); + if (dur.isValid) { + return Interval.after(start, dur); + } + } else if (endIsValid) { + var _dur = Duration.fromISO(s, opts); -const StatementDependencySchema = new mongoose.Schema({ - statement_name: String, - statement_references: [StatementReferenceSchema], -}); + if (_dur.isValid) { + return Interval.before(end, _dur); + } + } + } -module.exports.StatementReferenceSchema = StatementReferenceSchema; -class StatementReference extends mongoose.Document { - constructor(object) { - super(object, StatementReferenceSchema); + return Interval.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601"); } -} -module.exports.StatementReference = StatementReference; + /** + * Check if an object is an Interval. Works across context boundaries + * @param {object} o + * @return {boolean} + */ + ; -module.exports.StatementDependencySchema = StatementDependencySchema; -class StatementDependency extends mongoose.Document { - constructor(object) { - super(object, StatementDependencySchema); + Interval.isInterval = function isInterval(o) { + return o && o.isLuxonInterval || false; } -} -module.exports.StatementDependency = StatementDependency; - -},{"mongoose/browser":226}],183:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); - -const [String, Mixed] = [ - mongoose.Schema.Types.String, - mongoose.Schema.Types.Mixed, -]; + /** + * Returns the start of the Interval + * @type {DateTime} + */ + ; -const ClauseResultSchema = mongoose.Schema({ - // Library the clause this result is for is in - library_name: String, - // Statement the clause this result is for is in - statement_name: String, - // LocalId of the clause this result is for - localId: String, - // Final, processed result of raw calculation - final: String, - // Raw result of clause calculation - raw: Mixed, -}); + var _proto = Interval.prototype; + /** + * Returns the length of the Interval in the specified unit. + * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in. + * @return {number} + */ + _proto.length = function length(unit) { + if (unit === void 0) { + unit = "milliseconds"; + } -module.exports.ClauseResultSchema = ClauseResultSchema; -class ClauseResult extends mongoose.Document { - constructor(object) { - super(object, ClauseResultSchema); + return this.isValid ? this.toDuration.apply(this, [unit]).get(unit) : NaN; } -} -module.exports.ClauseResult = ClauseResult; - -},{"mongoose/browser":226}],184:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** + * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part. + * Unlike {@link length} this counts sections of the calendar, not periods of time, e.g. specifying 'day' + * asks 'what dates are included in this interval?', not 'how many days long is this interval?' + * @param {string} [unit='milliseconds'] - the unit of time to count. + * @return {number} + */ + ; -const ConceptSchema = new mongoose.Schema({ - code: String, - code_system_oid: String, - code_system_name: String, - code_system_version: String, - display_name: String, -}); + _proto.count = function count(unit) { + if (unit === void 0) { + unit = "milliseconds"; + } -module.exports.ConceptSchema = ConceptSchema; -class Concept extends mongoose.Document { - constructor(object) { - super(object, ConceptSchema); + if (!this.isValid) return NaN; + var start = this.start.startOf(unit), + end = this.end.startOf(unit); + return Math.floor(end.diff(start, unit).get(unit)) + 1; } -} -module.exports.Concept = Concept; - -},{"mongoose/browser":226}],185:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const { ClauseResultSchema } = require('./ClauseResult'); -const { StatementResultSchema } = require('./StatementResult'); + /** + * Returns whether this Interval's start and end are both in the same unit of time + * @param {string} unit - the unit of time to check sameness on + * @return {boolean} + */ + ; -const [Number, String, Mixed, ObjectId] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, - mongoose.Schema.Types.Mixed, - mongoose.Schema.Types.ObjectId, -]; + _proto.hasSame = function hasSame(unit) { + return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false; + } + /** + * Return whether this Interval has the same start and end DateTimes. + * @return {boolean} + */ + ; -const IndividualResultSchema = mongoose.Schema( - { - // Population Attributes - STRAT: Number, - IPP: Number, - DENOM: Number, - NUMER: Number, - NUMEX: Number, - DENEX: Number, - DENEXCEP: Number, - MSRPOPL: Number, - OBSERV: Number, - MSRPOPLEX: Number, + _proto.isEmpty = function isEmpty() { + return this.s.valueOf() === this.e.valueOf(); + } + /** + * Return whether this Interval's start is after the specified DateTime. + * @param {DateTime} dateTime + * @return {boolean} + */ + ; - // Result Attributes - clause_results: [ClauseResultSchema], - statement_results: [StatementResultSchema], - population_relevance: Mixed, - episode_results: Mixed, - observation_values: [Number], + _proto.isAfter = function isAfter(dateTime) { + if (!this.isValid) return false; + return this.s > dateTime; + } + /** + * Return whether this Interval's end is before the specified DateTime. + * @param {DateTime} dateTime + * @return {boolean} + */ + ; - // This field is for application specific information only. If both Bonnie and - // Cypress use a common field, it should be made a field on this model, - // and not put into extendedData. - extendedData: { - type: Mixed, - default: {}, - }, + _proto.isBefore = function isBefore(dateTime) { + if (!this.isValid) return false; + return this.e <= dateTime; + } + /** + * Return whether this Interval contains the specified DateTime. + * @param {DateTime} dateTime + * @return {boolean} + */ + ; - // Calculation State attributes - state: { - type: String, - enum: ['queued', 'running', 'complete', 'cancelled', 'failed'], - default: 'queued', - }, + _proto.contains = function contains(dateTime) { + if (!this.isValid) return false; + return this.s <= dateTime && this.e > dateTime; + } + /** + * "Sets" the start and/or end dates. Returns a newly-constructed Interval. + * @param {Object} values - the values to set + * @param {DateTime} values.start - the starting DateTime + * @param {DateTime} values.end - the ending DateTime + * @return {Interval} + */ + ; - // Relations to other model classes - // 'alias' field makes it so you can call obj.measure, and get the object referenced by measure_id - measure_id: { type: ObjectId, ref: 'Measure', alias: 'measure' }, - patient_id: { type: ObjectId, ref: 'Patient', alias: 'patient' }, + _proto.set = function set(_temp) { + var _ref = _temp === void 0 ? {} : _temp, + start = _ref.start, + end = _ref.end; - }, - // Options - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps + if (!this.isValid) return this; + return Interval.fromDateTimes(start || this.s, end || this.e); } -); + /** + * Split this Interval at each of the specified DateTimes + * @param {...[DateTime]} dateTimes - the unit of time to count. + * @return {[Interval]} + */ + ; -IndividualResultSchema.methods.clause_results_by_clause = function clause_results_by_clause() { - const clause_results_hash = {}; - this.clause_results.forEach((result) => { - if (!clause_results_hash[result.library_name]) { - clause_results_hash[result.library_name] = {}; + _proto.splitAt = function splitAt() { + var _this = this; + + if (!this.isValid) return []; + + for (var _len = arguments.length, dateTimes = new Array(_len), _key = 0; _key < _len; _key++) { + dateTimes[_key] = arguments[_key]; } - clause_results_hash[result.library_name][result.localId] = result; - }); - return clause_results_hash; -}; -IndividualResultSchema.methods.statement_results_by_statement = function statement_results_by_statement() { - const statement_results_hash = {}; - this.statement_results.forEach((result) => { - if (!statement_results_hash[result.library_name]) { - statement_results_hash[result.library_name] = {}; + var sorted = dateTimes.map(friendlyDateTime).filter(function (d) { + return _this.contains(d); + }).sort(), + results = []; + var s = this.s, + i = 0; + + while (s < this.e) { + var added = sorted[i] || this.e, + next = +added > +this.e ? this.e : added; + results.push(Interval.fromDateTimes(s, next)); + s = next; + i += 1; } - statement_results_hash[result.library_name][result.statement_name] = result; - }); - return statement_results_hash; -}; -module.exports.IndividualResultSchema = IndividualResultSchema; -class IndividualResult extends mongoose.Document { - constructor(object) { - super(object, IndividualResultSchema); + return results; } -} -module.exports.IndividualResult = IndividualResult; - -},{"./ClauseResult":183,"./StatementResult":191,"mongoose/browser":226}],186:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DataElementSchema = require('../basetypes/DataElement').DataElementSchema(); -const AllDataElements = require('../AllDataElements'); -const { CQLLibrarySchema } = require('./CQLLibrary'); -const { PopulationSetSchema } = require('./PopulationSet'); + /** + * Split this Interval into smaller Intervals, each of the specified length. + * Left over time is grouped into a smaller interval + * @param {Duration|Object|number} duration - The length of each resulting interval. + * @return {[Interval]} + */ + ; -const [Number, String, Boolean, Mixed, ObjectId, Date] = [ - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, - mongoose.Schema.Types.Boolean, - mongoose.Schema.Types.Mixed, - mongoose.Schema.Types.ObjectId, - mongoose.Schema.Types.Date, -]; + _proto.splitBy = function splitBy(duration) { + var dur = friendlyDuration(duration); -const MeasureSchema = new mongoose.Schema( - { - // A version-specific UUID for the measure - hqmf_id: String, - // A version-neutral UUID for the measure - hqmf_set_id: String, - // A Semantic Version-compliant string (e.g. "2.3.4") for the measure - hqmf_version_number: String, - // A CMS-style string (e.g. "CMS2v4") for the measure - cms_id: String, - title: String, - description: String, + if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) { + return []; + } - // Composite/component measure fields - composite: { - type: Boolean, - default: false, - }, - component: { - type: Boolean, - default: false, - }, - component_hqmf_set_ids: [String], - composite_hqmf_set_id: String, + var s = this.s, + idx = 1, + next; + var results = []; - // Measure type variables - measure_scoring: { - type: String, - enum: ['PROPORTION', 'RATIO', 'CONTINUOUS_VARIABLE', 'COHORT'], - default: 'PROPORTION', - }, - calculation_method: { - type: String, - enum: ['PATIENT', 'EPISODE_OF_CARE'], - default: 'PATIENT', - }, - calculate_sdes: Boolean, + while (s < this.e) { + var added = this.start.plus(dur.mapUnits(function (x) { + return x * idx; + })); + next = +added > +this.e ? this.e : added; + results.push(Interval.fromDateTimes(s, next)); + s = next; + idx += 1; + } - // ELM/CQL Measure-logic related data encapsulated in CQLLibrarySchema - // Field name changed from 'cql' to 'cql_libraries' because the semantics of - // embeds_many: cqls (on the Ruby side) sounded weird, - // and we wanted to keep the API consistent - cql_libraries: [CQLLibrarySchema], - main_cql_library: String, + return results; + } + /** + * Split this Interval into the specified number of smaller intervals. + * @param {number} numberOfParts - The number of Intervals to divide the Interval into. + * @return {[Interval]} + */ + ; - // HQMF/Tacoma-specific Measure-logic related data - population_criteria: Mixed, - source_data_criteria: [], - measure_period: Mixed, - measure_attributes: [], + _proto.divideEqually = function divideEqually(numberOfParts) { + if (!this.isValid) return []; + return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts); + } + /** + * Return whether this Interval overlaps with the specified Interval + * @param {Interval} other + * @return {boolean} + */ + ; - population_sets: [PopulationSetSchema], + _proto.overlaps = function overlaps(other) { + return this.e > other.s && this.s < other.e; + } + /** + * Return whether this Interval's end is adjacent to the specified Interval's start. + * @param {Interval} other + * @return {boolean} + */ + ; - // Relations to other model classes - bundle: { type: ObjectId, ref: 'Bundle' }, // Cypress-specific, until we migrate the Bundle into cqm-models - package: { type: ObjectId, ref: 'MeasurePackage' }, // Bonnie-specific - patients: [{ type: ObjectId, ref: 'Patient', index: true }], + _proto.abutsStart = function abutsStart(other) { + if (!this.isValid) return false; + return +this.e === +other.s; + } + /** + * Return whether this Interval's start is adjacent to the specified Interval's end. + * @param {Interval} other + * @return {boolean} + */ + ; - value_sets: [{ type: ObjectId, ref: 'ValueSet' }], - }, - // Options - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps + _proto.abutsEnd = function abutsEnd(other) { + if (!this.isValid) return false; + return +other.e === +this.s; } -); + /** + * Return whether this Interval engulfs the start and end of the specified Interval. + * @param {Interval} other + * @return {boolean} + */ + ; -// After initialization of a Measure model, initialize every individual data element -// to its respective Mongoose Model -MeasureSchema.methods.initializeDataElements = function initializeDataElements() { - let typeStripped; - const sourceDataCriteriaInit = []; - this.source_data_criteria.forEach((element) => { - typeStripped = element._type.replace(/QDM::/, ''); - sourceDataCriteriaInit.push(new AllDataElements[typeStripped](element)); - }); - this.set('source_data_criteria', sourceDataCriteriaInit); -}; + _proto.engulfs = function engulfs(other) { + if (!this.isValid) return false; + return this.s <= other.s && this.e >= other.e; + } + /** + * Return whether this Interval has the same start and end as the specified Interval. + * @param {Interval} other + * @return {boolean} + */ + ; -MeasureSchema.methods.all_stratifications = function all_stratifications() { - return this.population_sets.flatMap(ps => ps.stratifications); -}; + _proto.equals = function equals(other) { + if (!this.isValid || !other.isValid) { + return false; + } -module.exports.MeasureSchema = MeasureSchema; -class Measure extends mongoose.Document { - constructor(object) { - super(object, MeasureSchema); - this.initializeDataElements(); + return this.s.equals(other.s) && this.e.equals(other.e); } -} -module.exports.Measure = Measure; + /** + * Return an Interval representing the intersection of this Interval and the specified Interval. + * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals. + * Returns null if the intersection is empty, meaning, the intervals don't intersect. + * @param {Interval} other + * @return {Interval} + */ + ; -},{"../AllDataElements":108,"../basetypes/Code":175,"../basetypes/DataElement":176,"../basetypes/Interval":178,"../basetypes/Quantity":180,"./CQLLibrary":181,"./PopulationSet":189,"mongoose/browser":226}],187:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + _proto.intersection = function intersection(other) { + if (!this.isValid) return this; + var s = this.s > other.s ? this.s : other.s, + e = this.e < other.e ? this.e : other.e; -// using mBuffer to not conflict with system Buffer -const [mBuffer, ObjectId] = [ - mongoose.Schema.Types.Buffer, - mongoose.Schema.Types.ObjectId, -]; + if (s >= e) { + return null; + } else { + return Interval.fromDateTimes(s, e); + } + } + /** + * Return an Interval representing the union of this Interval and the specified Interval. + * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals. + * @param {Interval} other + * @return {Interval} + */ + ; -const MeasurePackageSchema = new mongoose.Schema( - { - file: mBuffer, - measure: { type: ObjectId, ref: 'Measure' }, - }, - // Options - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, + _proto.union = function union(other) { + if (!this.isValid) return this; + var s = this.s < other.s ? this.s : other.s, + e = this.e > other.e ? this.e : other.e; + return Interval.fromDateTimes(s, e); } -); + /** + * Merge an array of Intervals into a equivalent minimal set of Intervals. + * Combines overlapping and adjacent Intervals. + * @param {[Interval]} intervals + * @return {[Interval]} + */ + ; -module.exports.MeasurePackageSchema = MeasurePackageSchema; -class MeasurePackage extends mongoose.Document { - constructor(object) { - super(object, MeasurePackageSchema); + Interval.merge = function merge(intervals) { + var _intervals$sort$reduc = intervals.sort(function (a, b) { + return a.s - b.s; + }).reduce(function (_ref2, item) { + var sofar = _ref2[0], + current = _ref2[1]; + + if (!current) { + return [sofar, item]; + } else if (current.overlaps(item) || current.abutsStart(item)) { + return [sofar, current.union(item)]; + } else { + return [sofar.concat([current]), item]; + } + }, [[], null]), + found = _intervals$sort$reduc[0], + final = _intervals$sort$reduc[1]; + + if (final) { + found.push(final); + } + + return found; } -} -module.exports.MeasurePackage = MeasurePackage; + /** + * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals. + * @param {[Interval]} intervals + * @return {[Interval]} + */ + ; -},{"mongoose/browser":226}],188:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const Code = require('../basetypes/Code'); -const Interval = require('../basetypes/Interval'); -const Quantity = require('../basetypes/Quantity'); -const DateTime = require('../basetypes/DateTime'); -const { QDMPatientSchema, QDMPatient } = require('../QDMPatient'); -const { ProviderSchema } = require('./Provider'); + Interval.xor = function xor(intervals) { + var _Array$prototype; -const [Schema, Number, String, Mixed] = [ - mongoose.Schema, - mongoose.Schema.Types.Number, - mongoose.Schema.Types.String, - mongoose.Schema.Types.Mixed, -]; + var start = null, + currentCount = 0; -const PatientSchema = new Schema({ + var results = [], + ends = intervals.map(function (i) { + return [{ + time: i.s, + type: "s" + }, { + time: i.e, + type: "e" + }]; + }), + flattened = (_Array$prototype = Array.prototype).concat.apply(_Array$prototype, ends), + arr = flattened.sort(function (a, b) { + return a.time - b.time; + }); - givenNames: [String], - familyName: String, - bundleId: String, - expectedValues: [], - notes: String, - qdmPatient: QDMPatientSchema, - providers: [ProviderSchema], - measure_ids: [String], + for (var _iterator = _createForOfIteratorHelperLoose(arr), _step; !(_step = _iterator()).done;) { + var i = _step.value; + currentCount += i.type === "s" ? 1 : -1; -}, { id: false }); + if (currentCount === 1) { + start = i.time; + } else { + if (start && +start !== +i.time) { + results.push(Interval.fromDateTimes(start, i.time)); + } -module.exports.PatientSchema = PatientSchema; -class Patient extends mongoose.Document { - constructor(object) { - super(object, PatientSchema); - if (this.qdmPatient) { - this.qdmPatient = new QDMPatient(this.qdmPatient.toJSON()); + start = null; + } } - } -} -module.exports.Patient = Patient; - -},{"../QDMPatient":155,"../basetypes/Code":175,"../basetypes/DateTime":177,"../basetypes/Interval":178,"../basetypes/Quantity":180,"./Provider":190,"mongoose/browser":226}],189:[function(require,module,exports){ -/* eslint-disable no-unused-vars, no-param-reassign */ -const mongoose = require('mongoose/browser'); -const { StatementReferenceSchema } = require('./CQLStatementDependency'); -const [Mixed] = [ - mongoose.Schema.Types.Mixed, -]; + return Interval.merge(results); + } + /** + * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals. + * @param {...Interval} intervals + * @return {[Interval]} + */ + ; -// TODO: figure out if there is a better way to handle inheritance like mongoid. -// _type is how mongoid stores the specific type of the embedded document. -const PopulationMapSchema = new mongoose.Schema({ - _type: String, - IPP: StatementReferenceSchema, - DENOM: StatementReferenceSchema, - NUMER: StatementReferenceSchema, - NUMEX: StatementReferenceSchema, - DENEX: StatementReferenceSchema, - DENEXCEP: StatementReferenceSchema, - MSRPOPL: StatementReferenceSchema, - MSRPOPLEX: StatementReferenceSchema, - // STRAT is only here so cqm-execution can handle stratification results compliation with the current approach. - STRAT: StatementReferenceSchema, -}); + _proto.difference = function difference() { + var _this2 = this; -if (!PopulationMapSchema.options.toObject) PopulationMapSchema.options.toObject = {}; -PopulationMapSchema.options.toObject.transform = function transform(doc, ret, options) { - // remove the _id and _type of every document before returning the result - delete ret._id; - delete ret._type; - return ret; -}; + for (var _len2 = arguments.length, intervals = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + intervals[_key2] = arguments[_key2]; + } + return Interval.xor([this].concat(intervals)).map(function (i) { + return _this2.intersection(i); + }).filter(function (i) { + return i && !i.isEmpty(); + }); + } + /** + * Returns a string representation of this Interval appropriate for debugging. + * @return {string} + */ + ; -const StratificationSchema = new mongoose.Schema({ - title: String, - stratification_id: String, - hqmf_id: String, - statement: StatementReferenceSchema, -}); + _proto.toString = function toString() { + if (!this.isValid) return INVALID$1; + return "[" + this.s.toISO() + " \u2013 " + this.e.toISO() + ")"; + } + /** + * Returns an ISO 8601-compliant string representation of this Interval. + * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals + * @param {Object} opts - The same options as {@link DateTime.toISO} + * @return {string} + */ + ; -const ObservationSchema = new mongoose.Schema({ - title: String, - observation_function: StatementReferenceSchema, - observation_parameter: StatementReferenceSchema, - aggregation_type: String, - hqmf_id: String, -}); + _proto.toISO = function toISO(opts) { + if (!this.isValid) return INVALID$1; + return this.s.toISO(opts) + "/" + this.e.toISO(opts); + } + /** + * Returns an ISO 8601-compliant string representation of date of this Interval. + * The time components are ignored. + * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals + * @return {string} + */ + ; -const PopulationSetSchema = new mongoose.Schema({ - title: String, - population_set_id: String, - populations: PopulationMapSchema, - stratifications: [StratificationSchema], - supplemental_data_elements: [StatementReferenceSchema], - observations: [ObservationSchema], -}); + _proto.toISODate = function toISODate() { + if (!this.isValid) return INVALID$1; + return this.s.toISODate() + "/" + this.e.toISODate(); + } + /** + * Returns an ISO 8601-compliant string representation of time of this Interval. + * The date components are ignored. + * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals + * @param {Object} opts - The same options as {@link DateTime.toISO} + * @return {string} + */ + ; -module.exports.StratificationSchema = StratificationSchema; -class Stratification extends mongoose.Document { - constructor(object) { - super(object, StratificationSchema); + _proto.toISOTime = function toISOTime(opts) { + if (!this.isValid) return INVALID$1; + return this.s.toISOTime(opts) + "/" + this.e.toISOTime(opts); } -} -module.exports.Stratification = Stratification; + /** + * Returns a string representation of this Interval formatted according to the specified format string. + * @param {string} dateFormat - the format string. This string formats the start and end time. See {@link DateTime.toFormat} for details. + * @param {Object} opts - options + * @param {string} [opts.separator = ' – '] - a separator to place between the start and end representations + * @return {string} + */ + ; -module.exports.ObservationSchema = ObservationSchema; -class Observation extends mongoose.Document { - constructor(object) { - super(object, ObservationSchema); + _proto.toFormat = function toFormat(dateFormat, _temp2) { + var _ref3 = _temp2 === void 0 ? {} : _temp2, + _ref3$separator = _ref3.separator, + separator = _ref3$separator === void 0 ? " – " : _ref3$separator; + + if (!this.isValid) return INVALID$1; + return "" + this.s.toFormat(dateFormat) + separator + this.e.toFormat(dateFormat); } -} -module.exports.Observation = Observation; + /** + * Return a Duration representing the time spanned by this interval. + * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration. + * @param {Object} opts - options that affect the creation of the Duration + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 } + * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 } + * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 } + * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 } + * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 } + * @return {Duration} + */ + ; -module.exports.PopulationMapSchema = PopulationMapSchema; -class PopulationMap extends mongoose.Document { - constructor(object) { - super(object, PopulationMapSchema); - } -} -module.exports.PopulationMap = PopulationMap; + _proto.toDuration = function toDuration(unit, opts) { + if (!this.isValid) { + return Duration.invalid(this.invalidReason); + } -module.exports.PopulationSetSchema = PopulationSetSchema; -class PopulationSet extends mongoose.Document { - constructor(object) { - super(object, PopulationSetSchema); + return this.e.diff(this.s, unit, opts); } -} -module.exports.PopulationSet = PopulationSet; - -},{"./CQLStatementDependency":182,"mongoose/browser":226}],190:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); + /** + * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes + * @param {function} mapFn + * @return {Interval} + * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC()) + * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 })) + */ + ; -const [Schema, String, Boolean] = [ - mongoose.Schema, - mongoose.Schema.Types.String, - mongoose.Schema.Types.Boolean, -]; + _proto.mapEndpoints = function mapEndpoints(mapFn) { + return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e)); + }; -const AddressSchema = new mongoose.Schema({ - street: [String], - city: String, - state: String, - zip: String, - country: String, - use: String, -}); + _createClass(Interval, [{ + key: "start", + get: function get() { + return this.isValid ? this.s : null; + } + /** + * Returns the end of the Interval + * @type {DateTime} + */ -const TelecomSchema = new mongoose.Schema({ - use: String, - value: String, - preferred: Boolean, -}); + }, { + key: "end", + get: function get() { + return this.isValid ? this.e : null; + } + /** + * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'. + * @type {boolean} + */ -const ProviderSchema = new Schema({ - _type: { type: String, default: 'Provider' }, + }, { + key: "isValid", + get: function get() { + return this.invalidReason === null; + } + /** + * Returns an error code if this Interval is invalid, or null if the Interval is valid + * @type {string} + */ - givenNames: [String], - familyName: String, - specialty: String, - title: String, - addresses: [AddressSchema], - telecoms: [TelecomSchema], + }, { + key: "invalidReason", + get: function get() { + return this.invalid ? this.invalid.reason : null; + } + /** + * Returns an explanation of why this Interval became invalid, or null if the Interval is valid + * @type {string} + */ -}, { id: false }); + }, { + key: "invalidExplanation", + get: function get() { + return this.invalid ? this.invalid.explanation : null; + } + }]); -module.exports.ProviderSchema = ProviderSchema; -class Provider extends mongoose.Document { - constructor(object) { - super(object, ProviderSchema); - } -} -module.exports.Provider = Provider; + return Interval; +}(); -},{"mongoose/browser":226}],191:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); +/** + * The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment. + */ -const [String, Mixed] = [ - mongoose.Schema.Types.String, - mongoose.Schema.Types.Mixed, -]; +var Info = /*#__PURE__*/function () { + function Info() {} -const StatementResultSchema = mongoose.Schema({ - // Library the statement this result is for is in - library_name: String, - // Statement this result is for is in - statement_name: String, - // Result, processed for display, of the statement this result is for - pretty: String, - // Final, processed result of raw calculation - final: String, - // Raw result of clause calculation - raw: Mixed, - /* - * 'NA' - Not applicable. This statement is not relevant to any population calculation in this population_set. Common - * for unused library statements or statements only used for other population sets. - * - * 'FALSE' - This statement is not relevant to any of this patient's population inclusion calculations. - * - * 'TRUE' - This statement is relevant for one or more of the population inclusion calculations. - */ - relevance: { - type: String, - enum: ['NA', 'TRUE', 'FALSE'], - default: 'NA', - }, -}); + /** + * Return whether the specified zone contains a DST. + * @param {string|Zone} [zone='local'] - Zone to check. Defaults to the environment's local zone. + * @return {boolean} + */ + Info.hasDST = function hasDST(zone) { + if (zone === void 0) { + zone = Settings.defaultZone; + } + var proto = DateTime.now().setZone(zone).set({ + month: 12 + }); + return !zone.universal && proto.offset !== proto.set({ + month: 6 + }).offset; + } + /** + * Return whether the specified zone is a valid IANA specifier. + * @param {string} zone - Zone to check + * @return {boolean} + */ + ; -module.exports.StatementResultSchema = StatementResultSchema; -class StatementResult extends mongoose.Document { - constructor(object) { - super(object, StatementResultSchema); + Info.isValidIANAZone = function isValidIANAZone(zone) { + return IANAZone.isValidSpecifier(zone) && IANAZone.isValidZone(zone); } -} -module.exports.StatementResult = StatementResult; + /** + * Converts the input into a {@link Zone} instance. + * + * * If `input` is already a Zone instance, it is returned unchanged. + * * If `input` is a string containing a valid time zone name, a Zone instance + * with that name is returned. + * * If `input` is a string that doesn't refer to a known time zone, a Zone + * instance with {@link Zone.isValid} == false is returned. + * * If `input is a number, a Zone instance with the specified fixed offset + * in minutes is returned. + * * If `input` is `null` or `undefined`, the default zone is returned. + * @param {string|Zone|number} [input] - the value to be converted + * @return {Zone} + */ + ; -},{"mongoose/browser":226}],192:[function(require,module,exports){ -const mongoose = require('mongoose/browser'); -const Concept = require('./Concept.js'); + Info.normalizeZone = function normalizeZone$1(input) { + return normalizeZone(input, Settings.defaultZone); + } + /** + * Return an array of standalone month names. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat + * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long" + * @param {Object} opts - options + * @param {string} [opts.locale] - the locale code + * @param {string} [opts.numberingSystem=null] - the numbering system + * @param {string} [opts.locObj=null] - an existing locale object to use + * @param {string} [opts.outputCalendar='gregory'] - the calendar + * @example Info.months()[0] //=> 'January' + * @example Info.months('short')[0] //=> 'Jan' + * @example Info.months('numeric')[0] //=> '1' + * @example Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.' + * @example Info.months('numeric', { locale: 'ar' })[0] //=> '١' + * @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I' + * @return {[string]} + */ + ; -const [String] = [mongoose.Schema.Types.String]; + Info.months = function months(length, _temp) { + if (length === void 0) { + length = "long"; + } -const ValueSetSchema = new mongoose.Schema( - { - oid: String, - display_name: String, - version: String, + var _ref = _temp === void 0 ? {} : _temp, + _ref$locale = _ref.locale, + locale = _ref$locale === void 0 ? null : _ref$locale, + _ref$numberingSystem = _ref.numberingSystem, + numberingSystem = _ref$numberingSystem === void 0 ? null : _ref$numberingSystem, + _ref$locObj = _ref.locObj, + locObj = _ref$locObj === void 0 ? null : _ref$locObj, + _ref$outputCalendar = _ref.outputCalendar, + outputCalendar = _ref$outputCalendar === void 0 ? "gregory" : _ref$outputCalendar; - concepts: [Concept.ConceptSchema], - }, - // Options - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, + return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length); } -); + /** + * Return an array of format month names. + * Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that + * changes the string. + * See {@link months} + * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long" + * @param {Object} opts - options + * @param {string} [opts.locale] - the locale code + * @param {string} [opts.numberingSystem=null] - the numbering system + * @param {string} [opts.locObj=null] - an existing locale object to use + * @param {string} [opts.outputCalendar='gregory'] - the calendar + * @return {[string]} + */ + ; -module.exports.ValueSetSchema = ValueSetSchema; -class ValueSet extends mongoose.Document { - constructor(object) { - super(object, ValueSetSchema); + Info.monthsFormat = function monthsFormat(length, _temp2) { + if (length === void 0) { + length = "long"; + } + + var _ref2 = _temp2 === void 0 ? {} : _temp2, + _ref2$locale = _ref2.locale, + locale = _ref2$locale === void 0 ? null : _ref2$locale, + _ref2$numberingSystem = _ref2.numberingSystem, + numberingSystem = _ref2$numberingSystem === void 0 ? null : _ref2$numberingSystem, + _ref2$locObj = _ref2.locObj, + locObj = _ref2$locObj === void 0 ? null : _ref2$locObj, + _ref2$outputCalendar = _ref2.outputCalendar, + outputCalendar = _ref2$outputCalendar === void 0 ? "gregory" : _ref2$outputCalendar; + + return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true); } -} -module.exports.ValueSet = ValueSet; + /** + * Return an array of standalone week names. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat + * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long". + * @param {Object} opts - options + * @param {string} [opts.locale] - the locale code + * @param {string} [opts.numberingSystem=null] - the numbering system + * @param {string} [opts.locObj=null] - an existing locale object to use + * @example Info.weekdays()[0] //=> 'Monday' + * @example Info.weekdays('short')[0] //=> 'Mon' + * @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.' + * @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين' + * @return {[string]} + */ + ; -},{"./Concept.js":184,"mongoose/browser":226}],193:[function(require,module,exports){ -module.exports = require('./AllDataElements.js'); -module.exports.CQL = require('cql-execution'); -module.exports.Result = require('./Result.js').Result; -module.exports.ResultSchema = require('./Result.js').ResultSchema; -module.exports.Measure = require('./cqm/Measure.js').Measure; -module.exports.MeasureSchema = require('./cqm/Measure.js').MeasureSchema; -module.exports.MeasurePackage = require('./cqm/MeasurePackage.js').MeasurePackage; -module.exports.MeasurePackageSchema = require('./cqm/MeasurePackage.js').MeasurePackageSchema; -module.exports.Patient = require('./cqm/Patient.js').Patient; -module.exports.PatientSchema = require('./cqm/Patient.js').PatientSchema; -module.exports.Provider = require('./cqm/Provider.js').Provider; -module.exports.ProviderSchema = require('./cqm/Provider.js').ProviderSchema; -module.exports.StatementDependency = require('./cqm/CQLStatementDependency.js').StatementDependency; -module.exports.StatementDependencySchema = require('./cqm/CQLStatementDependency.js').StatementDependencySchema; -module.exports.PopulationSet = require('./cqm/PopulationSet.js').PopulationSet; -module.exports.PopulationSetSchema = require('./cqm/PopulationSet.js').PopulationSetSchema; -module.exports.CQLLibrary = require('./cqm/CQLLibrary.js').CQLLibrary; -module.exports.CQLLibrarySchema = require('./cqm/CQLLibrary.js').CQLLibrarySchema; -module.exports.ValueSet = require('./cqm/ValueSet.js').ValueSet; -module.exports.ValueSetSchema = require('./cqm/ValueSet.js').ValueSetSchema; -module.exports.Concept = require('./cqm/Concept.js').Concept; -module.exports.ConceptSchema = require('./cqm/Concept.js').ConceptSchema; -module.exports.IndividualResult = require('./cqm/IndividualResult.js').IndividualResult; -module.exports.IndividualResultSchema = require('./cqm/IndividualResult.js').IndividualResultSchema; -module.exports.ClauseResult = require('./cqm/ClauseResult.js').ClauseResult; -module.exports.ClauseResultSchema = require('./cqm/ClauseResult.js').ClauseResultSchema; -module.exports.StatementResult = require('./cqm/StatementResult.js').StatementResult; -module.exports.StatementResultSchema = require('./cqm/StatementResult.js').StatementResultchema; + Info.weekdays = function weekdays(length, _temp3) { + if (length === void 0) { + length = "long"; + } -},{"./AllDataElements.js":108,"./Result.js":157,"./cqm/CQLLibrary.js":181,"./cqm/CQLStatementDependency.js":182,"./cqm/ClauseResult.js":183,"./cqm/Concept.js":184,"./cqm/IndividualResult.js":185,"./cqm/Measure.js":186,"./cqm/MeasurePackage.js":187,"./cqm/Patient.js":188,"./cqm/PopulationSet.js":189,"./cqm/Provider.js":190,"./cqm/StatementResult.js":191,"./cqm/ValueSet.js":192,"cql-execution":55}],194:[function(require,module,exports){ -'use strict'; + var _ref3 = _temp3 === void 0 ? {} : _temp3, + _ref3$locale = _ref3.locale, + locale = _ref3$locale === void 0 ? null : _ref3$locale, + _ref3$numberingSystem = _ref3.numberingSystem, + numberingSystem = _ref3$numberingSystem === void 0 ? null : _ref3$numberingSystem, + _ref3$locObj = _ref3.locObj, + locObj = _ref3$locObj === void 0 ? null : _ref3$locObj; -var hasPropertyDescriptors = require('has-property-descriptors')(); + return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length); + } + /** + * Return an array of format week names. + * Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that + * changes the string. + * See {@link weekdays} + * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long". + * @param {Object} opts - options + * @param {string} [opts.locale=null] - the locale code + * @param {string} [opts.numberingSystem=null] - the numbering system + * @param {string} [opts.locObj=null] - an existing locale object to use + * @return {[string]} + */ + ; -var GetIntrinsic = require('get-intrinsic'); + Info.weekdaysFormat = function weekdaysFormat(length, _temp4) { + if (length === void 0) { + length = "long"; + } -var $defineProperty = hasPropertyDescriptors && GetIntrinsic('%Object.defineProperty%', true); -if ($defineProperty) { - try { - $defineProperty({}, 'a', { value: 1 }); - } catch (e) { - // IE 8 has a broken defineProperty - $defineProperty = false; - } -} + var _ref4 = _temp4 === void 0 ? {} : _temp4, + _ref4$locale = _ref4.locale, + locale = _ref4$locale === void 0 ? null : _ref4$locale, + _ref4$numberingSystem = _ref4.numberingSystem, + numberingSystem = _ref4$numberingSystem === void 0 ? null : _ref4$numberingSystem, + _ref4$locObj = _ref4.locObj, + locObj = _ref4$locObj === void 0 ? null : _ref4$locObj; -var $SyntaxError = GetIntrinsic('%SyntaxError%'); -var $TypeError = GetIntrinsic('%TypeError%'); + return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true); + } + /** + * Return an array of meridiems. + * @param {Object} opts - options + * @param {string} [opts.locale] - the locale code + * @example Info.meridiems() //=> [ 'AM', 'PM' ] + * @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ] + * @return {[string]} + */ + ; -var gopd = require('gopd'); + Info.meridiems = function meridiems(_temp5) { + var _ref5 = _temp5 === void 0 ? {} : _temp5, + _ref5$locale = _ref5.locale, + locale = _ref5$locale === void 0 ? null : _ref5$locale; -/** @type {(obj: Record, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void} */ -module.exports = function defineDataProperty( - obj, - property, - value -) { - if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { - throw new $TypeError('`obj` must be an object or a function`'); - } - if (typeof property !== 'string' && typeof property !== 'symbol') { - throw new $TypeError('`property` must be a string or a symbol`'); - } - if (arguments.length > 3 && typeof arguments[3] !== 'boolean' && arguments[3] !== null) { - throw new $TypeError('`nonEnumerable`, if provided, must be a boolean or null'); - } - if (arguments.length > 4 && typeof arguments[4] !== 'boolean' && arguments[4] !== null) { - throw new $TypeError('`nonWritable`, if provided, must be a boolean or null'); - } - if (arguments.length > 5 && typeof arguments[5] !== 'boolean' && arguments[5] !== null) { - throw new $TypeError('`nonConfigurable`, if provided, must be a boolean or null'); - } - if (arguments.length > 6 && typeof arguments[6] !== 'boolean') { - throw new $TypeError('`loose`, if provided, must be a boolean'); - } + return Locale.create(locale).meridiems(); + } + /** + * Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian. + * @param {string} [length='short'] - the length of the era representation, such as "short" or "long". + * @param {Object} opts - options + * @param {string} [opts.locale] - the locale code + * @example Info.eras() //=> [ 'BC', 'AD' ] + * @example Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ] + * @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ] + * @return {[string]} + */ + ; - var nonEnumerable = arguments.length > 3 ? arguments[3] : null; - var nonWritable = arguments.length > 4 ? arguments[4] : null; - var nonConfigurable = arguments.length > 5 ? arguments[5] : null; - var loose = arguments.length > 6 ? arguments[6] : false; + Info.eras = function eras(length, _temp6) { + if (length === void 0) { + length = "short"; + } - /* @type {false | TypedPropertyDescriptor} */ - var desc = !!gopd && gopd(obj, property); + var _ref6 = _temp6 === void 0 ? {} : _temp6, + _ref6$locale = _ref6.locale, + locale = _ref6$locale === void 0 ? null : _ref6$locale; - if ($defineProperty) { - $defineProperty(obj, property, { - configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable, - enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable, - value: value, - writable: nonWritable === null && desc ? desc.writable : !nonWritable - }); - } else if (loose || (!nonEnumerable && !nonWritable && !nonConfigurable)) { - // must fall back to [[Set]], and was not explicitly asked to make non-enumerable, non-writable, or non-configurable - obj[property] = value; // eslint-disable-line no-param-reassign - } else { - throw new $SyntaxError('This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.'); - } -}; + return Locale.create(locale, null, "gregory").eras(length); + } + /** + * Return the set of available features in this environment. + * Some features of Luxon are not available in all environments. For example, on older browsers, timezone support is not available. Use this function to figure out if that's the case. + * Keys: + * * `zones`: whether this environment supports IANA timezones + * * `intlTokens`: whether this environment supports internationalized token-based formatting/parsing + * * `intl`: whether this environment supports general internationalization + * * `relative`: whether this environment supports relative time formatting + * @example Info.features() //=> { intl: true, intlTokens: false, zones: true, relative: false } + * @return {Object} + */ + ; -},{"get-intrinsic":199,"gopd":202,"has-property-descriptors":204}],195:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + Info.features = function features() { + var intl = false, + intlTokens = false, + zones = false, + relative = false; -'use strict'; + if (hasIntl()) { + intl = true; + intlTokens = hasFormatToParts(); + relative = hasRelative(); -var R = typeof Reflect === 'object' ? Reflect : null -var ReflectApply = R && typeof R.apply === 'function' - ? R.apply - : function ReflectApply(target, receiver, args) { - return Function.prototype.apply.call(target, receiver, args); - } + try { + zones = new Intl.DateTimeFormat("en", { + timeZone: "America/New_York" + }).resolvedOptions().timeZone === "America/New_York"; + } catch (e) { + zones = false; + } + } -var ReflectOwnKeys -if (R && typeof R.ownKeys === 'function') { - ReflectOwnKeys = R.ownKeys -} else if (Object.getOwnPropertySymbols) { - ReflectOwnKeys = function ReflectOwnKeys(target) { - return Object.getOwnPropertyNames(target) - .concat(Object.getOwnPropertySymbols(target)); - }; -} else { - ReflectOwnKeys = function ReflectOwnKeys(target) { - return Object.getOwnPropertyNames(target); + return { + intl: intl, + intlTokens: intlTokens, + zones: zones, + relative: relative + }; }; -} -function ProcessEmitWarning(warning) { - if (console && console.warn) console.warn(warning); -} + return Info; +}(); -var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) { - return value !== value; -} +function dayDiff(earlier, later) { + var utcDayStart = function utcDayStart(dt) { + return dt.toUTC(0, { + keepLocalTime: true + }).startOf("day").valueOf(); + }, + ms = utcDayStart(later) - utcDayStart(earlier); -function EventEmitter() { - EventEmitter.init.call(this); + return Math.floor(Duration.fromMillis(ms).as("days")); } -module.exports = EventEmitter; -module.exports.once = once; - -// Backwards-compat with node 0.10.x -EventEmitter.EventEmitter = EventEmitter; - -EventEmitter.prototype._events = undefined; -EventEmitter.prototype._eventsCount = 0; -EventEmitter.prototype._maxListeners = undefined; -// By default EventEmitters will print a warning if more than 10 listeners are -// added to it. This is a useful default which helps finding memory leaks. -var defaultMaxListeners = 10; +function highOrderDiffs(cursor, later, units) { + var differs = [["years", function (a, b) { + return b.year - a.year; + }], ["quarters", function (a, b) { + return b.quarter - a.quarter; + }], ["months", function (a, b) { + return b.month - a.month + (b.year - a.year) * 12; + }], ["weeks", function (a, b) { + var days = dayDiff(a, b); + return (days - days % 7) / 7; + }], ["days", dayDiff]]; + var results = {}; + var lowestOrder, highWater; -function checkListener(listener) { - if (typeof listener !== 'function') { - throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); - } -} + for (var _i = 0, _differs = differs; _i < _differs.length; _i++) { + var _differs$_i = _differs[_i], + unit = _differs$_i[0], + differ = _differs$_i[1]; -Object.defineProperty(EventEmitter, 'defaultMaxListeners', { - enumerable: true, - get: function() { - return defaultMaxListeners; - }, - set: function(arg) { - if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) { - throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.'); - } - defaultMaxListeners = arg; - } -}); + if (units.indexOf(unit) >= 0) { + var _cursor$plus; -EventEmitter.init = function() { + lowestOrder = unit; + var delta = differ(cursor, later); + highWater = cursor.plus((_cursor$plus = {}, _cursor$plus[unit] = delta, _cursor$plus)); - if (this._events === undefined || - this._events === Object.getPrototypeOf(this)._events) { - this._events = Object.create(null); - this._eventsCount = 0; - } + if (highWater > later) { + var _cursor$plus2; - this._maxListeners = this._maxListeners || undefined; -}; + cursor = cursor.plus((_cursor$plus2 = {}, _cursor$plus2[unit] = delta - 1, _cursor$plus2)); + delta -= 1; + } else { + cursor = highWater; + } -// Obviously not all Emitters should be limited to 10. This function allows -// that to be increased. Set to zero for unlimited. -EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { - if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) { - throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.'); + results[unit] = delta; + } } - this._maxListeners = n; - return this; -}; -function _getMaxListeners(that) { - if (that._maxListeners === undefined) - return EventEmitter.defaultMaxListeners; - return that._maxListeners; + return [cursor, results, highWater, lowestOrder]; } -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - return _getMaxListeners(this); -}; +function _diff (earlier, later, units, opts) { + var _highOrderDiffs = highOrderDiffs(earlier, later, units), + cursor = _highOrderDiffs[0], + results = _highOrderDiffs[1], + highWater = _highOrderDiffs[2], + lowestOrder = _highOrderDiffs[3]; -EventEmitter.prototype.emit = function emit(type) { - var args = []; - for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); - var doError = (type === 'error'); + var remainingMillis = later - cursor; + var lowerOrderUnits = units.filter(function (u) { + return ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0; + }); - var events = this._events; - if (events !== undefined) - doError = (doError && events.error === undefined); - else if (!doError) - return false; + if (lowerOrderUnits.length === 0) { + if (highWater < later) { + var _cursor$plus3; - // If there is no 'error' event listener then throw. - if (doError) { - var er; - if (args.length > 0) - er = args[0]; - if (er instanceof Error) { - // Note: The comments on the `throw` lines are intentional, they show - // up in Node's output if this results in an unhandled exception. - throw er; // Unhandled 'error' event + highWater = cursor.plus((_cursor$plus3 = {}, _cursor$plus3[lowestOrder] = 1, _cursor$plus3)); + } + + if (highWater !== cursor) { + results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor); } - // At least give some kind of context to the user - var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : '')); - err.context = er; - throw err; // Unhandled 'error' event } - var handler = events[type]; + var duration = Duration.fromObject(Object.assign(results, opts)); - if (handler === undefined) - return false; + if (lowerOrderUnits.length > 0) { + var _Duration$fromMillis; - if (typeof handler === 'function') { - ReflectApply(handler, this, args); + return (_Duration$fromMillis = Duration.fromMillis(remainingMillis, opts)).shiftTo.apply(_Duration$fromMillis, lowerOrderUnits).plus(duration); } else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - ReflectApply(listeners[i], this, args); + return duration; } +} - return true; +var numberingSystems = { + arab: "[\u0660-\u0669]", + arabext: "[\u06F0-\u06F9]", + bali: "[\u1B50-\u1B59]", + beng: "[\u09E6-\u09EF]", + deva: "[\u0966-\u096F]", + fullwide: "[\uFF10-\uFF19]", + gujr: "[\u0AE6-\u0AEF]", + hanidec: "[〇|一|二|三|四|五|六|七|八|九]", + khmr: "[\u17E0-\u17E9]", + knda: "[\u0CE6-\u0CEF]", + laoo: "[\u0ED0-\u0ED9]", + limb: "[\u1946-\u194F]", + mlym: "[\u0D66-\u0D6F]", + mong: "[\u1810-\u1819]", + mymr: "[\u1040-\u1049]", + orya: "[\u0B66-\u0B6F]", + tamldec: "[\u0BE6-\u0BEF]", + telu: "[\u0C66-\u0C6F]", + thai: "[\u0E50-\u0E59]", + tibt: "[\u0F20-\u0F29]", + latn: "\\d" }; +var numberingSystemsUTF16 = { + arab: [1632, 1641], + arabext: [1776, 1785], + bali: [6992, 7001], + beng: [2534, 2543], + deva: [2406, 2415], + fullwide: [65296, 65303], + gujr: [2790, 2799], + khmr: [6112, 6121], + knda: [3302, 3311], + laoo: [3792, 3801], + limb: [6470, 6479], + mlym: [3430, 3439], + mong: [6160, 6169], + mymr: [4160, 4169], + orya: [2918, 2927], + tamldec: [3046, 3055], + telu: [3174, 3183], + thai: [3664, 3673], + tibt: [3872, 3881] +}; // eslint-disable-next-line -function _addListener(target, type, listener, prepend) { - var m; - var events; - var existing; +var hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split(""); +function parseDigits(str) { + var value = parseInt(str, 10); - checkListener(listener); + if (isNaN(value)) { + value = ""; - events = target._events; - if (events === undefined) { - events = target._events = Object.create(null); - target._eventsCount = 0; - } else { - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (events.newListener !== undefined) { - target.emit('newListener', type, - listener.listener ? listener.listener : listener); + for (var i = 0; i < str.length; i++) { + var code = str.charCodeAt(i); - // Re-assign `events` because a newListener handler could have caused the - // this._events to be assigned to a new object - events = target._events; - } - existing = events[type]; - } + if (str[i].search(numberingSystems.hanidec) !== -1) { + value += hanidecChars.indexOf(str[i]); + } else { + for (var key in numberingSystemsUTF16) { + var _numberingSystemsUTF = numberingSystemsUTF16[key], + min = _numberingSystemsUTF[0], + max = _numberingSystemsUTF[1]; - if (existing === undefined) { - // Optimize the case of one listener. Don't need the extra array object. - existing = events[type] = listener; - ++target._eventsCount; - } else { - if (typeof existing === 'function') { - // Adding the second element, need to change to array. - existing = events[type] = - prepend ? [listener, existing] : [existing, listener]; - // If we've already got an array, just append. - } else if (prepend) { - existing.unshift(listener); - } else { - existing.push(listener); + if (code >= min && code <= max) { + value += code - min; + } + } + } } - // Check for listener leak - m = _getMaxListeners(target); - if (m > 0 && existing.length > m && !existing.warned) { - existing.warned = true; - // No error code for this since it is a Warning - // eslint-disable-next-line no-restricted-syntax - var w = new Error('Possible EventEmitter memory leak detected. ' + - existing.length + ' ' + String(type) + ' listeners ' + - 'added. Use emitter.setMaxListeners() to ' + - 'increase limit'); - w.name = 'MaxListenersExceededWarning'; - w.emitter = target; - w.type = type; - w.count = existing.length; - ProcessEmitWarning(w); - } + return parseInt(value, 10); + } else { + return value; } - - return target; } +function digitRegex(_ref, append) { + var numberingSystem = _ref.numberingSystem; -EventEmitter.prototype.addListener = function addListener(type, listener) { - return _addListener(this, type, listener, false); -}; - -EventEmitter.prototype.on = EventEmitter.prototype.addListener; - -EventEmitter.prototype.prependListener = - function prependListener(type, listener) { - return _addListener(this, type, listener, true); - }; - -function onceWrapper() { - if (!this.fired) { - this.target.removeListener(this.type, this.wrapFn); - this.fired = true; - if (arguments.length === 0) - return this.listener.call(this.target); - return this.listener.apply(this.target, arguments); + if (append === void 0) { + append = ""; } -} -function _onceWrap(target, type, listener) { - var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; - var wrapped = onceWrapper.bind(state); - wrapped.listener = listener; - state.wrapFn = wrapped; - return wrapped; + return new RegExp("" + numberingSystems[numberingSystem || "latn"] + append); } -EventEmitter.prototype.once = function once(type, listener) { - checkListener(listener); - this.on(type, _onceWrap(this, type, listener)); - return this; -}; +var MISSING_FTP = "missing Intl.DateTimeFormat.formatToParts support"; -EventEmitter.prototype.prependOnceListener = - function prependOnceListener(type, listener) { - checkListener(listener); - this.prependListener(type, _onceWrap(this, type, listener)); - return this; +function intUnit(regex, post) { + if (post === void 0) { + post = function post(i) { + return i; }; + } -// Emits a 'removeListener' event if and only if the listener was removed. -EventEmitter.prototype.removeListener = - function removeListener(type, listener) { - var list, events, position, i, originalListener; - - checkListener(listener); - - events = this._events; - if (events === undefined) - return this; - - list = events[type]; - if (list === undefined) - return this; - - if (list === listener || list.listener === listener) { - if (--this._eventsCount === 0) - this._events = Object.create(null); - else { - delete events[type]; - if (events.removeListener) - this.emit('removeListener', type, list.listener || listener); - } - } else if (typeof list !== 'function') { - position = -1; - - for (i = list.length - 1; i >= 0; i--) { - if (list[i] === listener || list[i].listener === listener) { - originalListener = list[i].listener; - position = i; - break; - } - } + return { + regex: regex, + deser: function deser(_ref) { + var s = _ref[0]; + return post(parseDigits(s)); + } + }; +} - if (position < 0) - return this; +var NBSP = String.fromCharCode(160); +var spaceOrNBSP = "( |" + NBSP + ")"; +var spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g"); - if (position === 0) - list.shift(); - else { - spliceOne(list, position); - } +function fixListRegex(s) { + // make dots optional and also make them literal + // make space and non breakable space characters interchangeable + return s.replace(/\./g, "\\.?").replace(spaceOrNBSPRegExp, spaceOrNBSP); +} - if (list.length === 1) - events[type] = list[0]; +function stripInsensitivities(s) { + return s.replace(/\./g, "") // ignore dots that were made optional + .replace(spaceOrNBSPRegExp, " ") // interchange space and nbsp + .toLowerCase(); +} - if (events.removeListener !== undefined) - this.emit('removeListener', type, originalListener || listener); +function oneOf(strings, startIndex) { + if (strings === null) { + return null; + } else { + return { + regex: RegExp(strings.map(fixListRegex).join("|")), + deser: function deser(_ref2) { + var s = _ref2[0]; + return strings.findIndex(function (i) { + return stripInsensitivities(s) === stripInsensitivities(i); + }) + startIndex; } - - return this; }; + } +} -EventEmitter.prototype.off = EventEmitter.prototype.removeListener; - -EventEmitter.prototype.removeAllListeners = - function removeAllListeners(type) { - var listeners, events, i; - - events = this._events; - if (events === undefined) - return this; - - // not listening for removeListener, no need to emit - if (events.removeListener === undefined) { - if (arguments.length === 0) { - this._events = Object.create(null); - this._eventsCount = 0; - } else if (events[type] !== undefined) { - if (--this._eventsCount === 0) - this._events = Object.create(null); - else - delete events[type]; - } - return this; - } - - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - var keys = Object.keys(events); - var key; - for (i = 0; i < keys.length; ++i) { - key = keys[i]; - if (key === 'removeListener') continue; - this.removeAllListeners(key); - } - this.removeAllListeners('removeListener'); - this._events = Object.create(null); - this._eventsCount = 0; - return this; - } +function offset(regex, groups) { + return { + regex: regex, + deser: function deser(_ref3) { + var h = _ref3[1], + m = _ref3[2]; + return signedOffset(h, m); + }, + groups: groups + }; +} - listeners = events[type]; +function simple(regex) { + return { + regex: regex, + deser: function deser(_ref4) { + var s = _ref4[0]; + return s; + } + }; +} - if (typeof listeners === 'function') { - this.removeListener(type, listeners); - } else if (listeners !== undefined) { - // LIFO order - for (i = listeners.length - 1; i >= 0; i--) { - this.removeListener(type, listeners[i]); - } - } +function escapeToken(value) { + // eslint-disable-next-line no-useless-escape + return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); +} - return this; +function unitForToken(token, loc) { + var one = digitRegex(loc), + two = digitRegex(loc, "{2}"), + three = digitRegex(loc, "{3}"), + four = digitRegex(loc, "{4}"), + six = digitRegex(loc, "{6}"), + oneOrTwo = digitRegex(loc, "{1,2}"), + oneToThree = digitRegex(loc, "{1,3}"), + oneToSix = digitRegex(loc, "{1,6}"), + oneToNine = digitRegex(loc, "{1,9}"), + twoToFour = digitRegex(loc, "{2,4}"), + fourToSix = digitRegex(loc, "{4,6}"), + literal = function literal(t) { + return { + regex: RegExp(escapeToken(t.val)), + deser: function deser(_ref5) { + var s = _ref5[0]; + return s; + }, + literal: true }; + }, + unitate = function unitate(t) { + if (token.literal) { + return literal(t); + } -function _listeners(target, type, unwrap) { - var events = target._events; - - if (events === undefined) - return []; + switch (t.val) { + // era + case "G": + return oneOf(loc.eras("short", false), 0); - var evlistener = events[type]; - if (evlistener === undefined) - return []; + case "GG": + return oneOf(loc.eras("long", false), 0); + // years - if (typeof evlistener === 'function') - return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + case "y": + return intUnit(oneToSix); - return unwrap ? - unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); -} + case "yy": + return intUnit(twoToFour, untruncateYear); -EventEmitter.prototype.listeners = function listeners(type) { - return _listeners(this, type, true); -}; + case "yyyy": + return intUnit(four); -EventEmitter.prototype.rawListeners = function rawListeners(type) { - return _listeners(this, type, false); -}; + case "yyyyy": + return intUnit(fourToSix); -EventEmitter.listenerCount = function(emitter, type) { - if (typeof emitter.listenerCount === 'function') { - return emitter.listenerCount(type); - } else { - return listenerCount.call(emitter, type); - } -}; + case "yyyyyy": + return intUnit(six); + // months -EventEmitter.prototype.listenerCount = listenerCount; -function listenerCount(type) { - var events = this._events; + case "M": + return intUnit(oneOrTwo); - if (events !== undefined) { - var evlistener = events[type]; + case "MM": + return intUnit(two); - if (typeof evlistener === 'function') { - return 1; - } else if (evlistener !== undefined) { - return evlistener.length; - } - } + case "MMM": + return oneOf(loc.months("short", true, false), 1); - return 0; -} + case "MMMM": + return oneOf(loc.months("long", true, false), 1); -EventEmitter.prototype.eventNames = function eventNames() { - return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; -}; + case "L": + return intUnit(oneOrTwo); -function arrayClone(arr, n) { - var copy = new Array(n); - for (var i = 0; i < n; ++i) - copy[i] = arr[i]; - return copy; -} + case "LL": + return intUnit(two); -function spliceOne(list, index) { - for (; index + 1 < list.length; index++) - list[index] = list[index + 1]; - list.pop(); -} + case "LLL": + return oneOf(loc.months("short", false, false), 1); -function unwrapListeners(arr) { - var ret = new Array(arr.length); - for (var i = 0; i < ret.length; ++i) { - ret[i] = arr[i].listener || arr[i]; - } - return ret; -} + case "LLLL": + return oneOf(loc.months("long", false, false), 1); + // dates -function once(emitter, name) { - return new Promise(function (resolve, reject) { - function errorListener(err) { - emitter.removeListener(name, resolver); - reject(err); - } + case "d": + return intUnit(oneOrTwo); - function resolver() { - if (typeof emitter.removeListener === 'function') { - emitter.removeListener('error', errorListener); - } - resolve([].slice.call(arguments)); - }; + case "dd": + return intUnit(two); + // ordinals - eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); - if (name !== 'error') { - addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); - } - }); -} + case "o": + return intUnit(oneToThree); -function addErrorHandlerIfEventEmitter(emitter, handler, flags) { - if (typeof emitter.on === 'function') { - eventTargetAgnosticAddListener(emitter, 'error', handler, flags); - } -} + case "ooo": + return intUnit(three); + // time -function eventTargetAgnosticAddListener(emitter, name, listener, flags) { - if (typeof emitter.on === 'function') { - if (flags.once) { - emitter.once(name, listener); - } else { - emitter.on(name, listener); - } - } else if (typeof emitter.addEventListener === 'function') { - // EventTarget does not have `error` event semantics like Node - // EventEmitters, we do not listen for `error` events here. - emitter.addEventListener(name, function wrapListener(arg) { - // IE does not have builtin `{ once: true }` support so we - // have to do it manually. - if (flags.once) { - emitter.removeEventListener(name, wrapListener); - } - listener(arg); - }); - } else { - throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); - } -} + case "HH": + return intUnit(two); -},{}],196:[function(require,module,exports){ -'use strict'; + case "H": + return intUnit(oneOrTwo); -var isCallable = require('is-callable'); + case "hh": + return intUnit(two); -var toStr = Object.prototype.toString; -var hasOwnProperty = Object.prototype.hasOwnProperty; + case "h": + return intUnit(oneOrTwo); -var forEachArray = function forEachArray(array, iterator, receiver) { - for (var i = 0, len = array.length; i < len; i++) { - if (hasOwnProperty.call(array, i)) { - if (receiver == null) { - iterator(array[i], i, array); - } else { - iterator.call(receiver, array[i], i, array); - } - } - } -}; + case "mm": + return intUnit(two); -var forEachString = function forEachString(string, iterator, receiver) { - for (var i = 0, len = string.length; i < len; i++) { - // no such thing as a sparse string. - if (receiver == null) { - iterator(string.charAt(i), i, string); - } else { - iterator.call(receiver, string.charAt(i), i, string); - } - } -}; + case "m": + return intUnit(oneOrTwo); -var forEachObject = function forEachObject(object, iterator, receiver) { - for (var k in object) { - if (hasOwnProperty.call(object, k)) { - if (receiver == null) { - iterator(object[k], k, object); - } else { - iterator.call(receiver, object[k], k, object); - } - } - } -}; + case "q": + return intUnit(oneOrTwo); -var forEach = function forEach(list, iterator, thisArg) { - if (!isCallable(iterator)) { - throw new TypeError('iterator must be a function'); - } + case "qq": + return intUnit(two); - var receiver; - if (arguments.length >= 3) { - receiver = thisArg; - } + case "s": + return intUnit(oneOrTwo); - if (toStr.call(list) === '[object Array]') { - forEachArray(list, iterator, receiver); - } else if (typeof list === 'string') { - forEachString(list, iterator, receiver); - } else { - forEachObject(list, iterator, receiver); - } -}; + case "ss": + return intUnit(two); -module.exports = forEach; + case "S": + return intUnit(oneToThree); -},{"is-callable":218}],197:[function(require,module,exports){ -'use strict'; + case "SSS": + return intUnit(three); -/* eslint no-invalid-this: 1 */ + case "u": + return simple(oneToNine); + // meridiem -var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; -var slice = Array.prototype.slice; -var toStr = Object.prototype.toString; -var funcType = '[object Function]'; + case "a": + return oneOf(loc.meridiems(), 0); + // weekYear (k) -module.exports = function bind(that) { - var target = this; - if (typeof target !== 'function' || toStr.call(target) !== funcType) { - throw new TypeError(ERROR_MESSAGE + target); - } - var args = slice.call(arguments, 1); + case "kkkk": + return intUnit(four); - var bound; - var binder = function () { - if (this instanceof bound) { - var result = target.apply( - this, - args.concat(slice.call(arguments)) - ); - if (Object(result) === result) { - return result; - } - return this; - } else { - return target.apply( - that, - args.concat(slice.call(arguments)) - ); - } - }; + case "kk": + return intUnit(twoToFour, untruncateYear); + // weekNumber (W) - var boundLength = Math.max(0, target.length - args.length); - var boundArgs = []; - for (var i = 0; i < boundLength; i++) { - boundArgs.push('$' + i); - } + case "W": + return intUnit(oneOrTwo); - bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder); + case "WW": + return intUnit(two); + // weekdays - if (target.prototype) { - var Empty = function Empty() {}; - Empty.prototype = target.prototype; - bound.prototype = new Empty(); - Empty.prototype = null; - } + case "E": + case "c": + return intUnit(one); - return bound; -}; + case "EEE": + return oneOf(loc.weekdays("short", false, false), 1); -},{}],198:[function(require,module,exports){ -'use strict'; + case "EEEE": + return oneOf(loc.weekdays("long", false, false), 1); -var implementation = require('./implementation'); + case "ccc": + return oneOf(loc.weekdays("short", true, false), 1); -module.exports = Function.prototype.bind || implementation; + case "cccc": + return oneOf(loc.weekdays("long", true, false), 1); + // offset/zone -},{"./implementation":197}],199:[function(require,module,exports){ -'use strict'; + case "Z": + case "ZZ": + return offset(new RegExp("([+-]" + oneOrTwo.source + ")(?::(" + two.source + "))?"), 2); -var undefined; + case "ZZZ": + return offset(new RegExp("([+-]" + oneOrTwo.source + ")(" + two.source + ")?"), 2); + // we don't support ZZZZ (PST) or ZZZZZ (Pacific Standard Time) in parsing + // because we don't have any way to figure out what they are -var $SyntaxError = SyntaxError; -var $Function = Function; -var $TypeError = TypeError; + case "z": + return simple(/[a-z_+-/]{1,256}?/i); -// eslint-disable-next-line consistent-return -var getEvalledConstructor = function (expressionSyntax) { - try { - return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); - } catch (e) {} -}; + default: + return literal(t); + } + }; -var $gOPD = Object.getOwnPropertyDescriptor; -if ($gOPD) { - try { - $gOPD({}, ''); - } catch (e) { - $gOPD = null; // this is IE 8, which has a broken gOPD - } + var unit = unitate(token) || { + invalidReason: MISSING_FTP + }; + unit.token = token; + return unit; } -var throwTypeError = function () { - throw new $TypeError(); +var partTypeStyleToTokenVal = { + year: { + "2-digit": "yy", + numeric: "yyyyy" + }, + month: { + numeric: "M", + "2-digit": "MM", + short: "MMM", + long: "MMMM" + }, + day: { + numeric: "d", + "2-digit": "dd" + }, + weekday: { + short: "EEE", + long: "EEEE" + }, + dayperiod: "a", + dayPeriod: "a", + hour: { + numeric: "h", + "2-digit": "hh" + }, + minute: { + numeric: "m", + "2-digit": "mm" + }, + second: { + numeric: "s", + "2-digit": "ss" + } }; -var ThrowTypeError = $gOPD - ? (function () { - try { - // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties - arguments.callee; // IE 8 does not throw here - return throwTypeError; - } catch (calleeThrows) { - try { - // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') - return $gOPD(arguments, 'callee').get; - } catch (gOPDthrows) { - return throwTypeError; - } - } - }()) - : throwTypeError; - -var hasSymbols = require('has-symbols')(); -var hasProto = require('has-proto')(); - -var getProto = Object.getPrototypeOf || ( - hasProto - ? function (x) { return x.__proto__; } // eslint-disable-line no-proto - : null -); - -var needsEval = {}; - -var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined : getProto(Uint8Array); -var INTRINSICS = { - '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, - '%Array%': Array, - '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, - '%ArrayIteratorPrototype%': hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined, - '%AsyncFromSyncIteratorPrototype%': undefined, - '%AsyncFunction%': needsEval, - '%AsyncGenerator%': needsEval, - '%AsyncGeneratorFunction%': needsEval, - '%AsyncIteratorPrototype%': needsEval, - '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, - '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, - '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array, - '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array, - '%Boolean%': Boolean, - '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, - '%Date%': Date, - '%decodeURI%': decodeURI, - '%decodeURIComponent%': decodeURIComponent, - '%encodeURI%': encodeURI, - '%encodeURIComponent%': encodeURIComponent, - '%Error%': Error, - '%eval%': eval, // eslint-disable-line no-eval - '%EvalError%': EvalError, - '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, - '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, - '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, - '%Function%': $Function, - '%GeneratorFunction%': needsEval, - '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, - '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, - '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, - '%isFinite%': isFinite, - '%isNaN%': isNaN, - '%IteratorPrototype%': hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined, - '%JSON%': typeof JSON === 'object' ? JSON : undefined, - '%Map%': typeof Map === 'undefined' ? undefined : Map, - '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Map()[Symbol.iterator]()), - '%Math%': Math, - '%Number%': Number, - '%Object%': Object, - '%parseFloat%': parseFloat, - '%parseInt%': parseInt, - '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, - '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, - '%RangeError%': RangeError, - '%ReferenceError%': ReferenceError, - '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, - '%RegExp%': RegExp, - '%Set%': typeof Set === 'undefined' ? undefined : Set, - '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Set()[Symbol.iterator]()), - '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, - '%String%': String, - '%StringIteratorPrototype%': hasSymbols && getProto ? getProto(''[Symbol.iterator]()) : undefined, - '%Symbol%': hasSymbols ? Symbol : undefined, - '%SyntaxError%': $SyntaxError, - '%ThrowTypeError%': ThrowTypeError, - '%TypedArray%': TypedArray, - '%TypeError%': $TypeError, - '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, - '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, - '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, - '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, - '%URIError%': URIError, - '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, - '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, - '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet -}; +function tokenForPart(part, locale, formatOpts) { + var type = part.type, + value = part.value; -if (getProto) { - try { - null.error; // eslint-disable-line no-unused-expressions - } catch (e) { - // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 - var errorProto = getProto(getProto(e)); - INTRINSICS['%Error.prototype%'] = errorProto; - } -} + if (type === "literal") { + return { + literal: true, + val: value + }; + } -var doEval = function doEval(name) { - var value; - if (name === '%AsyncFunction%') { - value = getEvalledConstructor('async function () {}'); - } else if (name === '%GeneratorFunction%') { - value = getEvalledConstructor('function* () {}'); - } else if (name === '%AsyncGeneratorFunction%') { - value = getEvalledConstructor('async function* () {}'); - } else if (name === '%AsyncGenerator%') { - var fn = doEval('%AsyncGeneratorFunction%'); - if (fn) { - value = fn.prototype; - } - } else if (name === '%AsyncIteratorPrototype%') { - var gen = doEval('%AsyncGenerator%'); - if (gen && getProto) { - value = getProto(gen.prototype); - } - } + var style = formatOpts[type]; + var val = partTypeStyleToTokenVal[type]; - INTRINSICS[name] = value; + if (typeof val === "object") { + val = val[style]; + } - return value; -}; + if (val) { + return { + literal: false, + val: val + }; + } -var LEGACY_ALIASES = { - '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], - '%ArrayPrototype%': ['Array', 'prototype'], - '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], - '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], - '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], - '%ArrayProto_values%': ['Array', 'prototype', 'values'], - '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], - '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], - '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], - '%BooleanPrototype%': ['Boolean', 'prototype'], - '%DataViewPrototype%': ['DataView', 'prototype'], - '%DatePrototype%': ['Date', 'prototype'], - '%ErrorPrototype%': ['Error', 'prototype'], - '%EvalErrorPrototype%': ['EvalError', 'prototype'], - '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], - '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], - '%FunctionPrototype%': ['Function', 'prototype'], - '%Generator%': ['GeneratorFunction', 'prototype'], - '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], - '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], - '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], - '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], - '%JSONParse%': ['JSON', 'parse'], - '%JSONStringify%': ['JSON', 'stringify'], - '%MapPrototype%': ['Map', 'prototype'], - '%NumberPrototype%': ['Number', 'prototype'], - '%ObjectPrototype%': ['Object', 'prototype'], - '%ObjProto_toString%': ['Object', 'prototype', 'toString'], - '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], - '%PromisePrototype%': ['Promise', 'prototype'], - '%PromiseProto_then%': ['Promise', 'prototype', 'then'], - '%Promise_all%': ['Promise', 'all'], - '%Promise_reject%': ['Promise', 'reject'], - '%Promise_resolve%': ['Promise', 'resolve'], - '%RangeErrorPrototype%': ['RangeError', 'prototype'], - '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], - '%RegExpPrototype%': ['RegExp', 'prototype'], - '%SetPrototype%': ['Set', 'prototype'], - '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], - '%StringPrototype%': ['String', 'prototype'], - '%SymbolPrototype%': ['Symbol', 'prototype'], - '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], - '%TypedArrayPrototype%': ['TypedArray', 'prototype'], - '%TypeErrorPrototype%': ['TypeError', 'prototype'], - '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], - '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], - '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], - '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], - '%URIErrorPrototype%': ['URIError', 'prototype'], - '%WeakMapPrototype%': ['WeakMap', 'prototype'], - '%WeakSetPrototype%': ['WeakSet', 'prototype'] -}; + return undefined; +} -var bind = require('function-bind'); -var hasOwn = require('hasown'); -var $concat = bind.call(Function.call, Array.prototype.concat); -var $spliceApply = bind.call(Function.apply, Array.prototype.splice); -var $replace = bind.call(Function.call, String.prototype.replace); -var $strSlice = bind.call(Function.call, String.prototype.slice); -var $exec = bind.call(Function.call, RegExp.prototype.exec); +function buildRegex(units) { + var re = units.map(function (u) { + return u.regex; + }).reduce(function (f, r) { + return f + "(" + r.source + ")"; + }, ""); + return ["^" + re + "$", units]; +} -/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ -var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; -var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ -var stringToPath = function stringToPath(string) { - var first = $strSlice(string, 0, 1); - var last = $strSlice(string, -1); - if (first === '%' && last !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); - } else if (last === '%' && first !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); - } - var result = []; - $replace(string, rePropName, function (match, number, quote, subString) { - result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; - }); - return result; -}; -/* end adaptation */ +function match(input, regex, handlers) { + var matches = input.match(regex); -var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { - var intrinsicName = name; - var alias; - if (hasOwn(LEGACY_ALIASES, intrinsicName)) { - alias = LEGACY_ALIASES[intrinsicName]; - intrinsicName = '%' + alias[0] + '%'; - } + if (matches) { + var all = {}; + var matchIndex = 1; - if (hasOwn(INTRINSICS, intrinsicName)) { - var value = INTRINSICS[intrinsicName]; - if (value === needsEval) { - value = doEval(intrinsicName); - } - if (typeof value === 'undefined' && !allowMissing) { - throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); - } + for (var i in handlers) { + if (hasOwnProperty(handlers, i)) { + var h = handlers[i], + groups = h.groups ? h.groups + 1 : 1; - return { - alias: alias, - name: intrinsicName, - value: value - }; - } + if (!h.literal && h.token) { + all[h.token.val[0]] = h.deser(matches.slice(matchIndex, matchIndex + groups)); + } - throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); -}; + matchIndex += groups; + } + } -module.exports = function GetIntrinsic(name, allowMissing) { - if (typeof name !== 'string' || name.length === 0) { - throw new $TypeError('intrinsic name must be a non-empty string'); - } - if (arguments.length > 1 && typeof allowMissing !== 'boolean') { - throw new $TypeError('"allowMissing" argument must be a boolean'); - } + return [matches, all]; + } else { + return [matches, {}]; + } +} - if ($exec(/^%?[^%]*%?$/, name) === null) { - throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name'); - } - var parts = stringToPath(name); - var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; +function dateTimeFromMatches(matches) { + var toField = function toField(token) { + switch (token) { + case "S": + return "millisecond"; - var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); - var intrinsicRealName = intrinsic.name; - var value = intrinsic.value; - var skipFurtherCaching = false; + case "s": + return "second"; - var alias = intrinsic.alias; - if (alias) { - intrinsicBaseName = alias[0]; - $spliceApply(parts, $concat([0, 1], alias)); - } + case "m": + return "minute"; - for (var i = 1, isOwn = true; i < parts.length; i += 1) { - var part = parts[i]; - var first = $strSlice(part, 0, 1); - var last = $strSlice(part, -1); - if ( - ( - (first === '"' || first === "'" || first === '`') - || (last === '"' || last === "'" || last === '`') - ) - && first !== last - ) { - throw new $SyntaxError('property names with quotes must have matching quotes'); - } - if (part === 'constructor' || !isOwn) { - skipFurtherCaching = true; - } + case "h": + case "H": + return "hour"; - intrinsicBaseName += '.' + part; - intrinsicRealName = '%' + intrinsicBaseName + '%'; + case "d": + return "day"; - if (hasOwn(INTRINSICS, intrinsicRealName)) { - value = INTRINSICS[intrinsicRealName]; - } else if (value != null) { - if (!(part in value)) { - if (!allowMissing) { - throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.'); - } - return void undefined; - } - if ($gOPD && (i + 1) >= parts.length) { - var desc = $gOPD(value, part); - isOwn = !!desc; + case "o": + return "ordinal"; - // By convention, when a data property is converted to an accessor - // property to emulate a data property that does not suffer from - // the override mistake, that accessor's getter is marked with - // an `originalValue` property. Here, when we detect this, we - // uphold the illusion by pretending to see that original data - // property, i.e., returning the value rather than the getter - // itself. - if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { - value = desc.get; - } else { - value = value[part]; - } - } else { - isOwn = hasOwn(value, part); - value = value[part]; - } + case "L": + case "M": + return "month"; - if (isOwn && !skipFurtherCaching) { - INTRINSICS[intrinsicRealName] = value; - } - } - } - return value; -}; + case "y": + return "year"; -},{"function-bind":201,"has-proto":206,"has-symbols":207,"hasown":211}],200:[function(require,module,exports){ -'use strict'; + case "E": + case "c": + return "weekday"; -/* eslint no-invalid-this: 1 */ + case "W": + return "weekNumber"; -var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; -var toStr = Object.prototype.toString; -var max = Math.max; -var funcType = '[object Function]'; + case "k": + return "weekYear"; -var concatty = function concatty(a, b) { - var arr = []; + case "q": + return "quarter"; - for (var i = 0; i < a.length; i += 1) { - arr[i] = a[i]; - } - for (var j = 0; j < b.length; j += 1) { - arr[j + a.length] = b[j]; + default: + return null; } + }; - return arr; -}; + var zone; -var slicy = function slicy(arrLike, offset) { - var arr = []; - for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) { - arr[j] = arrLike[i]; - } - return arr; -}; + if (!isUndefined(matches.Z)) { + zone = new FixedOffsetZone(matches.Z); + } else if (!isUndefined(matches.z)) { + zone = IANAZone.create(matches.z); + } else { + zone = null; + } -var joiny = function (arr, joiner) { - var str = ''; - for (var i = 0; i < arr.length; i += 1) { - str += arr[i]; - if (i + 1 < arr.length) { - str += joiner; - } + if (!isUndefined(matches.q)) { + matches.M = (matches.q - 1) * 3 + 1; + } + + if (!isUndefined(matches.h)) { + if (matches.h < 12 && matches.a === 1) { + matches.h += 12; + } else if (matches.h === 12 && matches.a === 0) { + matches.h = 0; } - return str; -}; + } -module.exports = function bind(that) { - var target = this; - if (typeof target !== 'function' || toStr.apply(target) !== funcType) { - throw new TypeError(ERROR_MESSAGE + target); + if (matches.G === 0 && matches.y) { + matches.y = -matches.y; + } + + if (!isUndefined(matches.u)) { + matches.S = parseMillis(matches.u); + } + + var vals = Object.keys(matches).reduce(function (r, k) { + var f = toField(k); + + if (f) { + r[f] = matches[k]; } - var args = slicy(arguments, 1); - var bound; - var binder = function () { - if (this instanceof bound) { - var result = target.apply( - this, - concatty(args, arguments) - ); - if (Object(result) === result) { - return result; - } - return this; - } - return target.apply( - that, - concatty(args, arguments) - ); + return r; + }, {}); + return [vals, zone]; +} + +var dummyDateTimeCache = null; + +function getDummyDateTime() { + if (!dummyDateTimeCache) { + dummyDateTimeCache = DateTime.fromMillis(1555555555555); + } + + return dummyDateTimeCache; +} + +function maybeExpandMacroToken(token, locale) { + if (token.literal) { + return token; + } + + var formatOpts = Formatter.macroTokenToFormatOpts(token.val); + + if (!formatOpts) { + return token; + } + + var formatter = Formatter.create(locale, formatOpts); + var parts = formatter.formatDateTimeParts(getDummyDateTime()); + var tokens = parts.map(function (p) { + return tokenForPart(p, locale, formatOpts); + }); + + if (tokens.includes(undefined)) { + return token; + } + + return tokens; +} + +function expandMacroTokens(tokens, locale) { + var _Array$prototype; + + return (_Array$prototype = Array.prototype).concat.apply(_Array$prototype, tokens.map(function (t) { + return maybeExpandMacroToken(t, locale); + })); +} +/** + * @private + */ + +function explainFromTokens(locale, input, format) { + var tokens = expandMacroTokens(Formatter.parseFormat(format), locale), + units = tokens.map(function (t) { + return unitForToken(t, locale); + }), + disqualifyingUnit = units.find(function (t) { + return t.invalidReason; + }); + + if (disqualifyingUnit) { + return { + input: input, + tokens: tokens, + invalidReason: disqualifyingUnit.invalidReason }; + } else { + var _buildRegex = buildRegex(units), + regexString = _buildRegex[0], + handlers = _buildRegex[1], + regex = RegExp(regexString, "i"), + _match = match(input, regex, handlers), + rawMatches = _match[0], + matches = _match[1], + _ref6 = matches ? dateTimeFromMatches(matches) : [null, null], + result = _ref6[0], + zone = _ref6[1]; - var boundLength = max(0, target.length - args.length); - var boundArgs = []; - for (var i = 0; i < boundLength; i++) { - boundArgs[i] = '$' + i; + if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) { + throw new ConflictingSpecificationError("Can't include meridiem when specifying 24-hour format"); } - bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder); + return { + input: input, + tokens: tokens, + regex: regex, + rawMatches: rawMatches, + matches: matches, + result: result, + zone: zone + }; + } +} +function parseFromTokens(locale, input, format) { + var _explainFromTokens = explainFromTokens(locale, input, format), + result = _explainFromTokens.result, + zone = _explainFromTokens.zone, + invalidReason = _explainFromTokens.invalidReason; - if (target.prototype) { - var Empty = function Empty() {}; - Empty.prototype = target.prototype; - bound.prototype = new Empty(); - Empty.prototype = null; - } + return [result, zone, invalidReason]; +} - return bound; -}; +var nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], + leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]; -},{}],201:[function(require,module,exports){ -arguments[4][198][0].apply(exports,arguments) -},{"./implementation":200,"dup":198}],202:[function(require,module,exports){ -'use strict'; +function unitOutOfRange(unit, value) { + return new Invalid("unit out of range", "you specified " + value + " (of type " + typeof value + ") as a " + unit + ", which is invalid"); +} -var GetIntrinsic = require('get-intrinsic'); +function dayOfWeek(year, month, day) { + var js = new Date(Date.UTC(year, month - 1, day)).getUTCDay(); + return js === 0 ? 7 : js; +} -var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true); +function computeOrdinal(year, month, day) { + return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1]; +} -if ($gOPD) { - try { - $gOPD([], 'length'); - } catch (e) { - // IE 8 has a broken gOPD - $gOPD = null; - } +function uncomputeOrdinal(year, ordinal) { + var table = isLeapYear(year) ? leapLadder : nonLeapLadder, + month0 = table.findIndex(function (i) { + return i < ordinal; + }), + day = ordinal - table[month0]; + return { + month: month0 + 1, + day: day + }; } +/** + * @private + */ -module.exports = $gOPD; -},{"get-intrinsic":203}],203:[function(require,module,exports){ -arguments[4][52][0].apply(exports,arguments) -},{"dup":52,"function-bind":198,"has":210,"has-symbols":207}],204:[function(require,module,exports){ -'use strict'; +function gregorianToWeek(gregObj) { + var year = gregObj.year, + month = gregObj.month, + day = gregObj.day, + ordinal = computeOrdinal(year, month, day), + weekday = dayOfWeek(year, month, day); + var weekNumber = Math.floor((ordinal - weekday + 10) / 7), + weekYear; + + if (weekNumber < 1) { + weekYear = year - 1; + weekNumber = weeksInWeekYear(weekYear); + } else if (weekNumber > weeksInWeekYear(year)) { + weekYear = year + 1; + weekNumber = 1; + } else { + weekYear = year; + } + + return Object.assign({ + weekYear: weekYear, + weekNumber: weekNumber, + weekday: weekday + }, timeObject(gregObj)); +} +function weekToGregorian(weekData) { + var weekYear = weekData.weekYear, + weekNumber = weekData.weekNumber, + weekday = weekData.weekday, + weekdayOfJan4 = dayOfWeek(weekYear, 1, 4), + yearInDays = daysInYear(weekYear); + var ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 3, + year; + + if (ordinal < 1) { + year = weekYear - 1; + ordinal += daysInYear(year); + } else if (ordinal > yearInDays) { + year = weekYear + 1; + ordinal -= daysInYear(weekYear); + } else { + year = weekYear; + } -var GetIntrinsic = require('get-intrinsic'); + var _uncomputeOrdinal = uncomputeOrdinal(year, ordinal), + month = _uncomputeOrdinal.month, + day = _uncomputeOrdinal.day; -var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); + return Object.assign({ + year: year, + month: month, + day: day + }, timeObject(weekData)); +} +function gregorianToOrdinal(gregData) { + var year = gregData.year, + month = gregData.month, + day = gregData.day, + ordinal = computeOrdinal(year, month, day); + return Object.assign({ + year: year, + ordinal: ordinal + }, timeObject(gregData)); +} +function ordinalToGregorian(ordinalData) { + var year = ordinalData.year, + ordinal = ordinalData.ordinal, + _uncomputeOrdinal2 = uncomputeOrdinal(year, ordinal), + month = _uncomputeOrdinal2.month, + day = _uncomputeOrdinal2.day; -var hasPropertyDescriptors = function hasPropertyDescriptors() { - if ($defineProperty) { - try { - $defineProperty({}, 'a', { value: 1 }); - return true; - } catch (e) { - // IE 8 has a broken defineProperty - return false; - } - } - return false; -}; + return Object.assign({ + year: year, + month: month, + day: day + }, timeObject(ordinalData)); +} +function hasInvalidWeekData(obj) { + var validYear = isInteger(obj.weekYear), + validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)), + validWeekday = integerBetween(obj.weekday, 1, 7); -hasPropertyDescriptors.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() { - // node v0.6 has a bug where array lengths can be Set but not Defined - if (!hasPropertyDescriptors()) { - return null; - } - try { - return $defineProperty([], 'length', { value: 1 }).length !== 1; - } catch (e) { - // In Firefox 4-22, defining length on an array throws an exception. - return true; - } -}; + if (!validYear) { + return unitOutOfRange("weekYear", obj.weekYear); + } else if (!validWeek) { + return unitOutOfRange("week", obj.week); + } else if (!validWeekday) { + return unitOutOfRange("weekday", obj.weekday); + } else return false; +} +function hasInvalidOrdinalData(obj) { + var validYear = isInteger(obj.year), + validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year)); -module.exports = hasPropertyDescriptors; + if (!validYear) { + return unitOutOfRange("year", obj.year); + } else if (!validOrdinal) { + return unitOutOfRange("ordinal", obj.ordinal); + } else return false; +} +function hasInvalidGregorianData(obj) { + var validYear = isInteger(obj.year), + validMonth = integerBetween(obj.month, 1, 12), + validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month)); -},{"get-intrinsic":205}],205:[function(require,module,exports){ -arguments[4][52][0].apply(exports,arguments) -},{"dup":52,"function-bind":198,"has":210,"has-symbols":207}],206:[function(require,module,exports){ -'use strict'; + if (!validYear) { + return unitOutOfRange("year", obj.year); + } else if (!validMonth) { + return unitOutOfRange("month", obj.month); + } else if (!validDay) { + return unitOutOfRange("day", obj.day); + } else return false; +} +function hasInvalidTimeData(obj) { + var hour = obj.hour, + minute = obj.minute, + second = obj.second, + millisecond = obj.millisecond; + var validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0, + validMinute = integerBetween(minute, 0, 59), + validSecond = integerBetween(second, 0, 59), + validMillisecond = integerBetween(millisecond, 0, 999); -var test = { - foo: {} -}; + if (!validHour) { + return unitOutOfRange("hour", hour); + } else if (!validMinute) { + return unitOutOfRange("minute", minute); + } else if (!validSecond) { + return unitOutOfRange("second", second); + } else if (!validMillisecond) { + return unitOutOfRange("millisecond", millisecond); + } else return false; +} -var $Object = Object; +var INVALID$2 = "Invalid DateTime"; +var MAX_DATE = 8.64e15; -module.exports = function hasProto() { - return { __proto__: test }.foo === test.foo && !({ __proto__: null } instanceof $Object); -}; +function unsupportedZone(zone) { + return new Invalid("unsupported zone", "the zone \"" + zone.name + "\" is not supported"); +} // we cache week data on the DT object and this intermediates the cache -},{}],207:[function(require,module,exports){ -'use strict'; -var origSymbol = typeof Symbol !== 'undefined' && Symbol; -var hasSymbolSham = require('./shams'); +function possiblyCachedWeekData(dt) { + if (dt.weekData === null) { + dt.weekData = gregorianToWeek(dt.c); + } -module.exports = function hasNativeSymbols() { - if (typeof origSymbol !== 'function') { return false; } - if (typeof Symbol !== 'function') { return false; } - if (typeof origSymbol('foo') !== 'symbol') { return false; } - if (typeof Symbol('bar') !== 'symbol') { return false; } + return dt.weekData; +} // clone really means, "make a new object with these modifications". all "setters" really use this +// to create a new object while only changing some of the properties - return hasSymbolSham(); -}; -},{"./shams":208}],208:[function(require,module,exports){ -'use strict'; +function clone$1(inst, alts) { + var current = { + ts: inst.ts, + zone: inst.zone, + c: inst.c, + o: inst.o, + loc: inst.loc, + invalid: inst.invalid + }; + return new DateTime(Object.assign({}, current, alts, { + old: current + })); +} // find the right offset a given local time. The o input is our guess, which determines which +// offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST) -/* eslint complexity: [2, 18], max-statements: [2, 33] */ -module.exports = function hasSymbols() { - if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; } - if (typeof Symbol.iterator === 'symbol') { return true; } - var obj = {}; - var sym = Symbol('test'); - var symObj = Object(sym); - if (typeof sym === 'string') { return false; } +function fixOffset(localTS, o, tz) { + // Our UTC time is just a guess because our offset is just a guess + var utcGuess = localTS - o * 60 * 1000; // Test whether the zone matches the offset for this ts - if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; } - if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; } + var o2 = tz.offset(utcGuess); // If so, offset didn't change and we're done - // temp disabled per https://github.com/ljharb/object.assign/issues/17 - // if (sym instanceof Symbol) { return false; } - // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 - // if (!(symObj instanceof Symbol)) { return false; } + if (o === o2) { + return [utcGuess, o]; + } // If not, change the ts by the difference in the offset - // if (typeof Symbol.prototype.toString !== 'function') { return false; } - // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } - var symVal = 42; - obj[sym] = symVal; - for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop - if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; } + utcGuess -= (o2 - o) * 60 * 1000; // If that gives us the local time we want, we're done - if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; } + var o3 = tz.offset(utcGuess); - var syms = Object.getOwnPropertySymbols(obj); - if (syms.length !== 1 || syms[0] !== sym) { return false; } + if (o2 === o3) { + return [utcGuess, o2]; + } // If it's different, we're in a hole time. The offset has changed, but the we don't adjust the time - if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; } - if (typeof Object.getOwnPropertyDescriptor === 'function') { - var descriptor = Object.getOwnPropertyDescriptor(obj, sym); - if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; } - } + return [localTS - Math.min(o2, o3) * 60 * 1000, Math.max(o2, o3)]; +} // convert an epoch timestamp into a calendar object with the given offset - return true; -}; -},{}],209:[function(require,module,exports){ -'use strict'; +function tsToObj(ts, offset) { + ts += offset * 60 * 1000; + var d = new Date(ts); + return { + year: d.getUTCFullYear(), + month: d.getUTCMonth() + 1, + day: d.getUTCDate(), + hour: d.getUTCHours(), + minute: d.getUTCMinutes(), + second: d.getUTCSeconds(), + millisecond: d.getUTCMilliseconds() + }; +} // convert a calendar object to a epoch timestamp -var hasSymbols = require('has-symbols/shams'); -module.exports = function hasToStringTagShams() { - return hasSymbols() && !!Symbol.toStringTag; -}; +function objToTS(obj, offset, zone) { + return fixOffset(objToLocalTS(obj), offset, zone); +} // create a new DT instance by adding a duration, adjusting for DSTs -},{"has-symbols/shams":208}],210:[function(require,module,exports){ -'use strict'; -var bind = require('function-bind'); +function adjustTime(inst, dur) { + var oPre = inst.o, + year = inst.c.year + Math.trunc(dur.years), + month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3, + c = Object.assign({}, inst.c, { + year: year, + month: month, + day: Math.min(inst.c.day, daysInMonth(year, month)) + Math.trunc(dur.days) + Math.trunc(dur.weeks) * 7 + }), + millisToAdd = Duration.fromObject({ + years: dur.years - Math.trunc(dur.years), + quarters: dur.quarters - Math.trunc(dur.quarters), + months: dur.months - Math.trunc(dur.months), + weeks: dur.weeks - Math.trunc(dur.weeks), + days: dur.days - Math.trunc(dur.days), + hours: dur.hours, + minutes: dur.minutes, + seconds: dur.seconds, + milliseconds: dur.milliseconds + }).as("milliseconds"), + localTS = objToLocalTS(c); -module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty); + var _fixOffset = fixOffset(localTS, oPre, inst.zone), + ts = _fixOffset[0], + o = _fixOffset[1]; -},{"function-bind":198}],211:[function(require,module,exports){ -'use strict'; + if (millisToAdd !== 0) { + ts += millisToAdd; // that could have changed the offset by going over a DST, but we want to keep the ts the same -var call = Function.prototype.call; -var $hasOwn = Object.prototype.hasOwnProperty; -var bind = require('function-bind'); + o = inst.zone.offset(ts); + } -/** @type {(o: {}, p: PropertyKey) => p is keyof o} */ -module.exports = bind.call(call, $hasOwn); + return { + ts: ts, + o: o + }; +} // helper useful in turning the results of parsing into real dates +// by handling the zone options -},{"function-bind":213}],212:[function(require,module,exports){ -arguments[4][200][0].apply(exports,arguments) -},{"dup":200}],213:[function(require,module,exports){ -arguments[4][198][0].apply(exports,arguments) -},{"./implementation":212,"dup":198}],214:[function(require,module,exports){ -/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ -exports.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var nBits = -7 - var i = isLE ? (nBytes - 1) : 0 - var d = isLE ? -1 : 1 - var s = buffer[offset + i] - i += d +function parseDataToDateTime(parsed, parsedZone, opts, format, text) { + var setZone = opts.setZone, + zone = opts.zone; - e = s & ((1 << (-nBits)) - 1) - s >>= (-nBits) - nBits += eLen - for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} + if (parsed && Object.keys(parsed).length !== 0) { + var interpretationZone = parsedZone || zone, + inst = DateTime.fromObject(Object.assign(parsed, opts, { + zone: interpretationZone, + // setZone is a valid option in the calling methods, but not in fromObject + setZone: undefined + })); + return setZone ? inst : inst.setZone(zone); + } else { + return DateTime.invalid(new Invalid("unparsable", "the input \"" + text + "\" can't be parsed as " + format)); + } +} // if you want to output a technical format (e.g. RFC 2822), this helper +// helps handle the details - m = e & ((1 << (-nBits)) - 1) - e >>= (-nBits) - nBits += mLen - for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} - if (e === 0) { - e = 1 - eBias - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen) - e = e - eBias +function toTechFormat(dt, format, allowZ) { + if (allowZ === void 0) { + allowZ = true; } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) -} -exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) - var i = isLE ? 0 : (nBytes - 1) - var d = isLE ? 1 : -1 - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + return dt.isValid ? Formatter.create(Locale.create("en-US"), { + allowZ: allowZ, + forceSimple: true + }).formatDateTimeFromString(dt, format) : null; +} // technical time formats (e.g. the time part of ISO 8601), take some options +// and this commonizes their handling - value = Math.abs(value) - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0 - e = eMax - } else { - e = Math.floor(Math.log(value) / Math.LN2) - if (value * (c = Math.pow(2, -e)) < 1) { - e-- - c *= 2 - } - if (e + eBias >= 1) { - value += rt / c - } else { - value += rt * Math.pow(2, 1 - eBias) - } - if (value * c >= 2) { - e++ - c /= 2 - } +function toTechTimeFormat(dt, _ref) { + var _ref$suppressSeconds = _ref.suppressSeconds, + suppressSeconds = _ref$suppressSeconds === void 0 ? false : _ref$suppressSeconds, + _ref$suppressMillisec = _ref.suppressMilliseconds, + suppressMilliseconds = _ref$suppressMillisec === void 0 ? false : _ref$suppressMillisec, + includeOffset = _ref.includeOffset, + _ref$includePrefix = _ref.includePrefix, + includePrefix = _ref$includePrefix === void 0 ? false : _ref$includePrefix, + _ref$includeZone = _ref.includeZone, + includeZone = _ref$includeZone === void 0 ? false : _ref$includeZone, + _ref$spaceZone = _ref.spaceZone, + spaceZone = _ref$spaceZone === void 0 ? false : _ref$spaceZone, + _ref$format = _ref.format, + format = _ref$format === void 0 ? "extended" : _ref$format; + var fmt = format === "basic" ? "HHmm" : "HH:mm"; - if (e + eBias >= eMax) { - m = 0 - e = eMax - } else if (e + eBias >= 1) { - m = ((value * c) - 1) * Math.pow(2, mLen) - e = e + eBias - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) - e = 0 + if (!suppressSeconds || dt.second !== 0 || dt.millisecond !== 0) { + fmt += format === "basic" ? "ss" : ":ss"; + + if (!suppressMilliseconds || dt.millisecond !== 0) { + fmt += ".SSS"; } } - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + if ((includeZone || includeOffset) && spaceZone) { + fmt += " "; + } - e = (e << mLen) | m - eLen += mLen - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + if (includeZone) { + fmt += "z"; + } else if (includeOffset) { + fmt += format === "basic" ? "ZZZ" : "ZZ"; + } - buffer[offset + i - d] |= s * 128 -} + var str = toTechFormat(dt, fmt); -},{}],215:[function(require,module,exports){ -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }) - } - }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } + if (includePrefix) { + str = "T" + str; } -} -},{}],216:[function(require,module,exports){ -'use strict'; + return str; +} // defaults for unspecified units in the supported calendars -var hasToStringTag = require('has-tostringtag/shams')(); -var callBound = require('call-bind/callBound'); -var $toString = callBound('Object.prototype.toString'); +var defaultUnitValues = { + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0 +}, + defaultWeekUnitValues = { + weekNumber: 1, + weekday: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0 +}, + defaultOrdinalUnitValues = { + ordinal: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0 +}; // Units in the supported calendars, sorted by bigness -var isStandardArguments = function isArguments(value) { - if (hasToStringTag && value && typeof value === 'object' && Symbol.toStringTag in value) { - return false; - } - return $toString(value) === '[object Arguments]'; -}; +var orderedUnits$1 = ["year", "month", "day", "hour", "minute", "second", "millisecond"], + orderedWeekUnits = ["weekYear", "weekNumber", "weekday", "hour", "minute", "second", "millisecond"], + orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"]; // standardize case and plurality in units -var isLegacyArguments = function isArguments(value) { - if (isStandardArguments(value)) { - return true; - } - return value !== null && - typeof value === 'object' && - typeof value.length === 'number' && - value.length >= 0 && - $toString(value) !== '[object Array]' && - $toString(value.callee) === '[object Function]'; -}; +function normalizeUnit(unit) { + var normalized = { + year: "year", + years: "year", + month: "month", + months: "month", + day: "day", + days: "day", + hour: "hour", + hours: "hour", + minute: "minute", + minutes: "minute", + quarter: "quarter", + quarters: "quarter", + second: "second", + seconds: "second", + millisecond: "millisecond", + milliseconds: "millisecond", + weekday: "weekday", + weekdays: "weekday", + weeknumber: "weekNumber", + weeksnumber: "weekNumber", + weeknumbers: "weekNumber", + weekyear: "weekYear", + weekyears: "weekYear", + ordinal: "ordinal" + }[unit.toLowerCase()]; + if (!normalized) throw new InvalidUnitError(unit); + return normalized; +} // this is a dumbed down version of fromObject() that runs about 60% faster +// but doesn't do any validation, makes a bunch of assumptions about what units +// are present, and so on. + + +function quickDT(obj, zone) { + // assume we have the higher-order units + for (var _iterator = _createForOfIteratorHelperLoose(orderedUnits$1), _step; !(_step = _iterator()).done;) { + var u = _step.value; -var supportsStandardArguments = (function () { - return isStandardArguments(arguments); -}()); + if (isUndefined(obj[u])) { + obj[u] = defaultUnitValues[u]; + } + } -isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests + var invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj); -module.exports = supportsStandardArguments ? isStandardArguments : isLegacyArguments; + if (invalid) { + return DateTime.invalid(invalid); + } -},{"call-bind/callBound":50,"has-tostringtag/shams":209}],217:[function(require,module,exports){ -/*! - * Determine if an object is a Buffer - * - * @author Feross Aboukhadijeh - * @license MIT - */ + var tsNow = Settings.now(), + offsetProvis = zone.offset(tsNow), + _objToTS = objToTS(obj, offsetProvis, zone), + ts = _objToTS[0], + o = _objToTS[1]; -// The _isBuffer check is for Safari 5-7 support, because it's missing -// Object.prototype.constructor. Remove this eventually -module.exports = function (obj) { - return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) + return new DateTime({ + ts: ts, + zone: zone, + o: o + }); } -function isBuffer (obj) { - return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) -} +function diffRelative(start, end, opts) { + var round = isUndefined(opts.round) ? true : opts.round, + format = function format(c, unit) { + c = roundTo(c, round || opts.calendary ? 0 : 2, true); + var formatter = end.loc.clone(opts).relFormatter(opts); + return formatter.format(c, unit); + }, + differ = function differ(unit) { + if (opts.calendary) { + if (!end.hasSame(start, unit)) { + return end.startOf(unit).diff(start.startOf(unit), unit).get(unit); + } else return 0; + } else { + return end.diff(start, unit).get(unit); + } + }; -// For Node v0.10 support. Remove this eventually. -function isSlowBuffer (obj) { - return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) -} + if (opts.unit) { + return format(differ(opts.unit), opts.unit); + } -},{}],218:[function(require,module,exports){ -'use strict'; + for (var _iterator2 = _createForOfIteratorHelperLoose(opts.units), _step2; !(_step2 = _iterator2()).done;) { + var unit = _step2.value; + var count = differ(unit); -var fnToStr = Function.prototype.toString; -var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply; -var badArrayLike; -var isCallableMarker; -if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') { - try { - badArrayLike = Object.defineProperty({}, 'length', { - get: function () { - throw isCallableMarker; - } - }); - isCallableMarker = {}; - // eslint-disable-next-line no-throw-literal - reflectApply(function () { throw 42; }, null, badArrayLike); - } catch (_) { - if (_ !== isCallableMarker) { - reflectApply = null; - } - } -} else { - reflectApply = null; + if (Math.abs(count) >= 1) { + return format(count, unit); + } + } + + return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]); } +/** + * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them. + * + * A DateTime comprises of: + * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch. + * * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone). + * * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`. + * + * Here is a brief overview of the most commonly used functionality it provides: + * + * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link local}, {@link utc}, and (most flexibly) {@link fromObject}. To create one from a standard string format, use {@link fromISO}, {@link fromHTTP}, and {@link fromRFC2822}. To create one from a custom string format, use {@link fromFormat}. To create one from a native JS date, use {@link fromJSDate}. + * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e as opposed to collectively through {@link toObject}), use the {@link year}, {@link month}, + * {@link day}, {@link hour}, {@link minute}, {@link second}, {@link millisecond} accessors. + * * **Week calendar**: For ISO week calendar attributes, see the {@link weekYear}, {@link weekNumber}, and {@link weekday} accessors. + * * **Configuration** See the {@link locale} and {@link numberingSystem} accessors. + * * **Transformation**: To transform the DateTime into other DateTimes, use {@link set}, {@link reconfigure}, {@link setZone}, {@link setLocale}, {@link plus}, {@link minus}, {@link endOf}, {@link startOf}, {@link toUTC}, and {@link toLocal}. + * * **Output**: To convert the DateTime to other representations, use the {@link toRelative}, {@link toRelativeCalendar}, {@link toJSON}, {@link toISO}, {@link toHTTP}, {@link toObject}, {@link toRFC2822}, {@link toString}, {@link toLocaleString}, {@link toFormat}, {@link toMillis} and {@link toJSDate}. + * + * There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation. + */ -var constructorRegex = /^\s*class\b/; -var isES6ClassFn = function isES6ClassFunction(value) { - try { - var fnStr = fnToStr.call(value); - return constructorRegex.test(fnStr); - } catch (e) { - return false; // not a function - } -}; -var tryFunctionObject = function tryFunctionToStr(value) { - try { - if (isES6ClassFn(value)) { return false; } - fnToStr.call(value); - return true; - } catch (e) { - return false; - } -}; -var toStr = Object.prototype.toString; -var objectClass = '[object Object]'; -var fnClass = '[object Function]'; -var genClass = '[object GeneratorFunction]'; -var ddaClass = '[object HTMLAllCollection]'; // IE 11 -var ddaClass2 = '[object HTML document.all class]'; -var ddaClass3 = '[object HTMLCollection]'; // IE 9-10 -var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag` +var DateTime = /*#__PURE__*/function () { + /** + * @access private + */ + function DateTime(config) { + var zone = config.zone || Settings.defaultZone; + var invalid = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (!zone.isValid ? unsupportedZone(zone) : null); + /** + * @access private + */ -var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing + this.ts = isUndefined(config.ts) ? Settings.now() : config.ts; + var c = null, + o = null; -var isDDA = function isDocumentDotAll() { return false; }; -if (typeof document === 'object') { - // Firefox 3 canonicalizes DDA to undefined when it's not accessed directly - var all = document.all; - if (toStr.call(all) === toStr.call(document.all)) { - isDDA = function isDocumentDotAll(value) { - /* globals document: false */ - // in IE 6-8, typeof document.all is "object" and it's truthy - if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) { - try { - var str = toStr.call(value); - return ( - str === ddaClass - || str === ddaClass2 - || str === ddaClass3 // opera 12.16 - || str === objectClass // IE 6-8 - ) && value('') == null; // eslint-disable-line eqeqeq - } catch (e) { /**/ } - } - return false; - }; - } -} + if (!invalid) { + var unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone); -module.exports = reflectApply - ? function isCallable(value) { - if (isDDA(value)) { return true; } - if (!value) { return false; } - if (typeof value !== 'function' && typeof value !== 'object') { return false; } - try { - reflectApply(value, null, badArrayLike); - } catch (e) { - if (e !== isCallableMarker) { return false; } - } - return !isES6ClassFn(value) && tryFunctionObject(value); - } - : function isCallable(value) { - if (isDDA(value)) { return true; } - if (!value) { return false; } - if (typeof value !== 'function' && typeof value !== 'object') { return false; } - if (hasToStringTag) { return tryFunctionObject(value); } - if (isES6ClassFn(value)) { return false; } - var strClass = toStr.call(value); - if (strClass !== fnClass && strClass !== genClass && !(/^\[object HTML/).test(strClass)) { return false; } - return tryFunctionObject(value); - }; + if (unchanged) { + var _ref2 = [config.old.c, config.old.o]; + c = _ref2[0]; + o = _ref2[1]; + } else { + var ot = zone.offset(this.ts); + c = tsToObj(this.ts, ot); + invalid = Number.isNaN(c.year) ? new Invalid("invalid input") : null; + c = invalid ? null : c; + o = invalid ? null : ot; + } + } + /** + * @access private + */ -},{}],219:[function(require,module,exports){ -'use strict'; -module.exports = Number.isFinite || function (value) { - return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity); -}; + this._zone = zone; + /** + * @access private + */ -},{}],220:[function(require,module,exports){ -'use strict'; + this.loc = config.loc || Locale.create(); + /** + * @access private + */ -var toStr = Object.prototype.toString; -var fnToStr = Function.prototype.toString; -var isFnRegex = /^\s*(?:function)?\*/; -var hasToStringTag = require('has-tostringtag/shams')(); -var getProto = Object.getPrototypeOf; -var getGeneratorFunc = function () { // eslint-disable-line consistent-return - if (!hasToStringTag) { - return false; - } - try { - return Function('return function*() {}')(); - } catch (e) { - } -}; -var GeneratorFunction; + this.invalid = invalid; + /** + * @access private + */ -module.exports = function isGeneratorFunction(fn) { - if (typeof fn !== 'function') { - return false; - } - if (isFnRegex.test(fnToStr.call(fn))) { - return true; - } - if (!hasToStringTag) { - var str = toStr.call(fn); - return str === '[object GeneratorFunction]'; - } - if (!getProto) { - return false; - } - if (typeof GeneratorFunction === 'undefined') { - var generatorFunc = getGeneratorFunc(); - GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false; - } - return getProto(fn) === GeneratorFunction; -}; + this.weekData = null; + /** + * @access private + */ -},{"has-tostringtag/shams":209}],221:[function(require,module,exports){ -// https://github.com/paulmillr/es6-shim -// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger -var isFinite = require("is-finite"); -module.exports = Number.isInteger || function(val) { - return typeof val === "number" && - isFinite(val) && - Math.floor(val) === val; -}; + this.c = c; + /** + * @access private + */ -},{"is-finite":219}],222:[function(require,module,exports){ -(function (process){(function (){ -'use strict'; + this.o = o; + /** + * @access private + */ -function Kareem() { - this._pres = new Map(); - this._posts = new Map(); -} + this.isLuxonDateTime = true; + } // CONSTRUCT -Kareem.prototype.execPre = function(name, context, args, callback) { - if (arguments.length === 3) { - callback = args; - args = []; + /** + * Create a DateTime for the current instant, in the system's time zone. + * + * Use Settings to override these default values if needed. + * @example DateTime.now().toISO() //~> now in the ISO format + * @return {DateTime} + */ + + + DateTime.now = function now() { + return new DateTime({}); } - var pres = get(this._pres, name, []); - var numPres = pres.length; - var numAsyncPres = pres.numAsync || 0; - var currentPre = 0; - var asyncPresLeft = numAsyncPres; - var done = false; - var $args = args; + /** + * Create a local DateTime + * @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used + * @param {number} [month=1] - The month, 1-indexed + * @param {number} [day=1] - The day of the month, 1-indexed + * @param {number} [hour=0] - The hour of the day, in 24-hour time + * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59 + * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59 + * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999 + * @example DateTime.local() //~> now + * @example DateTime.local(2017) //~> 2017-01-01T00:00:00 + * @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00 + * @example DateTime.local(2017, 3, 12) //~> 2017-03-12T00:00:00 + * @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00 + * @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00 + * @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10 + * @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765 + * @return {DateTime} + */ + ; - if (!numPres) { - return process.nextTick(function() { - callback(null); - }); + DateTime.local = function local(year, month, day, hour, minute, second, millisecond) { + if (isUndefined(year)) { + return DateTime.now(); + } else { + return quickDT({ + year: year, + month: month, + day: day, + hour: hour, + minute: minute, + second: second, + millisecond: millisecond + }, Settings.defaultZone); + } } + /** + * Create a DateTime in UTC + * @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used + * @param {number} [month=1] - The month, 1-indexed + * @param {number} [day=1] - The day of the month + * @param {number} [hour=0] - The hour of the day, in 24-hour time + * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59 + * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59 + * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999 + * @example DateTime.utc() //~> now + * @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z + * @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z + * @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z + * @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z + * @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z + * @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z + * @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765Z + * @return {DateTime} + */ + ; - var next = function() { - if (currentPre >= numPres) { - return; + DateTime.utc = function utc(year, month, day, hour, minute, second, millisecond) { + if (isUndefined(year)) { + return new DateTime({ + ts: Settings.now(), + zone: FixedOffsetZone.utcInstance + }); + } else { + return quickDT({ + year: year, + month: month, + day: day, + hour: hour, + minute: minute, + second: second, + millisecond: millisecond + }, FixedOffsetZone.utcInstance); } - var pre = pres[currentPre]; + } + /** + * Create a DateTime from a JavaScript Date object. Uses the default zone. + * @param {Date} date - a JavaScript Date object + * @param {Object} options - configuration options for the DateTime + * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into + * @return {DateTime} + */ + ; - if (pre.isAsync) { - var args = [ - decorateNextFn(_next), - decorateNextFn(function(error) { - if (error) { - if (done) { - return; - } - done = true; - return callback(error); - } - if (--asyncPresLeft === 0 && currentPre >= numPres) { - return callback(null); - } - }) - ]; + DateTime.fromJSDate = function fromJSDate(date, options) { + if (options === void 0) { + options = {}; + } - callMiddlewareFunction(pre.fn, context, args, args[0]); - } else if (pre.fn.length > 0) { - var args = [decorateNextFn(_next)]; - var _args = arguments.length >= 2 ? arguments : [null].concat($args); - for (var i = 1; i < _args.length; ++i) { - args.push(_args[i]); - } + var ts = isDate(date) ? date.valueOf() : NaN; - callMiddlewareFunction(pre.fn, context, args, args[0]); - } else { - let maybePromise = null; - try { - maybePromise = pre.fn.call(context); - } catch (err) { - if (err != null) { - return callback(err); - } - } + if (Number.isNaN(ts)) { + return DateTime.invalid("invalid input"); + } - if (isPromise(maybePromise)) { - maybePromise.then(() => _next(), err => _next(err)); - } else { - if (++currentPre >= numPres) { - if (asyncPresLeft > 0) { - // Leave parallel hooks to run - return; - } else { - return process.nextTick(function() { - callback(null); - }); - } - } - next(); - } + var zoneToUse = normalizeZone(options.zone, Settings.defaultZone); + + if (!zoneToUse.isValid) { + return DateTime.invalid(unsupportedZone(zoneToUse)); } - }; - next.apply(null, [null].concat(args)); + return new DateTime({ + ts: ts, + zone: zoneToUse, + loc: Locale.fromObject(options) + }); + } + /** + * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone. + * @param {number} milliseconds - a number of milliseconds since 1970 UTC + * @param {Object} options - configuration options for the DateTime + * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into + * @param {string} [options.locale] - a locale to set on the resulting DateTime instance + * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance + * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance + * @return {DateTime} + */ + ; - function _next(error) { - if (error) { - if (done) { - return; - } - done = true; - return callback(error); + DateTime.fromMillis = function fromMillis(milliseconds, options) { + if (options === void 0) { + options = {}; } - if (++currentPre >= numPres) { - if (asyncPresLeft > 0) { - // Leave parallel hooks to run - return; - } else { - return callback(null); - } + if (!isNumber(milliseconds)) { + throw new InvalidArgumentError("fromMillis requires a numerical input, but received a " + typeof milliseconds + " with value " + milliseconds); + } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) { + // this isn't perfect because because we can still end up out of range because of additional shifting, but it's a start + return DateTime.invalid("Timestamp out of range"); + } else { + return new DateTime({ + ts: milliseconds, + zone: normalizeZone(options.zone, Settings.defaultZone), + loc: Locale.fromObject(options) + }); } - - next.apply(context, arguments); } -}; + /** + * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone. + * @param {number} seconds - a number of seconds since 1970 UTC + * @param {Object} options - configuration options for the DateTime + * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into + * @param {string} [options.locale] - a locale to set on the resulting DateTime instance + * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance + * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance + * @return {DateTime} + */ + ; -Kareem.prototype.execPreSync = function(name, context, args) { - var pres = get(this._pres, name, []); - var numPres = pres.length; + DateTime.fromSeconds = function fromSeconds(seconds, options) { + if (options === void 0) { + options = {}; + } - for (var i = 0; i < numPres; ++i) { - pres[i].fn.apply(context, args || []); + if (!isNumber(seconds)) { + throw new InvalidArgumentError("fromSeconds requires a numerical input"); + } else { + return new DateTime({ + ts: seconds * 1000, + zone: normalizeZone(options.zone, Settings.defaultZone), + loc: Locale.fromObject(options) + }); + } } -}; + /** + * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults. + * @param {Object} obj - the object to create the DateTime from + * @param {number} obj.year - a year, such as 1987 + * @param {number} obj.month - a month, 1-12 + * @param {number} obj.day - a day of the month, 1-31, depending on the month + * @param {number} obj.ordinal - day of the year, 1-365 or 366 + * @param {number} obj.weekYear - an ISO week year + * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year + * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday + * @param {number} obj.hour - hour of the day, 0-23 + * @param {number} obj.minute - minute of the hour, 0-59 + * @param {number} obj.second - second of the minute, 0-59 + * @param {number} obj.millisecond - millisecond of the second, 0-999 + * @param {string|Zone} [obj.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone() + * @param {string} [obj.locale='system's locale'] - a locale to set on the resulting DateTime instance + * @param {string} obj.outputCalendar - the output calendar to set on the resulting DateTime instance + * @param {string} obj.numberingSystem - the numbering system to set on the resulting DateTime instance + * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25' + * @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01' + * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06 + * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'utc' }), + * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'local' }) + * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'America/New_York' }) + * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13' + * @return {DateTime} + */ + ; -Kareem.prototype.execPost = function(name, context, args, options, callback) { - if (arguments.length < 5) { - callback = options; - options = null; - } - var posts = get(this._posts, name, []); - var numPosts = posts.length; - var currentPost = 0; + DateTime.fromObject = function fromObject(obj) { + var zoneToUse = normalizeZone(obj.zone, Settings.defaultZone); - var firstError = null; - if (options && options.error) { - firstError = options.error; - } + if (!zoneToUse.isValid) { + return DateTime.invalid(unsupportedZone(zoneToUse)); + } - if (!numPosts) { - return process.nextTick(function() { - callback.apply(null, [firstError].concat(args)); - }); - } + var tsNow = Settings.now(), + offsetProvis = zoneToUse.offset(tsNow), + normalized = normalizeObject(obj, normalizeUnit, ["zone", "locale", "outputCalendar", "numberingSystem"]), + containsOrdinal = !isUndefined(normalized.ordinal), + containsGregorYear = !isUndefined(normalized.year), + containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day), + containsGregor = containsGregorYear || containsGregorMD, + definiteWeekDef = normalized.weekYear || normalized.weekNumber, + loc = Locale.fromObject(obj); // cases: + // just a weekday -> this week's instance of that weekday, no worries + // (gregorian data or ordinal) + (weekYear or weekNumber) -> error + // (gregorian month or day) + ordinal -> error + // otherwise just use weeks or ordinals or gregorian, depending on what's specified - var next = function() { - var post = posts[currentPost].fn; - var numArgs = 0; - var argLength = args.length; - var newArgs = []; - for (var i = 0; i < argLength; ++i) { - numArgs += args[i] && args[i]._kareemIgnore ? 0 : 1; - if (!args[i] || !args[i]._kareemIgnore) { - newArgs.push(args[i]); - } + if ((containsGregor || containsOrdinal) && definiteWeekDef) { + throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals"); } - if (firstError) { - if (post.length === numArgs + 2) { - var _cb = decorateNextFn(function(error) { - if (error) { - firstError = error; - } - if (++currentPost >= numPosts) { - return callback.call(null, firstError); - } - next(); - }); + if (containsGregorMD && containsOrdinal) { + throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day"); + } - callMiddlewareFunction(post, context, - [firstError].concat(newArgs).concat([_cb]), _cb); - } else { - if (++currentPost >= numPosts) { - return callback.call(null, firstError); - } - next(); - } - } else { - const _cb = decorateNextFn(function(error) { - if (error) { - firstError = error; - return next(); - } + var useWeekData = definiteWeekDef || normalized.weekday && !containsGregor; // configure ourselves to deal with gregorian dates or week stuff - if (++currentPost >= numPosts) { - return callback.apply(null, [null].concat(args)); - } + var units, + defaultValues, + objNow = tsToObj(tsNow, offsetProvis); - next(); - }); + if (useWeekData) { + units = orderedWeekUnits; + defaultValues = defaultWeekUnitValues; + objNow = gregorianToWeek(objNow); + } else if (containsOrdinal) { + units = orderedOrdinalUnits; + defaultValues = defaultOrdinalUnitValues; + objNow = gregorianToOrdinal(objNow); + } else { + units = orderedUnits$1; + defaultValues = defaultUnitValues; + } // set default values for missing stuff - if (post.length === numArgs + 2) { - // Skip error handlers if no error - if (++currentPost >= numPosts) { - return callback.apply(null, [null].concat(args)); - } - return next(); - } - if (post.length === numArgs + 1) { - callMiddlewareFunction(post, context, newArgs.concat([_cb]), _cb); - } else { - let error; - let maybePromise; - try { - maybePromise = post.apply(context, newArgs); - } catch (err) { - error = err; - firstError = err; - } - if (isPromise(maybePromise)) { - return maybePromise.then(() => _cb(), err => _cb(err)); - } + var foundFirst = false; - if (++currentPost >= numPosts) { - return callback.apply(null, [error].concat(args)); - } + for (var _iterator3 = _createForOfIteratorHelperLoose(units), _step3; !(_step3 = _iterator3()).done;) { + var u = _step3.value; + var v = normalized[u]; - next(error); + if (!isUndefined(v)) { + foundFirst = true; + } else if (foundFirst) { + normalized[u] = defaultValues[u]; + } else { + normalized[u] = objNow[u]; } - } - }; + } // make sure the values we have are in range - next(); -}; -Kareem.prototype.execPostSync = function(name, context, args) { - const posts = get(this._posts, name, []); - const numPosts = posts.length; + var higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), + invalid = higherOrderInvalid || hasInvalidTimeData(normalized); - for (let i = 0; i < numPosts; ++i) { - posts[i].fn.apply(context, args || []); - } -}; + if (invalid) { + return DateTime.invalid(invalid); + } // compute the actual time -Kareem.prototype.createWrapperSync = function(name, fn) { - var kareem = this; - return function syncWrapper() { - kareem.execPreSync(name, this, arguments); - var toReturn = fn.apply(this, arguments); + var gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized, + _objToTS2 = objToTS(gregorian, offsetProvis, zoneToUse), + tsFinal = _objToTS2[0], + offsetFinal = _objToTS2[1], + inst = new DateTime({ + ts: tsFinal, + zone: zoneToUse, + o: offsetFinal, + loc: loc + }); // gregorian data + weekday serves only to validate - kareem.execPostSync(name, this, [toReturn]); - return toReturn; - }; -} + if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) { + return DateTime.invalid("mismatched weekday", "you can't specify both a weekday of " + normalized.weekday + " and a date of " + inst.toISO()); + } -function _handleWrapError(instance, error, name, context, args, options, callback) { - if (options.useErrorHandlers) { - var _options = { error: error }; - return instance.execPost(name, context, args, _options, function(error) { - return typeof callback === 'function' && callback(error); - }); - } else { - return typeof callback === 'function' ? - callback(error) : - undefined; + return inst; } -} - -Kareem.prototype.wrap = function(name, fn, context, args, options) { - const lastArg = (args.length > 0 ? args[args.length - 1] : null); - const argsWithoutCb = typeof lastArg === 'function' ? - args.slice(0, args.length - 1) : - args; - const _this = this; - - options = options || {}; - const checkForPromise = options.checkForPromise; + /** + * Create a DateTime from an ISO 8601 string + * @param {string} text - the ISO string + * @param {Object} opts - options to affect the creation + * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone + * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one + * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance + * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance + * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance + * @example DateTime.fromISO('2016-05-25T09:08:34.123') + * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00') + * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true}) + * @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'}) + * @example DateTime.fromISO('2016-W05-4') + * @return {DateTime} + */ + ; - this.execPre(name, context, args, function(error) { - if (error) { - const numCallbackParams = options.numCallbackParams || 0; - const errorArgs = options.contextParameter ? [context] : []; - for (var i = errorArgs.length; i < numCallbackParams; ++i) { - errorArgs.push(null); - } - return _handleWrapError(_this, error, name, context, errorArgs, - options, lastArg); + DateTime.fromISO = function fromISO(text, opts) { + if (opts === void 0) { + opts = {}; } - const end = (typeof lastArg === 'function' ? args.length - 1 : args.length); - const numParameters = fn.length; - const ret = fn.apply(context, args.slice(0, end).concat(_cb)); + var _parseISODate = parseISODate(text), + vals = _parseISODate[0], + parsedZone = _parseISODate[1]; - if (checkForPromise) { - if (ret != null && typeof ret.then === 'function') { - // Thenable, use it - return ret.then( - res => _cb(null, res), - err => _cb(err) - ); - } + return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text); + } + /** + * Create a DateTime from an RFC 2822 string + * @param {string} text - the RFC 2822 string + * @param {Object} opts - options to affect the creation + * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. + * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one + * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance + * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance + * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance + * @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT') + * @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600') + * @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z') + * @return {DateTime} + */ + ; - // If `fn()` doesn't have a callback argument and doesn't return a - // promise, assume it is sync - if (numParameters < end + 1) { - return _cb(null, ret); - } + DateTime.fromRFC2822 = function fromRFC2822(text, opts) { + if (opts === void 0) { + opts = {}; } - function _cb() { - const args = arguments; - const argsWithoutError = Array.prototype.slice.call(arguments, 1); - if (options.nullResultByDefault && argsWithoutError.length === 0) { - argsWithoutError.push(null); - } - if (arguments[0]) { - // Assume error - return _handleWrapError(_this, arguments[0], name, context, - argsWithoutError, options, lastArg); - } else { - _this.execPost(name, context, argsWithoutError, function() { - if (arguments[0]) { - return typeof lastArg === 'function' ? - lastArg(arguments[0]) : - undefined; - } + var _parseRFC2822Date = parseRFC2822Date(text), + vals = _parseRFC2822Date[0], + parsedZone = _parseRFC2822Date[1]; - return typeof lastArg === 'function' ? - lastArg.apply(context, arguments) : - undefined; - }); - } + return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text); + } + /** + * Create a DateTime from an HTTP header date + * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 + * @param {string} text - the HTTP header date + * @param {Object} opts - options to affect the creation + * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. + * @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods. + * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance + * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance + * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance + * @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT') + * @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT') + * @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994') + * @return {DateTime} + */ + ; + + DateTime.fromHTTP = function fromHTTP(text, opts) { + if (opts === void 0) { + opts = {}; } - }); -}; -Kareem.prototype.filter = function(fn) { - const clone = this.clone(); + var _parseHTTPDate = parseHTTPDate(text), + vals = _parseHTTPDate[0], + parsedZone = _parseHTTPDate[1]; - const pres = Array.from(clone._pres.keys()); - for (const name of pres) { - const hooks = this._pres.get(name). - map(h => Object.assign({}, h, { name: name })). - filter(fn); + return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts); + } + /** + * Create a DateTime from an input string and format string. + * Defaults to en-US if no locale has been specified, regardless of the system's locale. + * @see https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens + * @param {string} text - the string to parse + * @param {string} fmt - the format the string is expected to be in (see the link below for the formats) + * @param {Object} opts - options to affect the creation + * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone + * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one + * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale + * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system + * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance + * @return {DateTime} + */ + ; - if (hooks.length === 0) { - clone._pres.delete(name); - continue; + DateTime.fromFormat = function fromFormat(text, fmt, opts) { + if (opts === void 0) { + opts = {}; } - hooks.numAsync = hooks.filter(h => h.isAsync).length; + if (isUndefined(text) || isUndefined(fmt)) { + throw new InvalidArgumentError("fromFormat requires an input string and a format"); + } - clone._pres.set(name, hooks); - } + var _opts = opts, + _opts$locale = _opts.locale, + locale = _opts$locale === void 0 ? null : _opts$locale, + _opts$numberingSystem = _opts.numberingSystem, + numberingSystem = _opts$numberingSystem === void 0 ? null : _opts$numberingSystem, + localeToUse = Locale.fromOpts({ + locale: locale, + numberingSystem: numberingSystem, + defaultToEN: true + }), + _parseFromTokens = parseFromTokens(localeToUse, text, fmt), + vals = _parseFromTokens[0], + parsedZone = _parseFromTokens[1], + invalid = _parseFromTokens[2]; - const posts = Array.from(clone._posts.keys()); - for (const name of posts) { - const hooks = this._posts.get(name). - map(h => Object.assign({}, h, { name: name })). - filter(fn); + if (invalid) { + return DateTime.invalid(invalid); + } else { + return parseDataToDateTime(vals, parsedZone, opts, "format " + fmt, text); + } + } + /** + * @deprecated use fromFormat instead + */ + ; - if (hooks.length === 0) { - clone._posts.delete(name); - continue; + DateTime.fromString = function fromString(text, fmt, opts) { + if (opts === void 0) { + opts = {}; } - clone._posts.set(name, hooks); + return DateTime.fromFormat(text, fmt, opts); } + /** + * Create a DateTime from a SQL date, time, or datetime + * Defaults to en-US if no locale has been specified, regardless of the system's locale + * @param {string} text - the string to parse + * @param {Object} opts - options to affect the creation + * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone + * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one + * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale + * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system + * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance + * @example DateTime.fromSQL('2017-05-15') + * @example DateTime.fromSQL('2017-05-15 09:12:34') + * @example DateTime.fromSQL('2017-05-15 09:12:34.342') + * @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00') + * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles') + * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true }) + * @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' }) + * @example DateTime.fromSQL('09:12:34.342') + * @return {DateTime} + */ + ; - return clone; -}; + DateTime.fromSQL = function fromSQL(text, opts) { + if (opts === void 0) { + opts = {}; + } -Kareem.prototype.hasHooks = function(name) { - return this._pres.has(name) || this._posts.has(name); -}; + var _parseSQL = parseSQL(text), + vals = _parseSQL[0], + parsedZone = _parseSQL[1]; -Kareem.prototype.createWrapper = function(name, fn, context, options) { - var _this = this; - if (!this.hasHooks(name)) { - // Fast path: if there's no hooks for this function, just return the - // function wrapped in a nextTick() - return function() { - process.nextTick(() => fn.apply(this, arguments)); - }; + return parseDataToDateTime(vals, parsedZone, opts, "SQL", text); } - return function() { - var _context = context || this; - var args = Array.prototype.slice.call(arguments); - _this.wrap(name, fn, _context, args, options); - }; -}; + /** + * Create an invalid DateTime. + * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent + * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information + * @return {DateTime} + */ + ; -Kareem.prototype.pre = function(name, isAsync, fn, error, unshift) { - let options = {}; - if (typeof isAsync === 'object' && isAsync != null) { - options = isAsync; - isAsync = options.isAsync; - } else if (typeof arguments[1] !== 'boolean') { - error = fn; - fn = isAsync; - isAsync = false; - } + DateTime.invalid = function invalid(reason, explanation) { + if (explanation === void 0) { + explanation = null; + } - const pres = get(this._pres, name, []); - this._pres.set(name, pres); + if (!reason) { + throw new InvalidArgumentError("need to specify a reason the DateTime is invalid"); + } - if (isAsync) { - pres.numAsync = pres.numAsync || 0; - ++pres.numAsync; - } + var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); - if (typeof fn !== 'function') { - throw new Error('pre() requires a function, got "' + typeof fn + '"'); + if (Settings.throwOnInvalid) { + throw new InvalidDateTimeError(invalid); + } else { + return new DateTime({ + invalid: invalid + }); + } } + /** + * Check if an object is a DateTime. Works across context boundaries + * @param {object} o + * @return {boolean} + */ + ; - if (unshift) { - pres.unshift(Object.assign({}, options, { fn: fn, isAsync: isAsync })); - } else { - pres.push(Object.assign({}, options, { fn: fn, isAsync: isAsync })); - } + DateTime.isDateTime = function isDateTime(o) { + return o && o.isLuxonDateTime || false; + } // INFO - return this; -}; + /** + * Get the value of unit. + * @param {string} unit - a unit such as 'minute' or 'day' + * @example DateTime.local(2017, 7, 4).get('month'); //=> 7 + * @example DateTime.local(2017, 7, 4).get('day'); //=> 4 + * @return {number} + */ + ; -Kareem.prototype.post = function(name, options, fn, unshift) { - const hooks = get(this._posts, name, []); + var _proto = DateTime.prototype; - if (typeof options === 'function') { - unshift = !!fn; - fn = options; - options = {}; + _proto.get = function get(unit) { + return this[unit]; } + /** + * Returns whether the DateTime is valid. Invalid DateTimes occur when: + * * The DateTime was created from invalid calendar information, such as the 13th month or February 30 + * * The DateTime was created by an operation on another invalid date + * @type {boolean} + */ + ; - if (typeof fn !== 'function') { - throw new Error('post() requires a function, got "' + typeof fn + '"'); - } + /** + * Returns the resolved Intl options for this DateTime. + * This is useful in understanding the behavior of formatting methods + * @param {Object} opts - the same options as toLocaleString + * @return {Object} + */ + _proto.resolvedLocaleOpts = function resolvedLocaleOpts(opts) { + if (opts === void 0) { + opts = {}; + } - if (unshift) { - hooks.unshift(Object.assign({}, options, { fn: fn })); - } else { - hooks.push(Object.assign({}, options, { fn: fn })); - } - this._posts.set(name, hooks); - return this; -}; + var _Formatter$create$res = Formatter.create(this.loc.clone(opts), opts).resolvedOptions(this), + locale = _Formatter$create$res.locale, + numberingSystem = _Formatter$create$res.numberingSystem, + calendar = _Formatter$create$res.calendar; -Kareem.prototype.clone = function() { - const n = new Kareem(); + return { + locale: locale, + numberingSystem: numberingSystem, + outputCalendar: calendar + }; + } // TRANSFORM - for (let key of this._pres.keys()) { - const clone = this._pres.get(key).slice(); - clone.numAsync = this._pres.get(key).numAsync; - n._pres.set(key, clone); - } - for (let key of this._posts.keys()) { - n._posts.set(key, this._posts.get(key).slice()); - } + /** + * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime. + * + * Equivalent to {@link setZone}('utc') + * @param {number} [offset=0] - optionally, an offset from UTC in minutes + * @param {Object} [opts={}] - options to pass to `setZone()` + * @return {DateTime} + */ + ; - return n; -}; + _proto.toUTC = function toUTC(offset, opts) { + if (offset === void 0) { + offset = 0; + } -Kareem.prototype.merge = function(other, clone) { - clone = arguments.length === 1 ? true : clone; - var ret = clone ? this.clone() : this; + if (opts === void 0) { + opts = {}; + } - for (let key of other._pres.keys()) { - const sourcePres = get(ret._pres, key, []); - const deduplicated = other._pres.get(key). - // Deduplicate based on `fn` - filter(p => sourcePres.map(_p => _p.fn).indexOf(p.fn) === -1); - const combined = sourcePres.concat(deduplicated); - combined.numAsync = sourcePres.numAsync || 0; - combined.numAsync += deduplicated.filter(p => p.isAsync).length; - ret._pres.set(key, combined); - } - for (let key of other._posts.keys()) { - const sourcePosts = get(ret._posts, key, []); - const deduplicated = other._posts.get(key). - filter(p => sourcePosts.indexOf(p) === -1); - ret._posts.set(key, sourcePosts.concat(deduplicated)); + return this.setZone(FixedOffsetZone.instance(offset), opts); } + /** + * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime. + * + * Equivalent to `setZone('local')` + * @return {DateTime} + */ + ; - return ret; -}; - -function get(map, key, def) { - if (map.has(key)) { - return map.get(key); + _proto.toLocal = function toLocal() { + return this.setZone(Settings.defaultZone); } - return def; -} + /** + * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime. + * + * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link plus}. You may wish to use {@link toLocal} and {@link toUTC} which provide simple convenience wrappers for commonly used zones. + * @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link Zone} class. + * @param {Object} opts - options + * @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this. + * @return {DateTime} + */ + ; -function callMiddlewareFunction(fn, context, args, next) { - let maybePromise; - try { - maybePromise = fn.apply(context, args); - } catch (error) { - return next(error); - } + _proto.setZone = function setZone(zone, _temp) { + var _ref3 = _temp === void 0 ? {} : _temp, + _ref3$keepLocalTime = _ref3.keepLocalTime, + keepLocalTime = _ref3$keepLocalTime === void 0 ? false : _ref3$keepLocalTime, + _ref3$keepCalendarTim = _ref3.keepCalendarTime, + keepCalendarTime = _ref3$keepCalendarTim === void 0 ? false : _ref3$keepCalendarTim; - if (isPromise(maybePromise)) { - maybePromise.then(() => next(), err => next(err)); - } -} + zone = normalizeZone(zone, Settings.defaultZone); -function isPromise(v) { - return v != null && typeof v.then === 'function'; -} + if (zone.equals(this.zone)) { + return this; + } else if (!zone.isValid) { + return DateTime.invalid(unsupportedZone(zone)); + } else { + var newTS = this.ts; -function decorateNextFn(fn) { - var called = false; - var _this = this; - return function() { - // Ensure this function can only be called once - if (called) { - return; - } - called = true; - // Make sure to clear the stack so try/catch doesn't catch errors - // in subsequent middleware - return process.nextTick(() => fn.apply(_this, arguments)); - }; -} + if (keepLocalTime || keepCalendarTime) { + var offsetGuess = zone.offset(this.ts); + var asObj = this.toObject(); -module.exports = Kareem; + var _objToTS3 = objToTS(asObj, offsetGuess, zone); -}).call(this)}).call(this,require('_process')) -},{"_process":369}],223:[function(require,module,exports){ -(function (global){(function (){ -/** - * @license - * Lodash - * Copyright OpenJS Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ -;(function() { + newTS = _objToTS3[0]; + } - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; + return clone$1(this, { + ts: newTS, + zone: zone + }); + } + } + /** + * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime. + * @param {Object} properties - the properties to set + * @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' }) + * @return {DateTime} + */ + ; - /** Used as the semantic version number. */ - var VERSION = '4.17.21'; + _proto.reconfigure = function reconfigure(_temp2) { + var _ref4 = _temp2 === void 0 ? {} : _temp2, + locale = _ref4.locale, + numberingSystem = _ref4.numberingSystem, + outputCalendar = _ref4.outputCalendar; - /** Used as the size to enable large array optimizations. */ - var LARGE_ARRAY_SIZE = 200; + var loc = this.loc.clone({ + locale: locale, + numberingSystem: numberingSystem, + outputCalendar: outputCalendar + }); + return clone$1(this, { + loc: loc + }); + } + /** + * "Set" the locale. Returns a newly-constructed DateTime. + * Just a convenient alias for reconfigure({ locale }) + * @example DateTime.local(2017, 5, 25).setLocale('en-GB') + * @return {DateTime} + */ + ; - /** Error message constants. */ - var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', - FUNC_ERROR_TEXT = 'Expected a function', - INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`'; + _proto.setLocale = function setLocale(locale) { + return this.reconfigure({ + locale: locale + }); + } + /** + * "Set" the values of specified units. Returns a newly-constructed DateTime. + * You can only set units with this method; for "setting" metadata, see {@link reconfigure} and {@link setZone}. + * @param {Object} values - a mapping of units to numbers + * @example dt.set({ year: 2017 }) + * @example dt.set({ hour: 8, minute: 30 }) + * @example dt.set({ weekday: 5 }) + * @example dt.set({ year: 2005, ordinal: 234 }) + * @return {DateTime} + */ + ; - /** Used to stand-in for `undefined` hash values. */ - var HASH_UNDEFINED = '__lodash_hash_undefined__'; + _proto.set = function set(values) { + if (!this.isValid) return this; + var normalized = normalizeObject(values, normalizeUnit, []), + settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday), + containsOrdinal = !isUndefined(normalized.ordinal), + containsGregorYear = !isUndefined(normalized.year), + containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day), + containsGregor = containsGregorYear || containsGregorMD, + definiteWeekDef = normalized.weekYear || normalized.weekNumber; - /** Used as the maximum memoize cache size. */ - var MAX_MEMOIZE_SIZE = 500; + if ((containsGregor || containsOrdinal) && definiteWeekDef) { + throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals"); + } - /** Used as the internal argument placeholder. */ - var PLACEHOLDER = '__lodash_placeholder__'; + if (containsGregorMD && containsOrdinal) { + throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day"); + } - /** Used to compose bitmasks for cloning. */ - var CLONE_DEEP_FLAG = 1, - CLONE_FLAT_FLAG = 2, - CLONE_SYMBOLS_FLAG = 4; + var mixed; - /** Used to compose bitmasks for value comparisons. */ - var COMPARE_PARTIAL_FLAG = 1, - COMPARE_UNORDERED_FLAG = 2; + if (settingWeekStuff) { + mixed = weekToGregorian(Object.assign(gregorianToWeek(this.c), normalized)); + } else if (!isUndefined(normalized.ordinal)) { + mixed = ordinalToGregorian(Object.assign(gregorianToOrdinal(this.c), normalized)); + } else { + mixed = Object.assign(this.toObject(), normalized); // if we didn't set the day but we ended up on an overflow date, + // use the last day of the right month - /** Used to compose bitmasks for function metadata. */ - var WRAP_BIND_FLAG = 1, - WRAP_BIND_KEY_FLAG = 2, - WRAP_CURRY_BOUND_FLAG = 4, - WRAP_CURRY_FLAG = 8, - WRAP_CURRY_RIGHT_FLAG = 16, - WRAP_PARTIAL_FLAG = 32, - WRAP_PARTIAL_RIGHT_FLAG = 64, - WRAP_ARY_FLAG = 128, - WRAP_REARG_FLAG = 256, - WRAP_FLIP_FLAG = 512; + if (isUndefined(normalized.day)) { + mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day); + } + } - /** Used as default options for `_.truncate`. */ - var DEFAULT_TRUNC_LENGTH = 30, - DEFAULT_TRUNC_OMISSION = '...'; + var _objToTS4 = objToTS(mixed, this.o, this.zone), + ts = _objToTS4[0], + o = _objToTS4[1]; - /** Used to detect hot functions by number of calls within a span of milliseconds. */ - var HOT_COUNT = 800, - HOT_SPAN = 16; + return clone$1(this, { + ts: ts, + o: o + }); + } + /** + * Add a period of time to this DateTime and return the resulting DateTime + * + * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between. + * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() + * @example DateTime.now().plus(123) //~> in 123 milliseconds + * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes + * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow + * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday + * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min + * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min + * @return {DateTime} + */ + ; - /** Used to indicate the type of lazy iteratees. */ - var LAZY_FILTER_FLAG = 1, - LAZY_MAP_FLAG = 2, - LAZY_WHILE_FLAG = 3; + _proto.plus = function plus(duration) { + if (!this.isValid) return this; + var dur = friendlyDuration(duration); + return clone$1(this, adjustTime(this, dur)); + } + /** + * Subtract a period of time to this DateTime and return the resulting DateTime + * See {@link plus} + * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() + @return {DateTime} + */ + ; - /** Used as references for various `Number` constants. */ - var INFINITY = 1 / 0, - MAX_SAFE_INTEGER = 9007199254740991, - MAX_INTEGER = 1.7976931348623157e+308, - NAN = 0 / 0; + _proto.minus = function minus(duration) { + if (!this.isValid) return this; + var dur = friendlyDuration(duration).negate(); + return clone$1(this, adjustTime(this, dur)); + } + /** + * "Set" this DateTime to the beginning of a unit of time. + * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. + * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01' + * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01' + * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays + * @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00' + * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00' + * @return {DateTime} + */ + ; - /** Used as references for the maximum length and index of an array. */ - var MAX_ARRAY_LENGTH = 4294967295, - MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, - HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; + _proto.startOf = function startOf(unit) { + if (!this.isValid) return this; + var o = {}, + normalizedUnit = Duration.normalizeUnit(unit); - /** Used to associate wrap methods with their bit flags. */ - var wrapFlags = [ - ['ary', WRAP_ARY_FLAG], - ['bind', WRAP_BIND_FLAG], - ['bindKey', WRAP_BIND_KEY_FLAG], - ['curry', WRAP_CURRY_FLAG], - ['curryRight', WRAP_CURRY_RIGHT_FLAG], - ['flip', WRAP_FLIP_FLAG], - ['partial', WRAP_PARTIAL_FLAG], - ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], - ['rearg', WRAP_REARG_FLAG] - ]; + switch (normalizedUnit) { + case "years": + o.month = 1; + // falls through - /** `Object#toString` result references. */ - var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - asyncTag = '[object AsyncFunction]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - domExcTag = '[object DOMException]', - errorTag = '[object Error]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]', - mapTag = '[object Map]', - numberTag = '[object Number]', - nullTag = '[object Null]', - objectTag = '[object Object]', - promiseTag = '[object Promise]', - proxyTag = '[object Proxy]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - symbolTag = '[object Symbol]', - undefinedTag = '[object Undefined]', - weakMapTag = '[object WeakMap]', - weakSetTag = '[object WeakSet]'; + case "quarters": + case "months": + o.day = 1; + // falls through - var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; + case "weeks": + case "days": + o.hour = 0; + // falls through - /** Used to match empty string literals in compiled template source. */ - var reEmptyStringLeading = /\b__p \+= '';/g, - reEmptyStringMiddle = /\b(__p \+=) '' \+/g, - reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; + case "hours": + o.minute = 0; + // falls through - /** Used to match HTML entities and HTML characters. */ - var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, - reUnescapedHtml = /[&<>"']/g, - reHasEscapedHtml = RegExp(reEscapedHtml.source), - reHasUnescapedHtml = RegExp(reUnescapedHtml.source); + case "minutes": + o.second = 0; + // falls through - /** Used to match template delimiters. */ - var reEscape = /<%-([\s\S]+?)%>/g, - reEvaluate = /<%([\s\S]+?)%>/g, - reInterpolate = /<%=([\s\S]+?)%>/g; + case "seconds": + o.millisecond = 0; + break; + // no default, invalid units throw in normalizeUnit() + } - /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, - reIsPlainProp = /^\w*$/, - rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; + if (normalizedUnit === "weeks") { + o.weekday = 1; + } + + if (normalizedUnit === "quarters") { + var q = Math.ceil(this.month / 3); + o.month = (q - 1) * 3 + 1; + } + return this.set(o); + } /** - * Used to match `RegExp` - * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time + * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. + * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00' + * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00' + * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays + * @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00' + * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00' + * @return {DateTime} */ - var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, - reHasRegExpChar = RegExp(reRegExpChar.source); - - /** Used to match leading whitespace. */ - var reTrimStart = /^\s+/; - - /** Used to match a single whitespace character. */ - var reWhitespace = /\s/; + ; - /** Used to match wrap detail comments. */ - var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, - reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, - reSplitDetails = /,? & /; + _proto.endOf = function endOf(unit) { + var _this$plus; - /** Used to match words composed of alphanumeric characters. */ - var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; + return this.isValid ? this.plus((_this$plus = {}, _this$plus[unit] = 1, _this$plus)).startOf(unit).minus(1) : this; + } // OUTPUT /** - * Used to validate the `validate` option in `_.template` variable. - * - * Forbids characters which could potentially change the meaning of the function argument definition: - * - "()," (modification of function parameters) - * - "=" (default value) - * - "[]{}" (destructuring of function parameters) - * - "/" (beginning of a comment) - * - whitespace + * Returns a string representation of this DateTime formatted according to the specified format string. + * **You may not want this.** See {@link toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens). + * Defaults to en-US if no locale has been specified, regardless of the system's locale. + * @see https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens + * @param {string} fmt - the format string + * @param {Object} opts - opts to override the configuration options + * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22' + * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22' + * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22' + * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes' + * @return {string} */ - var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/; + ; - /** Used to match backslashes in property paths. */ - var reEscapeChar = /\\(\\)?/g; + _proto.toFormat = function toFormat(fmt, opts) { + if (opts === void 0) { + opts = {}; + } + return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID$2; + } /** - * Used to match - * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). + * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`. + * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation + * of the DateTime in the assigned locale. + * Defaults to the system's locale if no locale has been specified + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat + * @param opts {Object} - Intl.DateTimeFormat constructor options and configuration options + * @example DateTime.now().toLocaleString(); //=> 4/20/2017 + * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017' + * @example DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017' + * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017' + * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM' + * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM' + * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20' + * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM' + * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32' + * @return {string} */ - var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; + ; - /** Used to match `RegExp` flags from their coerced string values. */ - var reFlags = /\w*$/; + _proto.toLocaleString = function toLocaleString(opts) { + if (opts === void 0) { + opts = DATE_SHORT; + } - /** Used to detect bad signed hexadecimal string values. */ - var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTime(this) : INVALID$2; + } + /** + * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output. + * Defaults to the system's locale if no locale has been specified + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts + * @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`. + * @example DateTime.now().toLocaleParts(); //=> [ + * //=> { type: 'day', value: '25' }, + * //=> { type: 'literal', value: '/' }, + * //=> { type: 'month', value: '05' }, + * //=> { type: 'literal', value: '/' }, + * //=> { type: 'year', value: '1982' } + * //=> ] + */ + ; - /** Used to detect binary string values. */ - var reIsBinary = /^0b[01]+$/i; + _proto.toLocaleParts = function toLocaleParts(opts) { + if (opts === void 0) { + opts = {}; + } - /** Used to detect host constructors (Safari). */ - var reIsHostCtor = /^\[object .+?Constructor\]$/; + return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this) : []; + } + /** + * Returns an ISO 8601-compliant string representation of this DateTime + * @param {Object} opts - options + * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 + * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 + * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' + * @param {string} [opts.format='extended'] - choose between the basic and extended format + * @example DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z' + * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00' + * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335' + * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400' + * @return {string} + */ + ; - /** Used to detect octal string values. */ - var reIsOctal = /^0o[0-7]+$/i; + _proto.toISO = function toISO(opts) { + if (opts === void 0) { + opts = {}; + } - /** Used to detect unsigned integer values. */ - var reIsUint = /^(?:0|[1-9]\d*)$/; + if (!this.isValid) { + return null; + } - /** Used to match Latin Unicode letters (excluding mathematical operators). */ - var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; + return this.toISODate(opts) + "T" + this.toISOTime(opts); + } + /** + * Returns an ISO 8601-compliant string representation of this DateTime's date component + * @param {Object} opts - options + * @param {string} [opts.format='extended'] - choose between the basic and extended format + * @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25' + * @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525' + * @return {string} + */ + ; - /** Used to ensure capturing order of template delimiters. */ - var reNoMatch = /($^)/; + _proto.toISODate = function toISODate(_temp3) { + var _ref5 = _temp3 === void 0 ? {} : _temp3, + _ref5$format = _ref5.format, + format = _ref5$format === void 0 ? "extended" : _ref5$format; - /** Used to match unescaped characters in compiled string literals. */ - var reUnescapedString = /['\n\r\u2028\u2029\\]/g; + var fmt = format === "basic" ? "yyyyMMdd" : "yyyy-MM-dd"; - /** Used to compose unicode character classes. */ - var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f', - reComboHalfMarksRange = '\\ufe20-\\ufe2f', - rsComboSymbolsRange = '\\u20d0-\\u20ff', - rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, - rsDingbatRange = '\\u2700-\\u27bf', - rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', - rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', - rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', - rsPunctuationRange = '\\u2000-\\u206f', - rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', - rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', - rsVarRange = '\\ufe0e\\ufe0f', - rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; + if (this.year > 9999) { + fmt = "+" + fmt; + } - /** Used to compose unicode capture groups. */ - var rsApos = "['\u2019]", - rsAstral = '[' + rsAstralRange + ']', - rsBreak = '[' + rsBreakRange + ']', - rsCombo = '[' + rsComboRange + ']', - rsDigits = '\\d+', - rsDingbat = '[' + rsDingbatRange + ']', - rsLower = '[' + rsLowerRange + ']', - rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', - rsFitz = '\\ud83c[\\udffb-\\udfff]', - rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', - rsNonAstral = '[^' + rsAstralRange + ']', - rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsUpper = '[' + rsUpperRange + ']', - rsZWJ = '\\u200d'; + return toTechFormat(this, fmt); + } + /** + * Returns an ISO 8601-compliant string representation of this DateTime's week date + * @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2' + * @return {string} + */ + ; - /** Used to compose unicode regexes. */ - var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', - rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', - rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', - rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', - reOptMod = rsModifier + '?', - rsOptVar = '[' + rsVarRange + ']?', - rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', - rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', - rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', - rsSeq = rsOptVar + reOptMod + rsOptJoin, - rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, - rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + _proto.toISOWeekDate = function toISOWeekDate() { + return toTechFormat(this, "kkkk-'W'WW-c"); + } + /** + * Returns an ISO 8601-compliant string representation of this DateTime's time component + * @param {Object} opts - options + * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 + * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 + * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' + * @param {boolean} [opts.includePrefix=false] - include the `T` prefix + * @param {string} [opts.format='extended'] - choose between the basic and extended format + * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z' + * @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z' + * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z' + * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z' + * @return {string} + */ + ; - /** Used to match apostrophes. */ - var reApos = RegExp(rsApos, 'g'); + _proto.toISOTime = function toISOTime(_temp4) { + var _ref6 = _temp4 === void 0 ? {} : _temp4, + _ref6$suppressMillise = _ref6.suppressMilliseconds, + suppressMilliseconds = _ref6$suppressMillise === void 0 ? false : _ref6$suppressMillise, + _ref6$suppressSeconds = _ref6.suppressSeconds, + suppressSeconds = _ref6$suppressSeconds === void 0 ? false : _ref6$suppressSeconds, + _ref6$includeOffset = _ref6.includeOffset, + includeOffset = _ref6$includeOffset === void 0 ? true : _ref6$includeOffset, + _ref6$includePrefix = _ref6.includePrefix, + includePrefix = _ref6$includePrefix === void 0 ? false : _ref6$includePrefix, + _ref6$format = _ref6.format, + format = _ref6$format === void 0 ? "extended" : _ref6$format; + return toTechTimeFormat(this, { + suppressSeconds: suppressSeconds, + suppressMilliseconds: suppressMilliseconds, + includeOffset: includeOffset, + includePrefix: includePrefix, + format: format + }); + } /** - * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and - * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). + * Returns an RFC 2822-compatible string representation of this DateTime, always in UTC + * @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000' + * @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400' + * @return {string} */ - var reComboMark = RegExp(rsCombo, 'g'); + ; - /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ - var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + _proto.toRFC2822 = function toRFC2822() { + return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false); + } + /** + * Returns a string representation of this DateTime appropriate for use in HTTP headers. + * Specifically, the string conforms to RFC 1123. + * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 + * @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT' + * @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT' + * @return {string} + */ + ; - /** Used to match complex or compound words. */ - var reUnicodeWord = RegExp([ - rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', - rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, - rsUpper + '+' + rsOptContrUpper, - rsOrdUpper, - rsOrdLower, - rsDigits, - rsEmoji - ].join('|'), 'g'); + _proto.toHTTP = function toHTTP() { + return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'"); + } + /** + * Returns a string representation of this DateTime appropriate for use in SQL Date + * @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13' + * @return {string} + */ + ; - /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ - var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); + _proto.toSQLDate = function toSQLDate() { + return toTechFormat(this, "yyyy-MM-dd"); + } + /** + * Returns a string representation of this DateTime appropriate for use in SQL Time + * @param {Object} opts - options + * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset. + * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' + * @example DateTime.utc().toSQL() //=> '05:15:16.345' + * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00' + * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345' + * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York' + * @return {string} + */ + ; - /** Used to detect strings that need a more robust regexp to match words. */ - var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + _proto.toSQLTime = function toSQLTime(_temp5) { + var _ref7 = _temp5 === void 0 ? {} : _temp5, + _ref7$includeOffset = _ref7.includeOffset, + includeOffset = _ref7$includeOffset === void 0 ? true : _ref7$includeOffset, + _ref7$includeZone = _ref7.includeZone, + includeZone = _ref7$includeZone === void 0 ? false : _ref7$includeZone; - /** Used to assign default `context` object properties. */ - var contextProps = [ - 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', - 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', - 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', - 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', - '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' - ]; + return toTechTimeFormat(this, { + includeOffset: includeOffset, + includeZone: includeZone, + spaceZone: true + }); + } + /** + * Returns a string representation of this DateTime appropriate for use in SQL DateTime + * @param {Object} opts - options + * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset. + * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' + * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z' + * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00' + * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000' + * @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York' + * @return {string} + */ + ; - /** Used to make template sourceURLs easier to identify. */ - var templateCounter = -1; + _proto.toSQL = function toSQL(opts) { + if (opts === void 0) { + opts = {}; + } - /** Used to identify `toStringTag` values of typed arrays. */ - var typedArrayTags = {}; - typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = - typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = - typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = - typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = - typedArrayTags[uint32Tag] = true; - typedArrayTags[argsTag] = typedArrayTags[arrayTag] = - typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = - typedArrayTags[errorTag] = typedArrayTags[funcTag] = - typedArrayTags[mapTag] = typedArrayTags[numberTag] = - typedArrayTags[objectTag] = typedArrayTags[regexpTag] = - typedArrayTags[setTag] = typedArrayTags[stringTag] = - typedArrayTags[weakMapTag] = false; + if (!this.isValid) { + return null; + } - /** Used to identify `toStringTag` values supported by `_.clone`. */ - var cloneableTags = {}; - cloneableTags[argsTag] = cloneableTags[arrayTag] = - cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = - cloneableTags[boolTag] = cloneableTags[dateTag] = - cloneableTags[float32Tag] = cloneableTags[float64Tag] = - cloneableTags[int8Tag] = cloneableTags[int16Tag] = - cloneableTags[int32Tag] = cloneableTags[mapTag] = - cloneableTags[numberTag] = cloneableTags[objectTag] = - cloneableTags[regexpTag] = cloneableTags[setTag] = - cloneableTags[stringTag] = cloneableTags[symbolTag] = - cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = - cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; - cloneableTags[errorTag] = cloneableTags[funcTag] = - cloneableTags[weakMapTag] = false; + return this.toSQLDate() + " " + this.toSQLTime(opts); + } + /** + * Returns a string representation of this DateTime appropriate for debugging + * @return {string} + */ + ; - /** Used to map Latin Unicode letters to basic Latin letters. */ - var deburredLetters = { - // Latin-1 Supplement block. - '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', - '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', - '\xc7': 'C', '\xe7': 'c', - '\xd0': 'D', '\xf0': 'd', - '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', - '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', - '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', - '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', - '\xd1': 'N', '\xf1': 'n', - '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', - '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', - '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', - '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', - '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', - '\xc6': 'Ae', '\xe6': 'ae', - '\xde': 'Th', '\xfe': 'th', - '\xdf': 'ss', - // Latin Extended-A block. - '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', - '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', - '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', - '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', - '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', - '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', - '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', - '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', - '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', - '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', - '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', - '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', - '\u0134': 'J', '\u0135': 'j', - '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', - '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', - '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', - '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', - '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', - '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', - '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', - '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', - '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', - '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', - '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', - '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', - '\u0163': 't', '\u0165': 't', '\u0167': 't', - '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', - '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', - '\u0174': 'W', '\u0175': 'w', - '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', - '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', - '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', - '\u0132': 'IJ', '\u0133': 'ij', - '\u0152': 'Oe', '\u0153': 'oe', - '\u0149': "'n", '\u017f': 's' - }; + _proto.toString = function toString() { + return this.isValid ? this.toISO() : INVALID$2; + } + /** + * Returns the epoch milliseconds of this DateTime. Alias of {@link toMillis} + * @return {number} + */ + ; - /** Used to map characters to HTML entities. */ - var htmlEscapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; + _proto.valueOf = function valueOf() { + return this.toMillis(); + } + /** + * Returns the epoch milliseconds of this DateTime. + * @return {number} + */ + ; - /** Used to map HTML entities to characters. */ - var htmlUnescapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - ''': "'" - }; + _proto.toMillis = function toMillis() { + return this.isValid ? this.ts : NaN; + } + /** + * Returns the epoch seconds of this DateTime. + * @return {number} + */ + ; - /** Used to escape characters for inclusion in compiled string literals. */ - var stringEscapes = { - '\\': '\\', - "'": "'", - '\n': 'n', - '\r': 'r', - '\u2028': 'u2028', - '\u2029': 'u2029' - }; + _proto.toSeconds = function toSeconds() { + return this.isValid ? this.ts / 1000 : NaN; + } + /** + * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON. + * @return {string} + */ + ; - /** Built-in method references without a dependency on `root`. */ - var freeParseFloat = parseFloat, - freeParseInt = parseInt; + _proto.toJSON = function toJSON() { + return this.toISO(); + } + /** + * Returns a BSON serializable equivalent to this DateTime. + * @return {Date} + */ + ; - /** Detect free variable `global` from Node.js. */ - var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + _proto.toBSON = function toBSON() { + return this.toJSDate(); + } + /** + * Returns a JavaScript object with this DateTime's year, month, day, and so on. + * @param opts - options for generating the object + * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output + * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 } + * @return {Object} + */ + ; - /** Detect free variable `self`. */ - var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + _proto.toObject = function toObject(opts) { + if (opts === void 0) { + opts = {}; + } - /** Used as a reference to the global object. */ - var root = freeGlobal || freeSelf || Function('return this')(); + if (!this.isValid) return {}; + var base = Object.assign({}, this.c); - /** Detect free variable `exports`. */ - var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + if (opts.includeConfig) { + base.outputCalendar = this.outputCalendar; + base.numberingSystem = this.loc.numberingSystem; + base.locale = this.loc.locale; + } - /** Detect free variable `module`. */ - var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + return base; + } + /** + * Returns a JavaScript Date equivalent to this DateTime. + * @return {Date} + */ + ; - /** Detect the popular CommonJS extension `module.exports`. */ - var moduleExports = freeModule && freeModule.exports === freeExports; + _proto.toJSDate = function toJSDate() { + return new Date(this.isValid ? this.ts : NaN); + } // COMPARE - /** Detect free variable `process` from Node.js. */ - var freeProcess = moduleExports && freeGlobal.process; + /** + * Return the difference between two DateTimes as a Duration. + * @param {DateTime} otherDateTime - the DateTime to compare this one to + * @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration. + * @param {Object} opts - options that affect the creation of the Duration + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @example + * var i1 = DateTime.fromISO('1982-05-25T09:45'), + * i2 = DateTime.fromISO('1983-10-14T10:30'); + * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 } + * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 } + * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 } + * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 } + * @return {Duration} + */ + ; - /** Used to access faster Node.js helpers. */ - var nodeUtil = (function() { - try { - // Use `util.types` for Node.js 10+. - var types = freeModule && freeModule.require && freeModule.require('util').types; + _proto.diff = function diff(otherDateTime, unit, opts) { + if (unit === void 0) { + unit = "milliseconds"; + } - if (types) { - return types; - } + if (opts === void 0) { + opts = {}; + } - // Legacy `process.binding('util')` for Node.js < 10. - return freeProcess && freeProcess.binding && freeProcess.binding('util'); - } catch (e) {} - }()); + if (!this.isValid || !otherDateTime.isValid) { + return Duration.invalid(this.invalid || otherDateTime.invalid, "created by diffing an invalid DateTime"); + } - /* Node.js helper references. */ - var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, - nodeIsDate = nodeUtil && nodeUtil.isDate, - nodeIsMap = nodeUtil && nodeUtil.isMap, - nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, - nodeIsSet = nodeUtil && nodeUtil.isSet, - nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; + var durOpts = Object.assign({ + locale: this.locale, + numberingSystem: this.numberingSystem + }, opts); - /*--------------------------------------------------------------------------*/ + var units = maybeArray(unit).map(Duration.normalizeUnit), + otherIsLater = otherDateTime.valueOf() > this.valueOf(), + earlier = otherIsLater ? this : otherDateTime, + later = otherIsLater ? otherDateTime : this, + diffed = _diff(earlier, later, units, durOpts); + return otherIsLater ? diffed.negate() : diffed; + } /** - * A faster alternative to `Function#apply`, this function invokes `func` - * with the `this` binding of `thisArg` and the arguments of `args`. - * - * @private - * @param {Function} func The function to invoke. - * @param {*} thisArg The `this` binding of `func`. - * @param {Array} args The arguments to invoke `func` with. - * @returns {*} Returns the result of `func`. + * Return the difference between this DateTime and right now. + * See {@link diff} + * @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration + * @param {Object} opts - options that affect the creation of the Duration + * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use + * @return {Duration} */ - function apply(func, thisArg, args) { - switch (args.length) { - case 0: return func.call(thisArg); - case 1: return func.call(thisArg, args[0]); - case 2: return func.call(thisArg, args[0], args[1]); - case 3: return func.call(thisArg, args[0], args[1], args[2]); + ; + + _proto.diffNow = function diffNow(unit, opts) { + if (unit === void 0) { + unit = "milliseconds"; + } + + if (opts === void 0) { + opts = {}; } - return func.apply(thisArg, args); - } + return this.diff(DateTime.now(), unit, opts); + } /** - * A specialized version of `baseAggregator` for arrays. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} setter The function to set `accumulator` values. - * @param {Function} iteratee The iteratee to transform keys. - * @param {Object} accumulator The initial aggregated object. - * @returns {Function} Returns `accumulator`. + * Return an Interval spanning between this DateTime and another DateTime + * @param {DateTime} otherDateTime - the other end point of the Interval + * @return {Interval} */ - function arrayAggregator(array, setter, iteratee, accumulator) { - var index = -1, - length = array == null ? 0 : array.length; + ; - while (++index < length) { - var value = array[index]; - setter(accumulator, value, iteratee(value), array); - } - return accumulator; + _proto.until = function until(otherDateTime) { + return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this; } - /** - * A specialized version of `_.forEach` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns `array`. + * Return whether this DateTime is in the same unit of time as another DateTime. + * Higher-order units must also be identical for this function to return `true`. + * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link setZone} to convert one of the dates if needed. + * @param {DateTime} otherDateTime - the other DateTime + * @param {string} unit - the unit of time to check sameness on + * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day + * @return {boolean} */ - function arrayEach(array, iteratee) { - var index = -1, - length = array == null ? 0 : array.length; + ; - while (++index < length) { - if (iteratee(array[index], index, array) === false) { - break; - } - } - return array; + _proto.hasSame = function hasSame(otherDateTime, unit) { + if (!this.isValid) return false; + var inputMs = otherDateTime.valueOf(); + var otherZoneDateTime = this.setZone(otherDateTime.zone, { + keepLocalTime: true + }); + return otherZoneDateTime.startOf(unit) <= inputMs && inputMs <= otherZoneDateTime.endOf(unit); } - /** - * A specialized version of `_.forEachRight` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns `array`. + * Equality check + * Two DateTimes are equal iff they represent the same millisecond, have the same zone and location, and are both valid. + * To compare just the millisecond values, use `+dt1 === +dt2`. + * @param {DateTime} other - the other DateTime + * @return {boolean} */ - function arrayEachRight(array, iteratee) { - var length = array == null ? 0 : array.length; + ; - while (length--) { - if (iteratee(array[length], length, array) === false) { - break; - } - } - return array; + _proto.equals = function equals(other) { + return this.isValid && other.isValid && this.valueOf() === other.valueOf() && this.zone.equals(other.zone) && this.loc.equals(other.loc); } - /** - * A specialized version of `_.every` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, - * else `false`. + * Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your + * platform supports Intl.RelativeTimeFormat. Rounds down by default. + * @param {Object} options - options that affect the output + * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now. + * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow" + * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds" + * @param {boolean} [options.round=true] - whether to round the numbers in the output. + * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding. + * @param {string} options.locale - override the locale of this DateTime + * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this + * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day" + * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día" + * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures" + * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago" + * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago" + * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago" */ - function arrayEvery(array, predicate) { - var index = -1, - length = array == null ? 0 : array.length; + ; - while (++index < length) { - if (!predicate(array[index], index, array)) { - return false; - } + _proto.toRelative = function toRelative(options) { + if (options === void 0) { + options = {}; + } + + if (!this.isValid) return null; + var base = options.base || DateTime.fromObject({ + zone: this.zone + }), + padding = options.padding ? this < base ? -options.padding : options.padding : 0; + var units = ["years", "months", "days", "hours", "minutes", "seconds"]; + var unit = options.unit; + + if (Array.isArray(options.unit)) { + units = options.unit; + unit = undefined; } - return true; - } + return diffRelative(base, this.plus(padding), Object.assign(options, { + numeric: "always", + units: units, + unit: unit + })); + } /** - * A specialized version of `_.filter` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {Array} Returns the new filtered array. + * Returns a string representation of this date relative to today, such as "yesterday" or "next month". + * Only internationalizes on platforms that supports Intl.RelativeTimeFormat. + * @param {Object} options - options that affect the output + * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now. + * @param {string} options.locale - override the locale of this DateTime + * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days" + * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this + * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow" + * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana" + * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain" + * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago" */ - function arrayFilter(array, predicate) { - var index = -1, - length = array == null ? 0 : array.length, - resIndex = 0, - result = []; + ; - while (++index < length) { - var value = array[index]; - if (predicate(value, index, array)) { - result[resIndex++] = value; - } + _proto.toRelativeCalendar = function toRelativeCalendar(options) { + if (options === void 0) { + options = {}; } - return result; - } + if (!this.isValid) return null; + return diffRelative(options.base || DateTime.fromObject({ + zone: this.zone + }), this, Object.assign(options, { + numeric: "auto", + units: ["years", "months", "days"], + calendary: true + })); + } /** - * A specialized version of `_.includes` for arrays without support for - * specifying an index to search from. - * - * @private - * @param {Array} [array] The array to inspect. - * @param {*} target The value to search for. - * @returns {boolean} Returns `true` if `target` is found, else `false`. + * Return the min of several date times + * @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum + * @return {DateTime} the min DateTime, or undefined if called with no argument */ - function arrayIncludes(array, value) { - var length = array == null ? 0 : array.length; - return !!length && baseIndexOf(array, value, 0) > -1; - } + ; + + DateTime.min = function min() { + for (var _len = arguments.length, dateTimes = new Array(_len), _key = 0; _key < _len; _key++) { + dateTimes[_key] = arguments[_key]; + } + + if (!dateTimes.every(DateTime.isDateTime)) { + throw new InvalidArgumentError("min requires all arguments be DateTimes"); + } + return bestBy(dateTimes, function (i) { + return i.valueOf(); + }, Math.min); + } /** - * This function is like `arrayIncludes` except that it accepts a comparator. - * - * @private - * @param {Array} [array] The array to inspect. - * @param {*} target The value to search for. - * @param {Function} comparator The comparator invoked per element. - * @returns {boolean} Returns `true` if `target` is found, else `false`. + * Return the max of several date times + * @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum + * @return {DateTime} the max DateTime, or undefined if called with no argument */ - function arrayIncludesWith(array, value, comparator) { - var index = -1, - length = array == null ? 0 : array.length; + ; - while (++index < length) { - if (comparator(value, array[index])) { - return true; - } + DateTime.max = function max() { + for (var _len2 = arguments.length, dateTimes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + dateTimes[_key2] = arguments[_key2]; } - return false; - } + + if (!dateTimes.every(DateTime.isDateTime)) { + throw new InvalidArgumentError("max requires all arguments be DateTimes"); + } + + return bestBy(dateTimes, function (i) { + return i.valueOf(); + }, Math.max); + } // MISC /** - * A specialized version of `_.map` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the new mapped array. + * Explain how a string would be parsed by fromFormat() + * @param {string} text - the string to parse + * @param {string} fmt - the format the string is expected to be in (see description) + * @param {Object} options - options taken by fromFormat() + * @return {Object} */ - function arrayMap(array, iteratee) { - var index = -1, - length = array == null ? 0 : array.length, - result = Array(length); + ; - while (++index < length) { - result[index] = iteratee(array[index], index, array); + DateTime.fromFormatExplain = function fromFormatExplain(text, fmt, options) { + if (options === void 0) { + options = {}; } - return result; - } + var _options = options, + _options$locale = _options.locale, + locale = _options$locale === void 0 ? null : _options$locale, + _options$numberingSys = _options.numberingSystem, + numberingSystem = _options$numberingSys === void 0 ? null : _options$numberingSys, + localeToUse = Locale.fromOpts({ + locale: locale, + numberingSystem: numberingSystem, + defaultToEN: true + }); + return explainFromTokens(localeToUse, text, fmt); + } /** - * Appends the elements of `values` to `array`. - * - * @private - * @param {Array} array The array to modify. - * @param {Array} values The values to append. - * @returns {Array} Returns `array`. + * @deprecated use fromFormatExplain instead */ - function arrayPush(array, values) { - var index = -1, - length = values.length, - offset = array.length; + ; - while (++index < length) { - array[offset + index] = values[index]; + DateTime.fromStringExplain = function fromStringExplain(text, fmt, options) { + if (options === void 0) { + options = {}; } - return array; - } + + return DateTime.fromFormatExplain(text, fmt, options); + } // FORMAT PRESETS /** - * A specialized version of `_.reduce` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the first element of `array` as - * the initial value. - * @returns {*} Returns the accumulated value. + * {@link toLocaleString} format like 10/14/1983 + * @type {Object} */ - function arrayReduce(array, iteratee, accumulator, initAccum) { - var index = -1, - length = array == null ? 0 : array.length; + ; - if (initAccum && length) { - accumulator = array[++index]; + _createClass(DateTime, [{ + key: "isValid", + get: function get() { + return this.invalid === null; } - while (++index < length) { - accumulator = iteratee(accumulator, array[index], index, array); + /** + * Returns an error code if this DateTime is invalid, or null if the DateTime is valid + * @type {string} + */ + + }, { + key: "invalidReason", + get: function get() { + return this.invalid ? this.invalid.reason : null; } - return accumulator; - } + /** + * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid + * @type {string} + */ - /** - * A specialized version of `_.reduceRight` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the last element of `array` as - * the initial value. - * @returns {*} Returns the accumulated value. - */ - function arrayReduceRight(array, iteratee, accumulator, initAccum) { - var length = array == null ? 0 : array.length; - if (initAccum && length) { - accumulator = array[--length]; + }, { + key: "invalidExplanation", + get: function get() { + return this.invalid ? this.invalid.explanation : null; + } + /** + * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime + * + * @type {string} + */ + + }, { + key: "locale", + get: function get() { + return this.isValid ? this.loc.locale : null; + } + /** + * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime + * + * @type {string} + */ + + }, { + key: "numberingSystem", + get: function get() { + return this.isValid ? this.loc.numberingSystem : null; } - while (length--) { - accumulator = iteratee(accumulator, array[length], length, array); + /** + * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime + * + * @type {string} + */ + + }, { + key: "outputCalendar", + get: function get() { + return this.isValid ? this.loc.outputCalendar : null; } - return accumulator; - } + /** + * Get the time zone associated with this DateTime. + * @type {Zone} + */ - /** - * A specialized version of `_.some` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - */ - function arraySome(array, predicate) { - var index = -1, - length = array == null ? 0 : array.length; + }, { + key: "zone", + get: function get() { + return this._zone; + } + /** + * Get the name of the time zone. + * @type {string} + */ - while (++index < length) { - if (predicate(array[index], index, array)) { - return true; - } + }, { + key: "zoneName", + get: function get() { + return this.isValid ? this.zone.name : null; } - return false; - } + /** + * Get the year + * @example DateTime.local(2017, 5, 25).year //=> 2017 + * @type {number} + */ - /** - * Gets the size of an ASCII `string`. - * - * @private - * @param {string} string The string inspect. - * @returns {number} Returns the string size. - */ - var asciiSize = baseProperty('length'); + }, { + key: "year", + get: function get() { + return this.isValid ? this.c.year : NaN; + } + /** + * Get the quarter + * @example DateTime.local(2017, 5, 25).quarter //=> 2 + * @type {number} + */ - /** - * Converts an ASCII `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function asciiToArray(string) { - return string.split(''); - } + }, { + key: "quarter", + get: function get() { + return this.isValid ? Math.ceil(this.c.month / 3) : NaN; + } + /** + * Get the month (1-12). + * @example DateTime.local(2017, 5, 25).month //=> 5 + * @type {number} + */ - /** - * Splits an ASCII `string` into an array of its words. - * - * @private - * @param {string} The string to inspect. - * @returns {Array} Returns the words of `string`. - */ - function asciiWords(string) { - return string.match(reAsciiWord) || []; - } + }, { + key: "month", + get: function get() { + return this.isValid ? this.c.month : NaN; + } + /** + * Get the day of the month (1-30ish). + * @example DateTime.local(2017, 5, 25).day //=> 25 + * @type {number} + */ - /** - * The base implementation of methods like `_.findKey` and `_.findLastKey`, - * without support for iteratee shorthands, which iterates over `collection` - * using `eachFunc`. - * - * @private - * @param {Array|Object} collection The collection to inspect. - * @param {Function} predicate The function invoked per iteration. - * @param {Function} eachFunc The function to iterate over `collection`. - * @returns {*} Returns the found element or its key, else `undefined`. - */ - function baseFindKey(collection, predicate, eachFunc) { - var result; - eachFunc(collection, function(value, key, collection) { - if (predicate(value, key, collection)) { - result = key; - return false; - } - }); - return result; - } + }, { + key: "day", + get: function get() { + return this.isValid ? this.c.day : NaN; + } + /** + * Get the hour of the day (0-23). + * @example DateTime.local(2017, 5, 25, 9).hour //=> 9 + * @type {number} + */ - /** - * The base implementation of `_.findIndex` and `_.findLastIndex` without - * support for iteratee shorthands. - * - * @private - * @param {Array} array The array to inspect. - * @param {Function} predicate The function invoked per iteration. - * @param {number} fromIndex The index to search from. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function baseFindIndex(array, predicate, fromIndex, fromRight) { - var length = array.length, - index = fromIndex + (fromRight ? 1 : -1); + }, { + key: "hour", + get: function get() { + return this.isValid ? this.c.hour : NaN; + } + /** + * Get the minute of the hour (0-59). + * @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30 + * @type {number} + */ - while ((fromRight ? index-- : ++index < length)) { - if (predicate(array[index], index, array)) { - return index; - } + }, { + key: "minute", + get: function get() { + return this.isValid ? this.c.minute : NaN; } - return -1; - } + /** + * Get the second of the minute (0-59). + * @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52 + * @type {number} + */ - /** - * The base implementation of `_.indexOf` without `fromIndex` bounds checks. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} fromIndex The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function baseIndexOf(array, value, fromIndex) { - return value === value - ? strictIndexOf(array, value, fromIndex) - : baseFindIndex(array, baseIsNaN, fromIndex); - } + }, { + key: "second", + get: function get() { + return this.isValid ? this.c.second : NaN; + } + /** + * Get the millisecond of the second (0-999). + * @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654 + * @type {number} + */ - /** - * This function is like `baseIndexOf` except that it accepts a comparator. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} fromIndex The index to search from. - * @param {Function} comparator The comparator invoked per element. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function baseIndexOfWith(array, value, fromIndex, comparator) { - var index = fromIndex - 1, - length = array.length; + }, { + key: "millisecond", + get: function get() { + return this.isValid ? this.c.millisecond : NaN; + } + /** + * Get the week year + * @see https://en.wikipedia.org/wiki/ISO_week_date + * @example DateTime.local(2014, 12, 31).weekYear //=> 2015 + * @type {number} + */ - while (++index < length) { - if (comparator(array[index], value)) { - return index; - } + }, { + key: "weekYear", + get: function get() { + return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN; } - return -1; - } + /** + * Get the week number of the week year (1-52ish). + * @see https://en.wikipedia.org/wiki/ISO_week_date + * @example DateTime.local(2017, 5, 25).weekNumber //=> 21 + * @type {number} + */ - /** - * The base implementation of `_.isNaN` without support for number objects. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. - */ - function baseIsNaN(value) { - return value !== value; - } + }, { + key: "weekNumber", + get: function get() { + return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN; + } + /** + * Get the day of the week. + * 1 is Monday and 7 is Sunday + * @see https://en.wikipedia.org/wiki/ISO_week_date + * @example DateTime.local(2014, 11, 31).weekday //=> 4 + * @type {number} + */ - /** - * The base implementation of `_.mean` and `_.meanBy` without support for - * iteratee shorthands. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {number} Returns the mean. - */ - function baseMean(array, iteratee) { - var length = array == null ? 0 : array.length; - return length ? (baseSum(array, iteratee) / length) : NAN; - } + }, { + key: "weekday", + get: function get() { + return this.isValid ? possiblyCachedWeekData(this).weekday : NaN; + } + /** + * Get the ordinal (meaning the day of the year) + * @example DateTime.local(2017, 5, 25).ordinal //=> 145 + * @type {number|DateTime} + */ - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } + }, { + key: "ordinal", + get: function get() { + return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN; + } + /** + * Get the human readable short month name, such as 'Oct'. + * Defaults to the system's locale if no locale has been specified + * @example DateTime.local(2017, 10, 30).monthShort //=> Oct + * @type {string} + */ - /** - * The base implementation of `_.propertyOf` without support for deep paths. - * - * @private - * @param {Object} object The object to query. - * @returns {Function} Returns the new accessor function. - */ - function basePropertyOf(object) { - return function(key) { - return object == null ? undefined : object[key]; - }; - } + }, { + key: "monthShort", + get: function get() { + return this.isValid ? Info.months("short", { + locObj: this.loc + })[this.month - 1] : null; + } + /** + * Get the human readable long month name, such as 'October'. + * Defaults to the system's locale if no locale has been specified + * @example DateTime.local(2017, 10, 30).monthLong //=> October + * @type {string} + */ - /** - * The base implementation of `_.reduce` and `_.reduceRight`, without support - * for iteratee shorthands, which iterates over `collection` using `eachFunc`. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {*} accumulator The initial value. - * @param {boolean} initAccum Specify using the first or last element of - * `collection` as the initial value. - * @param {Function} eachFunc The function to iterate over `collection`. - * @returns {*} Returns the accumulated value. - */ - function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { - eachFunc(collection, function(value, index, collection) { - accumulator = initAccum - ? (initAccum = false, value) - : iteratee(accumulator, value, index, collection); - }); - return accumulator; - } + }, { + key: "monthLong", + get: function get() { + return this.isValid ? Info.months("long", { + locObj: this.loc + })[this.month - 1] : null; + } + /** + * Get the human readable short weekday, such as 'Mon'. + * Defaults to the system's locale if no locale has been specified + * @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon + * @type {string} + */ - /** - * The base implementation of `_.sortBy` which uses `comparer` to define the - * sort order of `array` and replaces criteria objects with their corresponding - * values. - * - * @private - * @param {Array} array The array to sort. - * @param {Function} comparer The function to define sort order. - * @returns {Array} Returns `array`. - */ - function baseSortBy(array, comparer) { - var length = array.length; + }, { + key: "weekdayShort", + get: function get() { + return this.isValid ? Info.weekdays("short", { + locObj: this.loc + })[this.weekday - 1] : null; + } + /** + * Get the human readable long weekday, such as 'Monday'. + * Defaults to the system's locale if no locale has been specified + * @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday + * @type {string} + */ - array.sort(comparer); - while (length--) { - array[length] = array[length].value; + }, { + key: "weekdayLong", + get: function get() { + return this.isValid ? Info.weekdays("long", { + locObj: this.loc + })[this.weekday - 1] : null; } - return array; - } + /** + * Get the UTC offset of this DateTime in minutes + * @example DateTime.now().offset //=> -240 + * @example DateTime.utc().offset //=> 0 + * @type {number} + */ - /** - * The base implementation of `_.sum` and `_.sumBy` without support for - * iteratee shorthands. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {number} Returns the sum. - */ - function baseSum(array, iteratee) { - var result, - index = -1, - length = array.length; + }, { + key: "offset", + get: function get() { + return this.isValid ? +this.o : NaN; + } + /** + * Get the short human name for the zone's current offset, for example "EST" or "EDT". + * Defaults to the system's locale if no locale has been specified + * @type {string} + */ - while (++index < length) { - var current = iteratee(array[index]); - if (current !== undefined) { - result = result === undefined ? current : (result + current); + }, { + key: "offsetNameShort", + get: function get() { + if (this.isValid) { + return this.zone.offsetName(this.ts, { + format: "short", + locale: this.locale + }); + } else { + return null; } } - return result; - } - - /** - * The base implementation of `_.times` without support for iteratee shorthands - * or max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ - function baseTimes(n, iteratee) { - var index = -1, - result = Array(n); + /** + * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time". + * Defaults to the system's locale if no locale has been specified + * @type {string} + */ - while (++index < n) { - result[index] = iteratee(index); + }, { + key: "offsetNameLong", + get: function get() { + if (this.isValid) { + return this.zone.offsetName(this.ts, { + format: "long", + locale: this.locale + }); + } else { + return null; + } } - return result; - } + /** + * Get whether this zone's offset ever changes, as in a DST. + * @type {boolean} + */ - /** - * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array - * of key-value pairs for `object` corresponding to the property names of `props`. - * - * @private - * @param {Object} object The object to query. - * @param {Array} props The property names to get values for. - * @returns {Object} Returns the key-value pairs. - */ - function baseToPairs(object, props) { - return arrayMap(props, function(key) { - return [key, object[key]]; - }); - } + }, { + key: "isOffsetFixed", + get: function get() { + return this.isValid ? this.zone.universal : null; + } + /** + * Get whether the DateTime is in a DST. + * @type {boolean} + */ - /** - * The base implementation of `_.trim`. - * - * @private - * @param {string} string The string to trim. - * @returns {string} Returns the trimmed string. - */ - function baseTrim(string) { - return string - ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') - : string; - } + }, { + key: "isInDST", + get: function get() { + if (this.isOffsetFixed) { + return false; + } else { + return this.offset > this.set({ + month: 1 + }).offset || this.offset > this.set({ + month: 5 + }).offset; + } + } + /** + * Returns true if this DateTime is in a leap year, false otherwise + * @example DateTime.local(2016).isInLeapYear //=> true + * @example DateTime.local(2013).isInLeapYear //=> false + * @type {boolean} + */ - /** - * The base implementation of `_.unary` without support for storing metadata. - * - * @private - * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new capped function. - */ - function baseUnary(func) { - return function(value) { - return func(value); - }; - } + }, { + key: "isInLeapYear", + get: function get() { + return isLeapYear(this.year); + } + /** + * Returns the number of days in this DateTime's month + * @example DateTime.local(2016, 2).daysInMonth //=> 29 + * @example DateTime.local(2016, 3).daysInMonth //=> 31 + * @type {number} + */ - /** - * The base implementation of `_.values` and `_.valuesIn` which creates an - * array of `object` property values corresponding to the property names - * of `props`. - * - * @private - * @param {Object} object The object to query. - * @param {Array} props The property names to get values for. - * @returns {Object} Returns the array of property values. - */ - function baseValues(object, props) { - return arrayMap(props, function(key) { - return object[key]; - }); - } + }, { + key: "daysInMonth", + get: function get() { + return daysInMonth(this.year, this.month); + } + /** + * Returns the number of days in this DateTime's year + * @example DateTime.local(2016).daysInYear //=> 366 + * @example DateTime.local(2013).daysInYear //=> 365 + * @type {number} + */ - /** - * Checks if a `cache` value for `key` exists. - * - * @private - * @param {Object} cache The cache to query. - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function cacheHas(cache, key) { - return cache.has(key); - } + }, { + key: "daysInYear", + get: function get() { + return this.isValid ? daysInYear(this.year) : NaN; + } + /** + * Returns the number of weeks in this DateTime's year + * @see https://en.wikipedia.org/wiki/ISO_week_date + * @example DateTime.local(2004).weeksInWeekYear //=> 53 + * @example DateTime.local(2013).weeksInWeekYear //=> 52 + * @type {number} + */ - /** - * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol - * that is not found in the character symbols. - * - * @private - * @param {Array} strSymbols The string symbols to inspect. - * @param {Array} chrSymbols The character symbols to find. - * @returns {number} Returns the index of the first unmatched string symbol. - */ - function charsStartIndex(strSymbols, chrSymbols) { - var index = -1, - length = strSymbols.length; + }, { + key: "weeksInWeekYear", + get: function get() { + return this.isValid ? weeksInWeekYear(this.weekYear) : NaN; + } + }], [{ + key: "DATE_SHORT", + get: function get() { + return DATE_SHORT; + } + /** + * {@link toLocaleString} format like 'Oct 14, 1983' + * @type {Object} + */ - while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} - return index; - } + }, { + key: "DATE_MED", + get: function get() { + return DATE_MED; + } + /** + * {@link toLocaleString} format like 'Fri, Oct 14, 1983' + * @type {Object} + */ - /** - * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol - * that is not found in the character symbols. - * - * @private - * @param {Array} strSymbols The string symbols to inspect. - * @param {Array} chrSymbols The character symbols to find. - * @returns {number} Returns the index of the last unmatched string symbol. - */ - function charsEndIndex(strSymbols, chrSymbols) { - var index = strSymbols.length; + }, { + key: "DATE_MED_WITH_WEEKDAY", + get: function get() { + return DATE_MED_WITH_WEEKDAY; + } + /** + * {@link toLocaleString} format like 'October 14, 1983' + * @type {Object} + */ - while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} - return index; - } + }, { + key: "DATE_FULL", + get: function get() { + return DATE_FULL; + } + /** + * {@link toLocaleString} format like 'Tuesday, October 14, 1983' + * @type {Object} + */ - /** - * Gets the number of `placeholder` occurrences in `array`. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} placeholder The placeholder to search for. - * @returns {number} Returns the placeholder count. - */ - function countHolders(array, placeholder) { - var length = array.length, - result = 0; + }, { + key: "DATE_HUGE", + get: function get() { + return DATE_HUGE; + } + /** + * {@link toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - while (length--) { - if (array[length] === placeholder) { - ++result; - } + }, { + key: "TIME_SIMPLE", + get: function get() { + return TIME_SIMPLE; } - return result; - } + /** + * {@link toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A - * letters to basic Latin letters. - * - * @private - * @param {string} letter The matched letter to deburr. - * @returns {string} Returns the deburred letter. - */ - var deburrLetter = basePropertyOf(deburredLetters); + }, { + key: "TIME_WITH_SECONDS", + get: function get() { + return TIME_WITH_SECONDS; + } + /** + * {@link toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Used by `_.escape` to convert characters to HTML entities. - * - * @private - * @param {string} chr The matched character to escape. - * @returns {string} Returns the escaped character. - */ - var escapeHtmlChar = basePropertyOf(htmlEscapes); + }, { + key: "TIME_WITH_SHORT_OFFSET", + get: function get() { + return TIME_WITH_SHORT_OFFSET; + } + /** + * {@link toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Used by `_.template` to escape characters for inclusion in compiled string literals. - * - * @private - * @param {string} chr The matched character to escape. - * @returns {string} Returns the escaped character. - */ - function escapeStringChar(chr) { - return '\\' + stringEscapes[chr]; - } + }, { + key: "TIME_WITH_LONG_OFFSET", + get: function get() { + return TIME_WITH_LONG_OFFSET; + } + /** + * {@link toLocaleString} format like '09:30', always 24-hour. + * @type {Object} + */ - /** - * Gets the value at `key` of `object`. - * - * @private - * @param {Object} [object] The object to query. - * @param {string} key The key of the property to get. - * @returns {*} Returns the property value. - */ - function getValue(object, key) { - return object == null ? undefined : object[key]; - } + }, { + key: "TIME_24_SIMPLE", + get: function get() { + return TIME_24_SIMPLE; + } + /** + * {@link toLocaleString} format like '09:30:23', always 24-hour. + * @type {Object} + */ - /** - * Checks if `string` contains Unicode symbols. - * - * @private - * @param {string} string The string to inspect. - * @returns {boolean} Returns `true` if a symbol is found, else `false`. - */ - function hasUnicode(string) { - return reHasUnicode.test(string); - } + }, { + key: "TIME_24_WITH_SECONDS", + get: function get() { + return TIME_24_WITH_SECONDS; + } + /** + * {@link toLocaleString} format like '09:30:23 EDT', always 24-hour. + * @type {Object} + */ - /** - * Checks if `string` contains a word composed of Unicode symbols. - * - * @private - * @param {string} string The string to inspect. - * @returns {boolean} Returns `true` if a word is found, else `false`. - */ - function hasUnicodeWord(string) { - return reHasUnicodeWord.test(string); - } + }, { + key: "TIME_24_WITH_SHORT_OFFSET", + get: function get() { + return TIME_24_WITH_SHORT_OFFSET; + } + /** + * {@link toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour. + * @type {Object} + */ - /** - * Converts `iterator` to an array. - * - * @private - * @param {Object} iterator The iterator to convert. - * @returns {Array} Returns the converted array. - */ - function iteratorToArray(iterator) { - var data, - result = []; + }, { + key: "TIME_24_WITH_LONG_OFFSET", + get: function get() { + return TIME_24_WITH_LONG_OFFSET; + } + /** + * {@link toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - while (!(data = iterator.next()).done) { - result.push(data.value); + }, { + key: "DATETIME_SHORT", + get: function get() { + return DATETIME_SHORT; } - return result; - } + /** + * {@link toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Converts `map` to its key-value pairs. - * - * @private - * @param {Object} map The map to convert. - * @returns {Array} Returns the key-value pairs. - */ - function mapToArray(map) { - var index = -1, - result = Array(map.size); + }, { + key: "DATETIME_SHORT_WITH_SECONDS", + get: function get() { + return DATETIME_SHORT_WITH_SECONDS; + } + /** + * {@link toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - map.forEach(function(value, key) { - result[++index] = [key, value]; - }); - return result; - } + }, { + key: "DATETIME_MED", + get: function get() { + return DATETIME_MED; + } + /** + * {@link toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Creates a unary function that invokes `func` with its argument transformed. - * - * @private - * @param {Function} func The function to wrap. - * @param {Function} transform The argument transform. - * @returns {Function} Returns the new function. - */ - function overArg(func, transform) { - return function(arg) { - return func(transform(arg)); - }; - } + }, { + key: "DATETIME_MED_WITH_SECONDS", + get: function get() { + return DATETIME_MED_WITH_SECONDS; + } + /** + * {@link toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Replaces all `placeholder` elements in `array` with an internal placeholder - * and returns an array of their indexes. - * - * @private - * @param {Array} array The array to modify. - * @param {*} placeholder The placeholder to replace. - * @returns {Array} Returns the new array of placeholder indexes. - */ - function replaceHolders(array, placeholder) { - var index = -1, - length = array.length, - resIndex = 0, - result = []; + }, { + key: "DATETIME_MED_WITH_WEEKDAY", + get: function get() { + return DATETIME_MED_WITH_WEEKDAY; + } + /** + * {@link toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is. + * @type {Object} + */ - while (++index < length) { - var value = array[index]; - if (value === placeholder || value === PLACEHOLDER) { - array[index] = PLACEHOLDER; - result[resIndex++] = index; - } + }, { + key: "DATETIME_FULL", + get: function get() { + return DATETIME_FULL; } - return result; - } + /** + * {@link toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Converts `set` to an array of its values. - * - * @private - * @param {Object} set The set to convert. - * @returns {Array} Returns the values. - */ - function setToArray(set) { - var index = -1, - result = Array(set.size); + }, { + key: "DATETIME_FULL_WITH_SECONDS", + get: function get() { + return DATETIME_FULL_WITH_SECONDS; + } + /** + * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is. + * @type {Object} + */ - set.forEach(function(value) { - result[++index] = value; - }); - return result; - } + }, { + key: "DATETIME_HUGE", + get: function get() { + return DATETIME_HUGE; + } + /** + * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is. + * @type {Object} + */ - /** - * Converts `set` to its value-value pairs. - * - * @private - * @param {Object} set The set to convert. - * @returns {Array} Returns the value-value pairs. - */ - function setToPairs(set) { - var index = -1, - result = Array(set.size); + }, { + key: "DATETIME_HUGE_WITH_SECONDS", + get: function get() { + return DATETIME_HUGE_WITH_SECONDS; + } + }]); - set.forEach(function(value) { - result[++index] = [value, value]; - }); - return result; + return DateTime; +}(); +function friendlyDateTime(dateTimeish) { + if (DateTime.isDateTime(dateTimeish)) { + return dateTimeish; + } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) { + return DateTime.fromJSDate(dateTimeish); + } else if (dateTimeish && typeof dateTimeish === "object") { + return DateTime.fromObject(dateTimeish); + } else { + throw new InvalidArgumentError("Unknown datetime argument: " + dateTimeish + ", of type " + typeof dateTimeish); } +} - /** - * A specialized version of `_.indexOf` which performs strict equality - * comparisons of values, i.e. `===`. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} fromIndex The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function strictIndexOf(array, value, fromIndex) { - var index = fromIndex - 1, - length = array.length; +var VERSION = "1.28.1"; - while (++index < length) { - if (array[index] === value) { - return index; - } - } - return -1; - } +exports.DateTime = DateTime; +exports.Duration = Duration; +exports.FixedOffsetZone = FixedOffsetZone; +exports.IANAZone = IANAZone; +exports.Info = Info; +exports.Interval = Interval; +exports.InvalidZone = InvalidZone; +exports.LocalZone = LocalZone; +exports.Settings = Settings; +exports.VERSION = VERSION; +exports.Zone = Zone; - /** - * A specialized version of `_.lastIndexOf` which performs strict equality - * comparisons of values, i.e. `===`. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} fromIndex The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function strictLastIndexOf(array, value, fromIndex) { - var index = fromIndex + 1; - while (index--) { - if (array[index] === value) { - return index; - } - } - return index; - } - /** - * Gets the number of symbols in `string`. - * - * @private - * @param {string} string The string to inspect. - * @returns {number} Returns the string size. - */ - function stringSize(string) { - return hasUnicode(string) - ? unicodeSize(string) - : asciiSize(string); - } +},{}],110:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Converts `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function stringToArray(string) { - return hasUnicode(string) - ? unicodeToArray(string) - : asciiToArray(string); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace - * character of `string`. - * - * @private - * @param {string} string The string to inspect. - * @returns {number} Returns the index of the last non-whitespace character. - */ - function trimmedEndIndex(string) { - var index = string.length; - while (index-- && reWhitespace.test(string.charAt(index))) {} - return index; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Used by `_.unescape` to convert HTML entities to characters. - * - * @private - * @param {string} chr The matched character to unescape. - * @returns {string} Returns the unescaped character. - */ - var unescapeHtmlChar = basePropertyOf(htmlUnescapes); +const AdverseEventSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + severity: Code, + facilityLocation: FacilityLocationSchema, + type: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Adverse Event' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.120' }, + qdmCategory: { type: String, default: 'adverse_event' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::AdverseEvent' }, - /** - * Gets the size of a Unicode `string`. - * - * @private - * @param {string} string The string inspect. - * @returns {number} Returns the string size. - */ - function unicodeSize(string) { - var result = reUnicode.lastIndex = 0; - while (reUnicode.test(string)) { - ++result; - } - return result; - } +}); - /** - * Converts a Unicode `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function unicodeToArray(string) { - return string.match(reUnicode) || []; +module.exports.AdverseEventSchema = AdverseEventSchema; +class AdverseEvent extends mongoose.Document { + constructor(object) { + super(object, AdverseEventSchema); + this._type = 'QDM::AdverseEvent'; } +} - /** - * Splits a Unicode `string` into an array of its words. - * - * @private - * @param {string} The string to inspect. - * @returns {Array} Returns the words of `string`. - */ - function unicodeWords(string) { - return string.match(reUnicodeWord) || []; - } +module.exports.AdverseEvent = AdverseEvent; - /*--------------------------------------------------------------------------*/ - /** - * Create a new pristine `lodash` function using the `context` object. - * - * @static - * @memberOf _ - * @since 1.1.0 - * @category Util - * @param {Object} [context=root] The context object. - * @returns {Function} Returns a new `lodash` function. - * @example - * - * _.mixin({ 'foo': _.constant('foo') }); - * - * var lodash = _.runInContext(); - * lodash.mixin({ 'bar': lodash.constant('bar') }); - * - * _.isFunction(_.foo); - * // => true - * _.isFunction(_.bar); - * // => false - * - * lodash.isFunction(lodash.foo); - * // => false - * lodash.isFunction(lodash.bar); - * // => true - * - * // Create a suped-up `defer` in Node.js. - * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; - */ - var runInContext = (function runInContext(context) { - context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],111:[function(require,module,exports){ +module.exports.Identifier = require('./attributes/Identifier.js').Identifier; +module.exports.IdentifierSchema = require('./attributes/Identifier.js').IdentifierSchema; +module.exports.Entity = require('./attributes/Entity.js').Entity; +module.exports.EntitySchema = require('./attributes/Entity.js').EntitySchema; +module.exports.PatientEntity = require('./attributes/PatientEntity.js').PatientEntity; +module.exports.PatientEntitySchema = require('./attributes/PatientEntity.js').PatientEntitySchema; +module.exports.CarePartner = require('./attributes/CarePartner.js').CarePartner; +module.exports.CarePartnerSchema = require('./attributes/CarePartner.js').CarePartnerSchema; +module.exports.RelatedPerson = require('./RelatedPerson.js').RelatedPerson; +module.exports.RelatedPersonSchema = require('./RelatedPerson.js').RelatedPersonSchema; +module.exports.Practitioner = require('./attributes/Practitioner.js').Practitioner; +module.exports.PractitionerSchema = require('./attributes/Practitioner.js').PractitionerSchema; +module.exports.Organization = require('./attributes/Organization.js').Organization; +module.exports.OrganizationSchema = require('./attributes/Organization.js').OrganizationSchema; +module.exports.Location = require('./attributes/Location.js').Location; +module.exports.LocationSchema = require('./attributes/Location.js').LocationSchema; +module.exports.PhysicalExamOrder = require('./PhysicalExamOrder.js').PhysicalExamOrder; +module.exports.PhysicalExamOrderSchema = require('./PhysicalExamOrder.js').PhysicalExamOrderSchema; +module.exports.Participation = require('./Participation.js').Participation; +module.exports.ParticipationSchema = require('./Participation.js').ParticipationSchema; +module.exports.PatientCharacteristicSex = require('./PatientCharacteristicSex.js').PatientCharacteristicSex; +module.exports.PatientCharacteristicSexSchema = require('./PatientCharacteristicSex.js').PatientCharacteristicSexSchema; +module.exports.CareGoal = require('./CareGoal.js').CareGoal; +module.exports.CareGoalSchema = require('./CareGoal.js').CareGoalSchema; +module.exports.PatientCharacteristic = require('./PatientCharacteristic.js').PatientCharacteristic; +module.exports.PatientCharacteristicSchema = require('./PatientCharacteristic.js').PatientCharacteristicSchema; +module.exports.PatientCharacteristicEthnicity = require('./PatientCharacteristicEthnicity.js').PatientCharacteristicEthnicity; +module.exports.PatientCharacteristicEthnicitySchema = require('./PatientCharacteristicEthnicity.js').PatientCharacteristicEthnicitySchema; +module.exports.PatientCharacteristicRace = require('./PatientCharacteristicRace.js').PatientCharacteristicRace; +module.exports.PatientCharacteristicRaceSchema = require('./PatientCharacteristicRace.js').PatientCharacteristicRaceSchema; +module.exports.LaboratoryTestPerformed = require('./LaboratoryTestPerformed.js').LaboratoryTestPerformed; +module.exports.LaboratoryTestPerformedSchema = require('./LaboratoryTestPerformed.js').LaboratoryTestPerformedSchema; +module.exports.Symptom = require('./Symptom.js').Symptom; +module.exports.SymptomSchema = require('./Symptom.js').SymptomSchema; +module.exports.MedicationAdministered = require('./MedicationAdministered.js').MedicationAdministered; +module.exports.MedicationAdministeredSchema = require('./MedicationAdministered.js').MedicationAdministeredSchema; +module.exports.ProcedureRecommended = require('./ProcedureRecommended.js').ProcedureRecommended; +module.exports.ProcedureRecommendedSchema = require('./ProcedureRecommended.js').ProcedureRecommendedSchema; +module.exports.EncounterPerformed = require('./EncounterPerformed.js').EncounterPerformed; +module.exports.EncounterPerformedSchema = require('./EncounterPerformed.js').EncounterPerformedSchema; +module.exports.Diagnosis = require('./Diagnosis.js').Diagnosis; +module.exports.DiagnosisSchema = require('./Diagnosis.js').DiagnosisSchema; +module.exports.CommunicationPerformed = require('./CommunicationPerformed.js').CommunicationPerformed; +module.exports.CommunicationPerformedSchema = require('./CommunicationPerformed.js').CommunicationPerformedSchema; +module.exports.AssessmentPerformed = require('./AssessmentPerformed.js').AssessmentPerformed; +module.exports.AssessmentPerformedSchema = require('./AssessmentPerformed.js').AssessmentPerformedSchema; +module.exports.PatientCharacteristicClinicalTrialParticipant = require('./PatientCharacteristicClinicalTrialParticipant.js').PatientCharacteristicClinicalTrialParticipant; +module.exports.PatientCharacteristicClinicalTrialParticipantSchema = require('./PatientCharacteristicClinicalTrialParticipant.js').PatientCharacteristicClinicalTrialParticipantSchema; +module.exports.DeviceOrder = require('./DeviceOrder.js').DeviceOrder; +module.exports.DeviceOrderSchema = require('./DeviceOrder.js').DeviceOrderSchema; +module.exports.DiagnosticStudyPerformed = require('./DiagnosticStudyPerformed.js').DiagnosticStudyPerformed; +module.exports.DiagnosticStudyPerformedSchema = require('./DiagnosticStudyPerformed.js').DiagnosticStudyPerformedSchema; +module.exports.InterventionOrder = require('./InterventionOrder.js').InterventionOrder; +module.exports.InterventionOrderSchema = require('./InterventionOrder.js').InterventionOrderSchema; +module.exports.FamilyHistory = require('./FamilyHistory.js').FamilyHistory; +module.exports.FamilyHistorySchema = require('./FamilyHistory.js').FamilyHistorySchema; +module.exports.Component = require('./attributes/Component.js').Component; +module.exports.ComponentSchema = require('./attributes/Component.js').ComponentSchema; +module.exports.DiagnosisComponent = require('./attributes/DiagnosisComponent.js').DiagnosisComponent; +module.exports.DiagnosisComponentSchema = require('./attributes/DiagnosisComponent.js').DiagnosisComponentSchema; +module.exports.ResultComponent = require('./attributes/ResultComponent.js').ResultComponent; +module.exports.ResultComponentSchema = require('./attributes/ResultComponent.js').ResultComponentSchema; +module.exports.FacilityLocation = require('./attributes/FacilityLocation.js').FacilityLocation; +module.exports.FacilityLocationSchema = require('./attributes/FacilityLocation.js').FacilityLocationSchema; +module.exports.MedicationActive = require('./MedicationActive.js').MedicationActive; +module.exports.MedicationActiveSchema = require('./MedicationActive.js').MedicationActiveSchema; +module.exports.LaboratoryTestOrder = require('./LaboratoryTestOrder.js').LaboratoryTestOrder; +module.exports.LaboratoryTestOrderSchema = require('./LaboratoryTestOrder.js').LaboratoryTestOrderSchema; +module.exports.DiagnosticStudyOrder = require('./DiagnosticStudyOrder.js').DiagnosticStudyOrder; +module.exports.DiagnosticStudyOrderSchema = require('./DiagnosticStudyOrder.js').DiagnosticStudyOrderSchema; +module.exports.SubstanceOrder = require('./SubstanceOrder.js').SubstanceOrder; +module.exports.SubstanceOrderSchema = require('./SubstanceOrder.js').SubstanceOrderSchema; +module.exports.PatientCharacteristicPayer = require('./PatientCharacteristicPayer.js').PatientCharacteristicPayer; +module.exports.PatientCharacteristicPayerSchema = require('./PatientCharacteristicPayer.js').PatientCharacteristicPayerSchema; +module.exports.PatientCharacteristicExpired = require('./PatientCharacteristicExpired.js').PatientCharacteristicExpired; +module.exports.PatientCharacteristicExpiredSchema = require('./PatientCharacteristicExpired.js').PatientCharacteristicExpiredSchema; +module.exports.AssessmentOrder = require('./AssessmentOrder.js').AssessmentOrder; +module.exports.AssessmentOrderSchema = require('./AssessmentOrder.js').AssessmentOrderSchema; +module.exports.AssessmentRecommended = require('./AssessmentRecommended.js').AssessmentRecommended; +module.exports.AssessmentRecommendedSchema = require('./AssessmentRecommended.js').AssessmentRecommendedSchema; +module.exports.ImmunizationAdministered = require('./ImmunizationAdministered.js').ImmunizationAdministered; +module.exports.ImmunizationAdministeredSchema = require('./ImmunizationAdministered.js').ImmunizationAdministeredSchema; +module.exports.SubstanceAdministered = require('./SubstanceAdministered.js').SubstanceAdministered; +module.exports.SubstanceAdministeredSchema = require('./SubstanceAdministered.js').SubstanceAdministeredSchema; +module.exports.EncounterOrder = require('./EncounterOrder.js').EncounterOrder; +module.exports.EncounterOrderSchema = require('./EncounterOrder.js').EncounterOrderSchema; +module.exports.EncounterRecommended = require('./EncounterRecommended.js').EncounterRecommended; +module.exports.EncounterRecommendedSchema = require('./EncounterRecommended.js').EncounterRecommendedSchema; +module.exports.ProcedurePerformed = require('./ProcedurePerformed.js').ProcedurePerformed; +module.exports.ProcedurePerformedSchema = require('./ProcedurePerformed.js').ProcedurePerformedSchema; +module.exports.AllergyIntolerance = require('./AllergyIntolerance.js').AllergyIntolerance; +module.exports.AllergyIntoleranceSchema = require('./AllergyIntolerance.js').AllergyIntoleranceSchema; +module.exports.PhysicalExamRecommended = require('./PhysicalExamRecommended.js').PhysicalExamRecommended; +module.exports.PhysicalExamRecommendedSchema = require('./PhysicalExamRecommended.js').PhysicalExamRecommendedSchema; +module.exports.PatientCharacteristicBirthdate = require('./PatientCharacteristicBirthdate.js').PatientCharacteristicBirthdate; +module.exports.PatientCharacteristicBirthdateSchema = require('./PatientCharacteristicBirthdate.js').PatientCharacteristicBirthdateSchema; +module.exports.AdverseEvent = require('./AdverseEvent.js').AdverseEvent; +module.exports.AdverseEventSchema = require('./AdverseEvent.js').AdverseEventSchema; +module.exports.DeviceRecommended = require('./DeviceRecommended.js').DeviceRecommended; +module.exports.DeviceRecommendedSchema = require('./DeviceRecommended.js').DeviceRecommendedSchema; +module.exports.MedicationDischarge = require('./MedicationDischarge.js').MedicationDischarge; +module.exports.MedicationDischargeSchema = require('./MedicationDischarge.js').MedicationDischargeSchema; +module.exports.InterventionPerformed = require('./InterventionPerformed.js').InterventionPerformed; +module.exports.InterventionPerformedSchema = require('./InterventionPerformed.js').InterventionPerformedSchema; +module.exports.LaboratoryTestRecommended = require('./LaboratoryTestRecommended.js').LaboratoryTestRecommended; +module.exports.LaboratoryTestRecommendedSchema = require('./LaboratoryTestRecommended.js').LaboratoryTestRecommendedSchema; +module.exports.MedicationDispensed = require('./MedicationDispensed.js').MedicationDispensed; +module.exports.MedicationDispensedSchema = require('./MedicationDispensed.js').MedicationDispensedSchema; +module.exports.DiagnosticStudyRecommended = require('./DiagnosticStudyRecommended.js').DiagnosticStudyRecommended; +module.exports.DiagnosticStudyRecommendedSchema = require('./DiagnosticStudyRecommended.js').DiagnosticStudyRecommendedSchema; +module.exports.ImmunizationOrder = require('./ImmunizationOrder.js').ImmunizationOrder; +module.exports.ImmunizationOrderSchema = require('./ImmunizationOrder.js').ImmunizationOrderSchema; +module.exports.PatientCareExperience = require('./PatientCareExperience.js').PatientCareExperience; +module.exports.PatientCareExperienceSchema = require('./PatientCareExperience.js').PatientCareExperienceSchema; +module.exports.ProviderCareExperience = require('./ProviderCareExperience.js').ProviderCareExperience; +module.exports.ProviderCareExperienceSchema = require('./ProviderCareExperience.js').ProviderCareExperienceSchema; +module.exports.ProcedureOrder = require('./ProcedureOrder.js').ProcedureOrder; +module.exports.ProcedureOrderSchema = require('./ProcedureOrder.js').ProcedureOrderSchema; +module.exports.MedicationOrder = require('./MedicationOrder.js').MedicationOrder; +module.exports.MedicationOrderSchema = require('./MedicationOrder.js').MedicationOrderSchema; +module.exports.SubstanceRecommended = require('./SubstanceRecommended.js').SubstanceRecommended; +module.exports.SubstanceRecommendedSchema = require('./SubstanceRecommended.js').SubstanceRecommendedSchema; +module.exports.InterventionRecommended = require('./InterventionRecommended.js').InterventionRecommended; +module.exports.InterventionRecommendedSchema = require('./InterventionRecommended.js').InterventionRecommendedSchema; +module.exports.PhysicalExamPerformed = require('./PhysicalExamPerformed.js').PhysicalExamPerformed; +module.exports.PhysicalExamPerformedSchema = require('./PhysicalExamPerformed.js').PhysicalExamPerformedSchema; +module.exports.QDMPatient = require('./QDMPatient.js').QDMPatient; +module.exports.QDMPatientSchema = require('./QDMPatient.js').QDMPatientSchema; - /** Built-in constructor references. */ - var Array = context.Array, - Date = context.Date, - Error = context.Error, - Function = context.Function, - Math = context.Math, - Object = context.Object, - RegExp = context.RegExp, - String = context.String, - TypeError = context.TypeError; +},{"./AdverseEvent.js":110,"./AllergyIntolerance.js":112,"./AssessmentOrder.js":113,"./AssessmentPerformed.js":114,"./AssessmentRecommended.js":115,"./CareGoal.js":116,"./CommunicationPerformed.js":117,"./DeviceOrder.js":118,"./DeviceRecommended.js":119,"./Diagnosis.js":120,"./DiagnosticStudyOrder.js":121,"./DiagnosticStudyPerformed.js":122,"./DiagnosticStudyRecommended.js":123,"./EncounterOrder.js":124,"./EncounterPerformed.js":125,"./EncounterRecommended.js":126,"./FamilyHistory.js":127,"./ImmunizationAdministered.js":128,"./ImmunizationOrder.js":129,"./InterventionOrder.js":130,"./InterventionPerformed.js":131,"./InterventionRecommended.js":132,"./LaboratoryTestOrder.js":133,"./LaboratoryTestPerformed.js":134,"./LaboratoryTestRecommended.js":135,"./MedicationActive.js":136,"./MedicationAdministered.js":137,"./MedicationDischarge.js":138,"./MedicationDispensed.js":139,"./MedicationOrder.js":140,"./Participation.js":141,"./PatientCareExperience.js":142,"./PatientCharacteristic.js":143,"./PatientCharacteristicBirthdate.js":144,"./PatientCharacteristicClinicalTrialParticipant.js":145,"./PatientCharacteristicEthnicity.js":146,"./PatientCharacteristicExpired.js":147,"./PatientCharacteristicPayer.js":148,"./PatientCharacteristicRace.js":149,"./PatientCharacteristicSex.js":150,"./PhysicalExamOrder.js":151,"./PhysicalExamPerformed.js":152,"./PhysicalExamRecommended.js":153,"./ProcedureOrder.js":154,"./ProcedurePerformed.js":155,"./ProcedureRecommended.js":156,"./ProviderCareExperience.js":157,"./QDMPatient.js":158,"./RelatedPerson.js":159,"./SubstanceAdministered.js":161,"./SubstanceOrder.js":162,"./SubstanceRecommended.js":163,"./Symptom.js":164,"./attributes/CarePartner.js":165,"./attributes/Component.js":166,"./attributes/DiagnosisComponent.js":167,"./attributes/Entity.js":168,"./attributes/FacilityLocation.js":169,"./attributes/Identifier.js":170,"./attributes/Location.js":171,"./attributes/Organization.js":172,"./attributes/PatientEntity.js":173,"./attributes/Practitioner.js":174,"./attributes/ResultComponent.js":175}],112:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** Used for built-in method references. */ - var arrayProto = Array.prototype, - funcProto = Function.prototype, - objectProto = Object.prototype; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** Used to detect overreaching core-js shims. */ - var coreJsData = context['__core-js_shared__']; - /** Used to resolve the decompiled source of functions. */ - var funcToString = funcProto.toString; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; +const AllergyIntoleranceSchema = DataElementSchema({ + authorDatetime: DateTime, + prevalencePeriod: Interval, + type: Code, + severity: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Allergy/Intolerance' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.119' }, + qdmCategory: { type: String, default: 'allergy' }, + qdmStatus: { type: String, default: 'intolerance' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::AllergyIntolerance' }, - /** Used to generate unique IDs. */ - var idCounter = 0; +}); - /** Used to detect methods masquerading as native. */ - var maskSrcKey = (function() { - var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); - return uid ? ('Symbol(src)_1.' + uid) : ''; - }()); +module.exports.AllergyIntoleranceSchema = AllergyIntoleranceSchema; +class AllergyIntolerance extends mongoose.Document { + constructor(object) { + super(object, AllergyIntoleranceSchema); + this._type = 'QDM::AllergyIntolerance'; + } +} - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var nativeObjectToString = objectProto.toString; +module.exports.AllergyIntolerance = AllergyIntolerance; - /** Used to infer the `Object` constructor. */ - var objectCtorString = funcToString.call(Object); - /** Used to restore the original `_` reference in `_.noConflict`. */ - var oldDash = root._; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],113:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** Used to detect if a method is native. */ - var reIsNative = RegExp('^' + - funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') - .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' - ); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** Built-in value references. */ - var Buffer = moduleExports ? context.Buffer : undefined, - Symbol = context.Symbol, - Uint8Array = context.Uint8Array, - allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined, - getPrototype = overArg(Object.getPrototypeOf, Object), - objectCreate = Object.create, - propertyIsEnumerable = objectProto.propertyIsEnumerable, - splice = arrayProto.splice, - spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined, - symIterator = Symbol ? Symbol.iterator : undefined, - symToStringTag = Symbol ? Symbol.toStringTag : undefined; - var defineProperty = (function() { - try { - var func = getNative(Object, 'defineProperty'); - func({}, '', {}); - return func; - } catch (e) {} - }()); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** Mocked built-ins. */ - var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, - ctxNow = Date && Date.now !== root.Date.now && Date.now, - ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; +const AssessmentOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + negationRationale: Code, + reason: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Assessment, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.131' }, + qdmCategory: { type: String, default: 'assessment' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::AssessmentOrder' }, - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeCeil = Math.ceil, - nativeFloor = Math.floor, - nativeGetSymbols = Object.getOwnPropertySymbols, - nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, - nativeIsFinite = context.isFinite, - nativeJoin = arrayProto.join, - nativeKeys = overArg(Object.keys, Object), - nativeMax = Math.max, - nativeMin = Math.min, - nativeNow = Date.now, - nativeParseInt = context.parseInt, - nativeRandom = Math.random, - nativeReverse = arrayProto.reverse; +}); - /* Built-in method references that are verified to be native. */ - var DataView = getNative(context, 'DataView'), - Map = getNative(context, 'Map'), - Promise = getNative(context, 'Promise'), - Set = getNative(context, 'Set'), - WeakMap = getNative(context, 'WeakMap'), - nativeCreate = getNative(Object, 'create'); +module.exports.AssessmentOrderSchema = AssessmentOrderSchema; +class AssessmentOrder extends mongoose.Document { + constructor(object) { + super(object, AssessmentOrderSchema); + this._type = 'QDM::AssessmentOrder'; + } +} - /** Used to store function metadata. */ - var metaMap = WeakMap && new WeakMap; +module.exports.AssessmentOrder = AssessmentOrder; - /** Used to lookup unminified function names. */ - var realNames = {}; - /** Used to detect maps, sets, and weakmaps. */ - var dataViewCtorString = toSource(DataView), - mapCtorString = toSource(Map), - promiseCtorString = toSource(Promise), - setCtorString = toSource(Set), - weakMapCtorString = toSource(WeakMap); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],114:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** Used to convert symbols to primitives and strings. */ - var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolValueOf = symbolProto ? symbolProto.valueOf : undefined, - symbolToString = symbolProto ? symbolProto.toString : undefined; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /*------------------------------------------------------------------------*/ - /** - * Creates a `lodash` object which wraps `value` to enable implicit method - * chain sequences. Methods that operate on and return arrays, collections, - * and functions can be chained together. Methods that retrieve a single value - * or may return a primitive value will automatically end the chain sequence - * and return the unwrapped value. Otherwise, the value must be unwrapped - * with `_#value`. - * - * Explicit chain sequences, which must be unwrapped with `_#value`, may be - * enabled using `_.chain`. - * - * The execution of chained methods is lazy, that is, it's deferred until - * `_#value` is implicitly or explicitly called. - * - * Lazy evaluation allows several methods to support shortcut fusion. - * Shortcut fusion is an optimization to merge iteratee calls; this avoids - * the creation of intermediate arrays and can greatly reduce the number of - * iteratee executions. Sections of a chain sequence qualify for shortcut - * fusion if the section is applied to an array and iteratees accept only - * one argument. The heuristic for whether a section qualifies for shortcut - * fusion is subject to change. - * - * Chaining is supported in custom builds as long as the `_#value` method is - * directly or indirectly included in the build. - * - * In addition to lodash methods, wrappers have `Array` and `String` methods. - * - * The wrapper `Array` methods are: - * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` - * - * The wrapper `String` methods are: - * `replace` and `split` - * - * The wrapper methods that support shortcut fusion are: - * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, - * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` - * - * The chainable wrapper methods are: - * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, - * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, - * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, - * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, - * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, - * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, - * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, - * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, - * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, - * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, - * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, - * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, - * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, - * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, - * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, - * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, - * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, - * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, - * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, - * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, - * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, - * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, - * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, - * `zipObject`, `zipObjectDeep`, and `zipWith` - * - * The wrapper methods that are **not** chainable by default are: - * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, - * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, - * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, - * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, - * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, - * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, - * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, - * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, - * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, - * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, - * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, - * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, - * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, - * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, - * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, - * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, - * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, - * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, - * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, - * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, - * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, - * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, - * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, - * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, - * `upperFirst`, `value`, and `words` - * - * @name _ - * @constructor - * @category Seq - * @param {*} value The value to wrap in a `lodash` instance. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * function square(n) { - * return n * n; - * } - * - * var wrapped = _([1, 2, 3]); - * - * // Returns an unwrapped value. - * wrapped.reduce(_.add); - * // => 6 - * - * // Returns a wrapped value. - * var squares = wrapped.map(square); - * - * _.isArray(squares); - * // => false - * - * _.isArray(squares.value()); - * // => true - */ - function lodash(value) { - if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { - if (value instanceof LodashWrapper) { - return value; - } - if (hasOwnProperty.call(value, '__wrapped__')) { - return wrapperClone(value); - } - } - return new LodashWrapper(value); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.create` without support for assigning - * properties to the created object. - * - * @private - * @param {Object} proto The object to inherit from. - * @returns {Object} Returns the new object. - */ - var baseCreate = (function() { - function object() {} - return function(proto) { - if (!isObject(proto)) { - return {}; - } - if (objectCreate) { - return objectCreate(proto); - } - object.prototype = proto; - var result = new object; - object.prototype = undefined; - return result; - }; - }()); +const AssessmentPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + negationRationale: Code, + reason: Code, + method: Code, + result: Any, + interpretation: Code, + components: [ComponentSchema], + relatedTo: [String], + performer: [AnyEntity], + qdmTitle: { type: String, default: 'Assessment, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.117' }, + qdmCategory: { type: String, default: 'assessment' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::AssessmentPerformed' }, - /** - * The function whose prototype chain sequence wrappers inherit from. - * - * @private - */ - function baseLodash() { - // No operation performed. - } +}); - /** - * The base constructor for creating `lodash` wrapper objects. - * - * @private - * @param {*} value The value to wrap. - * @param {boolean} [chainAll] Enable explicit method chain sequences. - */ - function LodashWrapper(value, chainAll) { - this.__wrapped__ = value; - this.__actions__ = []; - this.__chain__ = !!chainAll; - this.__index__ = 0; - this.__values__ = undefined; - } +module.exports.AssessmentPerformedSchema = AssessmentPerformedSchema; +class AssessmentPerformed extends mongoose.Document { + constructor(object) { + super(object, AssessmentPerformedSchema); + this._type = 'QDM::AssessmentPerformed'; + } +} - /** - * By default, the template delimiters used by lodash are like those in - * embedded Ruby (ERB) as well as ES2015 template strings. Change the - * following template settings to use alternative delimiters. - * - * @static - * @memberOf _ - * @type {Object} - */ - lodash.templateSettings = { +module.exports.AssessmentPerformed = AssessmentPerformed; - /** - * Used to detect `data` property values to be HTML-escaped. - * - * @memberOf _.templateSettings - * @type {RegExp} - */ - 'escape': reEscape, - /** - * Used to detect code to be evaluated. - * - * @memberOf _.templateSettings - * @type {RegExp} - */ - 'evaluate': reEvaluate, +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],115:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Used to detect `data` property values to inject. - * - * @memberOf _.templateSettings - * @type {RegExp} - */ - 'interpolate': reInterpolate, +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Used to reference the data object in the template text. - * - * @memberOf _.templateSettings - * @type {string} - */ - 'variable': '', - /** - * Used to import variables into the compiled template. - * - * @memberOf _.templateSettings - * @type {Object} - */ - 'imports': { +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * A reference to the `lodash` function. - * - * @memberOf _.templateSettings.imports - * @type {Function} - */ - '_': lodash - } - }; +const AssessmentRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + negationRationale: Code, + reason: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Assessment, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.118' }, + qdmCategory: { type: String, default: 'assessment' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::AssessmentRecommended' }, - // Ensure wrappers are instances of `baseLodash`. - lodash.prototype = baseLodash.prototype; - lodash.prototype.constructor = lodash; +}); - LodashWrapper.prototype = baseCreate(baseLodash.prototype); - LodashWrapper.prototype.constructor = LodashWrapper; +module.exports.AssessmentRecommendedSchema = AssessmentRecommendedSchema; +class AssessmentRecommended extends mongoose.Document { + constructor(object) { + super(object, AssessmentRecommendedSchema); + this._type = 'QDM::AssessmentRecommended'; + } +} - /*------------------------------------------------------------------------*/ +module.exports.AssessmentRecommended = AssessmentRecommended; - /** - * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. - * - * @private - * @constructor - * @param {*} value The value to wrap. - */ - function LazyWrapper(value) { - this.__wrapped__ = value; - this.__actions__ = []; - this.__dir__ = 1; - this.__filtered__ = false; - this.__iteratees__ = []; - this.__takeCount__ = MAX_ARRAY_LENGTH; - this.__views__ = []; - } - /** - * Creates a clone of the lazy wrapper object. - * - * @private - * @name clone - * @memberOf LazyWrapper - * @returns {Object} Returns the cloned `LazyWrapper` object. - */ - function lazyClone() { - var result = new LazyWrapper(this.__wrapped__); - result.__actions__ = copyArray(this.__actions__); - result.__dir__ = this.__dir__; - result.__filtered__ = this.__filtered__; - result.__iteratees__ = copyArray(this.__iteratees__); - result.__takeCount__ = this.__takeCount__; - result.__views__ = copyArray(this.__views__); - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],116:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Reverses the direction of lazy iteration. - * - * @private - * @name reverse - * @memberOf LazyWrapper - * @returns {Object} Returns the new reversed `LazyWrapper` object. - */ - function lazyReverse() { - if (this.__filtered__) { - var result = new LazyWrapper(this); - result.__dir__ = -1; - result.__filtered__ = true; - } else { - result = this.clone(); - result.__dir__ *= -1; - } - return result; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Extracts the unwrapped value from its lazy wrapper. - * - * @private - * @name value - * @memberOf LazyWrapper - * @returns {*} Returns the unwrapped value. - */ - function lazyValue() { - var array = this.__wrapped__.value(), - dir = this.__dir__, - isArr = isArray(array), - isRight = dir < 0, - arrLength = isArr ? array.length : 0, - view = getView(0, arrLength, this.__views__), - start = view.start, - end = view.end, - length = end - start, - index = isRight ? end : (start - 1), - iteratees = this.__iteratees__, - iterLength = iteratees.length, - resIndex = 0, - takeCount = nativeMin(length, this.__takeCount__); - if (!isArr || (!isRight && arrLength == length && takeCount == length)) { - return baseWrapperValue(array, this.__actions__); - } - var result = []; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - outer: - while (length-- && resIndex < takeCount) { - index += dir; +const CareGoalSchema = DataElementSchema({ + statusDate: QDMDate, + relevantPeriod: Interval, + relatedTo: [String], + targetOutcome: Any, + performer: [AnyEntity], + qdmTitle: { type: String, default: 'Care Goal' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.7' }, + qdmCategory: { type: String, default: 'care_goal' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::CareGoal' }, - var iterIndex = -1, - value = array[index]; +}); - while (++iterIndex < iterLength) { - var data = iteratees[iterIndex], - iteratee = data.iteratee, - type = data.type, - computed = iteratee(value); +module.exports.CareGoalSchema = CareGoalSchema; +class CareGoal extends mongoose.Document { + constructor(object) { + super(object, CareGoalSchema); + this._type = 'QDM::CareGoal'; + } +} - if (type == LAZY_MAP_FLAG) { - value = computed; - } else if (!computed) { - if (type == LAZY_FILTER_FLAG) { - continue outer; - } else { - break outer; - } - } - } - result[resIndex++] = value; - } - return result; - } +module.exports.CareGoal = CareGoal; - // Ensure `LazyWrapper` is an instance of `baseLodash`. - LazyWrapper.prototype = baseCreate(baseLodash.prototype); - LazyWrapper.prototype.constructor = LazyWrapper; - /*------------------------------------------------------------------------*/ +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],117:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates a hash object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Hash(entries) { - var index = -1, - length = entries == null ? 0 : entries.length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - /** - * Removes all key-value entries from the hash. - * - * @private - * @name clear - * @memberOf Hash - */ - function hashClear() { - this.__data__ = nativeCreate ? nativeCreate(null) : {}; - this.size = 0; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Removes `key` and its value from the hash. - * - * @private - * @name delete - * @memberOf Hash - * @param {Object} hash The hash to modify. - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function hashDelete(key) { - var result = this.has(key) && delete this.__data__[key]; - this.size -= result ? 1 : 0; - return result; - } +const CommunicationPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + category: Code, + medium: Code, + sender: [AnyEntity], + recipient: [AnyEntity], + relatedTo: [String], + sentDatetime: DateTime, + receivedDatetime: DateTime, + negationRationale: Code, + qdmTitle: { type: String, default: 'Communication, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.132' }, + qdmCategory: { type: String, default: 'communication' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::CommunicationPerformed' }, - /** - * Gets the hash value for `key`. - * - * @private - * @name get - * @memberOf Hash - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function hashGet(key) { - var data = this.__data__; - if (nativeCreate) { - var result = data[key]; - return result === HASH_UNDEFINED ? undefined : result; - } - return hasOwnProperty.call(data, key) ? data[key] : undefined; - } +}); - /** - * Checks if a hash value for `key` exists. - * - * @private - * @name has - * @memberOf Hash - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function hashHas(key) { - var data = this.__data__; - return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key); - } +module.exports.CommunicationPerformedSchema = CommunicationPerformedSchema; +class CommunicationPerformed extends mongoose.Document { + constructor(object) { + super(object, CommunicationPerformedSchema); + this._type = 'QDM::CommunicationPerformed'; + } +} - /** - * Sets the hash `key` to `value`. - * - * @private - * @name set - * @memberOf Hash - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the hash instance. - */ - function hashSet(key, value) { - var data = this.__data__; - this.size += this.has(key) ? 0 : 1; - data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; - return this; - } +module.exports.CommunicationPerformed = CommunicationPerformed; - // Add methods to `Hash`. - Hash.prototype.clear = hashClear; - Hash.prototype['delete'] = hashDelete; - Hash.prototype.get = hashGet; - Hash.prototype.has = hashHas; - Hash.prototype.set = hashSet; - /*------------------------------------------------------------------------*/ +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],118:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates an list cache object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function ListCache(entries) { - var index = -1, - length = entries == null ? 0 : entries.length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - /** - * Removes all key-value entries from the list cache. - * - * @private - * @name clear - * @memberOf ListCache - */ - function listCacheClear() { - this.__data__ = []; - this.size = 0; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Removes `key` and its value from the list cache. - * - * @private - * @name delete - * @memberOf ListCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function listCacheDelete(key) { - var data = this.__data__, - index = assocIndexOf(data, key); +const DeviceOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + negationRationale: Code, + reason: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Device, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.15' }, + qdmCategory: { type: String, default: 'device' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DeviceOrder' }, - if (index < 0) { - return false; - } - var lastIndex = data.length - 1; - if (index == lastIndex) { - data.pop(); - } else { - splice.call(data, index, 1); - } - --this.size; - return true; - } +}); - /** - * Gets the list cache value for `key`. - * - * @private - * @name get - * @memberOf ListCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function listCacheGet(key) { - var data = this.__data__, - index = assocIndexOf(data, key); +module.exports.DeviceOrderSchema = DeviceOrderSchema; +class DeviceOrder extends mongoose.Document { + constructor(object) { + super(object, DeviceOrderSchema); + this._type = 'QDM::DeviceOrder'; + } +} - return index < 0 ? undefined : data[index][1]; - } +module.exports.DeviceOrder = DeviceOrder; - /** - * Checks if a list cache value for `key` exists. - * - * @private - * @name has - * @memberOf ListCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function listCacheHas(key) { - return assocIndexOf(this.__data__, key) > -1; - } - /** - * Sets the list cache `key` to `value`. - * - * @private - * @name set - * @memberOf ListCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the list cache instance. - */ - function listCacheSet(key, value) { - var data = this.__data__, - index = assocIndexOf(data, key); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],119:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (index < 0) { - ++this.size; - data.push([key, value]); - } else { - data[index][1] = value; - } - return this; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - // Add methods to `ListCache`. - ListCache.prototype.clear = listCacheClear; - ListCache.prototype['delete'] = listCacheDelete; - ListCache.prototype.get = listCacheGet; - ListCache.prototype.has = listCacheHas; - ListCache.prototype.set = listCacheSet; - /*------------------------------------------------------------------------*/ +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates a map cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function MapCache(entries) { - var index = -1, - length = entries == null ? 0 : entries.length; +const DeviceRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + negationRationale: Code, + reason: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Device, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.16' }, + qdmCategory: { type: String, default: 'device' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DeviceRecommended' }, - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } +}); - /** - * Removes all key-value entries from the map. - * - * @private - * @name clear - * @memberOf MapCache - */ - function mapCacheClear() { - this.size = 0; - this.__data__ = { - 'hash': new Hash, - 'map': new (Map || ListCache), - 'string': new Hash - }; - } +module.exports.DeviceRecommendedSchema = DeviceRecommendedSchema; +class DeviceRecommended extends mongoose.Document { + constructor(object) { + super(object, DeviceRecommendedSchema); + this._type = 'QDM::DeviceRecommended'; + } +} - /** - * Removes `key` and its value from the map. - * - * @private - * @name delete - * @memberOf MapCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function mapCacheDelete(key) { - var result = getMapData(this, key)['delete'](key); - this.size -= result ? 1 : 0; - return result; - } +module.exports.DeviceRecommended = DeviceRecommended; - /** - * Gets the map value for `key`. - * - * @private - * @name get - * @memberOf MapCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function mapCacheGet(key) { - return getMapData(this, key).get(key); - } - /** - * Checks if a map value for `key` exists. - * - * @private - * @name has - * @memberOf MapCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function mapCacheHas(key) { - return getMapData(this, key).has(key); - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],120:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Sets the map `key` to `value`. - * - * @private - * @name set - * @memberOf MapCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the map cache instance. - */ - function mapCacheSet(key, value) { - var data = getMapData(this, key), - size = data.size; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - data.set(key, value); - this.size += data.size == size ? 0 : 1; - return this; - } - // Add methods to `MapCache`. - MapCache.prototype.clear = mapCacheClear; - MapCache.prototype['delete'] = mapCacheDelete; - MapCache.prototype.get = mapCacheGet; - MapCache.prototype.has = mapCacheHas; - MapCache.prototype.set = mapCacheSet; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /*------------------------------------------------------------------------*/ +const DiagnosisSchema = DataElementSchema({ + authorDatetime: DateTime, + prevalencePeriod: Interval, + anatomicalLocationSite: Code, + severity: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Diagnosis' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.110' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.135' }, + qdmCategory: { type: String, default: 'condition' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Diagnosis' }, - /** - * - * Creates an array cache object to store unique values. - * - * @private - * @constructor - * @param {Array} [values] The values to cache. - */ - function SetCache(values) { - var index = -1, - length = values == null ? 0 : values.length; +}); - this.__data__ = new MapCache; - while (++index < length) { - this.add(values[index]); - } - } +module.exports.DiagnosisSchema = DiagnosisSchema; +class Diagnosis extends mongoose.Document { + constructor(object) { + super(object, DiagnosisSchema); + this._type = 'QDM::Diagnosis'; + } +} - /** - * Adds `value` to the array cache. - * - * @private - * @name add - * @memberOf SetCache - * @alias push - * @param {*} value The value to cache. - * @returns {Object} Returns the cache instance. - */ - function setCacheAdd(value) { - this.__data__.set(value, HASH_UNDEFINED); - return this; - } +module.exports.Diagnosis = Diagnosis; - /** - * Checks if `value` is in the array cache. - * - * @private - * @name has - * @memberOf SetCache - * @param {*} value The value to search for. - * @returns {number} Returns `true` if `value` is found, else `false`. - */ - function setCacheHas(value) { - return this.__data__.has(value); - } - // Add methods to `SetCache`. - SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; - SetCache.prototype.has = setCacheHas; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],121:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /*------------------------------------------------------------------------*/ +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Creates a stack cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Stack(entries) { - var data = this.__data__ = new ListCache(entries); - this.size = data.size; - } - /** - * Removes all key-value entries from the stack. - * - * @private - * @name clear - * @memberOf Stack - */ - function stackClear() { - this.__data__ = new ListCache; - this.size = 0; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Removes `key` and its value from the stack. - * - * @private - * @name delete - * @memberOf Stack - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function stackDelete(key) { - var data = this.__data__, - result = data['delete'](key); +const DiagnosticStudyOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Diagnostic Study, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.22' }, + qdmCategory: { type: String, default: 'diagnostic_study' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DiagnosticStudyOrder' }, - this.size = data.size; - return result; - } +}); - /** - * Gets the stack value for `key`. - * - * @private - * @name get - * @memberOf Stack - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function stackGet(key) { - return this.__data__.get(key); - } +module.exports.DiagnosticStudyOrderSchema = DiagnosticStudyOrderSchema; +class DiagnosticStudyOrder extends mongoose.Document { + constructor(object) { + super(object, DiagnosticStudyOrderSchema); + this._type = 'QDM::DiagnosticStudyOrder'; + } +} - /** - * Checks if a stack value for `key` exists. - * - * @private - * @name has - * @memberOf Stack - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function stackHas(key) { - return this.__data__.has(key); - } +module.exports.DiagnosticStudyOrder = DiagnosticStudyOrder; - /** - * Sets the stack `key` to `value`. - * - * @private - * @name set - * @memberOf Stack - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the stack cache instance. - */ - function stackSet(key, value) { - var data = this.__data__; - if (data instanceof ListCache) { - var pairs = data.__data__; - if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { - pairs.push([key, value]); - this.size = ++data.size; - return this; - } - data = this.__data__ = new MapCache(pairs); - } - data.set(key, value); - this.size = data.size; - return this; - } - // Add methods to `Stack`. - Stack.prototype.clear = stackClear; - Stack.prototype['delete'] = stackDelete; - Stack.prototype.get = stackGet; - Stack.prototype.has = stackHas; - Stack.prototype.set = stackSet; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],122:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /*------------------------------------------------------------------------*/ +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Creates an array of the enumerable property names of the array-like `value`. - * - * @private - * @param {*} value The value to query. - * @param {boolean} inherited Specify returning inherited property names. - * @returns {Array} Returns the array of property names. - */ - function arrayLikeKeys(value, inherited) { - var isArr = isArray(value), - isArg = !isArr && isArguments(value), - isBuff = !isArr && !isArg && isBuffer(value), - isType = !isArr && !isArg && !isBuff && isTypedArray(value), - skipIndexes = isArr || isArg || isBuff || isType, - result = skipIndexes ? baseTimes(value.length, String) : [], - length = result.length; - for (var key in value) { - if ((inherited || hasOwnProperty.call(value, key)) && - !(skipIndexes && ( - // Safari 9 has enumerable `arguments.length` in strict mode. - key == 'length' || - // Node.js 0.10 has enumerable non-index properties on buffers. - (isBuff && (key == 'offset' || key == 'parent')) || - // PhantomJS 2 has enumerable non-index properties on typed arrays. - (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || - // Skip index properties. - isIndex(key, length) - ))) { - result.push(key); - } - } - return result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * A specialized version of `_.sample` for arrays. - * - * @private - * @param {Array} array The array to sample. - * @returns {*} Returns the random element. - */ - function arraySample(array) { - var length = array.length; - return length ? array[baseRandom(0, length - 1)] : undefined; - } +const DiagnosticStudyPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + reason: Code, + result: Any, + resultDatetime: DateTime, + interpretation: Code, + status: Code, + method: Code, + facilityLocation: FacilityLocationSchema, + negationRationale: Code, + components: [ComponentSchema], + performer: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Diagnostic Study, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.23' }, + qdmCategory: { type: String, default: 'diagnostic_study' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DiagnosticStudyPerformed' }, - /** - * A specialized version of `_.sampleSize` for arrays. - * - * @private - * @param {Array} array The array to sample. - * @param {number} n The number of elements to sample. - * @returns {Array} Returns the random elements. - */ - function arraySampleSize(array, n) { - return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); - } +}); - /** - * A specialized version of `_.shuffle` for arrays. - * - * @private - * @param {Array} array The array to shuffle. - * @returns {Array} Returns the new shuffled array. - */ - function arrayShuffle(array) { - return shuffleSelf(copyArray(array)); - } +module.exports.DiagnosticStudyPerformedSchema = DiagnosticStudyPerformedSchema; +class DiagnosticStudyPerformed extends mongoose.Document { + constructor(object) { + super(object, DiagnosticStudyPerformedSchema); + this._type = 'QDM::DiagnosticStudyPerformed'; + } +} - /** - * This function is like `assignValue` except that it doesn't assign - * `undefined` values. - * - * @private - * @param {Object} object The object to modify. - * @param {string} key The key of the property to assign. - * @param {*} value The value to assign. - */ - function assignMergeValue(object, key, value) { - if ((value !== undefined && !eq(object[key], value)) || - (value === undefined && !(key in object))) { - baseAssignValue(object, key, value); - } - } +module.exports.DiagnosticStudyPerformed = DiagnosticStudyPerformed; - /** - * Assigns `value` to `key` of `object` if the existing value is not equivalent - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * @private - * @param {Object} object The object to modify. - * @param {string} key The key of the property to assign. - * @param {*} value The value to assign. - */ - function assignValue(object, key, value) { - var objValue = object[key]; - if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || - (value === undefined && !(key in object))) { - baseAssignValue(object, key, value); - } - } - /** - * Gets the index at which the `key` is found in `array` of key-value pairs. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} key The key to search for. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function assocIndexOf(array, key) { - var length = array.length; - while (length--) { - if (eq(array[length][0], key)) { - return length; - } - } - return -1; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],123:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Aggregates elements of `collection` on `accumulator` with keys transformed - * by `iteratee` and values set by `setter`. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} setter The function to set `accumulator` values. - * @param {Function} iteratee The iteratee to transform keys. - * @param {Object} accumulator The initial aggregated object. - * @returns {Function} Returns `accumulator`. - */ - function baseAggregator(collection, setter, iteratee, accumulator) { - baseEach(collection, function(value, key, collection) { - setter(accumulator, value, iteratee(value), collection); - }); - return accumulator; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.assign` without support for multiple sources - * or `customizer` functions. - * - * @private - * @param {Object} object The destination object. - * @param {Object} source The source object. - * @returns {Object} Returns `object`. - */ - function baseAssign(object, source) { - return object && copyObject(source, keys(source), object); - } - /** - * The base implementation of `_.assignIn` without support for multiple sources - * or `customizer` functions. - * - * @private - * @param {Object} object The destination object. - * @param {Object} source The source object. - * @returns {Object} Returns `object`. - */ - function baseAssignIn(object, source) { - return object && copyObject(source, keysIn(source), object); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `assignValue` and `assignMergeValue` without - * value checks. - * - * @private - * @param {Object} object The object to modify. - * @param {string} key The key of the property to assign. - * @param {*} value The value to assign. - */ - function baseAssignValue(object, key, value) { - if (key == '__proto__' && defineProperty) { - defineProperty(object, key, { - 'configurable': true, - 'enumerable': true, - 'value': value, - 'writable': true - }); - } else { - object[key] = value; - } - } +const DiagnosticStudyRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Diagnostic Study, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.24' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.19' }, + qdmCategory: { type: String, default: 'diagnostic_study' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DiagnosticStudyRecommended' }, - /** - * The base implementation of `_.at` without support for individual paths. - * - * @private - * @param {Object} object The object to iterate over. - * @param {string[]} paths The property paths to pick. - * @returns {Array} Returns the picked elements. - */ - function baseAt(object, paths) { - var index = -1, - length = paths.length, - result = Array(length), - skip = object == null; +}); - while (++index < length) { - result[index] = skip ? undefined : get(object, paths[index]); - } - return result; - } +module.exports.DiagnosticStudyRecommendedSchema = DiagnosticStudyRecommendedSchema; +class DiagnosticStudyRecommended extends mongoose.Document { + constructor(object) { + super(object, DiagnosticStudyRecommendedSchema); + this._type = 'QDM::DiagnosticStudyRecommended'; + } +} - /** - * The base implementation of `_.clamp` which doesn't coerce arguments. - * - * @private - * @param {number} number The number to clamp. - * @param {number} [lower] The lower bound. - * @param {number} upper The upper bound. - * @returns {number} Returns the clamped number. - */ - function baseClamp(number, lower, upper) { - if (number === number) { - if (upper !== undefined) { - number = number <= upper ? number : upper; - } - if (lower !== undefined) { - number = number >= lower ? number : lower; - } - } - return number; - } +module.exports.DiagnosticStudyRecommended = DiagnosticStudyRecommended; - /** - * The base implementation of `_.clone` and `_.cloneDeep` which tracks - * traversed objects. - * - * @private - * @param {*} value The value to clone. - * @param {boolean} bitmask The bitmask flags. - * 1 - Deep clone - * 2 - Flatten inherited properties - * 4 - Clone symbols - * @param {Function} [customizer] The function to customize cloning. - * @param {string} [key] The key of `value`. - * @param {Object} [object] The parent object of `value`. - * @param {Object} [stack] Tracks traversed objects and their clone counterparts. - * @returns {*} Returns the cloned value. - */ - function baseClone(value, bitmask, customizer, key, object, stack) { - var result, - isDeep = bitmask & CLONE_DEEP_FLAG, - isFlat = bitmask & CLONE_FLAT_FLAG, - isFull = bitmask & CLONE_SYMBOLS_FLAG; - if (customizer) { - result = object ? customizer(value, key, object, stack) : customizer(value); - } - if (result !== undefined) { - return result; - } - if (!isObject(value)) { - return value; - } - var isArr = isArray(value); - if (isArr) { - result = initCloneArray(value); - if (!isDeep) { - return copyArray(value, result); - } - } else { - var tag = getTag(value), - isFunc = tag == funcTag || tag == genTag; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],124:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (isBuffer(value)) { - return cloneBuffer(value, isDeep); - } - if (tag == objectTag || tag == argsTag || (isFunc && !object)) { - result = (isFlat || isFunc) ? {} : initCloneObject(value); - if (!isDeep) { - return isFlat - ? copySymbolsIn(value, baseAssignIn(result, value)) - : copySymbols(value, baseAssign(result, value)); - } - } else { - if (!cloneableTags[tag]) { - return object ? value : {}; - } - result = initCloneByTag(value, tag, isDeep); - } - } - // Check for circular references and return its corresponding clone. - stack || (stack = new Stack); - var stacked = stack.get(value); - if (stacked) { - return stacked; - } - stack.set(value, result); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - if (isSet(value)) { - value.forEach(function(subValue) { - result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); - }); - } else if (isMap(value)) { - value.forEach(function(subValue, key) { - result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); - }); - } - var keysFunc = isFull - ? (isFlat ? getAllKeysIn : getAllKeys) - : (isFlat ? keysIn : keys); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - var props = isArr ? undefined : keysFunc(value); - arrayEach(props || value, function(subValue, key) { - if (props) { - key = subValue; - subValue = value[key]; - } - // Recursively populate clone (susceptible to call stack limits). - assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); - }); - return result; - } +const EncounterOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + facilityLocation: FacilityLocationSchema, + negationRationale: Code, + requester: [AnyEntity], + priority: Code, + qdmTitle: { type: String, default: 'Encounter, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.27' }, + qdmCategory: { type: String, default: 'encounter' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::EncounterOrder' }, - /** - * The base implementation of `_.conforms` which doesn't clone `source`. - * - * @private - * @param {Object} source The object of property predicates to conform to. - * @returns {Function} Returns the new spec function. - */ - function baseConforms(source) { - var props = keys(source); - return function(object) { - return baseConformsTo(object, source, props); - }; - } +}); - /** - * The base implementation of `_.conformsTo` which accepts `props` to check. - * - * @private - * @param {Object} object The object to inspect. - * @param {Object} source The object of property predicates to conform to. - * @returns {boolean} Returns `true` if `object` conforms, else `false`. - */ - function baseConformsTo(object, source, props) { - var length = props.length; - if (object == null) { - return !length; - } - object = Object(object); - while (length--) { - var key = props[length], - predicate = source[key], - value = object[key]; +module.exports.EncounterOrderSchema = EncounterOrderSchema; +class EncounterOrder extends mongoose.Document { + constructor(object) { + super(object, EncounterOrderSchema); + this._type = 'QDM::EncounterOrder'; + } +} - if ((value === undefined && !(key in object)) || !predicate(value)) { - return false; - } - } - return true; - } +module.exports.EncounterOrder = EncounterOrder; + + +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],125:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `_.delay` and `_.defer` which accepts `args` - * to provide to `func`. - * - * @private - * @param {Function} func The function to delay. - * @param {number} wait The number of milliseconds to delay invocation. - * @param {Array} args The arguments to provide to `func`. - * @returns {number|Object} Returns the timer id or timeout object. - */ - function baseDelay(func, wait, args) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - return setTimeout(function() { func.apply(undefined, args); }, wait); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); +const { DiagnosisComponentSchema } = require('./attributes/DiagnosisComponent'); - /** - * The base implementation of methods like `_.difference` without support - * for excluding multiple arrays or iteratee shorthands. - * - * @private - * @param {Array} array The array to inspect. - * @param {Array} values The values to exclude. - * @param {Function} [iteratee] The iteratee invoked per element. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of filtered values. - */ - function baseDifference(array, values, iteratee, comparator) { - var index = -1, - includes = arrayIncludes, - isCommon = true, - length = array.length, - result = [], - valuesLength = values.length; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (!length) { - return result; - } - if (iteratee) { - values = arrayMap(values, baseUnary(iteratee)); - } - if (comparator) { - includes = arrayIncludesWith; - isCommon = false; - } - else if (values.length >= LARGE_ARRAY_SIZE) { - includes = cacheHas; - isCommon = false; - values = new SetCache(values); - } - outer: - while (++index < length) { - var value = array[index], - computed = iteratee == null ? value : iteratee(value); +const EncounterPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + admissionSource: Code, + class: Code, + relevantPeriod: Interval, + dischargeDisposition: Code, + facilityLocations: [FacilityLocationSchema], + diagnoses: [DiagnosisComponentSchema], + lengthOfStay: Quantity, + priority: Code, + participant: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Encounter, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.5' }, + qdmCategory: { type: String, default: 'encounter' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::EncounterPerformed' }, - value = (comparator || value !== 0) ? value : 0; - if (isCommon && computed === computed) { - var valuesIndex = valuesLength; - while (valuesIndex--) { - if (values[valuesIndex] === computed) { - continue outer; - } - } - result.push(value); - } - else if (!includes(values, computed, comparator)) { - result.push(value); - } - } - return result; +}); + +module.exports.EncounterPerformedSchema = EncounterPerformedSchema; +class EncounterPerformed extends mongoose.Document { + constructor(object) { + super(object, EncounterPerformedSchema); + this._type = 'QDM::EncounterPerformed'; + if (object && object.clazz) { + this.class = object.clazz; } + } +} - /** - * The base implementation of `_.forEach` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array|Object} Returns `collection`. - */ - var baseEach = createBaseEach(baseForOwn); +module.exports.EncounterPerformed = EncounterPerformed; - /** - * The base implementation of `_.forEachRight` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array|Object} Returns `collection`. - */ - var baseEachRight = createBaseEach(baseForOwnRight, true); - /** - * The base implementation of `_.every` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, - * else `false` - */ - function baseEvery(collection, predicate) { - var result = true; - baseEach(collection, function(value, index, collection) { - result = !!predicate(value, index, collection); - return result; - }); - return result; - } +},{"./attributes/Component":166,"./attributes/DiagnosisComponent":167,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],126:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of methods like `_.max` and `_.min` which accepts a - * `comparator` to determine the extremum value. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} iteratee The iteratee invoked per iteration. - * @param {Function} comparator The comparator used to compare values. - * @returns {*} Returns the extremum value. - */ - function baseExtremum(array, iteratee, comparator) { - var index = -1, - length = array.length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (++index < length) { - var value = array[index], - current = iteratee(value); - if (current != null && (computed === undefined - ? (current === current && !isSymbol(current)) - : comparator(current, computed) - )) { - var computed = current, - result = value; - } - } - return result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.fill` without an iteratee call guard. - * - * @private - * @param {Array} array The array to fill. - * @param {*} value The value to fill `array` with. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns `array`. - */ - function baseFill(array, value, start, end) { - var length = array.length; +const EncounterRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + facilityLocation: FacilityLocationSchema, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Encounter, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.28' }, + qdmCategory: { type: String, default: 'encounter' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::EncounterRecommended' }, - start = toInteger(start); - if (start < 0) { - start = -start > length ? 0 : (length + start); - } - end = (end === undefined || end > length) ? length : toInteger(end); - if (end < 0) { - end += length; - } - end = start > end ? 0 : toLength(end); - while (start < end) { - array[start++] = value; - } - return array; - } +}); - /** - * The base implementation of `_.filter` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - */ - function baseFilter(collection, predicate) { - var result = []; - baseEach(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result.push(value); - } - }); - return result; - } +module.exports.EncounterRecommendedSchema = EncounterRecommendedSchema; +class EncounterRecommended extends mongoose.Document { + constructor(object) { + super(object, EncounterRecommendedSchema); + this._type = 'QDM::EncounterRecommended'; + } +} - /** - * The base implementation of `_.flatten` with support for restricting flattening. - * - * @private - * @param {Array} array The array to flatten. - * @param {number} depth The maximum recursion depth. - * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. - * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. - * @param {Array} [result=[]] The initial result value. - * @returns {Array} Returns the new flattened array. - */ - function baseFlatten(array, depth, predicate, isStrict, result) { - var index = -1, - length = array.length; +module.exports.EncounterRecommended = EncounterRecommended; - predicate || (predicate = isFlattenable); - result || (result = []); - while (++index < length) { - var value = array[index]; - if (depth > 0 && predicate(value)) { - if (depth > 1) { - // Recursively flatten arrays (susceptible to call stack limits). - baseFlatten(value, depth - 1, predicate, isStrict, result); - } else { - arrayPush(result, value); - } - } else if (!isStrict) { - result[result.length] = value; - } - } - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],127:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `baseForOwn` which iterates over `object` - * properties returned by `keysFunc` and invokes `iteratee` for each property. - * Iteratee functions may exit iteration early by explicitly returning `false`. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {Function} keysFunc The function to get the keys of `object`. - * @returns {Object} Returns `object`. - */ - var baseFor = createBaseFor(); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * This function is like `baseFor` except that it iterates over properties - * in the opposite order. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {Function} keysFunc The function to get the keys of `object`. - * @returns {Object} Returns `object`. - */ - var baseForRight = createBaseFor(true); - /** - * The base implementation of `_.forOwn` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForOwn(object, iteratee) { - return object && baseFor(object, iteratee, keys); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.forOwnRight` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForOwnRight(object, iteratee) { - return object && baseForRight(object, iteratee, keys); - } +const FamilyHistorySchema = DataElementSchema({ + authorDatetime: DateTime, + relationship: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Family History' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.111' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.12' }, + qdmCategory: { type: String, default: 'family_history' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::FamilyHistory' }, - /** - * The base implementation of `_.functions` which creates an array of - * `object` function property names filtered from `props`. - * - * @private - * @param {Object} object The object to inspect. - * @param {Array} props The property names to filter. - * @returns {Array} Returns the function names. - */ - function baseFunctions(object, props) { - return arrayFilter(props, function(key) { - return isFunction(object[key]); - }); - } +}); - /** - * The base implementation of `_.get` without support for default values. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @returns {*} Returns the resolved value. - */ - function baseGet(object, path) { - path = castPath(path, object); +module.exports.FamilyHistorySchema = FamilyHistorySchema; +class FamilyHistory extends mongoose.Document { + constructor(object) { + super(object, FamilyHistorySchema); + this._type = 'QDM::FamilyHistory'; + } +} - var index = 0, - length = path.length; +module.exports.FamilyHistory = FamilyHistory; - while (object != null && index < length) { - object = object[toKey(path[index++])]; - } - return (index && index == length) ? object : undefined; - } - /** - * The base implementation of `getAllKeys` and `getAllKeysIn` which uses - * `keysFunc` and `symbolsFunc` to get the enumerable property names and - * symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Function} keysFunc The function to get the keys of `object`. - * @param {Function} symbolsFunc The function to get the symbols of `object`. - * @returns {Array} Returns the array of property names and symbols. - */ - function baseGetAllKeys(object, keysFunc, symbolsFunc) { - var result = keysFunc(object); - return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],128:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `getTag` without fallbacks for buggy environments. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - function baseGetTag(value) { - if (value == null) { - return value === undefined ? undefinedTag : nullTag; - } - return (symToStringTag && symToStringTag in Object(value)) - ? getRawTag(value) - : objectToString(value); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.gt` which doesn't coerce arguments. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than `other`, - * else `false`. - */ - function baseGt(value, other) { - return value > other; - } - /** - * The base implementation of `_.has` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ - function baseHas(object, key) { - return object != null && hasOwnProperty.call(object, key); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.hasIn` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ - function baseHasIn(object, key) { - return object != null && key in Object(object); - } +const ImmunizationAdministeredSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + reason: Code, + dosage: Quantity, + route: Code, + negationRationale: Code, + performer: [AnyEntity], + qdmTitle: { type: String, default: 'Immunization, Administered' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.112' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.140' }, + qdmCategory: { type: String, default: 'immunization' }, + qdmStatus: { type: String, default: 'administered' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ImmunizationAdministered' }, - /** - * The base implementation of `_.inRange` which doesn't coerce arguments. - * - * @private - * @param {number} number The number to check. - * @param {number} start The start of the range. - * @param {number} end The end of the range. - * @returns {boolean} Returns `true` if `number` is in the range, else `false`. - */ - function baseInRange(number, start, end) { - return number >= nativeMin(start, end) && number < nativeMax(start, end); - } +}); + +module.exports.ImmunizationAdministeredSchema = ImmunizationAdministeredSchema; +class ImmunizationAdministered extends mongoose.Document { + constructor(object) { + super(object, ImmunizationAdministeredSchema); + this._type = 'QDM::ImmunizationAdministered'; + } +} - /** - * The base implementation of methods like `_.intersection`, without support - * for iteratee shorthands, that accepts an array of arrays to inspect. - * - * @private - * @param {Array} arrays The arrays to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of shared values. - */ - function baseIntersection(arrays, iteratee, comparator) { - var includes = comparator ? arrayIncludesWith : arrayIncludes, - length = arrays[0].length, - othLength = arrays.length, - othIndex = othLength, - caches = Array(othLength), - maxLength = Infinity, - result = []; +module.exports.ImmunizationAdministered = ImmunizationAdministered; - while (othIndex--) { - var array = arrays[othIndex]; - if (othIndex && iteratee) { - array = arrayMap(array, baseUnary(iteratee)); - } - maxLength = nativeMin(array.length, maxLength); - caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) - ? new SetCache(othIndex && array) - : undefined; - } - array = arrays[0]; - var index = -1, - seen = caches[0]; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],129:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - outer: - while (++index < length && result.length < maxLength) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - value = (comparator || value !== 0) ? value : 0; - if (!(seen - ? cacheHas(seen, computed) - : includes(result, computed, comparator) - )) { - othIndex = othLength; - while (--othIndex) { - var cache = caches[othIndex]; - if (!(cache - ? cacheHas(cache, computed) - : includes(arrays[othIndex], computed, comparator)) - ) { - continue outer; - } - } - if (seen) { - seen.push(computed); - } - result.push(value); - } - } - return result; - } - /** - * The base implementation of `_.invert` and `_.invertBy` which inverts - * `object` with values transformed by `iteratee` and set by `setter`. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} setter The function to set `accumulator` values. - * @param {Function} iteratee The iteratee to transform values. - * @param {Object} accumulator The initial inverted object. - * @returns {Function} Returns `accumulator`. - */ - function baseInverter(object, setter, iteratee, accumulator) { - baseForOwn(object, function(value, key, object) { - setter(accumulator, iteratee(value), key, object); - }); - return accumulator; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.invoke` without support for individual - * method arguments. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path of the method to invoke. - * @param {Array} args The arguments to invoke the method with. - * @returns {*} Returns the result of the invoked method. - */ - function baseInvoke(object, path, args) { - path = castPath(path, object); - object = parent(object, path); - var func = object == null ? object : object[toKey(last(path))]; - return func == null ? undefined : apply(func, object, args); - } +const ImmunizationOrderSchema = DataElementSchema({ + activeDatetime: DateTime, + authorDatetime: DateTime, + dosage: Quantity, + supply: Quantity, + reason: Code, + route: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Immunization, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.113' }, + qdmCategory: { type: String, default: 'immunization' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ImmunizationOrder' }, - /** - * The base implementation of `_.isArguments`. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - */ - function baseIsArguments(value) { - return isObjectLike(value) && baseGetTag(value) == argsTag; - } +}); - /** - * The base implementation of `_.isArrayBuffer` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. - */ - function baseIsArrayBuffer(value) { - return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; - } +module.exports.ImmunizationOrderSchema = ImmunizationOrderSchema; +class ImmunizationOrder extends mongoose.Document { + constructor(object) { + super(object, ImmunizationOrderSchema); + this._type = 'QDM::ImmunizationOrder'; + } +} - /** - * The base implementation of `_.isDate` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a date object, else `false`. - */ - function baseIsDate(value) { - return isObjectLike(value) && baseGetTag(value) == dateTag; - } +module.exports.ImmunizationOrder = ImmunizationOrder; - /** - * The base implementation of `_.isEqual` which supports partial comparisons - * and tracks traversed objects. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @param {boolean} bitmask The bitmask flags. - * 1 - Unordered comparison - * 2 - Partial comparison - * @param {Function} [customizer] The function to customize comparisons. - * @param {Object} [stack] Tracks traversed `value` and `other` objects. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - */ - function baseIsEqual(value, other, bitmask, customizer, stack) { - if (value === other) { - return true; - } - if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { - return value !== value && other !== other; - } - return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack); - } - /** - * A specialized version of `baseIsEqual` for arrays and objects which performs - * deep comparisons and tracks traversed objects enabling objects with circular - * references to be compared. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. - * @param {Function} customizer The function to customize comparisons. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Object} [stack] Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { - var objIsArr = isArray(object), - othIsArr = isArray(other), - objTag = objIsArr ? arrayTag : getTag(object), - othTag = othIsArr ? arrayTag : getTag(other); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],130:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - objTag = objTag == argsTag ? objectTag : objTag; - othTag = othTag == argsTag ? objectTag : othTag; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - var objIsObj = objTag == objectTag, - othIsObj = othTag == objectTag, - isSameTag = objTag == othTag; - if (isSameTag && isBuffer(object)) { - if (!isBuffer(other)) { - return false; - } - objIsArr = true; - objIsObj = false; - } - if (isSameTag && !objIsObj) { - stack || (stack = new Stack); - return (objIsArr || isTypedArray(object)) - ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) - : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); - } - if (!(bitmask & COMPARE_PARTIAL_FLAG)) { - var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (objIsWrapped || othIsWrapped) { - var objUnwrapped = objIsWrapped ? object.value() : object, - othUnwrapped = othIsWrapped ? other.value() : other; +const InterventionOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Intervention, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.35' }, + qdmCategory: { type: String, default: 'intervention' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::InterventionOrder' }, - stack || (stack = new Stack); - return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); - } - } - if (!isSameTag) { - return false; - } - stack || (stack = new Stack); - return equalObjects(object, other, bitmask, customizer, equalFunc, stack); - } +}); - /** - * The base implementation of `_.isMap` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a map, else `false`. - */ - function baseIsMap(value) { - return isObjectLike(value) && getTag(value) == mapTag; - } +module.exports.InterventionOrderSchema = InterventionOrderSchema; +class InterventionOrder extends mongoose.Document { + constructor(object) { + super(object, InterventionOrderSchema); + this._type = 'QDM::InterventionOrder'; + } +} - /** - * The base implementation of `_.isMatch` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to inspect. - * @param {Object} source The object of property values to match. - * @param {Array} matchData The property names, values, and compare flags to match. - * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if `object` is a match, else `false`. - */ - function baseIsMatch(object, source, matchData, customizer) { - var index = matchData.length, - length = index, - noCustomizer = !customizer; +module.exports.InterventionOrder = InterventionOrder; - if (object == null) { - return !length; - } - object = Object(object); - while (index--) { - var data = matchData[index]; - if ((noCustomizer && data[2]) - ? data[1] !== object[data[0]] - : !(data[0] in object) - ) { - return false; - } - } - while (++index < length) { - data = matchData[index]; - var key = data[0], - objValue = object[key], - srcValue = data[1]; - if (noCustomizer && data[2]) { - if (objValue === undefined && !(key in object)) { - return false; - } - } else { - var stack = new Stack; - if (customizer) { - var result = customizer(objValue, srcValue, key, object, source, stack); - } - if (!(result === undefined - ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) - : result - )) { - return false; - } - } - } - return true; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],131:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `_.isNative` without bad shim checks. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, - * else `false`. - */ - function baseIsNative(value) { - if (!isObject(value) || isMasked(value)) { - return false; - } - var pattern = isFunction(value) ? reIsNative : reIsHostCtor; - return pattern.test(toSource(value)); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.isRegExp` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. - */ - function baseIsRegExp(value) { - return isObjectLike(value) && baseGetTag(value) == regexpTag; - } - /** - * The base implementation of `_.isSet` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a set, else `false`. - */ - function baseIsSet(value) { - return isObjectLike(value) && getTag(value) == setTag; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.isTypedArray` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - */ - function baseIsTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; - } +const InterventionPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + reason: Code, + result: Any, + status: Code, + negationRationale: Code, + performer: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Intervention, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.36' }, + qdmCategory: { type: String, default: 'intervention' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::InterventionPerformed' }, - /** - * The base implementation of `_.iteratee`. - * - * @private - * @param {*} [value=_.identity] The value to convert to an iteratee. - * @returns {Function} Returns the iteratee. - */ - function baseIteratee(value) { - // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. - // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. - if (typeof value == 'function') { - return value; - } - if (value == null) { - return identity; - } - if (typeof value == 'object') { - return isArray(value) - ? baseMatchesProperty(value[0], value[1]) - : baseMatches(value); - } - return property(value); - } +}); - /** - * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function baseKeys(object) { - if (!isPrototype(object)) { - return nativeKeys(object); - } - var result = []; - for (var key in Object(object)) { - if (hasOwnProperty.call(object, key) && key != 'constructor') { - result.push(key); - } - } - return result; - } +module.exports.InterventionPerformedSchema = InterventionPerformedSchema; +class InterventionPerformed extends mongoose.Document { + constructor(object) { + super(object, InterventionPerformedSchema); + this._type = 'QDM::InterventionPerformed'; + } +} - /** - * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function baseKeysIn(object) { - if (!isObject(object)) { - return nativeKeysIn(object); - } - var isProto = isPrototype(object), - result = []; +module.exports.InterventionPerformed = InterventionPerformed; - for (var key in object) { - if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { - result.push(key); - } - } - return result; - } - /** - * The base implementation of `_.lt` which doesn't coerce arguments. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than `other`, - * else `false`. - */ - function baseLt(value, other) { - return value < other; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],132:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.map` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the new mapped array. - */ - function baseMap(collection, iteratee) { - var index = -1, - result = isArrayLike(collection) ? Array(collection.length) : []; - baseEach(collection, function(value, key, collection) { - result[++index] = iteratee(value, key, collection); - }); - return result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.matches` which doesn't clone `source`. - * - * @private - * @param {Object} source The object of property values to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatches(source) { - var matchData = getMatchData(source); - if (matchData.length == 1 && matchData[0][2]) { - return matchesStrictComparable(matchData[0][0], matchData[0][1]); - } - return function(object) { - return object === source || baseIsMatch(object, source, matchData); - }; - } +const InterventionRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Intervention, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.37' }, + qdmCategory: { type: String, default: 'intervention' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::InterventionRecommended' }, - /** - * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. - * - * @private - * @param {string} path The path of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatchesProperty(path, srcValue) { - if (isKey(path) && isStrictComparable(srcValue)) { - return matchesStrictComparable(toKey(path), srcValue); - } - return function(object) { - var objValue = get(object, path); - return (objValue === undefined && objValue === srcValue) - ? hasIn(object, path) - : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); - }; - } +}); - /** - * The base implementation of `_.merge` without support for multiple sources. - * - * @private - * @param {Object} object The destination object. - * @param {Object} source The source object. - * @param {number} srcIndex The index of `source`. - * @param {Function} [customizer] The function to customize merged values. - * @param {Object} [stack] Tracks traversed source values and their merged - * counterparts. - */ - function baseMerge(object, source, srcIndex, customizer, stack) { - if (object === source) { - return; - } - baseFor(source, function(srcValue, key) { - stack || (stack = new Stack); - if (isObject(srcValue)) { - baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); - } - else { - var newValue = customizer - ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) - : undefined; +module.exports.InterventionRecommendedSchema = InterventionRecommendedSchema; +class InterventionRecommended extends mongoose.Document { + constructor(object) { + super(object, InterventionRecommendedSchema); + this._type = 'QDM::InterventionRecommended'; + } +} - if (newValue === undefined) { - newValue = srcValue; - } - assignMergeValue(object, key, newValue); - } - }, keysIn); - } +module.exports.InterventionRecommended = InterventionRecommended; - /** - * A specialized version of `baseMerge` for arrays and objects which performs - * deep merges and tracks traversed objects enabling objects with circular - * references to be merged. - * - * @private - * @param {Object} object The destination object. - * @param {Object} source The source object. - * @param {string} key The key of the value to merge. - * @param {number} srcIndex The index of `source`. - * @param {Function} mergeFunc The function to merge values. - * @param {Function} [customizer] The function to customize assigned values. - * @param {Object} [stack] Tracks traversed source values and their merged - * counterparts. - */ - function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { - var objValue = safeGet(object, key), - srcValue = safeGet(source, key), - stacked = stack.get(srcValue); - if (stacked) { - assignMergeValue(object, key, stacked); - return; - } - var newValue = customizer - ? customizer(objValue, srcValue, (key + ''), object, source, stack) - : undefined; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],133:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - var isCommon = newValue === undefined; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - if (isCommon) { - var isArr = isArray(srcValue), - isBuff = !isArr && isBuffer(srcValue), - isTyped = !isArr && !isBuff && isTypedArray(srcValue); - newValue = srcValue; - if (isArr || isBuff || isTyped) { - if (isArray(objValue)) { - newValue = objValue; - } - else if (isArrayLikeObject(objValue)) { - newValue = copyArray(objValue); - } - else if (isBuff) { - isCommon = false; - newValue = cloneBuffer(srcValue, true); - } - else if (isTyped) { - isCommon = false; - newValue = cloneTypedArray(srcValue, true); - } - else { - newValue = []; - } - } - else if (isPlainObject(srcValue) || isArguments(srcValue)) { - newValue = objValue; - if (isArguments(objValue)) { - newValue = toPlainObject(objValue); - } - else if (!isObject(objValue) || isFunction(objValue)) { - newValue = initCloneObject(srcValue); - } - } - else { - isCommon = false; - } - } - if (isCommon) { - // Recursively merge objects and arrays (susceptible to call stack limits). - stack.set(srcValue, newValue); - mergeFunc(newValue, srcValue, srcIndex, customizer, stack); - stack['delete'](srcValue); - } - assignMergeValue(object, key, newValue); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.nth` which doesn't coerce arguments. - * - * @private - * @param {Array} array The array to query. - * @param {number} n The index of the element to return. - * @returns {*} Returns the nth element of `array`. - */ - function baseNth(array, n) { - var length = array.length; - if (!length) { - return; - } - n += n < 0 ? length : 0; - return isIndex(n, length) ? array[n] : undefined; - } +const LaboratoryTestOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Laboratory Test, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.41' }, + qdmCategory: { type: String, default: 'laboratory_test' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::LaboratoryTestOrder' }, - /** - * The base implementation of `_.orderBy` without param guards. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. - * @param {string[]} orders The sort orders of `iteratees`. - * @returns {Array} Returns the new sorted array. - */ - function baseOrderBy(collection, iteratees, orders) { - if (iteratees.length) { - iteratees = arrayMap(iteratees, function(iteratee) { - if (isArray(iteratee)) { - return function(value) { - return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee); - } - } - return iteratee; - }); - } else { - iteratees = [identity]; - } +}); - var index = -1; - iteratees = arrayMap(iteratees, baseUnary(getIteratee())); +module.exports.LaboratoryTestOrderSchema = LaboratoryTestOrderSchema; +class LaboratoryTestOrder extends mongoose.Document { + constructor(object) { + super(object, LaboratoryTestOrderSchema); + this._type = 'QDM::LaboratoryTestOrder'; + } +} - var result = baseMap(collection, function(value, key, collection) { - var criteria = arrayMap(iteratees, function(iteratee) { - return iteratee(value); - }); - return { 'criteria': criteria, 'index': ++index, 'value': value }; - }); +module.exports.LaboratoryTestOrder = LaboratoryTestOrder; - return baseSortBy(result, function(object, other) { - return compareMultiple(object, other, orders); - }); - } - /** - * The base implementation of `_.pick` without support for individual - * property identifiers. - * - * @private - * @param {Object} object The source object. - * @param {string[]} paths The property paths to pick. - * @returns {Object} Returns the new object. - */ - function basePick(object, paths) { - return basePickBy(object, paths, function(value, path) { - return hasIn(object, path); - }); - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],134:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `_.pickBy` without support for iteratee shorthands. - * - * @private - * @param {Object} object The source object. - * @param {string[]} paths The property paths to pick. - * @param {Function} predicate The function invoked per property. - * @returns {Object} Returns the new object. - */ - function basePickBy(object, paths, predicate) { - var index = -1, - length = paths.length, - result = {}; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (++index < length) { - var path = paths[index], - value = baseGet(object, path); - if (predicate(value, path)) { - baseSet(result, castPath(path, object), value); - } - } - return result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * A specialized version of `baseProperty` which supports deep paths. - * - * @private - * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function basePropertyDeep(path) { - return function(object) { - return baseGet(object, path); - }; - } +const LaboratoryTestPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + status: Code, + method: Code, + result: Any, + resultDatetime: DateTime, + reason: Code, + referenceRange: Interval, + interpretation: Code, + negationRationale: Code, + components: [ComponentSchema], + performer: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Laboratory Test, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.42' }, + qdmCategory: { type: String, default: 'laboratory_test' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::LaboratoryTestPerformed' }, - /** - * The base implementation of `_.pullAllBy` without support for iteratee - * shorthands. - * - * @private - * @param {Array} array The array to modify. - * @param {Array} values The values to remove. - * @param {Function} [iteratee] The iteratee invoked per element. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns `array`. - */ - function basePullAll(array, values, iteratee, comparator) { - var indexOf = comparator ? baseIndexOfWith : baseIndexOf, - index = -1, - length = values.length, - seen = array; +}); - if (array === values) { - values = copyArray(values); - } - if (iteratee) { - seen = arrayMap(array, baseUnary(iteratee)); - } - while (++index < length) { - var fromIndex = 0, - value = values[index], - computed = iteratee ? iteratee(value) : value; +module.exports.LaboratoryTestPerformedSchema = LaboratoryTestPerformedSchema; +class LaboratoryTestPerformed extends mongoose.Document { + constructor(object) { + super(object, LaboratoryTestPerformedSchema); + this._type = 'QDM::LaboratoryTestPerformed'; + } +} - while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { - if (seen !== array) { - splice.call(seen, fromIndex, 1); - } - splice.call(array, fromIndex, 1); - } - } - return array; - } +module.exports.LaboratoryTestPerformed = LaboratoryTestPerformed; - /** - * The base implementation of `_.pullAt` without support for individual - * indexes or capturing the removed elements. - * - * @private - * @param {Array} array The array to modify. - * @param {number[]} indexes The indexes of elements to remove. - * @returns {Array} Returns `array`. - */ - function basePullAt(array, indexes) { - var length = array ? indexes.length : 0, - lastIndex = length - 1; - while (length--) { - var index = indexes[length]; - if (length == lastIndex || index !== previous) { - var previous = index; - if (isIndex(index)) { - splice.call(array, index, 1); - } else { - baseUnset(array, index); - } - } - } - return array; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],135:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * The base implementation of `_.random` without support for returning - * floating-point numbers. - * - * @private - * @param {number} lower The lower bound. - * @param {number} upper The upper bound. - * @returns {number} Returns the random number. - */ - function baseRandom(lower, upper) { - return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.range` and `_.rangeRight` which doesn't - * coerce arguments. - * - * @private - * @param {number} start The start of the range. - * @param {number} end The end of the range. - * @param {number} step The value to increment or decrement by. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Array} Returns the range of numbers. - */ - function baseRange(start, end, step, fromRight) { - var index = -1, - length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), - result = Array(length); - while (length--) { - result[fromRight ? length : ++index] = start; - start += step; - } - return result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.repeat` which doesn't coerce arguments. - * - * @private - * @param {string} string The string to repeat. - * @param {number} n The number of times to repeat the string. - * @returns {string} Returns the repeated string. - */ - function baseRepeat(string, n) { - var result = ''; - if (!string || n < 1 || n > MAX_SAFE_INTEGER) { - return result; - } - // Leverage the exponentiation by squaring algorithm for a faster repeat. - // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. - do { - if (n % 2) { - result += string; - } - n = nativeFloor(n / 2); - if (n) { - string += string; - } - } while (n); +const LaboratoryTestRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Laboratory Test, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.43' }, + qdmCategory: { type: String, default: 'laboratory_test' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::LaboratoryTestRecommended' }, - return result; - } +}); - /** - * The base implementation of `_.rest` which doesn't validate or coerce arguments. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - */ - function baseRest(func, start) { - return setToString(overRest(func, start, identity), func + ''); - } +module.exports.LaboratoryTestRecommendedSchema = LaboratoryTestRecommendedSchema; +class LaboratoryTestRecommended extends mongoose.Document { + constructor(object) { + super(object, LaboratoryTestRecommendedSchema); + this._type = 'QDM::LaboratoryTestRecommended'; + } +} - /** - * The base implementation of `_.sample`. - * - * @private - * @param {Array|Object} collection The collection to sample. - * @returns {*} Returns the random element. - */ - function baseSample(collection) { - return arraySample(values(collection)); - } +module.exports.LaboratoryTestRecommended = LaboratoryTestRecommended; - /** - * The base implementation of `_.sampleSize` without param guards. - * - * @private - * @param {Array|Object} collection The collection to sample. - * @param {number} n The number of elements to sample. - * @returns {Array} Returns the random elements. - */ - function baseSampleSize(collection, n) { - var array = values(collection); - return shuffleSelf(array, baseClamp(n, 0, array.length)); - } - /** - * The base implementation of `_.set`. - * - * @private - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to set. - * @param {*} value The value to set. - * @param {Function} [customizer] The function to customize path creation. - * @returns {Object} Returns `object`. - */ - function baseSet(object, path, value, customizer) { - if (!isObject(object)) { - return object; - } - path = castPath(path, object); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],136:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - var index = -1, - length = path.length, - lastIndex = length - 1, - nested = object; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (nested != null && ++index < length) { - var key = toKey(path[index]), - newValue = value; - if (key === '__proto__' || key === 'constructor' || key === 'prototype') { - return object; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (index != lastIndex) { - var objValue = nested[key]; - newValue = customizer ? customizer(objValue, key, nested) : undefined; - if (newValue === undefined) { - newValue = isObject(objValue) - ? objValue - : (isIndex(path[index + 1]) ? [] : {}); - } - } - assignValue(nested, key, newValue); - nested = nested[key]; - } - return object; - } +const MedicationActiveSchema = DataElementSchema({ + relevantDatetime: DateTime, + relevantPeriod: Interval, + dosage: Quantity, + frequency: Code, + route: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Medication, Active' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.44' }, + qdmCategory: { type: String, default: 'medication' }, + qdmStatus: { type: String, default: 'active' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::MedicationActive' }, - /** - * The base implementation of `setData` without support for hot loop shorting. - * - * @private - * @param {Function} func The function to associate metadata with. - * @param {*} data The metadata. - * @returns {Function} Returns `func`. - */ - var baseSetData = !metaMap ? identity : function(func, data) { - metaMap.set(func, data); - return func; - }; +}); - /** - * The base implementation of `setToString` without support for hot loop shorting. - * - * @private - * @param {Function} func The function to modify. - * @param {Function} string The `toString` result. - * @returns {Function} Returns `func`. - */ - var baseSetToString = !defineProperty ? identity : function(func, string) { - return defineProperty(func, 'toString', { - 'configurable': true, - 'enumerable': false, - 'value': constant(string), - 'writable': true - }); - }; +module.exports.MedicationActiveSchema = MedicationActiveSchema; +class MedicationActive extends mongoose.Document { + constructor(object) { + super(object, MedicationActiveSchema); + this._type = 'QDM::MedicationActive'; + } +} - /** - * The base implementation of `_.shuffle`. - * - * @private - * @param {Array|Object} collection The collection to shuffle. - * @returns {Array} Returns the new shuffled array. - */ - function baseShuffle(collection) { - return shuffleSelf(values(collection)); - } +module.exports.MedicationActive = MedicationActive; - /** - * The base implementation of `_.slice` without an iteratee call guard. - * - * @private - * @param {Array} array The array to slice. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the slice of `array`. - */ - function baseSlice(array, start, end) { - var index = -1, - length = array.length; - if (start < 0) { - start = -start > length ? 0 : (length + start); - } - end = end > length ? length : end; - if (end < 0) { - end += length; - } - length = start > end ? 0 : ((end - start) >>> 0); - start >>>= 0; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],137:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - var result = Array(length); - while (++index < length) { - result[index] = array[index + start]; - } - return result; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.some` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - */ - function baseSome(collection, predicate) { - var result; - baseEach(collection, function(value, index, collection) { - result = predicate(value, index, collection); - return !result; - }); - return !!result; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which - * performs a binary search of `array` to determine the index at which `value` - * should be inserted into `array` in order to maintain its sort order. - * - * @private - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @param {boolean} [retHighest] Specify returning the highest qualified index. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - */ - function baseSortedIndex(array, value, retHighest) { - var low = 0, - high = array == null ? low : array.length; +const MedicationAdministeredSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + dosage: Quantity, + frequency: Code, + route: Code, + reason: Code, + negationRationale: Code, + performer: [AnyEntity], + qdmTitle: { type: String, default: 'Medication, Administered' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.45' }, + qdmCategory: { type: String, default: 'medication' }, + qdmStatus: { type: String, default: 'administered' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::MedicationAdministered' }, - if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { - while (low < high) { - var mid = (low + high) >>> 1, - computed = array[mid]; +}); - if (computed !== null && !isSymbol(computed) && - (retHighest ? (computed <= value) : (computed < value))) { - low = mid + 1; - } else { - high = mid; - } - } - return high; - } - return baseSortedIndexBy(array, value, identity, retHighest); - } +module.exports.MedicationAdministeredSchema = MedicationAdministeredSchema; +class MedicationAdministered extends mongoose.Document { + constructor(object) { + super(object, MedicationAdministeredSchema); + this._type = 'QDM::MedicationAdministered'; + } +} - /** - * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` - * which invokes `iteratee` for `value` and each element of `array` to compute - * their sort ranking. The iteratee is invoked with one argument; (value). - * - * @private - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @param {Function} iteratee The iteratee invoked per element. - * @param {boolean} [retHighest] Specify returning the highest qualified index. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - */ - function baseSortedIndexBy(array, value, iteratee, retHighest) { - var low = 0, - high = array == null ? 0 : array.length; - if (high === 0) { - return 0; - } +module.exports.MedicationAdministered = MedicationAdministered; - value = iteratee(value); - var valIsNaN = value !== value, - valIsNull = value === null, - valIsSymbol = isSymbol(value), - valIsUndefined = value === undefined; - while (low < high) { - var mid = nativeFloor((low + high) / 2), - computed = iteratee(array[mid]), - othIsDefined = computed !== undefined, - othIsNull = computed === null, - othIsReflexive = computed === computed, - othIsSymbol = isSymbol(computed); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],138:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (valIsNaN) { - var setLow = retHighest || othIsReflexive; - } else if (valIsUndefined) { - setLow = othIsReflexive && (retHighest || othIsDefined); - } else if (valIsNull) { - setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); - } else if (valIsSymbol) { - setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); - } else if (othIsNull || othIsSymbol) { - setLow = false; - } else { - setLow = retHighest ? (computed <= value) : (computed < value); - } - if (setLow) { - low = mid + 1; - } else { - high = mid; - } - } - return nativeMin(high, MAX_ARRAY_INDEX); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without - * support for iteratee shorthands. - * - * @private - * @param {Array} array The array to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @returns {Array} Returns the new duplicate free array. - */ - function baseSortedUniq(array, iteratee) { - var index = -1, - length = array.length, - resIndex = 0, - result = []; - while (++index < length) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (!index || !eq(computed, seen)) { - var seen = computed; - result[resIndex++] = value === 0 ? 0 : value; - } - } - return result; - } +const MedicationDischargeSchema = DataElementSchema({ + authorDatetime: DateTime, + refills: Number, + dosage: Quantity, + supply: Quantity, + frequency: Code, + daysSupplied: Number, + route: Code, + negationRationale: Code, + prescriber: [AnyEntity], + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Medication, Discharge' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.48' }, + qdmCategory: { type: String, default: 'medication' }, + qdmStatus: { type: String, default: 'discharge' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::MedicationDischarge' }, - /** - * The base implementation of `_.toNumber` which doesn't ensure correct - * conversions of binary, hexadecimal, or octal string values. - * - * @private - * @param {*} value The value to process. - * @returns {number} Returns the number. - */ - function baseToNumber(value) { - if (typeof value == 'number') { - return value; - } - if (isSymbol(value)) { - return NAN; - } - return +value; - } +}); - /** - * The base implementation of `_.toString` which doesn't convert nullish - * values to empty strings. - * - * @private - * @param {*} value The value to process. - * @returns {string} Returns the string. - */ - function baseToString(value) { - // Exit early for strings to avoid a performance hit in some environments. - if (typeof value == 'string') { - return value; - } - if (isArray(value)) { - // Recursively convert values (susceptible to call stack limits). - return arrayMap(value, baseToString) + ''; - } - if (isSymbol(value)) { - return symbolToString ? symbolToString.call(value) : ''; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } +module.exports.MedicationDischargeSchema = MedicationDischargeSchema; +class MedicationDischarge extends mongoose.Document { + constructor(object) { + super(object, MedicationDischargeSchema); + this._type = 'QDM::MedicationDischarge'; + } +} - /** - * The base implementation of `_.uniqBy` without support for iteratee shorthands. - * - * @private - * @param {Array} array The array to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new duplicate free array. - */ - function baseUniq(array, iteratee, comparator) { - var index = -1, - includes = arrayIncludes, - length = array.length, - isCommon = true, - result = [], - seen = result; +module.exports.MedicationDischarge = MedicationDischarge; - if (comparator) { - isCommon = false; - includes = arrayIncludesWith; - } - else if (length >= LARGE_ARRAY_SIZE) { - var set = iteratee ? null : createSet(array); - if (set) { - return setToArray(set); - } - isCommon = false; - includes = cacheHas; - seen = new SetCache; - } - else { - seen = iteratee ? [] : result; - } - outer: - while (++index < length) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; - value = (comparator || value !== 0) ? value : 0; - if (isCommon && computed === computed) { - var seenIndex = seen.length; - while (seenIndex--) { - if (seen[seenIndex] === computed) { - continue outer; - } - } - if (iteratee) { - seen.push(computed); - } - result.push(value); - } - else if (!includes(seen, computed, comparator)) { - if (seen !== result) { - seen.push(computed); - } - result.push(value); - } - } - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],139:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); + + +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const MedicationDispensedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + refills: Number, + dosage: Quantity, + supply: Quantity, + frequency: Code, + daysSupplied: Number, + route: Code, + prescriber: [AnyEntity], + dispenser: [AnyEntity], + negationRationale: Code, + relatedTo: [String], + qdmTitle: { type: String, default: 'Medication, Dispensed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.49' }, + qdmCategory: { type: String, default: 'medication' }, + qdmStatus: { type: String, default: 'dispensed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::MedicationDispensed' }, + +}); - /** - * The base implementation of `_.unset`. - * - * @private - * @param {Object} object The object to modify. - * @param {Array|string} path The property path to unset. - * @returns {boolean} Returns `true` if the property is deleted, else `false`. - */ - function baseUnset(object, path) { - path = castPath(path, object); - object = parent(object, path); - return object == null || delete object[toKey(last(path))]; - } +module.exports.MedicationDispensedSchema = MedicationDispensedSchema; +class MedicationDispensed extends mongoose.Document { + constructor(object) { + super(object, MedicationDispensedSchema); + this._type = 'QDM::MedicationDispensed'; + } +} - /** - * The base implementation of `_.update`. - * - * @private - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to update. - * @param {Function} updater The function to produce the updated value. - * @param {Function} [customizer] The function to customize path creation. - * @returns {Object} Returns `object`. - */ - function baseUpdate(object, path, updater, customizer) { - return baseSet(object, path, updater(baseGet(object, path)), customizer); - } +module.exports.MedicationDispensed = MedicationDispensed; - /** - * The base implementation of methods like `_.dropWhile` and `_.takeWhile` - * without support for iteratee shorthands. - * - * @private - * @param {Array} array The array to query. - * @param {Function} predicate The function invoked per iteration. - * @param {boolean} [isDrop] Specify dropping elements instead of taking them. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Array} Returns the slice of `array`. - */ - function baseWhile(array, predicate, isDrop, fromRight) { - var length = array.length, - index = fromRight ? length : -1; - while ((fromRight ? index-- : ++index < length) && - predicate(array[index], index, array)) {} +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],140:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - return isDrop - ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) - : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * The base implementation of `wrapperValue` which returns the result of - * performing a sequence of actions on the unwrapped `value`, where each - * successive action is supplied the return value of the previous. - * - * @private - * @param {*} value The unwrapped value. - * @param {Array} actions Actions to perform to resolve the unwrapped value. - * @returns {*} Returns the resolved value. - */ - function baseWrapperValue(value, actions) { - var result = value; - if (result instanceof LazyWrapper) { - result = result.value(); - } - return arrayReduce(actions, function(result, action) { - return action.func.apply(action.thisArg, arrayPush([result], action.args)); - }, result); - } - /** - * The base implementation of methods like `_.xor`, without support for - * iteratee shorthands, that accepts an array of arrays to inspect. - * - * @private - * @param {Array} arrays The arrays to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of values. - */ - function baseXor(arrays, iteratee, comparator) { - var length = arrays.length; - if (length < 2) { - return length ? baseUniq(arrays[0]) : []; - } - var index = -1, - result = Array(length); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - while (++index < length) { - var array = arrays[index], - othIndex = -1; +const MedicationOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantPeriod: Interval, + refills: Number, + dosage: Quantity, + supply: Quantity, + frequency: Code, + daysSupplied: Number, + route: Code, + setting: Code, + reason: Code, + negationRationale: Code, + prescriber: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Medication, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.51' }, + qdmCategory: { type: String, default: 'medication' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::MedicationOrder' }, - while (++othIndex < length) { - if (othIndex != index) { - result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); - } - } - } - return baseUniq(baseFlatten(result, 1), iteratee, comparator); - } +}); - /** - * This base implementation of `_.zipObject` which assigns values using `assignFunc`. - * - * @private - * @param {Array} props The property identifiers. - * @param {Array} values The property values. - * @param {Function} assignFunc The function to assign values. - * @returns {Object} Returns the new object. - */ - function baseZipObject(props, values, assignFunc) { - var index = -1, - length = props.length, - valsLength = values.length, - result = {}; +module.exports.MedicationOrderSchema = MedicationOrderSchema; +class MedicationOrder extends mongoose.Document { + constructor(object) { + super(object, MedicationOrderSchema); + this._type = 'QDM::MedicationOrder'; + } +} - while (++index < length) { - var value = index < valsLength ? values[index] : undefined; - assignFunc(result, props[index], value); - } - return result; - } +module.exports.MedicationOrder = MedicationOrder; - /** - * Casts `value` to an empty array if it's not an array like object. - * - * @private - * @param {*} value The value to inspect. - * @returns {Array|Object} Returns the cast array-like object. - */ - function castArrayLikeObject(value) { - return isArrayLikeObject(value) ? value : []; - } - /** - * Casts `value` to `identity` if it's not a function. - * - * @private - * @param {*} value The value to inspect. - * @returns {Function} Returns cast function. - */ - function castFunction(value) { - return typeof value == 'function' ? value : identity; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],141:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Casts `value` to a path array if it's not one. - * - * @private - * @param {*} value The value to inspect. - * @param {Object} [object] The object to query keys on. - * @returns {Array} Returns the cast property path array. - */ - function castPath(value, object) { - if (isArray(value)) { - return value; - } - return isKey(value, object) ? [value] : stringToPath(toString(value)); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * A `baseRest` alias which can be replaced with `identity` by module - * replacement plugins. - * - * @private - * @type {Function} - * @param {Function} func The function to apply a rest parameter to. - * @returns {Function} Returns the new function. - */ - var castRest = baseRest; - /** - * Casts `array` to a slice if it's needed. - * - * @private - * @param {Array} array The array to inspect. - * @param {number} start The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the cast slice. - */ - function castSlice(array, start, end) { - var length = array.length; - end = end === undefined ? length : end; - return (!start && end >= length) ? array : baseSlice(array, start, end); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout). - * - * @private - * @param {number|Object} id The timer id or timeout object of the timer to clear. - */ - var clearTimeout = ctxClearTimeout || function(id) { - return root.clearTimeout(id); - }; +const ParticipationSchema = DataElementSchema({ + participationPeriod: Interval, + qdmTitle: { type: String, default: 'Participation' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.130' }, + qdmCategory: { type: String, default: 'participation' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Participation' }, - /** - * Creates a clone of `buffer`. - * - * @private - * @param {Buffer} buffer The buffer to clone. - * @param {boolean} [isDeep] Specify a deep clone. - * @returns {Buffer} Returns the cloned buffer. - */ - function cloneBuffer(buffer, isDeep) { - if (isDeep) { - return buffer.slice(); - } - var length = buffer.length, - result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); +}); - buffer.copy(result); - return result; - } +module.exports.ParticipationSchema = ParticipationSchema; +class Participation extends mongoose.Document { + constructor(object) { + super(object, ParticipationSchema); + this._type = 'QDM::Participation'; + } +} - /** - * Creates a clone of `arrayBuffer`. - * - * @private - * @param {ArrayBuffer} arrayBuffer The array buffer to clone. - * @returns {ArrayBuffer} Returns the cloned array buffer. - */ - function cloneArrayBuffer(arrayBuffer) { - var result = new arrayBuffer.constructor(arrayBuffer.byteLength); - new Uint8Array(result).set(new Uint8Array(arrayBuffer)); - return result; - } +module.exports.Participation = Participation; - /** - * Creates a clone of `dataView`. - * - * @private - * @param {Object} dataView The data view to clone. - * @param {boolean} [isDeep] Specify a deep clone. - * @returns {Object} Returns the cloned data view. - */ - function cloneDataView(dataView, isDeep) { - var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; - return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); - } - /** - * Creates a clone of `regexp`. - * - * @private - * @param {Object} regexp The regexp to clone. - * @returns {Object} Returns the cloned regexp. - */ - function cloneRegExp(regexp) { - var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); - result.lastIndex = regexp.lastIndex; - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],142:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates a clone of the `symbol` object. - * - * @private - * @param {Object} symbol The symbol object to clone. - * @returns {Object} Returns the cloned symbol object. - */ - function cloneSymbol(symbol) { - return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Creates a clone of `typedArray`. - * - * @private - * @param {Object} typedArray The typed array to clone. - * @param {boolean} [isDeep] Specify a deep clone. - * @returns {Object} Returns the cloned typed array. - */ - function cloneTypedArray(typedArray, isDeep) { - var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; - return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); - } - /** - * Compares values to sort them in ascending order. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {number} Returns the sort order indicator for `value`. - */ - function compareAscending(value, other) { - if (value !== other) { - var valIsDefined = value !== undefined, - valIsNull = value === null, - valIsReflexive = value === value, - valIsSymbol = isSymbol(value); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - var othIsDefined = other !== undefined, - othIsNull = other === null, - othIsReflexive = other === other, - othIsSymbol = isSymbol(other); +const PatientCareExperienceSchema = DataElementSchema({ + authorDatetime: DateTime, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Patient Care Experience' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.52' }, + qdmCategory: { type: String, default: 'care_experience' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCareExperience' }, - if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || - (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || - (valIsNull && othIsDefined && othIsReflexive) || - (!valIsDefined && othIsReflexive) || - !valIsReflexive) { - return 1; - } - if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || - (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || - (othIsNull && valIsDefined && valIsReflexive) || - (!othIsDefined && valIsReflexive) || - !othIsReflexive) { - return -1; - } - } - return 0; - } +}); - /** - * Used by `_.orderBy` to compare multiple properties of a value to another - * and stable sort them. - * - * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, - * specify an order of "desc" for descending or "asc" for ascending sort order - * of corresponding values. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {boolean[]|string[]} orders The order to sort by for each property. - * @returns {number} Returns the sort order indicator for `object`. - */ - function compareMultiple(object, other, orders) { - var index = -1, - objCriteria = object.criteria, - othCriteria = other.criteria, - length = objCriteria.length, - ordersLength = orders.length; +module.exports.PatientCareExperienceSchema = PatientCareExperienceSchema; +class PatientCareExperience extends mongoose.Document { + constructor(object) { + super(object, PatientCareExperienceSchema); + this._type = 'QDM::PatientCareExperience'; + } +} - while (++index < length) { - var result = compareAscending(objCriteria[index], othCriteria[index]); - if (result) { - if (index >= ordersLength) { - return result; - } - var order = orders[index]; - return result * (order == 'desc' ? -1 : 1); - } - } - // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications - // that causes it, under certain circumstances, to provide the same value for - // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 - // for more details. - // - // This also ensures a stable sort in V8 and other engines. - // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. - return object.index - other.index; - } +module.exports.PatientCareExperience = PatientCareExperience; - /** - * Creates an array that is the composition of partially applied arguments, - * placeholders, and provided arguments into a single array of arguments. - * - * @private - * @param {Array} args The provided arguments. - * @param {Array} partials The arguments to prepend to those provided. - * @param {Array} holders The `partials` placeholder indexes. - * @params {boolean} [isCurried] Specify composing for a curried function. - * @returns {Array} Returns the new array of composed arguments. - */ - function composeArgs(args, partials, holders, isCurried) { - var argsIndex = -1, - argsLength = args.length, - holdersLength = holders.length, - leftIndex = -1, - leftLength = partials.length, - rangeLength = nativeMax(argsLength - holdersLength, 0), - result = Array(leftLength + rangeLength), - isUncurried = !isCurried; - while (++leftIndex < leftLength) { - result[leftIndex] = partials[leftIndex]; - } - while (++argsIndex < holdersLength) { - if (isUncurried || argsIndex < argsLength) { - result[holders[argsIndex]] = args[argsIndex]; - } - } - while (rangeLength--) { - result[leftIndex++] = args[argsIndex++]; - } - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],143:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); + + +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const PatientCharacteristicSchema = DataElementSchema({ + authorDatetime: DateTime, + qdmTitle: { type: String, default: 'Patient Characteristic' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.53' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristic' }, - /** - * This function is like `composeArgs` except that the arguments composition - * is tailored for `_.partialRight`. - * - * @private - * @param {Array} args The provided arguments. - * @param {Array} partials The arguments to append to those provided. - * @param {Array} holders The `partials` placeholder indexes. - * @params {boolean} [isCurried] Specify composing for a curried function. - * @returns {Array} Returns the new array of composed arguments. - */ - function composeArgsRight(args, partials, holders, isCurried) { - var argsIndex = -1, - argsLength = args.length, - holdersIndex = -1, - holdersLength = holders.length, - rightIndex = -1, - rightLength = partials.length, - rangeLength = nativeMax(argsLength - holdersLength, 0), - result = Array(rangeLength + rightLength), - isUncurried = !isCurried; +}); - while (++argsIndex < rangeLength) { - result[argsIndex] = args[argsIndex]; - } - var offset = argsIndex; - while (++rightIndex < rightLength) { - result[offset + rightIndex] = partials[rightIndex]; - } - while (++holdersIndex < holdersLength) { - if (isUncurried || argsIndex < argsLength) { - result[offset + holders[holdersIndex]] = args[argsIndex++]; - } - } - return result; - } +module.exports.PatientCharacteristicSchema = PatientCharacteristicSchema; +class PatientCharacteristic extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicSchema); + this._type = 'QDM::PatientCharacteristic'; + } +} - /** - * Copies the values of `source` to `array`. - * - * @private - * @param {Array} source The array to copy values from. - * @param {Array} [array=[]] The array to copy values to. - * @returns {Array} Returns `array`. - */ - function copyArray(source, array) { - var index = -1, - length = source.length; +module.exports.PatientCharacteristic = PatientCharacteristic; - array || (array = Array(length)); - while (++index < length) { - array[index] = source[index]; - } - return array; - } - /** - * Copies properties of `source` to `object`. - * - * @private - * @param {Object} source The object to copy properties from. - * @param {Array} props The property identifiers to copy. - * @param {Object} [object={}] The object to copy properties to. - * @param {Function} [customizer] The function to customize copied values. - * @returns {Object} Returns `object`. - */ - function copyObject(source, props, object, customizer) { - var isNew = !object; - object || (object = {}); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],144:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - var index = -1, - length = props.length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (++index < length) { - var key = props[index]; - var newValue = customizer - ? customizer(object[key], source[key], key, object, source) - : undefined; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (newValue === undefined) { - newValue = source[key]; - } - if (isNew) { - baseAssignValue(object, key, newValue); - } else { - assignValue(object, key, newValue); - } - } - return object; - } +const PatientCharacteristicBirthdateSchema = DataElementSchema({ + birthDatetime: DateTime, + qdmTitle: { type: String, default: 'Patient Characteristic Birthdate' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.54' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'birthdate' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicBirthdate' }, - /** - * Copies own symbols of `source` to `object`. - * - * @private - * @param {Object} source The object to copy symbols from. - * @param {Object} [object={}] The object to copy symbols to. - * @returns {Object} Returns `object`. - */ - function copySymbols(source, object) { - return copyObject(source, getSymbols(source), object); - } +}); - /** - * Copies own and inherited symbols of `source` to `object`. - * - * @private - * @param {Object} source The object to copy symbols from. - * @param {Object} [object={}] The object to copy symbols to. - * @returns {Object} Returns `object`. - */ - function copySymbolsIn(source, object) { - return copyObject(source, getSymbolsIn(source), object); - } +module.exports.PatientCharacteristicBirthdateSchema = PatientCharacteristicBirthdateSchema; +class PatientCharacteristicBirthdate extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicBirthdateSchema); + this._type = 'QDM::PatientCharacteristicBirthdate'; + } +} - /** - * Creates a function like `_.groupBy`. - * - * @private - * @param {Function} setter The function to set accumulator values. - * @param {Function} [initializer] The accumulator object initializer. - * @returns {Function} Returns the new aggregator function. - */ - function createAggregator(setter, initializer) { - return function(collection, iteratee) { - var func = isArray(collection) ? arrayAggregator : baseAggregator, - accumulator = initializer ? initializer() : {}; +module.exports.PatientCharacteristicBirthdate = PatientCharacteristicBirthdate; - return func(collection, setter, getIteratee(iteratee, 2), accumulator); - }; - } - /** - * Creates a function like `_.assign`. - * - * @private - * @param {Function} assigner The function to assign values. - * @returns {Function} Returns the new assigner function. - */ - function createAssigner(assigner) { - return baseRest(function(object, sources) { - var index = -1, - length = sources.length, - customizer = length > 1 ? sources[length - 1] : undefined, - guard = length > 2 ? sources[2] : undefined; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],145:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - customizer = (assigner.length > 3 && typeof customizer == 'function') - ? (length--, customizer) - : undefined; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - if (guard && isIterateeCall(sources[0], sources[1], guard)) { - customizer = length < 3 ? undefined : customizer; - length = 1; - } - object = Object(object); - while (++index < length) { - var source = sources[index]; - if (source) { - assigner(object, source, index, customizer); - } - } - return object; - }); - } - /** - * Creates a `baseEach` or `baseEachRight` function. - * - * @private - * @param {Function} eachFunc The function to iterate over a collection. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ - function createBaseEach(eachFunc, fromRight) { - return function(collection, iteratee) { - if (collection == null) { - return collection; - } - if (!isArrayLike(collection)) { - return eachFunc(collection, iteratee); - } - var length = collection.length, - index = fromRight ? length : -1, - iterable = Object(collection); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - while ((fromRight ? index-- : ++index < length)) { - if (iteratee(iterable[index], index, iterable) === false) { - break; - } - } - return collection; - }; - } +const PatientCharacteristicClinicalTrialParticipantSchema = DataElementSchema({ + reason: Code, + relevantPeriod: Interval, + qdmTitle: { type: String, default: 'Patient Characteristic Clinical Trial Participant' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.6' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.51' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'clinical_trial_participant' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicClinicalTrialParticipant' }, - /** - * Creates a base function for methods like `_.forIn` and `_.forOwn`. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ - function createBaseFor(fromRight) { - return function(object, iteratee, keysFunc) { - var index = -1, - iterable = Object(object), - props = keysFunc(object), - length = props.length; +}); - while (length--) { - var key = props[fromRight ? length : ++index]; - if (iteratee(iterable[key], key, iterable) === false) { - break; - } - } - return object; - }; - } +module.exports.PatientCharacteristicClinicalTrialParticipantSchema = PatientCharacteristicClinicalTrialParticipantSchema; +class PatientCharacteristicClinicalTrialParticipant extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicClinicalTrialParticipantSchema); + this._type = 'QDM::PatientCharacteristicClinicalTrialParticipant'; + } +} - /** - * Creates a function that wraps `func` to invoke it with the optional `this` - * binding of `thisArg`. - * - * @private - * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @param {*} [thisArg] The `this` binding of `func`. - * @returns {Function} Returns the new wrapped function. - */ - function createBind(func, bitmask, thisArg) { - var isBind = bitmask & WRAP_BIND_FLAG, - Ctor = createCtor(func); +module.exports.PatientCharacteristicClinicalTrialParticipant = PatientCharacteristicClinicalTrialParticipant; - function wrapper() { - var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; - return fn.apply(isBind ? thisArg : this, arguments); - } - return wrapper; - } - /** - * Creates a function like `_.lowerFirst`. - * - * @private - * @param {string} methodName The name of the `String` case method to use. - * @returns {Function} Returns the new case function. - */ - function createCaseFirst(methodName) { - return function(string) { - string = toString(string); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],146:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - var strSymbols = hasUnicode(string) - ? stringToArray(string) - : undefined; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - var chr = strSymbols - ? strSymbols[0] - : string.charAt(0); - var trailing = strSymbols - ? castSlice(strSymbols, 1).join('') - : string.slice(1); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - return chr[methodName]() + trailing; - }; - } +const PatientCharacteristicEthnicitySchema = DataElementSchema({ + qdmTitle: { type: String, default: 'Patient Characteristic Ethnicity' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.56' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'ethnicity' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicEthnicity' }, - /** - * Creates a function like `_.camelCase`. - * - * @private - * @param {Function} callback The function to combine each word. - * @returns {Function} Returns the new compounder function. - */ - function createCompounder(callback) { - return function(string) { - return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); - }; - } +}); - /** - * Creates a function that produces an instance of `Ctor` regardless of - * whether it was invoked as part of a `new` expression or by `call` or `apply`. - * - * @private - * @param {Function} Ctor The constructor to wrap. - * @returns {Function} Returns the new wrapped function. - */ - function createCtor(Ctor) { - return function() { - // Use a `switch` statement to work with class constructors. See - // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist - // for more details. - var args = arguments; - switch (args.length) { - case 0: return new Ctor; - case 1: return new Ctor(args[0]); - case 2: return new Ctor(args[0], args[1]); - case 3: return new Ctor(args[0], args[1], args[2]); - case 4: return new Ctor(args[0], args[1], args[2], args[3]); - case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); - case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); - case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - } - var thisBinding = baseCreate(Ctor.prototype), - result = Ctor.apply(thisBinding, args); +module.exports.PatientCharacteristicEthnicitySchema = PatientCharacteristicEthnicitySchema; +class PatientCharacteristicEthnicity extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicEthnicitySchema); + this._type = 'QDM::PatientCharacteristicEthnicity'; + } +} - // Mimic the constructor's `return` behavior. - // See https://es5.github.io/#x13.2.2 for more details. - return isObject(result) ? result : thisBinding; - }; - } +module.exports.PatientCharacteristicEthnicity = PatientCharacteristicEthnicity; - /** - * Creates a function that wraps `func` to enable currying. - * - * @private - * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @param {number} arity The arity of `func`. - * @returns {Function} Returns the new wrapped function. - */ - function createCurry(func, bitmask, arity) { - var Ctor = createCtor(func); - function wrapper() { - var length = arguments.length, - args = Array(length), - index = length, - placeholder = getHolder(wrapper); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],147:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - while (index--) { - args[index] = arguments[index]; - } - var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) - ? [] - : replaceHolders(args, placeholder); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - length -= holders.length; - if (length < arity) { - return createRecurry( - func, bitmask, createHybrid, wrapper.placeholder, undefined, - args, holders, undefined, undefined, arity - length); - } - var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; - return apply(fn, this, args); - } - return wrapper; - } - /** - * Creates a `_.find` or `_.findLast` function. - * - * @private - * @param {Function} findIndexFunc The function to find the collection index. - * @returns {Function} Returns the new find function. - */ - function createFind(findIndexFunc) { - return function(collection, predicate, fromIndex) { - var iterable = Object(collection); - if (!isArrayLike(collection)) { - var iteratee = getIteratee(predicate, 3); - collection = keys(collection); - predicate = function(key) { return iteratee(iterable[key], key, iterable); }; - } - var index = findIndexFunc(collection, predicate, fromIndex); - return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; - }; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates a `_.flow` or `_.flowRight` function. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new flow function. - */ - function createFlow(fromRight) { - return flatRest(function(funcs) { - var length = funcs.length, - index = length, - prereq = LodashWrapper.prototype.thru; +const PatientCharacteristicExpiredSchema = DataElementSchema({ + expiredDatetime: DateTime, + cause: Code, + qdmTitle: { type: String, default: 'Patient Characteristic Expired' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.57' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'expired' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicExpired' }, + +}); + +module.exports.PatientCharacteristicExpiredSchema = PatientCharacteristicExpiredSchema; +class PatientCharacteristicExpired extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicExpiredSchema); + this._type = 'QDM::PatientCharacteristicExpired'; + } +} - if (fromRight) { - funcs.reverse(); - } - while (index--) { - var func = funcs[index]; - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - if (prereq && !wrapper && getFuncName(func) == 'wrapper') { - var wrapper = new LodashWrapper([], true); - } - } - index = wrapper ? index : length; - while (++index < length) { - func = funcs[index]; +module.exports.PatientCharacteristicExpired = PatientCharacteristicExpired; - var funcName = getFuncName(func), - data = funcName == 'wrapper' ? getData(func) : undefined; - if (data && isLaziable(data[0]) && - data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && - !data[4].length && data[9] == 1 - ) { - wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); - } else { - wrapper = (func.length == 1 && isLaziable(func)) - ? wrapper[funcName]() - : wrapper.thru(func); - } - } - return function() { - var args = arguments, - value = args[0]; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],148:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (wrapper && args.length == 1 && isArray(value)) { - return wrapper.plant(value).value(); - } - var index = 0, - result = length ? funcs[index].apply(this, args) : value; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (++index < length) { - result = funcs[index].call(this, result); - } - return result; - }; - }); - } - /** - * Creates a function that wraps `func` to invoke it with optional `this` - * binding of `thisArg`, partial application, and currying. - * - * @private - * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to - * the new function. - * @param {Array} [holders] The `partials` placeholder indexes. - * @param {Array} [partialsRight] The arguments to append to those provided - * to the new function. - * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. - * @param {Array} [argPos] The argument positions of the new function. - * @param {number} [ary] The arity cap of `func`. - * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new wrapped function. - */ - function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { - var isAry = bitmask & WRAP_ARY_FLAG, - isBind = bitmask & WRAP_BIND_FLAG, - isBindKey = bitmask & WRAP_BIND_KEY_FLAG, - isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), - isFlip = bitmask & WRAP_FLIP_FLAG, - Ctor = isBindKey ? undefined : createCtor(func); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - function wrapper() { - var length = arguments.length, - args = Array(length), - index = length; +const PatientCharacteristicPayerSchema = DataElementSchema({ + relevantPeriod: Interval, + qdmTitle: { type: String, default: 'Patient Characteristic Payer' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.58' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'payer' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicPayer' }, - while (index--) { - args[index] = arguments[index]; - } - if (isCurried) { - var placeholder = getHolder(wrapper), - holdersCount = countHolders(args, placeholder); - } - if (partials) { - args = composeArgs(args, partials, holders, isCurried); - } - if (partialsRight) { - args = composeArgsRight(args, partialsRight, holdersRight, isCurried); - } - length -= holdersCount; - if (isCurried && length < arity) { - var newHolders = replaceHolders(args, placeholder); - return createRecurry( - func, bitmask, createHybrid, wrapper.placeholder, thisArg, - args, newHolders, argPos, ary, arity - length - ); - } - var thisBinding = isBind ? thisArg : this, - fn = isBindKey ? thisBinding[func] : func; +}); - length = args.length; - if (argPos) { - args = reorder(args, argPos); - } else if (isFlip && length > 1) { - args.reverse(); - } - if (isAry && ary < length) { - args.length = ary; - } - if (this && this !== root && this instanceof wrapper) { - fn = Ctor || createCtor(fn); - } - return fn.apply(thisBinding, args); - } - return wrapper; - } +module.exports.PatientCharacteristicPayerSchema = PatientCharacteristicPayerSchema; +class PatientCharacteristicPayer extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicPayerSchema); + this._type = 'QDM::PatientCharacteristicPayer'; + } +} - /** - * Creates a function like `_.invertBy`. - * - * @private - * @param {Function} setter The function to set accumulator values. - * @param {Function} toIteratee The function to resolve iteratees. - * @returns {Function} Returns the new inverter function. - */ - function createInverter(setter, toIteratee) { - return function(object, iteratee) { - return baseInverter(object, setter, toIteratee(iteratee), {}); - }; - } +module.exports.PatientCharacteristicPayer = PatientCharacteristicPayer; - /** - * Creates a function that performs a mathematical operation on two values. - * - * @private - * @param {Function} operator The function to perform the operation. - * @param {number} [defaultValue] The value used for `undefined` arguments. - * @returns {Function} Returns the new mathematical operation function. - */ - function createMathOperation(operator, defaultValue) { - return function(value, other) { - var result; - if (value === undefined && other === undefined) { - return defaultValue; - } - if (value !== undefined) { - result = value; - } - if (other !== undefined) { - if (result === undefined) { - return other; - } - if (typeof value == 'string' || typeof other == 'string') { - value = baseToString(value); - other = baseToString(other); - } else { - value = baseToNumber(value); - other = baseToNumber(other); - } - result = operator(value, other); - } - return result; - }; - } - /** - * Creates a function like `_.over`. - * - * @private - * @param {Function} arrayFunc The function to iterate over iteratees. - * @returns {Function} Returns the new over function. - */ - function createOver(arrayFunc) { - return flatRest(function(iteratees) { - iteratees = arrayMap(iteratees, baseUnary(getIteratee())); - return baseRest(function(args) { - var thisArg = this; - return arrayFunc(iteratees, function(iteratee) { - return apply(iteratee, thisArg, args); - }); - }); - }); - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],149:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates the padding for `string` based on `length`. The `chars` string - * is truncated if the number of characters exceeds `length`. - * - * @private - * @param {number} length The padding length. - * @param {string} [chars=' '] The string used as padding. - * @returns {string} Returns the padding for `string`. - */ - function createPadding(length, chars) { - chars = chars === undefined ? ' ' : baseToString(chars); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - var charsLength = chars.length; - if (charsLength < 2) { - return charsLength ? baseRepeat(chars, length) : chars; - } - var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); - return hasUnicode(chars) - ? castSlice(stringToArray(result), 0, length).join('') - : result.slice(0, length); - } - /** - * Creates a function that wraps `func` to invoke it with the `this` binding - * of `thisArg` and `partials` prepended to the arguments it receives. - * - * @private - * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @param {*} thisArg The `this` binding of `func`. - * @param {Array} partials The arguments to prepend to those provided to - * the new function. - * @returns {Function} Returns the new wrapped function. - */ - function createPartial(func, bitmask, thisArg, partials) { - var isBind = bitmask & WRAP_BIND_FLAG, - Ctor = createCtor(func); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - function wrapper() { - var argsIndex = -1, - argsLength = arguments.length, - leftIndex = -1, - leftLength = partials.length, - args = Array(leftLength + argsLength), - fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; +const PatientCharacteristicRaceSchema = DataElementSchema({ + qdmTitle: { type: String, default: 'Patient Characteristic Race' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.59' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'race' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicRace' }, - while (++leftIndex < leftLength) { - args[leftIndex] = partials[leftIndex]; - } - while (argsLength--) { - args[leftIndex++] = arguments[++argsIndex]; - } - return apply(fn, isBind ? thisArg : this, args); - } - return wrapper; - } +}); - /** - * Creates a `_.range` or `_.rangeRight` function. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new range function. - */ - function createRange(fromRight) { - return function(start, end, step) { - if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { - end = step = undefined; - } - // Ensure the sign of `-0` is preserved. - start = toFinite(start); - if (end === undefined) { - end = start; - start = 0; - } else { - end = toFinite(end); - } - step = step === undefined ? (start < end ? 1 : -1) : toFinite(step); - return baseRange(start, end, step, fromRight); - }; - } +module.exports.PatientCharacteristicRaceSchema = PatientCharacteristicRaceSchema; +class PatientCharacteristicRace extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicRaceSchema); + this._type = 'QDM::PatientCharacteristicRace'; + } +} - /** - * Creates a function that performs a relational operation on two values. - * - * @private - * @param {Function} operator The function to perform the operation. - * @returns {Function} Returns the new relational operation function. - */ - function createRelationalOperation(operator) { - return function(value, other) { - if (!(typeof value == 'string' && typeof other == 'string')) { - value = toNumber(value); - other = toNumber(other); - } - return operator(value, other); - }; - } +module.exports.PatientCharacteristicRace = PatientCharacteristicRace; - /** - * Creates a function that wraps `func` to continue currying. - * - * @private - * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @param {Function} wrapFunc The function to create the `func` wrapper. - * @param {*} placeholder The placeholder value. - * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to - * the new function. - * @param {Array} [holders] The `partials` placeholder indexes. - * @param {Array} [argPos] The argument positions of the new function. - * @param {number} [ary] The arity cap of `func`. - * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new wrapped function. - */ - function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { - var isCurry = bitmask & WRAP_CURRY_FLAG, - newHolders = isCurry ? holders : undefined, - newHoldersRight = isCurry ? undefined : holders, - newPartials = isCurry ? partials : undefined, - newPartialsRight = isCurry ? undefined : partials; - bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); - bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],150:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { - bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); - } - var newData = [ - func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, - newHoldersRight, argPos, ary, arity - ]; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - var result = wrapFunc.apply(undefined, newData); - if (isLaziable(func)) { - setData(result, newData); - } - result.placeholder = placeholder; - return setWrapToString(result, func, bitmask); - } - /** - * Creates a function like `_.round`. - * - * @private - * @param {string} methodName The name of the `Math` method to use when rounding. - * @returns {Function} Returns the new round function. - */ - function createRound(methodName) { - var func = Math[methodName]; - return function(number, precision) { - number = toNumber(number); - precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); - if (precision && nativeIsFinite(number)) { - // Shift with exponential notation to avoid floating-point issues. - // See [MDN](https://mdn.io/round#Examples) for more details. - var pair = (toString(number) + 'e').split('e'), - value = func(pair[0] + 'e' + (+pair[1] + precision)); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - pair = (toString(value) + 'e').split('e'); - return +(pair[0] + 'e' + (+pair[1] - precision)); - } - return func(number); - }; - } +const PatientCharacteristicSexSchema = DataElementSchema({ + qdmTitle: { type: String, default: 'Patient Characteristic Sex' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.55' }, + qdmCategory: { type: String, default: 'patient_characteristic' }, + qdmStatus: { type: String, default: 'gender' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PatientCharacteristicSex' }, - /** - * Creates a set object of `values`. - * - * @private - * @param {Array} values The values to add to the set. - * @returns {Object} Returns the new set. - */ - var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { - return new Set(values); - }; +}); - /** - * Creates a `_.toPairs` or `_.toPairsIn` function. - * - * @private - * @param {Function} keysFunc The function to get the keys of a given object. - * @returns {Function} Returns the new pairs function. - */ - function createToPairs(keysFunc) { - return function(object) { - var tag = getTag(object); - if (tag == mapTag) { - return mapToArray(object); - } - if (tag == setTag) { - return setToPairs(object); - } - return baseToPairs(object, keysFunc(object)); - }; - } +module.exports.PatientCharacteristicSexSchema = PatientCharacteristicSexSchema; +class PatientCharacteristicSex extends mongoose.Document { + constructor(object) { + super(object, PatientCharacteristicSexSchema); + this._type = 'QDM::PatientCharacteristicSex'; + } +} - /** - * Creates a function that either curries or invokes `func` with optional - * `this` binding and partially applied arguments. - * - * @private - * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask flags. - * 1 - `_.bind` - * 2 - `_.bindKey` - * 4 - `_.curry` or `_.curryRight` of a bound function - * 8 - `_.curry` - * 16 - `_.curryRight` - * 32 - `_.partial` - * 64 - `_.partialRight` - * 128 - `_.rearg` - * 256 - `_.ary` - * 512 - `_.flip` - * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to be partially applied. - * @param {Array} [holders] The `partials` placeholder indexes. - * @param {Array} [argPos] The argument positions of the new function. - * @param {number} [ary] The arity cap of `func`. - * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new wrapped function. - */ - function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { - var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; - if (!isBindKey && typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - var length = partials ? partials.length : 0; - if (!length) { - bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); - partials = holders = undefined; - } - ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0); - arity = arity === undefined ? arity : toInteger(arity); - length -= holders ? holders.length : 0; +module.exports.PatientCharacteristicSex = PatientCharacteristicSex; + + +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],151:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) { - var partialsRight = partials, - holdersRight = holders; - partials = holders = undefined; - } - var data = isBindKey ? undefined : getData(func); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - var newData = [ - func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, - argPos, ary, arity - ]; +const PhysicalExamOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + anatomicalLocationSite: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Physical Exam, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.61' }, + qdmCategory: { type: String, default: 'physical_exam' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PhysicalExamOrder' }, - if (data) { - mergeData(newData, data); - } - func = newData[0]; - bitmask = newData[1]; - thisArg = newData[2]; - partials = newData[3]; - holders = newData[4]; - arity = newData[9] = newData[9] === undefined - ? (isBindKey ? 0 : func.length) - : nativeMax(newData[9] - length, 0); +}); - if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) { - bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); - } - if (!bitmask || bitmask == WRAP_BIND_FLAG) { - var result = createBind(func, bitmask, thisArg); - } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { - result = createCurry(func, bitmask, arity); - } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { - result = createPartial(func, bitmask, thisArg, partials); - } else { - result = createHybrid.apply(undefined, newData); - } - var setter = data ? baseSetData : setData; - return setWrapToString(setter(result, newData), func, bitmask); - } +module.exports.PhysicalExamOrderSchema = PhysicalExamOrderSchema; +class PhysicalExamOrder extends mongoose.Document { + constructor(object) { + super(object, PhysicalExamOrderSchema); + this._type = 'QDM::PhysicalExamOrder'; + } +} - /** - * Used by `_.defaults` to customize its `_.assignIn` use to assign properties - * of source objects to the destination object for all destination properties - * that resolve to `undefined`. - * - * @private - * @param {*} objValue The destination value. - * @param {*} srcValue The source value. - * @param {string} key The key of the property to assign. - * @param {Object} object The parent object of `objValue`. - * @returns {*} Returns the value to assign. - */ - function customDefaultsAssignIn(objValue, srcValue, key, object) { - if (objValue === undefined || - (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { - return srcValue; - } - return objValue; - } +module.exports.PhysicalExamOrder = PhysicalExamOrder; - /** - * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source - * objects into destination objects that are passed thru. - * - * @private - * @param {*} objValue The destination value. - * @param {*} srcValue The source value. - * @param {string} key The key of the property to merge. - * @param {Object} object The parent object of `objValue`. - * @param {Object} source The parent object of `srcValue`. - * @param {Object} [stack] Tracks traversed source values and their merged - * counterparts. - * @returns {*} Returns the value to assign. - */ - function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { - if (isObject(objValue) && isObject(srcValue)) { - // Recursively merge objects and arrays (susceptible to call stack limits). - stack.set(srcValue, objValue); - baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack); - stack['delete'](srcValue); - } - return objValue; - } - /** - * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain - * objects. - * - * @private - * @param {*} value The value to inspect. - * @param {string} key The key of the property to inspect. - * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. - */ - function customOmitClone(value) { - return isPlainObject(value) ? undefined : value; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],152:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * A specialized version of `baseIsEqualDeep` for arrays with support for - * partial deep comparisons. - * - * @private - * @param {Array} array The array to compare. - * @param {Array} other The other array to compare. - * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. - * @param {Function} customizer The function to customize comparisons. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Object} stack Tracks traversed `array` and `other` objects. - * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. - */ - function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { - var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - arrLength = array.length, - othLength = other.length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - if (arrLength != othLength && !(isPartial && othLength > arrLength)) { - return false; - } - // Check that cyclic values are equal. - var arrStacked = stack.get(array); - var othStacked = stack.get(other); - if (arrStacked && othStacked) { - return arrStacked == other && othStacked == array; - } - var index = -1, - result = true, - seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; - stack.set(array, other); - stack.set(other, array); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - // Ignore non-index properties. - while (++index < arrLength) { - var arrValue = array[index], - othValue = other[index]; +const PhysicalExamPerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + reason: Code, + method: Code, + result: Any, + anatomicalLocationSite: Code, + negationRationale: Code, + components: [ComponentSchema], + performer: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Physical Exam, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.62' }, + qdmCategory: { type: String, default: 'physical_exam' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PhysicalExamPerformed' }, - if (customizer) { - var compared = isPartial - ? customizer(othValue, arrValue, index, other, array, stack) - : customizer(arrValue, othValue, index, array, other, stack); - } - if (compared !== undefined) { - if (compared) { - continue; - } - result = false; - break; - } - // Recursively compare arrays (susceptible to call stack limits). - if (seen) { - if (!arraySome(other, function(othValue, othIndex) { - if (!cacheHas(seen, othIndex) && - (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { - return seen.push(othIndex); - } - })) { - result = false; - break; - } - } else if (!( - arrValue === othValue || - equalFunc(arrValue, othValue, bitmask, customizer, stack) - )) { - result = false; - break; - } - } - stack['delete'](array); - stack['delete'](other); - return result; - } +}); - /** - * A specialized version of `baseIsEqualDeep` for comparing objects of - * the same `toStringTag`. - * - * **Note:** This function only supports comparing values with tags of - * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {string} tag The `toStringTag` of the objects to compare. - * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. - * @param {Function} customizer The function to customize comparisons. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { - switch (tag) { - case dataViewTag: - if ((object.byteLength != other.byteLength) || - (object.byteOffset != other.byteOffset)) { - return false; - } - object = object.buffer; - other = other.buffer; +module.exports.PhysicalExamPerformedSchema = PhysicalExamPerformedSchema; +class PhysicalExamPerformed extends mongoose.Document { + constructor(object) { + super(object, PhysicalExamPerformedSchema); + this._type = 'QDM::PhysicalExamPerformed'; + } +} - case arrayBufferTag: - if ((object.byteLength != other.byteLength) || - !equalFunc(new Uint8Array(object), new Uint8Array(other))) { - return false; - } - return true; +module.exports.PhysicalExamPerformed = PhysicalExamPerformed; - case boolTag: - case dateTag: - case numberTag: - // Coerce booleans to `1` or `0` and dates to milliseconds. - // Invalid dates are coerced to `NaN`. - return eq(+object, +other); - case errorTag: - return object.name == other.name && object.message == other.message; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],153:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - case regexpTag: - case stringTag: - // Coerce regexes to strings and treat strings, primitives and objects, - // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring - // for more details. - return object == (other + ''); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - case mapTag: - var convert = mapToArray; - case setTag: - var isPartial = bitmask & COMPARE_PARTIAL_FLAG; - convert || (convert = setToArray); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - if (object.size != other.size && !isPartial) { - return false; - } - // Assume cyclic values are equal. - var stacked = stack.get(object); - if (stacked) { - return stacked == other; - } - bitmask |= COMPARE_UNORDERED_FLAG; +const PhysicalExamRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + anatomicalLocationSite: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Physical Exam, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.63' }, + qdmCategory: { type: String, default: 'physical_exam' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::PhysicalExamRecommended' }, - // Recursively compare objects (susceptible to call stack limits). - stack.set(object, other); - var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); - stack['delete'](object); - return result; +}); - case symbolTag: - if (symbolValueOf) { - return symbolValueOf.call(object) == symbolValueOf.call(other); - } - } - return false; - } +module.exports.PhysicalExamRecommendedSchema = PhysicalExamRecommendedSchema; +class PhysicalExamRecommended extends mongoose.Document { + constructor(object) { + super(object, PhysicalExamRecommendedSchema); + this._type = 'QDM::PhysicalExamRecommended'; + } +} - /** - * A specialized version of `baseIsEqualDeep` for objects with support for - * partial deep comparisons. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. - * @param {Function} customizer The function to customize comparisons. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { - var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - objProps = getAllKeys(object), - objLength = objProps.length, - othProps = getAllKeys(other), - othLength = othProps.length; +module.exports.PhysicalExamRecommended = PhysicalExamRecommended; - if (objLength != othLength && !isPartial) { - return false; - } - var index = objLength; - while (index--) { - var key = objProps[index]; - if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { - return false; - } - } - // Check that cyclic values are equal. - var objStacked = stack.get(object); - var othStacked = stack.get(other); - if (objStacked && othStacked) { - return objStacked == other && othStacked == object; - } - var result = true; - stack.set(object, other); - stack.set(other, object); - var skipCtor = isPartial; - while (++index < objLength) { - key = objProps[index]; - var objValue = object[key], - othValue = other[key]; +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],154:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - if (customizer) { - var compared = isPartial - ? customizer(othValue, objValue, key, other, object, stack) - : customizer(objValue, othValue, key, object, other, stack); - } - // Recursively compare objects (susceptible to call stack limits). - if (!(compared === undefined - ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) - : compared - )) { - result = false; - break; - } - skipCtor || (skipCtor = key == 'constructor'); - } - if (result && !skipCtor) { - var objCtor = object.constructor, - othCtor = other.constructor; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - // Non `Object` object instances with different constructors are not equal. - if (objCtor != othCtor && - ('constructor' in object && 'constructor' in other) && - !(typeof objCtor == 'function' && objCtor instanceof objCtor && - typeof othCtor == 'function' && othCtor instanceof othCtor)) { - result = false; - } - } - stack['delete'](object); - stack['delete'](other); - return result; - } - /** - * A specialized version of `baseRest` which flattens the rest array. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @returns {Function} Returns the new function. - */ - function flatRest(func) { - return setToString(overRest(func, undefined, flatten), func + ''); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates an array of own enumerable property names and symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names and symbols. - */ - function getAllKeys(object) { - return baseGetAllKeys(object, keys, getSymbols); - } +const ProcedureOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + anatomicalLocationSite: Code, + rank: Number, + priority: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Procedure, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.66' }, + qdmCategory: { type: String, default: 'procedure' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ProcedureOrder' }, - /** - * Creates an array of own and inherited enumerable property names and - * symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names and symbols. - */ - function getAllKeysIn(object) { - return baseGetAllKeys(object, keysIn, getSymbolsIn); - } +}); - /** - * Gets metadata for `func`. - * - * @private - * @param {Function} func The function to query. - * @returns {*} Returns the metadata for `func`. - */ - var getData = !metaMap ? noop : function(func) { - return metaMap.get(func); - }; +module.exports.ProcedureOrderSchema = ProcedureOrderSchema; +class ProcedureOrder extends mongoose.Document { + constructor(object) { + super(object, ProcedureOrderSchema); + this._type = 'QDM::ProcedureOrder'; + } +} - /** - * Gets the name of `func`. - * - * @private - * @param {Function} func The function to query. - * @returns {string} Returns the function name. - */ - function getFuncName(func) { - var result = (func.name + ''), - array = realNames[result], - length = hasOwnProperty.call(realNames, result) ? array.length : 0; +module.exports.ProcedureOrder = ProcedureOrder; - while (length--) { - var data = array[length], - otherFunc = data.func; - if (otherFunc == null || otherFunc == func) { - return data.name; - } - } - return result; - } - /** - * Gets the argument placeholder value for `func`. - * - * @private - * @param {Function} func The function to inspect. - * @returns {*} Returns the placeholder value. - */ - function getHolder(func) { - var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; - return object.placeholder; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],155:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Gets the appropriate "iteratee" function. If `_.iteratee` is customized, - * this function returns the custom method, otherwise it returns `baseIteratee`. - * If arguments are provided, the chosen function is invoked with them and - * its result is returned. - * - * @private - * @param {*} [value] The value to convert to an iteratee. - * @param {number} [arity] The arity of the created iteratee. - * @returns {Function} Returns the chosen function or its result. - */ - function getIteratee() { - var result = lodash.iteratee || iteratee; - result = result === iteratee ? baseIteratee : result; - return arguments.length ? result(arguments[0], arguments[1]) : result; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Gets the data for `map`. - * - * @private - * @param {Object} map The map to query. - * @param {string} key The reference key. - * @returns {*} Returns the map data. - */ - function getMapData(map, key) { - var data = map.__data__; - return isKeyable(key) - ? data[typeof key == 'string' ? 'string' : 'hash'] - : data.map; - } - /** - * Gets the property names, values, and compare flags of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the match data of `object`. - */ - function getMatchData(object) { - var result = keys(object), - length = result.length; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - while (length--) { - var key = result[length], - value = object[key]; +const ProcedurePerformedSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + reason: Code, + method: Code, + result: Any, + status: Code, + anatomicalLocationSite: Code, + rank: Number, + incisionDatetime: DateTime, + negationRationale: Code, + components: [ComponentSchema], + performer: [AnyEntity], + relatedTo: [String], + qdmTitle: { type: String, default: 'Procedure, Performed' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.67' }, + qdmCategory: { type: String, default: 'procedure' }, + qdmStatus: { type: String, default: 'performed' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ProcedurePerformed' }, - result[length] = [key, value, isStrictComparable(value)]; - } - return result; - } +}); - /** - * Gets the native function at `key` of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {string} key The key of the method to get. - * @returns {*} Returns the function if it's native, else `undefined`. - */ - function getNative(object, key) { - var value = getValue(object, key); - return baseIsNative(value) ? value : undefined; - } +module.exports.ProcedurePerformedSchema = ProcedurePerformedSchema; +class ProcedurePerformed extends mongoose.Document { + constructor(object) { + super(object, ProcedurePerformedSchema); + this._type = 'QDM::ProcedurePerformed'; + } +} - /** - * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the raw `toStringTag`. - */ - function getRawTag(value) { - var isOwn = hasOwnProperty.call(value, symToStringTag), - tag = value[symToStringTag]; +module.exports.ProcedurePerformed = ProcedurePerformed; - try { - value[symToStringTag] = undefined; - var unmasked = true; - } catch (e) {} - var result = nativeObjectToString.call(value); - if (unmasked) { - if (isOwn) { - value[symToStringTag] = tag; - } else { - delete value[symToStringTag]; - } - } - return result; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],156:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates an array of the own enumerable symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of symbols. - */ - var getSymbols = !nativeGetSymbols ? stubArray : function(object) { - if (object == null) { - return []; - } - object = Object(object); - return arrayFilter(nativeGetSymbols(object), function(symbol) { - return propertyIsEnumerable.call(object, symbol); - }); - }; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Creates an array of the own and inherited enumerable symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of symbols. - */ - var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { - var result = []; - while (object) { - arrayPush(result, getSymbols(object)); - object = getPrototype(object); - } - return result; - }; - /** - * Gets the `toStringTag` of `value`. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - var getTag = baseGetTag; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. - if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || - (Map && getTag(new Map) != mapTag) || - (Promise && getTag(Promise.resolve()) != promiseTag) || - (Set && getTag(new Set) != setTag) || - (WeakMap && getTag(new WeakMap) != weakMapTag)) { - getTag = function(value) { - var result = baseGetTag(value), - Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : ''; +const ProcedureRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + anatomicalLocationSite: Code, + rank: Number, + requester: [AnyEntity], + negationRationale: Code, + qdmTitle: { type: String, default: 'Procedure, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.68' }, + qdmCategory: { type: String, default: 'procedure' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ProcedureRecommended' }, - if (ctorString) { - switch (ctorString) { - case dataViewCtorString: return dataViewTag; - case mapCtorString: return mapTag; - case promiseCtorString: return promiseTag; - case setCtorString: return setTag; - case weakMapCtorString: return weakMapTag; - } - } - return result; - }; - } +}); - /** - * Gets the view, applying any `transforms` to the `start` and `end` positions. - * - * @private - * @param {number} start The start of the view. - * @param {number} end The end of the view. - * @param {Array} transforms The transformations to apply to the view. - * @returns {Object} Returns an object containing the `start` and `end` - * positions of the view. - */ - function getView(start, end, transforms) { - var index = -1, - length = transforms.length; +module.exports.ProcedureRecommendedSchema = ProcedureRecommendedSchema; +class ProcedureRecommended extends mongoose.Document { + constructor(object) { + super(object, ProcedureRecommendedSchema); + this._type = 'QDM::ProcedureRecommended'; + } +} - while (++index < length) { - var data = transforms[index], - size = data.size; +module.exports.ProcedureRecommended = ProcedureRecommended; - switch (data.type) { - case 'drop': start += size; break; - case 'dropRight': end -= size; break; - case 'take': end = nativeMin(end, start + size); break; - case 'takeRight': start = nativeMax(start, end - size); break; - } - } - return { 'start': start, 'end': end }; - } - /** - * Extracts wrapper details from the `source` body comment. - * - * @private - * @param {string} source The source to inspect. - * @returns {Array} Returns the wrapper details. - */ - function getWrapDetails(source) { - var match = source.match(reWrapDetails); - return match ? match[1].split(reSplitDetails) : []; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],157:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Checks if `path` exists on `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @param {Function} hasFunc The function to check properties. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - */ - function hasPath(object, path, hasFunc) { - path = castPath(path, object); +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - var index = -1, - length = path.length, - result = false; - while (++index < length) { - var key = toKey(path[index]); - if (!(result = object != null && hasFunc(object, key))) { - break; - } - object = object[key]; - } - if (result || ++index != length) { - return result; - } - length = object == null ? 0 : object.length; - return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isArguments(object)); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Initializes an array clone. - * - * @private - * @param {Array} array The array to clone. - * @returns {Array} Returns the initialized clone. - */ - function initCloneArray(array) { - var length = array.length, - result = new array.constructor(length); +const ProviderCareExperienceSchema = DataElementSchema({ + authorDatetime: DateTime, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Provider Care Experience' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.70' }, + qdmCategory: { type: String, default: 'care_experience' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::ProviderCareExperience' }, - // Add properties assigned by `RegExp#exec`. - if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { - result.index = array.index; - result.input = array.input; - } - return result; - } +}); - /** - * Initializes an object clone. - * - * @private - * @param {Object} object The object to clone. - * @returns {Object} Returns the initialized clone. - */ - function initCloneObject(object) { - return (typeof object.constructor == 'function' && !isPrototype(object)) - ? baseCreate(getPrototype(object)) - : {}; - } +module.exports.ProviderCareExperienceSchema = ProviderCareExperienceSchema; +class ProviderCareExperience extends mongoose.Document { + constructor(object) { + super(object, ProviderCareExperienceSchema); + this._type = 'QDM::ProviderCareExperience'; + } +} - /** - * Initializes an object clone based on its `toStringTag`. - * - * **Note:** This function only supports cloning values with tags of - * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. - * - * @private - * @param {Object} object The object to clone. - * @param {string} tag The `toStringTag` of the object to clone. - * @param {boolean} [isDeep] Specify a deep clone. - * @returns {Object} Returns the initialized clone. - */ - function initCloneByTag(object, tag, isDeep) { - var Ctor = object.constructor; - switch (tag) { - case arrayBufferTag: - return cloneArrayBuffer(object); +module.exports.ProviderCareExperience = ProviderCareExperience; - case boolTag: - case dateTag: - return new Ctor(+object); - case dataViewTag: - return cloneDataView(object, isDeep); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],158:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const AnyEntity = require('./basetypes/AnyEntity'); +const AllDataElements = require('./AllDataElements'); - case float32Tag: case float64Tag: - case int8Tag: case int16Tag: case int32Tag: - case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: - return cloneTypedArray(object, isDeep); +const [Schema, Number, String, Mixed] = [ + mongoose.Schema, + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, + mongoose.Schema.Types.Mixed, +]; - case mapTag: - return new Ctor; +const QDMPatientSchema = new Schema({ + birthDatetime: DateTime, + qdmVersion: { type: String, default: '5.6' }, - case numberTag: - case stringTag: - return new Ctor(object); + // These are the "data criteria", or QDM datatype elements that exist on a + // patient. + dataElements: [], + // This field is for application specific information only. If both Bonnie + // Cypress use a common field, it should be made a field on this model, + // and not put into extendedData. + extendedData: { + type: Mixed, + default: {}, + }, +}, { id: false }); - case regexpTag: - return cloneRegExp(object); +// After initialization of a Patient model, initialize every individual data element +// to its respective Mongoose Model +QDMPatientSchema.methods.initializeDataElements = function initializeDataElements() { + let typeStripped; + const dataElementsInit = []; + this.dataElements.forEach((element) => { + typeStripped = element._type.replace(/QDM::/, ''); + dataElementsInit.push(new AllDataElements[typeStripped](element)); + }); + this.set({ dataElements: dataElementsInit }); +}; - case setTag: - return new Ctor; +QDMPatientSchema.methods.id = function id() { + return this._id; +}; - case symbolTag: - return cloneSymbol(object); - } - } +// Returns an array of elements that exist on this patient, that +// match the given HQMF data criteria OID. +QDMPatientSchema.methods.getByHqmfOid = function getByHqmfOid(hqmfOid) { + return this.dataElements.filter(element => element.hqmfOid === hqmfOid); +}; - /** - * Inserts wrapper `details` in a comment at the top of the `source` body. - * - * @private - * @param {string} source The source to modify. - * @returns {Array} details The details to insert. - * @returns {string} Returns the modified source. - */ - function insertWrapDetails(source, details) { - var length = details.length; - if (!length) { - return source; - } - var lastIndex = length - 1; - details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; - details = details.join(length > 2 ? ', ' : ' '); - return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); - } +// Returns an array of elements that exist on this patient, that +// match the given QRDA data criteria OID. +QDMPatientSchema.methods.getByQrdaOid = function getByQrdaOid(qrdaOid) { + return this.dataElements.filter(element => element.qrdaOid === qrdaOid); +}; - /** - * Checks if `value` is a flattenable `arguments` object or array. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. - */ - function isFlattenable(value) { - return isArray(value) || isArguments(value) || - !!(spreadableSymbol && value && value[spreadableSymbol]); - } +// cql-execution prefers getId() over id() because some data models may have an id property +QDMPatientSchema.methods.getId = function getId() { + return this._id; +}; + +/* eslint no-underscore-dangle: 0 */ +QDMPatientSchema.methods._is = function _is(typeSpecifier) { + return this._typeHierarchy().some( + t => t.type === typeSpecifier.type && t.name === typeSpecifier.name + ); +}; + +/* eslint no-underscore-dangle: 0 */ +QDMPatientSchema.methods._typeHierarchy = function _typeHierarchy() { + const ver = this.qdmVersion.replace('.', '_'); + return [ + { + name: `{urn:healthit-gov:qdm:v${ver}}Patient`, + type: 'NamedTypeSpecifier', + }, + { name: '{urn:hl7-org:elm-types:r1}Tuple', type: 'NamedTypeSpecifier' }, + { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' }, + ]; +}; - /** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ - function isIndex(value, length) { - var type = typeof value; - length = length == null ? MAX_SAFE_INTEGER : length; +// Returns an array of elements that exist on this patient. Optionally +// takes a qdmCategory, which returns all elements of that QDM qdmCategory. +// Example: patient.getDataElements({qdmCategory: 'encounters'}) will return +// all Encounter QDM data types active on the patient. +QDMPatientSchema.methods.getDataElements = function getDataElements(params) { + if (params !== undefined && params.qdmCategory !== undefined && params.qdmStatus !== undefined) { + return this.dataElements.filter(element => (element.qdmCategory === params.qdmCategory) && (element.qdmStatus === params.qdmStatus)); + } else if (params !== undefined && params.qdmCategory !== undefined) { + return this.dataElements.filter(element => element.qdmCategory === params.qdmCategory); + } + return this.dataElements; +}; - return !!length && - (type == 'number' || - (type != 'symbol' && reIsUint.test(value))) && - (value > -1 && value % 1 == 0 && value < length); - } +QDMPatientSchema.methods.addMethodsTo = function addMethodsTo(obj, methods) { + Object.entries(methods).forEach(([method_name, method]) => { + obj[method_name] = method; + }); +}; - /** - * Checks if the given arguments are from an iteratee call. - * - * @private - * @param {*} value The potential iteratee value argument. - * @param {*} index The potential iteratee index or key argument. - * @param {*} object The potential iteratee object argument. - * @returns {boolean} Returns `true` if the arguments are from an iteratee call, - * else `false`. - */ - function isIterateeCall(value, index, object) { - if (!isObject(object)) { - return false; - } - var type = typeof index; - if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object) - ) { - return eq(object[index], value); +// Returns an array of dataElements that exist on the patient, queried by +// QDM profile +// @param {string} profile - the data criteria requested by the execution engine +// @param {boolean} isNegated - whether dataElements should be returned based on their negation status +// @returns {DataElement[]} +QDMPatientSchema.methods.getByProfile = function getByProfile(profile, isNegated = null) { + // If isNegated == true, only return data elements with a negationRationale that is not null. + // If isNegated == false, only return data elements with a null negationRationale. + // If isNegated == null, return all matching data elements by type, regardless of negationRationale. + const results = this.dataElements.filter(element => (element._type === `QDM::${profile}` || element._type === profile) && (isNegated === null || !!element.negationRationale === isNegated)); + return results.map((result) => { + // we need to convert mongoose document to an object. + // This is required for comparing the two objects(in cql-execution) as we can't compare two mongoose documents. + const removedMongooseItems = new AllDataElements[profile](result).toObject({ virtuals: true }); + // toObject() will remove all mongoose functions but also remove the schema methods, so we add them back + this.addMethodsTo(removedMongooseItems, result.schema.methods); + // add methods to entities + Object.entries(result).forEach(([key, values]) => { + // entities are always an array + if (Array.isArray(values)) { + try { + // check if the attribute is of Entity + if (AnyEntity.prototype.cast(values[0])) { + values.forEach((value, index) => { + const entity = removedMongooseItems[key][index]; + this.addMethodsTo(entity, value.schema.methods); + }); + } + // eslint-disable-next-line no-empty + } catch (e) {} } - return false; - } + }); + return removedMongooseItems; + }); +}; - /** - * Checks if `value` is a property name and not a property path. - * - * @private - * @param {*} value The value to check. - * @param {Object} [object] The object to query keys on. - * @returns {boolean} Returns `true` if `value` is a property name, else `false`. - */ - function isKey(value, object) { - if (isArray(value)) { - return false; - } - var type = typeof value; - if (type == 'number' || type == 'symbol' || type == 'boolean' || - value == null || isSymbol(value)) { - return true; - } - return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || - (object != null && value in Object(object)); - } +// This method is called by the CQL execution engine on a CQLPatient when +// the execution engine wants information on a record. A record could be patient +// characteristic information about the patient, or it could be data criteria +// that currently exist on this patient (data criteria you drag on a patient +// in Bonnie patient builder). +// @param {String} profile - the data criteria requested by the execution engine +// @returns {Object} +QDMPatientSchema.methods.findRecords = function findRecords(profile) { + // Clear profile cache for this patient if there is no cache or the patient has changed + if (QDMPatientSchema.dataElementCache == null + || QDMPatientSchema.dataElementCachePatientId !== this._id) { + QDMPatientSchema.dataElementCache = {}; + QDMPatientSchema.dataElementCachePatientId = this._id; + } + // If there is a cache 'hit', return it + if (Object.prototype.hasOwnProperty.call(QDMPatientSchema.dataElementCache, profile)) { + return QDMPatientSchema.dataElementCache[profile]; + } + let profileStripped; + if (profile === 'Patient') { + // Requested generic patient info + const info = { birthDatetime: this.birthDatetime }; + QDMPatientSchema.dataElementCache[profile] = [info]; + return [info]; + } else if (/PatientCharacteristic/.test(profile)) { + // Requested a patient characteristic + profileStripped = profile.replace(/ *\{[^)]*\} */g, ''); + QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped); + return QDMPatientSchema.dataElementCache[profile]; + } else if (profile != null) { + // Requested something else (probably a QDM data type). - /** - * Checks if `value` is suitable for use as unique object key. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is suitable, else `false`. - */ - function isKeyable(value) { - var type = typeof value; - return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') - ? (value !== '__proto__') - : (value === null); + // Strip model details from request. The requested profile string contains + // a lot of things we do not need or care about. Example, we might see + // something like: + // "{urn:healthit-gov:qdm:v5_0_draft}PatientCharacteristicEthnicity" + // Where we only care about: "PatientCharacteristicEthnicity". + profileStripped = profile.replace(/ *\{[^)]*\} */g, ''); + + // Check and handle negation status + if (/Positive/.test(profileStripped)) { + profileStripped = profileStripped.replace(/Positive/, ''); + // Since the data criteria is 'Positive', it is not negated. + QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped, false); + return QDMPatientSchema.dataElementCache[profile]; + } else if (/Negative/.test(profileStripped)) { + profileStripped = profileStripped.replace(/Negative/, ''); + // Since the data criteria is 'Negative', it is negated. + QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped, true); + return QDMPatientSchema.dataElementCache[profile]; } + // No negation status, proceed normally + QDMPatientSchema.dataElementCache[profile] = this.getByProfile(profileStripped); + return QDMPatientSchema.dataElementCache[profile]; + } + return []; +}; - /** - * Checks if `func` has a lazy counterpart. - * - * @private - * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` has a lazy counterpart, - * else `false`. - */ - function isLaziable(func) { - var funcName = getFuncName(func), - other = lodash[funcName]; +QDMPatientSchema.methods.adverse_events = function adverse_events() { + return this.getDataElements({ qdmCategory: 'adverse_event' }); +}; - if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { - return false; - } - if (func === other) { - return true; - } - var data = getData(other); - return !!data && func === data[0]; - } +QDMPatientSchema.methods.allergies = function allergies() { + return this.getDataElements({ qdmCategory: 'allergy' }); +}; - /** - * Checks if `func` has its source masked. - * - * @private - * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` is masked, else `false`. - */ - function isMasked(func) { - return !!maskSrcKey && (maskSrcKey in func); - } +QDMPatientSchema.methods.assessments = function assessments() { + return this.getDataElements({ qdmCategory: 'assessment' }); +}; - /** - * Checks if `func` is capable of being masked. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `func` is maskable, else `false`. - */ - var isMaskable = coreJsData ? isFunction : stubFalse; +QDMPatientSchema.methods.care_experiences = function care_experiences() { + return this.getDataElements({ qdmCategory: 'care_experience' }); +}; - /** - * Checks if `value` is likely a prototype object. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. - */ - function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; +QDMPatientSchema.methods.care_goals = function care_goals() { + return this.getDataElements({ qdmCategory: 'care_goal' }); +}; - return value === proto; - } +QDMPatientSchema.methods.communications = function communications() { + return this.getDataElements({ qdmCategory: 'communication' }); +}; - /** - * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` if suitable for strict - * equality comparisons, else `false`. - */ - function isStrictComparable(value) { - return value === value && !isObject(value); - } +QDMPatientSchema.methods.conditions = function conditions() { + return this.getDataElements({ qdmCategory: 'condition' }); +}; - /** - * A specialized version of `matchesProperty` for source values suitable - * for strict equality comparisons, i.e. `===`. - * - * @private - * @param {string} key The key of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function matchesStrictComparable(key, srcValue) { - return function(object) { - if (object == null) { - return false; - } - return object[key] === srcValue && - (srcValue !== undefined || (key in Object(object))); - }; - } +QDMPatientSchema.methods.devices = function devices() { + return this.getDataElements({ qdmCategory: 'device' }); +}; - /** - * A specialized version of `_.memoize` which clears the memoized function's - * cache when it exceeds `MAX_MEMOIZE_SIZE`. - * - * @private - * @param {Function} func The function to have its output memoized. - * @returns {Function} Returns the new memoized function. - */ - function memoizeCapped(func) { - var result = memoize(func, function(key) { - if (cache.size === MAX_MEMOIZE_SIZE) { - cache.clear(); - } - return key; - }); +QDMPatientSchema.methods.diagnostic_studies = function diagnostic_studies() { + return this.getDataElements({ qdmCategory: 'diagnostic_study' }); +}; - var cache = result.cache; - return result; - } +QDMPatientSchema.methods.encounters = function encounters() { + return this.getDataElements({ qdmCategory: 'encounter' }); +}; - /** - * Merges the function metadata of `source` into `data`. - * - * Merging metadata reduces the number of wrappers used to invoke a function. - * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` - * may be applied regardless of execution order. Methods like `_.ary` and - * `_.rearg` modify function arguments, making the order in which they are - * executed important, preventing the merging of metadata. However, we make - * an exception for a safe combined case where curried functions have `_.ary` - * and or `_.rearg` applied. - * - * @private - * @param {Array} data The destination metadata. - * @param {Array} source The source metadata. - * @returns {Array} Returns `data`. - */ - function mergeData(data, source) { - var bitmask = data[1], - srcBitmask = source[1], - newBitmask = bitmask | srcBitmask, - isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); +QDMPatientSchema.methods.family_history = function family_history() { + return this.getDataElements({ qdmCategory: 'family_history' }); +}; - var isCombo = - ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || - ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || - ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); +QDMPatientSchema.methods.functional_statuses = function functional_statuses() { + return this.getDataElements({ qdmCategory: 'functional_status' }); +}; - // Exit early if metadata can't be merged. - if (!(isCommon || isCombo)) { - return data; - } - // Use source `thisArg` if available. - if (srcBitmask & WRAP_BIND_FLAG) { - data[2] = source[2]; - // Set when currying a bound function. - newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG; - } - // Compose partial arguments. - var value = source[3]; - if (value) { - var partials = data[3]; - data[3] = partials ? composeArgs(partials, value, source[4]) : value; - data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; - } - // Compose partial right arguments. - value = source[5]; - if (value) { - partials = data[5]; - data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; - data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; - } - // Use source `argPos` if available. - value = source[7]; - if (value) { - data[7] = value; - } - // Use source `ary` if it's smaller. - if (srcBitmask & WRAP_ARY_FLAG) { - data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); - } - // Use source `arity` if one is not provided. - if (data[9] == null) { - data[9] = source[9]; - } - // Use source `func` and merge bitmasks. - data[0] = source[0]; - data[1] = newBitmask; +QDMPatientSchema.methods.immunizations = function immunizations() { + return this.getDataElements({ qdmCategory: 'immunization' }); +}; - return data; - } +QDMPatientSchema.methods.interventions = function interventions() { + return this.getDataElements({ qdmCategory: 'intervention' }); +}; - /** - * This function is like - * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * except that it includes inherited enumerable properties. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function nativeKeysIn(object) { - var result = []; - if (object != null) { - for (var key in Object(object)) { - result.push(key); - } - } - return result; - } +QDMPatientSchema.methods.laboratory_tests = function laboratory_tests() { + return this.getDataElements({ qdmCategory: 'laboratory_test' }); +}; - /** - * Converts `value` to a string using `Object.prototype.toString`. - * - * @private - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - */ - function objectToString(value) { - return nativeObjectToString.call(value); - } +QDMPatientSchema.methods.medical_equipment = function medical_equipment() { + return this.getDataElements({ qdmCategory: 'medical_equipment' }); +}; - /** - * A specialized version of `baseRest` which transforms the rest array. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @param {Function} transform The rest array transform. - * @returns {Function} Returns the new function. - */ - function overRest(func, start, transform) { - start = nativeMax(start === undefined ? (func.length - 1) : start, 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); +QDMPatientSchema.methods.medications = function medications() { + return this.getDataElements({ qdmCategory: 'medication' }); +}; - while (++index < length) { - array[index] = args[start + index]; - } - index = -1; - var otherArgs = Array(start + 1); - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = transform(array); - return apply(func, this, otherArgs); - }; - } +QDMPatientSchema.methods.patient_characteristics = function patient_characteristics() { + return this.getDataElements({ qdmCategory: 'patient_characteristic' }); +}; - /** - * Gets the parent value at `path` of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Array} path The path to get the parent value of. - * @returns {*} Returns the parent value. - */ - function parent(object, path) { - return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); - } +QDMPatientSchema.methods.physical_exams = function physical_exams() { + return this.getDataElements({ qdmCategory: 'physical_exam' }); +}; - /** - * Reorder `array` according to the specified indexes where the element at - * the first index is assigned as the first element, the element at - * the second index is assigned as the second element, and so on. - * - * @private - * @param {Array} array The array to reorder. - * @param {Array} indexes The arranged array indexes. - * @returns {Array} Returns `array`. - */ - function reorder(array, indexes) { - var arrLength = array.length, - length = nativeMin(indexes.length, arrLength), - oldArray = copyArray(array); +QDMPatientSchema.methods.preferences = function preferences() { + return this.getDataElements({ qdmCategory: 'preference' }); +}; - while (length--) { - var index = indexes[length]; - array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined; - } - return array; - } +QDMPatientSchema.methods.procedures = function procedures() { + return this.getDataElements({ qdmCategory: 'procedure' }); +}; - /** - * Gets the value at `key`, unless `key` is "__proto__" or "constructor". - * - * @private - * @param {Object} object The object to query. - * @param {string} key The key of the property to get. - * @returns {*} Returns the property value. - */ - function safeGet(object, key) { - if (key === 'constructor' && typeof object[key] === 'function') { - return; - } +QDMPatientSchema.methods.results = function results() { + return this.getDataElements({ qdmCategory: 'result' }); +}; - if (key == '__proto__') { - return; - } +QDMPatientSchema.methods.risk_category_assessments = function risk_category_assessments() { + return this.getDataElements({ qdmCategory: 'risk_category_assessment' }); +}; - return object[key]; - } +QDMPatientSchema.methods.social_history = function social_history() { + return this.getDataElements({ qdmCategory: 'social_history' }); +}; - /** - * Sets metadata for `func`. - * - * **Note:** If this function becomes hot, i.e. is invoked a lot in a short - * period of time, it will trip its breaker and transition to an identity - * function to avoid garbage collection pauses in V8. See - * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) - * for more details. - * - * @private - * @param {Function} func The function to associate metadata with. - * @param {*} data The metadata. - * @returns {Function} Returns `func`. - */ - var setData = shortOut(baseSetData); +QDMPatientSchema.methods.substances = function substances() { + return this.getDataElements({ qdmCategory: 'substance' }); +}; - /** - * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout). - * - * @private - * @param {Function} func The function to delay. - * @param {number} wait The number of milliseconds to delay invocation. - * @returns {number|Object} Returns the timer id or timeout object. - */ - var setTimeout = ctxSetTimeout || function(func, wait) { - return root.setTimeout(func, wait); - }; +QDMPatientSchema.methods.symptoms = function symptoms() { + return this.getDataElements({ qdmCategory: 'symptom' }); +}; - /** - * Sets the `toString` method of `func` to return `string`. - * - * @private - * @param {Function} func The function to modify. - * @param {Function} string The `toString` result. - * @returns {Function} Returns `func`. - */ - var setToString = shortOut(baseSetToString); +QDMPatientSchema.methods.system_characteristics = function system_characteristics() { + return this.getDataElements({ qdmCategory: 'system_characteristic' }); +}; - /** - * Sets the `toString` method of `wrapper` to mimic the source of `reference` - * with wrapper details in a comment at the top of the source body. - * - * @private - * @param {Function} wrapper The function to modify. - * @param {Function} reference The reference function. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @returns {Function} Returns `wrapper`. - */ - function setWrapToString(wrapper, reference, bitmask) { - var source = (reference + ''); - return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))); - } +QDMPatientSchema.methods.transfers = function transfers() { + return this.getDataElements({ qdmCategory: 'transfer' }); +}; - /** - * Creates a function that'll short out and invoke `identity` instead - * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` - * milliseconds. - * - * @private - * @param {Function} func The function to restrict. - * @returns {Function} Returns the new shortable function. - */ - function shortOut(func) { - var count = 0, - lastCalled = 0; +QDMPatientSchema.methods.vital_signs = function vital_signs() { + return this.getDataElements({ qdmCategory: 'vital_sign' }); +}; - return function() { - var stamp = nativeNow(), - remaining = HOT_SPAN - (stamp - lastCalled); +QDMPatientSchema.clearDataElementCache = function clearDataElementCache() { + QDMPatientSchema.dataElementCachePatientId = null; + QDMPatientSchema.dataElementCache = null; +}; - lastCalled = stamp; - if (remaining > 0) { - if (++count >= HOT_COUNT) { - return arguments[0]; - } - } else { - count = 0; - } - return func.apply(undefined, arguments); - }; - } +module.exports.QDMPatientSchema = QDMPatientSchema; +class QDMPatient extends mongoose.Document { + constructor(object) { + super(object, QDMPatientSchema); + this.initializeDataElements(); + } +} +module.exports.QDMPatient = QDMPatient; - /** - * A specialized version of `_.shuffle` which mutates and sets the size of `array`. - * - * @private - * @param {Array} array The array to shuffle. - * @param {number} [size=array.length] The size of `array`. - * @returns {Array} Returns `array`. - */ - function shuffleSelf(array, size) { - var index = -1, - length = array.length, - lastIndex = length - 1; +},{"./AllDataElements":111,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/Quantity":183,"mongoose/browser":226}],159:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - size = size === undefined ? length : size; - while (++index < size) { - var rand = baseRandom(index, lastIndex), - value = array[rand]; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - array[rand] = array[index]; - array[index] = value; - } - array.length = size; - return array; - } - /** - * Converts `string` to a property path array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the property path array. - */ - var stringToPath = memoizeCapped(function(string) { - var result = []; - if (string.charCodeAt(0) === 46 /* . */) { - result.push(''); - } - string.replace(rePropName, function(match, number, quote, subString) { - result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); - }); - return result; - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Converts `value` to a string key if it's not a string or symbol. - * - * @private - * @param {*} value The value to inspect. - * @returns {string|symbol} Returns the key. - */ - function toKey(value) { - if (typeof value == 'string' || isSymbol(value)) { - return value; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } +const RelatedPersonSchema = DataElementSchema({ + identifier: IdentifierSchema, + linkedPatientId: String, + qdmTitle: { type: String, default: 'Related Person' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.141' }, + qdmCategory: { type: String, default: 'related_person' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::RelatedPerson' }, - /** - * Converts `func` to its source code. - * - * @private - * @param {Function} func The function to convert. - * @returns {string} Returns the source code. - */ - function toSource(func) { - if (func != null) { - try { - return funcToString.call(func); - } catch (e) {} - try { - return (func + ''); - } catch (e) {} - } - return ''; - } +}); - /** - * Updates wrapper `details` based on `bitmask` flags. - * - * @private - * @returns {Array} details The details to modify. - * @param {number} bitmask The bitmask flags. See `createWrap` for more details. - * @returns {Array} Returns `details`. - */ - function updateWrapDetails(details, bitmask) { - arrayEach(wrapFlags, function(pair) { - var value = '_.' + pair[0]; - if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { - details.push(value); - } - }); - return details.sort(); - } +module.exports.RelatedPersonSchema = RelatedPersonSchema; +class RelatedPerson extends mongoose.Document { + constructor(object) { + super(object, RelatedPersonSchema); + this._type = 'QDM::RelatedPerson'; + } +} - /** - * Creates a clone of `wrapper`. - * - * @private - * @param {Object} wrapper The wrapper to clone. - * @returns {Object} Returns the cloned wrapper. - */ - function wrapperClone(wrapper) { - if (wrapper instanceof LazyWrapper) { - return wrapper.clone(); - } - var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); - result.__actions__ = copyArray(wrapper.__actions__); - result.__index__ = wrapper.__index__; - result.__values__ = wrapper.__values__; - return result; - } +module.exports.RelatedPerson = RelatedPerson; - /*------------------------------------------------------------------------*/ - /** - * Creates an array of elements split into groups the length of `size`. - * If `array` can't be split evenly, the final chunk will be the remaining - * elements. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to process. - * @param {number} [size=1] The length of each chunk - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the new array of chunks. - * @example - * - * _.chunk(['a', 'b', 'c', 'd'], 2); - * // => [['a', 'b'], ['c', 'd']] - * - * _.chunk(['a', 'b', 'c', 'd'], 3); - * // => [['a', 'b', 'c'], ['d']] - */ - function chunk(array, size, guard) { - if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) { - size = 1; - } else { - size = nativeMax(toInteger(size), 0); - } - var length = array == null ? 0 : array.length; - if (!length || size < 1) { - return []; - } - var index = 0, - resIndex = 0, - result = Array(nativeCeil(length / size)); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],160:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - while (index < length) { - result[resIndex++] = baseSlice(array, index, (index += size)); - } - return result; - } +const PlaceholderResultSchema = mongoose.Schema({ + cache_id: String, + measure_id: String, + sub_id: String, + test_id: String, + effective_date: Number, + filters: Object, + prefilter: Object, + calculation_time: Date, + status: Object, + population_ids: Object, + STRAT: Number, + IPP: Number, + DENOM: Number, + NUMER: Number, + NUMEX: Number, + DENEX: Number, + DENEXCEP: Number, + MSRPOPL: Number, + OBSERV: Number, + MSRPOPLEX: Number, + supplemental_data: Object, +}); - /** - * Creates an array with all falsey values removed. The values `false`, `null`, - * `0`, `""`, `undefined`, and `NaN` are falsey. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to compact. - * @returns {Array} Returns the new array of filtered values. - * @example - * - * _.compact([0, 1, false, 2, '', 3]); - * // => [1, 2, 3] - */ - function compact(array) { - var index = -1, - length = array == null ? 0 : array.length, - resIndex = 0, - result = []; +module.exports.ResultSchema = PlaceholderResultSchema; +class PlaceholderResult extends mongoose.Document { + constructor(object) { + super(object, PlaceholderResultSchema); + } +} +module.exports.PlaceholderResult = PlaceholderResult; - while (++index < length) { - var value = array[index]; - if (value) { - result[resIndex++] = value; - } - } - return result; - } +},{"mongoose/browser":226}],161:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates a new array concatenating `array` with any additional arrays - * and/or values. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to concatenate. - * @param {...*} [values] The values to concatenate. - * @returns {Array} Returns the new concatenated array. - * @example - * - * var array = [1]; - * var other = _.concat(array, 2, [3], [[4]]); - * - * console.log(other); - * // => [1, 2, 3, [4]] - * - * console.log(array); - * // => [1] - */ - function concat() { - var length = arguments.length; - if (!length) { - return []; - } - var args = Array(length - 1), - array = arguments[0], - index = length; +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - while (index--) { - args[index - 1] = arguments[index]; - } - return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); - } - /** - * Creates an array of `array` values not included in the other given arrays - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. The order and references of result values are - * determined by the first array. - * - * **Note:** Unlike `_.pullAll`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {...Array} [values] The values to exclude. - * @returns {Array} Returns the new array of filtered values. - * @see _.without, _.xor - * @example - * - * _.difference([2, 1], [2, 3]); - * // => [1] - */ - var difference = baseRest(function(array, values) { - return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) - : []; - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * This method is like `_.difference` except that it accepts `iteratee` which - * is invoked for each element of `array` and `values` to generate the criterion - * by which they're compared. The order and references of result values are - * determined by the first array. The iteratee is invoked with one argument: - * (value). - * - * **Note:** Unlike `_.pullAllBy`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {...Array} [values] The values to exclude. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns the new array of filtered values. - * @example - * - * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); - * // => [1.2] - * - * // The `_.property` iteratee shorthand. - * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); - * // => [{ 'x': 2 }] - */ - var differenceBy = baseRest(function(array, values) { - var iteratee = last(values); - if (isArrayLikeObject(iteratee)) { - iteratee = undefined; - } - return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) - : []; - }); +const SubstanceAdministeredSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantDatetime: DateTime, + relevantPeriod: Interval, + dosage: Quantity, + frequency: Code, + route: Code, + negationRationale: Code, + performer: [AnyEntity], + qdmTitle: { type: String, default: 'Substance, Administered' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.73' }, + qdmCategory: { type: String, default: 'substance' }, + qdmStatus: { type: String, default: 'administered' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::SubstanceAdministered' }, - /** - * This method is like `_.difference` except that it accepts `comparator` - * which is invoked to compare elements of `array` to `values`. The order and - * references of result values are determined by the first array. The comparator - * is invoked with two arguments: (arrVal, othVal). - * - * **Note:** Unlike `_.pullAllWith`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {...Array} [values] The values to exclude. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of filtered values. - * @example - * - * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; - * - * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); - * // => [{ 'x': 2, 'y': 1 }] - */ - var differenceWith = baseRest(function(array, values) { - var comparator = last(values); - if (isArrayLikeObject(comparator)) { - comparator = undefined; - } - return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) - : []; - }); +}); - /** - * Creates a slice of `array` with `n` elements dropped from the beginning. - * - * @static - * @memberOf _ - * @since 0.5.0 - * @category Array - * @param {Array} array The array to query. - * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.drop([1, 2, 3]); - * // => [2, 3] - * - * _.drop([1, 2, 3], 2); - * // => [3] - * - * _.drop([1, 2, 3], 5); - * // => [] - * - * _.drop([1, 2, 3], 0); - * // => [1, 2, 3] - */ - function drop(array, n, guard) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - n = (guard || n === undefined) ? 1 : toInteger(n); - return baseSlice(array, n < 0 ? 0 : n, length); - } +module.exports.SubstanceAdministeredSchema = SubstanceAdministeredSchema; +class SubstanceAdministered extends mongoose.Document { + constructor(object) { + super(object, SubstanceAdministeredSchema); + this._type = 'QDM::SubstanceAdministered'; + } +} - /** - * Creates a slice of `array` with `n` elements dropped from the end. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.dropRight([1, 2, 3]); - * // => [1, 2] - * - * _.dropRight([1, 2, 3], 2); - * // => [1] - * - * _.dropRight([1, 2, 3], 5); - * // => [] - * - * _.dropRight([1, 2, 3], 0); - * // => [1, 2, 3] - */ - function dropRight(array, n, guard) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - n = (guard || n === undefined) ? 1 : toInteger(n); - n = length - n; - return baseSlice(array, 0, n < 0 ? 0 : n); - } +module.exports.SubstanceAdministered = SubstanceAdministered; - /** - * Creates a slice of `array` excluding elements dropped from the end. - * Elements are dropped until `predicate` returns falsey. The predicate is - * invoked with three arguments: (value, index, array). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the slice of `array`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': true }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': false } - * ]; - * - * _.dropRightWhile(users, function(o) { return !o.active; }); - * // => objects for ['barney'] - * - * // The `_.matches` iteratee shorthand. - * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); - * // => objects for ['barney', 'fred'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.dropRightWhile(users, ['active', false]); - * // => objects for ['barney'] - * - * // The `_.property` iteratee shorthand. - * _.dropRightWhile(users, 'active'); - * // => objects for ['barney', 'fred', 'pebbles'] - */ - function dropRightWhile(array, predicate) { - return (array && array.length) - ? baseWhile(array, getIteratee(predicate, 3), true, true) - : []; - } - /** - * Creates a slice of `array` excluding elements dropped from the beginning. - * Elements are dropped until `predicate` returns falsey. The predicate is - * invoked with three arguments: (value, index, array). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the slice of `array`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': false }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': true } - * ]; - * - * _.dropWhile(users, function(o) { return !o.active; }); - * // => objects for ['pebbles'] - * - * // The `_.matches` iteratee shorthand. - * _.dropWhile(users, { 'user': 'barney', 'active': false }); - * // => objects for ['fred', 'pebbles'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.dropWhile(users, ['active', false]); - * // => objects for ['pebbles'] - * - * // The `_.property` iteratee shorthand. - * _.dropWhile(users, 'active'); - * // => objects for ['barney', 'fred', 'pebbles'] - */ - function dropWhile(array, predicate) { - return (array && array.length) - ? baseWhile(array, getIteratee(predicate, 3), true) - : []; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],162:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Fills elements of `array` with `value` from `start` up to, but not - * including, `end`. - * - * **Note:** This method mutates `array`. - * - * @static - * @memberOf _ - * @since 3.2.0 - * @category Array - * @param {Array} array The array to fill. - * @param {*} value The value to fill `array` with. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns `array`. - * @example - * - * var array = [1, 2, 3]; - * - * _.fill(array, 'a'); - * console.log(array); - * // => ['a', 'a', 'a'] - * - * _.fill(Array(3), 2); - * // => [2, 2, 2] - * - * _.fill([4, 6, 8, 10], '*', 1, 3); - * // => [4, '*', '*', 10] - */ - function fill(array, value, start, end) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { - start = 0; - end = length; - } - return baseFill(array, value, start, end); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * This method is like `_.find` except that it returns the index of the first - * element `predicate` returns truthy for instead of the element itself. - * - * @static - * @memberOf _ - * @since 1.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the found element, else `-1`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': false }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': true } - * ]; - * - * _.findIndex(users, function(o) { return o.user == 'barney'; }); - * // => 0 - * - * // The `_.matches` iteratee shorthand. - * _.findIndex(users, { 'user': 'fred', 'active': false }); - * // => 1 - * - * // The `_.matchesProperty` iteratee shorthand. - * _.findIndex(users, ['active', false]); - * // => 0 - * - * // The `_.property` iteratee shorthand. - * _.findIndex(users, 'active'); - * // => 2 - */ - function findIndex(array, predicate, fromIndex) { - var length = array == null ? 0 : array.length; - if (!length) { - return -1; - } - var index = fromIndex == null ? 0 : toInteger(fromIndex); - if (index < 0) { - index = nativeMax(length + index, 0); - } - return baseFindIndex(array, getIteratee(predicate, 3), index); - } - /** - * This method is like `_.findIndex` except that it iterates over elements - * of `collection` from right to left. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param {number} [fromIndex=array.length-1] The index to search from. - * @returns {number} Returns the index of the found element, else `-1`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': true }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': false } - * ]; - * - * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); - * // => 2 - * - * // The `_.matches` iteratee shorthand. - * _.findLastIndex(users, { 'user': 'barney', 'active': true }); - * // => 0 - * - * // The `_.matchesProperty` iteratee shorthand. - * _.findLastIndex(users, ['active', false]); - * // => 2 - * - * // The `_.property` iteratee shorthand. - * _.findLastIndex(users, 'active'); - * // => 0 - */ - function findLastIndex(array, predicate, fromIndex) { - var length = array == null ? 0 : array.length; - if (!length) { - return -1; - } - var index = length - 1; - if (fromIndex !== undefined) { - index = toInteger(fromIndex); - index = fromIndex < 0 - ? nativeMax(length + index, 0) - : nativeMin(index, length - 1); - } - return baseFindIndex(array, getIteratee(predicate, 3), index, true); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Flattens `array` a single level deep. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to flatten. - * @returns {Array} Returns the new flattened array. - * @example - * - * _.flatten([1, [2, [3, [4]], 5]]); - * // => [1, 2, [3, [4]], 5] - */ - function flatten(array) { - var length = array == null ? 0 : array.length; - return length ? baseFlatten(array, 1) : []; - } +const SubstanceOrderSchema = DataElementSchema({ + authorDatetime: DateTime, + relevantPeriod: Interval, + reason: Code, + dosage: Quantity, + supply: Quantity, + frequency: Code, + refills: Number, + route: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Substance, Order' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.77' }, + qdmCategory: { type: String, default: 'substance' }, + qdmStatus: { type: String, default: 'order' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::SubstanceOrder' }, - /** - * Recursively flattens `array`. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to flatten. - * @returns {Array} Returns the new flattened array. - * @example - * - * _.flattenDeep([1, [2, [3, [4]], 5]]); - * // => [1, 2, 3, 4, 5] - */ - function flattenDeep(array) { - var length = array == null ? 0 : array.length; - return length ? baseFlatten(array, INFINITY) : []; - } +}); - /** - * Recursively flatten `array` up to `depth` times. - * - * @static - * @memberOf _ - * @since 4.4.0 - * @category Array - * @param {Array} array The array to flatten. - * @param {number} [depth=1] The maximum recursion depth. - * @returns {Array} Returns the new flattened array. - * @example - * - * var array = [1, [2, [3, [4]], 5]]; - * - * _.flattenDepth(array, 1); - * // => [1, 2, [3, [4]], 5] - * - * _.flattenDepth(array, 2); - * // => [1, 2, 3, [4], 5] - */ - function flattenDepth(array, depth) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - depth = depth === undefined ? 1 : toInteger(depth); - return baseFlatten(array, depth); - } +module.exports.SubstanceOrderSchema = SubstanceOrderSchema; +class SubstanceOrder extends mongoose.Document { + constructor(object) { + super(object, SubstanceOrderSchema); + this._type = 'QDM::SubstanceOrder'; + } +} - /** - * The inverse of `_.toPairs`; this method returns an object composed - * from key-value `pairs`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} pairs The key-value pairs. - * @returns {Object} Returns the new object. - * @example - * - * _.fromPairs([['a', 1], ['b', 2]]); - * // => { 'a': 1, 'b': 2 } - */ - function fromPairs(pairs) { - var index = -1, - length = pairs == null ? 0 : pairs.length, - result = {}; +module.exports.SubstanceOrder = SubstanceOrder; - while (++index < length) { - var pair = pairs[index]; - result[pair[0]] = pair[1]; - } - return result; - } - /** - * Gets the first element of `array`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @alias first - * @category Array - * @param {Array} array The array to query. - * @returns {*} Returns the first element of `array`. - * @example - * - * _.head([1, 2, 3]); - * // => 1 - * - * _.head([]); - * // => undefined - */ - function head(array) { - return (array && array.length) ? array[0] : undefined; - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],163:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Gets the index at which the first occurrence of `value` is found in `array` - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. If `fromIndex` is negative, it's used as the - * offset from the end of `array`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - * @example - * - * _.indexOf([1, 2, 1, 2], 2); - * // => 1 - * - * // Search from the `fromIndex`. - * _.indexOf([1, 2, 1, 2], 2, 2); - * // => 3 - */ - function indexOf(array, value, fromIndex) { - var length = array == null ? 0 : array.length; - if (!length) { - return -1; - } - var index = fromIndex == null ? 0 : toInteger(fromIndex); - if (index < 0) { - index = nativeMax(length + index, 0); - } - return baseIndexOf(array, value, index); - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * Gets all but the last element of `array`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to query. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.initial([1, 2, 3]); - * // => [1, 2] - */ - function initial(array) { - var length = array == null ? 0 : array.length; - return length ? baseSlice(array, 0, -1) : []; - } - /** - * Creates an array of unique values that are included in all given arrays - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. The order and references of result values are - * determined by the first array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @returns {Array} Returns the new array of intersecting values. - * @example - * - * _.intersection([2, 1], [2, 3]); - * // => [2] - */ - var intersection = baseRest(function(arrays) { - var mapped = arrayMap(arrays, castArrayLikeObject); - return (mapped.length && mapped[0] === arrays[0]) - ? baseIntersection(mapped) - : []; - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const SubstanceRecommendedSchema = DataElementSchema({ + authorDatetime: DateTime, + reason: Code, + dosage: Quantity, + frequency: Code, + refills: Number, + route: Code, + negationRationale: Code, + requester: [AnyEntity], + qdmTitle: { type: String, default: 'Substance, Recommended' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.78' }, + qdmCategory: { type: String, default: 'substance' }, + qdmStatus: { type: String, default: 'recommended' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::SubstanceRecommended' }, - /** - * This method is like `_.intersection` except that it accepts `iteratee` - * which is invoked for each element of each `arrays` to generate the criterion - * by which they're compared. The order and references of result values are - * determined by the first array. The iteratee is invoked with one argument: - * (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns the new array of intersecting values. - * @example - * - * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); - * // => [2.1] - * - * // The `_.property` iteratee shorthand. - * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); - * // => [{ 'x': 1 }] - */ - var intersectionBy = baseRest(function(arrays) { - var iteratee = last(arrays), - mapped = arrayMap(arrays, castArrayLikeObject); +}); - if (iteratee === last(mapped)) { - iteratee = undefined; - } else { - mapped.pop(); - } - return (mapped.length && mapped[0] === arrays[0]) - ? baseIntersection(mapped, getIteratee(iteratee, 2)) - : []; - }); +module.exports.SubstanceRecommendedSchema = SubstanceRecommendedSchema; +class SubstanceRecommended extends mongoose.Document { + constructor(object) { + super(object, SubstanceRecommendedSchema); + this._type = 'QDM::SubstanceRecommended'; + } +} - /** - * This method is like `_.intersection` except that it accepts `comparator` - * which is invoked to compare elements of `arrays`. The order and references - * of result values are determined by the first array. The comparator is - * invoked with two arguments: (arrVal, othVal). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of intersecting values. - * @example - * - * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; - * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; - * - * _.intersectionWith(objects, others, _.isEqual); - * // => [{ 'x': 1, 'y': 2 }] - */ - var intersectionWith = baseRest(function(arrays) { - var comparator = last(arrays), - mapped = arrayMap(arrays, castArrayLikeObject); +module.exports.SubstanceRecommended = SubstanceRecommended; - comparator = typeof comparator == 'function' ? comparator : undefined; - if (comparator) { - mapped.pop(); - } - return (mapped.length && mapped[0] === arrays[0]) - ? baseIntersection(mapped, undefined, comparator) - : []; - }); - /** - * Converts all elements in `array` into a string separated by `separator`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to convert. - * @param {string} [separator=','] The element separator. - * @returns {string} Returns the joined string. - * @example - * - * _.join(['a', 'b', 'c'], '~'); - * // => 'a~b~c' - */ - function join(array, separator) { - return array == null ? '' : nativeJoin.call(array, separator); - } +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],164:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Gets the last element of `array`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to query. - * @returns {*} Returns the last element of `array`. - * @example - * - * _.last([1, 2, 3]); - * // => 3 - */ - function last(array) { - var length = array == null ? 0 : array.length; - return length ? array[length - 1] : undefined; - } +const { IdentifierSchema } = require('./attributes/Identifier'); +const { DataElementSchema } = require('./basetypes/DataElement'); +const Code = require('./basetypes/Code'); +const Interval = require('./basetypes/Interval'); +const Quantity = require('./basetypes/Quantity'); +const DateTime = require('./basetypes/DateTime'); +const QDMDate = require('./basetypes/QDMDate'); +const Any = require('./basetypes/Any'); +const AnyEntity = require('./basetypes/AnyEntity'); +const { ComponentSchema } = require('./attributes/Component'); +const { FacilityLocationSchema } = require('./attributes/FacilityLocation'); +const { EntitySchema } = require('./attributes/Entity'); - /** - * This method is like `_.indexOf` except that it iterates over elements of - * `array` from right to left. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @param {number} [fromIndex=array.length-1] The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - * @example - * - * _.lastIndexOf([1, 2, 1, 2], 2); - * // => 3 - * - * // Search from the `fromIndex`. - * _.lastIndexOf([1, 2, 1, 2], 2, 2); - * // => 1 - */ - function lastIndexOf(array, value, fromIndex) { - var length = array == null ? 0 : array.length; - if (!length) { - return -1; - } - var index = length; - if (fromIndex !== undefined) { - index = toInteger(fromIndex); - index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); - } - return value === value - ? strictLastIndexOf(array, value, index) - : baseFindIndex(array, baseIsNaN, index, true); - } - /** - * Gets the element at index `n` of `array`. If `n` is negative, the nth - * element from the end is returned. - * - * @static - * @memberOf _ - * @since 4.11.0 - * @category Array - * @param {Array} array The array to query. - * @param {number} [n=0] The index of the element to return. - * @returns {*} Returns the nth element of `array`. - * @example - * - * var array = ['a', 'b', 'c', 'd']; - * - * _.nth(array, 1); - * // => 'b' - * - * _.nth(array, -2); - * // => 'c'; - */ - function nth(array, n) { - return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Removes all given values from `array` using - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove` - * to remove elements from an array by predicate. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {...*} [values] The values to remove. - * @returns {Array} Returns `array`. - * @example - * - * var array = ['a', 'b', 'c', 'a', 'b', 'c']; - * - * _.pull(array, 'a', 'c'); - * console.log(array); - * // => ['b', 'b'] - */ - var pull = baseRest(pullAll); +const SymptomSchema = DataElementSchema({ + prevalencePeriod: Interval, + severity: Code, + recorder: [AnyEntity], + qdmTitle: { type: String, default: 'Symptom' }, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.116' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.136' }, + qdmCategory: { type: String, default: 'symptom' }, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Symptom' }, - /** - * This method is like `_.pull` except that it accepts an array of values to remove. - * - * **Note:** Unlike `_.difference`, this method mutates `array`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {Array} values The values to remove. - * @returns {Array} Returns `array`. - * @example - * - * var array = ['a', 'b', 'c', 'a', 'b', 'c']; - * - * _.pullAll(array, ['a', 'c']); - * console.log(array); - * // => ['b', 'b'] - */ - function pullAll(array, values) { - return (array && array.length && values && values.length) - ? basePullAll(array, values) - : array; - } +}); - /** - * This method is like `_.pullAll` except that it accepts `iteratee` which is - * invoked for each element of `array` and `values` to generate the criterion - * by which they're compared. The iteratee is invoked with one argument: (value). - * - * **Note:** Unlike `_.differenceBy`, this method mutates `array`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {Array} values The values to remove. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns `array`. - * @example - * - * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; - * - * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); - * console.log(array); - * // => [{ 'x': 2 }] - */ - function pullAllBy(array, values, iteratee) { - return (array && array.length && values && values.length) - ? basePullAll(array, values, getIteratee(iteratee, 2)) - : array; - } +module.exports.SymptomSchema = SymptomSchema; +class Symptom extends mongoose.Document { + constructor(object) { + super(object, SymptomSchema); + this._type = 'QDM::Symptom'; + } +} - /** - * This method is like `_.pullAll` except that it accepts `comparator` which - * is invoked to compare elements of `array` to `values`. The comparator is - * invoked with two arguments: (arrVal, othVal). - * - * **Note:** Unlike `_.differenceWith`, this method mutates `array`. - * - * @static - * @memberOf _ - * @since 4.6.0 - * @category Array - * @param {Array} array The array to modify. - * @param {Array} values The values to remove. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns `array`. - * @example - * - * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; - * - * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); - * console.log(array); - * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] - */ - function pullAllWith(array, values, comparator) { - return (array && array.length && values && values.length) - ? basePullAll(array, values, undefined, comparator) - : array; - } +module.exports.Symptom = Symptom; - /** - * Removes elements from `array` corresponding to `indexes` and returns an - * array of removed elements. - * - * **Note:** Unlike `_.at`, this method mutates `array`. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {...(number|number[])} [indexes] The indexes of elements to remove. - * @returns {Array} Returns the new array of removed elements. - * @example - * - * var array = ['a', 'b', 'c', 'd']; - * var pulled = _.pullAt(array, [1, 3]); - * - * console.log(array); - * // => ['a', 'c'] - * - * console.log(pulled); - * // => ['b', 'd'] - */ - var pullAt = flatRest(function(array, indexes) { - var length = array == null ? 0 : array.length, - result = baseAt(array, indexes); - basePullAt(array, arrayMap(indexes, function(index) { - return isIndex(index, length) ? +index : index; - }).sort(compareAscending)); +},{"./attributes/Component":166,"./attributes/Entity":168,"./attributes/FacilityLocation":169,"./attributes/Identifier":170,"./basetypes/Any":176,"./basetypes/AnyEntity":177,"./basetypes/Code":178,"./basetypes/DataElement":179,"./basetypes/DateTime":180,"./basetypes/Interval":181,"./basetypes/QDMDate":182,"./basetypes/Quantity":183,"mongoose/browser":226}],165:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - return result; - }); +const { EntitySchemaFunction } = require('./Entity'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * Removes all elements from `array` that `predicate` returns truthy for - * and returns an array of the removed elements. The predicate is invoked - * with three arguments: (value, index, array). - * - * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` - * to pull elements from an array by value. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new array of removed elements. - * @example - * - * var array = [1, 2, 3, 4]; - * var evens = _.remove(array, function(n) { - * return n % 2 == 0; - * }); - * - * console.log(array); - * // => [1, 3] - * - * console.log(evens); - * // => [2, 4] - */ - function remove(array, predicate) { - var result = []; - if (!(array && array.length)) { - return result; - } - var index = -1, - indexes = [], - length = array.length; +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - predicate = getIteratee(predicate, 3); - while (++index < length) { - var value = array[index]; - if (predicate(value, index, array)) { - result.push(value); - indexes.push(index); - } - } - basePullAt(array, indexes); - return result; - } +const CarePartnerSchema = EntitySchemaFunction({ + relationship: Code, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.134' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.160' }, + _type: { type: String, default: 'QDM::CarePartner' }, - /** - * Reverses `array` so that the first element becomes the last, the second - * element becomes the second to last, and so on. - * - * **Note:** This method mutates `array` and is based on - * [`Array#reverse`](https://mdn.io/Array/reverse). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to modify. - * @returns {Array} Returns `array`. - * @example - * - * var array = [1, 2, 3]; - * - * _.reverse(array); - * // => [3, 2, 1] - * - * console.log(array); - * // => [3, 2, 1] - */ - function reverse(array) { - return array == null ? array : nativeReverse.call(array); - } +}); - /** - * Creates a slice of `array` from `start` up to, but not including, `end`. - * - * **Note:** This method is used instead of - * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are - * returned. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to slice. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the slice of `array`. - */ - function slice(array, start, end) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { - start = 0; - end = length; - } - else { - start = start == null ? 0 : toInteger(start); - end = end === undefined ? length : toInteger(end); - } - return baseSlice(array, start, end); - } +module.exports.CarePartnerSchema = CarePartnerSchema; +class CarePartner extends mongoose.Document { + constructor(object) { + super(object, CarePartnerSchema); + this._type = 'QDM::CarePartner'; + } +} - /** - * Uses a binary search to determine the lowest index at which `value` - * should be inserted into `array` in order to maintain its sort order. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - * @example - * - * _.sortedIndex([30, 50], 40); - * // => 1 - */ - function sortedIndex(array, value) { - return baseSortedIndex(array, value); - } +module.exports.CarePartner = CarePartner; - /** - * This method is like `_.sortedIndex` except that it accepts `iteratee` - * which is invoked for `value` and each element of `array` to compute their - * sort ranking. The iteratee is invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - * @example - * - * var objects = [{ 'x': 4 }, { 'x': 5 }]; - * - * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); - * // => 0 - * - * // The `_.property` iteratee shorthand. - * _.sortedIndexBy(objects, { 'x': 4 }, 'x'); - * // => 0 - */ - function sortedIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); - } - /** - * This method is like `_.indexOf` except that it performs a binary - * search on a sorted `array`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @returns {number} Returns the index of the matched value, else `-1`. - * @example - * - * _.sortedIndexOf([4, 5, 5, 5, 6], 5); - * // => 1 - */ - function sortedIndexOf(array, value) { - var length = array == null ? 0 : array.length; - if (length) { - var index = baseSortedIndex(array, value); - if (index < length && eq(array[index], value)) { - return index; - } - } - return -1; - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Entity":168,"mongoose/browser":226}],166:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * This method is like `_.sortedIndex` except that it returns the highest - * index at which `value` should be inserted into `array` in order to - * maintain its sort order. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - * @example - * - * _.sortedLastIndex([4, 5, 5, 5, 6], 5); - * // => 4 - */ - function sortedLastIndex(array, value) { - return baseSortedIndex(array, value, true); - } +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * This method is like `_.sortedLastIndex` except that it accepts `iteratee` - * which is invoked for `value` and each element of `array` to compute their - * sort ranking. The iteratee is invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The sorted array to inspect. - * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted - * into `array`. - * @example - * - * var objects = [{ 'x': 4 }, { 'x': 5 }]; - * - * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); - * // => 1 - * - * // The `_.property` iteratee shorthand. - * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x'); - * // => 1 - */ - function sortedLastIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); - } +const [Schema] = [mongoose.Schema]; - /** - * This method is like `_.lastIndexOf` except that it performs a binary - * search on a sorted `array`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {*} value The value to search for. - * @returns {number} Returns the index of the matched value, else `-1`. - * @example - * - * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5); - * // => 3 - */ - function sortedLastIndexOf(array, value) { - var length = array == null ? 0 : array.length; - if (length) { - var index = baseSortedIndex(array, value, true) - 1; - if (eq(array[index], value)) { - return index; - } - } - return -1; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * This method is like `_.uniq` except that it's designed and optimized - * for sorted arrays. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @returns {Array} Returns the new duplicate free array. - * @example - * - * _.sortedUniq([1, 1, 2]); - * // => [1, 2] - */ - function sortedUniq(array) { - return (array && array.length) - ? baseSortedUniq(array) - : []; - } +const ComponentSchema = new mongoose.Schema({ + code: Code, + result: Any, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Component' }, - /** - * This method is like `_.uniqBy` except that it's designed and optimized - * for sorted arrays. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @returns {Array} Returns the new duplicate free array. - * @example - * - * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); - * // => [1.1, 2.3] - */ - function sortedUniqBy(array, iteratee) { - return (array && array.length) - ? baseSortedUniq(array, getIteratee(iteratee, 2)) - : []; - } +}); - /** - * Gets all but the first element of `array`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to query. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.tail([1, 2, 3]); - * // => [2, 3] - */ - function tail(array) { - var length = array == null ? 0 : array.length; - return length ? baseSlice(array, 1, length) : []; - } +module.exports.ComponentSchema = ComponentSchema; +class Component extends mongoose.Document { + constructor(object) { + super(object, ComponentSchema); + this._type = 'QDM::Component'; + } +} - /** - * Creates a slice of `array` with `n` elements taken from the beginning. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to query. - * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.take([1, 2, 3]); - * // => [1] - * - * _.take([1, 2, 3], 2); - * // => [1, 2] - * - * _.take([1, 2, 3], 5); - * // => [1, 2, 3] - * - * _.take([1, 2, 3], 0); - * // => [] - */ - function take(array, n, guard) { - if (!(array && array.length)) { - return []; - } - n = (guard || n === undefined) ? 1 : toInteger(n); - return baseSlice(array, 0, n < 0 ? 0 : n); - } +function ComponentSchemaFunction(add, options) { + const extended = new Schema({ + code: Code, + result: Any, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Component' }, - /** - * Creates a slice of `array` with `n` elements taken from the end. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the slice of `array`. - * @example - * - * _.takeRight([1, 2, 3]); - * // => [3] - * - * _.takeRight([1, 2, 3], 2); - * // => [2, 3] - * - * _.takeRight([1, 2, 3], 5); - * // => [1, 2, 3] - * - * _.takeRight([1, 2, 3], 0); - * // => [] - */ - function takeRight(array, n, guard) { - var length = array == null ? 0 : array.length; - if (!length) { - return []; - } - n = (guard || n === undefined) ? 1 : toInteger(n); - n = length - n; - return baseSlice(array, n < 0 ? 0 : n, length); - } - /** - * Creates a slice of `array` with elements taken from the end. Elements are - * taken until `predicate` returns falsey. The predicate is invoked with - * three arguments: (value, index, array). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the slice of `array`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': true }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': false } - * ]; - * - * _.takeRightWhile(users, function(o) { return !o.active; }); - * // => objects for ['fred', 'pebbles'] - * - * // The `_.matches` iteratee shorthand. - * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); - * // => objects for ['pebbles'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.takeRightWhile(users, ['active', false]); - * // => objects for ['fred', 'pebbles'] - * - * // The `_.property` iteratee shorthand. - * _.takeRightWhile(users, 'active'); - * // => [] - */ - function takeRightWhile(array, predicate) { - return (array && array.length) - ? baseWhile(array, getIteratee(predicate, 3), false, true) - : []; - } + }, options); - /** - * Creates a slice of `array` with elements taken from the beginning. Elements - * are taken until `predicate` returns falsey. The predicate is invoked with - * three arguments: (value, index, array). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Array - * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the slice of `array`. - * @example - * - * var users = [ - * { 'user': 'barney', 'active': false }, - * { 'user': 'fred', 'active': false }, - * { 'user': 'pebbles', 'active': true } - * ]; - * - * _.takeWhile(users, function(o) { return !o.active; }); - * // => objects for ['barney', 'fred'] - * - * // The `_.matches` iteratee shorthand. - * _.takeWhile(users, { 'user': 'barney', 'active': false }); - * // => objects for ['barney'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.takeWhile(users, ['active', false]); - * // => objects for ['barney', 'fred'] - * - * // The `_.property` iteratee shorthand. - * _.takeWhile(users, 'active'); - * // => [] - */ - function takeWhile(array, predicate) { - return (array && array.length) - ? baseWhile(array, getIteratee(predicate, 3)) - : []; - } + if (add) { + extended.add(add); + } - /** - * Creates an array of unique values, in order, from all given arrays using - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @returns {Array} Returns the new array of combined values. - * @example - * - * _.union([2], [1, 2]); - * // => [2, 1] - */ - var union = baseRest(function(arrays) { - return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); - }); + /* eslint no-underscore-dangle: 0 */ + extended.methods._is = function _is(typeSpecifier) { + return this._typeHierarchy().some( + t => t.type === typeSpecifier.type && t.name === typeSpecifier.name + ); + }; - /** - * This method is like `_.union` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by - * which uniqueness is computed. Result values are chosen from the first - * array in which the value occurs. The iteratee is invoked with one argument: - * (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns the new array of combined values. - * @example - * - * _.unionBy([2.1], [1.2, 2.3], Math.floor); - * // => [2.1, 1.2] - * - * // The `_.property` iteratee shorthand. - * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); - * // => [{ 'x': 1 }, { 'x': 2 }] - */ - var unionBy = baseRest(function(arrays) { - var iteratee = last(arrays); - if (isArrayLikeObject(iteratee)) { - iteratee = undefined; - } - return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); - }); + extended.methods._typeHierarchy = function _typeHierarchy() { + const typeName = this._type.replace(/QDM::/, ''); + const ver = this.qdmVersion.replace('.', '_'); + return [ + { + name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, + type: 'NamedTypeSpecifier', + }, + ]; + }; + return extended; +} - /** - * This method is like `_.union` except that it accepts `comparator` which - * is invoked to compare elements of `arrays`. Result values are chosen from - * the first array in which the value occurs. The comparator is invoked - * with two arguments: (arrVal, othVal). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of combined values. - * @example - * - * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; - * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; - * - * _.unionWith(objects, others, _.isEqual); - * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] - */ - var unionWith = baseRest(function(arrays) { - var comparator = last(arrays); - comparator = typeof comparator == 'function' ? comparator : undefined; - return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); - }); +module.exports.Component = Component; +module.exports.ComponentSchemaFunction = ComponentSchemaFunction; + +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"mongoose/browser":226}],167:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); + + +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const DiagnosisComponentSchema = new mongoose.Schema({ + code: Code, + presentOnAdmissionIndicator: Code, + rank: Number, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::DiagnosisComponent' }, + +}); + +module.exports.DiagnosisComponentSchema = DiagnosisComponentSchema; +class DiagnosisComponent extends mongoose.Document { + constructor(object) { + super(object, DiagnosisComponentSchema); + this._type = 'QDM::DiagnosisComponent'; + } +} - /** - * Creates a duplicate-free version of an array, using - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons, in which only the first occurrence of each element - * is kept. The order of result values is determined by the order they occur - * in the array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @returns {Array} Returns the new duplicate free array. - * @example - * - * _.uniq([2, 1, 2]); - * // => [2, 1] - */ - function uniq(array) { - return (array && array.length) ? baseUniq(array) : []; - } +module.exports.DiagnosisComponent = DiagnosisComponent; - /** - * This method is like `_.uniq` except that it accepts `iteratee` which is - * invoked for each element in `array` to generate the criterion by which - * uniqueness is computed. The order of result values is determined by the - * order they occur in the array. The iteratee is invoked with one argument: - * (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns the new duplicate free array. - * @example - * - * _.uniqBy([2.1, 1.2, 2.3], Math.floor); - * // => [2.1, 1.2] - * - * // The `_.property` iteratee shorthand. - * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); - * // => [{ 'x': 1 }, { 'x': 2 }] - */ - function uniqBy(array, iteratee) { - return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; - } - /** - * This method is like `_.uniq` except that it accepts `comparator` which - * is invoked to compare elements of `array`. The order of result values is - * determined by the order they occur in the array.The comparator is invoked - * with two arguments: (arrVal, othVal). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new duplicate free array. - * @example - * - * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; - * - * _.uniqWith(objects, _.isEqual); - * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] - */ - function uniqWith(array, comparator) { - comparator = typeof comparator == 'function' ? comparator : undefined; - return (array && array.length) ? baseUniq(array, undefined, comparator) : []; - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"mongoose/browser":226}],168:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * This method is like `_.zip` except that it accepts an array of grouped - * elements and creates an array regrouping the elements to their pre-zip - * configuration. - * - * @static - * @memberOf _ - * @since 1.2.0 - * @category Array - * @param {Array} array The array of grouped elements to process. - * @returns {Array} Returns the new array of regrouped elements. - * @example - * - * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); - * // => [['a', 1, true], ['b', 2, false]] - * - * _.unzip(zipped); - * // => [['a', 'b'], [1, 2], [true, false]] - */ - function unzip(array) { - if (!(array && array.length)) { - return []; - } - var length = 0; - array = arrayFilter(array, function(group) { - if (isArrayLikeObject(group)) { - length = nativeMax(group.length, length); - return true; - } - }); - return baseTimes(length, function(index) { - return arrayMap(array, baseProperty(index)); - }); - } +const { IdentifierSchema } = require('./Identifier'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * This method is like `_.unzip` except that it accepts `iteratee` to specify - * how regrouped values should be combined. The iteratee is invoked with the - * elements of each group: (...group). - * - * @static - * @memberOf _ - * @since 3.8.0 - * @category Array - * @param {Array} array The array of grouped elements to process. - * @param {Function} [iteratee=_.identity] The function to combine - * regrouped values. - * @returns {Array} Returns the new array of regrouped elements. - * @example - * - * var zipped = _.zip([1, 2], [10, 20], [100, 200]); - * // => [[1, 10, 100], [2, 20, 200]] - * - * _.unzipWith(zipped, _.add); - * // => [3, 30, 300] - */ - function unzipWith(array, iteratee) { - if (!(array && array.length)) { - return []; - } - var result = unzip(array); - if (iteratee == null) { - return result; - } - return arrayMap(result, function(group) { - return apply(iteratee, undefined, group); - }); - } +const [Schema] = [mongoose.Schema]; - /** - * Creates an array excluding all given values using - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * **Note:** Unlike `_.pull`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to inspect. - * @param {...*} [values] The values to exclude. - * @returns {Array} Returns the new array of filtered values. - * @see _.difference, _.xor - * @example - * - * _.without([2, 1, 2, 3], 1, 2); - * // => [3] - */ - var without = baseRest(function(array, values) { - return isArrayLikeObject(array) - ? baseDifference(array, values) - : []; - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates an array of unique values that is the - * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) - * of the given arrays. The order of result values is determined by the order - * they occur in the arrays. - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @returns {Array} Returns the new array of filtered values. - * @see _.difference, _.without - * @example - * - * _.xor([2, 1], [2, 3]); - * // => [1, 3] - */ - var xor = baseRest(function(arrays) { - return baseXor(arrayFilter(arrays, isArrayLikeObject)); - }); +const EntitySchema = new mongoose.Schema({ + id: String, + identifier: IdentifierSchema, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Entity' }, - /** - * This method is like `_.xor` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by - * which by which they're compared. The order of result values is determined - * by the order they occur in the arrays. The iteratee is invoked with one - * argument: (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Array} Returns the new array of filtered values. - * @example - * - * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); - * // => [1.2, 3.4] - * - * // The `_.property` iteratee shorthand. - * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); - * // => [{ 'x': 2 }] - */ - var xorBy = baseRest(function(arrays) { - var iteratee = last(arrays); - if (isArrayLikeObject(iteratee)) { - iteratee = undefined; - } - return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); - }); +}); - /** - * This method is like `_.xor` except that it accepts `comparator` which is - * invoked to compare elements of `arrays`. The order of result values is - * determined by the order they occur in the arrays. The comparator is invoked - * with two arguments: (arrVal, othVal). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Array - * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of filtered values. - * @example - * - * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; - * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; - * - * _.xorWith(objects, others, _.isEqual); - * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] - */ - var xorWith = baseRest(function(arrays) { - var comparator = last(arrays); - comparator = typeof comparator == 'function' ? comparator : undefined; - return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); - }); +module.exports.EntitySchema = EntitySchema; +class Entity extends mongoose.Document { + constructor(object) { + super(object, EntitySchema); + this._type = 'QDM::Entity'; + } +} - /** - * Creates an array of grouped elements, the first of which contains the - * first elements of the given arrays, the second of which contains the - * second elements of the given arrays, and so on. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {...Array} [arrays] The arrays to process. - * @returns {Array} Returns the new array of grouped elements. - * @example - * - * _.zip(['a', 'b'], [1, 2], [true, false]); - * // => [['a', 1, true], ['b', 2, false]] - */ - var zip = baseRest(unzip); +function EntitySchemaFunction(add, options) { + const extended = new Schema({ + identifier: IdentifierSchema, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Entity' }, - /** - * This method is like `_.fromPairs` except that it accepts two arrays, - * one of property identifiers and one of corresponding values. - * - * @static - * @memberOf _ - * @since 0.4.0 - * @category Array - * @param {Array} [props=[]] The property identifiers. - * @param {Array} [values=[]] The property values. - * @returns {Object} Returns the new object. - * @example - * - * _.zipObject(['a', 'b'], [1, 2]); - * // => { 'a': 1, 'b': 2 } - */ - function zipObject(props, values) { - return baseZipObject(props || [], values || [], assignValue); - } - /** - * This method is like `_.zipObject` except that it supports property paths. - * - * @static - * @memberOf _ - * @since 4.1.0 - * @category Array - * @param {Array} [props=[]] The property identifiers. - * @param {Array} [values=[]] The property values. - * @returns {Object} Returns the new object. - * @example - * - * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]); - * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } - */ - function zipObjectDeep(props, values) { - return baseZipObject(props || [], values || [], baseSet); - } + id: { + type: String, + default() { + return this._id ? this._id.toString() : mongoose.Types.ObjectId().toString(); + }, + }, - /** - * This method is like `_.zip` except that it accepts `iteratee` to specify - * how grouped values should be combined. The iteratee is invoked with the - * elements of each group: (...group). - * - * @static - * @memberOf _ - * @since 3.8.0 - * @category Array - * @param {...Array} [arrays] The arrays to process. - * @param {Function} [iteratee=_.identity] The function to combine - * grouped values. - * @returns {Array} Returns the new array of grouped elements. - * @example - * - * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { - * return a + b + c; - * }); - * // => [111, 222] - */ - var zipWith = baseRest(function(arrays) { - var length = arrays.length, - iteratee = length > 1 ? arrays[length - 1] : undefined; + }, options); - iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined; - return unzipWith(arrays, iteratee); - }); + if (add) { + extended.add(add); + } - /*------------------------------------------------------------------------*/ + /* eslint no-underscore-dangle: 0 */ + extended.methods._is = function _is(typeSpecifier) { + return this._typeHierarchy().some( + t => t.type === typeSpecifier.type && t.name === typeSpecifier.name + ); + }; - /** - * Creates a `lodash` wrapper instance that wraps `value` with explicit method - * chain sequences enabled. The result of such sequences must be unwrapped - * with `_#value`. - * - * @static - * @memberOf _ - * @since 1.3.0 - * @category Seq - * @param {*} value The value to wrap. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 }, - * { 'user': 'pebbles', 'age': 1 } - * ]; - * - * var youngest = _ - * .chain(users) - * .sortBy('age') - * .map(function(o) { - * return o.user + ' is ' + o.age; - * }) - * .head() - * .value(); - * // => 'pebbles is 1' - */ - function chain(value) { - var result = lodash(value); - result.__chain__ = true; - return result; - } + extended.methods._typeHierarchy = function _typeHierarchy() { + const typeName = this._type.replace(/QDM::/, ''); + const ver = this.qdmVersion.replace('.', '_'); + return [ + { + name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, + type: 'NamedTypeSpecifier', + }, + ]; + }; + return extended; +} - /** - * This method invokes `interceptor` and returns `value`. The interceptor - * is invoked with one argument; (value). The purpose of this method is to - * "tap into" a method chain sequence in order to modify intermediate results. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Seq - * @param {*} value The value to provide to `interceptor`. - * @param {Function} interceptor The function to invoke. - * @returns {*} Returns `value`. - * @example - * - * _([1, 2, 3]) - * .tap(function(array) { - * // Mutate input array. - * array.pop(); - * }) - * .reverse() - * .value(); - * // => [2, 1] - */ - function tap(value, interceptor) { - interceptor(value); - return value; - } +module.exports.Entity = Entity; +module.exports.EntitySchemaFunction = EntitySchemaFunction; - /** - * This method is like `_.tap` except that it returns the result of `interceptor`. - * The purpose of this method is to "pass thru" values replacing intermediate - * results in a method chain sequence. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Seq - * @param {*} value The value to provide to `interceptor`. - * @param {Function} interceptor The function to invoke. - * @returns {*} Returns the result of `interceptor`. - * @example - * - * _(' abc ') - * .chain() - * .trim() - * .thru(function(value) { - * return [value]; - * }) - * .value(); - * // => ['abc'] - */ - function thru(value, interceptor) { - return interceptor(value); - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Identifier":170,"mongoose/browser":226}],169:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * This method is the wrapper version of `_.at`. - * - * @name at - * @memberOf _ - * @since 1.0.0 - * @category Seq - * @param {...(string|string[])} [paths] The property paths to pick. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; - * - * _(object).at(['a[0].b.c', 'a[1]']).value(); - * // => [3, 4] - */ - var wrapperAt = flatRest(function(paths) { - var length = paths.length, - start = length ? paths[0] : 0, - value = this.__wrapped__, - interceptor = function(object) { return baseAt(object, paths); }; +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); + + +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const FacilityLocationSchema = new mongoose.Schema({ + code: Code, + locationPeriod: Interval, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::FacilityLocation' }, - if (length > 1 || this.__actions__.length || - !(value instanceof LazyWrapper) || !isIndex(start)) { - return this.thru(interceptor); - } - value = value.slice(start, +start + (length ? 1 : 0)); - value.__actions__.push({ - 'func': thru, - 'args': [interceptor], - 'thisArg': undefined - }); - return new LodashWrapper(value, this.__chain__).thru(function(array) { - if (length && !array.length) { - array.push(undefined); - } - return array; - }); - }); +}); - /** - * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. - * - * @name chain - * @memberOf _ - * @since 0.1.0 - * @category Seq - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } - * ]; - * - * // A sequence without explicit chaining. - * _(users).head(); - * // => { 'user': 'barney', 'age': 36 } - * - * // A sequence with explicit chaining. - * _(users) - * .chain() - * .head() - * .pick('user') - * .value(); - * // => { 'user': 'barney' } - */ - function wrapperChain() { - return chain(this); - } +module.exports.FacilityLocationSchema = FacilityLocationSchema; +class FacilityLocation extends mongoose.Document { + constructor(object) { + super(object, FacilityLocationSchema); + this._type = 'QDM::FacilityLocation'; + } +} - /** - * Executes the chain sequence and returns the wrapped result. - * - * @name commit - * @memberOf _ - * @since 3.2.0 - * @category Seq - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * var array = [1, 2]; - * var wrapped = _(array).push(3); - * - * console.log(array); - * // => [1, 2] - * - * wrapped = wrapped.commit(); - * console.log(array); - * // => [1, 2, 3] - * - * wrapped.last(); - * // => 3 - * - * console.log(array); - * // => [1, 2, 3] - */ - function wrapperCommit() { - return new LodashWrapper(this.value(), this.__chain__); - } +module.exports.FacilityLocation = FacilityLocation; - /** - * Gets the next value on a wrapped object following the - * [iterator protocol](https://mdn.io/iteration_protocols#iterator). - * - * @name next - * @memberOf _ - * @since 4.0.0 - * @category Seq - * @returns {Object} Returns the next iterator value. - * @example - * - * var wrapped = _([1, 2]); - * - * wrapped.next(); - * // => { 'done': false, 'value': 1 } - * - * wrapped.next(); - * // => { 'done': false, 'value': 2 } - * - * wrapped.next(); - * // => { 'done': true, 'value': undefined } - */ - function wrapperNext() { - if (this.__values__ === undefined) { - this.__values__ = toArray(this.value()); - } - var done = this.__index__ >= this.__values__.length, - value = done ? undefined : this.__values__[this.__index__++]; - return { 'done': done, 'value': value }; - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"mongoose/browser":226}],170:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Enables the wrapper to be iterable. - * - * @name Symbol.iterator - * @memberOf _ - * @since 4.0.0 - * @category Seq - * @returns {Object} Returns the wrapper object. - * @example - * - * var wrapped = _([1, 2]); - * - * wrapped[Symbol.iterator]() === wrapped; - * // => true - * - * Array.from(wrapped); - * // => [1, 2] - */ - function wrapperToIterator() { - return this; - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates a clone of the chain sequence planting `value` as the wrapped value. - * - * @name plant - * @memberOf _ - * @since 3.2.0 - * @category Seq - * @param {*} value The value to plant. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * function square(n) { - * return n * n; - * } - * - * var wrapped = _([1, 2]).map(square); - * var other = wrapped.plant([3, 4]); - * - * other.value(); - * // => [9, 16] - * - * wrapped.value(); - * // => [1, 4] - */ - function wrapperPlant(value) { - var result, - parent = this; +const IdentifierSchema = mongoose.Schema({ + namingSystem: String, + value: String, + qdmVersion: { type: String, default: '5.6' }, + _type: { type: String, default: 'QDM::Identifier' }, - while (parent instanceof baseLodash) { - var clone = wrapperClone(parent); - clone.__index__ = 0; - clone.__values__ = undefined; - if (result) { - previous.__wrapped__ = clone; - } else { - result = clone; - } - var previous = clone; - parent = parent.__wrapped__; - } - previous.__wrapped__ = value; - return result; - } +}, { _id: false, id: false }); - /** - * This method is the wrapper version of `_.reverse`. - * - * **Note:** This method mutates the wrapped array. - * - * @name reverse - * @memberOf _ - * @since 0.1.0 - * @category Seq - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * var array = [1, 2, 3]; - * - * _(array).reverse().value() - * // => [3, 2, 1] - * - * console.log(array); - * // => [3, 2, 1] - */ - function wrapperReverse() { - var value = this.__wrapped__; - if (value instanceof LazyWrapper) { - var wrapped = value; - if (this.__actions__.length) { - wrapped = new LazyWrapper(this); - } - wrapped = wrapped.reverse(); - wrapped.__actions__.push({ - 'func': thru, - 'args': [reverse], - 'thisArg': undefined - }); - return new LodashWrapper(wrapped, this.__chain__); - } - return this.thru(reverse); - } +module.exports.IdentifierSchema = IdentifierSchema; +class Identifier extends mongoose.Document { + constructor(object) { + super(object, IdentifierSchema); + this._type = 'QDM::Identifier'; + } +} +module.exports.Identifier = Identifier; - /** - * Executes the chain sequence to resolve the unwrapped value. - * - * @name value - * @memberOf _ - * @since 0.1.0 - * @alias toJSON, valueOf - * @category Seq - * @returns {*} Returns the resolved unwrapped value. - * @example - * - * _([1, 2, 3]).value(); - * // => [1, 2, 3] - */ - function wrapperValue() { - return baseWrapperValue(this.__wrapped__, this.__actions__); - } +},{"mongoose/browser":226}],171:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /*------------------------------------------------------------------------*/ +const { EntitySchemaFunction } = require('./Entity'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * Creates an object composed of keys generated from the results of running - * each element of `collection` thru `iteratee`. The corresponding value of - * each key is the number of times the key was returned by `iteratee`. The - * iteratee is invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 0.5.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The iteratee to transform keys. - * @returns {Object} Returns the composed aggregate object. - * @example - * - * _.countBy([6.1, 4.2, 6.3], Math.floor); - * // => { '4': 1, '6': 2 } - * - * // The `_.property` iteratee shorthand. - * _.countBy(['one', 'two', 'three'], 'length'); - * // => { '3': 2, '5': 1 } - */ - var countBy = createAggregator(function(result, value, key) { - if (hasOwnProperty.call(result, key)) { - ++result[key]; - } else { - baseAssignValue(result, key, 1); - } - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Checks if `predicate` returns truthy for **all** elements of `collection`. - * Iteration is stopped once `predicate` returns falsey. The predicate is - * invoked with three arguments: (value, index|key, collection). - * - * **Note:** This method returns `true` for - * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because - * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of - * elements of empty collections. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {boolean} Returns `true` if all elements pass the predicate check, - * else `false`. - * @example - * - * _.every([true, 1, null, 'yes'], Boolean); - * // => false - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': false } - * ]; - * - * // The `_.matches` iteratee shorthand. - * _.every(users, { 'user': 'barney', 'active': false }); - * // => false - * - * // The `_.matchesProperty` iteratee shorthand. - * _.every(users, ['active', false]); - * // => true - * - * // The `_.property` iteratee shorthand. - * _.every(users, 'active'); - * // => false - */ - function every(collection, predicate, guard) { - var func = isArray(collection) ? arrayEvery : baseEvery; - if (guard && isIterateeCall(collection, predicate, guard)) { - predicate = undefined; - } - return func(collection, getIteratee(predicate, 3)); - } +const LocationSchema = EntitySchemaFunction({ + locationType: Code, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.142' }, + _type: { type: String, default: 'QDM::Location' }, - /** - * Iterates over elements of `collection`, returning an array of all elements - * `predicate` returns truthy for. The predicate is invoked with three - * arguments: (value, index|key, collection). - * - * **Note:** Unlike `_.remove`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - * @see _.reject - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false } - * ]; - * - * _.filter(users, function(o) { return !o.active; }); - * // => objects for ['fred'] - * - * // The `_.matches` iteratee shorthand. - * _.filter(users, { 'age': 36, 'active': true }); - * // => objects for ['barney'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.filter(users, ['active', false]); - * // => objects for ['fred'] - * - * // The `_.property` iteratee shorthand. - * _.filter(users, 'active'); - * // => objects for ['barney'] - * - * // Combining several predicates using `_.overEvery` or `_.overSome`. - * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); - * // => objects for ['fred', 'barney'] - */ - function filter(collection, predicate) { - var func = isArray(collection) ? arrayFilter : baseFilter; - return func(collection, getIteratee(predicate, 3)); - } +}); - /** - * Iterates over elements of `collection`, returning the first element - * `predicate` returns truthy for. The predicate is invoked with three - * arguments: (value, index|key, collection). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param {number} [fromIndex=0] The index to search from. - * @returns {*} Returns the matched element, else `undefined`. - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false }, - * { 'user': 'pebbles', 'age': 1, 'active': true } - * ]; - * - * _.find(users, function(o) { return o.age < 40; }); - * // => object for 'barney' - * - * // The `_.matches` iteratee shorthand. - * _.find(users, { 'age': 1, 'active': true }); - * // => object for 'pebbles' - * - * // The `_.matchesProperty` iteratee shorthand. - * _.find(users, ['active', false]); - * // => object for 'fred' - * - * // The `_.property` iteratee shorthand. - * _.find(users, 'active'); - * // => object for 'barney' - */ - var find = createFind(findIndex); +module.exports.LocationSchema = LocationSchema; +class Location extends mongoose.Document { + constructor(object) { + super(object, LocationSchema); + this._type = 'QDM::Location'; + } +} - /** - * This method is like `_.find` except that it iterates over elements of - * `collection` from right to left. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Collection - * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param {number} [fromIndex=collection.length-1] The index to search from. - * @returns {*} Returns the matched element, else `undefined`. - * @example - * - * _.findLast([1, 2, 3, 4], function(n) { - * return n % 2 == 1; - * }); - * // => 3 - */ - var findLast = createFind(findLastIndex); +module.exports.Location = Location; - /** - * Creates a flattened array of values by running each element in `collection` - * thru `iteratee` and flattening the mapped results. The iteratee is invoked - * with three arguments: (value, index|key, collection). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new flattened array. - * @example - * - * function duplicate(n) { - * return [n, n]; - * } - * - * _.flatMap([1, 2], duplicate); - * // => [1, 1, 2, 2] - */ - function flatMap(collection, iteratee) { - return baseFlatten(map(collection, iteratee), 1); - } - /** - * This method is like `_.flatMap` except that it recursively flattens the - * mapped results. - * - * @static - * @memberOf _ - * @since 4.7.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new flattened array. - * @example - * - * function duplicate(n) { - * return [[[n, n]]]; - * } - * - * _.flatMapDeep([1, 2], duplicate); - * // => [1, 1, 2, 2] - */ - function flatMapDeep(collection, iteratee) { - return baseFlatten(map(collection, iteratee), INFINITY); - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Entity":168,"mongoose/browser":226}],172:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const { EntitySchemaFunction } = require('./Entity'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * This method is like `_.flatMap` except that it recursively flattens the - * mapped results up to `depth` times. - * - * @static - * @memberOf _ - * @since 4.7.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @param {number} [depth=1] The maximum recursion depth. - * @returns {Array} Returns the new flattened array. - * @example - * - * function duplicate(n) { - * return [[[n, n]]]; - * } - * - * _.flatMapDepth([1, 2], duplicate, 2); - * // => [[1, 1], [2, 2]] - */ - function flatMapDepth(collection, iteratee, depth) { - depth = depth === undefined ? 1 : toInteger(depth); - return baseFlatten(map(collection, iteratee), depth); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Iterates over elements of `collection` and invokes `iteratee` for each element. - * The iteratee is invoked with three arguments: (value, index|key, collection). - * Iteratee functions may exit iteration early by explicitly returning `false`. - * - * **Note:** As with other "Collections" methods, objects with a "length" - * property are iterated like arrays. To avoid this behavior use `_.forIn` - * or `_.forOwn` for object iteration. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @alias each - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array|Object} Returns `collection`. - * @see _.forEachRight - * @example - * - * _.forEach([1, 2], function(value) { - * console.log(value); - * }); - * // => Logs `1` then `2`. - * - * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { - * console.log(key); - * }); - * // => Logs 'a' then 'b' (iteration order is not guaranteed). - */ - function forEach(collection, iteratee) { - var func = isArray(collection) ? arrayEach : baseEach; - return func(collection, getIteratee(iteratee, 3)); - } +const OrganizationSchema = EntitySchemaFunction({ + organizationType: Code, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.135' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.163' }, + _type: { type: String, default: 'QDM::Organization' }, - /** - * This method is like `_.forEach` except that it iterates over elements of - * `collection` from right to left. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @alias eachRight - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array|Object} Returns `collection`. - * @see _.forEach - * @example - * - * _.forEachRight([1, 2], function(value) { - * console.log(value); - * }); - * // => Logs `2` then `1`. - */ - function forEachRight(collection, iteratee) { - var func = isArray(collection) ? arrayEachRight : baseEachRight; - return func(collection, getIteratee(iteratee, 3)); - } +}); - /** - * Creates an object composed of keys generated from the results of running - * each element of `collection` thru `iteratee`. The order of grouped values - * is determined by the order they occur in `collection`. The corresponding - * value of each key is an array of elements responsible for generating the - * key. The iteratee is invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The iteratee to transform keys. - * @returns {Object} Returns the composed aggregate object. - * @example - * - * _.groupBy([6.1, 4.2, 6.3], Math.floor); - * // => { '4': [4.2], '6': [6.1, 6.3] } - * - * // The `_.property` iteratee shorthand. - * _.groupBy(['one', 'two', 'three'], 'length'); - * // => { '3': ['one', 'two'], '5': ['three'] } - */ - var groupBy = createAggregator(function(result, value, key) { - if (hasOwnProperty.call(result, key)) { - result[key].push(value); - } else { - baseAssignValue(result, key, [value]); - } - }); +module.exports.OrganizationSchema = OrganizationSchema; +class Organization extends mongoose.Document { + constructor(object) { + super(object, OrganizationSchema); + this._type = 'QDM::Organization'; + } +} - /** - * Checks if `value` is in `collection`. If `collection` is a string, it's - * checked for a substring of `value`, otherwise - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * is used for equality comparisons. If `fromIndex` is negative, it's used as - * the offset from the end of `collection`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object|string} collection The collection to inspect. - * @param {*} value The value to search for. - * @param {number} [fromIndex=0] The index to search from. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. - * @returns {boolean} Returns `true` if `value` is found, else `false`. - * @example - * - * _.includes([1, 2, 3], 1); - * // => true - * - * _.includes([1, 2, 3], 1, 2); - * // => false - * - * _.includes({ 'a': 1, 'b': 2 }, 1); - * // => true - * - * _.includes('abcd', 'bc'); - * // => true - */ - function includes(collection, value, fromIndex, guard) { - collection = isArrayLike(collection) ? collection : values(collection); - fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; +module.exports.Organization = Organization; - var length = collection.length; - if (fromIndex < 0) { - fromIndex = nativeMax(length + fromIndex, 0); - } - return isString(collection) - ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) - : (!!length && baseIndexOf(collection, value, fromIndex) > -1); - } - /** - * Invokes the method at `path` of each element in `collection`, returning - * an array of the results of each invoked method. Any additional arguments - * are provided to each invoked method. If `path` is a function, it's invoked - * for, and `this` bound to, each element in `collection`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|string} path The path of the method to invoke or - * the function invoked per iteration. - * @param {...*} [args] The arguments to invoke each method with. - * @returns {Array} Returns the array of results. - * @example - * - * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); - * // => [[1, 5, 7], [1, 2, 3]] - * - * _.invokeMap([123, 456], String.prototype.split, ''); - * // => [['1', '2', '3'], ['4', '5', '6']] - */ - var invokeMap = baseRest(function(collection, path, args) { - var index = -1, - isFunc = typeof path == 'function', - result = isArrayLike(collection) ? Array(collection.length) : []; +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Entity":168,"mongoose/browser":226}],173:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - baseEach(collection, function(value) { - result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); - }); - return result; - }); +const { EntitySchemaFunction } = require('./Entity'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * Creates an object composed of keys generated from the results of running - * each element of `collection` thru `iteratee`. The corresponding value of - * each key is the last element responsible for generating the key. The - * iteratee is invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The iteratee to transform keys. - * @returns {Object} Returns the composed aggregate object. - * @example - * - * var array = [ - * { 'dir': 'left', 'code': 97 }, - * { 'dir': 'right', 'code': 100 } - * ]; - * - * _.keyBy(array, function(o) { - * return String.fromCharCode(o.code); - * }); - * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } - * - * _.keyBy(array, 'dir'); - * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } - */ - var keyBy = createAggregator(function(result, value, key) { - baseAssignValue(result, key, value); - }); +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Creates an array of values by running each element in `collection` thru - * `iteratee`. The iteratee is invoked with three arguments: - * (value, index|key, collection). - * - * Many lodash methods are guarded to work as iteratees for methods like - * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. - * - * The guarded methods are: - * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, - * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, - * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, - * `template`, `trim`, `trimEnd`, `trimStart`, and `words` - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new mapped array. - * @example - * - * function square(n) { - * return n * n; - * } - * - * _.map([4, 8], square); - * // => [16, 64] - * - * _.map({ 'a': 4, 'b': 8 }, square); - * // => [16, 64] (iteration order is not guaranteed) - * - * var users = [ - * { 'user': 'barney' }, - * { 'user': 'fred' } - * ]; - * - * // The `_.property` iteratee shorthand. - * _.map(users, 'user'); - * // => ['barney', 'fred'] - */ - function map(collection, iteratee) { - var func = isArray(collection) ? arrayMap : baseMap; - return func(collection, getIteratee(iteratee, 3)); - } +const PatientEntitySchema = EntitySchemaFunction({ + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.136' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.161' }, + _type: { type: String, default: 'QDM::PatientEntity' }, - /** - * This method is like `_.sortBy` except that it allows specifying the sort - * orders of the iteratees to sort by. If `orders` is unspecified, all values - * are sorted in ascending order. Otherwise, specify an order of "desc" for - * descending or "asc" for ascending sort order of corresponding values. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] - * The iteratees to sort by. - * @param {string[]} [orders] The sort orders of `iteratees`. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. - * @returns {Array} Returns the new sorted array. - * @example - * - * var users = [ - * { 'user': 'fred', 'age': 48 }, - * { 'user': 'barney', 'age': 34 }, - * { 'user': 'fred', 'age': 40 }, - * { 'user': 'barney', 'age': 36 } - * ]; - * - * // Sort by `user` in ascending order and by `age` in descending order. - * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] - */ - function orderBy(collection, iteratees, orders, guard) { - if (collection == null) { - return []; - } - if (!isArray(iteratees)) { - iteratees = iteratees == null ? [] : [iteratees]; - } - orders = guard ? undefined : orders; - if (!isArray(orders)) { - orders = orders == null ? [] : [orders]; - } - return baseOrderBy(collection, iteratees, orders); - } +}); - /** - * Creates an array of elements split into two groups, the first of which - * contains elements `predicate` returns truthy for, the second of which - * contains elements `predicate` returns falsey for. The predicate is - * invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the array of grouped elements. - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true }, - * { 'user': 'pebbles', 'age': 1, 'active': false } - * ]; - * - * _.partition(users, function(o) { return o.active; }); - * // => objects for [['fred'], ['barney', 'pebbles']] - * - * // The `_.matches` iteratee shorthand. - * _.partition(users, { 'age': 1, 'active': false }); - * // => objects for [['pebbles'], ['barney', 'fred']] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.partition(users, ['active', false]); - * // => objects for [['barney', 'pebbles'], ['fred']] - * - * // The `_.property` iteratee shorthand. - * _.partition(users, 'active'); - * // => objects for [['fred'], ['barney', 'pebbles']] - */ - var partition = createAggregator(function(result, value, key) { - result[key ? 0 : 1].push(value); - }, function() { return [[], []]; }); +module.exports.PatientEntitySchema = PatientEntitySchema; +class PatientEntity extends mongoose.Document { + constructor(object) { + super(object, PatientEntitySchema); + this._type = 'QDM::PatientEntity'; + } +} - /** - * Reduces `collection` to a value which is the accumulated result of running - * each element in `collection` thru `iteratee`, where each successive - * invocation is supplied the return value of the previous. If `accumulator` - * is not given, the first element of `collection` is used as the initial - * value. The iteratee is invoked with four arguments: - * (accumulator, value, index|key, collection). - * - * Many lodash methods are guarded to work as iteratees for methods like - * `_.reduce`, `_.reduceRight`, and `_.transform`. - * - * The guarded methods are: - * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, - * and `sortBy` - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @param {*} [accumulator] The initial value. - * @returns {*} Returns the accumulated value. - * @see _.reduceRight - * @example - * - * _.reduce([1, 2], function(sum, n) { - * return sum + n; - * }, 0); - * // => 3 - * - * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { - * (result[value] || (result[value] = [])).push(key); - * return result; - * }, {}); - * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) - */ - function reduce(collection, iteratee, accumulator) { - var func = isArray(collection) ? arrayReduce : baseReduce, - initAccum = arguments.length < 3; +module.exports.PatientEntity = PatientEntity; - return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); - } - /** - * This method is like `_.reduce` except that it iterates over elements of - * `collection` from right to left. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @param {*} [accumulator] The initial value. - * @returns {*} Returns the accumulated value. - * @see _.reduce - * @example - * - * var array = [[0, 1], [2, 3], [4, 5]]; - * - * _.reduceRight(array, function(flattened, other) { - * return flattened.concat(other); - * }, []); - * // => [4, 5, 2, 3, 0, 1] - */ - function reduceRight(collection, iteratee, accumulator) { - var func = isArray(collection) ? arrayReduceRight : baseReduce, - initAccum = arguments.length < 3; +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Entity":168,"mongoose/browser":226}],174:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); - } +const { EntitySchemaFunction } = require('./Entity'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /** - * The opposite of `_.filter`; this method returns the elements of `collection` - * that `predicate` does **not** return truthy for. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - * @see _.filter - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true } - * ]; - * - * _.reject(users, function(o) { return !o.active; }); - * // => objects for ['fred'] - * - * // The `_.matches` iteratee shorthand. - * _.reject(users, { 'age': 40, 'active': true }); - * // => objects for ['barney'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.reject(users, ['active', false]); - * // => objects for ['fred'] - * - * // The `_.property` iteratee shorthand. - * _.reject(users, 'active'); - * // => objects for ['barney'] - */ - function reject(collection, predicate) { - var func = isArray(collection) ? arrayFilter : baseFilter; - return func(collection, negate(getIteratee(predicate, 3))); - } +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; + +const PractitionerSchema = EntitySchemaFunction({ + role: Code, + specialty: Code, + qualification: Code, + hqmfOid: { type: String, default: '2.16.840.1.113883.10.20.28.4.137' }, + qrdaOid: { type: String, default: '2.16.840.1.113883.10.20.24.3.162' }, + _type: { type: String, default: 'QDM::Practitioner' }, - /** - * Gets a random element from `collection`. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Collection - * @param {Array|Object} collection The collection to sample. - * @returns {*} Returns the random element. - * @example - * - * _.sample([1, 2, 3, 4]); - * // => 2 - */ - function sample(collection) { - var func = isArray(collection) ? arraySample : baseSample; - return func(collection); - } +}); - /** - * Gets `n` random elements at unique keys from `collection` up to the - * size of `collection`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Collection - * @param {Array|Object} collection The collection to sample. - * @param {number} [n=1] The number of elements to sample. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the random elements. - * @example - * - * _.sampleSize([1, 2, 3], 2); - * // => [3, 1] - * - * _.sampleSize([1, 2, 3], 4); - * // => [2, 3, 1] - */ - function sampleSize(collection, n, guard) { - if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) { - n = 1; - } else { - n = toInteger(n); - } - var func = isArray(collection) ? arraySampleSize : baseSampleSize; - return func(collection, n); - } +module.exports.PractitionerSchema = PractitionerSchema; +class Practitioner extends mongoose.Document { + constructor(object) { + super(object, PractitionerSchema); + this._type = 'QDM::Practitioner'; + } +} - /** - * Creates an array of shuffled values, using a version of the - * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to shuffle. - * @returns {Array} Returns the new shuffled array. - * @example - * - * _.shuffle([1, 2, 3, 4]); - * // => [4, 1, 3, 2] - */ - function shuffle(collection) { - var func = isArray(collection) ? arrayShuffle : baseShuffle; - return func(collection); - } +module.exports.Practitioner = Practitioner; - /** - * Gets the size of `collection` by returning its length for array-like - * values or the number of own enumerable string keyed properties for objects. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object|string} collection The collection to inspect. - * @returns {number} Returns the collection size. - * @example - * - * _.size([1, 2, 3]); - * // => 3 - * - * _.size({ 'a': 1, 'b': 2 }); - * // => 2 - * - * _.size('pebbles'); - * // => 7 - */ - function size(collection) { - if (collection == null) { - return 0; - } - if (isArrayLike(collection)) { - return isString(collection) ? stringSize(collection) : collection.length; - } - var tag = getTag(collection); - if (tag == mapTag || tag == setTag) { - return collection.size; - } - return baseKeys(collection).length; - } - /** - * Checks if `predicate` returns truthy for **any** element of `collection`. - * Iteration is stopped once `predicate` returns truthy. The predicate is - * invoked with three arguments: (value, index|key, collection). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - * @example - * - * _.some([null, 0, 'yes', false], Boolean); - * // => true - * - * var users = [ - * { 'user': 'barney', 'active': true }, - * { 'user': 'fred', 'active': false } - * ]; - * - * // The `_.matches` iteratee shorthand. - * _.some(users, { 'user': 'barney', 'active': false }); - * // => false - * - * // The `_.matchesProperty` iteratee shorthand. - * _.some(users, ['active', false]); - * // => true - * - * // The `_.property` iteratee shorthand. - * _.some(users, 'active'); - * // => true - */ - function some(collection, predicate, guard) { - var func = isArray(collection) ? arraySome : baseSome; - if (guard && isIterateeCall(collection, predicate, guard)) { - predicate = undefined; - } - return func(collection, getIteratee(predicate, 3)); - } +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Entity":168,"mongoose/browser":226}],175:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Creates an array of elements, sorted in ascending order by the results of - * running each element in a collection thru each iteratee. This method - * performs a stable sort, that is, it preserves the original sort order of - * equal elements. The iteratees are invoked with one argument: (value). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {...(Function|Function[])} [iteratees=[_.identity]] - * The iteratees to sort by. - * @returns {Array} Returns the new sorted array. - * @example - * - * var users = [ - * { 'user': 'fred', 'age': 48 }, - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 30 }, - * { 'user': 'barney', 'age': 34 } - * ]; - * - * _.sortBy(users, [function(o) { return o.user; }]); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]] - * - * _.sortBy(users, ['user', 'age']); - * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]] - */ - var sortBy = baseRest(function(collection, iteratees) { - if (collection == null) { - return []; - } - var length = iteratees.length; - if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { - iteratees = []; - } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { - iteratees = [iteratees[0]]; - } - return baseOrderBy(collection, baseFlatten(iteratees, 1), []); - }); +const { ComponentSchemaFunction } = require('./Component'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const QDMDate = require('../basetypes/QDMDate'); +const Any = require('../basetypes/Any'); - /*------------------------------------------------------------------------*/ +const [Number, String] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, +]; - /** - * Gets the timestamp of the number of milliseconds that have elapsed since - * the Unix epoch (1 January 1970 00:00:00 UTC). - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Date - * @returns {number} Returns the timestamp. - * @example - * - * _.defer(function(stamp) { - * console.log(_.now() - stamp); - * }, _.now()); - * // => Logs the number of milliseconds it took for the deferred invocation. - */ - var now = ctxNow || function() { - return root.Date.now(); - }; +const ResultComponentSchema = ComponentSchemaFunction({ + referenceRange: Interval, + _type: { type: String, default: 'QDM::ResultComponent' }, - /*------------------------------------------------------------------------*/ +}); - /** - * The opposite of `_.before`; this method creates a function that invokes - * `func` once it's called `n` or more times. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {number} n The number of calls before `func` is invoked. - * @param {Function} func The function to restrict. - * @returns {Function} Returns the new restricted function. - * @example - * - * var saves = ['profile', 'settings']; - * - * var done = _.after(saves.length, function() { - * console.log('done saving!'); - * }); - * - * _.forEach(saves, function(type) { - * asyncSave({ 'type': type, 'complete': done }); - * }); - * // => Logs 'done saving!' after the two async saves have completed. - */ - function after(n, func) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - n = toInteger(n); - return function() { - if (--n < 1) { - return func.apply(this, arguments); - } - }; - } +module.exports.ResultComponentSchema = ResultComponentSchema; +class ResultComponent extends mongoose.Document { + constructor(object) { + super(object, ResultComponentSchema); + this._type = 'QDM::ResultComponent'; + } +} - /** - * Creates a function that invokes `func`, with up to `n` arguments, - * ignoring any additional arguments. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Function - * @param {Function} func The function to cap arguments for. - * @param {number} [n=func.length] The arity cap. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Function} Returns the new capped function. - * @example - * - * _.map(['6', '8', '10'], _.ary(parseInt, 1)); - * // => [6, 8, 10] - */ - function ary(func, n, guard) { - n = guard ? undefined : n; - n = (func && n == null) ? func.length : n; - return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n); - } +module.exports.ResultComponent = ResultComponent; - /** - * Creates a function that invokes `func`, with the `this` binding and arguments - * of the created function, while it's called less than `n` times. Subsequent - * calls to the created function return the result of the last `func` invocation. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Function - * @param {number} n The number of calls at which `func` is no longer invoked. - * @param {Function} func The function to restrict. - * @returns {Function} Returns the new restricted function. - * @example - * - * jQuery(element).on('click', _.before(5, addContactToList)); - * // => Allows adding up to 4 contacts to the list. - */ - function before(n, func) { - var result; - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - n = toInteger(n); - return function() { - if (--n > 0) { - result = func.apply(this, arguments); - } - if (n <= 1) { - func = undefined; - } - return result; - }; - } - /** - * Creates a function that invokes `func` with the `this` binding of `thisArg` - * and `partials` prepended to the arguments it receives. - * - * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, - * may be used as a placeholder for partially applied arguments. - * - * **Note:** Unlike native `Function#bind`, this method doesn't set the "length" - * property of bound functions. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to bind. - * @param {*} thisArg The `this` binding of `func`. - * @param {...*} [partials] The arguments to be partially applied. - * @returns {Function} Returns the new bound function. - * @example - * - * function greet(greeting, punctuation) { - * return greeting + ' ' + this.user + punctuation; - * } - * - * var object = { 'user': 'fred' }; - * - * var bound = _.bind(greet, object, 'hi'); - * bound('!'); - * // => 'hi fred!' - * - * // Bound with placeholders. - * var bound = _.bind(greet, object, _, '!'); - * bound('hi'); - * // => 'hi fred!' - */ - var bind = baseRest(function(func, thisArg, partials) { - var bitmask = WRAP_BIND_FLAG; - if (partials.length) { - var holders = replaceHolders(partials, getHolder(bind)); - bitmask |= WRAP_PARTIAL_FLAG; - } - return createWrap(func, bitmask, thisArg, partials, holders); - }); +},{"../basetypes/Any":176,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/QDMDate":182,"../basetypes/Quantity":183,"./Component":166,"mongoose/browser":226}],176:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); - /** - * Creates a function that invokes the method at `object[key]` with `partials` - * prepended to the arguments it receives. - * - * This method differs from `_.bind` by allowing bound functions to reference - * methods that may be redefined or don't yet exist. See - * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) - * for more details. - * - * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic - * builds, may be used as a placeholder for partially applied arguments. - * - * @static - * @memberOf _ - * @since 0.10.0 - * @category Function - * @param {Object} object The object to invoke the method on. - * @param {string} key The key of the method. - * @param {...*} [partials] The arguments to be partially applied. - * @returns {Function} Returns the new bound function. - * @example - * - * var object = { - * 'user': 'fred', - * 'greet': function(greeting, punctuation) { - * return greeting + ' ' + this.user + punctuation; - * } - * }; - * - * var bound = _.bindKey(object, 'greet', 'hi'); - * bound('!'); - * // => 'hi fred!' - * - * object.greet = function(greeting, punctuation) { - * return greeting + 'ya ' + this.user + punctuation; - * }; - * - * bound('!'); - * // => 'hiya fred!' - * - * // Bound with placeholders. - * var bound = _.bindKey(object, 'greet', _, '!'); - * bound('hi'); - * // => 'hiya fred!' - */ - var bindKey = baseRest(function(object, key, partials) { - var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; - if (partials.length) { - var holders = replaceHolders(partials, getHolder(bindKey)); - bitmask |= WRAP_PARTIAL_FLAG; - } - return createWrap(key, bitmask, object, partials, holders); - }); +function Any(key, options) { + mongoose.SchemaType.call(this, key, options, 'Any'); +} +Any.prototype = Object.create(mongoose.SchemaType.prototype); - /** - * Creates a function that accepts arguments of `func` and either invokes - * `func` returning its result, if at least `arity` number of arguments have - * been provided, or returns a function that accepts the remaining `func` - * arguments, and so on. The arity of `func` may be specified if `func.length` - * is not sufficient. - * - * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, - * may be used as a placeholder for provided arguments. - * - * **Note:** This method doesn't set the "length" property of curried functions. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Function - * @param {Function} func The function to curry. - * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Function} Returns the new curried function. - * @example - * - * var abc = function(a, b, c) { - * return [a, b, c]; - * }; - * - * var curried = _.curry(abc); - * - * curried(1)(2)(3); - * // => [1, 2, 3] - * - * curried(1, 2)(3); - * // => [1, 2, 3] - * - * curried(1, 2, 3); - * // => [1, 2, 3] - * - * // Curried with placeholders. - * curried(1)(_, 3)(2); - * // => [1, 2, 3] - */ - function curry(func, arity, guard) { - arity = guard ? undefined : arity; - var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); - result.placeholder = curry.placeholder; - return result; +function RecursiveCast(any) { + if (any && any.value !== undefined && any.unit) { + return new cql.Quantity(any.value, any.unit); + } + + if (any && any.numerator && any.denominator) { + const numerator = new cql.Quantity(any.numerator.value, any.numerator.unit); + const denominator = new cql.Quantity(any.denominator.value, any.denominator.unit); + return new cql.Ratio(numerator, denominator); + } + + if (any.isCode || any.isConcept || any.isValueSet || any.isList || + any.isDateTime || any.isDate || any.isRatio || any.isQuantiy || + any.isInterval || any.isBooleanLiteral || any.isIntegerLiteral || + any.isDecimalLiteral || any.isStringLiteral || any.isTuple) { + return any; + } + + if (any && any.code && any.system) { + const val = { code: any.code, system: any.system }; + val.display = (typeof any.display !== 'undefined') ? any.display : null; + val.version = (typeof any.version !== 'undefined') ? any.version : null; + + return new cql.Code(val.code, val.system, val.version, val.display); + } + if (any && any.low) { + const casted = new cql.Interval(any.low, any.high, any.lowClosed, any.highClosed); + + // Cast Low and High values to Quantities if it is a quantity + if (casted.low && casted.low.unit && casted.low.value) { + casted.low = new cql.Quantity(casted.low.value, casted.low.unit); + if (casted.high && casted.high.unit && casted.high.value) { + casted.high = new cql.Quantity(casted.high.value, casted.high.unit); + } + return casted; } - /** - * This method is like `_.curry` except that arguments are applied to `func` - * in the manner of `_.partialRight` instead of `_.partial`. - * - * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic - * builds, may be used as a placeholder for provided arguments. - * - * **Note:** This method doesn't set the "length" property of curried functions. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Function - * @param {Function} func The function to curry. - * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Function} Returns the new curried function. - * @example - * - * var abc = function(a, b, c) { - * return [a, b, c]; - * }; - * - * var curried = _.curryRight(abc); - * - * curried(3)(2)(1); - * // => [1, 2, 3] - * - * curried(2, 3)(1); - * // => [1, 2, 3] - * - * curried(1, 2, 3); - * // => [1, 2, 3] - * - * // Curried with placeholders. - * curried(3)(1, _)(2); - * // => [1, 2, 3] - */ - function curryRight(func, arity, guard) { - arity = guard ? undefined : arity; - var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); - result.placeholder = curryRight.placeholder; - return result; + // Cast to DateTime if it is a string representing a DateTime + if (casted.low && Date.parse(casted.low)) { + casted.low = cql.DateTime.fromJSDate(new Date(casted.low), 0); + } + if (casted.high && Date.parse(casted.high)) { + casted.high = cql.DateTime.fromJSDate(new Date(casted.high), 0); + } + return casted; + } + if (Array.isArray(any)) { + const casted = []; + any.forEach((val) => { + casted.push(RecursiveCast(val)); + }); + return casted; + } + if (Number.isFinite(any)) { + return any; + } + if (Date.parse(any) || Date.parse(`1984-01-01T${any}`)) { + if (any.match(/T/) || any.match(/\+/)) { + // If it has a T or a timezoneoffset, it must be a DateTime + return cql.DateTime.fromJSDate(new Date(any), 0); + } + if (any.match(/:/)) { + // If it has a : but no T or timezoneoffset, it must be a Time + return cql.DateTime.fromJSDate(new Date(`1984-01-01T${any}`), 0).getTime(); } + // Must be a Date + return cql.DateTime.fromJSDate(new Date(any), 0).getDate(); + } + return any; +} - /** - * Creates a debounced function that delays invoking `func` until after `wait` - * milliseconds have elapsed since the last time the debounced function was - * invoked. The debounced function comes with a `cancel` method to cancel - * delayed `func` invocations and a `flush` method to immediately invoke them. - * Provide `options` to indicate whether `func` should be invoked on the - * leading and/or trailing edge of the `wait` timeout. The `func` is invoked - * with the last arguments provided to the debounced function. Subsequent - * calls to the debounced function return the result of the last `func` - * invocation. - * - * **Note:** If `leading` and `trailing` options are `true`, `func` is - * invoked on the trailing edge of the timeout only if the debounced function - * is invoked more than once during the `wait` timeout. - * - * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred - * until to the next tick, similar to `setTimeout` with a timeout of `0`. - * - * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) - * for details over the differences between `_.debounce` and `_.throttle`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to debounce. - * @param {number} [wait=0] The number of milliseconds to delay. - * @param {Object} [options={}] The options object. - * @param {boolean} [options.leading=false] - * Specify invoking on the leading edge of the timeout. - * @param {number} [options.maxWait] - * The maximum time `func` is allowed to be delayed before it's invoked. - * @param {boolean} [options.trailing=true] - * Specify invoking on the trailing edge of the timeout. - * @returns {Function} Returns the new debounced function. - * @example - * - * // Avoid costly calculations while the window size is in flux. - * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); - * - * // Invoke `sendMail` when clicked, debouncing subsequent calls. - * jQuery(element).on('click', _.debounce(sendMail, 300, { - * 'leading': true, - * 'trailing': false - * })); - * - * // Ensure `batchLog` is invoked once after 1 second of debounced calls. - * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); - * var source = new EventSource('/stream'); - * jQuery(source).on('message', debounced); - * - * // Cancel the trailing debounced invocation. - * jQuery(window).on('popstate', debounced.cancel); - */ - function debounce(func, wait, options) { - var lastArgs, - lastThis, - maxWait, - result, - timerId, - lastCallTime, - lastInvokeTime = 0, - leading = false, - maxing = false, - trailing = true; +Any.prototype.cast = any => RecursiveCast(any); - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - wait = toNumber(wait) || 0; - if (isObject(options)) { - leading = !!options.leading; - maxing = 'maxWait' in options; - maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; - trailing = 'trailing' in options ? !!options.trailing : trailing; - } +mongoose.Schema.Types.Any = Any; +module.exports = Any; - function invokeFunc(time) { - var args = lastArgs, - thisArg = lastThis; +},{"cql-execution":41,"mongoose/browser":226}],177:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const { PatientEntity } = require('../attributes/PatientEntity'); +const { Practitioner } = require('../attributes/Practitioner'); +const { CarePartner } = require('../attributes/CarePartner'); +const { Organization } = require('../attributes/Organization'); +const { Location } = require('../attributes/Location'); - lastArgs = lastThis = undefined; - lastInvokeTime = time; - result = func.apply(thisArg, args); - return result; - } +function AnyEntity(key, options) { + mongoose.SchemaType.call(this, key, options, 'AnyEntity'); +} +AnyEntity.prototype = Object.create(mongoose.SchemaType.prototype); - function leadingEdge(time) { - // Reset any `maxWait` timer. - lastInvokeTime = time; - // Start the timer for the trailing edge. - timerId = setTimeout(timerExpired, wait); - // Invoke the leading edge. - return leading ? invokeFunc(time) : result; - } +AnyEntity.prototype.cast = (entity) => { + if (entity == null) { + return null; + } - function remainingWait(time) { - var timeSinceLastCall = time - lastCallTime, - timeSinceLastInvoke = time - lastInvokeTime, - timeWaiting = wait - timeSinceLastCall; + if (entity instanceof PatientEntity || entity instanceof Practitioner || entity instanceof CarePartner || entity instanceof Organization || entity instanceof Location) { + return entity; + } - return maxing - ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) - : timeWaiting; - } + if (entity._type != null) { + // copy _id to id if it isn't defined + if (entity.id == null && entity._id != null) { + entity.id = entity._id; + } + switch (entity._type) { + case 'QDM::PatientEntity': + return new PatientEntity(entity); + case 'QDM::Practitioner': + return new Practitioner(entity); + case 'QDM::CarePartner': + return new CarePartner(entity); + case 'QDM::Organization': + return new Organization(entity); + case 'QDM::Location': + return new Location(entity); + default: + throw new Error(`Could not find entity type "${entity._type}".`); + } + } else { + throw new Error('Could not find _type indicator for entity.'); + } +}; - function shouldInvoke(time) { - var timeSinceLastCall = time - lastCallTime, - timeSinceLastInvoke = time - lastInvokeTime; +mongoose.Schema.Types.AnyEntity = AnyEntity; +module.exports = AnyEntity; - // Either this is the first call, activity has stopped and we're at the - // trailing edge, the system time has gone backwards and we're treating - // it as the trailing edge, or we've hit the `maxWait` limit. - return (lastCallTime === undefined || (timeSinceLastCall >= wait) || - (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); - } +},{"../attributes/CarePartner":165,"../attributes/Location":171,"../attributes/Organization":172,"../attributes/PatientEntity":173,"../attributes/Practitioner":174,"mongoose/browser":226}],178:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); - function timerExpired() { - var time = now(); - if (shouldInvoke(time)) { - return trailingEdge(time); - } - // Restart the timer. - timerId = setTimeout(timerExpired, remainingWait(time)); - } +function Code(key, options) { + mongoose.SchemaType.call(this, key, options, 'Code'); +} +Code.prototype = Object.create(mongoose.SchemaType.prototype); - function trailingEdge(time) { - timerId = undefined; +Code.prototype.cast = (code) => { + if (code != null) { + // return code if it doesn't even need casting + if (code.isCode) { + return code; + } + // handles codes that have not yet been cast to a code and those that have already been cast to a code + if (code.code && code.system) { + const val = { code: code.code, system: code.system }; + val.display = (typeof code.display !== 'undefined') ? code.display : null; + val.version = (typeof code.version !== 'undefined') ? code.version : null; - // Only invoke if we have `lastArgs` which means `func` has been - // debounced at least once. - if (trailing && lastArgs) { - return invokeFunc(time); - } - lastArgs = lastThis = undefined; - return result; - } + return new cql.Code(val.code, val.system, val.version, val.display); + } + throw new Error(`Expected a code. Received ${code}.`); + } else { + // returns a null or undefined if what is passed in is null or undefined + return code; + } +}; - function cancel() { - if (timerId !== undefined) { - clearTimeout(timerId); - } - lastInvokeTime = 0; - lastArgs = lastCallTime = lastThis = timerId = undefined; - } +mongoose.Schema.Types.Code = Code; +module.exports = Code; - function flush() { - return timerId === undefined ? result : trailingEdge(now()); - } +},{"cql-execution":41,"mongoose/browser":226}],179:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); +const Code = require('./Code.js'); +const Identifier = require('../attributes/Identifier'); - function debounced() { - var time = now(), - isInvoking = shouldInvoke(time); +const [Schema] = [mongoose.Schema]; - lastArgs = arguments; - lastThis = this; - lastCallTime = time; +function DataElementSchema(add, options) { + const extended = new Schema({ + dataElementCodes: { type: [Code] }, + description: { type: String }, + codeListId: { type: String }, + id: { + type: String, + default() { + return this._id ? this._id.toString() : mongoose.Types.ObjectId().toString(); + }, + }, + }, options); - if (isInvoking) { - if (timerId === undefined) { - return leadingEdge(lastCallTime); - } - if (maxing) { - // Handle invocations in a tight loop. - clearTimeout(timerId); - timerId = setTimeout(timerExpired, wait); - return invokeFunc(lastCallTime); - } - } - if (timerId === undefined) { - timerId = setTimeout(timerExpired, wait); + if (add) { + extended.add(add); + } + + // Returns all of the codes on this data element in a format usable by + // the cql-execution framework. + extended.methods.getCode = function getCode() { + if (this.dataElementCodes) { + return this.dataElementCodes.map((code) => { + if (code.isCode) { + return code; } - return result; + return new cql.Code(code.code, code.system, code.version, code.display); + }); + } + return null; + }; + + // Return the first code on this data element in a format usable by + // the cql-execution framework. + extended.methods.code = function code() { + if (this.dataElementCodes && this.dataElementCodes[0]) { + const qdmCode = this.dataElementCodes[0]; + if (qdmCode.isCode) { + return qdmCode; } - debounced.cancel = cancel; - debounced.flush = flush; - return debounced; + return new cql.Code(qdmCode.code, qdmCode.system, qdmCode.version, qdmCode.display); } + return null; + }; - /** - * Defers invoking the `func` until the current call stack has cleared. Any - * additional arguments are provided to `func` when it's invoked. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to defer. - * @param {...*} [args] The arguments to invoke `func` with. - * @returns {number} Returns the timer id. - * @example - * - * _.defer(function(text) { - * console.log(text); - * }, 'deferred'); - * // => Logs 'deferred' after one millisecond. - */ - var defer = baseRest(function(func, args) { - return baseDelay(func, 1, args); - }); + /* eslint no-underscore-dangle: 0 */ + extended.methods._is = function _is(typeSpecifier) { + return this._typeHierarchy().some( + t => t.type === typeSpecifier.type && t.name === typeSpecifier.name + ); + }; - /** - * Invokes `func` after `wait` milliseconds. Any additional arguments are - * provided to `func` when it's invoked. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to delay. - * @param {number} wait The number of milliseconds to delay invocation. - * @param {...*} [args] The arguments to invoke `func` with. - * @returns {number} Returns the timer id. - * @example - * - * _.delay(function(text) { - * console.log(text); - * }, 1000, 'later'); - * // => Logs 'later' after one second. - */ - var delay = baseRest(function(func, wait, args) { - return baseDelay(func, toNumber(wait) || 0, args); - }); + /* eslint no-underscore-dangle: 0 */ + extended.methods._typeHierarchy = function _typeHierarchy() { + const typeName = this._type.replace(/QDM::/, ''); + const prefix = this.negationRationale ? 'Negative' : 'Positive'; + const ver = this.qdmVersion.replace('.', '_'); + return [ + { + name: `{urn:healthit-gov:qdm:v${ver}}${prefix}${typeName}`, + type: 'NamedTypeSpecifier', + }, + { + name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`, + type: 'NamedTypeSpecifier', + }, + { name: '{urn:hl7-org:elm-types:r1}Tuple', type: 'NamedTypeSpecifier' }, + { name: '{urn:hl7-org:elm-types:r1}Any', type: 'NamedTypeSpecifier' }, + ]; + }; + return extended; +} - /** - * Creates a function that invokes `func` with arguments reversed. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Function - * @param {Function} func The function to flip arguments for. - * @returns {Function} Returns the new flipped function. - * @example - * - * var flipped = _.flip(function() { - * return _.toArray(arguments); - * }); - * - * flipped('a', 'b', 'c', 'd'); - * // => ['d', 'c', 'b', 'a'] - */ - function flip(func) { - return createWrap(func, WRAP_FLIP_FLAG); - } +module.exports.DataElementSchema = DataElementSchema; - /** - * Creates a function that memoizes the result of `func`. If `resolver` is - * provided, it determines the cache key for storing the result based on the - * arguments provided to the memoized function. By default, the first argument - * provided to the memoized function is used as the map cache key. The `func` - * is invoked with the `this` binding of the memoized function. - * - * **Note:** The cache is exposed as the `cache` property on the memoized - * function. Its creation may be customized by replacing the `_.memoize.Cache` - * constructor with one whose instances implement the - * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) - * method interface of `clear`, `delete`, `get`, `has`, and `set`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] The function to resolve the cache key. - * @returns {Function} Returns the new memoized function. - * @example - * - * var object = { 'a': 1, 'b': 2 }; - * var other = { 'c': 3, 'd': 4 }; - * - * var values = _.memoize(_.values); - * values(object); - * // => [1, 2] - * - * values(other); - * // => [3, 4] - * - * object.a = 2; - * values(object); - * // => [1, 2] - * - * // Modify the result cache. - * values.cache.set(object, ['a', 'b']); - * values(object); - * // => ['a', 'b'] - * - * // Replace `_.memoize.Cache`. - * _.memoize.Cache = WeakMap; - */ - function memoize(func, resolver) { - if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { - throw new TypeError(FUNC_ERROR_TEXT); - } - var memoized = function() { - var args = arguments, - key = resolver ? resolver.apply(this, args) : args[0], - cache = memoized.cache; +},{"../attributes/Identifier":170,"./Code.js":178,"cql-execution":41,"mongoose/browser":226}],180:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); + +function DateTime(key, options) { + mongoose.SchemaType.call(this, key, options, 'DateTime'); +} +DateTime.prototype = Object.create(mongoose.SchemaType.prototype); + +DateTime.prototype.cast = (dateTime) => { + if (dateTime.isDateTime) { + return dateTime; + } + + if (!Date.parse(dateTime)) { + throw new Error(`DateTime: ${dateTime} is not a valid DateTime`); + } - if (cache.has(key)) { - return cache.get(key); - } - var result = func.apply(this, args); - memoized.cache = cache.set(key, result) || cache; - return result; - }; - memoized.cache = new (memoize.Cache || MapCache); - return memoized; - } + return cql.DateTime.fromJSDate(new Date(dateTime), 0); +}; - // Expose `MapCache`. - memoize.Cache = MapCache; +mongoose.Schema.Types.DateTime = DateTime; +module.exports = DateTime; - /** - * Creates a function that negates the result of the predicate `func`. The - * `func` predicate is invoked with the `this` binding and arguments of the - * created function. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Function - * @param {Function} predicate The predicate to negate. - * @returns {Function} Returns the new negated function. - * @example - * - * function isEven(n) { - * return n % 2 == 0; - * } - * - * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); - * // => [1, 3, 5] - */ - function negate(predicate) { - if (typeof predicate != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - return function() { - var args = arguments; - switch (args.length) { - case 0: return !predicate.call(this); - case 1: return !predicate.call(this, args[0]); - case 2: return !predicate.call(this, args[0], args[1]); - case 3: return !predicate.call(this, args[0], args[1], args[2]); - } - return !predicate.apply(this, args); - }; - } +},{"cql-execution":41,"mongoose/browser":226}],181:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); +const DateTime = require('./DateTime'); - /** - * Creates a function that is restricted to invoking `func` once. Repeat calls - * to the function return the value of the first invocation. The `func` is - * invoked with the `this` binding and arguments of the created function. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to restrict. - * @returns {Function} Returns the new restricted function. - * @example - * - * var initialize = _.once(createApplication); - * initialize(); - * initialize(); - * // => `createApplication` is invoked once - */ - function once(func) { - return before(2, func); +function Interval(key, options) { + mongoose.SchemaType.call(this, key, options, 'Interval'); +} +Interval.prototype = Object.create(mongoose.SchemaType.prototype); + +Interval.prototype.cast = (interval) => { + if (interval.isInterval) { + return interval; + } + const casted = new cql.Interval(interval.low, interval.high, interval.lowClosed, interval.highClosed); + + // Cast Low and High values to Quantities if it is a quantity + if (casted.low && casted.low.unit && casted.low.value) { + casted.low = new cql.Quantity(casted.low.value, casted.low.unit); + if (casted.high && casted.high.unit && casted.high.value) { + casted.high = new cql.Quantity(casted.high.value, casted.high.unit); } + return casted; + } - /** - * Creates a function that invokes `func` with its arguments transformed. - * - * @static - * @since 4.0.0 - * @memberOf _ - * @category Function - * @param {Function} func The function to wrap. - * @param {...(Function|Function[])} [transforms=[_.identity]] - * The argument transforms. - * @returns {Function} Returns the new function. - * @example - * - * function doubled(n) { - * return n * 2; - * } - * - * function square(n) { - * return n * n; - * } - * - * var func = _.overArgs(function(x, y) { - * return [x, y]; - * }, [square, doubled]); - * - * func(9, 3); - * // => [81, 6] - * - * func(10, 5); - * // => [100, 10] - */ - var overArgs = castRest(function(func, transforms) { - transforms = (transforms.length == 1 && isArray(transforms[0])) - ? arrayMap(transforms[0], baseUnary(getIteratee())) - : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); + // Cast to DateTime if it is a string representing a DateTime + if (casted.low) { + casted.low = DateTime.prototype.cast(casted.low); + } - var funcsLength = transforms.length; - return baseRest(function(args) { - var index = -1, - length = nativeMin(args.length, funcsLength); + if (casted.high) { + casted.high = DateTime.prototype.cast(casted.high); + } + return casted; +}; - while (++index < length) { - args[index] = transforms[index].call(this, args[index]); - } - return apply(func, this, args); - }); - }); +mongoose.Schema.Types.Interval = Interval; +module.exports = Interval; - /** - * Creates a function that invokes `func` with `partials` prepended to the - * arguments it receives. This method is like `_.bind` except it does **not** - * alter the `this` binding. - * - * The `_.partial.placeholder` value, which defaults to `_` in monolithic - * builds, may be used as a placeholder for partially applied arguments. - * - * **Note:** This method doesn't set the "length" property of partially - * applied functions. - * - * @static - * @memberOf _ - * @since 0.2.0 - * @category Function - * @param {Function} func The function to partially apply arguments to. - * @param {...*} [partials] The arguments to be partially applied. - * @returns {Function} Returns the new partially applied function. - * @example - * - * function greet(greeting, name) { - * return greeting + ' ' + name; - * } - * - * var sayHelloTo = _.partial(greet, 'hello'); - * sayHelloTo('fred'); - * // => 'hello fred' - * - * // Partially applied with placeholders. - * var greetFred = _.partial(greet, _, 'fred'); - * greetFred('hi'); - * // => 'hi fred' - */ - var partial = baseRest(function(func, partials) { - var holders = replaceHolders(partials, getHolder(partial)); - return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders); - }); +},{"./DateTime":180,"cql-execution":41,"mongoose/browser":226}],182:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); - /** - * This method is like `_.partial` except that partially applied arguments - * are appended to the arguments it receives. - * - * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic - * builds, may be used as a placeholder for partially applied arguments. - * - * **Note:** This method doesn't set the "length" property of partially - * applied functions. - * - * @static - * @memberOf _ - * @since 1.0.0 - * @category Function - * @param {Function} func The function to partially apply arguments to. - * @param {...*} [partials] The arguments to be partially applied. - * @returns {Function} Returns the new partially applied function. - * @example - * - * function greet(greeting, name) { - * return greeting + ' ' + name; - * } - * - * var greetFred = _.partialRight(greet, 'fred'); - * greetFred('hi'); - * // => 'hi fred' - * - * // Partially applied with placeholders. - * var sayHelloTo = _.partialRight(greet, 'hello', _); - * sayHelloTo('fred'); - * // => 'hello fred' - */ - var partialRight = baseRest(function(func, partials) { - var holders = replaceHolders(partials, getHolder(partialRight)); - return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders); - }); +function QDMDate(key, options) { + mongoose.SchemaType.call(this, key, options, 'Date'); +} +QDMDate.prototype = Object.create(mongoose.SchemaType.prototype); - /** - * Creates a function that invokes `func` with arguments arranged according - * to the specified `indexes` where the argument value at the first index is - * provided as the first argument, the argument value at the second index is - * provided as the second argument, and so on. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Function - * @param {Function} func The function to rearrange arguments for. - * @param {...(number|number[])} indexes The arranged argument indexes. - * @returns {Function} Returns the new function. - * @example - * - * var rearged = _.rearg(function(a, b, c) { - * return [a, b, c]; - * }, [2, 0, 1]); - * - * rearged('b', 'c', 'a') - * // => ['a', 'b', 'c'] - */ - var rearg = flatRest(function(func, indexes) { - return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes); - }); +QDMDate.prototype.cast = (date) => { + if (date == null) { + return date; + } - /** - * Creates a function that invokes `func` with the `this` binding of the - * created function and arguments from `start` and beyond provided as - * an array. - * - * **Note:** This method is based on the - * [rest parameter](https://mdn.io/rest_parameters). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Function - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - * @example - * - * var say = _.rest(function(what, names) { - * return what + ' ' + _.initial(names).join(', ') + - * (_.size(names) > 1 ? ', & ' : '') + _.last(names); - * }); - * - * say('hello', 'fred', 'barney', 'pebbles'); - * // => 'hello fred, barney, & pebbles' - */ - function rest(func, start) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - start = start === undefined ? start : toInteger(start); - return baseRest(func, start); + // Already a CQL Date + if (date.isDate) { + return date; + } + + // Object + if (typeof date === 'object') { + const keys = Object.keys(date); + if (keys.includes('year') && keys.includes('month') && keys.includes('day')) { + return new cql.Date(date.year, date.month, date.day); } + } - /** - * Creates a function that invokes `func` with the `this` binding of the - * create function and an array of arguments much like - * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply). - * - * **Note:** This method is based on the - * [spread operator](https://mdn.io/spread_operator). - * - * @static - * @memberOf _ - * @since 3.2.0 - * @category Function - * @param {Function} func The function to spread arguments over. - * @param {number} [start=0] The start position of the spread. - * @returns {Function} Returns the new function. - * @example - * - * var say = _.spread(function(who, what) { - * return who + ' says ' + what; - * }); - * - * say(['fred', 'hello']); - * // => 'fred says hello' - * - * var numbers = Promise.all([ - * Promise.resolve(40), - * Promise.resolve(36) - * ]); - * - * numbers.then(_.spread(function(x, y) { - * return x + y; - * })); - * // => a Promise of 76 - */ - function spread(func, start) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - start = start == null ? 0 : nativeMax(toInteger(start), 0); - return baseRest(function(args) { - var array = args[start], - otherArgs = castSlice(args, 0, start); + // Date String + if (!cql.Date.parse(date)) { + throw new Error(`Date: ${date} is not a valid Date`); + } else { + return cql.Date.parse(date); + } +}; - if (array) { - arrayPush(otherArgs, array); - } - return apply(func, this, otherArgs); - }); - } +mongoose.Schema.Types.QDMDate = QDMDate; +module.exports = QDMDate; - /** - * Creates a throttled function that only invokes `func` at most once per - * every `wait` milliseconds. The throttled function comes with a `cancel` - * method to cancel delayed `func` invocations and a `flush` method to - * immediately invoke them. Provide `options` to indicate whether `func` - * should be invoked on the leading and/or trailing edge of the `wait` - * timeout. The `func` is invoked with the last arguments provided to the - * throttled function. Subsequent calls to the throttled function return the - * result of the last `func` invocation. - * - * **Note:** If `leading` and `trailing` options are `true`, `func` is - * invoked on the trailing edge of the timeout only if the throttled function - * is invoked more than once during the `wait` timeout. - * - * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred - * until to the next tick, similar to `setTimeout` with a timeout of `0`. - * - * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) - * for details over the differences between `_.throttle` and `_.debounce`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to throttle. - * @param {number} [wait=0] The number of milliseconds to throttle invocations to. - * @param {Object} [options={}] The options object. - * @param {boolean} [options.leading=true] - * Specify invoking on the leading edge of the timeout. - * @param {boolean} [options.trailing=true] - * Specify invoking on the trailing edge of the timeout. - * @returns {Function} Returns the new throttled function. - * @example - * - * // Avoid excessively updating the position while scrolling. - * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); - * - * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. - * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); - * jQuery(element).on('click', throttled); - * - * // Cancel the trailing throttled invocation. - * jQuery(window).on('popstate', throttled.cancel); - */ - function throttle(func, wait, options) { - var leading = true, - trailing = true; +},{"cql-execution":41,"mongoose/browser":226}],183:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const cql = require('cql-execution'); - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - if (isObject(options)) { - leading = 'leading' in options ? !!options.leading : leading; - trailing = 'trailing' in options ? !!options.trailing : trailing; - } - return debounce(func, wait, { - 'leading': leading, - 'maxWait': wait, - 'trailing': trailing - }); - } +function Quantity(key, options) { + mongoose.SchemaType.call(this, key, options, 'Quantity'); +} +Quantity.prototype = Object.create(mongoose.SchemaType.prototype); - /** - * Creates a function that accepts up to one argument, ignoring any - * additional arguments. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Function - * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new capped function. - * @example - * - * _.map(['6', '8', '10'], _.unary(parseInt)); - * // => [6, 8, 10] - */ - function unary(func) { - return ary(func, 1); - } +Quantity.prototype.cast = (quantity) => { + if (typeof quantity.value === 'undefined') { + throw new Error(`Quantity: ${quantity} does not have a value`); + } else if (typeof quantity.unit === 'undefined') { + throw new Error(`Quantity: ${quantity} does not have a unit`); + } + + return new cql.Quantity(quantity.value, quantity.unit); +}; + +mongoose.Schema.Types.Quantity = Quantity; +module.exports = Quantity; + +},{"cql-execution":41,"mongoose/browser":226}],184:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const { StatementDependencySchema } = require('./CQLStatementDependency'); + +const [Mixed, mDate] = [ + mongoose.Schema.Types.Mixed, + mongoose.Schema.Types.Date, +]; + +const CQLLibrarySchema = new mongoose.Schema( + { + library_name: String, + library_version: String, + cql: String, + elm: Mixed, + elm_annotations: Mixed, + is_main_library: { type: Boolean, default: false }, + is_top_level: { type: Boolean, default: true }, + statement_dependencies: [StatementDependencySchema], + }, + // Options + { + timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps + } +); + +module.exports.CQLLibrarySchema = CQLLibrarySchema; +class CQLLibrary extends mongoose.Document { + constructor(object) { + super(object, CQLLibrarySchema); + } +} +module.exports.CQLLibrary = CQLLibrary; + +},{"./CQLStatementDependency":185,"mongoose/browser":226}],185:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +const StatementReferenceSchema = new mongoose.Schema({ + library_name: String, + statement_name: String, + hqmf_id: String, +}); + +const StatementDependencySchema = new mongoose.Schema({ + statement_name: String, + statement_references: [StatementReferenceSchema], +}); + +module.exports.StatementReferenceSchema = StatementReferenceSchema; +class StatementReference extends mongoose.Document { + constructor(object) { + super(object, StatementReferenceSchema); + } +} +module.exports.StatementReference = StatementReference; + +module.exports.StatementDependencySchema = StatementDependencySchema; +class StatementDependency extends mongoose.Document { + constructor(object) { + super(object, StatementDependencySchema); + } +} +module.exports.StatementDependency = StatementDependency; - /** - * Creates a function that provides `value` to `wrapper` as its first - * argument. Any additional arguments provided to the function are appended - * to those provided to the `wrapper`. The wrapper is invoked with the `this` - * binding of the created function. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {*} value The value to wrap. - * @param {Function} [wrapper=identity] The wrapper function. - * @returns {Function} Returns the new function. - * @example - * - * var p = _.wrap(_.escape, function(func, text) { - * return '

' + func(text) + '

'; - * }); - * - * p('fred, barney, & pebbles'); - * // => '

fred, barney, & pebbles

' - */ - function wrap(value, wrapper) { - return partial(castFunction(wrapper), value); - } +},{"mongoose/browser":226}],186:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /*------------------------------------------------------------------------*/ +const [String, Mixed] = [ + mongoose.Schema.Types.String, + mongoose.Schema.Types.Mixed, +]; - /** - * Casts `value` as an array if it's not one. - * - * @static - * @memberOf _ - * @since 4.4.0 - * @category Lang - * @param {*} value The value to inspect. - * @returns {Array} Returns the cast array. - * @example - * - * _.castArray(1); - * // => [1] - * - * _.castArray({ 'a': 1 }); - * // => [{ 'a': 1 }] - * - * _.castArray('abc'); - * // => ['abc'] - * - * _.castArray(null); - * // => [null] - * - * _.castArray(undefined); - * // => [undefined] - * - * _.castArray(); - * // => [] - * - * var array = [1, 2, 3]; - * console.log(_.castArray(array) === array); - * // => true - */ - function castArray() { - if (!arguments.length) { - return []; - } - var value = arguments[0]; - return isArray(value) ? value : [value]; - } +const ClauseResultSchema = mongoose.Schema({ + // Library the clause this result is for is in + library_name: String, + // Statement the clause this result is for is in + statement_name: String, + // LocalId of the clause this result is for + localId: String, + // Final, processed result of raw calculation + final: String, + // Raw result of clause calculation + raw: Mixed, +}); - /** - * Creates a shallow clone of `value`. - * - * **Note:** This method is loosely based on the - * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) - * and supports cloning arrays, array buffers, booleans, date objects, maps, - * numbers, `Object` objects, regexes, sets, strings, symbols, and typed - * arrays. The own enumerable properties of `arguments` objects are cloned - * as plain objects. An empty object is returned for uncloneable values such - * as error objects, functions, DOM nodes, and WeakMaps. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to clone. - * @returns {*} Returns the cloned value. - * @see _.cloneDeep - * @example - * - * var objects = [{ 'a': 1 }, { 'b': 2 }]; - * - * var shallow = _.clone(objects); - * console.log(shallow[0] === objects[0]); - * // => true - */ - function clone(value) { - return baseClone(value, CLONE_SYMBOLS_FLAG); - } - /** - * This method is like `_.clone` except that it accepts `customizer` which - * is invoked to produce the cloned value. If `customizer` returns `undefined`, - * cloning is handled by the method instead. The `customizer` is invoked with - * up to four arguments; (value [, index|key, object, stack]). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to clone. - * @param {Function} [customizer] The function to customize cloning. - * @returns {*} Returns the cloned value. - * @see _.cloneDeepWith - * @example - * - * function customizer(value) { - * if (_.isElement(value)) { - * return value.cloneNode(false); - * } - * } - * - * var el = _.cloneWith(document.body, customizer); - * - * console.log(el === document.body); - * // => false - * console.log(el.nodeName); - * // => 'BODY' - * console.log(el.childNodes.length); - * // => 0 - */ - function cloneWith(value, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - return baseClone(value, CLONE_SYMBOLS_FLAG, customizer); - } +module.exports.ClauseResultSchema = ClauseResultSchema; +class ClauseResult extends mongoose.Document { + constructor(object) { + super(object, ClauseResultSchema); + } +} +module.exports.ClauseResult = ClauseResult; - /** - * This method is like `_.clone` except that it recursively clones `value`. - * - * @static - * @memberOf _ - * @since 1.0.0 - * @category Lang - * @param {*} value The value to recursively clone. - * @returns {*} Returns the deep cloned value. - * @see _.clone - * @example - * - * var objects = [{ 'a': 1 }, { 'b': 2 }]; - * - * var deep = _.cloneDeep(objects); - * console.log(deep[0] === objects[0]); - * // => false - */ - function cloneDeep(value) { - return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG); - } +},{"mongoose/browser":226}],187:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * This method is like `_.cloneWith` except that it recursively clones `value`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to recursively clone. - * @param {Function} [customizer] The function to customize cloning. - * @returns {*} Returns the deep cloned value. - * @see _.cloneWith - * @example - * - * function customizer(value) { - * if (_.isElement(value)) { - * return value.cloneNode(true); - * } - * } - * - * var el = _.cloneDeepWith(document.body, customizer); - * - * console.log(el === document.body); - * // => false - * console.log(el.nodeName); - * // => 'BODY' - * console.log(el.childNodes.length); - * // => 20 - */ - function cloneDeepWith(value, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer); - } +const ConceptSchema = new mongoose.Schema({ + code: String, + code_system_oid: String, + code_system_name: String, + code_system_version: String, + display_name: String, +}); - /** - * Checks if `object` conforms to `source` by invoking the predicate - * properties of `source` with the corresponding property values of `object`. - * - * **Note:** This method is equivalent to `_.conforms` when `source` is - * partially applied. - * - * @static - * @memberOf _ - * @since 4.14.0 - * @category Lang - * @param {Object} object The object to inspect. - * @param {Object} source The object of property predicates to conform to. - * @returns {boolean} Returns `true` if `object` conforms, else `false`. - * @example - * - * var object = { 'a': 1, 'b': 2 }; - * - * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); - * // => true - * - * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); - * // => false - */ - function conformsTo(object, source) { - return source == null || baseConformsTo(object, source, keys(source)); - } +module.exports.ConceptSchema = ConceptSchema; +class Concept extends mongoose.Document { + constructor(object) { + super(object, ConceptSchema); + } +} +module.exports.Concept = Concept; - /** - * Performs a - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * comparison between two values to determine if they are equivalent. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.eq(object, object); - * // => true - * - * _.eq(object, other); - * // => false - * - * _.eq('a', 'a'); - * // => true - * - * _.eq('a', Object('a')); - * // => false - * - * _.eq(NaN, NaN); - * // => true - */ - function eq(value, other) { - return value === other || (value !== value && other !== other); - } +},{"mongoose/browser":226}],188:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const { ClauseResultSchema } = require('./ClauseResult'); +const { StatementResultSchema } = require('./StatementResult'); - /** - * Checks if `value` is greater than `other`. - * - * @static - * @memberOf _ - * @since 3.9.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than `other`, - * else `false`. - * @see _.lt - * @example - * - * _.gt(3, 1); - * // => true - * - * _.gt(3, 3); - * // => false - * - * _.gt(1, 3); - * // => false - */ - var gt = createRelationalOperation(baseGt); +const [Number, String, Mixed, ObjectId] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, + mongoose.Schema.Types.Mixed, + mongoose.Schema.Types.ObjectId, +]; - /** - * Checks if `value` is greater than or equal to `other`. - * - * @static - * @memberOf _ - * @since 3.9.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than or equal to - * `other`, else `false`. - * @see _.lte - * @example - * - * _.gte(3, 1); - * // => true - * - * _.gte(3, 3); - * // => true - * - * _.gte(1, 3); - * // => false - */ - var gte = createRelationalOperation(function(value, other) { - return value >= other; - }); +const IndividualResultSchema = mongoose.Schema( + { + // Population Attributes + STRAT: Number, + IPP: Number, + DENOM: Number, + NUMER: Number, + NUMEX: Number, + DENEX: Number, + DENEXCEP: Number, + MSRPOPL: Number, + OBSERV: Number, + MSRPOPLEX: Number, - /** - * Checks if `value` is likely an `arguments` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. - * @example - * - * _.isArguments(function() { return arguments; }()); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ - var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { - return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && - !propertyIsEnumerable.call(value, 'callee'); - }; + // Result Attributes + clause_results: [ClauseResultSchema], + statement_results: [StatementResultSchema], + population_relevance: Mixed, + episode_results: Mixed, + observation_values: [Number], - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; + // This field is for application specific information only. If both Bonnie and + // Cypress use a common field, it should be made a field on this model, + // and not put into extendedData. + extendedData: { + type: Mixed, + default: {}, + }, - /** - * Checks if `value` is classified as an `ArrayBuffer` object. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. - * @example - * - * _.isArrayBuffer(new ArrayBuffer(2)); - * // => true - * - * _.isArrayBuffer(new Array(2)); - * // => false - */ - var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; + // Calculation State attributes + state: { + type: String, + enum: ['queued', 'running', 'complete', 'cancelled', 'failed'], + default: 'queued', + }, - /** - * Checks if `value` is array-like. A value is considered array-like if it's - * not a function and has a `value.length` that's an integer greater than or - * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. - * @example - * - * _.isArrayLike([1, 2, 3]); - * // => true - * - * _.isArrayLike(document.body.children); - * // => true - * - * _.isArrayLike('abc'); - * // => true - * - * _.isArrayLike(_.noop); - * // => false - */ - function isArrayLike(value) { - return value != null && isLength(value.length) && !isFunction(value); - } + // Relations to other model classes + // 'alias' field makes it so you can call obj.measure, and get the object referenced by measure_id + measure_id: { type: ObjectId, ref: 'Measure', alias: 'measure' }, + patient_id: { type: ObjectId, ref: 'Patient', alias: 'patient' }, - /** - * This method is like `_.isArrayLike` except that it also checks if `value` - * is an object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, - * else `false`. - * @example - * - * _.isArrayLikeObject([1, 2, 3]); - * // => true - * - * _.isArrayLikeObject(document.body.children); - * // => true - * - * _.isArrayLikeObject('abc'); - * // => false - * - * _.isArrayLikeObject(_.noop); - * // => false - */ - function isArrayLikeObject(value) { - return isObjectLike(value) && isArrayLike(value); + }, + // Options + { + timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps + } +); + +IndividualResultSchema.methods.clause_results_by_clause = function clause_results_by_clause() { + const clause_results_hash = {}; + this.clause_results.forEach((result) => { + if (!clause_results_hash[result.library_name]) { + clause_results_hash[result.library_name] = {}; } + clause_results_hash[result.library_name][result.localId] = result; + }); + return clause_results_hash; +}; - /** - * Checks if `value` is classified as a boolean primitive or object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. - * @example - * - * _.isBoolean(false); - * // => true - * - * _.isBoolean(null); - * // => false - */ - function isBoolean(value) { - return value === true || value === false || - (isObjectLike(value) && baseGetTag(value) == boolTag); +IndividualResultSchema.methods.statement_results_by_statement = function statement_results_by_statement() { + const statement_results_hash = {}; + this.statement_results.forEach((result) => { + if (!statement_results_hash[result.library_name]) { + statement_results_hash[result.library_name] = {}; } + statement_results_hash[result.library_name][result.statement_name] = result; + }); + return statement_results_hash; +}; - /** - * Checks if `value` is a buffer. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. - * @example - * - * _.isBuffer(new Buffer(2)); - * // => true - * - * _.isBuffer(new Uint8Array(2)); - * // => false - */ - var isBuffer = nativeIsBuffer || stubFalse; +module.exports.IndividualResultSchema = IndividualResultSchema; +class IndividualResult extends mongoose.Document { + constructor(object) { + super(object, IndividualResultSchema); + } +} +module.exports.IndividualResult = IndividualResult; - /** - * Checks if `value` is classified as a `Date` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a date object, else `false`. - * @example - * - * _.isDate(new Date); - * // => true - * - * _.isDate('Mon April 23 2012'); - * // => false - */ - var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; +},{"./ClauseResult":186,"./StatementResult":194,"mongoose/browser":226}],189:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DataElementSchema = require('../basetypes/DataElement').DataElementSchema(); +const AllDataElements = require('../AllDataElements'); +const { CQLLibrarySchema } = require('./CQLLibrary'); +const { PopulationSetSchema } = require('./PopulationSet'); - /** - * Checks if `value` is likely a DOM element. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. - * @example - * - * _.isElement(document.body); - * // => true - * - * _.isElement(''); - * // => false - */ - function isElement(value) { - return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); - } +const [Number, String, Boolean, Mixed, ObjectId, Date] = [ + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, + mongoose.Schema.Types.Boolean, + mongoose.Schema.Types.Mixed, + mongoose.Schema.Types.ObjectId, + mongoose.Schema.Types.Date, +]; - /** - * Checks if `value` is an empty object, collection, map, or set. - * - * Objects are considered empty if they have no own enumerable string keyed - * properties. - * - * Array-like values such as `arguments` objects, arrays, buffers, strings, or - * jQuery-like collections are considered empty if they have a `length` of `0`. - * Similarly, maps and sets are considered empty if they have a `size` of `0`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is empty, else `false`. - * @example - * - * _.isEmpty(null); - * // => true - * - * _.isEmpty(true); - * // => true - * - * _.isEmpty(1); - * // => true - * - * _.isEmpty([1, 2, 3]); - * // => false - * - * _.isEmpty({ 'a': 1 }); - * // => false - */ - function isEmpty(value) { - if (value == null) { - return true; - } - if (isArrayLike(value) && - (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || - isBuffer(value) || isTypedArray(value) || isArguments(value))) { - return !value.length; - } - var tag = getTag(value); - if (tag == mapTag || tag == setTag) { - return !value.size; - } - if (isPrototype(value)) { - return !baseKeys(value).length; - } - for (var key in value) { - if (hasOwnProperty.call(value, key)) { - return false; - } - } - return true; - } +const MeasureSchema = new mongoose.Schema( + { + // A version-specific UUID for the measure + hqmf_id: String, + // A version-neutral UUID for the measure + hqmf_set_id: String, + // A Semantic Version-compliant string (e.g. "2.3.4") for the measure + hqmf_version_number: String, + // A CMS-style string (e.g. "CMS2v4") for the measure + cms_id: String, + title: String, + description: String, - /** - * Performs a deep comparison between two values to determine if they are - * equivalent. - * - * **Note:** This method supports comparing arrays, array buffers, booleans, - * date objects, error objects, maps, numbers, `Object` objects, regexes, - * sets, strings, symbols, and typed arrays. `Object` objects are compared - * by their own, not inherited, enumerable properties. Functions and DOM - * nodes are compared by strict equality, i.e. `===`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.isEqual(object, other); - * // => true - * - * object === other; - * // => false - */ - function isEqual(value, other) { - return baseIsEqual(value, other); - } + // Composite/component measure fields + composite: { + type: Boolean, + default: false, + }, + component: { + type: Boolean, + default: false, + }, + component_hqmf_set_ids: [String], + composite_hqmf_set_id: String, - /** - * This method is like `_.isEqual` except that it accepts `customizer` which - * is invoked to compare values. If `customizer` returns `undefined`, comparisons - * are handled by the method instead. The `customizer` is invoked with up to - * six arguments: (objValue, othValue [, index|key, object, other, stack]). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * function isGreeting(value) { - * return /^h(?:i|ello)$/.test(value); - * } - * - * function customizer(objValue, othValue) { - * if (isGreeting(objValue) && isGreeting(othValue)) { - * return true; - * } - * } - * - * var array = ['hello', 'goodbye']; - * var other = ['hi', 'goodbye']; - * - * _.isEqualWith(array, other, customizer); - * // => true - */ - function isEqualWith(value, other, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - var result = customizer ? customizer(value, other) : undefined; - return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result; - } + // Measure type variables + measure_scoring: { + type: String, + enum: ['PROPORTION', 'RATIO', 'CONTINUOUS_VARIABLE', 'COHORT'], + default: 'PROPORTION', + }, + calculation_method: { + type: String, + enum: ['PATIENT', 'EPISODE_OF_CARE'], + default: 'PATIENT', + }, + calculate_sdes: Boolean, - /** - * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, - * `SyntaxError`, `TypeError`, or `URIError` object. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an error object, else `false`. - * @example - * - * _.isError(new Error); - * // => true - * - * _.isError(Error); - * // => false - */ - function isError(value) { - if (!isObjectLike(value)) { - return false; - } - var tag = baseGetTag(value); - return tag == errorTag || tag == domExcTag || - (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); - } + // ELM/CQL Measure-logic related data encapsulated in CQLLibrarySchema + // Field name changed from 'cql' to 'cql_libraries' because the semantics of + // embeds_many: cqls (on the Ruby side) sounded weird, + // and we wanted to keep the API consistent + cql_libraries: [CQLLibrarySchema], + main_cql_library: String, - /** - * Checks if `value` is a finite primitive number. - * - * **Note:** This method is based on - * [`Number.isFinite`](https://mdn.io/Number/isFinite). - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. - * @example - * - * _.isFinite(3); - * // => true - * - * _.isFinite(Number.MIN_VALUE); - * // => true - * - * _.isFinite(Infinity); - * // => false - * - * _.isFinite('3'); - * // => false - */ - function isFinite(value) { - return typeof value == 'number' && nativeIsFinite(value); - } + // HQMF/Tacoma-specific Measure-logic related data + population_criteria: Mixed, + source_data_criteria: [], + measure_period: Mixed, + measure_attributes: [], - /** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a function, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ - function isFunction(value) { - if (!isObject(value)) { - return false; - } - // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 9 which returns 'object' for typed arrays and other constructors. - var tag = baseGetTag(value); - return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; - } + population_sets: [PopulationSetSchema], - /** - * Checks if `value` is an integer. - * - * **Note:** This method is based on - * [`Number.isInteger`](https://mdn.io/Number/isInteger). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an integer, else `false`. - * @example - * - * _.isInteger(3); - * // => true - * - * _.isInteger(Number.MIN_VALUE); - * // => false - * - * _.isInteger(Infinity); - * // => false - * - * _.isInteger('3'); - * // => false - */ - function isInteger(value) { - return typeof value == 'number' && value == toInteger(value); - } + // Relations to other model classes + bundle: { type: ObjectId, ref: 'Bundle' }, // Cypress-specific, until we migrate the Bundle into cqm-models + package: { type: ObjectId, ref: 'MeasurePackage' }, // Bonnie-specific + patients: [{ type: ObjectId, ref: 'Patient', index: true }], - /** - * Checks if `value` is a valid array-like length. - * - * **Note:** This method is loosely based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. - * @example - * - * _.isLength(3); - * // => true - * - * _.isLength(Number.MIN_VALUE); - * // => false - * - * _.isLength(Infinity); - * // => false - * - * _.isLength('3'); - * // => false - */ - function isLength(value) { - return typeof value == 'number' && - value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; - } + value_sets: [{ type: ObjectId, ref: 'ValueSet' }], + }, + // Options + { + timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, // These are the Mongoid conventions for timestamps + } +); - /** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ - function isObject(value) { - var type = typeof value; - return value != null && (type == 'object' || type == 'function'); - } +// After initialization of a Measure model, initialize every individual data element +// to its respective Mongoose Model +MeasureSchema.methods.initializeDataElements = function initializeDataElements() { + let typeStripped; + const sourceDataCriteriaInit = []; + this.source_data_criteria.forEach((element) => { + typeStripped = element._type.replace(/QDM::/, ''); + sourceDataCriteriaInit.push(new AllDataElements[typeStripped](element)); + }); + this.set('source_data_criteria', sourceDataCriteriaInit); +}; + +MeasureSchema.methods.all_stratifications = function all_stratifications() { + return this.population_sets.flatMap(ps => ps.stratifications); +}; + +module.exports.MeasureSchema = MeasureSchema; +class Measure extends mongoose.Document { + constructor(object) { + super(object, MeasureSchema); + this.initializeDataElements(); + } +} +module.exports.Measure = Measure; + +},{"../AllDataElements":111,"../basetypes/Code":178,"../basetypes/DataElement":179,"../basetypes/Interval":181,"../basetypes/Quantity":183,"./CQLLibrary":184,"./PopulationSet":192,"mongoose/browser":226}],190:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); + +// using mBuffer to not conflict with system Buffer +const [mBuffer, ObjectId] = [ + mongoose.Schema.Types.Buffer, + mongoose.Schema.Types.ObjectId, +]; + +const MeasurePackageSchema = new mongoose.Schema( + { + file: mBuffer, + measure: { type: ObjectId, ref: 'Measure' }, + }, + // Options + { + timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, + } +); + +module.exports.MeasurePackageSchema = MeasurePackageSchema; +class MeasurePackage extends mongoose.Document { + constructor(object) { + super(object, MeasurePackageSchema); + } +} +module.exports.MeasurePackage = MeasurePackage; - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return value != null && typeof value == 'object'; - } +},{"mongoose/browser":226}],191:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const Code = require('../basetypes/Code'); +const Interval = require('../basetypes/Interval'); +const Quantity = require('../basetypes/Quantity'); +const DateTime = require('../basetypes/DateTime'); +const { QDMPatientSchema, QDMPatient } = require('../QDMPatient'); +const { ProviderSchema } = require('./Provider'); - /** - * Checks if `value` is classified as a `Map` object. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a map, else `false`. - * @example - * - * _.isMap(new Map); - * // => true - * - * _.isMap(new WeakMap); - * // => false - */ - var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; +const [Schema, Number, String, Mixed] = [ + mongoose.Schema, + mongoose.Schema.Types.Number, + mongoose.Schema.Types.String, + mongoose.Schema.Types.Mixed, +]; - /** - * Performs a partial deep comparison between `object` and `source` to - * determine if `object` contains equivalent property values. - * - * **Note:** This method is equivalent to `_.matches` when `source` is - * partially applied. - * - * Partial comparisons will match empty array and empty object `source` - * values against any array or object value, respectively. See `_.isEqual` - * for a list of supported value comparisons. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {Object} object The object to inspect. - * @param {Object} source The object of property values to match. - * @returns {boolean} Returns `true` if `object` is a match, else `false`. - * @example - * - * var object = { 'a': 1, 'b': 2 }; - * - * _.isMatch(object, { 'b': 2 }); - * // => true - * - * _.isMatch(object, { 'b': 1 }); - * // => false - */ - function isMatch(object, source) { - return object === source || baseIsMatch(object, source, getMatchData(source)); - } +const PatientSchema = new Schema({ - /** - * This method is like `_.isMatch` except that it accepts `customizer` which - * is invoked to compare values. If `customizer` returns `undefined`, comparisons - * are handled by the method instead. The `customizer` is invoked with five - * arguments: (objValue, srcValue, index|key, object, source). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {Object} object The object to inspect. - * @param {Object} source The object of property values to match. - * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if `object` is a match, else `false`. - * @example - * - * function isGreeting(value) { - * return /^h(?:i|ello)$/.test(value); - * } - * - * function customizer(objValue, srcValue) { - * if (isGreeting(objValue) && isGreeting(srcValue)) { - * return true; - * } - * } - * - * var object = { 'greeting': 'hello' }; - * var source = { 'greeting': 'hi' }; - * - * _.isMatchWith(object, source, customizer); - * // => true - */ - function isMatchWith(object, source, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - return baseIsMatch(object, source, getMatchData(source), customizer); - } + givenNames: [String], + familyName: String, + bundleId: String, + expectedValues: [], + notes: String, + qdmPatient: QDMPatientSchema, + providers: [ProviderSchema], + measure_ids: [String], - /** - * Checks if `value` is `NaN`. - * - * **Note:** This method is based on - * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as - * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for - * `undefined` and other non-number values. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. - * @example - * - * _.isNaN(NaN); - * // => true - * - * _.isNaN(new Number(NaN)); - * // => true - * - * isNaN(undefined); - * // => true - * - * _.isNaN(undefined); - * // => false - */ - function isNaN(value) { - // An `NaN` primitive is the only value that is not equal to itself. - // Perform the `toStringTag` check first to avoid errors with some - // ActiveX objects in IE. - return isNumber(value) && value != +value; - } +}, { id: false }); - /** - * Checks if `value` is a pristine native function. - * - * **Note:** This method can't reliably detect native functions in the presence - * of the core-js package because core-js circumvents this kind of detection. - * Despite multiple requests, the core-js maintainer has made it clear: any - * attempt to fix the detection will be obstructed. As a result, we're left - * with little choice but to throw an error. Unfortunately, this also affects - * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), - * which rely on core-js. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, - * else `false`. - * @example - * - * _.isNative(Array.prototype.push); - * // => true - * - * _.isNative(_); - * // => false - */ - function isNative(value) { - if (isMaskable(value)) { - throw new Error(CORE_ERROR_TEXT); - } - return baseIsNative(value); +module.exports.PatientSchema = PatientSchema; +class Patient extends mongoose.Document { + constructor(object) { + super(object, PatientSchema); + if (this.qdmPatient) { + this.qdmPatient = new QDMPatient(this.qdmPatient.toJSON()); } + } +} +module.exports.Patient = Patient; - /** - * Checks if `value` is `null`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `null`, else `false`. - * @example - * - * _.isNull(null); - * // => true - * - * _.isNull(void 0); - * // => false - */ - function isNull(value) { - return value === null; - } +},{"../QDMPatient":158,"../basetypes/Code":178,"../basetypes/DateTime":180,"../basetypes/Interval":181,"../basetypes/Quantity":183,"./Provider":193,"mongoose/browser":226}],192:[function(require,module,exports){ +/* eslint-disable no-unused-vars, no-param-reassign */ +const mongoose = require('mongoose/browser'); +const { StatementReferenceSchema } = require('./CQLStatementDependency'); - /** - * Checks if `value` is `null` or `undefined`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is nullish, else `false`. - * @example - * - * _.isNil(null); - * // => true - * - * _.isNil(void 0); - * // => true - * - * _.isNil(NaN); - * // => false - */ - function isNil(value) { - return value == null; - } +const [Mixed] = [ + mongoose.Schema.Types.Mixed, +]; - /** - * Checks if `value` is classified as a `Number` primitive or object. - * - * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are - * classified as numbers, use the `_.isFinite` method. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a number, else `false`. - * @example - * - * _.isNumber(3); - * // => true - * - * _.isNumber(Number.MIN_VALUE); - * // => true - * - * _.isNumber(Infinity); - * // => true - * - * _.isNumber('3'); - * // => false - */ - function isNumber(value) { - return typeof value == 'number' || - (isObjectLike(value) && baseGetTag(value) == numberTag); - } +// TODO: figure out if there is a better way to handle inheritance like mongoid. +// _type is how mongoid stores the specific type of the embedded document. +const PopulationMapSchema = new mongoose.Schema({ + _type: String, + IPP: StatementReferenceSchema, + DENOM: StatementReferenceSchema, + NUMER: StatementReferenceSchema, + NUMEX: StatementReferenceSchema, + DENEX: StatementReferenceSchema, + DENEXCEP: StatementReferenceSchema, + MSRPOPL: StatementReferenceSchema, + MSRPOPLEX: StatementReferenceSchema, + // STRAT is only here so cqm-execution can handle stratification results compliation with the current approach. + STRAT: StatementReferenceSchema, +}); - /** - * Checks if `value` is a plain object, that is, an object created by the - * `Object` constructor or one with a `[[Prototype]]` of `null`. - * - * @static - * @memberOf _ - * @since 0.8.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * _.isPlainObject(new Foo); - * // => false - * - * _.isPlainObject([1, 2, 3]); - * // => false - * - * _.isPlainObject({ 'x': 0, 'y': 0 }); - * // => true - * - * _.isPlainObject(Object.create(null)); - * // => true - */ - function isPlainObject(value) { - if (!isObjectLike(value) || baseGetTag(value) != objectTag) { - return false; - } - var proto = getPrototype(value); - if (proto === null) { - return true; - } - var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; - return typeof Ctor == 'function' && Ctor instanceof Ctor && - funcToString.call(Ctor) == objectCtorString; - } +if (!PopulationMapSchema.options.toObject) PopulationMapSchema.options.toObject = {}; +PopulationMapSchema.options.toObject.transform = function transform(doc, ret, options) { + // remove the _id and _type of every document before returning the result + delete ret._id; + delete ret._type; + return ret; +}; - /** - * Checks if `value` is classified as a `RegExp` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. - * @example - * - * _.isRegExp(/abc/); - * // => true - * - * _.isRegExp('/abc/'); - * // => false - */ - var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; - /** - * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 - * double precision number which isn't the result of a rounded unsafe integer. - * - * **Note:** This method is based on - * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. - * @example - * - * _.isSafeInteger(3); - * // => true - * - * _.isSafeInteger(Number.MIN_VALUE); - * // => false - * - * _.isSafeInteger(Infinity); - * // => false - * - * _.isSafeInteger('3'); - * // => false - */ - function isSafeInteger(value) { - return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; - } +const StratificationSchema = new mongoose.Schema({ + title: String, + stratification_id: String, + hqmf_id: String, + statement: StatementReferenceSchema, +}); - /** - * Checks if `value` is classified as a `Set` object. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a set, else `false`. - * @example - * - * _.isSet(new Set); - * // => true - * - * _.isSet(new WeakSet); - * // => false - */ - var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; +const ObservationSchema = new mongoose.Schema({ + title: String, + observation_function: StatementReferenceSchema, + observation_parameter: StatementReferenceSchema, + aggregation_type: String, + hqmf_id: String, +}); - /** - * Checks if `value` is classified as a `String` primitive or object. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a string, else `false`. - * @example - * - * _.isString('abc'); - * // => true - * - * _.isString(1); - * // => false - */ - function isString(value) { - return typeof value == 'string' || - (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); - } +const PopulationSetSchema = new mongoose.Schema({ + title: String, + population_set_id: String, + populations: PopulationMapSchema, + stratifications: [StratificationSchema], + supplemental_data_elements: [StatementReferenceSchema], + observations: [ObservationSchema], +}); - /** - * Checks if `value` is classified as a `Symbol` primitive or object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. - * @example - * - * _.isSymbol(Symbol.iterator); - * // => true - * - * _.isSymbol('abc'); - * // => false - */ - function isSymbol(value) { - return typeof value == 'symbol' || - (isObjectLike(value) && baseGetTag(value) == symbolTag); - } +module.exports.StratificationSchema = StratificationSchema; +class Stratification extends mongoose.Document { + constructor(object) { + super(object, StratificationSchema); + } +} +module.exports.Stratification = Stratification; - /** - * Checks if `value` is classified as a typed array. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - * @example - * - * _.isTypedArray(new Uint8Array); - * // => true - * - * _.isTypedArray([]); - * // => false - */ - var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; +module.exports.ObservationSchema = ObservationSchema; +class Observation extends mongoose.Document { + constructor(object) { + super(object, ObservationSchema); + } +} +module.exports.Observation = Observation; - /** - * Checks if `value` is `undefined`. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. - * @example - * - * _.isUndefined(void 0); - * // => true - * - * _.isUndefined(null); - * // => false - */ - function isUndefined(value) { - return value === undefined; - } +module.exports.PopulationMapSchema = PopulationMapSchema; +class PopulationMap extends mongoose.Document { + constructor(object) { + super(object, PopulationMapSchema); + } +} +module.exports.PopulationMap = PopulationMap; - /** - * Checks if `value` is classified as a `WeakMap` object. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. - * @example - * - * _.isWeakMap(new WeakMap); - * // => true - * - * _.isWeakMap(new Map); - * // => false - */ - function isWeakMap(value) { - return isObjectLike(value) && getTag(value) == weakMapTag; - } +module.exports.PopulationSetSchema = PopulationSetSchema; +class PopulationSet extends mongoose.Document { + constructor(object) { + super(object, PopulationSetSchema); + } +} +module.exports.PopulationSet = PopulationSet; - /** - * Checks if `value` is classified as a `WeakSet` object. - * - * @static - * @memberOf _ - * @since 4.3.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. - * @example - * - * _.isWeakSet(new WeakSet); - * // => true - * - * _.isWeakSet(new Set); - * // => false - */ - function isWeakSet(value) { - return isObjectLike(value) && baseGetTag(value) == weakSetTag; - } +},{"./CQLStatementDependency":185,"mongoose/browser":226}],193:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Checks if `value` is less than `other`. - * - * @static - * @memberOf _ - * @since 3.9.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than `other`, - * else `false`. - * @see _.gt - * @example - * - * _.lt(1, 3); - * // => true - * - * _.lt(3, 3); - * // => false - * - * _.lt(3, 1); - * // => false - */ - var lt = createRelationalOperation(baseLt); +const [Schema, String, Boolean] = [ + mongoose.Schema, + mongoose.Schema.Types.String, + mongoose.Schema.Types.Boolean, +]; - /** - * Checks if `value` is less than or equal to `other`. - * - * @static - * @memberOf _ - * @since 3.9.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than or equal to - * `other`, else `false`. - * @see _.gte - * @example - * - * _.lte(1, 3); - * // => true - * - * _.lte(3, 3); - * // => true - * - * _.lte(3, 1); - * // => false - */ - var lte = createRelationalOperation(function(value, other) { - return value <= other; - }); +const AddressSchema = new mongoose.Schema({ + street: [String], + city: String, + state: String, + zip: String, + country: String, + use: String, +}); - /** - * Converts `value` to an array. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Lang - * @param {*} value The value to convert. - * @returns {Array} Returns the converted array. - * @example - * - * _.toArray({ 'a': 1, 'b': 2 }); - * // => [1, 2] - * - * _.toArray('abc'); - * // => ['a', 'b', 'c'] - * - * _.toArray(1); - * // => [] - * - * _.toArray(null); - * // => [] - */ - function toArray(value) { - if (!value) { - return []; - } - if (isArrayLike(value)) { - return isString(value) ? stringToArray(value) : copyArray(value); - } - if (symIterator && value[symIterator]) { - return iteratorToArray(value[symIterator]()); - } - var tag = getTag(value), - func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); +const TelecomSchema = new mongoose.Schema({ + use: String, + value: String, + preferred: Boolean, +}); - return func(value); - } +const ProviderSchema = new Schema({ + _type: { type: String, default: 'Provider' }, - /** - * Converts `value` to a finite number. - * - * @static - * @memberOf _ - * @since 4.12.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {number} Returns the converted number. - * @example - * - * _.toFinite(3.2); - * // => 3.2 - * - * _.toFinite(Number.MIN_VALUE); - * // => 5e-324 - * - * _.toFinite(Infinity); - * // => 1.7976931348623157e+308 - * - * _.toFinite('3.2'); - * // => 3.2 - */ - function toFinite(value) { - if (!value) { - return value === 0 ? value : 0; - } - value = toNumber(value); - if (value === INFINITY || value === -INFINITY) { - var sign = (value < 0 ? -1 : 1); - return sign * MAX_INTEGER; - } - return value === value ? value : 0; - } + givenNames: [String], + familyName: String, + specialty: String, + title: String, + addresses: [AddressSchema], + telecoms: [TelecomSchema], - /** - * Converts `value` to an integer. - * - * **Note:** This method is loosely based on - * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - * @example - * - * _.toInteger(3.2); - * // => 3 - * - * _.toInteger(Number.MIN_VALUE); - * // => 0 - * - * _.toInteger(Infinity); - * // => 1.7976931348623157e+308 - * - * _.toInteger('3.2'); - * // => 3 - */ - function toInteger(value) { - var result = toFinite(value), - remainder = result % 1; +}, { id: false }); - return result === result ? (remainder ? result - remainder : result) : 0; - } +module.exports.ProviderSchema = ProviderSchema; +class Provider extends mongoose.Document { + constructor(object) { + super(object, ProviderSchema); + } +} +module.exports.Provider = Provider; - /** - * Converts `value` to an integer suitable for use as the length of an - * array-like object. - * - * **Note:** This method is based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - * @example - * - * _.toLength(3.2); - * // => 3 - * - * _.toLength(Number.MIN_VALUE); - * // => 0 - * - * _.toLength(Infinity); - * // => 4294967295 - * - * _.toLength('3.2'); - * // => 3 - */ - function toLength(value) { - return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; - } +},{"mongoose/browser":226}],194:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); - /** - * Converts `value` to a number. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to process. - * @returns {number} Returns the number. - * @example - * - * _.toNumber(3.2); - * // => 3.2 - * - * _.toNumber(Number.MIN_VALUE); - * // => 5e-324 - * - * _.toNumber(Infinity); - * // => Infinity - * - * _.toNumber('3.2'); - * // => 3.2 - */ - function toNumber(value) { - if (typeof value == 'number') { - return value; - } - if (isSymbol(value)) { - return NAN; - } - if (isObject(value)) { - var other = typeof value.valueOf == 'function' ? value.valueOf() : value; - value = isObject(other) ? (other + '') : other; - } - if (typeof value != 'string') { - return value === 0 ? value : +value; - } - value = baseTrim(value); - var isBinary = reIsBinary.test(value); - return (isBinary || reIsOctal.test(value)) - ? freeParseInt(value.slice(2), isBinary ? 2 : 8) - : (reIsBadHex.test(value) ? NAN : +value); - } +const [String, Mixed] = [ + mongoose.Schema.Types.String, + mongoose.Schema.Types.Mixed, +]; - /** - * Converts `value` to a plain object flattening inherited enumerable string - * keyed properties of `value` to own properties of the plain object. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {Object} Returns the converted plain object. - * @example - * - * function Foo() { - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.assign({ 'a': 1 }, new Foo); - * // => { 'a': 1, 'b': 2 } - * - * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); - * // => { 'a': 1, 'b': 2, 'c': 3 } - */ - function toPlainObject(value) { - return copyObject(value, keysIn(value)); - } +const StatementResultSchema = mongoose.Schema({ + // Library the statement this result is for is in + library_name: String, + // Statement this result is for is in + statement_name: String, + // Result, processed for display, of the statement this result is for + pretty: String, + // Final, processed result of raw calculation + final: String, + // Raw result of clause calculation + raw: Mixed, + /* + * 'NA' - Not applicable. This statement is not relevant to any population calculation in this population_set. Common + * for unused library statements or statements only used for other population sets. + * + * 'FALSE' - This statement is not relevant to any of this patient's population inclusion calculations. + * + * 'TRUE' - This statement is relevant for one or more of the population inclusion calculations. + */ + relevance: { + type: String, + enum: ['NA', 'TRUE', 'FALSE'], + default: 'NA', + }, +}); - /** - * Converts `value` to a safe integer. A safe integer can be compared and - * represented correctly. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - * @example - * - * _.toSafeInteger(3.2); - * // => 3 - * - * _.toSafeInteger(Number.MIN_VALUE); - * // => 0 - * - * _.toSafeInteger(Infinity); - * // => 9007199254740991 - * - * _.toSafeInteger('3.2'); - * // => 3 - */ - function toSafeInteger(value) { - return value - ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) - : (value === 0 ? value : 0); - } - /** - * Converts `value` to a string. An empty string is returned for `null` - * and `undefined` values. The sign of `-0` is preserved. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - * @example - * - * _.toString(null); - * // => '' - * - * _.toString(-0); - * // => '-0' - * - * _.toString([1, 2, 3]); - * // => '1,2,3' - */ - function toString(value) { - return value == null ? '' : baseToString(value); - } +module.exports.StatementResultSchema = StatementResultSchema; +class StatementResult extends mongoose.Document { + constructor(object) { + super(object, StatementResultSchema); + } +} +module.exports.StatementResult = StatementResult; - /*------------------------------------------------------------------------*/ +},{"mongoose/browser":226}],195:[function(require,module,exports){ +const mongoose = require('mongoose/browser'); +const Concept = require('./Concept.js'); - /** - * Assigns own enumerable string keyed properties of source objects to the - * destination object. Source objects are applied from left to right. - * Subsequent sources overwrite property assignments of previous sources. - * - * **Note:** This method mutates `object` and is loosely based on - * [`Object.assign`](https://mdn.io/Object/assign). - * - * @static - * @memberOf _ - * @since 0.10.0 - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.assignIn - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * function Bar() { - * this.c = 3; - * } - * - * Foo.prototype.b = 2; - * Bar.prototype.d = 4; - * - * _.assign({ 'a': 0 }, new Foo, new Bar); - * // => { 'a': 1, 'c': 3 } - */ - var assign = createAssigner(function(object, source) { - if (isPrototype(source) || isArrayLike(source)) { - copyObject(source, keys(source), object); - return; - } - for (var key in source) { - if (hasOwnProperty.call(source, key)) { - assignValue(object, key, source[key]); - } - } - }); +const [String] = [mongoose.Schema.Types.String]; + +const ValueSetSchema = new mongoose.Schema( + { + oid: String, + display_name: String, + version: String, + + concepts: [Concept.ConceptSchema], + }, + // Options + { + timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }, + } +); - /** - * This method is like `_.assign` except that it iterates over own and - * inherited source properties. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias extend - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.assign - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * function Bar() { - * this.c = 3; - * } - * - * Foo.prototype.b = 2; - * Bar.prototype.d = 4; - * - * _.assignIn({ 'a': 0 }, new Foo, new Bar); - * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } - */ - var assignIn = createAssigner(function(object, source) { - copyObject(source, keysIn(source), object); - }); +module.exports.ValueSetSchema = ValueSetSchema; +class ValueSet extends mongoose.Document { + constructor(object) { + super(object, ValueSetSchema); + } +} +module.exports.ValueSet = ValueSet; - /** - * This method is like `_.assignIn` except that it accepts `customizer` - * which is invoked to produce the assigned values. If `customizer` returns - * `undefined`, assignment is handled by the method instead. The `customizer` - * is invoked with five arguments: (objValue, srcValue, key, object, source). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias extendWith - * @category Object - * @param {Object} object The destination object. - * @param {...Object} sources The source objects. - * @param {Function} [customizer] The function to customize assigned values. - * @returns {Object} Returns `object`. - * @see _.assignWith - * @example - * - * function customizer(objValue, srcValue) { - * return _.isUndefined(objValue) ? srcValue : objValue; - * } - * - * var defaults = _.partialRight(_.assignInWith, customizer); - * - * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); - * // => { 'a': 1, 'b': 2 } - */ - var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObject(source, keysIn(source), object, customizer); - }); +},{"./Concept.js":187,"mongoose/browser":226}],196:[function(require,module,exports){ +module.exports = require('./AllDataElements.js'); +module.exports.CQL = require('cql-execution'); +module.exports.Result = require('./Result.js').Result; +module.exports.ResultSchema = require('./Result.js').ResultSchema; +module.exports.Measure = require('./cqm/Measure.js').Measure; +module.exports.MeasureSchema = require('./cqm/Measure.js').MeasureSchema; +module.exports.MeasurePackage = require('./cqm/MeasurePackage.js').MeasurePackage; +module.exports.MeasurePackageSchema = require('./cqm/MeasurePackage.js').MeasurePackageSchema; +module.exports.Patient = require('./cqm/Patient.js').Patient; +module.exports.PatientSchema = require('./cqm/Patient.js').PatientSchema; +module.exports.Provider = require('./cqm/Provider.js').Provider; +module.exports.ProviderSchema = require('./cqm/Provider.js').ProviderSchema; +module.exports.StatementDependency = require('./cqm/CQLStatementDependency.js').StatementDependency; +module.exports.StatementDependencySchema = require('./cqm/CQLStatementDependency.js').StatementDependencySchema; +module.exports.PopulationSet = require('./cqm/PopulationSet.js').PopulationSet; +module.exports.PopulationSetSchema = require('./cqm/PopulationSet.js').PopulationSetSchema; +module.exports.CQLLibrary = require('./cqm/CQLLibrary.js').CQLLibrary; +module.exports.CQLLibrarySchema = require('./cqm/CQLLibrary.js').CQLLibrarySchema; +module.exports.ValueSet = require('./cqm/ValueSet.js').ValueSet; +module.exports.ValueSetSchema = require('./cqm/ValueSet.js').ValueSetSchema; +module.exports.Concept = require('./cqm/Concept.js').Concept; +module.exports.ConceptSchema = require('./cqm/Concept.js').ConceptSchema; +module.exports.IndividualResult = require('./cqm/IndividualResult.js').IndividualResult; +module.exports.IndividualResultSchema = require('./cqm/IndividualResult.js').IndividualResultSchema; +module.exports.ClauseResult = require('./cqm/ClauseResult.js').ClauseResult; +module.exports.ClauseResultSchema = require('./cqm/ClauseResult.js').ClauseResultSchema; +module.exports.StatementResult = require('./cqm/StatementResult.js').StatementResult; +module.exports.StatementResultSchema = require('./cqm/StatementResult.js').StatementResultchema; - /** - * This method is like `_.assign` except that it accepts `customizer` - * which is invoked to produce the assigned values. If `customizer` returns - * `undefined`, assignment is handled by the method instead. The `customizer` - * is invoked with five arguments: (objValue, srcValue, key, object, source). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The destination object. - * @param {...Object} sources The source objects. - * @param {Function} [customizer] The function to customize assigned values. - * @returns {Object} Returns `object`. - * @see _.assignInWith - * @example - * - * function customizer(objValue, srcValue) { - * return _.isUndefined(objValue) ? srcValue : objValue; - * } - * - * var defaults = _.partialRight(_.assignWith, customizer); - * - * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); - * // => { 'a': 1, 'b': 2 } - */ - var assignWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObject(source, keys(source), object, customizer); - }); +},{"./AllDataElements.js":111,"./Result.js":160,"./cqm/CQLLibrary.js":184,"./cqm/CQLStatementDependency.js":185,"./cqm/ClauseResult.js":186,"./cqm/Concept.js":187,"./cqm/IndividualResult.js":188,"./cqm/Measure.js":189,"./cqm/MeasurePackage.js":190,"./cqm/Patient.js":191,"./cqm/PopulationSet.js":192,"./cqm/Provider.js":193,"./cqm/StatementResult.js":194,"./cqm/ValueSet.js":195,"cql-execution":41}],197:[function(require,module,exports){ +'use strict'; - /** - * Creates an array of values corresponding to `paths` of `object`. - * - * @static - * @memberOf _ - * @since 1.0.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {...(string|string[])} [paths] The property paths to pick. - * @returns {Array} Returns the picked values. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; - * - * _.at(object, ['a[0].b.c', 'a[1]']); - * // => [3, 4] - */ - var at = flatRest(baseAt); +var hasPropertyDescriptors = require('has-property-descriptors')(); - /** - * Creates an object that inherits from the `prototype` object. If a - * `properties` object is given, its own enumerable string keyed properties - * are assigned to the created object. - * - * @static - * @memberOf _ - * @since 2.3.0 - * @category Object - * @param {Object} prototype The object to inherit from. - * @param {Object} [properties] The properties to assign to the object. - * @returns {Object} Returns the new object. - * @example - * - * function Shape() { - * this.x = 0; - * this.y = 0; - * } - * - * function Circle() { - * Shape.call(this); - * } - * - * Circle.prototype = _.create(Shape.prototype, { - * 'constructor': Circle - * }); - * - * var circle = new Circle; - * circle instanceof Circle; - * // => true - * - * circle instanceof Shape; - * // => true - */ - function create(prototype, properties) { - var result = baseCreate(prototype); - return properties == null ? result : baseAssign(result, properties); - } +var GetIntrinsic = require('get-intrinsic'); - /** - * Assigns own and inherited enumerable string keyed properties of source - * objects to the destination object for all destination properties that - * resolve to `undefined`. Source objects are applied from left to right. - * Once a property is set, additional values of the same property are ignored. - * - * **Note:** This method mutates `object`. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.defaultsDeep - * @example - * - * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); - * // => { 'a': 1, 'b': 2 } - */ - var defaults = baseRest(function(object, sources) { - object = Object(object); +var $defineProperty = hasPropertyDescriptors && GetIntrinsic('%Object.defineProperty%', true); +if ($defineProperty) { + try { + $defineProperty({}, 'a', { value: 1 }); + } catch (e) { + // IE 8 has a broken defineProperty + $defineProperty = false; + } +} - var index = -1; - var length = sources.length; - var guard = length > 2 ? sources[2] : undefined; +var $SyntaxError = GetIntrinsic('%SyntaxError%'); +var $TypeError = GetIntrinsic('%TypeError%'); - if (guard && isIterateeCall(sources[0], sources[1], guard)) { - length = 1; - } +var gopd = require('gopd'); - while (++index < length) { - var source = sources[index]; - var props = keysIn(source); - var propsIndex = -1; - var propsLength = props.length; +/** @type {(obj: Record, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void} */ +module.exports = function defineDataProperty( + obj, + property, + value +) { + if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { + throw new $TypeError('`obj` must be an object or a function`'); + } + if (typeof property !== 'string' && typeof property !== 'symbol') { + throw new $TypeError('`property` must be a string or a symbol`'); + } + if (arguments.length > 3 && typeof arguments[3] !== 'boolean' && arguments[3] !== null) { + throw new $TypeError('`nonEnumerable`, if provided, must be a boolean or null'); + } + if (arguments.length > 4 && typeof arguments[4] !== 'boolean' && arguments[4] !== null) { + throw new $TypeError('`nonWritable`, if provided, must be a boolean or null'); + } + if (arguments.length > 5 && typeof arguments[5] !== 'boolean' && arguments[5] !== null) { + throw new $TypeError('`nonConfigurable`, if provided, must be a boolean or null'); + } + if (arguments.length > 6 && typeof arguments[6] !== 'boolean') { + throw new $TypeError('`loose`, if provided, must be a boolean'); + } - while (++propsIndex < propsLength) { - var key = props[propsIndex]; - var value = object[key]; + var nonEnumerable = arguments.length > 3 ? arguments[3] : null; + var nonWritable = arguments.length > 4 ? arguments[4] : null; + var nonConfigurable = arguments.length > 5 ? arguments[5] : null; + var loose = arguments.length > 6 ? arguments[6] : false; - if (value === undefined || - (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { - object[key] = source[key]; - } - } - } + /* @type {false | TypedPropertyDescriptor} */ + var desc = !!gopd && gopd(obj, property); - return object; - }); + if ($defineProperty) { + $defineProperty(obj, property, { + configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable, + enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable, + value: value, + writable: nonWritable === null && desc ? desc.writable : !nonWritable + }); + } else if (loose || (!nonEnumerable && !nonWritable && !nonConfigurable)) { + // must fall back to [[Set]], and was not explicitly asked to make non-enumerable, non-writable, or non-configurable + obj[property] = value; // eslint-disable-line no-param-reassign + } else { + throw new $SyntaxError('This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.'); + } +}; - /** - * This method is like `_.defaults` except that it recursively assigns - * default properties. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 3.10.0 - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.defaults - * @example - * - * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); - * // => { 'a': { 'b': 2, 'c': 3 } } - */ - var defaultsDeep = baseRest(function(args) { - args.push(undefined, customDefaultsMerge); - return apply(mergeWith, undefined, args); - }); +},{"get-intrinsic":202,"gopd":205,"has-property-descriptors":207}],198:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - /** - * This method is like `_.find` except that it returns the key of the first - * element `predicate` returns truthy for instead of the element itself. - * - * @static - * @memberOf _ - * @since 1.1.0 - * @category Object - * @param {Object} object The object to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, - * else `undefined`. - * @example - * - * var users = { - * 'barney': { 'age': 36, 'active': true }, - * 'fred': { 'age': 40, 'active': false }, - * 'pebbles': { 'age': 1, 'active': true } - * }; - * - * _.findKey(users, function(o) { return o.age < 40; }); - * // => 'barney' (iteration order is not guaranteed) - * - * // The `_.matches` iteratee shorthand. - * _.findKey(users, { 'age': 1, 'active': true }); - * // => 'pebbles' - * - * // The `_.matchesProperty` iteratee shorthand. - * _.findKey(users, ['active', false]); - * // => 'fred' - * - * // The `_.property` iteratee shorthand. - * _.findKey(users, 'active'); - * // => 'barney' - */ - function findKey(object, predicate) { - return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); - } +'use strict'; - /** - * This method is like `_.findKey` except that it iterates over elements of - * a collection in the opposite order. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Object - * @param {Object} object The object to inspect. - * @param {Function} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, - * else `undefined`. - * @example - * - * var users = { - * 'barney': { 'age': 36, 'active': true }, - * 'fred': { 'age': 40, 'active': false }, - * 'pebbles': { 'age': 1, 'active': true } - * }; - * - * _.findLastKey(users, function(o) { return o.age < 40; }); - * // => returns 'pebbles' assuming `_.findKey` returns 'barney' - * - * // The `_.matches` iteratee shorthand. - * _.findLastKey(users, { 'age': 36, 'active': true }); - * // => 'barney' - * - * // The `_.matchesProperty` iteratee shorthand. - * _.findLastKey(users, ['active', false]); - * // => 'fred' - * - * // The `_.property` iteratee shorthand. - * _.findLastKey(users, 'active'); - * // => 'pebbles' - */ - function findLastKey(object, predicate) { - return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); - } +var R = typeof Reflect === 'object' ? Reflect : null +var ReflectApply = R && typeof R.apply === 'function' + ? R.apply + : function ReflectApply(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + } - /** - * Iterates over own and inherited enumerable string keyed properties of an - * object and invokes `iteratee` for each property. The iteratee is invoked - * with three arguments: (value, key, object). Iteratee functions may exit - * iteration early by explicitly returning `false`. - * - * @static - * @memberOf _ - * @since 0.3.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns `object`. - * @see _.forInRight - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.forIn(new Foo, function(value, key) { - * console.log(key); - * }); - * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). - */ - function forIn(object, iteratee) { - return object == null - ? object - : baseFor(object, getIteratee(iteratee, 3), keysIn); - } +var ReflectOwnKeys +if (R && typeof R.ownKeys === 'function') { + ReflectOwnKeys = R.ownKeys +} else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target) + .concat(Object.getOwnPropertySymbols(target)); + }; +} else { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target); + }; +} - /** - * This method is like `_.forIn` except that it iterates over properties of - * `object` in the opposite order. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns `object`. - * @see _.forIn - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.forInRight(new Foo, function(value, key) { - * console.log(key); - * }); - * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. - */ - function forInRight(object, iteratee) { - return object == null - ? object - : baseForRight(object, getIteratee(iteratee, 3), keysIn); - } +function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); +} + +var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) { + return value !== value; +} + +function EventEmitter() { + EventEmitter.init.call(this); +} +module.exports = EventEmitter; +module.exports.once = once; - /** - * Iterates over own enumerable string keyed properties of an object and - * invokes `iteratee` for each property. The iteratee is invoked with three - * arguments: (value, key, object). Iteratee functions may exit iteration - * early by explicitly returning `false`. - * - * @static - * @memberOf _ - * @since 0.3.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns `object`. - * @see _.forOwnRight - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.forOwn(new Foo, function(value, key) { - * console.log(key); - * }); - * // => Logs 'a' then 'b' (iteration order is not guaranteed). - */ - function forOwn(object, iteratee) { - return object && baseForOwn(object, getIteratee(iteratee, 3)); - } +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; - /** - * This method is like `_.forOwn` except that it iterates over properties of - * `object` in the opposite order. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns `object`. - * @see _.forOwn - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.forOwnRight(new Foo, function(value, key) { - * console.log(key); - * }); - * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. - */ - function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, getIteratee(iteratee, 3)); - } +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._eventsCount = 0; +EventEmitter.prototype._maxListeners = undefined; - /** - * Creates an array of function property names from own enumerable properties - * of `object`. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to inspect. - * @returns {Array} Returns the function names. - * @see _.functionsIn - * @example - * - * function Foo() { - * this.a = _.constant('a'); - * this.b = _.constant('b'); - * } - * - * Foo.prototype.c = _.constant('c'); - * - * _.functions(new Foo); - * // => ['a', 'b'] - */ - function functions(object) { - return object == null ? [] : baseFunctions(object, keys(object)); - } +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +var defaultMaxListeners = 10; - /** - * Creates an array of function property names from own and inherited - * enumerable properties of `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to inspect. - * @returns {Array} Returns the function names. - * @see _.functions - * @example - * - * function Foo() { - * this.a = _.constant('a'); - * this.b = _.constant('b'); - * } - * - * Foo.prototype.c = _.constant('c'); - * - * _.functionsIn(new Foo); - * // => ['a', 'b', 'c'] - */ - function functionsIn(object) { - return object == null ? [] : baseFunctions(object, keysIn(object)); - } +function checkListener(listener) { + if (typeof listener !== 'function') { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } +} - /** - * Gets the value at `path` of `object`. If the resolved value is - * `undefined`, the `defaultValue` is returned in its place. - * - * @static - * @memberOf _ - * @since 3.7.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @param {*} [defaultValue] The value returned for `undefined` resolved values. - * @returns {*} Returns the resolved value. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }] }; - * - * _.get(object, 'a[0].b.c'); - * // => 3 - * - * _.get(object, ['a', '0', 'b', 'c']); - * // => 3 - * - * _.get(object, 'a.b.c', 'default'); - * // => 'default' - */ - function get(object, path, defaultValue) { - var result = object == null ? undefined : baseGet(object, path); - return result === undefined ? defaultValue : result; +Object.defineProperty(EventEmitter, 'defaultMaxListeners', { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.'); } + defaultMaxListeners = arg; + } +}); - /** - * Checks if `path` is a direct property of `object`. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - * @example - * - * var object = { 'a': { 'b': 2 } }; - * var other = _.create({ 'a': _.create({ 'b': 2 }) }); - * - * _.has(object, 'a'); - * // => true - * - * _.has(object, 'a.b'); - * // => true - * - * _.has(object, ['a', 'b']); - * // => true - * - * _.has(other, 'a'); - * // => false - */ - function has(object, path) { - return object != null && hasPath(object, path, baseHas); - } +EventEmitter.init = function() { - /** - * Checks if `path` is a direct or inherited property of `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - * @example - * - * var object = _.create({ 'a': _.create({ 'b': 2 }) }); - * - * _.hasIn(object, 'a'); - * // => true - * - * _.hasIn(object, 'a.b'); - * // => true - * - * _.hasIn(object, ['a', 'b']); - * // => true - * - * _.hasIn(object, 'b'); - * // => false - */ - function hasIn(object, path) { - return object != null && hasPath(object, path, baseHasIn); + if (this._events === undefined || + this._events === Object.getPrototypeOf(this)._events) { + this._events = Object.create(null); + this._eventsCount = 0; + } + + this._maxListeners = this._maxListeners || undefined; +}; + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.'); + } + this._maxListeners = n; + return this; +}; + +function _getMaxListeners(that) { + if (that._maxListeners === undefined) + return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); +}; + +EventEmitter.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = (type === 'error'); + + var events = this._events; + if (events !== undefined) + doError = (doError && events.error === undefined); + else if (!doError) + return false; + + // If there is no 'error' event listener then throw. + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + // Note: The comments on the `throw` lines are intentional, they show + // up in Node's output if this results in an unhandled exception. + throw er; // Unhandled 'error' event } + // At least give some kind of context to the user + var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : '')); + err.context = er; + throw err; // Unhandled 'error' event + } - /** - * Creates an object composed of the inverted keys and values of `object`. - * If `object` contains duplicate values, subsequent values overwrite - * property assignments of previous values. - * - * @static - * @memberOf _ - * @since 0.7.0 - * @category Object - * @param {Object} object The object to invert. - * @returns {Object} Returns the new inverted object. - * @example - * - * var object = { 'a': 1, 'b': 2, 'c': 1 }; - * - * _.invert(object); - * // => { '1': 'c', '2': 'b' } - */ - var invert = createInverter(function(result, value, key) { - if (value != null && - typeof value.toString != 'function') { - value = nativeObjectToString.call(value); - } + var handler = events[type]; - result[value] = key; - }, constant(identity)); + if (handler === undefined) + return false; - /** - * This method is like `_.invert` except that the inverted object is generated - * from the results of running each element of `object` thru `iteratee`. The - * corresponding inverted value of each inverted key is an array of keys - * responsible for generating the inverted value. The iteratee is invoked - * with one argument: (value). - * - * @static - * @memberOf _ - * @since 4.1.0 - * @category Object - * @param {Object} object The object to invert. - * @param {Function} [iteratee=_.identity] The iteratee invoked per element. - * @returns {Object} Returns the new inverted object. - * @example - * - * var object = { 'a': 1, 'b': 2, 'c': 1 }; - * - * _.invertBy(object); - * // => { '1': ['a', 'c'], '2': ['b'] } - * - * _.invertBy(object, function(value) { - * return 'group' + value; - * }); - * // => { 'group1': ['a', 'c'], 'group2': ['b'] } - */ - var invertBy = createInverter(function(result, value, key) { - if (value != null && - typeof value.toString != 'function') { - value = nativeObjectToString.call(value); - } + if (typeof handler === 'function') { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } - if (hasOwnProperty.call(result, value)) { - result[value].push(key); - } else { - result[value] = [key]; - } - }, getIteratee); + return true; +}; - /** - * Invokes the method at `path` of `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path of the method to invoke. - * @param {...*} [args] The arguments to invoke the method with. - * @returns {*} Returns the result of the invoked method. - * @example - * - * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; - * - * _.invoke(object, 'a[0].b.c.slice', 1, 3); - * // => [2, 3] - */ - var invoke = baseRest(baseInvoke); +function _addListener(target, type, listener, prepend) { + var m; + var events; + var existing; - /** - * Creates an array of the own enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. See the - * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * for more details. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keys(new Foo); - * // => ['a', 'b'] (iteration order is not guaranteed) - * - * _.keys('hi'); - * // => ['0', '1'] - */ - function keys(object) { - return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); + checkListener(listener); + + events = target._events; + if (events === undefined) { + events = target._events = Object.create(null); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener !== undefined) { + target.emit('newListener', type, + listener.listener ? listener.listener : listener); + + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; } + existing = events[type]; + } - /** - * Creates an array of the own and inherited enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keysIn(new Foo); - * // => ['a', 'b', 'c'] (iteration order is not guaranteed) - */ - function keysIn(object) { - return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); + if (existing === undefined) { + // Optimize the case of one listener. Don't need the extra array object. + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === 'function') { + // Adding the second element, need to change to array. + existing = events[type] = + prepend ? [listener, existing] : [existing, listener]; + // If we've already got an array, just append. + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); } - /** - * The opposite of `_.mapValues`; this method creates an object with the - * same values as `object` and keys generated by running each own enumerable - * string keyed property of `object` thru `iteratee`. The iteratee is invoked - * with three arguments: (value, key, object). - * - * @static - * @memberOf _ - * @since 3.8.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns the new mapped object. - * @see _.mapValues - * @example - * - * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { - * return key + value; - * }); - * // => { 'a1': 1, 'b2': 2 } - */ - function mapKeys(object, iteratee) { - var result = {}; - iteratee = getIteratee(iteratee, 3); + // Check for listener leak + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + // No error code for this since it is a Warning + // eslint-disable-next-line no-restricted-syntax + var w = new Error('Possible EventEmitter memory leak detected. ' + + existing.length + ' ' + String(type) + ' listeners ' + + 'added. Use emitter.setMaxListeners() to ' + + 'increase limit'); + w.name = 'MaxListenersExceededWarning'; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + + return target; +} + +EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; - baseForOwn(object, function(value, key, object) { - baseAssignValue(result, iteratee(value, key, object), value); - }); - return result; - } +EventEmitter.prototype.prependListener = + function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; - /** - * Creates an object with the same keys as `object` and values generated - * by running each own enumerable string keyed property of `object` thru - * `iteratee`. The iteratee is invoked with three arguments: - * (value, key, object). - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns the new mapped object. - * @see _.mapKeys - * @example - * - * var users = { - * 'fred': { 'user': 'fred', 'age': 40 }, - * 'pebbles': { 'user': 'pebbles', 'age': 1 } - * }; - * - * _.mapValues(users, function(o) { return o.age; }); - * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) - * - * // The `_.property` iteratee shorthand. - * _.mapValues(users, 'age'); - * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) - */ - function mapValues(object, iteratee) { - var result = {}; - iteratee = getIteratee(iteratee, 3); +function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } +} - baseForOwn(object, function(value, key, object) { - baseAssignValue(result, key, iteratee(value, key, object)); - }); - return result; - } +function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; +} - /** - * This method is like `_.assign` except that it recursively merges own and - * inherited enumerable string keyed properties of source objects into the - * destination object. Source properties that resolve to `undefined` are - * skipped if a destination value exists. Array and plain object properties - * are merged recursively. Other objects and value types are overridden by - * assignment. Source objects are applied from left to right. Subsequent - * sources overwrite property assignments of previous sources. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 0.5.0 - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @example - * - * var object = { - * 'a': [{ 'b': 2 }, { 'd': 4 }] - * }; - * - * var other = { - * 'a': [{ 'c': 3 }, { 'e': 5 }] - * }; - * - * _.merge(object, other); - * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } - */ - var merge = createAssigner(function(object, source, srcIndex) { - baseMerge(object, source, srcIndex); - }); +EventEmitter.prototype.once = function once(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; +}; - /** - * This method is like `_.merge` except that it accepts `customizer` which - * is invoked to produce the merged values of the destination and source - * properties. If `customizer` returns `undefined`, merging is handled by the - * method instead. The `customizer` is invoked with six arguments: - * (objValue, srcValue, key, object, source, stack). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The destination object. - * @param {...Object} sources The source objects. - * @param {Function} customizer The function to customize assigned values. - * @returns {Object} Returns `object`. - * @example - * - * function customizer(objValue, srcValue) { - * if (_.isArray(objValue)) { - * return objValue.concat(srcValue); - * } - * } - * - * var object = { 'a': [1], 'b': [2] }; - * var other = { 'a': [3], 'b': [4] }; - * - * _.mergeWith(object, other, customizer); - * // => { 'a': [1, 3], 'b': [2, 4] } - */ - var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { - baseMerge(object, source, srcIndex, customizer); - }); +EventEmitter.prototype.prependOnceListener = + function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; - /** - * The opposite of `_.pick`; this method creates an object composed of the - * own and inherited enumerable property paths of `object` that are not omitted. - * - * **Note:** This method is considerably slower than `_.pick`. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The source object. - * @param {...(string|string[])} [paths] The property paths to omit. - * @returns {Object} Returns the new object. - * @example - * - * var object = { 'a': 1, 'b': '2', 'c': 3 }; - * - * _.omit(object, ['a', 'c']); - * // => { 'b': '2' } - */ - var omit = flatRest(function(object, paths) { - var result = {}; - if (object == null) { - return result; - } - var isDeep = false; - paths = arrayMap(paths, function(path) { - path = castPath(path, object); - isDeep || (isDeep = path.length > 1); - return path; - }); - copyObject(object, getAllKeysIn(object), result); - if (isDeep) { - result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); - } - var length = paths.length; - while (length--) { - baseUnset(result, paths[length]); - } - return result; - }); +// Emits a 'removeListener' event if and only if the listener was removed. +EventEmitter.prototype.removeListener = + function removeListener(type, listener) { + var list, events, position, i, originalListener; - /** - * The opposite of `_.pickBy`; this method creates an object composed of - * the own and inherited enumerable string keyed properties of `object` that - * `predicate` doesn't return truthy for. The predicate is invoked with two - * arguments: (value, key). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The source object. - * @param {Function} [predicate=_.identity] The function invoked per property. - * @returns {Object} Returns the new object. - * @example - * - * var object = { 'a': 1, 'b': '2', 'c': 3 }; - * - * _.omitBy(object, _.isNumber); - * // => { 'b': '2' } - */ - function omitBy(object, predicate) { - return pickBy(object, negate(getIteratee(predicate))); - } + checkListener(listener); - /** - * Creates an object composed of the picked `object` properties. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The source object. - * @param {...(string|string[])} [paths] The property paths to pick. - * @returns {Object} Returns the new object. - * @example - * - * var object = { 'a': 1, 'b': '2', 'c': 3 }; - * - * _.pick(object, ['a', 'c']); - * // => { 'a': 1, 'c': 3 } - */ - var pick = flatRest(function(object, paths) { - return object == null ? {} : basePick(object, paths); - }); + events = this._events; + if (events === undefined) + return this; - /** - * Creates an object composed of the `object` properties `predicate` returns - * truthy for. The predicate is invoked with two arguments: (value, key). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The source object. - * @param {Function} [predicate=_.identity] The function invoked per property. - * @returns {Object} Returns the new object. - * @example - * - * var object = { 'a': 1, 'b': '2', 'c': 3 }; - * - * _.pickBy(object, _.isNumber); - * // => { 'a': 1, 'c': 3 } - */ - function pickBy(object, predicate) { - if (object == null) { - return {}; - } - var props = arrayMap(getAllKeysIn(object), function(prop) { - return [prop]; - }); - predicate = getIteratee(predicate); - return basePickBy(object, props, function(value, path) { - return predicate(value, path[0]); - }); - } + list = events[type]; + if (list === undefined) + return this; - /** - * This method is like `_.get` except that if the resolved value is a - * function it's invoked with the `this` binding of its parent object and - * its result is returned. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to resolve. - * @param {*} [defaultValue] The value returned for `undefined` resolved values. - * @returns {*} Returns the resolved value. - * @example - * - * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; - * - * _.result(object, 'a[0].b.c1'); - * // => 3 - * - * _.result(object, 'a[0].b.c2'); - * // => 4 - * - * _.result(object, 'a[0].b.c3', 'default'); - * // => 'default' - * - * _.result(object, 'a[0].b.c3', _.constant('default')); - * // => 'default' - */ - function result(object, path, defaultValue) { - path = castPath(path, object); + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = Object.create(null); + else { + delete events[type]; + if (events.removeListener) + this.emit('removeListener', type, list.listener || listener); + } + } else if (typeof list !== 'function') { + position = -1; - var index = -1, - length = path.length; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } - // Ensure the loop is entered when path is empty. - if (!length) { - length = 1; - object = undefined; - } - while (++index < length) { - var value = object == null ? undefined : object[toKey(path[index])]; - if (value === undefined) { - index = length; - value = defaultValue; + if (position < 0) + return this; + + if (position === 0) + list.shift(); + else { + spliceOne(list, position); } - object = isFunction(value) ? value.call(object) : value; - } - return object; - } - /** - * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, - * it's created. Arrays are created for missing index properties while objects - * are created for all other missing properties. Use `_.setWith` to customize - * `path` creation. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 3.7.0 - * @category Object - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to set. - * @param {*} value The value to set. - * @returns {Object} Returns `object`. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }] }; - * - * _.set(object, 'a[0].b.c', 4); - * console.log(object.a[0].b.c); - * // => 4 - * - * _.set(object, ['x', '0', 'y', 'z'], 5); - * console.log(object.x[0].y.z); - * // => 5 - */ - function set(object, path, value) { - return object == null ? object : baseSet(object, path, value); - } + if (list.length === 1) + events[type] = list[0]; - /** - * This method is like `_.set` except that it accepts `customizer` which is - * invoked to produce the objects of `path`. If `customizer` returns `undefined` - * path creation is handled by the method instead. The `customizer` is invoked - * with three arguments: (nsValue, key, nsObject). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to set. - * @param {*} value The value to set. - * @param {Function} [customizer] The function to customize assigned values. - * @returns {Object} Returns `object`. - * @example - * - * var object = {}; - * - * _.setWith(object, '[0][1]', 'a', Object); - * // => { '0': { '1': 'a' } } - */ - function setWith(object, path, value, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - return object == null ? object : baseSet(object, path, value, customizer); - } + if (events.removeListener !== undefined) + this.emit('removeListener', type, originalListener || listener); + } - /** - * Creates an array of own enumerable string keyed-value pairs for `object` - * which can be consumed by `_.fromPairs`. If `object` is a map or set, its - * entries are returned. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias entries - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the key-value pairs. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.toPairs(new Foo); - * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) - */ - var toPairs = createToPairs(keys); + return this; + }; - /** - * Creates an array of own and inherited enumerable string keyed-value pairs - * for `object` which can be consumed by `_.fromPairs`. If `object` is a map - * or set, its entries are returned. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias entriesIn - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the key-value pairs. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.toPairsIn(new Foo); - * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) - */ - var toPairsIn = createToPairs(keysIn); +EventEmitter.prototype.off = EventEmitter.prototype.removeListener; - /** - * An alternative to `_.reduce`; this method transforms `object` to a new - * `accumulator` object which is the result of running each of its own - * enumerable string keyed properties thru `iteratee`, with each invocation - * potentially mutating the `accumulator` object. If `accumulator` is not - * provided, a new object with the same `[[Prototype]]` will be used. The - * iteratee is invoked with four arguments: (accumulator, value, key, object). - * Iteratee functions may exit iteration early by explicitly returning `false`. - * - * @static - * @memberOf _ - * @since 1.3.0 - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @param {*} [accumulator] The custom accumulator value. - * @returns {*} Returns the accumulated value. - * @example - * - * _.transform([2, 3, 4], function(result, n) { - * result.push(n *= n); - * return n % 2 == 0; - * }, []); - * // => [4, 9] - * - * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { - * (result[value] || (result[value] = [])).push(key); - * }, {}); - * // => { '1': ['a', 'c'], '2': ['b'] } - */ - function transform(object, iteratee, accumulator) { - var isArr = isArray(object), - isArrLike = isArr || isBuffer(object) || isTypedArray(object); +EventEmitter.prototype.removeAllListeners = + function removeAllListeners(type) { + var listeners, events, i; - iteratee = getIteratee(iteratee, 4); - if (accumulator == null) { - var Ctor = object && object.constructor; - if (isArrLike) { - accumulator = isArr ? new Ctor : []; + events = this._events; + if (events === undefined) + return this; + + // not listening for removeListener, no need to emit + if (events.removeListener === undefined) { + if (arguments.length === 0) { + this._events = Object.create(null); + this._eventsCount = 0; + } else if (events[type] !== undefined) { + if (--this._eventsCount === 0) + this._events = Object.create(null); + else + delete events[type]; } - else if (isObject(object)) { - accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = Object.keys(events); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === 'removeListener') continue; + this.removeAllListeners(key); } - else { - accumulator = {}; + this.removeAllListeners('removeListener'); + this._events = Object.create(null); + this._eventsCount = 0; + return this; + } + + listeners = events[type]; + + if (typeof listeners === 'function') { + this.removeListener(type, listeners); + } else if (listeners !== undefined) { + // LIFO order + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); } } - (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) { - return iteratee(accumulator, value, index, object); - }); - return accumulator; - } - /** - * Removes the property at `path` of `object`. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to unset. - * @returns {boolean} Returns `true` if the property is deleted, else `false`. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 7 } }] }; - * _.unset(object, 'a[0].b.c'); - * // => true - * - * console.log(object); - * // => { 'a': [{ 'b': {} }] }; - * - * _.unset(object, ['a', '0', 'b', 'c']); - * // => true - * - * console.log(object); - * // => { 'a': [{ 'b': {} }] }; - */ - function unset(object, path) { - return object == null ? true : baseUnset(object, path); - } + return this; + }; - /** - * This method is like `_.set` except that accepts `updater` to produce the - * value to set. Use `_.updateWith` to customize `path` creation. The `updater` - * is invoked with one argument: (value). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.6.0 - * @category Object - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to set. - * @param {Function} updater The function to produce the updated value. - * @returns {Object} Returns `object`. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }] }; - * - * _.update(object, 'a[0].b.c', function(n) { return n * n; }); - * console.log(object.a[0].b.c); - * // => 9 - * - * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); - * console.log(object.x[0].y.z); - * // => 0 - */ - function update(object, path, updater) { - return object == null ? object : baseUpdate(object, path, castFunction(updater)); - } +function _listeners(target, type, unwrap) { + var events = target._events; - /** - * This method is like `_.update` except that it accepts `customizer` which is - * invoked to produce the objects of `path`. If `customizer` returns `undefined` - * path creation is handled by the method instead. The `customizer` is invoked - * with three arguments: (nsValue, key, nsObject). - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.6.0 - * @category Object - * @param {Object} object The object to modify. - * @param {Array|string} path The path of the property to set. - * @param {Function} updater The function to produce the updated value. - * @param {Function} [customizer] The function to customize assigned values. - * @returns {Object} Returns `object`. - * @example - * - * var object = {}; - * - * _.updateWith(object, '[0][1]', _.constant('a'), Object); - * // => { '0': { '1': 'a' } } - */ - function updateWith(object, path, updater, customizer) { - customizer = typeof customizer == 'function' ? customizer : undefined; - return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); - } + if (events === undefined) + return []; - /** - * Creates an array of the own enumerable string keyed property values of `object`. - * - * **Note:** Non-object values are coerced to objects. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property values. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.values(new Foo); - * // => [1, 2] (iteration order is not guaranteed) - * - * _.values('hi'); - * // => ['h', 'i'] - */ - function values(object) { - return object == null ? [] : baseValues(object, keys(object)); - } + var evlistener = events[type]; + if (evlistener === undefined) + return []; - /** - * Creates an array of the own and inherited enumerable string keyed property - * values of `object`. - * - * **Note:** Non-object values are coerced to objects. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property values. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.valuesIn(new Foo); - * // => [1, 2, 3] (iteration order is not guaranteed) - */ - function valuesIn(object) { - return object == null ? [] : baseValues(object, keysIn(object)); - } + if (typeof evlistener === 'function') + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; - /*------------------------------------------------------------------------*/ + return unwrap ? + unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); +} - /** - * Clamps `number` within the inclusive `lower` and `upper` bounds. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Number - * @param {number} number The number to clamp. - * @param {number} [lower] The lower bound. - * @param {number} upper The upper bound. - * @returns {number} Returns the clamped number. - * @example - * - * _.clamp(-10, -5, 5); - * // => -5 - * - * _.clamp(10, -5, 5); - * // => 5 - */ - function clamp(number, lower, upper) { - if (upper === undefined) { - upper = lower; - lower = undefined; - } - if (upper !== undefined) { - upper = toNumber(upper); - upper = upper === upper ? upper : 0; - } - if (lower !== undefined) { - lower = toNumber(lower); - lower = lower === lower ? lower : 0; - } - return baseClamp(toNumber(number), lower, upper); +EventEmitter.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); +}; + +EventEmitter.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); +}; + +EventEmitter.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === 'function') { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } +}; + +EventEmitter.prototype.listenerCount = listenerCount; +function listenerCount(type) { + var events = this._events; + + if (events !== undefined) { + var evlistener = events[type]; + + if (typeof evlistener === 'function') { + return 1; + } else if (evlistener !== undefined) { + return evlistener.length; } + } - /** - * Checks if `n` is between `start` and up to, but not including, `end`. If - * `end` is not specified, it's set to `start` with `start` then set to `0`. - * If `start` is greater than `end` the params are swapped to support - * negative ranges. - * - * @static - * @memberOf _ - * @since 3.3.0 - * @category Number - * @param {number} number The number to check. - * @param {number} [start=0] The start of the range. - * @param {number} end The end of the range. - * @returns {boolean} Returns `true` if `number` is in the range, else `false`. - * @see _.range, _.rangeRight - * @example - * - * _.inRange(3, 2, 4); - * // => true - * - * _.inRange(4, 8); - * // => true - * - * _.inRange(4, 2); - * // => false - * - * _.inRange(2, 2); - * // => false - * - * _.inRange(1.2, 2); - * // => true - * - * _.inRange(5.2, 4); - * // => false - * - * _.inRange(-3, -2, -6); - * // => true - */ - function inRange(number, start, end) { - start = toFinite(start); - if (end === undefined) { - end = start; - start = 0; - } else { - end = toFinite(end); - } - number = toNumber(number); - return baseInRange(number, start, end); + return 0; +} + +EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; +}; + +function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; +} + +function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); +} + +function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; +} + +function once(emitter, name) { + return new Promise(function (resolve, reject) { + function errorListener(err) { + emitter.removeListener(name, resolver); + reject(err); } - /** - * Produces a random number between the inclusive `lower` and `upper` bounds. - * If only one argument is provided a number between `0` and the given number - * is returned. If `floating` is `true`, or either `lower` or `upper` are - * floats, a floating-point number is returned instead of an integer. - * - * **Note:** JavaScript follows the IEEE-754 standard for resolving - * floating-point values which can produce unexpected results. - * - * @static - * @memberOf _ - * @since 0.7.0 - * @category Number - * @param {number} [lower=0] The lower bound. - * @param {number} [upper=1] The upper bound. - * @param {boolean} [floating] Specify returning a floating-point number. - * @returns {number} Returns the random number. - * @example - * - * _.random(0, 5); - * // => an integer between 0 and 5 - * - * _.random(5); - * // => also an integer between 0 and 5 - * - * _.random(5, true); - * // => a floating-point number between 0 and 5 - * - * _.random(1.2, 5.2); - * // => a floating-point number between 1.2 and 5.2 - */ - function random(lower, upper, floating) { - if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { - upper = floating = undefined; - } - if (floating === undefined) { - if (typeof upper == 'boolean') { - floating = upper; - upper = undefined; - } - else if (typeof lower == 'boolean') { - floating = lower; - lower = undefined; - } - } - if (lower === undefined && upper === undefined) { - lower = 0; - upper = 1; - } - else { - lower = toFinite(lower); - if (upper === undefined) { - upper = lower; - lower = 0; - } else { - upper = toFinite(upper); - } - } - if (lower > upper) { - var temp = lower; - lower = upper; - upper = temp; - } - if (floating || lower % 1 || upper % 1) { - var rand = nativeRandom(); - return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); + function resolver() { + if (typeof emitter.removeListener === 'function') { + emitter.removeListener('error', errorListener); } - return baseRandom(lower, upper); + resolve([].slice.call(arguments)); + }; + + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== 'error') { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); } + }); +} - /*------------------------------------------------------------------------*/ +function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === 'function') { + eventTargetAgnosticAddListener(emitter, 'error', handler, flags); + } +} - /** - * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the camel cased string. - * @example - * - * _.camelCase('Foo Bar'); - * // => 'fooBar' - * - * _.camelCase('--foo-bar--'); - * // => 'fooBar' - * - * _.camelCase('__FOO_BAR__'); - * // => 'fooBar' - */ - var camelCase = createCompounder(function(result, word, index) { - word = word.toLowerCase(); - return result + (index ? capitalize(word) : word); +function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === 'function') { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === 'function') { + // EventTarget does not have `error` event semantics like Node + // EventEmitters, we do not listen for `error` events here. + emitter.addEventListener(name, function wrapListener(arg) { + // IE does not have builtin `{ once: true }` support so we + // have to do it manually. + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } +} - /** - * Converts the first character of `string` to upper case and the remaining - * to lower case. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to capitalize. - * @returns {string} Returns the capitalized string. - * @example - * - * _.capitalize('FRED'); - * // => 'Fred' - */ - function capitalize(string) { - return upperFirst(toString(string).toLowerCase()); - } +},{}],199:[function(require,module,exports){ +'use strict'; - /** - * Deburrs `string` by converting - * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) - * letters to basic Latin letters and removing - * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to deburr. - * @returns {string} Returns the deburred string. - * @example - * - * _.deburr('déjà vu'); - * // => 'deja vu' - */ - function deburr(string) { - string = toString(string); - return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); +var isCallable = require('is-callable'); + +var toStr = Object.prototype.toString; +var hasOwnProperty = Object.prototype.hasOwnProperty; + +var forEachArray = function forEachArray(array, iterator, receiver) { + for (var i = 0, len = array.length; i < len; i++) { + if (hasOwnProperty.call(array, i)) { + if (receiver == null) { + iterator(array[i], i, array); + } else { + iterator.call(receiver, array[i], i, array); + } + } } +}; - /** - * Checks if `string` ends with the given target string. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to inspect. - * @param {string} [target] The string to search for. - * @param {number} [position=string.length] The position to search up to. - * @returns {boolean} Returns `true` if `string` ends with `target`, - * else `false`. - * @example - * - * _.endsWith('abc', 'c'); - * // => true - * - * _.endsWith('abc', 'b'); - * // => false - * - * _.endsWith('abc', 'b', 2); - * // => true - */ - function endsWith(string, target, position) { - string = toString(string); - target = baseToString(target); +var forEachString = function forEachString(string, iterator, receiver) { + for (var i = 0, len = string.length; i < len; i++) { + // no such thing as a sparse string. + if (receiver == null) { + iterator(string.charAt(i), i, string); + } else { + iterator.call(receiver, string.charAt(i), i, string); + } + } +}; - var length = string.length; - position = position === undefined - ? length - : baseClamp(toInteger(position), 0, length); +var forEachObject = function forEachObject(object, iterator, receiver) { + for (var k in object) { + if (hasOwnProperty.call(object, k)) { + if (receiver == null) { + iterator(object[k], k, object); + } else { + iterator.call(receiver, object[k], k, object); + } + } + } +}; - var end = position; - position -= target.length; - return position >= 0 && string.slice(position, end) == target; +var forEach = function forEach(list, iterator, thisArg) { + if (!isCallable(iterator)) { + throw new TypeError('iterator must be a function'); } - /** - * Converts the characters "&", "<", ">", '"', and "'" in `string` to their - * corresponding HTML entities. - * - * **Note:** No other characters are escaped. To escape additional - * characters use a third-party library like [_he_](https://mths.be/he). - * - * Though the ">" character is escaped for symmetry, characters like - * ">" and "/" don't need escaping in HTML and have no special meaning - * unless they're part of a tag or unquoted attribute value. See - * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) - * (under "semi-related fun fact") for more details. - * - * When working with HTML you should always - * [quote attribute values](http://wonko.com/post/html-escaping) to reduce - * XSS vectors. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category String - * @param {string} [string=''] The string to escape. - * @returns {string} Returns the escaped string. - * @example - * - * _.escape('fred, barney, & pebbles'); - * // => 'fred, barney, & pebbles' - */ - function escape(string) { - string = toString(string); - return (string && reHasUnescapedHtml.test(string)) - ? string.replace(reUnescapedHtml, escapeHtmlChar) - : string; + var receiver; + if (arguments.length >= 3) { + receiver = thisArg; } - /** - * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", - * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to escape. - * @returns {string} Returns the escaped string. - * @example - * - * _.escapeRegExp('[lodash](https://lodash.com/)'); - * // => '\[lodash\]\(https://lodash\.com/\)' - */ - function escapeRegExp(string) { - string = toString(string); - return (string && reHasRegExpChar.test(string)) - ? string.replace(reRegExpChar, '\\$&') - : string; + if (toStr.call(list) === '[object Array]') { + forEachArray(list, iterator, receiver); + } else if (typeof list === 'string') { + forEachString(list, iterator, receiver); + } else { + forEachObject(list, iterator, receiver); } +}; - /** - * Converts `string` to - * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the kebab cased string. - * @example - * - * _.kebabCase('Foo Bar'); - * // => 'foo-bar' - * - * _.kebabCase('fooBar'); - * // => 'foo-bar' - * - * _.kebabCase('__FOO_BAR__'); - * // => 'foo-bar' - */ - var kebabCase = createCompounder(function(result, word, index) { - return result + (index ? '-' : '') + word.toLowerCase(); - }); +module.exports = forEach; - /** - * Converts `string`, as space separated words, to lower case. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the lower cased string. - * @example - * - * _.lowerCase('--Foo-Bar--'); - * // => 'foo bar' - * - * _.lowerCase('fooBar'); - * // => 'foo bar' - * - * _.lowerCase('__FOO_BAR__'); - * // => 'foo bar' - */ - var lowerCase = createCompounder(function(result, word, index) { - return result + (index ? ' ' : '') + word.toLowerCase(); - }); +},{"is-callable":221}],200:[function(require,module,exports){ +'use strict'; - /** - * Converts the first character of `string` to lower case. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the converted string. - * @example - * - * _.lowerFirst('Fred'); - * // => 'fred' - * - * _.lowerFirst('FRED'); - * // => 'fRED' - */ - var lowerFirst = createCaseFirst('toLowerCase'); +/* eslint no-invalid-this: 1 */ - /** - * Pads `string` on the left and right sides if it's shorter than `length`. - * Padding characters are truncated if they can't be evenly divided by `length`. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to pad. - * @param {number} [length=0] The padding length. - * @param {string} [chars=' '] The string used as padding. - * @returns {string} Returns the padded string. - * @example - * - * _.pad('abc', 8); - * // => ' abc ' - * - * _.pad('abc', 8, '_-'); - * // => '_-abc_-_' - * - * _.pad('abc', 3); - * // => 'abc' - */ - function pad(string, length, chars) { - string = toString(string); - length = toInteger(length); +var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; +var slice = Array.prototype.slice; +var toStr = Object.prototype.toString; +var funcType = '[object Function]'; - var strLength = length ? stringSize(string) : 0; - if (!length || strLength >= length) { - return string; - } - var mid = (length - strLength) / 2; - return ( - createPadding(nativeFloor(mid), chars) + - string + - createPadding(nativeCeil(mid), chars) - ); +module.exports = function bind(that) { + var target = this; + if (typeof target !== 'function' || toStr.call(target) !== funcType) { + throw new TypeError(ERROR_MESSAGE + target); } + var args = slice.call(arguments, 1); - /** - * Pads `string` on the right side if it's shorter than `length`. Padding - * characters are truncated if they exceed `length`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to pad. - * @param {number} [length=0] The padding length. - * @param {string} [chars=' '] The string used as padding. - * @returns {string} Returns the padded string. - * @example - * - * _.padEnd('abc', 6); - * // => 'abc ' - * - * _.padEnd('abc', 6, '_-'); - * // => 'abc_-_' - * - * _.padEnd('abc', 3); - * // => 'abc' - */ - function padEnd(string, length, chars) { - string = toString(string); - length = toInteger(length); + var bound; + var binder = function () { + if (this instanceof bound) { + var result = target.apply( + this, + args.concat(slice.call(arguments)) + ); + if (Object(result) === result) { + return result; + } + return this; + } else { + return target.apply( + that, + args.concat(slice.call(arguments)) + ); + } + }; - var strLength = length ? stringSize(string) : 0; - return (length && strLength < length) - ? (string + createPadding(length - strLength, chars)) - : string; + var boundLength = Math.max(0, target.length - args.length); + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + boundArgs.push('$' + i); } - /** - * Pads `string` on the left side if it's shorter than `length`. Padding - * characters are truncated if they exceed `length`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to pad. - * @param {number} [length=0] The padding length. - * @param {string} [chars=' '] The string used as padding. - * @returns {string} Returns the padded string. - * @example - * - * _.padStart('abc', 6); - * // => ' abc' - * - * _.padStart('abc', 6, '_-'); - * // => '_-_abc' - * - * _.padStart('abc', 3); - * // => 'abc' - */ - function padStart(string, length, chars) { - string = toString(string); - length = toInteger(length); + bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder); - var strLength = length ? stringSize(string) : 0; - return (length && strLength < length) - ? (createPadding(length - strLength, chars) + string) - : string; + if (target.prototype) { + var Empty = function Empty() {}; + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + Empty.prototype = null; } - /** - * Converts `string` to an integer of the specified radix. If `radix` is - * `undefined` or `0`, a `radix` of `10` is used unless `value` is a - * hexadecimal, in which case a `radix` of `16` is used. - * - * **Note:** This method aligns with the - * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. - * - * @static - * @memberOf _ - * @since 1.1.0 - * @category String - * @param {string} string The string to convert. - * @param {number} [radix=10] The radix to interpret `value` by. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {number} Returns the converted integer. - * @example - * - * _.parseInt('08'); - * // => 8 - * - * _.map(['6', '08', '10'], _.parseInt); - * // => [6, 8, 10] - */ - function parseInt(string, radix, guard) { - if (guard || radix == null) { - radix = 0; - } else if (radix) { - radix = +radix; - } - return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); - } + return bound; +}; + +},{}],201:[function(require,module,exports){ +'use strict'; + +var implementation = require('./implementation'); + +module.exports = Function.prototype.bind || implementation; + +},{"./implementation":200}],202:[function(require,module,exports){ +'use strict'; + +var undefined; + +var $SyntaxError = SyntaxError; +var $Function = Function; +var $TypeError = TypeError; + +// eslint-disable-next-line consistent-return +var getEvalledConstructor = function (expressionSyntax) { + try { + return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); + } catch (e) {} +}; + +var $gOPD = Object.getOwnPropertyDescriptor; +if ($gOPD) { + try { + $gOPD({}, ''); + } catch (e) { + $gOPD = null; // this is IE 8, which has a broken gOPD + } +} + +var throwTypeError = function () { + throw new $TypeError(); +}; +var ThrowTypeError = $gOPD + ? (function () { + try { + // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties + arguments.callee; // IE 8 does not throw here + return throwTypeError; + } catch (calleeThrows) { + try { + // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') + return $gOPD(arguments, 'callee').get; + } catch (gOPDthrows) { + return throwTypeError; + } + } + }()) + : throwTypeError; + +var hasSymbols = require('has-symbols')(); +var hasProto = require('has-proto')(); + +var getProto = Object.getPrototypeOf || ( + hasProto + ? function (x) { return x.__proto__; } // eslint-disable-line no-proto + : null +); + +var needsEval = {}; + +var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined : getProto(Uint8Array); + +var INTRINSICS = { + '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, + '%Array%': Array, + '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, + '%ArrayIteratorPrototype%': hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined, + '%AsyncFromSyncIteratorPrototype%': undefined, + '%AsyncFunction%': needsEval, + '%AsyncGenerator%': needsEval, + '%AsyncGeneratorFunction%': needsEval, + '%AsyncIteratorPrototype%': needsEval, + '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, + '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, + '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array, + '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array, + '%Boolean%': Boolean, + '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, + '%Date%': Date, + '%decodeURI%': decodeURI, + '%decodeURIComponent%': decodeURIComponent, + '%encodeURI%': encodeURI, + '%encodeURIComponent%': encodeURIComponent, + '%Error%': Error, + '%eval%': eval, // eslint-disable-line no-eval + '%EvalError%': EvalError, + '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, + '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, + '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, + '%Function%': $Function, + '%GeneratorFunction%': needsEval, + '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, + '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, + '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, + '%isFinite%': isFinite, + '%isNaN%': isNaN, + '%IteratorPrototype%': hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined, + '%JSON%': typeof JSON === 'object' ? JSON : undefined, + '%Map%': typeof Map === 'undefined' ? undefined : Map, + '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Map()[Symbol.iterator]()), + '%Math%': Math, + '%Number%': Number, + '%Object%': Object, + '%parseFloat%': parseFloat, + '%parseInt%': parseInt, + '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, + '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, + '%RangeError%': RangeError, + '%ReferenceError%': ReferenceError, + '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, + '%RegExp%': RegExp, + '%Set%': typeof Set === 'undefined' ? undefined : Set, + '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Set()[Symbol.iterator]()), + '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, + '%String%': String, + '%StringIteratorPrototype%': hasSymbols && getProto ? getProto(''[Symbol.iterator]()) : undefined, + '%Symbol%': hasSymbols ? Symbol : undefined, + '%SyntaxError%': $SyntaxError, + '%ThrowTypeError%': ThrowTypeError, + '%TypedArray%': TypedArray, + '%TypeError%': $TypeError, + '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, + '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, + '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, + '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, + '%URIError%': URIError, + '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, + '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, + '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet +}; + +if (getProto) { + try { + null.error; // eslint-disable-line no-unused-expressions + } catch (e) { + // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 + var errorProto = getProto(getProto(e)); + INTRINSICS['%Error.prototype%'] = errorProto; + } +} + +var doEval = function doEval(name) { + var value; + if (name === '%AsyncFunction%') { + value = getEvalledConstructor('async function () {}'); + } else if (name === '%GeneratorFunction%') { + value = getEvalledConstructor('function* () {}'); + } else if (name === '%AsyncGeneratorFunction%') { + value = getEvalledConstructor('async function* () {}'); + } else if (name === '%AsyncGenerator%') { + var fn = doEval('%AsyncGeneratorFunction%'); + if (fn) { + value = fn.prototype; + } + } else if (name === '%AsyncIteratorPrototype%') { + var gen = doEval('%AsyncGenerator%'); + if (gen && getProto) { + value = getProto(gen.prototype); + } + } - /** - * Repeats the given string `n` times. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to repeat. - * @param {number} [n=1] The number of times to repeat the string. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {string} Returns the repeated string. - * @example - * - * _.repeat('*', 3); - * // => '***' - * - * _.repeat('abc', 2); - * // => 'abcabc' - * - * _.repeat('abc', 0); - * // => '' - */ - function repeat(string, n, guard) { - if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { - n = 1; - } else { - n = toInteger(n); - } - return baseRepeat(toString(string), n); - } + INTRINSICS[name] = value; - /** - * Replaces matches for `pattern` in `string` with `replacement`. - * - * **Note:** This method is based on - * [`String#replace`](https://mdn.io/String/replace). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to modify. - * @param {RegExp|string} pattern The pattern to replace. - * @param {Function|string} replacement The match replacement. - * @returns {string} Returns the modified string. - * @example - * - * _.replace('Hi Fred', 'Fred', 'Barney'); - * // => 'Hi Barney' - */ - function replace() { - var args = arguments, - string = toString(args[0]); + return value; +}; - return args.length < 3 ? string : string.replace(args[1], args[2]); - } +var LEGACY_ALIASES = { + '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], + '%ArrayPrototype%': ['Array', 'prototype'], + '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], + '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], + '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], + '%ArrayProto_values%': ['Array', 'prototype', 'values'], + '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], + '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], + '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], + '%BooleanPrototype%': ['Boolean', 'prototype'], + '%DataViewPrototype%': ['DataView', 'prototype'], + '%DatePrototype%': ['Date', 'prototype'], + '%ErrorPrototype%': ['Error', 'prototype'], + '%EvalErrorPrototype%': ['EvalError', 'prototype'], + '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], + '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], + '%FunctionPrototype%': ['Function', 'prototype'], + '%Generator%': ['GeneratorFunction', 'prototype'], + '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], + '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], + '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], + '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], + '%JSONParse%': ['JSON', 'parse'], + '%JSONStringify%': ['JSON', 'stringify'], + '%MapPrototype%': ['Map', 'prototype'], + '%NumberPrototype%': ['Number', 'prototype'], + '%ObjectPrototype%': ['Object', 'prototype'], + '%ObjProto_toString%': ['Object', 'prototype', 'toString'], + '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], + '%PromisePrototype%': ['Promise', 'prototype'], + '%PromiseProto_then%': ['Promise', 'prototype', 'then'], + '%Promise_all%': ['Promise', 'all'], + '%Promise_reject%': ['Promise', 'reject'], + '%Promise_resolve%': ['Promise', 'resolve'], + '%RangeErrorPrototype%': ['RangeError', 'prototype'], + '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], + '%RegExpPrototype%': ['RegExp', 'prototype'], + '%SetPrototype%': ['Set', 'prototype'], + '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], + '%StringPrototype%': ['String', 'prototype'], + '%SymbolPrototype%': ['Symbol', 'prototype'], + '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], + '%TypedArrayPrototype%': ['TypedArray', 'prototype'], + '%TypeErrorPrototype%': ['TypeError', 'prototype'], + '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], + '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], + '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], + '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], + '%URIErrorPrototype%': ['URIError', 'prototype'], + '%WeakMapPrototype%': ['WeakMap', 'prototype'], + '%WeakSetPrototype%': ['WeakSet', 'prototype'] +}; - /** - * Converts `string` to - * [snake case](https://en.wikipedia.org/wiki/Snake_case). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the snake cased string. - * @example - * - * _.snakeCase('Foo Bar'); - * // => 'foo_bar' - * - * _.snakeCase('fooBar'); - * // => 'foo_bar' - * - * _.snakeCase('--FOO-BAR--'); - * // => 'foo_bar' - */ - var snakeCase = createCompounder(function(result, word, index) { - return result + (index ? '_' : '') + word.toLowerCase(); - }); +var bind = require('function-bind'); +var hasOwn = require('hasown'); +var $concat = bind.call(Function.call, Array.prototype.concat); +var $spliceApply = bind.call(Function.apply, Array.prototype.splice); +var $replace = bind.call(Function.call, String.prototype.replace); +var $strSlice = bind.call(Function.call, String.prototype.slice); +var $exec = bind.call(Function.call, RegExp.prototype.exec); - /** - * Splits `string` by `separator`. - * - * **Note:** This method is based on - * [`String#split`](https://mdn.io/String/split). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to split. - * @param {RegExp|string} separator The separator pattern to split by. - * @param {number} [limit] The length to truncate results to. - * @returns {Array} Returns the string segments. - * @example - * - * _.split('a-b-c', '-', 2); - * // => ['a', 'b'] - */ - function split(string, separator, limit) { - if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { - separator = limit = undefined; - } - limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; - if (!limit) { - return []; - } - string = toString(string); - if (string && ( - typeof separator == 'string' || - (separator != null && !isRegExp(separator)) - )) { - separator = baseToString(separator); - if (!separator && hasUnicode(string)) { - return castSlice(stringToArray(string), 0, limit); - } - } - return string.split(separator, limit); - } +/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ +var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; +var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ +var stringToPath = function stringToPath(string) { + var first = $strSlice(string, 0, 1); + var last = $strSlice(string, -1); + if (first === '%' && last !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); + } else if (last === '%' && first !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); + } + var result = []; + $replace(string, rePropName, function (match, number, quote, subString) { + result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; + }); + return result; +}; +/* end adaptation */ - /** - * Converts `string` to - * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). - * - * @static - * @memberOf _ - * @since 3.1.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the start cased string. - * @example - * - * _.startCase('--foo-bar--'); - * // => 'Foo Bar' - * - * _.startCase('fooBar'); - * // => 'Foo Bar' - * - * _.startCase('__FOO_BAR__'); - * // => 'FOO BAR' - */ - var startCase = createCompounder(function(result, word, index) { - return result + (index ? ' ' : '') + upperFirst(word); - }); +var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { + var intrinsicName = name; + var alias; + if (hasOwn(LEGACY_ALIASES, intrinsicName)) { + alias = LEGACY_ALIASES[intrinsicName]; + intrinsicName = '%' + alias[0] + '%'; + } - /** - * Checks if `string` starts with the given target string. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to inspect. - * @param {string} [target] The string to search for. - * @param {number} [position=0] The position to search from. - * @returns {boolean} Returns `true` if `string` starts with `target`, - * else `false`. - * @example - * - * _.startsWith('abc', 'a'); - * // => true - * - * _.startsWith('abc', 'b'); - * // => false - * - * _.startsWith('abc', 'b', 1); - * // => true - */ - function startsWith(string, target, position) { - string = toString(string); - position = position == null - ? 0 - : baseClamp(toInteger(position), 0, string.length); + if (hasOwn(INTRINSICS, intrinsicName)) { + var value = INTRINSICS[intrinsicName]; + if (value === needsEval) { + value = doEval(intrinsicName); + } + if (typeof value === 'undefined' && !allowMissing) { + throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); + } - target = baseToString(target); - return string.slice(position, position + target.length) == target; - } + return { + alias: alias, + name: intrinsicName, + value: value + }; + } - /** - * Creates a compiled template function that can interpolate data properties - * in "interpolate" delimiters, HTML-escape interpolated data properties in - * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data - * properties may be accessed as free variables in the template. If a setting - * object is given, it takes precedence over `_.templateSettings` values. - * - * **Note:** In the development build `_.template` utilizes - * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) - * for easier debugging. - * - * For more information on precompiling templates see - * [lodash's custom builds documentation](https://lodash.com/custom-builds). - * - * For more information on Chrome extension sandboxes see - * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category String - * @param {string} [string=''] The template string. - * @param {Object} [options={}] The options object. - * @param {RegExp} [options.escape=_.templateSettings.escape] - * The HTML "escape" delimiter. - * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] - * The "evaluate" delimiter. - * @param {Object} [options.imports=_.templateSettings.imports] - * An object to import into the template as free variables. - * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] - * The "interpolate" delimiter. - * @param {string} [options.sourceURL='lodash.templateSources[n]'] - * The sourceURL of the compiled template. - * @param {string} [options.variable='obj'] - * The data object variable name. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Function} Returns the compiled template function. - * @example - * - * // Use the "interpolate" delimiter to create a compiled template. - * var compiled = _.template('hello <%= user %>!'); - * compiled({ 'user': 'fred' }); - * // => 'hello fred!' - * - * // Use the HTML "escape" delimiter to escape data property values. - * var compiled = _.template('<%- value %>'); - * compiled({ 'value': '