public virtual void Render(StringBuilder builder, string propertyPath, Hl7Errors errors) { Relationship r = this.relationship; if (r.HasFixedValue()) { FormatFixedValue(builder, r); } else { object value = GetValue(); // structural attributes should never have a conformance of populated, and should never have a nullFlavor (no need to check these cases) if (value == null && ConformanceLevelUtil.IsMandatory(r) && r.HasDefaultValue()) { FormatDefaultValue(builder, r); } else { if (value != null) { FormatValue(builder, r, value); } else { if (ConformanceLevelUtil.IsMandatory(this.relationship)) { string errorMessage = "Relationship " + r.Name + " is mandatory (and not a fixed or default value), but no value is specified"; Hl7Error error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage, propertyPath); errors.AddHl7Error(error); } } } } }
private void HandleNotAllowedAndIgnored(Relationship relationship, string propertyPath) { Hl7Error hl7Error = null; if (ConformanceLevelUtil.IsIgnored(relationship)) { if (ConformanceLevelUtil.IsIgnoredNotAllowed()) { string message = System.String.Format(ConformanceLevelUtil.ATTRIBUTE_IS_IGNORED_AND_CANNOT_BE_USED, relationship.Name); hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.ERROR, message, propertyPath); } else { string message = System.String.Format(ConformanceLevelUtil.ATTRIBUTE_IS_IGNORED_AND_WILL_NOT_BE_USED, relationship.Name); hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.INFO, message, propertyPath); } } else { if (ConformanceLevelUtil.IsNotAllowed(relationship)) { string message = System.String.Format(ConformanceLevelUtil.ATTRIBUTE_IS_NOT_ALLOWED, relationship.Name); hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.ERROR, message, propertyPath); } } if (hl7Error != null) { this.result.AddHl7Error(hl7Error); } }
public virtual NullFlavor ParseNullNode() { string attributeValue = GetAttributeValue(node, NULL_FLAVOR_ATTRIBUTE_NAME); NullFlavor nullFlavor = CodeResolverRegistry.Lookup <NullFlavor>(attributeValue); if (ConformanceLevelUtil.IsMandatory(this.conformanceLevel, null)) { xmlToModelResult.AddHl7Error(Hl7Error.CreateMandatoryAttributeIsNullError(NodeUtil.GetLocalOrTagName((XmlElement)node), GetAttributeValue (node, NULL_FLAVOR_ATTRIBUTE_NAME), (XmlElement)node)); } else { // RM #15431 - strictly speaking, nullFlavors are not allowed for REQUIRED fields. However, jurisdictions often ignore this restriction. // FIXME: TM (see RM18424) - once MB has error levels implemented, this can be reinstated as a warning // } else if (this.conformanceLevel != null && this.conformanceLevel == ConformanceLevel.REQUIRED) { // xmlToModelResult.addHl7Error(Hl7Error.createRequiredAttributeIsNullError( // NodeUtil.getLocalOrTagName((Element) node), // getAttributeValue(node, NULL_FLAVOR_ATTRIBUTE_NAME), // (Element) node)); if (this.isAssociation && !StringUtils.Equals(GetAttributeValue(node, NULL_FLAVOR_XSI_NIL_ATTRIBUTE_NAME), "true")) { if (!Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(Ca.Infoway.Messagebuilder.Marshalling.HL7.Parser.NullFlavorHelper .MB_SUPPRESS_XSI_NIL_ON_NULLFLAVOR))) { xmlToModelResult.AddHl7Error(Hl7Error.CreateNullFlavorMissingXsiNilError(NodeUtil.GetLocalOrTagName((XmlElement)node), (XmlElement )node)); } } } return(nullFlavor); }
private void Validate(StringBuilder buffer, int indentLevel, FormatContext context, bool isStLang, BareANY dataType) { // ST.LANG not allowed for CeRx; not checking as this should be controlled by the message set // is ST allowed to be 0 length or only whitespace??? ModelToXmlResult result = context.GetModelToXmlResult(); string language = GetLanguage(dataType); if (isStLang) { if (!STImpl.ALLOWED_LANGUAGES.Contains(language)) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute content ({0}) is not an allowed value. Using en-CA instead." , language), context.GetPropertyPath()); result.AddHl7Error(hl7Error); } } else { if (language != null) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute ({0}) is not allowed for ST element types" , language), context.GetPropertyPath()); result.AddHl7Error(hl7Error); } } }
private void Validate(StringBuilder buffer, int indentLevel, FormatContext context, bool hasLang, BareANY dataType) { // ST has min length of 1 according to schema, and cannot have both a NF and text // no details on what language strings are allowed ModelToXmlResult result = context.GetModelToXmlResult(); if (dataType.HasNullFlavor()) { if (dataType.BareValue != null) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST cannot have both a nullFlavour and a text value.", context .GetPropertyPath()); result.AddHl7Error(hl7Error); } } else { if (StringUtils.IsBlank(GetStringValue(dataType))) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST text value must be provided.", context.GetPropertyPath ()); result.AddHl7Error(hl7Error); } } if (hasLang && StringUtils.IsBlank(GetLanguage(dataType))) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST language attribute, if provided, can not be blank.", context .GetPropertyPath()); result.AddHl7Error(hl7Error); } }
// public as a result of needing to call this method from ValidatingVistor public virtual Boolean? ParseBooleanValue(XmlToModelResult result, string unparsedBoolean, XmlElement element, XmlAttribute attr) { Boolean? booleanResult = null; if (StringUtils.IsBlank(unparsedBoolean)) { result.AddHl7Error(Hl7Error.CreateMandatoryBooleanValueError(element, attr)); } else { if (VALID_BOOLEAN_STRINGS.Contains(unparsedBoolean)) { booleanResult = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(unparsedBoolean); } else { if (VALID_BOOLEAN_STRINGS.Contains(unparsedBoolean.ToLower())) { result.AddHl7Error(Hl7Error.CreateIncorrectCapitalizationBooleanValueError(unparsedBoolean, element, attr)); booleanResult = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(unparsedBoolean); } else { result.AddHl7Error(Hl7Error.CreateInvalidBooleanValueError(element, attr)); } } } return booleanResult; }
private void ValidateNamespace(XmlNode node, Relationship xmlRelationship, Hl7Source source) { if (!NamespaceUtil.IsNamespaceCorrect(node, xmlRelationship)) { string message = System.String.Format("Expected relationship {0}.{1} to have namespace {2} but was {3}", xmlRelationship. ParentType, xmlRelationship.Name, NamespaceUtil.GetExpectedNamespace(xmlRelationship), NamespaceUtil.GetActualNamespace( node)); Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.UNEXPECTED_NAMESPACE, ErrorLevel.ERROR, message, node); source.GetResult().AddHl7Error(hl7Error); } }
public virtual void TestParseInvalidValueUrlScheme() { XmlNode node = CreateNode("<something value=\"mailfrom://monkey\" />"); new TelR2ElementParser().Parse(CreateContext("TEL", SpecificationVersion.V02R02), node, this.xmlResult); Assert.IsFalse(this.xmlResult.IsValid()); Assert.AreEqual(1, this.xmlResult.GetHl7Errors().Count, "HL7 error count"); // invalid scheme Hl7Error hl7Error = this.xmlResult.GetHl7Errors()[0]; Assert.AreEqual("Unrecognized URL scheme 'mailfrom' in element /something", hl7Error.GetMessage(), "error message"); }
public virtual void TestParseInvalidValueAttribute() { XmlNode node = CreateNode("<something value=\"19990355101112\" />"); new TsElementParser().Parse(CreateContext(), node, this.xmlResult); Assert.IsFalse(this.xmlResult.IsValid(), "valid date"); Assert.AreEqual(1, this.xmlResult.GetHl7Errors().Count, "one error"); Hl7Error hl7Error = this.xmlResult.GetHl7Errors()[0]; Assert.AreEqual("The timestamp 19990355101112 in element <something value=\"19990355101112\"/> cannot be parsed.", hl7Error .GetMessage(), "error message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error message type"); }
public virtual void TestParseInvalidValueAttributeNode() { XmlNode node = CreateNode("<something value=\"1234\" />"); new TelElementParser().Parse(CreateContext("TEL.PHONE", SpecificationVersion.V02R02), node, this.xmlResult); Assert.IsFalse(this.xmlResult.IsValid()); Assert.AreEqual(1, this.xmlResult.GetHl7Errors().Count, "HL7 error count"); Hl7Error hl7Error = this.xmlResult.GetHl7Errors()[0]; Assert.AreEqual("TelecomAddress must have a valid URL scheme (e.g. 'http://') (<something value=\"1234\"/>)", hl7Error.GetMessage (), "error message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error message code"); }
private void ValidateDatePattern(string datePattern, FormatContext context) { StandardDataType standardDataType = StandardDataType.GetByTypeName(context); VersionNumber version = (context == null ? null : context.GetVersion()); string[] allowedDateFormats = TsDateFormats.GetAllDateFormats(standardDataType, version); if (!ArrayContains(allowedDateFormats, datePattern)) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Invalid date format {0} supplied for value of type {1}" , datePattern, context == null ? "TS" : context.Type), context.GetPropertyPath()); context.GetModelToXmlResult().AddHl7Error(hl7Error); } }
private void ValidateAssociationCardinality(Hl7Source source, IList <XmlNode> nodes, string traversalName, Relationship relationship ) { Cardinality cardinality = relationship.Cardinality; int numberOfAssociations = nodes.Count; if (cardinality != null && !cardinality.Contains(numberOfAssociations)) { Hl7Error error = Hl7Error.CreateWrongNumberOfAssociationsError(traversalName, source.GetCurrentElement(), numberOfAssociations , cardinality); source.GetResult().AddHl7Error(error); } }
public virtual void TestParseInvalidValueAttribute() { XmlNode node = CreateNode("<something value=\"19990355\" />"); XmlToModelResult result = new XmlToModelResult(); new TsElementParser().Parse(new TrivialContext("TS.DATETIME"), node, result); Assert.IsFalse(result.IsValid(), "valid date"); Assert.AreEqual(1, result.GetHl7Errors().Count, "one error"); Hl7Error hl7Error = result.GetHl7Errors()[0]; Assert.AreEqual("The timestamp 19990355 in element <something value=\"19990355\"/> cannot be parsed.", hl7Error.GetMessage (), "error message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error message type"); }
public virtual void TestParseWidthFailureUnit() { XmlNode node = CreateNode("<effectiveTime>" + " <width value=\"1\" unit=\"monkeys\"/>" + "</effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNull(interval, "null"); Assert.IsFalse(this.result.IsValid(), "not valid"); Assert.AreEqual(2, this.result.GetHl7Errors().Count, "error count"); Hl7Error hl7Error = this.result.GetHl7Errors()[1]; Assert.AreEqual("Unit \"monkeys\" is not valid for type PQ.TIME (<width unit=\"monkeys\" value=\"1\"/>)", hl7Error.GetMessage (), "message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error type"); }
public virtual void TestParseWidthFailureValue() { XmlNode node = CreateNode("<effectiveTime>" + " <width value=\"1.d\" unit=\"d\"/>" + "</effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNull(interval, "null"); Assert.IsFalse(this.result.IsValid(), "not valid"); Assert.AreEqual(1, this.result.GetHl7Errors().Count, "error count"); // width invalid Hl7Error hl7Error = this.result.GetHl7Errors()[0]; Assert.AreEqual("value \"1.d\" is not a valid decimal value (<width unit=\"d\" value=\"1.d\"/>)", hl7Error.GetMessage(), "message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error type"); }
public virtual void TestParseWidthFailureValue() { XmlNode node = CreateNode("<effectiveTime>" + " <width value=\"1.d\" unit=\"d\"/>" + "</effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNull(interval, "null"); Assert.IsFalse(this.result.IsValid(), "not valid"); System.Console.Out.WriteLine(this.result.GetHl7Errors()[1]); Assert.AreEqual(2, this.result.GetHl7Errors().Count, "error count"); Hl7Error hl7Error = this.result.GetHl7Errors()[1]; Assert.AreEqual("value \"1.d\" must contain digits only (<width unit=\"d\" value=\"1.d\"/>)", hl7Error.GetMessage(), "message" ); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error type"); }
private void CreateError(string errorMessage, XmlElement element, string propertyPath, Hl7Errors errors) { Hl7Error error = null; if (element != null) { error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage + " (" + XmlDescriber.DescribeSingleElement(element) + ")" , element); } else { // assuming this has a property path error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage, propertyPath); } errors.AddHl7Error(error); }
/// <exception cref="System.Exception"></exception> public virtual void TestInvalidNode(XmlNode invalidNode) { XmlToModelResult xmlResult = new XmlToModelResult(); string parseResult = (string)new EdSignatureElementParser().Parse(CreateEdContext(), invalidNode, xmlResult).BareValue; Assert.IsNull(parseResult, "parse result"); Assert.AreEqual(2, xmlResult.GetHl7Errors().Count, "HL7 error count"); Hl7Error hl7Error = xmlResult.GetHl7Errors()[0]; Assert.AreEqual("Attribute mediaType must be included with a value of \"text/xml\" for ED.SIGNATURE", hl7Error.GetMessage (), "error message"); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error message code"); hl7Error = xmlResult.GetHl7Errors()[1]; Assert.AreEqual("Expected ED.SIGNATURE node to have a child element named signature", hl7Error.GetMessage(), "error message" ); Assert.AreEqual(Hl7ErrorCode.DATA_TYPE_ERROR, hl7Error.GetHl7ErrorCode(), "error message code"); }
private object DelegateToConcreteParser(ParseContext context, XmlNode node, BareANY hl7Result, XmlToModelResult xmlToModelResult ) { object result = null; string parentType = context == null ? null : context.Type; string specializationType = ObtainSpecializationType(parentType, node, xmlToModelResult); if (StringUtils.IsNotBlank(specializationType)) { string mappedSpecializationType = this.polymorphismHandler.MapCdaR1Type(StandardDataType.GetByTypeName(specializationType ), context.IsCda()); ElementParser elementParser = ParserRegistry.GetInstance().Get(mappedSpecializationType); if (elementParser == null || !IsValidTypeForAny(parentType, specializationType)) { xmlToModelResult.AddHl7Error(Hl7Error.CreateInvalidTypeError(specializationType, parentType, (XmlElement)node)); } else { BareANY parsedValue = elementParser.Parse(ParseContextImpl.CreateWithConstraints(mappedSpecializationType, DetermineReturnType (specializationType, GetReturnType(context)), context), Arrays.AsList(node), xmlToModelResult); result = parsedValue.BareValue; // Yes, this is a side effect of calling this method. If we don't do this then the actual type of the ANY.LAB (i.e. PQ.LAB) is lost. hl7Result.DataType = parsedValue.DataType; hl7Result.NullFlavor = parsedValue.NullFlavor; // preserve all metadata (yes, also not a great side effect); this will have to be adjusted whenever new metadata is added to a data type (extremely infrequently) if (hl7Result is ANYMetaData && parsedValue is ANYMetaData) { ANYMetaData anyMetaDataResult = (ANYMetaData)hl7Result; ANYMetaData anyMetaDataParsed = (ANYMetaData)parsedValue; anyMetaDataResult.Language = anyMetaDataParsed.Language; anyMetaDataResult.DisplayName = anyMetaDataParsed.DisplayName; anyMetaDataResult.OriginalText = anyMetaDataParsed.OriginalText; anyMetaDataResult.Translations.AddAll(anyMetaDataParsed.Translations); anyMetaDataResult.IsCdata = anyMetaDataParsed.IsCdata; anyMetaDataResult.Operator = anyMetaDataParsed.Operator; anyMetaDataResult.Unsorted = anyMetaDataParsed.Unsorted; } } } else { xmlToModelResult.AddHl7Error(Hl7Error.CreateMissingMandatoryAttributeError(AbstractElementParser.SPECIALIZATION_TYPE, (XmlElement )node)); } return(result); }
private void CreateError(string errorMessage, XmlElement element, string propertyPath, Hl7Errors errors, bool isTranslation ) { errorMessage = (isTranslation ? "(translation level) " : string.Empty) + errorMessage; Hl7Error error = null; if (element != null) { error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage + " (" + XmlDescriber.DescribeSingleElement(element) + ")" , element); } else { // assuming this has a property path error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage, propertyPath); } errors.AddHl7Error(error); }
private void ValidateMissingMandatoryNonStructuralRelationships(Hl7Source source, IDictionary <string, string> resolvedRelationshipNames ) { // compare xml provided elements with all known mandatory relationships (watch for nested) IList <Relationship> allRelationships = source.GetAllRelationships(); foreach (Relationship relationship in allRelationships) { // ignore structural - this has been checked elsewhere (and isn't contained in the resolved relationships anyway) if (!relationship.Structural && relationship.Cardinality.Min > 0) { if (!resolvedRelationshipNames.ContainsKey(GenerateRelationshipKey(relationship))) { Hl7Error error = new Hl7Error(relationship.Association ? Hl7ErrorCode.MANDATORY_ASSOCIATION_NOT_PROVIDED : Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED , "Relationship '" + relationship.Name + "' has a minimum cardinality greater than zero, but no value was provided.", source .GetCurrentElement()); source.GetResult().AddHl7Error(error); // check for missing fixed constraints ConstrainedDatatype constraints = source.GetService().GetConstraints(source.GetVersion(), relationship.ConstrainedType); if (constraints != null) { bool isTemplateId = constraints.Name.EndsWith("templateId"); foreach (Relationship constraint in constraints.Relationships) { if (constraint.HasFixedValue()) { string msg = System.String.Format("{0}.{1} property constrained to {2} but no value was provided.", relationship.Name, constraint .Name, constraint.FixedValue); Hl7ErrorCode errorCode = (isTemplateId ? Hl7ErrorCode.CDA_TEMPLATEID_FIXED_CONSTRAINT_MISSING : Hl7ErrorCode.CDA_FIXED_CONSTRAINT_MISSING ); source.GetResult().AddHl7Error(new Hl7Error(errorCode, ErrorLevel.WARNING, msg, source.GetCurrentElement())); } } } } } } }
private ParseContext HandleSpecializationType(ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult) { string specializationType = GetSpecializationType(node); if (specializationType == null) { // TM - RedMine issue 492 - there is some concern over MBT forcing a specialization type for abstract TS type TS_FULLDATEWITHTIME // - I'm relaxing this validation for the time being (the formatter currently ignores specialization type completely) // - (update: perhaps the real issue is that this was an IVL<TS.FULLDATEWITHTIME> and MB has a bug where inner types can't have specializationType set??) // TM - 16/10/2012 - should be able to set specialization type now (need to specify IVL_FULL_DATE_TIME as the specialization type for IVL<TS.FULLDATEWITHTIME>, for example) // - in a cowardly move, I have allowed for a system property to bypass this validation error if (Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(TsDateFormats.ABSTRACT_TS_IGNORE_SPECIALIZATION_TYPE_ERROR_PROPERTY_NAME ))) { } else { // do nothing - fall back to parsing through all allowable date formats for TS.FULLDATEWITHTIME xmlToModelResult.AddHl7Error(Hl7Error.CreateMissingMandatoryAttributeError(AbstractElementParser.SPECIALIZATION_TYPE, (XmlElement )node)); } } else { if (IsValidSpecializationType(specializationType)) { context = ParseContextImpl.Create(specializationType, context); } else { // log error - fall back to parsing through all allowable date formats for TS.FULLDATEWITHTIME xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Invalid specialization type " + specializationType + " (" + XmlDescriber.DescribeSingleElement((XmlElement)node) + ")", (XmlElement)node)); } } return(context); }
private IList <object> HandleCdaChoice(IList <XmlNode> nodes, string traversalName, Relationship relationship, Hl7Source source ) { IList <object> convertedBeans = new List <object>(); foreach (XmlNode node in nodes) { XmlElement childNode = (XmlElement)node; int currentNodeDepth = XmlDescriber.GetDepth(childNode); int currentErrorCount = source.GetResult().GetHl7Errors().Count; IList <Relationship> allChoiceTypes = DetermineAllChoiceTypes(relationship.Choices); Hl7SourceMapperChoiceCandidate choiceCandidate = null; Relationship choiceCandidateRelationship = null; bool foundMultipleChoiceCandidates = false; foreach (Relationship choiceType in allChoiceTypes) { Hl7PartSource childSource = source.CreatePartSourceForSpecificType(relationship, childNode, choiceType.Type); this.log.Debug("RECURSE for node=" + source.GetCurrentElement().Name + " - relationship=" + relationship.Name + ", tarversalName=" + traversalName + ", of type: " + childSource.Type); // after creating tealChild for each choiceType // - store tealChild // - store all new errors, removing them from the main error container object tealChild = MapPartSourceToTeal(childSource, relationship); Hl7SourceMapperChoiceCandidate newChoiceCandidate = new Hl7SourceMapperChoiceCandidate(tealChild); int newErrorsCount = (source.GetResult().GetHl7Errors().Count - currentErrorCount); for (int i = 0; i < newErrorsCount; i++) { IList <Hl7Error> hl7Errors = source.GetResult().GetHl7Errors(); Hl7Error removedError = hl7Errors[currentErrorCount]; hl7Errors.RemoveAt(currentErrorCount); //.NET conversion newChoiceCandidate.AddError(removedError); } if (newChoiceCandidate.IsAcceptableChoiceCandidate(currentNodeDepth)) { if (newChoiceCandidate.HasTemplateIdMatch(currentNodeDepth)) { // we'll take the first one that has a template id match, even if we found other acceptable candidates choiceCandidate = newChoiceCandidate; choiceCandidateRelationship = choiceType; foundMultipleChoiceCandidates = false; break; } else { if (choiceCandidate == null || choiceCandidateRelationship.DefaultChoice) { // we have found our first match, or we are dumping the default choice in favor of a better match choiceCandidate = newChoiceCandidate; choiceCandidateRelationship = choiceType; } else { if (!choiceType.DefaultChoice) { foundMultipleChoiceCandidates = true; } } } } } // else newChoiceCandidate is a default, and we ignore it in favor of the non-default we previously found // error if no candidates found if (choiceCandidate == null) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.CDA_NO_ACCEPTABLE_CHOICE_OPTION, ErrorLevel.WARNING, "Could not determine an appropriate match for a choice element: " + XmlDescriber.DescribePath(node), childNode)); } else { // error if multiple candidates found (excluding the default; but still take the first acceptable candidate) if (foundMultipleChoiceCandidates) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.CDA_MULTIPLE_CHOICE_OPTIONS_FOUND, ErrorLevel.WARNING, "Multiple appropriate matches for a choice element found - choosing first one: " + XmlDescriber.DescribePath(node), childNode)); } convertedBeans.Add(choiceCandidate.GetParsedBean()); source.GetResult().GetHl7Errors().AddAll(choiceCandidate.GetStoredErrors()); } } return(convertedBeans); }
public virtual void LogError(Hl7Error error) { }
public virtual void AddHl7Error(Hl7Error hl7Error) { this.hl7Errors.Add(hl7Error); }
internal virtual void AddError(Hl7Error error) { this.storedErrors.Add(error); }
public virtual void LogError(Hl7Error error) { this.result.AddHl7Error(error); }
private void RenderNonStructuralAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints , TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone) { string propertyPath = BuildPropertyPath(); BareANY hl7Value = tealBean.GetHl7Value(); string type = DetermineActualType(relationship, hl7Value, this.result, propertyPath); PropertyFormatter formatter = this.formatterRegistry.Get(type); if (formatter == null) { throw new RenderingException("Cannot support properties of type " + type); } else { string xmlFragment = string.Empty; try { BareANY any = null; bool isMandatoryOrPopulated = ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship ); if (relationship.HasFixedValue()) { // suppress rendering fixed values for optional or required if (isMandatoryOrPopulated) { any = (BareANY)DataTypeFactory.CreateDataType(relationship.Type, this.isCda && this.isR2); object fixedValue = NonStructuralHl7AttributeRenderer.GetFixedValue(relationship, version, this.isR2, this.result, propertyPath ); ((BareANYImpl)any).BareValue = fixedValue; } } else { any = hl7Value; any = this.adapterProvider.GetAdapter(any != null ? any.GetType() : null, type).Adapt(type, any); } // TODO - CDA - TM - implement default value handling // boolean valueNotProvided = (any.getBareValue() == null && !any.hasNullFlavor()); // if (valueNotProvided && relationship.hasDefaultValue() && isMandatoryOrPopulated) { // // FIXME - CDA - TM - this doesn't work - will have a class cast exception (put Object convert(Object/String?) on ANY, implement trivial in ANYImpl, implement where necessary?) // // any.setBareValue(relationship.getDefaultValue()); // } if (hl7Value != null && Hl7ValueHasContent(hl7Value)) { HandleNotAllowedAndIgnored(relationship, propertyPath); } FormatContext context = Ca.Infoway.Messagebuilder.Marshalling.FormatContextImpl.Create(this.result, propertyPath, relationship , version, dateTimeZone, dateTimeTimeZone, constraints, this.isCda); if (!StringUtils.Equals(type, relationship.Type)) { context = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, true, context); } xmlFragment += formatter.Format(context, any, GetIndent()); // if relationship specifies a namespace, need to add it to xml if (StringUtils.IsNotBlank(xmlFragment) & StringUtils.IsNotBlank(relationship.Namespaze)) { xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + " ", "<" + relationship .Namespaze + ":" + relationship.Name + " "); xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + ">", "<" + relationship .Namespaze + ":" + relationship.Name + ">"); xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "</" + relationship.Name + ">", "</" + relationship .Namespaze + ":" + relationship.Name + ">"); } } catch (ModelToXmlTransformationException e) { Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, e.Message, propertyPath); this.result.AddHl7Error(hl7Error); } RenderNewErrorsToXml(CurrentBuffer().GetChildBuilder()); CurrentBuffer().GetChildBuilder().Append(xmlFragment); } }