예제 #1
0
        public void CustomerOrdersRead()
        {
            var engine = new MasterDetailEngine(typeof(CustomersVerticalBar),
                                                typeof(OrdersVerticalBar),
                                                new MasterDetailSelector(Test1Selector));

            MasterDetails[] res = engine.ReadFile(FileTest.Good.MasterDetail1.Path);

            Assert.AreEqual(4, res.Length);

            Assert.AreEqual(4, engine.TotalRecords);

            Assert.AreEqual(4, res[0].Details.Length);
            Assert.AreEqual(3, res[1].Details.Length);
            Assert.AreEqual(2, res[2].Details.Length);
            Assert.AreEqual(0, res[3].Details.Length);

            Assert.AreEqual("ALFKI", ((CustomersVerticalBar)res[0].Master).CustomerID);
            Assert.AreEqual(10248, ((OrdersVerticalBar)res[0].Details[0]).OrderID);
            Assert.AreEqual(10249, ((OrdersVerticalBar)res[0].Details[1]).OrderID);
            Assert.AreEqual(10250, ((OrdersVerticalBar)res[0].Details[2]).OrderID);
            Assert.AreEqual(10251, ((OrdersVerticalBar)res[0].Details[3]).OrderID);

            Assert.AreEqual("ANATR", ((CustomersVerticalBar)res[1].Master).CustomerID);
            Assert.AreEqual(10252, ((OrdersVerticalBar)res[1].Details[0]).OrderID);
            Assert.AreEqual(10253, ((OrdersVerticalBar)res[1].Details[1]).OrderID);
            Assert.AreEqual(10254, ((OrdersVerticalBar)res[1].Details[2]).OrderID);

            Assert.AreEqual("ANTON", ((CustomersVerticalBar)res[2].Master).CustomerID);
            Assert.AreEqual(10257, ((OrdersVerticalBar)res[2].Details[0]).OrderID);
            Assert.AreEqual(10258, ((OrdersVerticalBar)res[2].Details[1]).OrderID);

            Assert.AreEqual("DUMON", ((CustomersVerticalBar)res[3].Master).CustomerID);
        }
        public void CustomerOrdersRead2()
        {
            var engine = new MasterDetailEngine(typeof(CustomersVerticalBar), typeof(OrdersVerticalBar), CommonSelector.MasterIfContains, "@");

            MasterDetails[] res = engine.ReadFile(FileTest.Good.MasterDetail3.Path);

            Assert.AreEqual(4, res.Length);

            Assert.AreEqual(4, engine.TotalRecords);

            Assert.AreEqual(4, res[0].Details.Length);
            Assert.AreEqual(3, res[1].Details.Length);
            Assert.AreEqual(2, res[2].Details.Length);
            Assert.AreEqual(0, res[3].Details.Length);

            Assert.AreEqual("ALFKI", ((CustomersVerticalBar)res[0].Master).CustomerID);
            Assert.AreEqual(10248, ((OrdersVerticalBar)res[0].Details[0]).OrderID);
            Assert.AreEqual(10249, ((OrdersVerticalBar)res[0].Details[1]).OrderID);
            Assert.AreEqual(10250, ((OrdersVerticalBar)res[0].Details[2]).OrderID);
            Assert.AreEqual(10251, ((OrdersVerticalBar)res[0].Details[3]).OrderID);

            Assert.AreEqual("ANATR", ((CustomersVerticalBar)res[1].Master).CustomerID);
            Assert.AreEqual(10252, ((OrdersVerticalBar)res[1].Details[0]).OrderID);
            Assert.AreEqual(10253, ((OrdersVerticalBar)res[1].Details[1]).OrderID);
            Assert.AreEqual(10254, ((OrdersVerticalBar)res[1].Details[2]).OrderID);

            Assert.AreEqual("ANTON", ((CustomersVerticalBar)res[2].Master).CustomerID);
            Assert.AreEqual(10257, ((OrdersVerticalBar)res[2].Details[0]).OrderID);
            Assert.AreEqual(10258, ((OrdersVerticalBar)res[2].Details[1]).OrderID);

            Assert.AreEqual("DUMON", ((CustomersVerticalBar)res[3].Master).CustomerID);
        }
        //-> {Example.Name:Master Detail sample}
        //-> {Example.Description:Show how to implement Master detail reading where record contains characters}
        //-> {Example.File:RunEngine.cs}
        /// <summary>
        /// Run a record through engine using a Common selector where master contains a characrter to create a master detail input
        /// </summary>
        public override void Run()
        {
            var engine = new MasterDetailEngine<Customers, Orders>
                                         (CommonSelector.MasterIfContains, "@");
            // to Read use:
            var res = engine.ReadFile("Input.txt");

            // to Write use:
            engine.WriteFile("Output.txt", res);
        }
예제 #4
0
        public void CustomerOrdersWrite()
        {
            var engine = new MasterDetailEngine(typeof (CustomersVerticalBar),
                typeof (OrdersVerticalBar),
                new MasterDetailSelector(Test1Selector));
            MasterDetails[] resTmp = engine.ReadFile(FileTest.Good.MasterDetail1.Path);
            Assert.AreEqual(4, resTmp.Length);

            engine.WriteFile("tempmd.txt", resTmp);


            MasterDetails[] res = engine.ReadFile("tempmd.txt");

            Assert.AreEqual(4, res.Length);

            Assert.AreEqual(4, engine.TotalRecords);

            Assert.AreEqual(4, res[0].Details.Length);
            Assert.AreEqual(3, res[1].Details.Length);
            Assert.AreEqual(2, res[2].Details.Length);
            Assert.AreEqual(0, res[3].Details.Length);

            Assert.AreEqual("ALFKI", ((CustomersVerticalBar) res[0].Master).CustomerID);
            Assert.AreEqual(10248, ((OrdersVerticalBar) res[0].Details[0]).OrderID);
            Assert.AreEqual(10249, ((OrdersVerticalBar) res[0].Details[1]).OrderID);
            Assert.AreEqual(10250, ((OrdersVerticalBar) res[0].Details[2]).OrderID);
            Assert.AreEqual(10251, ((OrdersVerticalBar) res[0].Details[3]).OrderID);

            Assert.AreEqual("ANATR", ((CustomersVerticalBar) res[1].Master).CustomerID);
            Assert.AreEqual(10252, ((OrdersVerticalBar) res[1].Details[0]).OrderID);
            Assert.AreEqual(10253, ((OrdersVerticalBar) res[1].Details[1]).OrderID);
            Assert.AreEqual(10254, ((OrdersVerticalBar) res[1].Details[2]).OrderID);

            Assert.AreEqual("ANTON", ((CustomersVerticalBar) res[2].Master).CustomerID);
            Assert.AreEqual(10257, ((OrdersVerticalBar) res[2].Details[0]).OrderID);
            Assert.AreEqual(10258, ((OrdersVerticalBar) res[2].Details[1]).OrderID);

            Assert.AreEqual("DUMON", ((CustomersVerticalBar) res[3].Master).CustomerID);


            if (File.Exists("tempmd.txt"))
                File.Delete("tempmd.txt");
        }
        //-> Name:Master Detail sample
        //-> Description:Show how to implement Master detail reading where record contains characters

        //-> File:RunEngine.cs
        /// <summary>
        /// Run a record through engine using a Common selector where master contains a characrter to create a master detail input
        /// </summary>
        public override void Run()
        {
            var engine = new MasterDetailEngine <Customers, Orders>
                             (CommonSelector.MasterIfContains, "@");
            // to Read use:
            var res = engine.ReadFile("Input.txt");

            // to Write use:
            engine.WriteFile("Output.txt", res);
        }
        //-> Name: Master Detail Custom Selector
        //-> Description:Show how to implement Master detail reading using a selection subroutine

        //-> File:RunEngine.cs
        /// <summary>
        /// Run a record through engine using a selector to create a master detail input
        /// </summary>
        public override void Run()
        {
            var engine = new MasterDetailEngine<Customers, Orders>(new MasterDetailSelector(ExampleSelector));

            var result = engine.ReadFile("Input.txt");

            foreach (var group in result) {
                Console.WriteLine("Customer: {0}", group.Master.CustomerID);
                foreach (var detail in group.Details)
                    Console.WriteLine("    Freight: {0}", detail.Freight);
            }
        }
예제 #7
0
        public void GenerateSimpleInvoice()
        {
            string             t              = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "../../../Core.UnitTests/Data/Invoice.txt");
            string             target         = File.ReadAllText(t);
            MasterDetailEngine engine         = new MasterDetailEngine(typeof(PaypalRecord), typeof(PaypalRecord), new MasterDetailSelector(Process.PaypalSelectorClass.PaypalSelector));
            string             PaypalFilePath = "../../../Core.UnitTests/Data/Paypal_InvoiceSingleItem.csv";

            MasterDetails[] recordsMS     = (MasterDetails[])engine.ReadFile(PaypalFilePath);
            var             invoicestring = Process.CreateInvoicesString(recordsMS[0], 1, 1, 2);

            Assert.That(invoicestring, Is.EqualTo(target));
        }
        //-> Name: Master Detail Custom Selector
        //-> Description:Show how to implement Master detail reading using a selection subroutine

        //-> File:RunEngine.cs
        /// <summary>
        /// Run a record through engine using a selector to create a master detail input
        /// </summary>
        public override void Run()
        {
            var engine = new MasterDetailEngine <Customers, Orders>(new MasterDetailSelector(ExampleSelector));

            var result = engine.ReadFile("Input.txt");

            foreach (var group in result)
            {
                Console.WriteLine("Customer: {0}", group.Master.CustomerID);
                foreach (var detail in group.Details)
                {
                    Console.WriteLine("    Freight: {0}", detail.Freight);
                }
            }
        }
예제 #9
0
        public void CustomerOrdersWrite()
        {
            engine = new MasterDetailEngine(typeof(CustomersVerticalBar), typeof(OrdersVerticalBar), new MasterDetailSelector(Test1Selector));
            MasterDetails[] resTmp = TestCommon.ReadTest(engine, @"Good\MasterDetail1.txt");
            Assert.AreEqual(4, resTmp.Length);

            engine.WriteFile("tempmd.txt", resTmp);


            MasterDetails[] res = engine.ReadFile("tempmd.txt");

            Assert.AreEqual(4, res.Length);

            Assert.AreEqual(4, engine.TotalRecords);

            Assert.AreEqual(4, res[0].Details.Length);
            Assert.AreEqual(3, res[1].Details.Length);
            Assert.AreEqual(2, res[2].Details.Length);
            Assert.AreEqual(0, res[3].Details.Length);

            Assert.AreEqual("ALFKI", ((CustomersVerticalBar)res[0].Master).CustomerID);
            Assert.AreEqual(10248, ((OrdersVerticalBar)res[0].Details[0]).OrderID);
            Assert.AreEqual(10249, ((OrdersVerticalBar)res[0].Details[1]).OrderID);
            Assert.AreEqual(10250, ((OrdersVerticalBar)res[0].Details[2]).OrderID);
            Assert.AreEqual(10251, ((OrdersVerticalBar)res[0].Details[3]).OrderID);

            Assert.AreEqual("ANATR", ((CustomersVerticalBar)res[1].Master).CustomerID);
            Assert.AreEqual(10252, ((OrdersVerticalBar)res[1].Details[0]).OrderID);
            Assert.AreEqual(10253, ((OrdersVerticalBar)res[1].Details[1]).OrderID);
            Assert.AreEqual(10254, ((OrdersVerticalBar)res[1].Details[2]).OrderID);

            Assert.AreEqual("ANTON", ((CustomersVerticalBar)res[2].Master).CustomerID);
            Assert.AreEqual(10257, ((OrdersVerticalBar)res[2].Details[0]).OrderID);
            Assert.AreEqual(10258, ((OrdersVerticalBar)res[2].Details[1]).OrderID);

            Assert.AreEqual("DUMON", ((CustomersVerticalBar)res[3].Master).CustomerID);


            if (File.Exists("tempmd.txt"))
            {
                File.Delete("tempmd.txt");
            }
        }
예제 #10
0
        public MasterDetails[] LoadPaypalFile(string PaypalFilePath)
        {
            MasterDetails[] recordsMS;
            try //see if you can open the file in the new Paypal Format
            {
                MasterDetailEngine engine = new MasterDetailEngine(typeof(PaypalRecord), typeof(PaypalRecord), new MasterDetailSelector(Process.PaypalSelectorClass.PaypalSelector));
                recordsMS = (MasterDetails[])engine.ReadFile(PaypalFilePath);
            }
            catch (ConvertException) //else try to open in the old Paypal Format
            {
                try
                {
                    MasterDetailEngine engine = new MasterDetailEngine(typeof(PaypalRecordOldType), typeof(PaypalRecordOldType), new MasterDetailSelector(Process.PaypalSelectorClass.PaypalSelector));
                    recordsMS = (MasterDetails[])engine.ReadFile(PaypalFilePath);
                    foreach (MasterDetails record in recordsMS)
                    {
                        //convert each record in the file to a PaypalRecord from PaypalRecordOldType!
                        record.Master = Core.Converter.ConvertToPaypalRecord((PaypalRecordOldType)record.Master);
                        for (int x = 0; x < record.Details.Length; x++)
                        {
                            record.Details[x] = Converter.ConvertToPaypalRecord((PaypalRecordOldType)record.Details[x]);
                        }
                    }
                }
                catch (ConvertException)
                {
                    MasterDetailEngine engine = new MasterDetailEngine(typeof(PaypalRecordBusinessAccount), typeof(PaypalRecordBusinessAccount), new MasterDetailSelector(Process.PaypalSelectorClass.PaypalSelector));
                    recordsMS = (MasterDetails[])engine.ReadFile(PaypalFilePath);
                    foreach (MasterDetails record in recordsMS)
                    {
                        //convert each record in the file to a PaypalRecord from PaypalRecordOldType!
                        record.Master = Core.Converter.ConvertToPaypalRecord((PaypalRecordBusinessAccount)record.Master);
                        for (int x = 0; x < record.Details.Length; x++)
                        {
                            record.Details[x] = Converter.ConvertToPaypalRecord((PaypalRecordBusinessAccount)record.Details[x]);
                        }
                    }
                }
            }

            return(recordsMS);
        }
예제 #11
0
        private void txtFileName_TextChanged(object sender, EventArgs e)
        {
            MasterDetailEngine engine = new MasterDetailEngine(typeof(CAPTxtIEMaster), typeof(CAPTxtIEDetails), new MasterDetailSelector(RecSelector));

            md = engine.ReadFile(Path.Combine(mstrDirectory, txtFileName.Text));

            for (int i = 0; i < md.Length; i++)
            {
                CAPTxtIEMaster CAPItem = md[i].Master as CAPTxtIEMaster;

                ListViewItem oItem = lvImportedList.Items.Add(CAPItem.RecType);
                oItem.SubItems.Add(CAPItem.Location);
                oItem.SubItems.Add(CAPItem.Operator);
                oItem.SubItems.Add(DateTimeHelper.DateTimeToString(CAPItem.RecvDate, false));
                oItem.SubItems.Add(CAPItem.Supplier);
                oItem.SubItems.Add(CAPItem.RefNumber);
                oItem.SubItems.Add(CAPItem.Remarks);
                oItem.SubItems.Add(String.Empty);       // 2012.09.14 paulus: 加咗,咁個 colMessage 才有效
            }

            lblTxCount.Text = md.Length.ToString();
        }
예제 #12
0
        private void txtFileName_TextChanged(object sender, EventArgs e)
        {
            MasterDetailEngine engine = new MasterDetailEngine(typeof(TxferTxtIEMaster), typeof(TxferTxtIEDetails), new MasterDetailSelector(RecSelector));

            md = engine.ReadFile(Path.Combine(mstrDirectory, txtFileName.Text));

            for (int i = 0; i < md.Length; i++)
            {
                TxferTxtIEMaster txferItem = md[0].Master as TxferTxtIEMaster;

                ListViewItem oItem = lvImportedList.Items.Add(txferItem.RecType);
                oItem.SubItems.Add(txferItem.FromLocation);
                oItem.SubItems.Add(txferItem.ToLocation);
                oItem.SubItems.Add(txferItem.Operator);
                oItem.SubItems.Add(DateTimeHelper.DateTimeToString(txferItem.TxDate, false));
                oItem.SubItems.Add(DateTimeHelper.DateTimeToString(txferItem.TxferDate, false));
                oItem.SubItems.Add(DateTimeHelper.DateTimeToString(txferItem.CompletionDate, false));
                oItem.SubItems.Add(txferItem.RefNumber);
                oItem.SubItems.Add(txferItem.Remarks);
            }

            lblTxCount.Text = md.Length.ToString();
        }
예제 #13
0
        private IList <Questionnaire> GetQuestionnairesFromFlatFileFormatV1(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"File not found: '{path}'", path);
            }

            IList <Questionnaire> questionnaires = new List <Questionnaire>();

            var engine = new MasterDetailEngine <QuestionnaireHeader, QuestionnaireItem>(new MasterDetailSelector(RecordSelector))
            {
                Encoding = new UTF8Encoding()
            };

            MasterDetails <QuestionnaireHeader, QuestionnaireItem>[] masterDetails = engine.ReadFile(path);
            foreach (MasterDetails <QuestionnaireHeader, QuestionnaireItem> masterDetail in masterDetails)
            {
                _logger.LogDebug($"Questionnaire: {masterDetail.Master.Name} - {masterDetail.Master.Title}");

                Questionnaire questionnaire = new Questionnaire();

                questionnaire.Meta = new Meta
                {
                    Profile = new string[] { "http://ehelse.no/fhir/StructureDefinition/sdf-Questionnaire" }
                };

                questionnaire.Id          = string.IsNullOrWhiteSpace(masterDetail.Master.Id) ? null : masterDetail.Master.Id;
                questionnaire.Url         = string.IsNullOrWhiteSpace(masterDetail.Master.Url) ? null : masterDetail.Master.Url;
                questionnaire.Version     = string.IsNullOrWhiteSpace(masterDetail.Master.Version) ? null : masterDetail.Master.Version;
                questionnaire.Name        = string.IsNullOrWhiteSpace(masterDetail.Master.Name) ? null : masterDetail.Master.Name;
                questionnaire.Title       = string.IsNullOrWhiteSpace(masterDetail.Master.Title) ? null : masterDetail.Master.Title;
                questionnaire.Status      = string.IsNullOrWhiteSpace(masterDetail.Master.Status) ? null : EnumUtility.ParseLiteral <PublicationStatus>(masterDetail.Master.Status);
                questionnaire.Date        = string.IsNullOrWhiteSpace(masterDetail.Master.Date) ? null : masterDetail.Master.Date;
                questionnaire.Publisher   = string.IsNullOrWhiteSpace(masterDetail.Master.Publisher) ? null : masterDetail.Master.Publisher;
                questionnaire.Description = string.IsNullOrWhiteSpace(masterDetail.Master.Description) ? null : new Markdown(masterDetail.Master.Description);
                questionnaire.Purpose     = string.IsNullOrWhiteSpace(masterDetail.Master.Purpose) ? null : new Markdown(masterDetail.Master.Purpose);
                questionnaire.Contact     = string.IsNullOrWhiteSpace(masterDetail.Master.Contact) ? null : new List <ContactDetail> {
                    new ContactDetail {
                        Telecom = new List <ContactPoint> {
                            new ContactPoint {
                                System = ContactPoint.ContactPointSystem.Url, Value = masterDetail.Master.Contact
                            }
                        }
                    }
                };

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Language))
                {
                    questionnaire.Language = masterDetail.Master.Language;
                    // TODO: Vi trenger definere Visningsnavn for språket, eksempelvis: Norsk (bokmål), osv.
                    questionnaire.Meta.Tag.Add(new Coding("urn:ietf:bcp:47", questionnaire.Language));
                }

                IList <string> linkIds           = new List <string>();
                Questionnaire.ItemComponent item = null;
                for (int i = 0; i < masterDetail.Details.Length; i++)
                {
                    QuestionnaireItem questionnaireItem = masterDetail.Details[i];

                    if (linkIds.IndexOf(questionnaireItem.LinkId) > 0)
                    {
                        throw new DuplicateLinkIdException(questionnaireItem.LinkId);
                    }

                    _logger.LogDebug($"Questionnaire Item: {questionnaireItem.LinkId} - {questionnaireItem.Type} - {questionnaireItem.Text}");

                    int level = questionnaireItem.LinkId.Split('.').Length - 1;
                    if (level > 0)
                    {
                        i = DiveV1(i, level, item.Item, masterDetail.Details);
                    }
                    else
                    {
                        item = CreateItemComponentV1(questionnaireItem);
                        questionnaire.Item.Add(item);
                    }
                }

                questionnaires.Add(questionnaire);
            }

            return(questionnaires);
        }
예제 #14
0
        private IList <ValueSet> GetValueSetsFromFlatFileFormat(string path, bool genereateNarrative = true)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"File not found: '{path}'.", path);
            }

            IList <ValueSet> valueSets = new List <ValueSet>();
            var engine = new MasterDetailEngine <ValueSetHeader, ValueSetCodeReferences>(new MasterDetailSelector(RecordSelector))
            {
                Encoding = new UTF8Encoding()
            };

            MasterDetails <ValueSetHeader, ValueSetCodeReferences>[] masterDetails = engine.ReadFile(path);
            foreach (MasterDetails <ValueSetHeader, ValueSetCodeReferences> masterDetail in masterDetails)
            {
                _logger.LogDebug($"ValueSet: {masterDetail.Master.Id} - {masterDetail.Master.Title}");

                ValueSet valueSet = new ValueSet
                {
                    Id        = masterDetail.Master.Id,
                    Name      = masterDetail.Master.Name,
                    Title     = masterDetail.Master.Title,
                    Status    = PublicationStatus.Draft,
                    Version   = masterDetail.Master.Version,
                    Publisher = masterDetail.Master.Publisher,
                };

                ValueSet.ConceptSetComponent conceptSet = new ValueSet.ConceptSetComponent
                {
                    System = masterDetail.Master.System
                };
                valueSet.Compose = new ValueSet.ComposeComponent
                {
                    Include = new List <ValueSet.ConceptSetComponent>
                    {
                        conceptSet
                    }
                };
                foreach (ValueSetCodeReferences valueSetCodeReference in masterDetail.Details)
                {
                    _logger.LogDebug($"ValueSetCodeReference: {valueSetCodeReference.Code} - {valueSetCodeReference.Display}");

                    conceptSet.Concept.Add(new ValueSet.ConceptReferenceComponent {
                        Code = valueSetCodeReference.Code, Display = valueSetCodeReference.Display
                    });
                }

                if (genereateNarrative)
                {
                    valueSet.GenerateAndSetNarrative();
                }

                valueSets.Add(valueSet);
            }

            return(valueSets);
        }
예제 #15
0
        private IList <Questionnaire> GetQuestionnairesFromFlatFileFormatV2(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"File not found: '{path}'", path);
            }

            IList <Questionnaire> questionnaires = new List <Questionnaire>();

            var engine = new MasterDetailEngine <QuestionnaireHeader2, QuestionnaireItem2>(new MasterDetailSelector(RecordSelector))
            {
                Encoding = new UTF8Encoding()
            };

            MasterDetails <QuestionnaireHeader2, QuestionnaireItem2>[] masterDetails = engine.ReadFile(path);
            foreach (MasterDetails <QuestionnaireHeader2, QuestionnaireItem2> masterDetail in masterDetails)
            {
                _logger.LogDebug($"Questionnaire: {masterDetail.Master.Name} - {masterDetail.Master.Title}");

                Questionnaire questionnaire = new Questionnaire
                {
                    Meta = new Meta
                    {
                        Profile = new string[] { Constants.QuestionnaireProfileUri }
                    },

                    Id      = string.IsNullOrWhiteSpace(masterDetail.Master.Id) ? null : masterDetail.Master.Id,
                    Url     = string.IsNullOrWhiteSpace(masterDetail.Master.Url) ? null : masterDetail.Master.Url,
                    Version = string.IsNullOrWhiteSpace(masterDetail.Master.Version) ? null : masterDetail.Master.Version,
                    Name    = string.IsNullOrWhiteSpace(masterDetail.Master.Name) ? null : masterDetail.Master.Name,
                    Title   = string.IsNullOrWhiteSpace(masterDetail.Master.Title) ? null : masterDetail.Master.Title,
                    Status  = string.IsNullOrWhiteSpace(masterDetail.Master.Status) ? null : EnumUtility.ParseLiteral <PublicationStatus>(masterDetail.Master.Status)
                };
                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Date))
                {
                    if (!DateUtility.IsValidFhirDateTime(masterDetail.Master.Date))
                    {
                        throw new Exception($"The date {masterDetail.Master.Date} is not conforming to the expected format: 'yyyy-MM-dd'");
                    }
                    questionnaire.DateElement = new FhirDateTime(masterDetail.Master.Date);
                }
                questionnaire.Publisher   = string.IsNullOrWhiteSpace(masterDetail.Master.Publisher) ? null : masterDetail.Master.Publisher;
                questionnaire.Description = string.IsNullOrWhiteSpace(masterDetail.Master.Description) ? null : new Markdown(masterDetail.Master.Description);
                questionnaire.Purpose     = string.IsNullOrWhiteSpace(masterDetail.Master.Purpose) ? null : new Markdown(masterDetail.Master.Purpose);
                if (!string.IsNullOrWhiteSpace(masterDetail.Master.ApprovalDate))
                {
                    if (!DateUtility.IsValidFhirDate(masterDetail.Master.ApprovalDate))
                    {
                        throw new Exception($"The date {masterDetail.Master.ApprovalDate} is not conforming to the expected format: 'yyyy-MM-dd'");
                    }
                    questionnaire.ApprovalDateElement = new Date(masterDetail.Master.ApprovalDate);
                }
                if (!string.IsNullOrWhiteSpace(masterDetail.Master.ApprovalDate))
                {
                    if (!DateUtility.IsValidFhirDate(masterDetail.Master.LastReviewDate))
                    {
                        throw new Exception($"The date {masterDetail.Master.LastReviewDate} is not conforming to the expected format: 'yyyy-MM-dd'");
                    }
                    questionnaire.LastReviewDateElement = new Date(masterDetail.Master.LastReviewDate);
                }
                questionnaire.Contact = string.IsNullOrWhiteSpace(masterDetail.Master.ContactName) ? null : new List <ContactDetail> {
                    new ContactDetail {
                        Name = masterDetail.Master.ContactName
                    }
                };
                questionnaire.Copyright = string.IsNullOrWhiteSpace(masterDetail.Master.Copyright) ? null : new Markdown(masterDetail.Master.Copyright);

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.SubjectType))
                {
                    IList <ResourceType?> resourceTypes = new List <ResourceType?>();
                    string[] subjectTypes = masterDetail.Master.SubjectType.Split('|');
                    foreach (string subjectType in subjectTypes)
                    {
                        ResourceType?resourceType = EnumUtility.ParseLiteral <ResourceType>(subjectType);
                        if (resourceType.HasValue)
                        {
                            resourceTypes.Add(resourceType);
                        }
                    }
                    questionnaire.SubjectType = resourceTypes;
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Language))
                {
                    questionnaire.Language = masterDetail.Master.Language;
                    string displayName = CultureInfo.GetCultureInfo(LanguageCodeUtility.GetLanguageCode(questionnaire.Language))?.NativeName.UpperCaseFirstCharacter();
                    questionnaire.Meta.Tag.Add(new Coding("urn:ietf:bcp:47", questionnaire.Language, displayName == null ? string.Empty : displayName));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.UseContext))
                {
                    questionnaire.UseContext = ParseUsageContext(masterDetail.Master.UseContext);
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Endpoint))
                {
                    questionnaire.SetExtension(Constants.EndPointUri, new ResourceReference(masterDetail.Master.Endpoint));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.AuthenticationRequirement))
                {
                    questionnaire.SetExtension(Constants.AuthenticationRequirementUri, new Coding(Constants.AuthenticationRequirementSystem, masterDetail.Master.AuthenticationRequirement));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.AccessibilityToResponse))
                {
                    questionnaire.SetExtension(Constants.AccessibilityToResponseUri, new Coding(Constants.AccessibilityToResponseSystem, masterDetail.Master.AccessibilityToResponse));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.CanBePerformedBy))
                {
                    questionnaire.SetExtension(Constants.CanBePerformedByUri, new Coding(Constants.CanBePerformedBySystem, masterDetail.Master.CanBePerformedBy));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Discretion))
                {
                    questionnaire.SetExtension(Constants.DiscretionUri, new Coding(Constants.DiscretionSystem, masterDetail.Master.Discretion));
                }

                if (masterDetail.Master.GeneratePdf.HasValue)
                {
                    questionnaire.SetExtension(Constants.GeneratePdfUri, new FhirBoolean(masterDetail.Master.GeneratePdf.Value));
                }
                else
                {
                    questionnaire.SetExtension(Constants.GeneratePdfUri, new FhirBoolean(true));
                }

                if (masterDetail.Master.GenerateNarrative.HasValue)
                {
                    questionnaire.SetExtension(Constants.GenerateNarrativeUri, new FhirBoolean(masterDetail.Master.GenerateNarrative.Value));
                }
                else
                {
                    questionnaire.SetExtension(Constants.GenerateNarrativeUri, new FhirBoolean(true));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.PresentationButtons))
                {
                    questionnaire.SetExtension(Constants.PresentationButtonsUri, new Coding(Constants.PresentationButtonsSystem, masterDetail.Master.PresentationButtons));
                }
                else
                {
                    questionnaire.SetExtension(Constants.PresentationButtonsUri, new Coding(Constants.PresentationButtonsSystem, "sticky"));
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.Code))
                {
                    questionnaire.Code = ParseArrayOfCoding(masterDetail.Master.Code);
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.QuestionaireNavigatorState))
                {
                    questionnaire.SetExtension(Constants.QuestionaireNavigatorStateUri, new CodeableConcept {
                        Coding = new List <Coding> {
                            new Coding {
                                System = Constants.NavigatorStateSystem, Code = masterDetail.Master.QuestionaireNavigatorState,
                            }
                        }
                    });
                }

                if (!string.IsNullOrWhiteSpace(masterDetail.Master.QuestionnairePrintVersionReference))
                {
                    questionnaire.SetExtension(Constants.QuestionnairePrintVersionUri, new ResourceReference(masterDetail.Master.QuestionnairePrintVersionReference));
                }

                IList <string> linkIds           = new List <string>();
                Questionnaire.ItemComponent item = null;
                for (int i = 0; i < masterDetail.Details.Length; i++)
                {
                    QuestionnaireItem2 questionnaireItem = masterDetail.Details[i];

                    if (linkIds.IndexOf(questionnaireItem.LinkId) > 0)
                    {
                        throw new DuplicateLinkIdException(questionnaireItem.LinkId);
                    }

                    _logger.LogDebug($"Questionnaire Item: {questionnaireItem.LinkId} - {questionnaireItem.Type} - {questionnaireItem.Text}");

                    int level = questionnaireItem.LinkId.Split('.').Length - 1;
                    if (level > 0)
                    {
                        // item could be null if a line in the .txt-file is empty or blank
                        if (item == null)
                        {
                            continue;
                        }

                        i = DiveV2(i, level, item.Item, masterDetail.Details);
                    }
                    else
                    {
                        item = CreateItemComponentV2(questionnaireItem);
                        questionnaire.Item.Add(item);
                    }
                }

                questionnaires.Add(questionnaire);
            }

            return(questionnaires);
        }
예제 #16
0
 public static MasterDetails[] ReadTest(MasterDetailEngine engine, string fileName)
 {
     return(engine.ReadFile(TestPath(fileName)));
 }
예제 #17
0
 public static MasterDetails[] ReadTest(MasterDetailEngine engine, string fileName)
 {
     return(engine.ReadFile(@"..\data\" + fileName));
 }
예제 #18
0
		public static MasterDetails[] ReadTest(MasterDetailEngine engine, string fileName)
        {
            return engine.ReadFile(@"..\data\" + fileName);
        }