Example #1
0
        public virtual void HandleConstraints(ConstrainedDatatype constraints, EncapsulatedData ed, ErrorLogger logger)
        {
            if (ed == null || constraints == null)
            {
                return;
            }
            TelecommunicationAddress reference = ed.ReferenceObj;

            // ignoring any fixed value returned from reference constraints checking
            this.constraintsHandler.ValidateConstraint("reference", reference == null ? null : "reference", constraints, logger);
            // just checks if reference provided
            if (reference != null)
            {
                // only check this constraint if a reference has been provided (whether the reference was mandatory or not)
                string referenceValue = reference.ToString();
                this.constraintsHandler.ValidateConstraint("reference.value", referenceValue, constraints, logger);
            }
            // checks for actual value
            string mediaType    = ed.MediaType == null ? null : ed.MediaType.CodeValue;
            string newMediaType = this.constraintsHandler.ValidateConstraint("mediaType", mediaType, constraints, logger);

            if (!StringUtils.Equals(mediaType, newMediaType))
            {
                x_DocumentMediaType newMediaTypeEnum = Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_DocumentMediaType.Get(newMediaType);
                if (newMediaTypeEnum != null)
                {
                    ed.MediaType = newMediaTypeEnum;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Constructs a CompressData object given the supplied parameters.
 /// </summary>
 ///
 /// <param name="mediaType">a media type</param>
 /// <param name="reference">a reference</param>
 /// <param name="content">the data content</param>
 /// <param name="compression_0">a compression type</param>
 /// <param name="language_1">a language</param>
 public CompressedData(
     x_DocumentMediaType mediaType,
     String reference, byte[] content, Compression compression_0,
     String language_1)
     : base(mediaType, reference, language_1, content)
 {
     base.Compression = compression_0;
 }
Example #3
0
 public EncapsulatedData(
     x_DocumentMediaType mediaType_0,
     String reference_1, String lanuage_2, byte[] content_3)
 {
     MediaType    = mediaType_0;
     Language     = lanuage_2;
     this.content = content_3 == null || content_3.Length == 0 ? null : XmlStringEscape.Escape(ASCIIEncoding.ASCII.GetString(content_3));
     if (!StringUtils.IsBlank(reference_1))
     {
         String[] parts = reference_1.Split(new string[] { "://" }, StringSplitOptions.None);
         if (parts.Length > 0)
         {
             Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme urlsScheme = null;
             if (parts.Length > 1)
             {
                 urlsScheme = Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme.ValueOf <Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme>(
                     typeof(Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme), parts[0]);
             }
             String address = (parts.Length > 1 ? parts[1] : parts[0]);
             ReferenceObj = new TelecommunicationAddress(urlsScheme, address);
         }
     }
 }
Example #4
0
 public virtual void DoValidate(string specializationType, Compression compression, bool hasCompression, x_DocumentMediaType
                                mediaType, string language, string representation, bool hasReference, bool hasContent, int contentSize, Hl7BaseVersion
                                baseVersion, string type, XmlElement element, string propertyPath, Hl7Errors errors)
 {
     // specializationType - must be provided for ED.DOCORREF *except* for CeRx; must be ED.DOC or ED.DOCREF
     if (StandardDataType.ED_DOC_OR_REF.Type.Equals(type) && !Hl7BaseVersion.CERX.Equals(baseVersion))
     {
         if (StringUtils.IsBlank(specializationType) || StandardDataType.ED.Type.Equals(specializationType))
         {
             // must specify
             type = (!hasContent ? StandardDataType.ED_DOC_REF.Type : StandardDataType.ED_DOC.Type);
             CreateError("Must specify specializationType for ED.DOC_OR_REF types. Value will be treated as " + type + ".", element, propertyPath
                         , errors);
         }
         else
         {
             if (!(StandardDataType.ED_DOC.Type.Equals(specializationType) || StandardDataType.ED_DOC_REF.Type.Equals(specializationType
                                                                                                                      )))
             {
                 // must be doc or docref; default to something suitable
                 type = (!hasContent ? StandardDataType.ED_DOC_REF.Type : StandardDataType.ED_DOC.Type);
                 CreateError("Invalid specializationType: " + specializationType + ". The specializationType must be ED.DOC or ED.DOCREF for ED.DOC_OR_REF types. Value will be treated as "
                             + type + ".", element, propertyPath, errors);
             }
             else
             {
                 type = specializationType;
             }
         }
     }
     // compression - required, must be DF or GZ
     //             - only GZ for CeRx (ED.DOCORREF), and only allowed if content present
     //             - not permitted for ED.REF
     if (hasCompression)
     {
         if (StandardDataType.ED_REF.Type.Equals(type))
         {
             // not allowed
             CreateError("Compression not allowed for ED.REF types.", element, propertyPath, errors);
         }
         else
         {
             if (Hl7BaseVersion.CERX.Equals(baseVersion) && (compression == null || !Compression.GZIP.CompressionType.Equals(compression
                                                                                                                             .CompressionType)))
             {
                 // only GZ allowed in this case
                 CreateError("Only GZ compression allowed for CeRx ED.DOCORREF type.", element, propertyPath, errors);
             }
             else
             {
                 if (compression == null || (!Compression.GZIP.CompressionType.Equals(compression.CompressionType) && !Compression.DEFLATE
                                             .CompressionType.Equals(compression.CompressionType)))
                 {
                     // only DF or GZ
                     CreateError("Compression must be DF or GZ.", element, propertyPath, errors);
                 }
             }
         }
     }
     // mediatype - mandatory; value from x_DocumentMediaType
     //           - ED.DOC/ED.DOCREF/MR2007, ED.DOCORREF/ED.REF/CeRx: restricted to "text/plain", "text/html", "text/xml", "application/pdf"
     if (mediaType == null)
     {
         // must be provided, and must be acceptable value
         CreateError("MediaType must be provided and must be a value from x_DocumentMediaType.", element, propertyPath, errors);
     }
     // language - required, 2-2
     //          - "eng" or "fre" (CeRx)
     if (StringUtils.IsNotBlank(language))
     {
         if (Hl7BaseVersion.CERX.Equals(baseVersion))
         {
             if (!CERX_ENGLISH.EqualsIgnoreCase(language) && !CERX_FRENCH.EqualsIgnoreCase(language))
             {
                 // incorrect language for CeRx
                 CreateError("The language attribute must be one of 'eng' or 'fre'.", element, propertyPath, errors);
             }
         }
         else
         {
             if (language.Length != 5 || (language[2] != '-'))
             {
                 // needs to be a language code (yes, the above check isn't perfect, but it should be fine for most cases)
                 CreateError("The language attribute must be a 2-letter language code, followed by a hyphen, followed by a 2-letter country code."
                             , element, propertyPath, errors);
             }
         }
     }
     // representation - TXT or B64; vague on if this is mandatory or not; not permitted for CeRx
     if (StringUtils.IsNotBlank(representation))
     {
         if (!REPRESENTATION_TXT.EqualsIgnoreCase(representation) && !REPRESENTATION_B64.EqualsIgnoreCase(representation))
         {
             // error
             CreateError("The representation attribute must be one of 'TXT' or 'B64'.", element, propertyPath, errors);
         }
     }
     // reference - required; must be TEL.URI (mandatory for ED.DOCREF)
     //           - CeRx: only allowed (and mandatory?) if content not present; must be FTP, HTTP, HTTPS  (ED.REF, ED.DOCORREF)
     if (!hasReference)
     {
         if (StandardDataType.ED_DOC_REF.Type.Equals(type) || StandardDataType.ED_REF.Type.Equals(type))
         {
             // mandatory case
             CreateError("Reference is mandatory.", element, propertyPath, errors);
         }
     }
     if (element != null && element.HasAttribute(ELEMENT_REFERENCE))
     {
         CreateError("Reference is not allowed as an attribute; it should be in a <reference> element having a value attribute containing the actual reference."
                     , element, propertyPath, errors);
     }
     // content - max 1 MB after compression and base64 encoding; compressed or pdf must be b64-encoded; any checks done on this??
     //         - mandatory for ED.DOC, ED.DOCORREF/CeRx (if no ref provided)
     //         - not permitted for ED.DOCREF/ED.REF
     if (hasContent && contentSize > 0)
     {
         if (StandardDataType.ED_DOC_REF.Type.Equals(type) || StandardDataType.ED_REF.Type.Equals(type))
         {
             // not permitted
             CreateError("Content is not permitted for " + type + ".", element, propertyPath, errors);
         }
         if (contentSize > ONE_MEGABYTE_SIZE)
         {
             // too large
             CreateError("Content must be less than 1 MB.", element, propertyPath, errors);
         }
     }
     else
     {
         if (StandardDataType.ED_DOC.Type.Equals(type))
         {
             // must be provided
             CreateError("Content must be provided for " + type + ".", element, propertyPath, errors);
         }
     }
     if (Hl7BaseVersion.CERX.Equals(baseVersion) && StandardDataType.ED_DOC_OR_REF.Type.Equals(type))
     {
         if (hasReference && hasContent)
         {
             // can't provide both
             CreateError("Cannot provide both content and reference.", element, propertyPath, errors);
         }
         else
         {
             if (!hasReference && !hasContent)
             {
                 // must provide one
                 CreateError("Must provide one and only one of content or reference.", element, propertyPath, errors);
             }
         }
     }
 }
Example #5
0
        /// <exception cref="System.Exception"></exception>
        private EncapsulatedData CreateEd(bool createReference, bool createReferenceValue, x_DocumentMediaType mediaType)
        {
            EncapsulatedData ed = new EncapsulatedData();

            if (createReference)
            {
                ed.ReferenceObj = new TelecommunicationAddress();
                if (createReferenceValue)
                {
                    ed.ReferenceObj.UrlScheme = Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme.TEL;
                    ed.ReferenceObj.Address   = "4167620032";
                }
            }
            if (mediaType != null)
            {
                ed.MediaType = mediaType;
            }
            ed.Content = "some content";
            return(ed);
        }