operator - method

FhirPathQuantity operator -(
  1. Object o
)

Implementation

FhirPathQuantity operator -(Object o) {
  if (o is! FhirPathQuantity) {
    throw primitives.InvalidTypes<FhirPathQuantity>(
        'A + operator was attemped with an object that was not a FhirPathQuantity: '
        'instead this was passed $o which is a type ${o.runtimeType}');
  } else if (unit == o.unit) {
    final value = amount - o.amount;
    return FhirPathQuantity(value, unit);
  } else {
    final fromUnit = stringUnitToProperty[o.unit];
    final toUnit = stringUnitToProperty[unit];
    final convertedAmount = o.amount.convertFromTo(fromUnit, toUnit);
    if (convertedAmount == null) {
      throw primitives.InvalidTypes<FhirPathQuantity>(
          'A + operator was attemped with two units types that are not '
          'comparable: $this and $o');
    } else {
      amount = amount - convertedAmount;
      return this;
    }
  }
}