Index: sources/storage/TreatmentLog.cpp =================================================================== diff -u -rb16dca16497e752a74bab670eb06bd25f4207659 -r20d74e4816626ec810d9401752de4903650c9830 --- sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision b16dca16497e752a74bab670eb06bd25f4207659) +++ sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 20d74e4816626ec810d9401752de4903650c9830) @@ -32,7 +32,7 @@ #define FLOAT3 0,'f',3 #define ADDTITLE(vTITLE) logContent += QString("[%1]\n").arg(vTITLE) #define ADDALINE(vTEXT ) logContent += QString("%1\n" ).arg(vTEXT ) -#define ADDTOLOG(vINDEX) index = vINDEX; logContent += title(index) + sep + value(index) + sep + unit(index) + "\n"; +#define ADDTOLOG(vINDEX) index = vINDEX; logContent += title(index) + _sep + value(index) + _sep + unit(index) + "\n"; /*! * \brief TreatmentLog::TreatmentLog @@ -335,14 +335,14 @@ QString logContent ; - QString sep = "," ; - QString csv = "%1" + sep ; + QString csv = "%1" + _sep ; QString end = "%1" ; uint index = 0 ; - QString txCode = "Tx Code,%1," ; + QString txCode = "%1,%2," ; ADDTITLE("Title"); - ADDALINE(txCode.arg(_gTxCode) ); + ADDALINE(txCode + .arg(_txCodeKey).arg(_gTxCode) ); ADDTOLOG( ePatientID ); ADDTITLE("Treatment Parameters" ); @@ -580,7 +580,7 @@ ok = _gTxCode == _rTxCode; if ( ! ok ) { - LOG_DEBUG(QString("Generated '%1' TxCode and Received TxCode '%1' does not match").arg(_gTxCode).arg(_rTxCode)); + LOG_DEBUG(QString("Generated '%1' TxCode and Received TxCode '%2' does not match").arg(_gTxCode).arg(_rTxCode)); return ok; } @@ -594,6 +594,28 @@ return ok; } +bool TreatmentLog::findTxCode() +{ + bool ok = false; + QString content = ""; + FileHandler::read(_pendingTxr, content); + QStringList lines = content.split('\n'); + for ( const QString &line : lines ) { + if ( line.contains(_txCodeKey) ) { + QStringList fields = line.split(','); + if ( fields.count() >= Role::eCount ) { + if ( fields[Role::eTitle] == _txCodeKey ) { + if ( fields[Role::eValue].length() ) { + _gTxCode = fields[Role::eValue]; + ok = true; + } + } + } + } + } + return ok; +} + /*! * \brief TreatmentLog::sendPending * \details Resets the pending counter to immediately/ASAP as for the pending and won't waits for the timeout. @@ -613,6 +635,7 @@ */ void TreatmentLog::testPendingTxReports() { + static QString pendingTxr = ""; if ( _pendingCounter ) { _pendingCounter -- ; return; @@ -631,6 +654,12 @@ if ( pendingFiles.count() ) { // the most recent/first Tx file, to first ask for the current treatment which has just saved as pending on screen _pendingTxr = pendingFiles.first().absoluteFilePath(); + if (pendingTxr != _pendingTxr ) { + pendingTxr = _pendingTxr; + findTxCode(); + } + QString message = pendingTxr + " , " + _pendingTxr + " , " + _gTxCode; + LOG_DEBUG(message); emit didTxPending( _pendingTxr ); } } Index: sources/storage/TreatmentLog.h =================================================================== diff -u -rf9e747f0f28df1cc6a33179f0bc78bfc03d486fc -r20d74e4816626ec810d9401752de4903650c9830 --- sources/storage/TreatmentLog.h (.../TreatmentLog.h) (revision f9e747f0f28df1cc6a33179f0bc78bfc03d486fc) +++ sources/storage/TreatmentLog.h (.../TreatmentLog.h) (revision 20d74e4816626ec810d9401752de4903650c9830) @@ -44,10 +44,14 @@ const int _pendingInterval= 60 ; // 1m int _pendingCounter = 0 ; // + const QString _sep = ","; + QString _treatmentLogPath; const char* _treatmentLogExtUploaded = "txr"; const char* _treatmentLogExtPending = "txr.p"; + const char* _txCodeKey = "Tx Code"; + QFutureWatcher _saveWatcher; QFutureWatcher _exportWatcher; @@ -90,9 +94,10 @@ MEMBER( QString , rTxCode, ""); // content of this value be received from CloudSync App. enum Role { - eValue, eTitle, - eUnit + eValue, + eUnit , + eCount }; enum TreatmentLogIndex { @@ -195,19 +200,19 @@ _unitTextFluid , // eSalineBolusVolume }; - QString title(quint8 vIndex) const { - if (vIndex < _titles.count()) return _titles[vIndex]; - return ""; + QString string(quint8 vIndex , const QStringList &vStringList) const { + QString str = ""; + if (vIndex < vStringList.count()) { + str = vStringList[vIndex]; + str.remove(_sep); + } + return str; } - QString value(quint8 vIndex) const { - if (vIndex < _valuesLog.count()) return _valuesLog[vIndex]; - return ""; - } - QString unit(quint8 vIndex) const { - if (vIndex < _units.count()) return _units[vIndex]; - return ""; - } + QString title(quint8 vIndex) const { return string(vIndex, _titles );} + QString value(quint8 vIndex) const { return string(vIndex, _valuesLog );} + QString unit (quint8 vIndex) const { return string(vIndex, _units );} + // Lists QStringList _valuesLog; @@ -233,6 +238,7 @@ bool exportLog (); void exportLogConcurrent(); bool checkTxCode(); + bool findTxCode (); void sendPending(); // Pending Tx Report Index: sources/view/VTreatmentCreate.cpp =================================================================== diff -u -rf9e747f0f28df1cc6a33179f0bc78bfc03d486fc -r20d74e4816626ec810d9401752de4903650c9830 --- sources/view/VTreatmentCreate.cpp (.../VTreatmentCreate.cpp) (revision f9e747f0f28df1cc6a33179f0bc78bfc03d486fc) +++ sources/view/VTreatmentCreate.cpp (.../VTreatmentCreate.cpp) (revision 20d74e4816626ec810d9401752de4903650c9830) @@ -148,13 +148,15 @@ /*! * \brief VTreatmentCreate::generateTxCode - * \details Generates the txCode by combination of the HD serial number and date and time in yyyyMMddHHmm + * \details Generates the txCode by combination of the HD serial number and date and time in yyyyMMddHHmmss * And updates the TreatmenLog class to be saved in the Tx Report. */ void VTreatmentCreate::generateTxCode() { QDateTime datetime = QDateTime::currentDateTime(); - txCode(datetime.toString("%1yyyyMMddHHmm").arg(_HDSerialNumber)); + QString today = datetime.toString("yyyyMMddHHmmss"); + txCode(_HDSerialNumber + today); _TreatmentLog.gTxCode(_txCode); + LOG_APPED_UI(QString("Generated Treatment Code is %1").arg(_txCode)); } /*!