From 8b7a226994242f2d12d4c47ac02205d509892c6e Mon Sep 17 00:00:00 2001 From: cris Date: Tue, 24 Jun 2003 08:47:34 +0000 Subject: [PATCH] Patch level : at Files correlati : at8.exe at8900a.msk Ricompilazione Demo : [ ] Commento : varie su procedure di acquisizione dati da CT git-svn-id: svn://10.65.10.50/trunk@11271 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- at/at8.cpp | 4 +- at/at8.h | 2 +- at/at8800.cpp | 65 +- at/at8900.cpp | 1594 ++++++++++++++++++++++++++++++++++++++++-------- at/at8900a.uml | 2 +- at/at8a00.cpp | 91 ++- 6 files changed, 1450 insertions(+), 308 deletions(-) diff --git a/at/at8.cpp b/at/at8.cpp index 896ad7e7b..0f93b99e7 100755 --- a/at/at8.cpp +++ b/at/at8.cpp @@ -4,7 +4,7 @@ #include "at8.h" -#define usage "Error - usage : %s -{0|1|2|3|4|5|6|7|8}" +#define usage "Error - usage : %s -{0|1|2|3|4|5|6|7|8|9}" int main(int argc,char** argv) @@ -32,6 +32,8 @@ int main(int argc,char** argv) rt = at8800(argc,argv) ; break; case 8: rt = at8900(argc,argv) ; break; + case 9: + rt = at8a00(argc,argv) ; break; default: error_box(usage, argv[0]) ; break; } diff --git a/at/at8.h b/at/at8.h index 675f08c5e..357e2f731 100755 --- a/at/at8.h +++ b/at/at8.h @@ -10,6 +10,6 @@ int at8500(int argc, char* argv[]); int at8700(int argc, char* argv[]); int at8800(int argc, char* argv[]); int at8900(int argc, char* argv[]); - +int at8a00(int argc, char* argv[]); #endif // __AT8_H diff --git a/at/at8800.cpp b/at/at8800.cpp index 21d9cf045..ef8046c46 100755 --- a/at/at8800.cpp +++ b/at/at8800.cpp @@ -260,7 +260,10 @@ void TCtbo2at::calcola_categoria(TRectype& recsog) } bool TCtbo2at::test_inter(TRectype& recsog, const char* tipo, const TDate& datadon, int inter) -{ +{ + const char* tipoido = stricmp(tipo, "SI") != 0 ? "AF" : "SI"; + int intervallo = 0; + TRectype* key_cont = new TRectype(LF_CONTSAN); key_cont->put(CON_CODICE, recsog.get(SOG_CODICE)); TRecord_array controlli(LF_CONTSAN,CON_PROGCON); @@ -270,29 +273,35 @@ bool TCtbo2at::test_inter(TRectype& recsog, const char* tipo, const TDate& datad key->put(IDO_CODICE, recsog.get(SOG_CODICE)); TRecord_array idoneita(LF_IDONEITA,IDO_PROGIDO); idoneita.read(key); - - TString16 stato = recsog.get(SOG_STATO); - if (modstato_tcs(stato) != 'S' && stato.not_empty()) - return FALSE; - if (tipo == "SI") + + TString16 stato; + if (tipo == "SI") + { stato = recsog.get(SOG_STATOSI); + intervallo = recsog.get_int(SOG_INTSI); + } else + { stato = recsog.get(SOG_STATOAF); - if (modstato_tcs(stato) != 'S' && stato.not_empty()) + intervallo = recsog.get_int(SOG_INTAF); + } + if (stato.empty()) + stato = recsog.get(SOG_STATO); + if (modstato_tcs(stato) != 'S' && stato.not_empty() && intervallo == inter) return FALSE; const int r = idoneita.last_row(); //se trova una data idoneita >= di quella in esame, quest'ultima viene ignorata if (r > 0) { const TRectype& lastido = idoneita[r]; - if (lastido.get_date(IDO_DATAIDO) >= datadon) + if ((lastido.get_date(IDO_DATAIDO) >= datadon) && (tipoido == lastido.get(IDO_TIPOIDO))) return FALSE; } TRectype* rec = new TRectype(LF_IDONEITA); rec->put(IDO_CODICE, recsog.get(SOG_CODICE)); - rec->put(IDO_PROGIDO, r+1); + //rec->put(IDO_PROGIDO, r+1); rec->put(IDO_DATAIDO, datadon); - rec->put(IDO_TIPOIDO, stricmp(tipo, "SI") != 0 ? "AF" : "SI"); // Il mondo è bello perchè c'é l'AVIS (tutte le donaz. non SI sono AF! mah?!) + rec->put(IDO_TIPOIDO, tipoido); // Il mondo è bello perchè c'é l'AVIS (tutte le donaz. non SI sono AF! mah?!) rec->put(IDO_IDO_SOS, "ID"); rec->put(IDO_INTERVALLO, inter); // aggiunto da cristina il 18/09/2002 altrimenti non so che quella riga é stata aggiunta da CT @@ -301,6 +310,13 @@ bool TCtbo2at::test_inter(TRectype& recsog, const char* tipo, const TDate& datad idoneita.write(); con_reord(recsog, &controlli, &idoneita); + // verifico se occorre azzerare numero convocazioni e data ultima convocazione + TDate dataultdon = recsog.get(SOG_DATAULTDON); + if ((datadon - dataultdon) > 730) + { + recsog.put(SOG_DATACONV, NULLDATE); + recsog.put(SOG_NUMCONV, 0); + } // aggiorno data e utente ultimo aggiornamento (Cristina 18/09/2002) const TDate oggi(TODAY); recsog.put(SOG_DATAULTAGG,oggi); @@ -376,30 +392,17 @@ void TCtbo2at::transfer() if (str == "UROB") str = "O.BE"; else if (str == "IMOLA") - str = "70"; + str = "70"; update |= test_donation(sogg, tipo[i], datadon, str); - //rimette a posto idoneitá ed intervalli vari...(lo fa solo per chi ha donato perché per gli altri non viene passata - //alcuna data... winsit del c...o!) - str = curr.get(27+i); - if (!real::is_null(str)) - update |= test_inter(sogg, tipo[i], datadon, atoi(str)); } - else - { - int intervallo; - if (tipo[i] == "SI") - intervallo = sogg.get_int(SOG_INTSI); - else - intervallo = sogg.get_int(SOG_INTAF); - str = curr.get(27+i); - if ((!real::is_null(str)) && (intervallo != atoi(str))) - { - TDate oggi(TODAY); - update |= test_inter(sogg, tipo[i], oggi, atoi(str)); - } - } - if (update) + str = curr.get(27+i); + if (!real::is_null(str)) + update |= test_inter(sogg, tipo[i], datadon, atoi(str)); + if (update) + { + calcola_categoria(sogg); rel.rewrite(); + } } } _trasfile->close(); diff --git a/at/at8900.cpp b/at/at8900.cpp index d4f30c7a2..7076cb497 100755 --- a/at/at8900.cpp +++ b/at/at8900.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -20,102 +19,13 @@ #include "convoc.h" #include "rconvoc.h" #include "storico.h" - -#define ATFILENAME "aggiorna.txt" +#include "comuni.h" +#include "medici.h" //////////////////////////////////////////////////////// // Classe TCtpr2at_file customizzata dalla TFile_text // //////////////////////////////////////////////////////// -class TCtpr2at_file: public TFile_text -{ -protected: - virtual void preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString &tipo_tr); - -public: - virtual int autosave(TRelation& rel, const TRecord_text& rec); - - TCtpr2at_file(const TString& file_name, const TString& config_name); - virtual ~TCtpr2at_file() { } -}; - -TCtpr2at_file::TCtpr2at_file(const TString& file_name, const TString& config_name) - : TFile_text(file_name, config_name) -{ -} - -int TCtpr2at_file::autosave(TRelation& rel, const TRecord_text& rec) -{ - const TString& type = rec.type();//prendo il tracciato record del tipo del record_text - TTracciato_record& tr = *t_rec(type); - - TArray& a_tc = tr.tracciati_campo(); - const int items = a_tc.items(); - TString valore; - for (int i = 0; i < items; i++) - { - const TTracciato_campo& tc = tr.get(i); - TFieldref field(tc.field()); - if (field.name().not_empty()) - { - if (field.file()==0) - field.set_file(rel.lfile().num()); - valore = rec.row(i); - // formatta il campo del file di testo secondo le specifiche del campo su file isam - preformat_field(field,valore,rel,tr.type()); - const TRectype& rel_rec = rel.curr(field.file()); - TFieldtypes tipo_campo = rel_rec.type(field.name()); - bool vuoto = valore.blank(); - if (valore[0] == '@') //se trovo il carattere @ -> azzero il campo - valore.cut(0); - switch(tipo_campo) //in base al tipo di campo formatta i valori seguendo le specifiche del tracciato - { - case _datefld: //tipo data... - { - if (real::is_null(valore)) - { - valore.cut(0); - vuoto = TRUE; - } - TDate data(valore); - format_date(data, fpicture(tc), valore);//formatta la data secondo le specifiche del tracciato - } - break; - case _realfld: //tipi numerici - case _intfld: - case _longfld: - { - const real numero(valore); - vuoto = numero.is_zero(); - - valore = numero.string(fpicture(tc));//formatta il numero secondo le specifiche del tracciato - - int length = flength(tc,rel_rec); - if (falign(tc) == 'L') - valore.left_just(length, ffiller(tc)); - else - valore.right_just(length, ffiller(tc)); } - break; - default: - valore = format_field(tc, rel.lfile().num(), valore);//formatta il campo secondo le specifiche del record - break; - } - - if (!vuoto && rel.exist(field.file())) - field.write(valore, rel);//faccio una write sulla relazione del fieldref - } - } - - int err = NOERR; - if (pre_writerel(rel,rec)) - { - err= rel.write(); - if (err == _isdupkey || err ==_isreinsert) - err = rel.rewrite(); - } - return err; -} - ///////////////////////////////////////////////////// // Classe TCtpr2at: applicazione principale // ///////////////////////////////////////////////////// @@ -123,25 +33,50 @@ int TCtpr2at_file::autosave(TRelation& rel, const TRecord_text& rec) class TCtpr2at: public TSkeleton_application { TMask* _msk; - TCtpr2at_file* _trasfile; + TRelation* _rel; + TRelation* _relcom; + TLocalisamfile* _soggetti; + TLocalisamfile* _donaz; + TLocalisamfile* _contsan; + TLocalisamfile* _idoneita; + TRecord_array* _sdonazioni; + TRecord_array* _scontrolli; + TRecord_array* _sidoneita; + TAssoc_array* _array_comuni; + TAssoc_array* _array_donaz; + int _numdon1, _numdon2; - TString16 _catini1, _catfin1, _catini2, _catfin2; + TString4 _catini1, _catfin1, _catini2, _catfin2; bool _sttess2, _dataisc; + TConfig* _configfile; + + TDate _dataagg; + long _progins; + bool _message; + TString80 _intestazione; protected: virtual bool create(void); virtual void main_loop(); virtual bool destroy(void) ; - void transfer(void); - void inizializza_file(void); + void transfer(); + void transfer_file(const bool prima = TRUE); static bool annulla_handler(TMask_field& f, KEY k); bool test_donation(TRectype& recsog, const char* tipo, const TDate& datadon, const TString& luogodon); bool test_inter(TRectype& recsog, const char* tipo, const TDate& datadon, int inter); void calcola_categoria(TRectype& recsog); bool print_header(); - void print_line(const TString& rigastampa); + void print_line(const TString& rigastampa = ""); void print_footer(); - void new_sogg(TRectype& sogg, const TRecord_text& curr); + bool build_record(TAssoc_array& record, const TString& istruzione); + bool update_record(TRectype& recsog, TAssoc_array& record); + bool soggetto(const TString& istruzione); + bool accesso(const TString& istruzione); + bool sacca(const TString& istruzione); + bool analisi(const TString& istruzione); + bool intervalli(const TString& istruzione); + bool esclusione(const TString& istruzione); + long get_next_key(); public: const TMask& msk() const { return *_msk; } TCtpr2at() {} @@ -153,11 +88,19 @@ inline TCtpr2at& app() { return (TCtpr2at&) main_app();} // creazione dell'applicazione bool TCtpr2at::create() -{ +{ open_files(LF_SOGGETTI, LF_DONAZ, LF_CONTSAN, LF_IDONEITA, LF_CONVOC, LF_RCONVOC, LF_STORICO, 0); _msk = new TMask("at8900a"); - _msk->set(F_FILENAME,ATFILENAME); - _trasfile = NULL; + _rel = new TRelation(LF_SOGGETTI); + _relcom = new TRelation(LF_COMUNI); + _donaz = new TLocalisamfile(LF_DONAZ); + _contsan = new TLocalisamfile(LF_CONTSAN); + _idoneita = new TLocalisamfile(LF_IDONEITA); + _sdonazioni = new TRecord_array(LF_DONAZ,DON_PROGDON); + _scontrolli = new TRecord_array(LF_CONTSAN,CON_PROGCON); + _sidoneita = new TRecord_array(LF_IDONEITA,IDO_PROGIDO); + _array_comuni = new TAssoc_array(); + _array_donaz = new TAssoc_array(); TConfig config(CONFIG_STUDIO); _numdon1 = config.get_int("NumDon1"); _numdon2 = config.get_int("NumDon2"); @@ -167,26 +110,44 @@ bool TCtpr2at::create() _catfin2 = config.get("CatFin2"); _sttess2 = config.get_bool("StTess2"); _dataisc = config.get_bool("DataIsc"); + _configfile = new TConfig("at8900a.ini"); + _donaz->setkey(3); + _donaz->last(); + _progins = _donaz->get_long(DON_PROGINS); + _donaz->setkey(1); + return TSkeleton_application::create(); } // distruzione dell'applicazione bool TCtpr2at::destroy() -{ +{ + delete _array_donaz; + delete _array_comuni; + delete _sidoneita; + delete _scontrolli; + delete _sdonazioni; + delete _idoneita; + delete _contsan; + delete _donaz; + delete _rel; delete _msk; + delete _configfile; return TSkeleton_application::destroy(); } // carica la maschera void TCtpr2at::main_loop() -{ - KEY key = K_ENTER; - while (key != K_QUIT) +{ + _intestazione = ""; + _message = FALSE; + _msk->set(F_FILENAME,_configfile->get("PERCORSO", "ARCHIVIO")); + KEY key = _msk->run(); + if (key == K_ENTER) { - key = _msk->run(); - if (key == K_ENTER) - transfer(); - } + transfer(); + _configfile->set("PERCORSO", _msk->get(F_FILENAME), "ARCHIVIO"); + } } bool TCtpr2at::test_donation(TRectype& recsog, const char* tipo, const TDate& datadon, const TString& luogodon) @@ -229,9 +190,10 @@ bool TCtpr2at::test_donation(TRectype& recsog, const char* tipo, const TDate& da } void TCtpr2at::calcola_categoria(TRectype& recsog) -{ +{ + TString256 stampa; TTable ctd("CTD"); - TString16 catdon = recsog.get(SOG_CATDON); + TString4 catdon = recsog.get(SOG_CATDON); const int totdon = recsog.get_int(SOG_TOTDON); ctd.put("CODTAB",catdon); if (ctd.read() == NOERR) @@ -241,22 +203,26 @@ void TCtpr2at::calcola_categoria(TRectype& recsog) { const TString& cat_coll = ctd.get("S6"); if (cat_coll.not_empty()) - { - catdon = cat_coll; - recsog.put(SOG_CATDON, catdon); + { + stampa = "Il soggetto è dimesso, non effettuato cambio di categoria "; + stampa << cat_coll; + print_line(stampa); } - } - if ((catdon == _catini1 || _catini1.empty()) && (totdon>=_numdon1) && _catfin1.not_empty()) - { - recsog.put(SOG_CATDON, _catfin1); - catdon = _catfin1; } - bool tstampata = recsog.get_bool(SOG_T_STAMPATA); - if ((catdon == _catini2 || _catini2.empty()) && (totdon>=_numdon2) && _catfin2.not_empty() && (!_sttess2 || tstampata)) + else { - recsog.put(SOG_CATDON, _catfin2); - catdon = _catfin2; - } + if ((catdon == _catini1 || _catini1.empty()) && (totdon>=_numdon1) && _catfin1.not_empty()) + { + recsog.put(SOG_CATDON, _catfin1); + catdon = _catfin1; + } + bool tstampata = recsog.get_bool(SOG_T_STAMPATA); + if ((catdon == _catini2 || _catini2.empty()) && (totdon>=_numdon2) && _catfin2.not_empty() && (!_sttess2 || tstampata)) + { + recsog.put(SOG_CATDON, _catfin2); + catdon = _catfin2; + } + } } } @@ -272,7 +238,7 @@ bool TCtpr2at::test_inter(TRectype& recsog, const char* tipo, const TDate& datad TRecord_array idoneita(LF_IDONEITA,IDO_PROGIDO); idoneita.read(key); - TString16 stato = recsog.get(SOG_STATO); + TString4 stato = recsog.get(SOG_STATO); if (modstato_tcs(stato) != 'S' && stato.not_empty()) return FALSE; if (tipo == "SI") @@ -335,8 +301,19 @@ bool TCtpr2at::print_header() } void TCtpr2at::print_line(const TString& rigastampa) -{ +{ TPrintrow row; + row.reset(); + if (rigastampa.not_empty()) + if (_intestazione.not_empty()) + { + printer().print(row); + row.reset(); + row.put((const char*) _intestazione); + printer().print(row); + _intestazione = ""; + row.reset(); + } row.put((const char*) rigastampa); printer().print(row); } @@ -347,121 +324,1257 @@ void TCtpr2at::print_footer() printer().close(); } -void TCtpr2at::new_sogg(TRectype& sogg, const TRecord_text& curr) -{ - TLocalisamfile soggetti(LF_SOGGETTI); - soggetti.last(); - long codice = soggetti.get_long(SOG_CODICE); - sogg.put(SOG_CODICE, codice+1); - sogg.put(SOG_CATDON, "NU"); -} +void TCtpr2at::transfer_file(const bool prima) +{ + _dataagg = TODAY; + TString256 rigastampa; + TScanner s(_msk->get(F_FILENAME)); + TString16 key, archivio; + TString istruzione; + while (s.ok()) + { + const TString& line = s.line(); + if (line.find("UPDATE") != -1) + istruzione = line; + else + { + if (line.find("INSERT") == -1) + istruzione << line; + if (istruzione.not_empty()) + { + TToken_string* record = new TToken_string(istruzione); + archivio = record->get(0); + archivio.trim(); archivio.upper(); + int n = _configfile->get_int(archivio, "ARCHIVIO"); + _configfile->set_paragraph(archivio); + if (prima) + { + switch (n) + { + case 1: + soggetto(record->get(1)); + break; + case 2: + sacca(record->get(1)); + break; + case 4: + intervalli(record->get(1)); + break; + case 5: + esclusione(record->get(1)); + break; + default: + break; + } + } + else + { + switch (n) + { + case 3: + analisi(record->get(1)); + break; + case 6: + accesso(record->get(1)); + break; + default: + break; + } + } + istruzione = ""; + } + } + } + s.close(); +} + // trasferimento dati da file CT su programma avis void TCtpr2at::transfer() -{ +{ if (print_header()) - { - TFilename ctprini = "ctpr2at.ini"; - _trasfile = new TCtpr2at_file(_msk->get(F_FILENAME), ctprini); - inizializza_file(); - const long dimension = fsize(_msk->get(F_FILENAME)); - TProgind pi(dimension,"Acquisizione in corso..."); - TRelation rel(LF_SOGGETTI); - rel.lfile().setkey(2); - TRectype& sogg = rel.curr(); - TString256 rigastampa; - TString80 cognome, nome, datanasc, str; - TString8 tipodon_at, luogodon_at; - char tipoacc, tipodon; - TDate dataacc; - bool update; - TRecord_text curr; - bool cancelled = FALSE; - while ((_trasfile->read(curr) == NOERR) && (!cancelled)) - { - pi.setstatus(_trasfile->read_file()->tellg()); - // cerco il donatore con cognome, nome e data nascita - cognome = curr.get(1); - str = cognome.left(7); - if (str != "COGNOME") - { - sogg.put(SOG_COGNOME, cognome); - nome = curr.get(2); - sogg.put(SOG_NOME, nome); - datanasc = curr.get(4); - sogg.put(SOG_DATANASC, datanasc); - if (rel.read(_isequal) != NOERR) - { - // segnalo l'errore - rigastampa.format("Inserito soggetto %s %s %s", (const char*) cognome, (const char*) nome, (const char*) datanasc); - print_line(rigastampa); - // nuovo donatore - sogg.zero(); - sogg.put(SOG_COGNOME, cognome); - sogg.put(SOG_NOME, nome); - sogg.put(SOG_DATANASC, datanasc); - new_sogg(sogg, curr); - } - //esegue l'effettivo passaggio dati basandosi sulla formattazione del file .ini - _trasfile->autosave(rel, curr); - update = FALSE; - tipoacc = curr.get(25)[0]; - str = curr.get(24); - dataacc = TDate(str); - // se l'accesso è una donazione - if (tipoacc == 'D') - { - tipodon = curr.get(27)[0]; - switch (tipodon) - { - case '1': - tipodon_at = "SI"; break; - case '2': - tipodon_at = "PL"; break; - case '3': - tipodon_at = "PT"; break; - default: - tipodon_at = ""; break; - } - str = curr.get(26); - if (str.left(2) == "52") - luogodon_at = "0001"; - else - { - if (sogg.get(SOG_CODSEZ) == "13") - luogodon_at = "1301"; - else - luogodon_at = "0000"; - } - if (tipodon_at.not_empty()) - update |= test_donation(sogg, tipodon_at, dataacc, luogodon_at); - if (update) - { - rel.rewrite(); - rigastampa.format("Inserita donazione del %s a %s %s %s", (const char*) dataacc.string(), (const char*) cognome, (const char*) nome, (const char*) datanasc); - print_line(rigastampa); - } - } - // aggiungere le visite e i controlli - } - cancelled = pi.iscancelled(); - } - _trasfile->close(); + { + transfer_file(); + transfer_file(FALSE); print_footer(); - if (cancelled) - message_box("Operazione annullata: il trasferimento non è stato completato"); - else - message_box("Operazione terminata"); } else error_box("Errore in apertura stampante."); } -//inizializza il file di testo su cui emettere i dati -void TCtpr2at::inizializza_file() +bool TCtpr2at::build_record(TAssoc_array& record, const TString& istruzione) +{ + bool ok = TRUE; + record.destroy(); + TString lavoro = istruzione; + TString80 campo; + TString valore; + int indice1 = lavoro.find(" SET "); + int indice2 = lavoro.find(" WHERE "); + if ((indice1 != -1) && (indice2 != -1)) + { + lavoro = lavoro.sub(indice1+5,indice2); + lavoro.trim(); + int i = lavoro.find("''"); + if (i != -1) + { + TString aiuto = lavoro.sub(0,i); + aiuto << '~'; + aiuto << lavoro.sub(i+2); + lavoro = aiuto; + } + while (lavoro.not_empty()) + { + indice1 = lavoro.find('='); + if (indice1 != -1) + { + campo = lavoro.sub(0, indice1-1); + campo.trim(); + lavoro = lavoro.sub(indice1+1); + lavoro.trim(); + indice1 = lavoro.find(','); + if (indice1 != -1) + { + valore = lavoro.sub(0,indice1); + valore.trim(); + if ((valore[0] == '\'') && (valore[valore.len()-1] == '\'')) + { + // e' una stringa: tolgo le virgolette + valore = valore.sub(1,valore.len()-1); + lavoro = lavoro.sub(indice1+1); + } + else + { + if ((valore[0] != '\'') && (valore[valore.len()-1] != '\'')) + // e' un numero oppure null (in questo caso vuoto il valore + { + if (valore == "null") + valore = ""; + lavoro = lavoro.sub(indice1+1); + } + else + // e' una stringa dove c'è una virgola, quindi elaboro diversamente per trovare il vero valore + { + indice1 = lavoro.find("\',"); + indice2 = lavoro.find("\' ,"); + if (indice1 != 1 && indice2 != -1) + { + if (indice2 > indice1) + { + valore = lavoro.sub(0,indice1+1); + lavoro = lavoro.sub(indice1+2); + } + else + { + valore = lavoro.sub(0,indice2+1); + lavoro = lavoro.sub(indice2+3); + } + } + else + { + if (indice1 != 0) + { + valore = lavoro.sub(0,indice1+1); + lavoro = lavoro.sub(indice1+2); + } + else + { + if (indice2 != 0) + { + valore = lavoro.sub(0,indice2-1); + lavoro = lavoro.sub(indice2+3); + } + else + { + // e' l'ultimo campo della lista, quindi non trova la virgola + valore = lavoro.trim(); + lavoro = ""; + } + } + } + valore = valore.sub(1,valore.len()-1); + } + } + } + else + { + valore = lavoro.trim(); + lavoro = ""; + } + } + else + lavoro = ""; + if ((valore[0] == '\'') && (valore[valore.len()-1] == '\'')) + // e' una stringa: tolgo le virgolette + valore = valore.sub(1,valore.len()-1); + else if (valore == "null") + valore = ""; + campo.upper(); + int doppie = valore.find("'"); + while (doppie != -1) + { + if (valore[doppie+1] == '\'') + { + TString str = valore; + valore = str.sub(0,doppie); + valore << str.sub(doppie+1); + } + doppie = valore.find("'", doppie+1); + } + i = valore.find('~'); + if (i != -1) + valore.replace('~','\''); + record.add(campo, valore); + } + } + else + ok = FALSE; + return ok; +} + +bool TCtpr2at::soggetto(const TString& istruzione) +{ + int error = NOERR; + TAssoc_array record; + if (build_record(record, istruzione)) + { + // ricerca del soggetto per cognome, nome e data di nascita + TString80& cognome = (TString80&) record["COGNOME"]; + TString80& nome = (TString80&) record["NOME"]; + TString16& str = (TString16&) record["DT_NASCITA"]; + TDate datanasc = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + // codice centro trasfusionale per verifica cognome, nome, data di nascita + TString16& codct = (TString16&) record["ID_ANAGRAFICA"]; + + _rel->lfile().setkey(2); + TRectype& recsog = _rel->curr(); + recsog.zero(); + recsog.put(SOG_COGNOME, cognome); + recsog.put(SOG_NOME, nome); + recsog.put(SOG_DATANASC, datanasc); + error = recsog.read(_rel->lfile()); + TString80 stampa = ""; + _intestazione = ""; + _intestazione << cognome << " " << nome << " " << datanasc; + if (error != NOERR) + { + // non ho trovato il donatore, cerco per cognome nome e codicesit + recsog.zero(); + recsog.put(SOG_COGNOME, cognome); + recsog.put(SOG_NOME, nome); + error = recsog.read(_rel->lfile()); + bool trovato = FALSE; + while ((!trovato) && (cognome == recsog.get(SOG_COGNOME)) && (nome == recsog.get(SOG_NOME)) && (!_rel->lfile().eof())) + { + TString16 codicesit = recsog.get(SOG_CODCT); + if ((codicesit == codct) && (codicesit.not_empty()) && codct.not_empty()) + { + datanasc = recsog.get_date(SOG_DATANASC); + trovato = TRUE; + } + else + _rel->lfile().next(); + } + if (trovato) + { + recsog.put(SOG_COGNOME, cognome); + recsog.put(SOG_NOME, nome); + recsog.put(SOG_DATANASC, datanasc); + error = recsog.read(_rel->lfile()); + if (error == NOERR) + { + stampa = "Verificare la data di nascita: AVIS "; + stampa << datanasc; + print_line(stampa); + } + } + } + if (error != NOERR) + { + recsog.zero(); + recsog.put(SOG_COGNOME, cognome); + recsog.put(SOG_NOME, nome); + recsog.put(SOG_DATANASC, datanasc); + recsog.put(SOG_NOTIZIARIO, 'X'); + recsog.put(SOG_BENEM, 'X'); + recsog.put(SOG_CODICE, get_next_key()); + error = recsog.write(_rel->lfile()); + stampa = "Inserito da CETRAPLUS"; + print_line(stampa); + } + if (update_record(recsog, record)) + { + TDate oggi(TODAY); + recsog.put(SOG_DATAULTAGG, oggi); + recsog.put(SOG_UTENULTAGG, "CETRAPLUS"); + error = recsog.rewrite(_rel->lfile()); + } + return (error = NOERR); + } + else + return FALSE; +} + +bool TCtpr2at::update_record(TRectype& record_at, TAssoc_array& record_ct) +{ + TString256 stampa = ""; + TString field, str; + bool update = FALSE; + FOR_EACH_ASSOC_STRING(record_ct, obj, key, val) + { + field = _configfile->get(key); + if (field.not_empty()) + { + update = TRUE; + if (field.sub(0,2) == "!_") + { + TString80 elab = field.sub(2); + TString16 campo = ""; + const int virgola = elab.find(','); + if (virgola != -1) + { + campo = elab.sub(virgola+1); + elab = elab.sub(0,virgola); + } + if (elab == "STATO") // stato sanitario + { + TRectype recpr1 = cache().get("PR1", val); + TString16 catdon = recpr1.get("S6"); + TString16 catsog = record_at.get(SOG_CATDON); + if ((catdon.not_empty()) && (catdon != catsog)) + { + bool dimissione = cache().get("CTD", catdon).get_bool("B0"); + if (dimissione) + { + if (catsog == "NU") + catdon = "DN"; + dimissione = cache().get("CTD", catsog).get_bool("B0"); + } + if (!dimissione) + { + if (!(cache().get("CTD", catdon).get_bool("B0")) && (cache().get("CTD", catsog).get_bool("B0"))) + { + stampa = "CATEGORIA diversa: avis "; + stampa << catsog << " sit " << catdon; + print_line(stampa); + } + else + { + if ((catdon == "NU") && (catsog == "AV")) + { + stampa = "CATEGORIA diversa: avis "; + stampa << catsog << " sit " << catdon; + print_line(stampa); + } + else + { + bool cambia = TRUE; + if ((catdon == "AV") && (catsog == "NU")) + { + const int totdon = record_at.get_int(SOG_TOTDON); + if (totdon < 1) + { + cambia = FALSE; + //stampa = "CATEGORIA diversa: avis "; + //stampa << catsog << " sit " << catdon << ", soggetto senza donazioni"; + //print_line(stampa); + } + } + if (cambia) + { + stampa = "Cambio categoria: da "; + stampa << catsog << " a " << catdon; + print_line(stampa); + record_at.put(SOG_CATDON, catdon); + if (cache().get("CTD", catdon).get_bool("B0")) + { + TString16 data = record_at.get(SOG_DATADIM); + if (data.empty()) + { + record_at.put(SOG_DATADIM, _dataagg); + stampa = "Inserita data dimissione "; + stampa << _dataagg.string(); + print_line(stampa); + } + } + } + //aggiorna_storico(); + } + } + } + } + TString16 tipocontrollo = recpr1.get("S7"); + if (tipocontrollo.not_empty()) + { + //aggiorna_controlli(); + } + } + else if (elab == "SESSO") // sesso + { + if (val[0] == 'M') + record_at.put(SOG_SESSO, "1"); // maschio + else if (val[0] == 'F') + record_at.put(SOG_SESSO, "2"); // femmina + else record_at.put(SOG_SESSO, "0"); // non specificato + } + else if (elab == "SEZIONE") // sezione/sottogruppo + { + str = val; + if (str[0] == '0') + str = str.sub(1); + if ((record_at.get(SOG_CODSEZ) != str.sub(0,2)) || (record_at.get(SOG_CODSOT) != str.sub(2,4))) + { + stampa << "SEZIONE diversa: avis " << record_at.get(SOG_CODSEZ); + stampa << record_at.get(SOG_CODSOT) << " sit " << str; + print_line(stampa); + if (record_at.get(SOG_CODSEZ).empty()) + { + record_at.put(SOG_CODSEZ, str.sub(0,2)); + record_at.put(SOG_CODSOT, str.sub(2,4)); + } + } + } + else if (elab == "GIORNOPREF") // giorno preferito donazione + { + str = val; + if (!str.empty()) + { + str << "XXXXXXX"; + str = str.sub(0,7); + for (int i = 0; i< 7; i++) + { + if (str[i] != 'X') + str[i] = 'X'; + else + str[i] = ' '; + } + record_at.put(SOG_GIOPREDON, str); + } + } + else if (elab == "DATA") // data + { + str = val; + TDate data = TDate(atoi(str.sub(8,10)), atoi(str.sub(5,7)), atoi(str.sub(0,4))); + if (campo.not_empty()) + record_at.put(campo, data); + } + else if (elab == "COMUNE") // comune nascita o domicilio + { + update = FALSE; + TString16 codcom = ""; + str = val; + if (str.not_empty()) + { + if (_array_comuni->is_key(str)) + { + codcom = (TString16&) _array_comuni->find(str); + update = (codcom != record_at.get(campo)); + } + else + { + codcom = record_at.get(campo); + if (codcom.not_empty()) + { + codcom = " |"; + codcom << record_at.get(campo); + TRectype reccom = cache().get(LF_COMUNI, codcom); + if (reccom.get_long(COM_CODISTAT) != atol(str)) + update = TRUE; + else + _array_comuni->add(str, reccom.get(COM_COM)) ; + } + else + update = TRUE; + if (update) + { + TString80 filtro = ""; + filtro.format("%s == %ld", COM_CODISTAT, atol(str)); + TCursor cur(_relcom, filtro); + if (cur.items() == 1) + { + cur.next_match(LF_COMUNI); + codcom = cur.curr().get(COM_COM); + _array_comuni->add(str, codcom); + } + else + update = FALSE; + } + } + } + if (campo.not_empty() && update) + record_at.put(campo, codcom); + } + else if (elab == "POSNEG") // positivo e negativo (rh, du) + { + if (val[0] == '+') + record_at.put(campo, "POS"); + else if (val[0] == '-') + record_at.put(campo, "NEG"); + else record_at.put(campo, ""); + } + else if (elab == "KELL") // kell (vuoto = vuoto, presenza di K maiuscola = POS, altrimenti = NEG) + { + str = val; + if (str.empty()) + record_at.put(SOG_KELL, ""); + else if (str.find('K') != -1) + record_at.put(SOG_KELL, "POS"); + else record_at.put(SOG_KELL, "NEG"); + } + else if ((elab == "TELEFONO") || (elab == "CELLULARE") || (elab == "NOCELLULARE")) // toglie barre e altre cose inutili dal numero di telefono + { + str = val; + str.trim(); + if (str.not_empty()) + { + str.strip_spaces(); + str.strip("/"); + str.strip("\\"); + if (elab == "TELEFONO") + record_at.put(campo, str); + else + { + if ((elab == "CELLULARE") && ((str[0]!='0') && (str.len()>9))) + record_at.put(campo, str); + else + if ((elab == "NOCELLULARE") && !((str[0]!='0') && (str.len()>9))) + record_at.put(campo, str); + } + } + } + else if (elab == "SENUMERO") // campo da caricare solo se numerico (nello specifico tess. ssn) + { + long numero = atol(val); + if (numero != 0) + record_at.put(campo, val); + } + else if (elab == "MEDICO") // medico (solo confronto) + { + str = val; + TRectype recmed = cache().get(LF_MEDICI, record_at.get(SOG_CODMED)); + TString80 medico = recmed.get(MED_COGNOME); + medico.trim(); + medico << ' '; + medico << recmed.get(MED_NOME); + medico.trim(); + str.trim(); + if ((medico != str) && (medico.not_empty() || str.not_empty())) + { + bool segnala = TRUE; + int i = medico.len(); + int j = str.len(); + if (i != j) + { + if ((i < j) && i > 0) j = i; + if ((j > 0) && (i > 0)) + segnala = (medico.sub(0,j-1) != str.sub(0,j-1)); + else + segnala = TRUE; + } + if (segnala) + { + TString256 stampa = ""; + stampa << "MEDICO diverso: " << " avis " << medico << " sit " << str; + print_line(stampa); + } + } + } + else if (elab == "INDIRIZZO") // indirizzo (per vedere di isolare la localita) + { + TString80 localita = ""; + str = val; + const int i = str.find('-'); + if (i > 0) + { + localita = str.sub(i+1); + str = str.sub(0,i); + str.trim(); + localita.trim(); + localita.upper(); + } + TString tmp = record_at.get(SOG_DOM_INDIR); + str.trim(); + str = str.upper(); + tmp.trim(); + tmp = tmp.upper(); + if (tmp != str) + { + TString256 stampa = ""; + stampa << "INDIRIZZO "; + if (tmp.empty()) + { + record_at.put(SOG_DOM_INDIR, str); + stampa << " inserito da CETRAPLUS: " << str; + } + else + stampa << " diverso: avis " << tmp << " sit " << str; + print_line(stampa); + stampa = ""; + if (localita.not_empty()) + { + tmp = record_at.get(SOG_DOM_CODLOC); + TString80 desloc = cache().get("LCP",tmp).get("S0"); + desloc.trim(); + if (localita != desloc) + { + stampa << "LOCALITA "; + if (desloc.empty()) + { + TTable lcp("LCP"); + lcp.setkey(2); + lcp.put("S0", localita); + if (lcp.read() == NOERR) + { + tmp = lcp.get("CODTAB"); + record_at.put(SOG_DOM_CODLOC, tmp); + stampa << " inserito da CETRAPLUS: " << tmp << " " << localita; + } + else + stampa << " non presente in tabella avis " << localita; + } + else + stampa << " diverso: avis " << desloc << " sit " << localita; + print_line(stampa); + } + } + } + } + else if ((elab == "CONFRONTA") || (elab == "SEGNALA")) // SEGNALA = solo segnalazione, CONFRONTA = segnala e modifica + { + if (campo.not_empty()) + { + str = val; + TString tmp = record_at.get(campo); + str.trim(); + str = str.upper(); + tmp.trim(); + tmp = tmp.upper(); + if (tmp != str) + { + TString256 stampa = ""; + if (elab == "CONFRONTA") + { + stampa << "Cambio " << campo << ": da " << tmp << " a " << str; + print_line(stampa); + record_at.put(campo, str); + } + else + { + stampa << campo << " diverso: avis " << tmp << " sit " << str; + print_line(stampa); + } + } + } + } + else if (elab == "SEVUOTO") // segnala differenza, e modifica solo se vuoto + { + if (campo.not_empty()) + { + str = val; + TString tmp = record_at.get(campo); + str.trim(); + str = str.upper(); + tmp.trim(); + tmp = tmp.upper(); + if (tmp != str) + { + TString256 stampa = ""; + stampa << campo; + if (tmp.empty()) + { + record_at.put(campo, str); + stampa << " inserito da CETRAPLUS: " << str; + } + else + stampa << " diverso: avis " << tmp << " sit " << str; + print_line(stampa); + + } + } + } + else if ((elab == "CONFRONTADATA") || (elab == "SEGNALADATA")) // come sopra ma per campi data + { + if (campo.not_empty()) + { + str = val; + TDate tmp = record_at.get_date(campo); + TDate data = TDate(atoi(str.sub(8,10)), atoi(str.sub(5,7)), atoi(str.sub(0,4))); + if (tmp != data) + { + TString256 stampa = ""; + stampa << campo << " diverso: avis " << tmp.string(); + stampa << " sit " << data.string(); + print_line(stampa); + if (elab == "CONFRONTA") + record_at.put(campo, data); + } + } + } + } + else + record_at.put(field, val); // campi da passare semplicemente! + } + } + return update; +} + +long TCtpr2at::get_next_key() { - TFilename filect = _msk->get(F_FILENAME); //aggiungere lettura automatica nomi file - _trasfile->open(filect,'r'); + TLocalisamfile soggetti(LF_SOGGETTI); + soggetti.setkey(1); + soggetti.last(); + long codice = soggetti.get_long(SOG_CODICE); + return codice+1; +} + +bool TCtpr2at::accesso(const TString& istruzione) +{ + TString256 stampa = ""; + int error = NOERR; + TAssoc_array record; + if (build_record(record, istruzione)) + { + // ricerca del soggetto per codice SIT + TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"]; + _rel->lfile().setkey(7); + TRectype& recsog = _rel->curr(); + recsog.zero(); + recsog.put(SOG_CODCT, id_anagrafica); + error = recsog.read(_rel->lfile()); + if (error == NOERR) + { + stampa = recsog.get(SOG_COGNOME); + stampa << " " << recsog.get(SOG_NOME); + stampa << " " << recsog.get(SOG_DATANASC); + // ho trovato il soggetto, ora verifico che tipo di accesso è + TString8& tp_accesso = (TString8&)record["TP_ACCESSO"]; + if (tp_accesso[0] == 'D') + { + // trattasi di donazione + // mi serve solo il codabar per decidere il punto di prelievo (la donazione c'è già) + TString8 luogodon_at; + TString16& str = (TString16&) record["DT_ACCESSO"]; + const TDate datadon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + TString16& codabar = (TString16&) record["CODABAR"]; + _donaz->setkey(2); + TRectype& recdon = _donaz->curr(); + recdon.zero(); + recdon.put(DON_CODICE, recsog.get(SOG_CODICE)); + recdon.put(DON_DATADON, datadon); + if (_donaz->read() == NOERR) + { + if ((codabar.left(2) == "52") || (codabar.left(2) == "53") || (codabar.left(2) == "54") || (codabar.left(2) == "55")) + luogodon_at = "0001"; + else + { + if (recsog.get(SOG_CODSEZ) == "13") + luogodon_at = "1301"; + else + luogodon_at = "0000"; + } + recdon.put(DON_LUOGODON, luogodon_at); + _donaz->rewrite(); + TString16& prog = (TString16&) record["PROG_GIORNAL"]; + if (!_array_donaz->is_key(prog)) + _array_donaz->add(prog, record["ID_ANAGRAFICA"]) ; + } + } + else + { + // trattasi di controllo o visita + TString4 tipocon = _configfile->get(tp_accesso, "ACCESSI"); + TString16& str = (TString16&) record["DT_ACCESSO"]; + const TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + if (tipocon.empty()) + { + print_line(stampa); + stampa = "Tipo accesso "; + stampa << tp_accesso[0] << " del "; + stampa << datacon.string() << " senza corrispondenza. Non inserito."; + print_line(stampa); + tipocon = "VS"; + } + else + { + TRectype* recc = new TRectype(LF_CONTSAN); + recc->put(CON_CODICE, recsog.get(SOG_CODICE)); + recc->put(CON_DATACON, datacon); + recc->put(CON_TIPOCON, tipocon); + recc->put(CON_RESPONSAB, "CETRAPLUS"); + + bool insert = FALSE; + bool exist = FALSE; + TRectype* keyc = new TRectype(LF_CONTSAN); + keyc->put(CON_CODICE, recsog.get(SOG_CODICE)); + int err = _scontrolli->read(keyc); + if (err == NOERR) + { + int r=_scontrolli->rows(); + while (r>=1 && !insert && !exist) + { + const TRectype& riga = _scontrolli->row(r); + const TDate d = riga.get(CON_DATACON); + if (datacon==d) // esiste gia' un controllo in questa data + { + exist=TRUE; + r=0; + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Controllo già esistente in data " << datacon.string(); + print_line(stampa); + print_line(); + } + } + else + if (datacon > d) + { + recc->put(CON_PROGCON,r+1); + _scontrolli->insert_row(recc); + insert=TRUE; + } + r--; + } + if (!exist && !insert) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + } + else + if (err == _iseof || err == _isemptyfile) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + if (!exist) + { + _scontrolli->write(TRUE); + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Inserito controllo " << tipocon << " del " << datacon.string(); + print_line(stampa); + print_line(); + } + // aggiorno data e utente ultimo aggiornamento + TDate oggi(TODAY); + recsog.put(SOG_DATAULTAGG, oggi); + recsog.put(SOG_UTENULTAGG, "CETRAPLUS"); + err = recsog.rewrite(_rel->lfile()); + } + } + } + } + else + { + // soggetto non trovato + stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile aggiornare accesso "; + stampa << record["TP_ACCESSO"] << " del "; + stampa << record["DT_ACCESSO"]; + print_line(stampa); + } + return (error = NOERR); + } + else + return FALSE; +} + +bool TCtpr2at::sacca(const TString& istruzione) +{ + TString256 stampa = ""; + int err = NOERR; + TAssoc_array record; + if (build_record(record, istruzione)) + { + // ricerca del soggetto per codice SIT + TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"]; + _rel->lfile().setkey(7); + TRectype& recsog = _rel->curr(); + recsog.zero(); + recsog.put(SOG_CODCT, id_anagrafica); + err = recsog.read(_rel->lfile()); + if (err == NOERR) + { + stampa = recsog.get(SOG_COGNOME); + stampa << " " << recsog.get(SOG_NOME); + stampa << " " << recsog.get(SOG_DATANASC); + // ho trovato il soggetto, ora verifico la donazione + TString16& str = (TString16&) record["DT_PRELIEVO"]; + const TDate datadon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + _progins++; + TRectype* rec = new TRectype(LF_DONAZ); + rec->put(DON_CODICE, recsog.get(SOG_CODICE)); + rec->put(DON_DATADON, datadon); + str = (TString16&) record["TP_DONAZIONE"]; + TRectype recpr2 = cache().get("PR2", str); + TString16 tipodon = recpr2.get("S6"); + if (tipodon.empty()) + { + print_line(stampa); + stampa = ""; + stampa << "Tipo donazione SIT " << str << " senza corrispondenza: non inserita"; + print_line(stampa); + stampa = ""; + } + else + { + rec->put(DON_TIPODON, tipodon); + TString16& etichetta = (TString16&) record["ID_SACCA"]; + rec->put(DON_ETICHETTA, etichetta); + rec->put(DON_CODSEZ, recsog.get(SOG_CODSEZ)); + rec->put(DON_CODSOT, recsog.get(SOG_CODSOT)); + rec->put(DON_PROGINS, _progins); + + bool insert = FALSE; + bool exist = FALSE; + TRectype* key = new TRectype(LF_DONAZ); + key->put(DON_CODICE, recsog.get(SOG_CODICE)); + err = _sdonazioni->read(key); + if (err == NOERR) + { + int r=_sdonazioni->rows(); + while (r>=1 && !insert && !exist) + { + const TRectype& riga = _sdonazioni->row(r); + const TDate d = riga.get(DON_DATADON); + if (datadon==d) // esiste gia' una donazione in questa data + { + exist=TRUE; + r=0; + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Donazione già esistente in data " << datadon.string(); + print_line(stampa); + print_line(); + } + } + else + if (datadon > d) + { + rec->put(DON_PROGDON,r+1); + _sdonazioni->insert_row(rec); + insert=TRUE; + } + r--; + } + if (!exist && !insert) + { + rec->put(DON_PROGDON,1); + _sdonazioni->insert_row(rec); + } + } + else + if (err == _iseof || err == _isemptyfile) + { + rec->put(DON_PROGDON,1); + rec->put(DON_PRIMADON,'X'); + _sdonazioni->insert_row(rec); + } + if (!exist) + { + err = _sdonazioni->write(TRUE); + if (err == NOERR) + { + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Inserita donazione del " << datadon; + print_line(stampa); + } + calcola_donazioni_lib(recsog, _sdonazioni); // questo metodo sistema tutto!!! + calcola_categoria(recsog); // modificato per dare i messaggi al posto dei veri cambiamenti + print_line(); + // aggiorno data e utente ultimo aggiornamento + TDate oggi(TODAY); + recsog.put(SOG_DATAULTAGG, oggi); + recsog.put(SOG_UTENULTAGG, "CETRAPLUS"); + err = recsog.rewrite(_rel->lfile()); + } + //else + //error_box("Errore %d in scrittura archivio donazioni, riga %d", err, rigasog); + } + } + } + else + { + // soggetto non trovato + stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire donazione "; + stampa << record["TP_DONAZIONE"] << " del "; + stampa << record["DT_PRELIEVO"]; + print_line(stampa); + print_line(); + } + } + return TRUE; +} + +bool TCtpr2at::analisi(const TString& istruzione) +{ + TString256 stampa = ""; + int error = NOERR; + TAssoc_array record; + if (build_record(record, istruzione)) + { + TString16& id_analisi = (TString16&) record["ID_ANALISI"]; + TString4 tipocon = _configfile->get(id_analisi, "ANALISI"); + if (!tipocon.empty()) + { + TString16& prog = (TString16&) record["PROG_GIORNAL"]; + if (_array_donaz->is_key(prog)) + { + // ricerca del soggetto per codice SIT + TString16& id_anagrafica = (TString16&) _array_donaz->find(prog); + _rel->lfile().setkey(7); + TRectype& recsog = _rel->curr(); + recsog.zero(); + recsog.put(SOG_CODCT, id_anagrafica); + error = recsog.read(_rel->lfile()); + if (error == NOERR) + { + stampa = recsog.get(SOG_COGNOME); + stampa << " " << recsog.get(SOG_NOME); + stampa << " " << recsog.get(SOG_DATANASC); + TString16& str = (TString16&) record["DT_ACCESSO"]; + const TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + + TRectype* recc = new TRectype(LF_CONTSAN); + recc->put(CON_CODICE, recsog.get(SOG_CODICE)); + recc->put(CON_DATACON, datacon); + recc->put(CON_TIPOCON, tipocon); + recc->put(CON_RESPONSAB, "CETRAPLUS"); + + bool insert = FALSE; + bool exist = FALSE; + TRectype* keyc = new TRectype(LF_CONTSAN); + keyc->put(CON_CODICE, recsog.get(SOG_CODICE)); + int err = _scontrolli->read(keyc); + if (err == NOERR) + { + int r=_scontrolli->rows(); + while (r>=1 && !insert && !exist) + { + const TRectype& riga = _scontrolli->row(r); + const TDate d = riga.get(CON_DATACON); + if (datacon==d) // esiste gia' un controllo in questa data + { + exist=TRUE; + r=0; + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Controllo già esistente in data " << datacon.string(); + print_line(stampa); + print_line(); + } + } + else + if (datacon > d) + { + recc->put(CON_PROGCON,r+1); + _scontrolli->insert_row(recc); + insert=TRUE; + } + r--; + } + if (!exist && !insert) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + } + else + if (err == _iseof || err == _isemptyfile) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + if (!exist) + { + _scontrolli->write(TRUE); + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Inserito controllo " << tipocon << " del " << datacon.string(); + print_line(stampa); + print_line(); + } + // aggiorno data e utente ultimo aggiornamento + TDate oggi(TODAY); + recsog.put(SOG_DATAULTAGG, oggi); + recsog.put(SOG_UTENULTAGG, "CETRAPLUS"); + err = recsog.rewrite(_rel->lfile()); + } + } + else + { + // soggetto non trovato + stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire controllo "; + stampa << record["ID_ANALISI"] << " del "; + stampa << record["DT_ACCESSO"]; + print_line(stampa); + print_line(); + } + return (error = NOERR); + } + } + } + return FALSE; +} + +bool TCtpr2at::intervalli(const TString& istruzione) +{ + return TRUE; +} + +bool TCtpr2at::esclusione(const TString& istruzione) +{ + int error = NOERR; + TAssoc_array record; + if (build_record(record, istruzione)) + { + TString16& strc = (TString16&) record["DT_CANCEL"]; + const TDate dt_cancel = TDate(atoi(strc.sub(8,10)) ,atoi(strc.sub(5,7)), atoi(strc.sub(0,4))); + if (dt_cancel.empty()) + { + TString16& tp_esclusione = (TString16&) record["TP_ESCLUSIONE"]; + TString4 tipocon = _configfile->get(tp_esclusione, "ESCLUSIONI"); + if (!tipocon.empty()) + { + // ricerca del soggetto per codice SIT + TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"]; + _rel->lfile().setkey(7); + TRectype& recsog = _rel->curr(); + recsog.zero(); + recsog.put(SOG_CODCT, id_anagrafica); + error = recsog.read(_rel->lfile()); + TString256 stampa = ""; + if (error == NOERR) + { + stampa = recsog.get(SOG_COGNOME); + stampa << " " << recsog.get(SOG_NOME); + stampa << " " << recsog.get(SOG_DATANASC); + // ho trovato il soggetto + const long codsog = recsog.get_long(SOG_CODICE); + //TString16& str = (TString16&) record["DA_DATA"]; + //const TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + const TDate datacon(TODAY); + TString16& str = (TString16&) record["A_DATA"]; + const TDate datapross = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4))); + TDate datanulla(NULLDATE); + if ((datacon < datapross) || (datapross == datanulla)) + { + TRectype* recc = new TRectype(LF_CONTSAN); + recc->put(CON_CODICE, recsog.get(SOG_CODICE)); + recc->put(CON_DATACON, datacon); + recc->put(CON_TIPOCON, tipocon); + recc->put(CON_PROSSDATA, datapross); + recc->put(CON_PROSSTIPO, tipocon); + recc->put(CON_RESPONSAB, "CETRAPLUS"); + + bool insert = FALSE; + bool exist = FALSE; + TRectype* keyc = new TRectype(LF_CONTSAN); + keyc->put(CON_CODICE, recsog.get(SOG_CODICE)); + int err = _scontrolli->read(keyc); + if (err == NOERR) + { + int r=_scontrolli->rows(); + while (r>=1 && !insert && !exist) + { + const TRectype& riga = _scontrolli->row(r); + const TDate d = riga.get(CON_DATACON); + if (datacon==d) // esiste gia' un controllo in questa data + { + exist=TRUE; + r=0; + if (_message) + { + print_line(stampa); + stampa = ""; + stampa << "Controllo già esistente in data " << datacon.string(); + print_line(stampa); + print_line(); + } + } + else + if (datacon > d) + { + recc->put(CON_PROGCON,r+1); + _scontrolli->insert_row(recc); + insert=TRUE; + } + r--; + } + if (!exist && !insert) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + } + else + if (err == _iseof || err == _isemptyfile) + { + recc->put(CON_PROGCON,1); + _scontrolli->insert_row(recc); + } + if (!exist) + { + _scontrolli->write(TRUE); + TRectype* key = new TRectype(LF_IDONEITA); + key->put(IDO_CODICE, recsog.get(SOG_CODICE)); + _sidoneita->read(key); + con_reord(recsog, _scontrolli, _sidoneita); + if (datapross.empty()) + { + print_line(stampa); + stampa = ""; + stampa << "Inserita sospensione " << tipocon << " dal " << datacon.string(); + stampa << " al " << datapross.string(); + print_line(stampa); + print_line(); + } + // aggiorno data e utente ultimo aggiornamento + TDate oggi(TODAY); + recsog.put(SOG_DATAULTAGG, oggi); + recsog.put(SOG_UTENULTAGG, "CETRAPLUS"); + err = recsog.rewrite(_rel->lfile()); + } + } + //else + //{ + // print_line(stampa); + // stampa = ""; + // stampa << "Sospensione " << tipocon << " dal " << datacon.string(); + // stampa << " al " << datapross.string(); + // stampa << " non inserita perchè già scaduta"; + // print_line(stampa); + // print_line(); + //} + } + else + { + // soggetto non trovato + stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire sospensione "; + stampa << record["TP_ESCLUSIONE"] << " dal "; + stampa << record["DA_DATA"]; + stampa << " al " << record["A_DATA"]; + print_line(stampa); + print_line(); + } + return (error = NOERR); + } + } + } + return FALSE; + } // handler per gestire la conferma dell'annullamento dei dati inseriti @@ -477,27 +1590,6 @@ bool TCtpr2at::annulla_handler(TMask_field& f, KEY k) return TRUE; } -void TCtpr2at_file::preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString &tipo_tr) -{ - TString tmp; - TString80 fieldname = field.name(); - if (fieldname == "SESSO") - { - const char sesso = str[0]; - if (sesso == 'M') - str = "1"; - else if (sesso == 'F') - str = "2"; - else str = " "; - } - else if ((fieldname == "CODCF") || (fieldname == "TESSSSN")) - { - tmp = rel.curr(field.file()).get(fieldname); - if (tmp.not_empty()) - str.cut(0); - } -} - int at8900(int argc, char* argv[]) { TCtpr2at a; diff --git a/at/at8900a.uml b/at/at8900a.uml index 6870f235d..91c759fb8 100755 --- a/at/at8900a.uml +++ b/at/at8900a.uml @@ -14,7 +14,7 @@ END ENDPAGE -PAGE "Acquisizione dati da SIT Parma" -1 -1 78 20 +PAGE "Aggiornamento archivi da SIT Parma" -1 -1 78 20 GROUPBOX DLG_NULL 77 9 BEGIN diff --git a/at/at8a00.cpp b/at/at8a00.cpp index 1ec6ff5b1..74d7f8d21 100755 --- a/at/at8a00.cpp +++ b/at/at8a00.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +//#include #include #include @@ -31,6 +31,7 @@ class TCtDonpr2at_file: public TFile_text { protected: virtual void preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString &tipo_tr); + virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str); public: virtual int autosave(TRelation& rel, const TRecord_text& rec); @@ -44,6 +45,18 @@ TCtDonpr2at_file::TCtDonpr2at_file(const TString& file_name, const TString& conf { } +void TCtDonpr2at_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str) +{ + const TString code(s.get(0)); + TString valore; + if (code == "_UPPERCASE") + { + valore.upper(); + } + else NFCHECK("Macro non definita: %s", (const char *)code); + str = valore; +} + int TCtDonpr2at_file::autosave(TRelation& rel, const TRecord_text& rec) { const TString& type = rec.type();//prendo il tracciato record del tipo del record_text @@ -230,6 +243,7 @@ bool TCtDonpr2at::test_donation(TRectype& recsog, const char* tipo, const TDate& void TCtDonpr2at::calcola_categoria(TRectype& recsog) { + TString256 rigastampa; TTable ctd("CTD"); TString4 catdon = recsog.get(SOG_CATDON); const int totdon = recsog.get_int(SOG_TOTDON); @@ -239,24 +253,32 @@ void TCtDonpr2at::calcola_categoria(TRectype& recsog) bool dimissione = ctd.get_bool("B0"); if (dimissione) { + rigastampa.format("Categoria: attuale %s", (const char*) catdon); const TString& cat_coll = ctd.get("S6"); if (cat_coll.not_empty()) { catdon = cat_coll; - recsog.put(SOG_CATDON, catdon); - } - } - if ((catdon == _catini1 || _catini1.empty()) && (totdon>=_numdon1) && _catfin1.not_empty()) - { - recsog.put(SOG_CATDON, _catfin1); - catdon = _catfin1; - } - bool tstampata = recsog.get_bool(SOG_T_STAMPATA); - if ((catdon == _catini2 || _catini2.empty()) && (totdon>=_numdon2) && _catfin2.not_empty() && (!_sttess2 || tstampata)) - { - recsog.put(SOG_CATDON, _catfin2); - catdon = _catfin2; - } + //recsog.put(SOG_CATDON, catdon); + } + } + if ((catdon == _catini1 || _catini1.empty()) && (totdon>=_numdon1) && _catfin1.not_empty()) + { + if (!dimissione) + recsog.put(SOG_CATDON, _catfin1); + catdon = _catfin1; + } + bool tstampata = recsog.get_bool(SOG_T_STAMPATA); + if ((catdon == _catini2 || _catini2.empty()) && (totdon>=_numdon2) && _catfin2.not_empty() && (!_sttess2 || tstampata)) + { + if (!dimissione) + recsog.put(SOG_CATDON, _catfin2); + catdon = _catfin2; + } + if (dimissione) + { + rigastampa << " - calcolata " << catdon; + print_line(rigastampa); + } } } @@ -354,6 +376,16 @@ void TCtDonpr2at::new_sogg(TRectype& sogg, const TRecord_text& curr) long codice = soggetti.get_long(SOG_CODICE); sogg.put(SOG_CODICE, codice+1); sogg.put(SOG_CATDON, "NU"); + TString str; + str = curr.get(32); + if (str[0] == '0') + str = str.sub(1); + sogg.put(SOG_CODSEZ, str.sub(0,2)); + sogg.put(SOG_CODSOT, str.sub(2,4)); + const TDate oggi(TODAY); + sogg.put(SOG_DATAULTAGG,oggi); + sogg.put(SOG_UTENULTAGG,"SIT"); + } // trasferimento dati da file CT su programma avis @@ -365,7 +397,7 @@ void TCtDonpr2at::transfer() _trasfile = new TCtDonpr2at_file(_msk->get(F_FILENAME), ctprini); inizializza_file(); const long dimension = fsize(_msk->get(F_FILENAME)); - TProgind pi(dimension,"Acquisizione in corso..."); + //TProgind pi(dimension,"Acquisizione in corso..."); TRelation rel(LF_SOGGETTI); rel.lfile().setkey(2); TRectype& sogg = rel.curr(); @@ -379,7 +411,7 @@ void TCtDonpr2at::transfer() bool cancelled = FALSE; while ((_trasfile->read(curr) == NOERR) && (!cancelled)) { - pi.setstatus(_trasfile->read_file()->tellg()); + //pi.setstatus(_trasfile->read_file()->tellg()); // cerco il donatore con cognome, nome e data nascita cognome = curr.get(1); str = cognome.left(7); @@ -444,14 +476,14 @@ void TCtDonpr2at::transfer() } // aggiungere le visite e i controlli } - cancelled = pi.iscancelled(); + //cancelled = pi.iscancelled(); } _trasfile->close(); print_footer(); - if (cancelled) - message_box("Operazione annullata: il trasferimento non è stato completato"); - else - message_box("Operazione terminata"); + //if (cancelled) + // message_box("Operazione annullata: il trasferimento non è stato completato"); + //else + // message_box("Operazione terminata"); } else error_box("Errore in apertura stampante."); @@ -480,7 +512,8 @@ bool TCtDonpr2at::annulla_handler(TMask_field& f, KEY k) void TCtDonpr2at_file::preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString &tipo_tr) { TString tmp; - TString80 fieldname = field.name(); + TString80 fieldname = field.name(); + if (fieldname == "SESSO") { const char sesso = str[0]; @@ -490,6 +523,18 @@ void TCtDonpr2at_file::preformat_field(const TFieldref&field,TString &str,TRelat str = "2"; else str = " "; } + else if (fieldname == "PREFERENZE") // giorno preferito donazione + { + str << "XXXXXXX"; + str = str.sub(0,7); + for (int i = 0; i< 7; i++) + { + if (str[i] != 'X') + str[i] = 'X'; + else + str[i] = ' '; + } + } else if ((fieldname == "CODCF") || (fieldname == "TESSSSN")) { tmp = rel.curr(field.file()).get(fieldname);