コード例 #1
0
ファイル: HtmlTables.cs プロジェクト: x97mdr/fitsharp
            Tree <CellBase> ParseElement(LexicalAnalyzer theAnalyzer)
            {
                string tag    = theAnalyzer.Token;
                string leader = theAnalyzer.Leader;

                theAnalyzer.PushEnd("/" + myKeyword);
                List <Tree <CellBase> > children = myChildParser.Parse(theAnalyzer);

                if (IRequireChildren && children.Count == 0)
                {
                    throw new ApplicationException(string.Format("Can't find tag: {0}", myChildParser.Keyword));
                }
                theAnalyzer.PopEnd();
                theAnalyzer.GoToNextToken("/" + myKeyword);
                if (theAnalyzer.Token.Length == 0)
                {
                    throw new ApplicationException("expected /" + myKeyword + " tag");
                }
                var result = new TreeList <CellBase>(new CellBase(HtmlToText(theAnalyzer.Leader)));

                result.Value.SetAttribute(CellAttribute.Body, theAnalyzer.Leader);
                result.Value.SetAttribute(CellAttribute.EndTag, theAnalyzer.Token);
                result.Value.SetAttribute(CellAttribute.Leader, leader);
                result.Value.SetAttribute(CellAttribute.StartTag, tag);
                foreach (Tree <CellBase> child in children)
                {
                    result.AddBranch(child);
                }
                return(result);
            }
コード例 #2
0
        private Int32?ParseNumerator(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult)
        {
            ElementParser parser     = ParserRegistry.GetInstance().Get("INT.NONNEG");
            ParseContext  subContext = ParseContextImpl.Create("INT.NONNEG", typeof(Int32?), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((Int32?)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
コード例 #3
0
        private PhysicalQuantity ParseDenominator(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult)
        {
            ElementParser parser     = ParserRegistry.GetInstance().Get("PQ.TIME");
            ParseContext  subContext = ParseContextImpl.Create("PQ.TIME", typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((PhysicalQuantity)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
コード例 #4
0
        private CSConvert(StreamReader _sr)
        {
            result.Clear();

            List <string> readList = StreamParser.Parse(_sr);

            ElemRoot elem = ElementParser.Parse(readList);

            result.AddRange(elem.Collecting().ToList());
        }
コード例 #5
0
        private Interval <PhysicalQuantity> ParseDenominatorSk(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult
                                                               )
        {
            // TM - Unsure if SK is allowed to send in any kind of PQ, or only specific ones. Picked PQ.BASIC to cover most scenarios.
            ElementParser parser     = ParserRegistry.GetInstance().Get("IVL<PQ.BASIC>");
            ParseContext  subContext = ParseContextImpl.Create("IVL<PQ.BASIC>", typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((Interval <PhysicalQuantity>)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
コード例 #6
0
        private BareANY CreateType(ParseContext context, XmlElement element, XmlToModelResult parseResult)
        {
            string        type   = GetParameterizedType(context);
            ElementParser parser = ParserRegistry.GetInstance().Get(type);

            if (parser != null)
            {
                return(parser.Parse(ParseContextImpl.CreateWithConstraints(type, context), Arrays.AsList((XmlNode)element), parseResult));
            }
            else
            {
                parseResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Cannot find a parser for type {0}"
                                                                                                        , type), element));
                return(null);
            }
        }
コード例 #7
0
        // only checking II constraints for now
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        public override BareANY Parse(ParseContext context, IList <XmlNode> nodes, XmlToModelResult xmlToModelResult)
        {
            string subType             = GetSubType(context);
            ICollection <BareANY> list = GetCollectionType(context);

            ValidateCardinality(context, nodes, xmlToModelResult);
            foreach (XmlNode node in nodes)
            {
                string        actualType = DetermineActualType(node, subType, context.IsCda(), xmlToModelResult);
                ElementParser parser     = this.parserRegistry.Get(actualType);
                if (parser != null)
                {
                    BareANY result = parser.Parse(ParseContextImpl.Create(actualType, GetSubTypeAsModelType(context), context), ToList(node),
                                                  xmlToModelResult);
                    // constraints are *not* passed down with collections
                    if (result != null)
                    {
                        if (!StringUtils.Equals(subType, actualType))
                        {
                            result.DataType = StandardDataType.GetByTypeName(actualType);
                        }
                        if (list.Contains(result))
                        {
                            ResultAlreadyExistsInCollection(result, (XmlElement)node, xmlToModelResult);
                        }
                        list.Add(result);
                    }
                }
                else
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "No parser type found for " + actualType, (XmlElement
                                                                                                                                      )node));
                }
            }
            HandleConstraints(subType, list, context.GetConstraints(), nodes, xmlToModelResult);
            BareANY wrapResult = null;

            try
            {
                wrapResult = WrapWithHl7DataType(context.Type, subType, list, context);
            }
            catch (MarshallingException e)
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, e.Message, (string)null));
            }
            return(wrapResult);
        }
コード例 #8
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        private void WriteAttribute(BeanWrapper bean, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName
                                    )
        {
            if (relationship.Structural)
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Data found for relationship as an element but should have been an attribute. "
                                                            + (nodes.IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ?
                                                            null : (XmlElement)nodes[0]));
            }
            string        type   = DetermineType(nodes, relationship, source, source.GetResult());
            ElementParser parser = (source.IsR2() ? ParserR2Registry.GetInstance().Get(type) : ParserRegistry.GetInstance().Get(type)
                                    );

            if (parser != null)
            {
                try
                {
                    ConstrainedDatatype constraints = source.GetService().GetConstraints(source.GetVersion(), relationship.ConstrainedType);
                    ParseContextImpl    context     = new ParseContextImpl(relationship, constraints, source.GetVersion(), source.GetDateTimeZone(),
                                                                           source.GetDateTimeTimeZone(), CodeTypeRegistry.GetInstance(), source.IsCda());
                    BareANY @object = parser.Parse(context, nodes, source.GetResult());
                    ChangeDatatypeIfNecessary(type, relationship, @object);
                    if (relationship.HasFixedValue())
                    {
                        ValidateNonstructuralFixedValue(relationship, @object, source, nodes);
                    }
                    else
                    {
                        // fixed means nothing to write to bean
                        bean.Write(relationship, @object);
                    }
                }
                catch (InvalidCastException e)
                {
                    source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Can't parse relationship name=" + relationship.
                                                                Name + ", traversalName=" + traversalName + " [" + e.Message + "]", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[
                                                                    0]));
                }
            }
            else
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "No parser for type \"" + type + "\". " + (nodes
                                                                                                                                    .IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ? null : (
                                                                XmlElement)nodes[0]));
            }
        }
コード例 #9
0
        public void NotSupportDataSourceTest()
        {
            var dataSourceLocation = new XMLDataSourceLocation("", "");
            var mockDataToImport   = new Mock <IDataToImport>();

            var parserFactory = new DefaultParserFactory();

            var testCellParser = new ElementParser(parserFactory);

            var testParsingResult = testCellParser.Parse(mockDataToImport.Object, dataSourceLocation, typeof(int)) as ParsingResult;


            Assert.NotNull(testParsingResult);
            Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level);
            Assert.AreEqual("Castle.Proxies.IDataToImportProxy is not supported by XML Node Parser", testParsingResult.Message);
            Assert.Null(testParsingResult.Value);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        private void txtHtml_TextChanged(object sender, EventArgs e)
        {
            this.dgvAttributes.Tag = "busy";
            string        html   = this.txtHtml.Text;
            ElementParser parser = new ElementParser();

            this.elementInfo              = parser.Parse(html);
            this.txtTagName.Text          = this.elementInfo.TagName;
            this.dgvAttributes.DataSource = null;
            this.dgvAttributes.Rows.Clear();
            if (this.elementInfo.Attributes != null)
            {
                foreach (KeyValuePair <string, string> kv in this.elementInfo.Attributes)
                {
                    this.dgvAttributes.Rows.Add(kv.Key, kv.Value);
                }
            }
            this.dgvAttributes.Tag = "";
            GenerateSelector(null, null);
        }
コード例 #12
0
        public void ParsingSuccessTest()
        {
            var path               = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml");
            var dataSource         = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();
            var dataToImport       = new XMLDataToImport(dataFromFileSystem);

            var dataSourceLocation = new XMLDataSourceLocation("LabReport", "Lab_Report_Number");

            var parserFactory = new DefaultParserFactory();

            var testCellParser = new ElementParser(parserFactory);

            var testParsingResult = testCellParser.Parse(dataToImport, dataSourceLocation, typeof(string)) as ParsingResult;

            Assert.NotNull(testParsingResult);
            Assert.AreEqual(ResultLevel.INFO, testParsingResult.Level);
            Assert.AreEqual("Parsing value successfully", testParsingResult.Message);
            Assert.AreEqual("LR04927", testParsingResult.Value);
        }
コード例 #13
0
        public void OutOfRangeTest()
        {
            var path               = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml");
            var dataSource         = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();

            var dataSourceLocation = new XMLDataSourceLocation("here", "there");
            var dataToImport       = new XMLDataToImport(dataFromFileSystem);

            var parserFactory = new DefaultParserFactory();

            var testElementParser = new ElementParser(parserFactory);

            var testParsingResult = testElementParser.Parse(dataToImport, dataSourceLocation, typeof(int)) as ParsingResult;


            Assert.NotNull(testParsingResult);
            Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level);
            //Assert.AreEqual("Argument is out of range", testParsingResult.Message);
            Assert.Null(testParsingResult.Value);
        }
コード例 #14
0
        private Diff <PlatformDate> CreateDateDiff(ParseContext context, XmlElement width, XmlToModelResult xmlToModelResult)
        {
            Diff <PlatformDate> result = null;

            if (GetAttributeValue(width, NullFlavorHelper.NULL_FLAVOR_ATTRIBUTE_NAME) != null)
            {
                result = ParseNullWidthNode(width);
            }
            else
            {
                try
                {
                    StandardDataType diffType = StandardDataType.PQ_TIME;
                    ElementParser    parser   = ParserRegistry.GetInstance().Get(diffType);
                    if (parser != null)
                    {
                        ParseContext subContext = ParseContextImpl.Create(diffType.Type, typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                                          .POPULATED, Cardinality.Create("1"), context);
                        PhysicalQuantity quantity = (PhysicalQuantity)parser.Parse(subContext, Arrays.AsList((XmlNode)width), xmlToModelResult).BareValue;
                        // though in some PQ cases units can be null, this situation does not seem to make sense for PQ.TIME
                        if (quantity != null && quantity.Quantity != null && quantity.Unit != null)
                        {
                            result = new DateDiff(quantity);
                        }
                    }
                    else
                    {
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Cannot find a parser for " + diffType.Type, width
                                                                  ));
                    }
                }
                catch (XmlToModelTransformationException e)
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, e.Message, width));
                }
            }
            return(result);
        }