Oximetry indice rebuild/repair menu option

This commit is contained in:
Mark Watkins 2011-12-01 11:47:09 +10:00
parent 30105c5b64
commit b003e38968
5 changed files with 115 additions and 11 deletions

View File

@ -290,7 +290,7 @@ void MainWindow::on_action_Import_Data_triggered()
qstatus->setText(tr("Importing Data")); qstatus->setText(tr("Importing Data"));
int c=PROFILE.Import(dir); int c=PROFILE.Import(dir);
if (!c) { if (!c) {
QMessageBox::warning(this,"Import Problem","Couldn't Find any Machine Data at this location:\n"+dir,QMessageBox::Ok); mainwin->Notify("Import Problem\n\nCouldn't Find any Machine Data at this location:\n"+dir);
if (newdir==dir) addnew=false; // Don't bother asking to add it. if (newdir==dir) addnew=false; // Don't bother asking to add it.
} }
qDebug() << "Finished Importing data" << c; qDebug() << "Finished Importing data" << c;
@ -469,7 +469,7 @@ void MainWindow::on_oximetryButton_clicked()
bool first=false; bool first=false;
if (!oximetry) { if (!oximetry) {
if (!PROFILE.Exists("EnableOximetry") || !PROFILE["EnableOximetry"].toBool()) { if (!PROFILE.Exists("EnableOximetry") || !PROFILE["EnableOximetry"].toBool()) {
if (QMessageBox::question(this,"Question","Do you have a CMS50[x] Oximeter?\nOne is required to use this section.\nNote: This section is not fully completed yet.",QMessageBox::Yes,QMessageBox::No)==QMessageBox::No) return; if (QMessageBox::question(this,"Question","Do you have a CMS50[x] Oximeter?\nOne is required to use this section.",QMessageBox::Yes,QMessageBox::No)==QMessageBox::No) return;
PROFILE["EnableOximetry"]=true; PROFILE["EnableOximetry"]=true;
} }
oximetry=new Oximetry(ui->tabWidget,daily->graphView()); oximetry=new Oximetry(ui->tabWidget,daily->graphView());
@ -605,3 +605,57 @@ void MainWindow::on_action_Frequently_Asked_Questions_triggered()
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
} }
void MainWindow::on_action_Rebuild_Oximetry_Index_triggered()
{
Day *day;
QMap<QDate,QVector<Day *> >::iterator z;
QHash<Machine *,QString> machines;
QVector<QString> valid;
valid.push_back(OXI_Pulse);
valid.push_back(OXI_SPO2);
valid.push_back(OXI_Plethy);
valid.push_back(OXI_PulseChange);
valid.push_back(OXI_SPO2Drop);
QVector<QString> invalid;
for (z=p_profile->daylist.begin();z!=p_profile->daylist.end();z++) {
for (int y=0;y<z.value().size();y++) {
day=z.value()[y];
if (day->machine->GetType()!=MT_OXIMETER) continue;
for (int s=0;s<day->getSessions().size();s++) {
Session *sess=day->getSessions()[s];
machines[sess->machine()]=sess->machine()->GetClass();
invalid.clear();
for (QHash<ChannelID,QVector<EventList *> >::iterator e=sess->eventlist.begin();e!=sess->eventlist.end();e++) {
if (!valid.contains(e.key())) {
invalid.push_back(e.key());
}
}
for (int i=0;i<invalid.size();i++) {
sess->eventlist.erase(sess->eventlist.find(invalid[i]));
}
sess->m_sum.clear();
sess->m_min.clear();
sess->m_max.clear();
sess->m_cph.clear();
sess->m_sph.clear();
sess->m_avg.clear();
sess->m_wavg.clear();
sess->m_90p.clear();
sess->m_firstchan.clear();
sess->m_lastchan.clear();
sess->SetChanged(true);
}
}
}
for (QHash<Machine *,QString>::iterator i=machines.begin();i!=machines.end();i++) {
Machine *m=i.key();
m->Save();
}
getDaily()->ReloadGraphs();
getOverview()->ReloadGraphs();
}

View File

@ -110,6 +110,8 @@ private slots:
void on_action_Frequently_Asked_Questions_triggered(); void on_action_Frequently_Asked_Questions_triggered();
void on_action_Rebuild_Oximetry_Index_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
Daily * daily; Daily * daily;

View File

@ -609,8 +609,15 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_About"/> <addaction name="action_About"/>
</widget> </widget>
<widget class="QMenu" name="menu_Data">
<property name="title">
<string>&amp;Data</string>
</property>
<addaction name="action_Rebuild_Oximetry_Index"/>
</widget>
<addaction name="menu_File"/> <addaction name="menu_File"/>
<addaction name="menu_View"/> <addaction name="menu_View"/>
<addaction name="menu_Data"/>
<addaction name="menu_Help"/> <addaction name="menu_Help"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
@ -760,6 +767,11 @@
<string>&amp;Frequently Asked Questions</string> <string>&amp;Frequently Asked Questions</string>
</property> </property>
</action> </action>
<action name="action_Rebuild_Oximetry_Index">
<property name="text">
<string>&amp;Rebuild Oximetry Indices</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -3,6 +3,7 @@
#include <QProgressBar> #include <QProgressBar>
#include <QMessageBox> #include <QMessageBox>
#include <QLabel> #include <QLabel>
#include <QTimer>
#include "oximetry.h" #include "oximetry.h"
#include "ui_oximetry.h" #include "ui_oximetry.h"
@ -66,9 +67,9 @@ bool SerialOximeter::Open(QextSerialPort::QueryMode mode)
if (m_port) m_port->close(); if (m_port) m_port->close();
} }
m_mode=mode; m_portmode=mode;
m_port=new QextSerialPort(m_portname,m_mode); m_port=new QextSerialPort(m_portname,m_portmode);
m_port->setBaudRate(m_baud); m_port->setBaudRate(m_baud);
m_port->setFlowControl(m_flow); m_port->setFlowControl(m_flow);
m_port->setParity(m_parity); m_port->setParity(m_parity);
@ -95,8 +96,9 @@ void SerialOximeter::Close()
if (!m_opened) return; if (!m_opened) return;
if (m_port) m_port->close(); if (m_port) m_port->close();
if (m_mode==QextSerialPort::EventDriven) if (m_portmode==QextSerialPort::EventDriven)
disconnect(m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead())); disconnect(m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
m_mode=SO_OFF;
m_opened=false; m_opened=false;
} }
@ -230,6 +232,7 @@ void SerialOximeter::compactToWaveform(EventList *el)
} }
void SerialOximeter::compactToEvent(EventList *el) void SerialOximeter::compactToEvent(EventList *el)
{ {
if (el->count()==0) return;
EventList nel(EVL_Waveform); EventList nel(EVL_Waveform);
EventDataType t,lastt=el->data(0); EventDataType t,lastt=el->data(0);
qint64 ti=el->time(0); qint64 ti=el->time(0);
@ -305,12 +308,15 @@ Session *SerialOximeter::createSession()
spo2->setFirst(lasttime); spo2->setFirst(lasttime);
plethy->setFirst(lasttime); plethy->setFirst(lasttime);
m_callbacks=0;
emit(sessionCreated(session)); emit(sessionCreated(session));
return session; return session;
} }
bool SerialOximeter::startLive() bool SerialOximeter::startLive()
{ {
m_mode=SO_LIVE;
import_mode=false; import_mode=false;
if (Open(QextSerialPort::EventDriven)) { if (Open(QextSerialPort::EventDriven)) {
createSession(); createSession();
@ -432,12 +438,14 @@ void CMS50Serial::on_import_process()
emit(importComplete(session)); emit(importComplete(session));
disconnect(this,SIGNAL(importProcess()),this,SLOT(on_import_process())); disconnect(this,SIGNAL(importProcess()),this,SLOT(on_import_process()));
} }
void CMS50Serial::onReadyRead() void CMS50Serial::onReadyRead()
{ {
QByteArray bytes; QByteArray bytes;
int a = m_port->bytesAvailable(); int a = m_port->bytesAvailable();
bytes.resize(a); bytes.resize(a);
m_port->read(bytes.data(), bytes.size()); m_port->read(bytes.data(), bytes.size());
m_callbacks++;
int i=0; int i=0;
@ -568,6 +576,7 @@ void CMS50Serial::onReadyRead()
bool CMS50Serial::startImport() bool CMS50Serial::startImport()
{ {
m_mode=SO_IMPORT;
import_mode=true; import_mode=true;
waitf6=true; waitf6=true;
cntf6=0; cntf6=0;
@ -777,8 +786,9 @@ void Oximetry::on_RunButton_toggled(bool checked)
SPO2->setRecMinY(90); SPO2->setRecMinY(90);
SPO2->setRecMaxY(100); SPO2->setRecMaxY(100);
QTimer::singleShot(1000,this,SLOT(oximeter_running_check()));
if (!oximeter->startLive()) { if (!oximeter->startLive()) {
QMessageBox::warning(this,"Error","Something is wrong with the device connection.",QMessageBox::Ok); mainwin->Notify("Oximetry Error!\n\nSomething is wrong with the device connection.");
return; return;
} }
ui->saveButton->setEnabled(false); ui->saveButton->setEnabled(false);
@ -878,6 +888,17 @@ void DumpBytes(int blocks, unsigned char * b,int len)
} }
qDebug() << a; qDebug() << a;
} }
void Oximetry::oximeter_running_check()
{
if (!oximeter->isOpen()) {
qDebug() << "Not sure how oximeter_running_check gets called with a closed oximeter";
mainwin->Notify("Oximeter Error\n\nThe device has not responded.. Make sure it's switched on2");
return;
}
if (oximeter->callbacks()==0) {
mainwin->Notify("Oximeter Error\n\nThe device has not responded.. Make sure it's switched on.");
}
}
// Move this code to CMS50 Importer?? // Move this code to CMS50 Importer??
void Oximetry::on_ImportButton_clicked() void Oximetry::on_ImportButton_clicked()
@ -887,10 +908,13 @@ void Oximetry::on_ImportButton_clicked()
connect(oximeter,SIGNAL(updateProgress(float)),this,SLOT(on_updateProgress(float))); connect(oximeter,SIGNAL(updateProgress(float)),this,SLOT(on_updateProgress(float)));
//connect(oximeter,SIGNAL(dataChanged()),this,SLOT(onDataChanged())); //connect(oximeter,SIGNAL(dataChanged()),this,SLOT(onDataChanged()));
QTimer::singleShot(1000,this,SLOT(oximeter_running_check()));
if (!oximeter->startImport()) { if (!oximeter->startImport()) {
qDebug() << "Error starting oximetry serial import process"; mainwin->Notify("Oximeter Error\n\nThe device did not respond.. Make sure it's switched on.");
//qDebug() << "Error starting oximetry serial import process";
return; return;
} }
day->getSessions().clear(); day->getSessions().clear();
day->AddSession(oximeter->getSession()); day->AddSession(oximeter->getSession());
@ -926,7 +950,9 @@ void Oximetry::import_finished()
void Oximetry::on_import_aborted() void Oximetry::on_import_aborted()
{ {
qDebug() << "Oximetry import failed"; //QMessageBox::warning(mainwin,"Oximeter Error","Please make sure your oximeter is switched on, and able to transmit data.\n(You may need to enter the oximeters Settings screen for it to be able to transmit.)",QMessageBox::Ok);
mainwin->Notify("Oximeter Error!\n\nPlease make sure your oximeter is switched on, and in the right mode to transmit data.");
//qDebug() << "Oximetry import failed";
import_finished(); import_finished();
} }
void Oximetry::on_import_complete(Session * session) void Oximetry::on_import_complete(Session * session)
@ -1023,7 +1049,7 @@ void Oximetry::onSpO2Changed(float o2)
void Oximetry::on_saveButton_clicked() void Oximetry::on_saveButton_clicked()
{ {
if (QMessageBox::question(this,"Keep This Recording?","A save dialog will go here allowing you to edit parameters for this oximetry session..\nFor now, would you like to save this as is?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes) { if (QMessageBox::question(this,"Keep This Recording?","Would you like to save this oximetery session?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes) {
Session *session=oximeter->getSession(); Session *session=oximeter->getSession();
// Process??? // Process???
//session->UpdateSummaries(); //session->UpdateSummaries();

View File

@ -20,6 +20,7 @@
#include "Graphs/gLineChart.h" #include "Graphs/gLineChart.h"
#include "Graphs/gFooBar.h" #include "Graphs/gFooBar.h"
enum SerialOxMode { SO_OFF, SO_IMPORT, SO_LIVE };
class SerialOximeter:public QObject class SerialOximeter:public QObject
{ {
Q_OBJECT Q_OBJECT
@ -36,6 +37,11 @@ public:
virtual bool startLive(); virtual bool startLive();
virtual void stopLive(); virtual void stopLive();
SerialOxMode mode() { return m_mode; }
bool isOpen() { return m_opened; }
int callbacks() { return m_callbacks; }
qint64 lastTime() { return lasttime; } qint64 lastTime() { return lasttime; }
Machine * getMachine() { return machine; } Machine * getMachine() { return machine; }
@ -91,7 +97,7 @@ protected:
EventList * spo2; EventList * spo2;
EventList * plethy; EventList * plethy;
QextSerialPort *m_port; QextSerialPort *m_port;
SerialOxMode m_mode;
bool m_opened; bool m_opened;
QString m_oxiname; QString m_oxiname;
QString m_portname; QString m_portname;
@ -100,11 +106,13 @@ protected:
ParityType m_parity; ParityType m_parity;
DataBitsType m_databits; DataBitsType m_databits;
StopBitsType m_stopbits; StopBitsType m_stopbits;
QextSerialPort::QueryMode m_mode; QextSerialPort::QueryMode m_portmode;
Machine *machine; Machine *machine;
qint64 lasttime; qint64 lasttime;
bool import_mode; bool import_mode;
int m_callbacks;
}; };
class CMS50Serial:public SerialOximeter class CMS50Serial:public SerialOximeter
@ -167,6 +175,8 @@ private slots:
void on_import_aborted(); void on_import_aborted();
void on_import_complete(Session *session); void on_import_complete(Session *session);
void oximeter_running_check();
private: private:
void import_finished(); void import_finished();
Ui::Oximetry *ui; Ui::Oximetry *ui;