private void ValidateCardinality(FormatContext context, ICollection <BareANY> collection) { int size = collection.Count; int min = (int)context.GetCardinality().Min; int max = (int)context.GetCardinality().Max; if (size < min) { context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Number of elements (" + size + ") is less than the specified minimum (" + min + ")", context.GetPropertyPath())); } if (size > max) { context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Number of elements (" + size + ") is more than the specified maximum (" + max + ")", context.GetPropertyPath())); } }
protected virtual bool IsMandatoryOrPopulated(FormatContext context) { Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformance = context.GetConformanceLevel(); Cardinality cardinality = context.GetCardinality(); return(ConformanceLevelUtil.IsMandatory(conformance, cardinality) || ConformanceLevelUtil.IsPopulated(conformance, cardinality )); }
public override string Format(FormatContext context, BareANY hl7Value, int indentLevel) { string result = string.Empty; if (hl7Value != null) { V value = ExtractBareValue(hl7Value); Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel(); Cardinality cardinality = context.GetCardinality(); if (hl7Value.HasNullFlavor()) { result = CreateElement(context, CreateNullFlavorAttributes(hl7Value.NullFlavor), indentLevel, true, true); if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { CreateMissingMandatoryWarning(context); } } else { if (value == null || IsEmptyCollection(value)) { if (conformanceLevel == null || IsMandatoryOrPopulated(context)) { if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { result = CreateElement(context, AbstractPropertyFormatter.EMPTY_ATTRIBUTE_MAP, indentLevel, true, true); CreateMissingMandatoryWarning(context); } else { result = CreateElement(context, AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES, indentLevel, true, true); } } } else { result = FormatNonNullDataType(context, hl7Value, indentLevel); } } } return(result); }
private void HandleNullFlavor(CodedTypeR2 <Code> codedType, IDictionary <string, string> result, BareANY bareAny, FormatContext context) { if (bareAny != null && bareAny.HasNullFlavor()) { result.PutAll(CreateNullFlavorAttributes(bareAny.NullFlavor)); } else { if (codedType == null) { Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel(); Cardinality cardinality = context.GetCardinality(); if (conformanceLevel == null || ConformanceLevelUtil.IsPopulated(conformanceLevel, cardinality)) { result.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES); } } } }
public FormatContextImpl(string newType, string newElementName, FormatContext context) : this(newType, false, context.GetConformanceLevel (), context.GetCardinality(), newElementName, context) { }
public FormatContextImpl(string newType, bool isSpecializationType, FormatContext context) : this(newType, isSpecializationType , context.GetConformanceLevel(), context.GetCardinality(), context.GetElementName(), context) { }
public override string Format(FormatContext context, BareANY hl7Value, int indentLevel) { bool isAny = false; CD cd = null; if (hl7Value is CD) { cd = (CD)hl7Value; } else { isAny = true; // bypass some validations cd = ConvertAnyToCd(hl7Value); } StringBuilder result = new StringBuilder(); if (cd != null) { HandleConstraints(cd.Value, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult()); // don't bother validating if we don't have anything to validate if (cd.HasNullFlavor() || HasValue(cd, context)) { Hl7Errors errors = context.GetModelToXmlResult(); VersionNumber version = context.GetVersion(); string type = context.Type; bool isCne = context.GetCodingStrength() == CodingStrength.CNE; bool isCwe = context.GetCodingStrength() == CodingStrength.CWE; // we can't lookup a code supplied in an ANY datatype as we don't know the domain // a "reverse" lookup of domain type by code/codesystem could be possible, but difficult to implement to be 100% correct (MB does not track code systems) if (!isAny) { if (cd.Value != null && cd.Value.CodeValue != null) { ValidateCodeExists(cd.Value, context.GetDomainType(), version, context.IsCda(), context.GetPropertyPath(), errors); } } string codeAsString = (cd.Value != null ? cd.Value.CodeValue : null); CD_VALIDATION_UTILS.ValidateCodedType(cd, codeAsString, isCwe, isCne, false, context.IsFixed(), type, version, null, context .GetPropertyPath(), errors); } IDictionary <string, string> attributes = new Dictionary <string, string>(); Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel(); Cardinality cardinality = context.GetCardinality(); if (cd.HasNullFlavor()) { if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { LogMandatoryError(context); } else { attributes.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor)); } } else { if (!HasValue(cd, context)) { if (conformanceLevel == null || IsMandatoryOrPopulated(context)) { if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { LogMandatoryError(context); } else { attributes.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES); } } } } // Codes can have other attributes in map even if has NullFlavor attributes.PutAll(GetAttributeNameValuePairs(context, cd.Value, hl7Value)); bool hasChildContent = HasChildContent(cd, context); if (hasChildContent || (!attributes.IsEmpty() || ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))) { result.Append(CreateElement(context, attributes, indentLevel, !hasChildContent, !hasChildContent)); if (hasChildContent) { CreateChildContent(cd, result); result.Append("</").Append(context.GetElementName()).Append(">"); result.Append(SystemUtils.LINE_SEPARATOR); } } } return(result.ToString()); }
private void HandleConstraints(Identifier identifier, FormatContext context) { ErrorLogger logger = new _ErrorLogger_164(context); this.constraintsHandler.HandleConstraints(context.GetConstraints(), identifier, logger, IsSingleCardinality(context.GetCardinality ())); }
public override string Format(FormatContext formatContext, BareANY hl7Value, int indentLevel) { if (hl7Value == null) { return(string.Empty); } string specializationType = hl7Value.DataType.Type; StandardDataType specializationTypeAsEnum = StandardDataType.GetByTypeName(specializationType); if (specializationTypeAsEnum != null && StandardDataType.ANY.Equals(specializationTypeAsEnum.RootDataType)) { // specializationType has been determined to be an ANY variant; this (most likely) means specializationType has not been specified, so don't do any special processing return(base.Format(formatContext, hl7Value, indentLevel)); } else { string mappedSpecializationType = this.polymorphismHandler.MapCdaR1Type(hl7Value.DataType, formatContext.IsCda()); PropertyFormatter formatter = FormatterRegistry.GetInstance().Get(mappedSpecializationType); string parentType = formatContext.Type; if (formatter == null || !AnyHelper.IsValidTypeForAny(parentType, specializationType)) { string errorText = "Cannot support properties of type " + specializationType + " for " + parentType + ". Please specify a specializationType applicable for " + parentType + " in the appropriate message bean."; throw new ModelToXmlTransformationException(errorText); } else { // pass processing off to the formatter applicable for the given specializationType StandardDataType type = hl7Value.DataType; return(formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(formatContext.GetModelToXmlResult (), formatContext.GetPropertyPath(), formatContext.GetElementName(), mappedSpecializationType, type.Coded ? "Code" : formatContext .GetDomainType(), formatContext.GetConformanceLevel(), formatContext.GetCardinality(), true, formatContext.GetVersion(), formatContext.GetDateTimeZone(), formatContext.GetDateTimeTimeZone(), null, formatContext.GetConstraints(), formatContext .IsCda()), hl7Value, indentLevel)); } } }
// only checking II constraints for now protected virtual FormatContext CreateSubContext(FormatContext context) { return(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(context.GetModelToXmlResult(), context.GetPropertyPath (), context.GetElementName(), GetSubType(context), context.GetDomainType(), context.GetConformanceLevel(), context.GetCardinality (), context.IsSpecializationType(), context.GetVersion(), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), null , null, context.IsCda())); }