public virtual void TestParseWidth() { XmlNode node = CreateNode("<effectiveTime>" + " <width value=\"1\" unit=\"d\"/>" + "</effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL.WIDTH<TS>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); Assert.IsNull(interval.Low, "low"); Assert.IsNull(interval.High, "high"); Assert.IsNull(interval.Centre, "centre"); Assert.IsNotNull(interval.Width, "width"); DateDiff diff = (DateDiff)interval.Width; Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive unit = diff.Unit; Assert.AreEqual("d", unit.CodeValue, "unit"); Assert.IsNull(diff.NullFlavor, "null flavor"); node = CreateNode("<effectiveTime>" + " <low nullFlavor=\"OTH\"/>" + " <width nullFlavor=\"OTH\"/>" + "</effectiveTime>" ); interval = Parse(node, "IVL<TS>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); Assert.IsNull(interval.Low, "low"); Assert.IsNull(interval.High, "high"); Assert.IsNull(interval.Centre, "centre"); Assert.IsNotNull(interval.Width, "width"); diff = (DateDiff)interval.Width; Assert.AreEqual("OTH", diff.NullFlavor.CodeValue, "nullFlavor"); Assert.IsNull(diff.Unit, "unit"); }
public static bool IsDayBased(Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive units) { if (units == null || units.CodeValue == null) { return(false); } return(YEAR.CodeValue.Equals(units.CodeValue) || MONTH.CodeValue.Equals(units.CodeValue) || WEEK.CodeValue.Equals(units.CodeValue) || DAY.CodeValue.Equals(units.CodeValue)); }
protected virtual string GetDateDiffUnits(BareDiff diff) { if (diff is DateDiff) { Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive unit = ((DateDiff)diff).Unit; return(unit != null ? unit.CodeValue : string.Empty); } else { return(IvlPropertyFormatter <T> .UNITS_OF_MEASURE_DAY); } }
/// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception> protected override PhysicalQuantity ParseNonNullNode(ParseContext context, XmlNode node, BareANY result, Type expectedReturnType , XmlToModelResult xmlToModelResult) { XmlElement element = (XmlElement)node; bool hasNullFlavor = HasValidNullFlavorAttribute(context, node, xmlToModelResult); BigDecimal value = this.pqValidationUtils.ValidateValue(element.GetAttribute("value"), context.GetVersion(), context.Type , hasNullFlavor, element, null, xmlToModelResult); Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive unit = this.pqValidationUtils.ValidateUnits(context.Type , element.GetAttribute("unit"), element, null, xmlToModelResult, false); PhysicalQuantity physicalQuantity = (value != null || unit != null) ? new PhysicalQuantity(value, unit) : null; // this is not the usual way of doing things; this is to make validation easier ((BareANYImpl)result).BareValue = physicalQuantity; return(physicalQuantity); }
public virtual Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive ValidateUnits(string type, string unitsAsString , XmlElement element, string propertyPath, Hl7Errors errors, bool isR2) { Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive units = null; if (StringUtils.IsNotBlank(unitsAsString)) { units = (Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive)CodeResolverRegistry.Lookup(this.GetUnitTypeByHl7Type (type, element, propertyPath, errors, isR2), unitsAsString); if (units == null) { CreateWarning(System.String.Format("Unit \"{0}\" is not valid for type {1}", unitsAsString, type), element, propertyPath, errors); } } return(units); }
private void DoOtherValidations(BareANY lowAny, BareANY highAny, BareANY centerAny, BareDiff widthType, XmlElement element , ParseContext context, XmlToModelResult xmlToModelResult) { string type = context.Type; NullFlavor lowNullFlavor = (lowAny == null ? null : lowAny.NullFlavor); NullFlavor centerNullFlavor = (centerAny == null ? null : centerAny.NullFlavor); NullFlavor highNullFlavor = (highAny == null ? null : highAny.NullFlavor); NullFlavor widthNullFlavor = (widthType == null ? null : widthType.NullFlavor); Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive widthTimeUnits = ((widthType != null && widthType is DateDiff ) ? ((DateDiff)widthType).Unit : null); IList <string> errors = this.ivlValidationUtils.DoOtherValidations(type, lowNullFlavor, centerNullFlavor, highNullFlavor, widthNullFlavor, widthTimeUnits); RecordAnyErrors(errors, element, xmlToModelResult); }
public virtual IList <string> DoOtherValidations(string type, NullFlavor lowNullFlavor, NullFlavor centerNullFlavor, NullFlavor highNullFlavor, NullFlavor widthNullFlavor, Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive widthTimeUnits ) { IList <string> errors = new List <string>(); string parameterizedType = Hl7DataTypeName.GetParameterizedType(type); string unqualifiedParameterizedType = Hl7DataTypeName.Unqualify(parameterizedType); StandardDataType innerType = StandardDataType.GetByTypeName(parameterizedType); StandardDataType baseInnerType = StandardDataType.GetByTypeName(unqualifiedParameterizedType); if (!this.isUncertainRangeValidation) { if (baseInnerType == StandardDataType.PQ) { // TODO - VALIDATION - TM - this might apply to URG<PQ.x> (check with Lloyd) bool lowNull = (lowNullFlavor != null); bool highNull = (highNullFlavor != null); if (lowNull && highNull) { errors.Add("For " + GetIntervalOrRange() + "s of type PQ.x, one of (low, high) must be non-null."); } } else { EnsureNotPinfOrNinf("low", lowNullFlavor, errors); EnsureNotPinfOrNinf("high", highNullFlavor, errors); EnsureNotPinfOrNinf("center", centerNullFlavor, errors); EnsureNotPinfOrNinf("width", widthNullFlavor, errors); } // TS.DATE/TS.FULLDATE have width restrictions (does not seem to apply to URG; check with Lloyd) if (innerType == StandardDataType.TS_DATE || innerType == StandardDataType.TS_FULLDATE) { if (widthTimeUnits != null) { if (!Ca.Infoway.Messagebuilder.Domainvalue.Basic.DefaultTimeUnit.IsDayBased(widthTimeUnits)) { errors.Add("Width units must be days (d), weeks (wk), months (mo) or years (a)."); } } } } return(errors); }