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 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)) { // check if this pattern is missing a timezone if (!IsCerx(standardDataType, version) && TsDateFormats.datetimeFormatsRequiringWarning.Contains(datePattern)) { context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Date format {0} supplied for value of type {1} should also have a timezone (ZZZZZ)" , datePattern, context == null ? "TS" : context.Type), context.GetPropertyPath())); } } else { // MBR-368: a temporary work-around for producing AB PIN compliant date time renderings // with out error messages -- required until the runtime's knowledge of datatypes has been // corrected to distinguish between CeRx v3 (ie., V01R03) and CeRx v4 (ie., V01R04) if (!SpecificationVersion.IsExactVersion(SpecificationVersion.V01R04_1_AB, version)) { context.GetModelToXmlResult().AddHl7Error(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())); } } }
protected override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel) { IDictionary <string, string> attributeMap = new Dictionary <string, string>(); string useAttribute = GetUseAttribute(context.Type, postalAddress, context.GetVersion().GetBaseVersion()); if (StringUtils.IsNotBlank(useAttribute)) { attributeMap["use"] = useAttribute; } Boolean?isNotOrdered = postalAddress.IsNotOrdered; if (isNotOrdered != null) { attributeMap["isNotOrdered"] = isNotOrdered.ToString().ToLower(); } //lowercase for .NET StringBuilder buffer = new StringBuilder(); buffer.Append(CreateElement(context, attributeMap, indentLevel, false, true)); foreach (PostalAddressPart postalAddressPart in postalAddress.Parts) { AppendPostalAddressPart(buffer, postalAddressPart, indentLevel + 1); } IDictionary <PlatformDate, SetOperator> useablePeriods = postalAddress.UseablePeriods; foreach (PlatformDate date in useablePeriods.Keys) { SetOperator @operator = useablePeriods.SafeGet(date); AppendUseablePeriod(buffer, date, @operator, indentLevel + 1, context); } buffer.Append(CreateElementClosure(context, indentLevel, true)); return(buffer.ToString()); }
protected override void AddOtherAttributesIfNecessary(TelecommunicationAddress phonemail, IDictionary <string, string> attributes , FormatContext context, BareANY bareAny) { VersionNumber version = context.GetVersion(); string type = (bareAny == null || bareAny.DataType == null) ? null : bareAny.DataType.Type; string actualType = TEL_VALIDATION_UTILS.DetermineActualType(phonemail, context.Type, type, version, null, context.GetPropertyPath (), context.GetModelToXmlResult(), false); if (!context.Type.Equals(actualType)) { // excluding our test NFLD version to allow legacy tests to pass if (!"NEWFOUNDLAND".Equals(version == null ? null : version.VersionLiteral)) { AddSpecializationType(attributes, actualType); } } if (!phonemail.AddressUses.IsEmpty()) { StringBuilder useValue = new StringBuilder(); bool isFirst = true; foreach (Ca.Infoway.Messagebuilder.Domainvalue.TelecommunicationAddressUse addressUse in phonemail.AddressUses) { if (TEL_VALIDATION_UTILS.IsAllowableUse(actualType, addressUse, version)) { if (!isFirst) { useValue.Append(XmlRenderingUtils.SPACE); } useValue.Append(addressUse.CodeValue); isFirst = false; } } attributes["use"] = useValue.ToString(); } }
private void Validate(FormatContext context, BareANY dataType, EncapsulatedData encapsulatedData) { string type = context.Type; string specializationType = dataType.DataType == null ? null : dataType.DataType.Type; Hl7BaseVersion baseVersion = context.GetVersion().GetBaseVersion(); Hl7Errors errors = context.GetModelToXmlResult(); this.edValidationUtils.DoValidate(encapsulatedData, specializationType, baseVersion, type, context.GetPropertyPath(), errors ); }
protected sealed override string GetValue(TelecommunicationAddress uri, FormatContext context, BareANY bareAny) { string type = context.Type; StandardDataType specializationType = bareAny.DataType; VersionNumber version = context.GetVersion(); Hl7Errors errors = context.GetModelToXmlResult(); TEL_VALIDATION_UTILS.ValidateTelecommunicationAddress(uri, type, specializationType.Type, version, null, context.GetPropertyPath (), errors); return(uri.ToString()); }
private bool RequiresSpecializationType(FormatContext formatContext) { bool result = true; if (formatContext != null && formatContext.GetVersion() != null) { result = !SpecificationVersion.IsVersion(StandardDataType.GTS_BOUNDEDPIVL, formatContext.GetVersion(), Hl7BaseVersion.CERX ); } return(result); }
private bool RequiresOperatorOnFirstRepetition(FormatContext formatContext) { bool result = false; if (formatContext != null && formatContext.GetVersion() != null) { result = SpecificationVersion.IsVersion(StandardDataType.GTS_BOUNDEDPIVL, formatContext.GetVersion(), Hl7BaseVersion.CERX ) || SpecificationVersion.IsVersion(StandardDataType.GTS_BOUNDEDPIVL, formatContext.GetVersion(), Hl7BaseVersion.MR2007); } return(result); }
protected override IDictionary <string, string> GetAttributeNameValuePairs(FormatContext context, Identifier ii, BareANY bareAny ) { VersionNumber version = context.GetVersion(); IDictionary <string, string> result = new Dictionary <string, string>(); string typeFromContext = context.Type; ii = Validate(ii, typeFromContext, version, context); AddStandardAttributes(ii, result); return(result); }
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 ValidatePhysicalQuantity(FormatContext context, PhysicalQuantity physicalQuantity, BareANY bareANY) { // does not validate originalText here as this section is bypassed when value is a NullFlavor string type = context.Type; ModelToXmlResult errors = context.GetModelToXmlResult(); bool hasNullFlavor = (bareANY == null || bareANY.NullFlavor != null); string quantityAsString = physicalQuantity.Quantity == null ? null : physicalQuantity.Quantity.ToPlainString(); this.pqValidationUtils.ValidateValue(quantityAsString, context.GetVersion(), type, hasNullFlavor, null, context.GetPropertyPath (), errors); string unitsAsString = (physicalQuantity.Unit == null ? null : physicalQuantity.Unit.CodeValue); this.pqValidationUtils.ValidateUnits(type, unitsAsString, null, context.GetPropertyPath(), errors, false); }
private string HandleSpecializationType(BareANY bareAny, FormatContext context, IDictionary <string, string> result) { string typeFromContext = context.Type; string typeFromField = bareAny.DataType == null ? null : bareAny.DataType.Type; if (iiValidationUtils.IsSpecializationTypeRequired(context.GetVersion(), typeFromContext, context.IsCda())) { bool validSpecializationType = IsSpecializationTypeProvided(typeFromContext, typeFromField); if (iiValidationUtils.IsII(typeFromContext)) { validSpecializationType &= IiValidationUtils.concreteIiTypes.Contains(typeFromField); } else { if (iiValidationUtils.IsIiBusAndVer(typeFromContext)) { validSpecializationType &= iiValidationUtils.IsIiBusOrIiVer(typeFromField); } } // only override type if new type is valid if (validSpecializationType) { typeFromContext = typeFromField; AddSpecializationTypeAttributesBasedOnVersion(result, typeFromContext, context.GetVersion()); } else { if (iiValidationUtils.IsIiBusAndVer(typeFromContext)) { AddSpecializationTypeAttributesBasedOnVersion(result, IiValidationUtils.II_BUS, context.GetVersion()); typeFromContext = IiValidationUtils.II_BUS; RecordError(iiValidationUtils.GetInvalidSpecializationTypeForBusAndVerErrorMessage(typeFromField, typeFromContext), context ); } else { RecordError(iiValidationUtils.GetInvalidOrMissingSpecializationTypeErrorMessage(typeFromField), context); } } } else { if (IsSpecializationTypeProvided(typeFromContext, typeFromField)) { RecordError(iiValidationUtils.GetShouldNotProvideSpecializationTypeErrorMessage(typeFromContext), context); } } return(typeFromContext); }
protected override string FormatNonNullValue(FormatContext context, TelecommunicationAddress value, int indentLevel) { // any validation that can be done for R2?? // scheme/address cannot be null bool hasUseablePeriods = !value.UseablePeriods.IsEmpty(); StringBuilder buffer = new StringBuilder(); buffer.Append(CreateElement(context, GetAttributesMap(value, context.GetVersion()), indentLevel, !hasUseablePeriods, true )); if (hasUseablePeriods) { AppendUseablePeriods(value, buffer, indentLevel + 1, context); buffer.Append(CreateElementClosure(context, indentLevel, true)); } return(buffer.ToString()); }
protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel) { Hl7BaseVersion baseVersion = context.GetVersion().GetBaseVersion(); string dataType = context.Type; AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, dataType, context.GetVersion(), null , context.GetPropertyPath(), context.GetModelToXmlResult()); PostalAddress basicAddress = new PostalAddress(); StringBuilder builder = new StringBuilder(); // remove any non-basic address parts foreach (PostalAddressPart part in EmptyIterable <object> .NullSafeIterable(postalAddress.Parts)) { if (part.Type == PostalAddressPartType.CITY || part.Type == PostalAddressPartType.STATE || part.Type == PostalAddressPartType .COUNTRY || part.Type == PostalAddressPartType.POSTAL_CODE || part.Type == PostalAddressPartType.DELIMITER) { Flush(builder, basicAddress); basicAddress.AddPostalAddressPart(part); } else { if (StringUtils.IsNotBlank(part.Value)) { if (builder.Length > 0) { builder.Append(" "); } builder.Append(part.Value); } } } Flush(builder, basicAddress); foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse use in postalAddress.Uses) { if (AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.IsAllowableUse(dataType, use, baseVersion)) { basicAddress.AddUse(use); } } return(base.FormatNonNullValue(context, basicAddress, indentLevel)); }
public FormatContextImpl(string newType, bool isSpecializationType, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel newConformanceLevel , Cardinality newCardinality, string elementName, FormatContext context) : this(context.GetModelToXmlResult(), context.GetPropertyPath (), elementName, newType, context.GetDomainType(), newConformanceLevel, newCardinality, isSpecializationType, context.GetVersion (), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), context.GetCodingStrength(), null, context.IsCda()) { }
private VersionNumber GetVersion(FormatContext context) { return(context == null ? null : context.GetVersion()); }
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 ValidateDatePattern(string datePattern, FormatContext context) { string[] allowedDateFormats = TsDateFormats.GetAllDateFormats(StandardDataType.TS_DATETIME, context.GetVersion()); if (!ArrayContains(allowedDateFormats, datePattern)) { context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Unknown date format {0} supplied for value of type {1}" , datePattern, context == null ? "TS" : context.Type), context.GetPropertyPath())); } }
protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel) { AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, context.Type, context.GetVersion(), null, context.GetPropertyPath(), context.GetModelToXmlResult()); return(base.FormatNonNullValue(context, postalAddress, indentLevel)); }
private void AppendIntervalBounds(PeriodicIntervalTime value, StringBuilder buffer, int indentLevel, FormatContext context ) { string period = CreatePeriodElement(value.Period, indentLevel, context); string phase = CreatePhaseElement(value.Phase, indentLevel, context); switch (value.Representation) { case Representation.PERIOD: { buffer.Append(period); break; } case Representation.PHASE: { buffer.Append(phase); break; } case Representation.PERIOD_PHASE: { buffer.Append(period); buffer.Append(phase); break; } case Representation.FREQUENCY: { // Change for Saskatchewan bool isSask = SpecificationVersion.IsExactVersion(SpecificationVersion.V01R04_2_SK, context != null ? context.GetVersion( ) : null); if (isSask && value is PeriodicIntervalTimeSk) { buffer.Append(CreateFrequencyElementForSk(FREQUENCY, value.Repetitions, ((PeriodicIntervalTimeSk)value).QuantitySk, indentLevel , context)); } else { buffer.Append(CreateFrequencyElement(value.Repetitions, value.Quantity, indentLevel, context)); } break; } default: { break; } } }
protected override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel) { StringBuilder buffer = new StringBuilder(); IDictionary <string, string> useAttributeMap = GetUseAttributeMap(context.Type, postalAddress, context.GetVersion().GetBaseVersion ()); buffer.Append(CreateElement(context, useAttributeMap, indentLevel, false, false)); foreach (PostalAddressPart postalAddressPart in postalAddress.Parts) { if (AD_VALIDATION_UTILS.IsAllowableAddressPart(postalAddressPart.Type, context.Type)) { AppendPostalAddressPart(buffer, postalAddressPart); } } buffer.Append(CreateElementClosure(context, 0, true)); return(buffer.ToString()); }
// 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())); }
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()); }
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)); } } }