Exemplo n.º 1
0
        private void saveNewPatientButton_Click(object sender, RoutedEventArgs e)
        {
            //here comes the code for saving a new patient
            // first check inputs
            string   _newPatientId        = patientIdTextBox.Text;
            string   _newPatientFirstName = patientFirstNameTextBox.Text;
            string   _newPatientLastName  = patientLastNameTextBox.Text;
            string   _newPatientComment   = patientCommentTextBox.Text;
            DateTime _newPatientBirthDate = new DateTime(1900, 1, 1);

            try
            {
                _newPatientBirthDate = (DateTime)patientBirthDate.SelectedDate;
            }
            catch { }
            int        _newPatientSexIndex = patientSexComboBox.SelectedIndex;
            PatientSex _newPatientSex      = PatientSex.N;

            switch (_newPatientSexIndex)
            {
            case 0: _newPatientSex = PatientSex.F;
                break;

            case 1: _newPatientSex = PatientSex.M;
                break;

            case 2: _newPatientSex = PatientSex.N;
                break;

            case 3: _newPatientSex = PatientSex.O;
                break;
            }
            //patientSexComboBox.SelectedItem as PatientSex;
            DateTime _newPatientCreationTime = DateTime.Now;
            // create new study folder
            string path = fileParameters.RSOMdataFolder + "\\study" + _newPatientId;

            if (Directory.Exists(path))
            {
                Console.WriteLine("That study exists already.");
                System.Windows.MessageBox.Show("That study exists already. Please change ID");
                return;
            }
            else
            {
                try
                {
                    Directory.CreateDirectory(@path);
                }
                catch
                {
                    System.Windows.MessageBox.Show("Not able to create new patient folder. Please check permissions");
                }
            }

            // Create patient Study nod-file and save data
            XDocument objXDoc = new XDocument(

                new XElement("DataModelPatient",
                             new XElement("FriendlyName", ""),
                             new XElement("CreationTime", _newPatientCreationTime.ToString("o")),
                             new XElement("Comment", _newPatientComment),
                             new XElement("FirstName", _newPatientFirstName),
                             new XElement("LastName", _newPatientLastName),
                             new XElement("Id", _newPatientId),
                             new XElement("BirthDate", _newPatientBirthDate.ToString("o")),
                             new XElement("Sex", _newPatientSex.ToString()),
                             new XElement("LastExam", "")
                             )
                );

            objXDoc.Declaration = new XDeclaration("1.0", "utf-8", "true");
            //
            string filename = path + "\\study" + _newPatientId + studyParameters.PatientFileNameExtension;

            objXDoc.Save(@filename);

            // Add to patient List
            DataModelPatient _newCreatedPatient = (new DataModelPatient {
                FirstName = _newPatientFirstName, LastName = _newPatientLastName, Id = _newPatientId, BirthDate = _newPatientBirthDate, Sex = _newPatientSex, Comment = _newPatientComment, FriendlyName = "", CreationTime = _newPatientCreationTime, PatientFilePath = path
            });

            patientList.Add(_newCreatedPatient);
            studyParameters.highestCurrentStudyId = Convert.ToInt32(_newPatientId);
            //
            //ViewModelPatient selected = patientsListView.SelectedItem as ViewModelPatient;
            //selectAndScrollToPatientListViewItem(selected);
            // fill the patient details with last selected patient
            //fillPatientDetails(_newCreatedPatient);
            patientsListView.SelectedItem = _newCreatedPatient;
            patientsListView.Items.Refresh();
            EditingNewPatient = false;


            // Change back GUI behaviour
            patientsListView.IsEnabled      = true;
            deletePatientButton.IsEnabled   = true;
            clearFilterButton.IsEnabled     = true;
            filterTextBox.IsEnabled         = true;
            selectButton.Visibility         = Visibility.Visible;
            saveNewPatientButton.Visibility = Visibility.Collapsed;
        }
Exemplo n.º 2
0
        private void CheckAndSaveChangesInPatientData()
        {
            // first get inputs
            string     _newPatientId        = patientIdTextBox.Text;
            string     _newPatientFirstName = patientFirstNameTextBox.Text;
            string     _newPatientLastName  = patientLastNameTextBox.Text;
            string     _newPatientComment   = patientCommentTextBox.Text;
            DateTime   _newPatientBirthDate = (DateTime)patientBirthDate.SelectedDate;
            int        _newPatientSexIndex  = patientSexComboBox.SelectedIndex;
            PatientSex _newPatientSex       = PatientSex.N;

            switch (_newPatientSexIndex)
            {
            case 0: _newPatientSex = PatientSex.F;
                break;

            case 1: _newPatientSex = PatientSex.M;
                break;

            case 2: _newPatientSex = PatientSex.O;
                break;

            case 3: _newPatientSex = PatientSex.N;
                break;
            }
            // check conformity of inputs
            // checkinputs();

            // compare inputs with actual data
            if (_newPatientId != (patientsListView.SelectedItem as DataModelPatient).Id || _newPatientFirstName != (patientsListView.SelectedItem as DataModelPatient).FirstName || _newPatientLastName != (patientsListView.SelectedItem as DataModelPatient).LastName || _newPatientComment != (patientsListView.SelectedItem as DataModelPatient).Comment || _newPatientBirthDate != (patientsListView.SelectedItem as DataModelPatient).BirthDate || _newPatientSex != (patientsListView.SelectedItem as DataModelPatient).Sex)
            {
                string           messageBoxText = "Save changes to study?";
                string           caption        = "Study data changed";
                MessageBoxButton button         = MessageBoxButton.YesNo;
                MessageBoxImage  icon           = MessageBoxImage.Warning;
                MessageBoxResult result         = MessageBox.Show(messageBoxText, caption, button, icon);

                // Process message box results
                switch (result)
                {
                case MessageBoxResult.Yes:
                    try
                    {
                        //save Changes to patientInfoFile
                        XDocument objXDoc = new XDocument(

                            new XElement("DataModelPatient",
                                         new XElement("FriendlyName", ""),
                                         new XElement("CreationTime", (patientsListView.SelectedItem as DataModelPatient).CreationTime.ToString("o")),
                                         new XElement("Comment", _newPatientComment),
                                         new XElement("FirstName", _newPatientFirstName),
                                         new XElement("LastName", _newPatientLastName),
                                         new XElement("Id", _newPatientId),
                                         new XElement("BirthDate", _newPatientBirthDate.ToString("o")),
                                         new XElement("Sex", _newPatientSex.ToString()),
                                         new XElement("LastExam", "")
                                         )
                            );

                        objXDoc.Declaration = new XDeclaration("1.0", "utf-8", "true");
                        //
                        string path     = fileParameters.RSOMdataFolder + "\\study" + _newPatientId;
                        string filename = path + "\\study" + _newPatientId + studyParameters.PatientFileNameExtension;
                        objXDoc.Save(@filename);

                        //Refresh patient List
                        (patientsListView.SelectedItem as DataModelPatient).FirstName = _newPatientFirstName;
                        (patientsListView.SelectedItem as DataModelPatient).LastName  = _newPatientLastName;
                        (patientsListView.SelectedItem as DataModelPatient).BirthDate = _newPatientBirthDate;
                        (patientsListView.SelectedItem as DataModelPatient).Sex       = _newPatientSex;
                        (patientsListView.SelectedItem as DataModelPatient).Comment   = _newPatientComment;

                        //refresh View
                        int lastSelectedIndex = patientsListView.SelectedIndex;
                        patientsListView.SelectedIndex = lastSelectedIndex;
                        patientsListView.Items.Refresh();
                    }
                    catch { }


                    break;

                case MessageBoxResult.No:

                    break;
                }
            }
        }