int TfrmEnterResults::fnProcessResults(TStringList* tsl) { frmFront->fnDeleteEmpowerOutput(); if (tsl->Text.IsEmpty()) { APPMSG("File is empty", "File is empty", MB_OK); return false; } int count = 0; for( int idx = 1; idx < tsl->Count; idx++ ) { String record = tsl->Strings[ idx ]; if (!record.IsEmpty() && record.Pos( "Component Results" ) == 0 && record.Pos( "'#','SampleName'" ) == 0 ) { if (!fnParseLine(record)) return -1; else count++; } } return count; }
int main( int argc, char const ** argv ) { WHEFSApp.usageText = "[flags] vfs_file file1 [... fileN]"; WHEFSApp.helpText = "This program imports and exports local files to and from an EFS file." ; int rc = 0; bool gotHelp = false; rc = WHEFSApp_init( argc, argv, WHEFSApp_NoOpen, &gotHelp, CpArgSpec ); if( (0 != rc) ) { APPMSG("Initialization failed with error code #%d\n", rc); return rc; } if( (1==argc) || gotHelp ) { //cp_show_help(); return 0; } if( ! WHEFSApp.fe ) { APPERR("No source files specified!\n"); return whefs_rc.ArgError; } VERBOSE("Opening EFS [%s]\n", WHEFSApp.fsName); rc = whefs_openfs( WHEFSApp.fsName, &WHEFSApp.fs, ThisApp.exportMode ? false : true ); if( whefs_rc.OK != rc ) { APPERR("Open of EFS file [%s] failed with error code %d!\n", WHEFSApp.fsName, rc ); return rc; } WHEFSApp_fe * fe = WHEFSApp.fe; for( ; fe; fe = fe->next ) { VERBOSE("Copying file [%s] %s EFS\n", fe->name,(ThisApp.exportMode?"from":"to")); if( ThisApp.exportMode ) rc = cp_export(fe->name); else rc = cp_import(fe->name); if( whefs_rc.OK != rc ) { APPERR("%s failed for file [%s]! Error code=%d!\n", (ThisApp.exportMode?"Export":"Import"), fe->name, rc ); return rc; } continue; } //printf("vfs file=[%s]\n",WHEFSApp.fsName); //whefs_fs_dump_info( WHEFSApp.fs, stdout ); /* reminder: memory is cleaned up via atexit() */ return 0; }
//--------------------------------------------------------------------------- void __fastcall TfrmEnterResults::btnOKClick(TObject *Sender) { if (edtFilename->Text.IsEmpty()) { APPMSG( "Please choose an Empower(tm) output file" , "No output file selected", MB_OK); ModalResult = mrNone; return; } if (!FileExists(edtFilename->Text)) { APPMSG( "Invalid Empower(tm) output file specification" , "Invalid output file", MB_OK); ModalResult = mrNone; return; } if (cbAnalysers->Text.IsEmpty() || cbAnalysers->Text == CBANALYSER_DEFAULT && !MYDEBUG) { APPMSG( "Please choose a source analyser" , "No source analyser selected", MB_OK); ModalResult = mrNone; return; } LCDbAnalysers & analysers = LCDbAnalysers::records(); const LCDbAnalyser * machine = analysers.findByName(cbAnalysers->Text); if (machine != NULL) { analysers.setCurrent( *machine ); LCDbTests::records().read(frmCommon->qryLabCentral,false); } else { APPMSG( "Error - machine not recognised - contact Core Programming" , "Machine not recognised", MB_OK); ModalResult = mrNone; if (!MYDEBUG) return; } fnGetResults(); ModalResult = mrOk; }
int main( int argc, char const ** argv ) { WHEFSApp.usageText = "[flags] vfs_file"; WHEFSApp.helpText = "This program adds data blocks to an existing whefs container." ; int rc = 0; bool gotHelp = false; rc = WHEFSApp_init( argc, argv, WHEFSApp_OpenRW, &gotHelp, AddblocksArgSpec ); if( (0 != rc) ) { APPMSG("Initialization failed with error code #%d\n", rc); return rc; } if( (1==argc) || gotHelp ) { //cp_show_help(); return 0; } if( ! ThisApp.count ) { APPERR("You must specify -aNNN to set the number of blocks to add.\n"); return whefs_rc.ArgError; } whefs_fs_options const * fopt = whefs_fs_options_get( WHEFSApp.fs ); const whefs_id_type total = fopt->block_count + ThisApp.count; if( (total < fopt->block_count) ) /* this only catches once-around overflows :( */ { APPERR("Adding %"WHEFS_ID_TYPE_PFMT" blocks to the EFS would overflow its ID type!\n",ThisApp.count); return whefs_rc.RangeError; } VERBOSE("total blocks=%"WHEFS_ID_TYPE_PFMT"\n",total); rc = whefs_fs_append_blocks( WHEFSApp.fs, ThisApp.count ); if( whefs_rc.OK != rc ) { APPWARN("whefs_fs_append_blocks([%s], %"WHEFS_ID_TYPE_PFMT") failed with rc %d!\n", WHEFSApp.fsName, ThisApp.count,rc ); } else { VERBOSE("Appended %"WHEFS_ID_TYPE_PFMT".\n", ThisApp.count ); } return rc; }
bool TfrmEnterResults::fnParseLine(String strLine) { pEmpowerOutputRow TheEmpowerOutputRow; char *szTok, *szLine; // cheap test to see if input is valid: szLine = strLine.c_str(); int count = 0; while (*szLine != '\0') if (*szLine++ == ',') count++; if (count < 5) return false; try { TheEmpowerOutputRow = new EmpowerOutputRow; TokenString tsLine(strLine, ","); /*if (IDYES == APPMSG("tsLine: "+String(tsLine), "", MB_YESNO)) { String temp; temp = "Barcode: "+tsLine.First(); temp += "Test: "+tsLine.Next(); temp += "Conc: "+tsLine.Next(); temp += "Height: "+tsLine.Next(); temp += "Date: "+tsLine.Next(); temp += "Vial: "+tsLine.Next(); APPMSG("Result:\n"+temp, "", MB_OK); } */ String strTok; // # <row number> strTok = tsLine.First(); if (strTok.IsEmpty()) throw Exception("Missing row number"); TheEmpowerOutputRow->iRow = atoi(strTok.c_str()); // SampleName <sample barcode> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing barcode"); TheEmpowerOutputRow->strBarcode = fnTrimQuotes(strTok); // Name <test ID> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing test ID"); TheEmpowerOutputRow->strTestID = fnTrimQuotes(strTok); // Concentration <result value> strTok = tsLine.Next(); if (strTok.IsEmpty()) TheEmpowerOutputRow->flResultValue = -1; else TheEmpowerOutputRow->flResultValue = atof(strTok.c_str()); // Area/Height <peak area/height of component> strTok = tsLine.Next(); if (strTok.IsEmpty()) TheEmpowerOutputRow->flAreaHeight = -1; else TheEmpowerOutputRow->flAreaHeight = atof(strTok.c_str()); // Date Acquired <date of analysis> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing date"); TheEmpowerOutputRow->tdtDateOfAnalysis = TDateTime::TDateTime(fnTrimQuotes(strTok), TDateTime::DateTime); // Vial <vial number when analysed> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing vial number"); TheEmpowerOutputRow->iVialNum = atoi(fnTrimQuotes(strTok).c_str()); //APPMSG("Result: "+String(*TheEmpowerOutputRow), "", MB_OK); vecpEmpowerOutputRows.push_back(TheEmpowerOutputRow); } catch (Exception &e) { APPMSG(e.Message, "Error", MB_OK); delete TheEmpowerOutputRow; return false; } return true; }
void TfrmEnterResults::fnGetResults(void) { tdvecpEmpowerOutputRow::const_iterator it; pEmpowerOutputRow pResult; tslResults->LoadFromFile(OpenDialog4->FileName); int nresults = fnProcessResults(tslResults); if (-1 == nresults) { APPMSG("Problem with analyser data, contact Core Programming", "Error", MB_OK); return; } else if (0 == nresults) { APPMSG("No results returned", "No results", MB_OK); return; } frmFront->bGotWorklist = false; frmFront->ListBox1->Clear(); frmFront->ListBox1->Items->Add("Results added:"); frmFront->ListBox1->Items->Add(""); frmFront->ListBox1->Items->Add("Vial Barcode Test Result Area or Height Timestamp"); bool problem; bool therewereerrors = false; for (it = vecpEmpowerOutputRows.begin(); it != vecpEmpowerOutputRows.end(); it++) { pResult = *it; problem = false; String strError; int testID = LCDbTests::records().findTestID( pResult->strTestID ); if( testID == 0 ) { static bool testnotfound = false; if (!testnotfound) { APPMSG( "Mapping for test '"+pResult->strTestID+"' not found, contact Core Programming" , "Error", MB_OK); } strError = "Test '"+pResult->strTestID+"' not found: "; testnotfound = true; problem = true; therewereerrors = true; } if (pResult->strBarcode.IsEmpty()) { static bool emptybarcode = false; if (!emptybarcode) { APPMSG( "Barcode not found, contact Core Programming" , "Error", MB_OK); } strError += "Barcode empty: "; emptybarcode = true; problem = true; therewereerrors = true; } String strOutput; if (problem) { strOutput = "Problem: "+ strError; } else { try { LIMSResult result( pResult->strBarcode, pResult->tdtDateOfAnalysis ); result.setTestResult( testID, pResult->tdtDateOfAnalysis, pResult->flResultValue ); result.updateWorklist( frmCommon->qryBuddyDB, frmCommon->qryLabCentral ); result.saveRecord( frmCommon->qryBuddyDB ); } catch (Exception &e) { strOutput = "Problem: "+ e.Message; } } // "Vial Barcode Test Result Area or height Timestamp" String strTemp; strTemp.sprintf( "%4d %-16s %-10s %8.3f %10.1f %-20s", pResult->iVialNum, pResult->strBarcode, pResult->strTestID, pResult->flResultValue, pResult->flAreaHeight, pResult->tdtDateOfAnalysis ); strOutput += strTemp; frmFront->ListBox1->Items->Add(strOutput); } frmFront->StatusBar1->SimpleText = String(nresults) + " results added"; if (therewereerrors) { APPMSG( "There were errors - contact Core Programming" , "Error", MB_OK); } }