Updated permissive mode warning message.

This commit is contained in:
LoudSnorer 2023-06-04 21:53:56 -04:00
parent fd247a29a2
commit d96d245474
2 changed files with 139 additions and 3 deletions

View File

@ -165,6 +165,97 @@ bool rxAHILessThan(const RXItem * rx1, const RXItem * rx2)
return (double(rx1->ahi) / rx1->hours) < (double(rx2->ahi) / rx2->hours);
}
void Statistics::updateDisabledInfo()
{
disabledInfo.update( p_profile->LastDay(MT_CPAP), p_profile->FirstDay(MT_CPAP) );
}
void DisabledInfo::update(QDate latestDate, QDate earliestDate)
{
clear();
if (AppSetting->clinicalMode()) return;
qint64 complianceLimit = 3600000.0 * p_profile->cpap->complianceHours(); // conbvert to ms
totalDays = 1+earliestDate.daysTo(latestDate);
for (QDate date = latestDate ; date >= earliestDate ; date=date.addDays(-1) ) {
Day* day = p_profile->GetDay(date);
if (!day) { daysNoData++; continue;};
int numDisabled=0;
qint64 sessLength = 0;
qint64 dayLength = 0;
qint64 complianceLength = 0;
//qint64 disableLength = 0;
QList<Session *> sessions = day->getSessions(MT_CPAP,true);
for (auto & sess : sessions) {
sessLength = sess->length();
dayLength += sessLength;
if (!sess->enabled(true)) {
numDisabled ++;
numDisabledsessions ++;
//disableLength += sessLength;
totalDurationOfDisabledSessions += sessLength;
if (maxDurationOfaDisabledsession < sessLength) maxDurationOfaDisabledsession = sessLength;
} else {
complianceLength += sess->length();
}
}
if ( complianceLimit <= complianceLength ) {
daysInCompliance ++;
} else {
if (complianceLimit < dayLength ) {
numDaysDisabledSessionChangedCompliance++;
} else {
daysOutOfCompliance ++;
}
}
if ( numDisabled > 0 ) {
numDaysWithDisabledsessions++;
};
}
// convect ms to minutes
maxDurationOfaDisabledsession/=60000 ;
totalDurationOfDisabledSessions/=60000 ;
#if 0
DEBUGQ;
DEBUGQ;
DEBUGFW Q(p_profile->cpap->complianceHours()) ;
DEBUGFW Q( totalDays ) ;
DEBUGQ;
DEBUGFW Q( daysNoData ) ;
DEBUGFW Q( daysInCompliance ) ;
DEBUGFW Q( daysOutOfCompliance ) ;
DEBUGFW Q( numDaysDisabledSessionChangedCompliance ) ;
DEBUGQ;
DEBUGFW Q( numDisabledsessions ) ;
DEBUGFW Q( maxDurationOfaDisabledsession) O("minutes");
DEBUGFW Q( totalDurationOfDisabledSessions) O("minutes") ;
DEBUGFW Q( numDaysWithDisabledsessions ) ;
#endif
};
QString DisabledInfo::display(int type)
{
/*
Warning: As Permissive mode is set (Preferences/Clinical), some sessions are excluded from this report, as follows:
Total disabled sessions: xx, found in yy days, of which zz days would have caused compliance failures.
Duration of longest disabled session: aa minutes, Total duration of all disabled sessions: bb minutes.
*/
switch (type) {
default :
case 0:
return QString(QObject::tr("Warning: As Permissive mode is set (Preferences/Clinical), some sessions are excluded from this report"));
case 1:
return QString(QObject::tr("Total disabled sessions: %1, found in %2 days, of which %3 days would have caused compliance failures")
.arg(numDisabledsessions)
.arg(numDaysWithDisabledsessions)
.arg(numDaysDisabledSessionChangedCompliance) );
case 2:
return QString(QObject::tr( "Duration of longest disabled session: %1 minutes, Total duration of all disabled sessions: %2 minutes.")
.arg(maxDurationOfaDisabledsession)
.arg(totalDurationOfDisabledSessions));
}
}
void Statistics::updateRXChanges()
{
// Set conditional progress bar.
@ -537,8 +628,12 @@ Statistics::Statistics(QObject *parent) :
QObject(parent)
{
rows.push_back(StatisticsRow(tr("CPAP Statistics"), SC_HEADING, MT_CPAP));
if (!AppSetting->clinicalMode())
rows.push_back(StatisticsRow(tr("Permissive Mode Warning: Disabled session data is excluded in this report"),SC_WARNING,MT_CPAP));
if (!AppSetting->clinicalMode()) {
updateDisabledInfo();
rows.push_back(StatisticsRow(disabledInfo.display(0),SC_WARNING ,MT_CPAP));
rows.push_back(StatisticsRow(disabledInfo.display(1),SC_WARNING2,MT_CPAP));
rows.push_back(StatisticsRow(disabledInfo.display(2),SC_WARNING2,MT_CPAP));
}
rows.push_back(StatisticsRow("", SC_DAYS, MT_CPAP));
rows.push_back(StatisticsRow("", SC_COLUMNHEADERS, MT_CPAP));
rows.push_back(StatisticsRow(tr("CPAP Usage"), SC_SUBHEADING, MT_CPAP));
@ -1261,6 +1356,10 @@ QString Statistics::GenerateCPAPUsage()
html+=QString("<tr bgcolor='%1'><th colspan=%2 align=center><font size='+1'>%3</font></th></tr>").
arg(warning_color).arg(periods.size()+1).arg(row.src);
continue;
} else if (row.calc == SC_WARNING2) {
html+=QString("<tr bgcolor='%1'><th colspan=%2 align=center><font size='+0'>%3</font></th></tr>").
arg(warning_color).arg(periods.size()+1).arg(row.src);
continue;
} else {
ChannelID id = schema::channel[row.src].id();
if ((id == NoChannel) || (!p_profile->channelAvailable(id))) {

View File

@ -16,12 +16,47 @@
#include <QPainter>
#include <QHash>
#include <QList>
#include "SleepLib/schema.h"
#include "SleepLib/machine.h"
class DisabledInfo
{
public:
QString display(int);
void update(QDate latest, QDate earliest) ;
private:
int totalDays ;
int daysNoData ;
int daysOutOfCompliance ;
int daysInCompliance ;
int numDisabledsessions ;
int numDaysWithDisabledsessions ;
int maxDurationOfaDisabledsession ;
int numDaysDisabledSessionChangedCompliance ;
int totalDurationOfDisabledSessions ;
void clear () {
totalDays = 0;
daysNoData = 0;
daysOutOfCompliance = 0;
daysInCompliance = 0;
numDisabledsessions = 0;
numDaysWithDisabledsessions = 0;
maxDurationOfaDisabledsession = 0;
numDaysDisabledSessionChangedCompliance = 0;
totalDurationOfDisabledSessions = 0;
};
};
//! \brief Type of calculation on one statistics row
enum StatCalcType {
SC_UNDEFINED=0, SC_COLUMNHEADERS, SC_HEADING, SC_SUBHEADING, SC_MEDIAN, SC_AVG, SC_WAVG, SC_90P, SC_MIN, SC_MAX, SC_CPH, SC_SPH, SC_AHI, SC_HOURS, SC_COMPLIANCE, SC_DAYS, SC_ABOVE, SC_BELOW , SC_WARNING
SC_UNDEFINED=0, SC_COLUMNHEADERS, SC_HEADING, SC_SUBHEADING, SC_MEDIAN, SC_AVG, SC_WAVG, SC_90P, SC_MIN, SC_MAX, SC_CPH, SC_SPH, SC_AHI, SC_HOURS, SC_COMPLIANCE, SC_DAYS, SC_ABOVE, SC_BELOW , SC_WARNING , SC_WARNING2
};
/*! \struct StatisticsRow
@ -172,6 +207,7 @@ class Statistics : public QObject
static void printReport(QWidget *parent = nullptr);
void updateDisabledInfo();
protected:
void loadRXChanges();
@ -198,6 +234,7 @@ class Statistics : public QObject
QList<QDate> record_best_ahi;
QList<QDate> record_worst_ahi;
DisabledInfo disabledInfo;
signals: