Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 89 additions & 8 deletions examples/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,12 @@ class Interval {
get isInterval() {
return true;
}
get isBoundlessInterval() {
return this.low == null && this.lowClosed && this.high == null && this.highClosed;
}
get isUnknownInterval() {
return this.low == null && !this.lowClosed && this.high == null && !this.highClosed;
}
get pointType() {
let pointType = null;
const point = this.low != null ? this.low : this.high;
Expand Down Expand Up @@ -1835,19 +1841,22 @@ class Interval {
if (this.high != null && typeof this.high.copy === 'function') {
newHigh = this.high.copy();
}
return new Interval(newLow, newHigh, this.lowClosed, this.highClosed);
return new Interval(newLow, newHigh, this.lowClosed, this.highClosed, this.defaultPointType);
}
contains(item, precision) {
// These first two checks ensure correct handling of edge case where an item equals the closed boundary
if (item != null && item.isInterval) {
throw new Error('Argument to contains must be a point');
}
if (this.isBoundlessInterval) {
return true;
}
// 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');
}
let lowFn;
if (this.lowClosed && this.low == null) {
lowFn = () => true;
Expand Down Expand Up @@ -1877,6 +1886,12 @@ class Interval {
return logic_1.ThreeValuedLogic.and(this.includes(other, precision), logic_1.ThreeValuedLogic.not(other.includes(this, precision)));
}
includes(other, precision) {
if (this.isBoundlessInterval) {
return true;
}
else if (other === null || other === void 0 ? void 0 : other.isBoundlessInterval) {
return this.isUnknownInterval ? null : false;
}
if (other == null || !other.isInterval) {
return this.contains(other, precision);
}
Expand All @@ -1894,6 +1909,9 @@ class Interval {
}
}
overlaps(item, precision) {
if (this.isBoundlessInterval || (item === null || item === void 0 ? void 0 : item.isBoundlessInterval)) {
return true;
}
const closed = this.toClosed();
const [low, high] = (() => {
if (item != null && item.isInterval) {
Expand All @@ -1907,19 +1925,37 @@ class Interval {
return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThanOrEquals(closed.high, low, precision));
}
overlapsAfter(item, precision) {
const closed = this.toClosed();
const high = item != null && item.isInterval ? item.toClosed().high : item;
if (this.isBoundlessInterval) {
return cmp.lessThan(high, (0, math_1.maxValueForInstance)(high), precision);
}
else if (item === null || item === void 0 ? void 0 : item.isBoundlessInterval) {
return false;
}
const closed = this.toClosed();
return logic_1.ThreeValuedLogic.and(cmp.lessThanOrEquals(closed.low, high, precision), cmp.greaterThan(closed.high, high, precision));
}
overlapsBefore(item, precision) {
const closed = this.toClosed();
const low = item != null && item.isInterval ? item.toClosed().low : item;
if (this.isBoundlessInterval) {
return cmp.greaterThan(low, (0, math_1.minValueForInstance)(low), precision);
}
else if (item === null || item === void 0 ? void 0 : item.isBoundlessInterval) {
return false;
}
const closed = this.toClosed();
return logic_1.ThreeValuedLogic.and(cmp.lessThan(closed.low, low, precision), cmp.greaterThanOrEquals(closed.high, low, precision));
}
union(other) {
if (other == null || !other.isInterval) {
throw new Error('Argument to union must be an interval');
}
if (this.isBoundlessInterval) {
return this.copy();
}
else if (other.isBoundlessInterval) {
return other.copy();
}
// Note that interval union is only defined if the arguments overlap or meet.
if (this.overlaps(other) || this.meets(other)) {
const [a, b] = [this.toClosed(), other.toClosed()];
Expand Down Expand Up @@ -1967,7 +2003,13 @@ class Interval {
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.isBoundlessInterval) {
return other.copy();
}
else if (other.isBoundlessInterval) {
return this.copy();
}
// Note that interval intersect is only defined if the arguments overlap.
if (this.overlaps(other)) {
const [a, b] = [this.toClosed(), other.toClosed()];
let l, lc;
Expand Down Expand Up @@ -2110,6 +2152,9 @@ class Interval {
}
}
sameOrBefore(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return this.equals(other);
}
if (this.end() == null || other == null || other.start() == null) {
return null;
}
Expand All @@ -2118,6 +2163,9 @@ class Interval {
}
}
sameOrAfter(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return this.equals(other);
}
if (this.start() == null || other == null || other.end() == null) {
return null;
}
Expand All @@ -2127,6 +2175,12 @@ class Interval {
}
equals(other) {
if (other != null && other.isInterval) {
if (this.isBoundlessInterval) {
return other.isBoundlessInterval ? true : other.isUnknownInterval ? null : false;
}
else if (other.isBoundlessInterval) {
return this.isUnknownInterval ? null : false;
}
const [a, b] = [this.toClosed(), other.toClosed()];
return logic_1.ThreeValuedLogic.and(cmp.equals(a.low, b.low), cmp.equals(a.high, b.high));
}
Expand All @@ -2135,6 +2189,9 @@ class Interval {
}
}
after(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return false;
}
const 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
Expand All @@ -2146,6 +2203,9 @@ class Interval {
}
}
before(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return false;
}
const 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
Expand All @@ -2157,9 +2217,15 @@ class Interval {
}
}
meets(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return false;
}
return logic_1.ThreeValuedLogic.or(this.meetsBefore(other, precision), this.meetsAfter(other, precision));
}
meetsAfter(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return false;
}
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);
Expand All @@ -2173,6 +2239,9 @@ class Interval {
}
}
meetsBefore(other, precision) {
if (this.isBoundlessInterval || (other === null || other === void 0 ? void 0 : other.isBoundlessInterval)) {
return false;
}
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);
Expand Down Expand Up @@ -2208,6 +2277,12 @@ class Interval {
return this.toClosed().high;
}
starts(other, precision) {
if (this.isBoundlessInterval) {
return other.isBoundlessInterval ? true : other.isUnknownInterval ? null : false;
}
else if (other === null || other === void 0 ? void 0 : other.isBoundlessInterval) {
return this.isUnknownInterval ? null : false;
}
let startEqual;
if (precision != null && this.low != null && this.low.isDateTime) {
startEqual = this.low.sameAs(other.low, precision);
Expand All @@ -2219,6 +2294,12 @@ class Interval {
return startEqual && endLessThanOrEqual;
}
ends(other, precision) {
if (this.isBoundlessInterval) {
return other.isBoundlessInterval ? true : other.isUnknownInterval ? null : false;
}
else if (other === null || other === void 0 ? void 0 : other.isBoundlessInterval) {
return this.isUnknownInterval ? null : false;
}
let endEqual;
const startGreaterThanOrEqual = cmp.greaterThanOrEquals(this.low, other.low, precision);
if (precision != null && (this.low != null ? this.low.isDateTime : undefined)) {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading