예제 #1
0
        public void AddAnalysis(string policyNumber, Analysis analysis)
        {
            OpenConnection();

            using (DbCommand command = _dbProviderFactory.CreateCommand())
            {
                command.Connection = _sqlConnection;
                var binFormatter = new ListBinaryFormatter<string>();
                command.CommandText =
                    "INSERT INTO Analyzes(PolicyNumber, TemplateTitle, Data, Date) VALUES(@PolicyNumber, @TemplateTitle, @Data, @Date)";

                command.Parameters.Add(GetParam("@TemplateTitle", analysis.TemplateTitle));
                command.Parameters.Add(GetParam("@Data", binFormatter.Serialize(analysis.Data)));
                command.Parameters.Add(GetParam("@Date", analysis.Date));
                command.Parameters.Add(GetParam("@PolicyNumber", policyNumber));

                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Can't add analysis!");
                }
                finally
                {
                    _sqlConnection.Close();
                }
            }
        }
예제 #2
0
 public void AddandGetAnalyzes_TwoAnalyzes_ShouldPass(string policyNumber, Analysis analysis)
 {
     var dataStorage = new HospitalDAL(_dataProvider, _connectionString);
     dataStorage.AddAnalysis(policyNumber, analysis);
     int analyzesCount = dataStorage.GetAnalyzes(policyNumber).Count;
     Assert.True(analyzesCount >= 1);
 }
예제 #3
0
        public void AddAnalysis(string policyNumber, Analysis analysis)
        {
            OpenConnection();
            var binFormatter = new ListBinaryFormatter<string>();
            _command.CommandText =
                "INSERT INTO Analyzes(PolicyNumber, TemplateTitle, Data, Date) VALUES(@PolicyNumber, @TemplateTitle, @Data, @Date)";

            _command.Parameters.Add(GetParam("@TemplateTitle", analysis.TemplateTitle));
            _command.Parameters.Add(GetParam("@Data", binFormatter.Serialize(analysis.Data)));
            _command.Parameters.Add(GetParam("@Date", analysis.Date));
            _command.Parameters.Add(GetParam("@PolicyNumber", policyNumber));

            try
            {
                _command.ExecuteNonQuery();
                //LOGGING
                Logger.Info("Analysis was added");
            }
            catch (Exception ex)
            {
                //LOGGING
                Logger.Error("Can't add analysis!",ex);
                throw new InvalidOperationException("Can't add analysis!");
            }
            finally
            {
                CloseConnection();
            }
        }
예제 #4
0
        public void FillTemplate_HtmlTemplate_ShouldPass()
        {
            var template = new Template(new List<string> {"hemoglobin", "erythrocytes"}, "BloodTest");
            var person = new Person("Igor", "Shein", new DateTime(1994, 4, 20), "Yaroslavl", "123456789");
            var analysis = new Analysis(new List<string> {"20", "50"}, "Blood Test", new DateTime(2014, 08, 3));

            var templateFiller = new TemplateFiller("Blood Test.html");
            string actual = templateFiller.FillTemplate(person, analysis, template);
            //File.WriteAllText("expected.html", actual);
            string expected = File.ReadAllText("expected.html");
            Assert.Equal(expected, actual);
        }
예제 #5
0
        public string FillTemplate(Person person, Analysis analysis, Template template)
        {
            InitSubstitutions(person);

            StringBuilder templateContent = GetTemplateContent();

            FillTemplateTitle(template, templateContent);
            FillPersonFields(templateContent);
            FillAnalysisFields(analysis, template, templateContent);

            return templateContent.ToString();
        }
예제 #6
0
        private void FillAnalysisFields(Analysis analysis, Template template, StringBuilder templateContent)
        {
            for (int i = 0; i < analysis.Data.Count; ++i)
            {
                string fieldSubstitution = FieldSubstitition + i;
                string valueSubstitution = ValueSubstitition + i;

                CheckFillPosibility(templateContent, fieldSubstitution, valueSubstitution);

                templateContent.Replace(fieldSubstitution, template.Data[i]);
                templateContent.Replace(valueSubstitution, analysis.Data[i]);
            }
        }
예제 #7
0
        private void AddAnalysisOKButton_Click(object sender, RoutedEventArgs e)
        {
            List<string> analysisInformation = GetInformationFromTextBoxes().Values.ToList();

            if (_currentPerson == null)
            {
                //LOGGING
                Logger.Info("Anylysis was not choosen");
                MessageBox.Show("There is no selected persons!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            bool hasEmptyFields = analysisInformation.Any(string.IsNullOrEmpty);

            if (hasEmptyFields)
            {

                //LOGGING
                Logger.Info("Not all fields in template are filled");
                MessageBox.Show("Not all fields are filled!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            _currentAnalysis = new Analysis(analysisInformation,
                _currentTemplate.Title, DateTime.Now);

            try
            {
                _dataAccessLayer.AddAnalysis(_currentPerson.PolicyNumber, _currentAnalysis);
            }
            catch (InvalidOperationException ex)
            {
                //LOGGING
                Logger.Error("Anylysis was added",ex);
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //LOGGING
            Logger.Info("Anylysis was added");
            MessageBox.Show("Analysis added successfully!", "Information", MessageBoxButton.OK,
                MessageBoxImage.Information);

            ClearCanvas();
        }