private CodedTypeR2 <Code> ParseTranslation(XmlElement translationElement, ParseContext newContext, XmlToModelResult result ) { BareANY anyResult = this.pqrParser.Parse(newContext, translationElement, result); return(anyResult == null ? null : (CodedTypeR2 <Code>)anyResult.BareValue); }
public virtual void TestAdaptValueEventRelatedPeriodicInterval() { ANYImpl <EventRelatedPeriodicIntervalTime> original = new ANYImpl <EventRelatedPeriodicIntervalTime>(); original.Value = new EventRelatedPeriodicIntervalTime(); original.NullFlavor = Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.NO_INFORMATION; original.DataType = StandardDataType.IVL_TS; original.Language = "Fr"; original.DisplayName = "Display Name"; original.Translations.Add(new CDImpl(Ca.Infoway.Messagebuilder.Domainvalue.Basic.UnitsOfMeasureCaseSensitive.CUP)); original.Translations.Add(new CDImpl(Ca.Infoway.Messagebuilder.Domainvalue.Basic.UnitsOfMeasureCaseSensitive.GALLON)); original.OriginalText = "Original Text"; original.IsCdata = false; original.Unsorted = true; original.Operator = SetOperator.CONVEX_HULL; BareANY adaptedValue = GenericClassUtil.AdaptValue(original); Assert.IsTrue(adaptedValue is SXCM_R2Impl <MbDate>); SXCM_R2Impl <MbDate> actualValue = (SXCM_R2Impl <MbDate>)adaptedValue; Assert.AreSame(original.Value, actualValue.Value); Assert.AreSame(original.NullFlavor, actualValue.NullFlavor); Assert.AreSame(original.DataType, actualValue.DataType); Assert.AreSame(original.Language, actualValue.Language); Assert.AreSame(original.DisplayName, actualValue.DisplayName); Assert.AreSame(original.OriginalText, actualValue.OriginalText); Assert.AreEqual(original.IsCdata, actualValue.IsCdata); Assert.AreEqual(original.Unsorted, actualValue.Unsorted); Assert.AreEqual(original.Operator, actualValue.Operator); AssertTranslations(original.Translations, actualValue.Translations); }
public virtual BareANY Adapt(Type toDataType, BareANY any) { IVL <TS, Interval <PlatformDate> > ivl = (IVL <TS, Interval <PlatformDate> >)any; return((BareANY) new DataTypeAdapterHelper().CopyAndReturnAdapted(any, (BareANY) new TSImpl(), ((Interval <PlatformDate>)ivl .Value).Low)); }
private void WriteDataType(BeanProperty property, BareANY value, string dataTypeName) { BareANY field = new DataTypeFieldHelper(property.Bean, property.Name).Get <BareANY>(); if (field == null) { //this is required for the case sure when we collapse an association with cardinality > 1 //into a List of data types. See DevicePrescriptionSummaryQueryCriteriaBean#getRxDispenseIndicator if (property.Collection) { ListElementUtil.AddElement(property.Get(), value.BareValue); } } else { value = this.adapterProvider.GetAdapter(dataTypeName, field.GetType()).Adapt(field.GetType(), value); if (value.HasNullFlavor()) { new DataTypeFieldHelper(property.Bean, property.Name).SetNullFlavor(value.NullFlavor); } if (field is ANYMetaData && value is ANYMetaData) { // preserve any meta data (yes, this is not ideal) ((ANYMetaData)field).Language = ((ANYMetaData)value).Language; ((ANYMetaData)field).DisplayName = ((ANYMetaData)value).DisplayName; ((ANYMetaData)field).OriginalText = ((ANYMetaData)value).OriginalText; ((ANYMetaData)field).Translations.AddAll(((ANYMetaData)value).Translations); } ((BareANYImpl)field).BareValue = value.BareValue; field.DataType = value.DataType; } }
private void ParseUseablePeriods(XmlNode node, XmlToModelResult xmlToModelResult, TelecommunicationAddress result, ParseContext context) { XmlNodeList childNodes = node.ChildNodes; foreach (XmlNode childNode in new XmlNodeListIterable(childNodes)) { if (childNode is XmlElement) { XmlElement useablePeriodElement = (XmlElement)childNode; string name = NodeUtil.GetLocalOrTagName(useablePeriodElement); if ("useablePeriod".Equals(name)) { BareANY tsAny = tsR2ElementParser.Parse(TsContext(context), useablePeriodElement, xmlToModelResult); MbDate mbDate = (MbDate)tsAny.BareValue; result.AddUseablePeriod(mbDate == null ? null : mbDate.Value, ((ANYMetaData)tsAny).Operator); } else { xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Unexpected TEL child element: \"" + useablePeriodElement .Name + "\"", useablePeriodElement)); } } } }
/// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception> private Interval <Int32?> Parse(XmlNode node) { BareANY ivl = this.parser.Parse(ParseContextImpl.Create("IVL<INT>", typeof(Interval <object>), SpecificationVersion.V02R02 , null, null, null, null, null, false), Arrays.AsList(node), this.result); return((Interval <Int32?>)(ivl.BareValue)); }
private void Validate(Int32?integer, FormatContext context, BareANY bareAny) { if (integer.Value < 0) { RecordNotNegativeError(integer, context.GetPropertyPath(), context.GetModelToXmlResult()); } }
public virtual void TestPivlPhasePeriod() { XmlToModelResult result = new XmlToModelResult(); XmlNode node = CreateNode("<pivl><period unit=\"d\" value=\"1\"/><phase><low value=\"20120503\"/><high value=\"20120708\"/></phase></pivl>" ); ParseContext context = ParseContextImpl.Create("PIVLTSCDAR1", null, SpecificationVersion.R02_04_03, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel .MANDATORY, Cardinality.Create("1"), null, true); BareANY parseResult = this.parser.Parse(context, Arrays.AsList(node), result); PhysicalQuantity expectedPeriod = new PhysicalQuantity(BigDecimal.ONE, Ca.Infoway.Messagebuilder.Domainvalue.Basic.UnitsOfMeasureCaseSensitive .DAY); PlatformDate dateLow = DateUtil.GetDate(2012, 4, 3); DateWithPattern dateWithPatternLow = new DateWithPattern(dateLow, "yyyyMMdd"); PlatformDate dateHigh = DateUtil.GetDate(2012, 6, 8); DateWithPattern dateWithPatternHigh = new DateWithPattern(dateHigh, "yyyyMMdd"); Interval <PlatformDate> expectedPhase = IntervalFactory.CreateLowHigh((PlatformDate)dateWithPatternLow, (PlatformDate)dateWithPatternHigh ); Assert.IsTrue(result.IsValid()); Assert.IsTrue(parseResult is PIVLTSCDAR1); PeriodicIntervalTimeR2 pivl = (PeriodicIntervalTimeR2)parseResult.BareValue; Assert.AreEqual(expectedPeriod.Quantity, pivl.Period.Quantity); Assert.AreEqual(expectedPeriod.Unit.CodeValue, pivl.Period.Unit.CodeValue); Assert.AreEqual(expectedPhase, pivl.Phase); Assert.IsNull(pivl.FrequencyRepetitions); Assert.IsNull(pivl.FrequencyQuantity); }
private void Validate(Int32?integer, FormatContext context, BareANY bareAny) { if (integer.Value <= 0) { RecordMustBeGreaterThanZeroError(integer, context.GetPropertyPath(), context.GetModelToXmlResult()); } }
private Interval <PlatformDate> ParseValidTime(XmlElement node, ParseContext context, XmlToModelResult xmlToModelResult) { Interval <PlatformDate> validTime = null; bool foundValidTime = false; bool loggedValidTimeError = false; XmlNodeList childNodes = node.ChildNodes; foreach (XmlNode childNode in new XmlNodeListIterable(childNodes)) { string childElementName = NodeUtil.GetLocalOrTagName(childNode); bool isValidTime = AbstractNameR2ElementParser <V> .VALID_TIME_ELEMENT.Equals(childElementName); if (!loggedValidTimeError && foundValidTime) { loggedValidTimeError = true; RecordError("Only one validTime is allowed, and it must come after all name parts", (XmlElement)node, xmlToModelResult); } if (childNode is XmlElement) { if (isValidTime) { foundValidTime = true; ParseContext newContext = ParseContextImpl.Create("IVL<TS>", context); BareANY ivlTsAny = this.ivlTsParser.Parse(newContext, Arrays.AsList(childNode), xmlToModelResult); if (ivlTsAny != null && ivlTsAny.BareValue != null) { DateInterval dateInterval = (DateInterval)ivlTsAny.BareValue; validTime = dateInterval == null ? null : dateInterval.Interval; } } } } return(validTime); }
public override BareANY Parse(ParseContext context, XmlNode node, XmlToModelResult result) { BareANY codedTypeAny = DoCreateR2DataTypeInstance(context); XmlElement element = (XmlElement)node; CodedTypeR2 <Code> codedType = new CodedTypeR2 <Code>(); // attributes HandleNullFlavor(element, codedTypeAny, context, result); HandleCodeAndCodeSystem(element, codedType, context, result); HandleCodeSystemName(element, codedType, context, result); HandleCodeSystemVersion(element, codedType, context, result); HandleDisplayName(element, codedType, context, result); HandleValue(element, codedType, context, result); HandleQty(element, codedType, context, result); HandleOperator(element, codedTypeAny, codedType, context, result); // elements HandleSimpleValue(element, codedType, context, result); HandleOriginalText(element, codedType, context, result); HandleQualifier(element, codedType, context, result); HandleTranslation(element, codedType, context, result); HandleValidTime(element, codedType, context, result); HandleConstraints(codedType, context.GetConstraints(), element, result); // want to return null if no attributes or elements are present if (codedType.IsEmpty()) { codedType = null; } ((BareANYImpl)codedTypeAny).BareValue = CodedTypeR2Helper.ConvertCodedTypeR2(codedType, context.GetExpectedReturnType()); return(codedTypeAny); }
private string DetermineActualType(Relationship relationship, BareANY hl7Value, Hl7Errors errors, string propertyPath) { StandardDataType newTypeEnum = (hl7Value == null ? null : hl7Value.DataType); return(this.polymorphismHandler.DetermineActualDataType(relationship.Type, newTypeEnum, this.isCda, !this.isR2, CreateErrorLogger (propertyPath, errors))); }
public virtual void ShouldAdaptCorrectly() { TSImpl ts = new TSImpl(new PlatformDate()); BareANY adapted = this.adapter.Adapt(StandardDataType.IVL_FULL_DATE.Type, ts); Assert.AreEqual(((IVL <TS, Interval <PlatformDate> >)adapted).Value.Low, ts.Value, "low"); }
public virtual BareANY Adapt(string toDataTypeName, BareANY any) { BareANY element = null; if (any != null) { PropertyInfo property = any.GetType().GetProperty("Value"); object collectionValue = property.GetValue(any, null); if (collectionValue != null) { IEnumerable <BareANY> enumerable = (IEnumerable <BareANY>)collectionValue; IEnumerator <BareANY> enumerator = enumerable.GetEnumerator(); if (enumerator.MoveNext()) { element = enumerator.Current; } } } if (element == null) { element = new ANYImpl <object>(); } return((BareANY)element); }
protected virtual BareANY CreateDataTypeInstance(string typeName) { BareANY dataTypeInstance = DoCreateDataTypeInstance(typeName); SetDataType(typeName, dataTypeInstance); return(dataTypeInstance); }
private void PopulateValue(BareANY dataType, ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult, string codeAttributeName) { Code value = ParseNonNullCodeNode(context, codeAttributeName, node, dataType, GetReturnType(context), xmlToModelResult); ((BareANYImpl)dataType).BareValue = value; }
private void ExerciseVisitorOverInteractionWithAttribute(BareANY attributeHl7Value, Relationship attributeRelationship) { this.attributeBridge.SetHl7Value(attributeHl7Value); this.visitor.VisitRootStart(this.partBridge, this.interation); this.visitor.VisitAttribute(this.attributeBridge, attributeRelationship, null, null, null); this.visitor.VisitRootEnd(this.partBridge, this.interation); }
private void RenderRealmCodes(PartBridge tealBean) { if (tealBean.GetRealmCode() != null) { string type = "CS"; PropertyFormatter formatter = this.formatterRegistry.Get(type); Relationship placeholderRelationship = new Relationship("realmCode", type, Cardinality.Create("0-*")); placeholderRelationship.DomainType = "Realm"; FormatContext context = Ca.Infoway.Messagebuilder.Marshalling.FormatContextImpl.Create(this.result, null, placeholderRelationship , version, null, null, null, this.isCda); foreach (Realm realm in tealBean.GetRealmCode()) { BareANY any = (BareANY)DataTypeFactory.CreateDataType(type, this.isCda && this.isR2); if (this.isR2) { ((BareANYImpl)any).BareValue = new CodedTypeR2 <Realm>(realm); } else { ((BareANYImpl)any).BareValue = realm; } string xmlFragment = formatter.Format(context, any, GetIndent()); CurrentBuffer().GetChildBuilder().Append(xmlFragment); } } }
public override string Format(FormatContext context, BareANY hl7Value, int indentLevel) { string result = base.Format(context, hl7Value, indentLevel); if (hl7Value != null) { string originalText = ((ANYMetaData)hl7Value).OriginalText; bool hasNullFlavor = hl7Value.HasNullFlavor(); bool hasAnyValues = HasAnyValues(hl7Value); this.pqValidationUtils.ValidateOriginalText(context.Type, originalText, hasAnyValues, hasNullFlavor, context.GetVersion() , null, context.GetPropertyPath(), context.GetModelToXmlResult()); // complete hack for BC if (SpecificationVersion.IsExactVersion(context.GetVersion(), SpecificationVersion.V02R04_BC)) { if (hasNullFlavor && HasAnyValues(hl7Value)) { // dump the result and rebuild, adding in NF IDictionary <string, string> attributeNameValuePairs = GetAttributeNameValuePairs(context, (PhysicalQuantity)hl7Value.BareValue , hl7Value); attributeNameValuePairs.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor)); result = CreateElement(context, attributeNameValuePairs, indentLevel, true, true); } } if (StringUtils.IsNotBlank(originalText)) { string otElement = CreateElement("originalText", null, indentLevel + 1, false, false); otElement += XmlStringEscape.Escape(originalText); otElement += CreateElementClosure("originalText", 0, true); // pulling off the end "/>" is not the most elegant solution, but superclass would need significant refactoring otherwise result = Ca.Infoway.Messagebuilder.StringUtils.Substring(result, 0, result.IndexOf("/>")) + ">" + SystemUtils.LINE_SEPARATOR + otElement + CreateElementClosure(context.GetElementName(), indentLevel, true); } } return(result); }
private FormatContext ValidateInterval(Interval <T> value, BareANY bareAny, FormatContext context) { string type = context.Type; IList <string> errors = new List <string>(); string specializationType = bareAny.DataType == null ? null : bareAny.DataType.Type; string newType = this.ivlValidationUtils.ValidateSpecializationType(type, specializationType, errors); RecordAnyErrors(errors, context); if (!StringUtils.Equals(type, newType)) { // replace the context with one using the specialization type context = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(newType, true, context); } bool lowProvided = RepresentationUtil.HasLow(value.Representation) && (value.Low != null || value.LowNullFlavor != null); bool highProvided = RepresentationUtil.HasHigh(value.Representation) && (value.High != null || value.HighNullFlavor != null ); bool centerProvided = RepresentationUtil.HasCentre(value.Representation) && (value.Centre != null || value.CentreNullFlavor != null); bool widthProvided = RepresentationUtil.HasWidth(value.Representation) && (value.Width != null && (value.Width.Value != null || value.Width.NullFlavor != null)); errors = this.ivlValidationUtils.ValidateCorrectElementsProvided(type, context.GetVersion(), lowProvided, highProvided, centerProvided , widthProvided); RecordAnyErrors(errors, context); errors = this.ivlValidationUtils.DoOtherValidations(type, lowProvided ? value.LowNullFlavor : null, centerProvided ? value .CentreNullFlavor : null, highProvided ? value.HighNullFlavor : null, widthProvided ? value.Width.NullFlavor : null, (widthProvided && value.Width is DateDiff) ? (DateDiff.ConvertDiff(value.Width)).Unit : null); RecordAnyErrors(errors, context); return(context); }
private void HandleOriginalText(XmlElement element, CodedTypeR2 <Code> codedType, ParseContext context, XmlToModelResult result ) { if (OriginalTextAllowed()) { IList <XmlElement> originalTextElements = GetNamedElements("originalText", element); if (originalTextElements.Count > 0) { if (originalTextElements.Count > 1) { RecordError("Only one original text element is allowed.", element, context, result); } ParseContext newContext = ParseContextImpl.Create("ED", context); BareANY parsedOriginalText = this.edParser.Parse(newContext, originalTextElements[0], result); if (parsedOriginalText != null) { codedType.OriginalText = (EncapsulatedData)parsedOriginalText.BareValue; } } } else { ValidateUnallowedChildNode(context.Type, element, result, "originalText"); } }
/// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception> public override BareANY Parse(ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult) { BareANY result = CreateDataTypeInstance(context != null ? GetType(context) : null); // RM20416 - some PQ specifications allow for NF to coexist with other properties if (HasValidNullFlavorAttribute(context, node, xmlToModelResult)) { NullFlavor nullFlavor = ParseNullNode(context, node, xmlToModelResult); result.NullFlavor = nullFlavor; } PhysicalQuantity value = ParseNonNullNode(context, node, result, GetReturnType(context), xmlToModelResult); if (value != null && (value.Quantity != null || value.Unit != null)) { ((BareANYImpl)result).BareValue = value; } XmlElement element = (XmlElement)node; // validation of OT done a bit later below string originalText = GetOriginalText(element); if (HasOriginalText(element)) { ((PQ)result).OriginalText = originalText; } bool hasValues = HasAnyValues(element); bool hasNullFlavor = HasValidNullFlavorAttribute(context, node, xmlToModelResult); this.pqValidationUtils.ValidateOriginalText(context.Type, originalText, hasValues, hasNullFlavor, context.GetVersion(), element , null, xmlToModelResult); return(result); }
private T Wrap(object element) { BareANY bareAny = (BareANY)ClassUtil.NewInstance(originalElementType); ((BareANYImpl)bareAny).BareValue = element; return((T)bareAny); }
public virtual void TestIvlTsConstraintsInvalid() { XmlToModelResult result = new XmlToModelResult(); XmlNode node = CreateNode("<ivl><low value=\"20120503\"/><high value=\"20120708\"/></ivl>"); ConstrainedDatatype constraints = new ConstrainedDatatype("ivl", "IVL<TS>"); constraints.Relationships.Add(new Relationship("low", "TS", Cardinality.Create("0"))); constraints.Relationships.Add(new Relationship("high", "TS", Cardinality.Create("0"))); ParseContext context = ParseContextImpl.Create("IVLTSCDAR1", null, SpecificationVersion.R02_04_03, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel .MANDATORY, Cardinality.Create("1"), constraints, true); BareANY parseResult = this.parser.Parse(context, Arrays.AsList(node), result); PlatformDate dateLow = DateUtil.GetDate(2012, 4, 3); DateWithPattern dateWithPatternLow = new DateWithPattern(dateLow, "yyyyMMdd"); PlatformDate dateHigh = DateUtil.GetDate(2012, 6, 8); DateWithPattern dateWithPatternHigh = new DateWithPattern(dateHigh, "yyyyMMdd"); Interval <PlatformDate> expectedIvl = IntervalFactory.CreateLowHigh((PlatformDate)dateWithPatternLow, (PlatformDate)dateWithPatternHigh ); Assert.IsFalse(result.IsValid()); Assert.AreEqual(2, result.GetHl7Errors().Count); Assert.IsTrue(parseResult is IVLTSCDAR1); DateInterval ivl = (DateInterval)parseResult.BareValue; Assert.AreEqual(expectedIvl, ivl.Interval); }
protected override string FormatNonNullDataType(FormatContext context, BareANY dataType, int indentLevel) { EncapsulatedData encapsulatedData = ExtractBareValue(dataType); HandleConstraints(encapsulatedData, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult()); IDictionary <string, string> attributes = CreateAttributes(encapsulatedData, context); bool hasContent = HasContent(encapsulatedData); bool hasReferenceOrThumbnailOrDocument = HasReferenceOrThumbnailOrDocument(encapsulatedData); if (!this.isR2) { AddSpecializationType(encapsulatedData, attributes, context.Type, dataType.DataType, context.GetVersion()); Validate(context, dataType, encapsulatedData); } StringBuilder buffer = new StringBuilder(); buffer.Append(CreateElement(context, attributes, indentLevel, !hasContent, hasReferenceOrThumbnailOrDocument)); if (hasContent) { WriteReference(encapsulatedData, buffer, indentLevel + 1, context); WriteThumbnail(encapsulatedData, buffer, indentLevel + 1, context); this.edContentRenderer.RenderContent(encapsulatedData, buffer, indentLevel + 1, context, hasReferenceOrThumbnailOrDocument ); buffer.Append(CreateElementClosure(context, hasReferenceOrThumbnailOrDocument ? indentLevel : 0, true)); } return(buffer.ToString()); }
protected virtual void PopulateOriginalText(BareANY dataType, ParseContext context, XmlElement element, XmlToModelResult xmlToModelResult) { if (HasOriginalText(element)) { ((CD)dataType).OriginalText = GetOriginalText(element); } }
private void PopulateNullFlavor(BareANY dataType, ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult) { if (HasValidNullFlavorAttribute(context, node, xmlToModelResult)) { NullFlavor nullFlavor = ParseNullNode(context, node, xmlToModelResult); dataType.NullFlavor = nullFlavor; } }
public virtual void TestParseNullNode() { XmlNode node = CreateNode("<something nullFlavor=\"NI\" />"); BareANY ii = this.parser.Parse(this.context, node, this.xmlResult); Assert.IsNull(ii.BareValue, "null result"); Assert.AreEqual(Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.NO_INFORMATION, ii.NullFlavor, "null flavor"); }
private void HandleNullFlavor(XmlElement element, BareANY dataType, ParseContext context, XmlToModelResult result) { if (HasValidNullFlavorAttribute(context, element, result)) { NullFlavor nullFlavor = ParseNullNode(context, element, result); dataType.NullFlavor = nullFlavor; } }
public virtual void ShouldAdaptCorrectly() { IIImpl ii = new IIImpl(new Identifier("1", "2")); BareANY adapted = this.adapter.Adapt(typeof(LISTImpl <IIImpl, Identifier>), ii); Assert.IsTrue(adapted is LISTImpl <IIImpl, Identifier>); Assert.IsTrue(((LISTImpl <IIImpl, Identifier>)adapted).Value.Contains(ii)); }