Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="fileID"></param>
        public void LoadPatientChannels(string patientId, string fileID, string dateTimeValue)
        {
            if (DataSource.OpenConnection())
            {
                SqlDataReader sqlDataReader = null;

                string     LoadPatChID = ConfigurationManager.AppSettings["LoadPatChQuery"].ToString();
                SqlCommand sqlcmd      = new SqlCommand(LoadPatChID, DataSource.SqlConn);

                SqlParameter patientidParam = new SqlParameter("@patient_id", SqlDbType.UniqueIdentifier, 50);
                Guid         guidPatientId  = new Guid(patientId);
                patientidParam.Value = guidPatientId;
                sqlcmd.Parameters.Add(patientidParam);
                sqlDataReader = sqlcmd.ExecuteReader();

                while (sqlDataReader.Read())
                {
                    Guid   patient_channel_id = (Guid)sqlDataReader["patient_channel_id"];
                    string label           = (string)sqlDataReader["label"];
                    Guid   channel_type_id = (Guid)sqlDataReader["channel_type_id"];
                    Int32  freq            = Convert.ToInt32(sqlDataReader["freq"]);
                    load_binary_waveform(patient_channel_id, patientId, channel_type_id, freq, label, FilePath, fileID, dateTimeValue);
                    ChannelInformation channel = new ChannelInformation(patient_channel_id, labelData, freq, channel_type_id, guidPatientId);
                    PatChannelToChannelType.Add(patient_channel_id.ToString(), channel);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnExportWave_Click(object sender, EventArgs e)
        {
            DialogResult result = DialogResult.OK;

            //check if patient is is selected
            if (string.IsNullOrEmpty(PatientID))
            {
                MessageBox.Show("Patient id is required.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                result = DialogResult.Cancel;
            }
            //check if file path is defined
            else if (string.IsNullOrEmpty(txtPath.Text) || !Directory.Exists(txtPath.Text))
            {
                MessageBox.Show("File directory is not valid.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                result = DialogResult.Cancel;
            }
            else if (!DataSource.HaveValidDBConnInfo)
            {
                DBInfoForm dbInfoForm = new DBInfoForm();
                result = dbInfoForm.ShowDialog();
            }

            if (result == DialogResult.OK)
            {
                try
                { //get unique file id
                    string fileID = GetFileID();

                    if (!string.IsNullOrEmpty(fileID))
                    {
                        WaveFormHelper waveFormHelper = new WaveFormHelper();
                        string         path           = txtPath.Text;
                        string         DateTimeValue;
                        DateTime       now     = DateTime.Now;
                        string         dformat = "yyyy-MM-dd_hh-mm-ss-tt";
                        DateTimeValue = now.ToString(dformat);

                        string filePathName = path + "\\" + "WaveformSampleInfo" + "_" + fileID + "_" + DateTimeValue + ".txt";
                        waveFormHelper.FilePath = path;

                        long         startft = 0;
                        long         endft   = 0;
                        StreamWriter writer  = File.AppendText(filePathName);
                        writer.AutoFlush = true;
                        writer.WriteLine("\r\n");
                        writer.WriteLine("\r\n");
                        writer.WriteLine("\r\n");
                        writer.WriteLine("ChannelName\tSampleRate\tStartFT\t\t\t\tEndFT\t\t\t\tSampleCount\r\n");
                        writer.WriteLine("=================================================================================================================");

                        //for each channel
                        //  helper.LoadPatientChannels(mPatID);
                        waveFormHelper.LoadPatientChannels(PatientID, fileID, DateTimeValue);

                        foreach (Object obj in waveFormHelper.PatChannelToChannelType.Keys)
                        {
                            ChannelInformation channelinfo = (ChannelInformation)waveFormHelper.PatChannelToChannelType[obj as string];
                            startft = waveFormHelper.GetPatientStartFt(PatientID, obj as string);
                            endft   = waveFormHelper.GetPatientEndFt(PatientID, obj as string);

                            long samples = waveFormHelper.GetPatientWaveform(PatientID, channelinfo.Rate, startft, endft);

                            writer.WriteLine(string.Format("{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}", channelinfo.Label, channelinfo.Rate.ToString(),
                                                           startft.ToString(), endft.ToString(), samples.ToString()));
                        }

                        writer.Close();

                        MessageBox.Show("Binary WaveForm data and 'WaveformSampleInfo.txt' files are exported. Check Folder Path Location.",
                                        "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("File ID is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                catch (Exception ex)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("Failed to export waveform data." + Environment.NewLine + "Error: " + ex.Message,
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }