#include #include #include "atlib.h" #include "soggetti.h" #include "contsan.h" #include "idoneita.h" #define IDON_SI "SI" #define IDON_AF "AF" #define IDONEITA "ID" #define SOSPENSIONE "SO" bool is_idon_one(TString16 idon, const char* tipo) // verifica che l'idoneità "idon" sia del tipo "tipo" // esempio: se passo PL, AF restituisce TRUE { bool is_idon = FALSE; TTable ido("IDO"); ido.put("CODTAB",idon); if (ido.read() == NOERR) { TString tipol(2); tipol = ido.get("S6"); if (tipol == tipo) is_idon = TRUE; } return is_idon; } bool is_idon(TString16 id1, TString16 id2, TString16 id3, TString16 id4, const char* tipo) //verifica che almeno una delle "id" sia del tipo "tipo" { return (is_idon_one(id1,tipo) || is_idon_one(id2,tipo) || is_idon_one(id3,tipo) || is_idon_one(id4,tipo)); } bool is_donaz(TString16 don, const char* tipo) // verifica che il tipo di donazione "don" sia del tipo "tipo" { bool is_don = FALSE; TTable tdn("TDN"); tdn.put("CODTAB",don); if (tdn.read() == NOERR) { TString tipol(2); tipol = tdn.get("S6"); if (tipol == tipo) is_don = TRUE; } return is_don; } char modstato_tcs(TString16 tipo) // verifica se il controllo sanitario "tipo" e' un controllo che modifica // lo stato del soggetto { char modstato = ' '; TTable tcs("TCS"); tcs.put("CODTAB",tipo); if (tcs.read() == NOERR) modstato = tcs.get_char("S6"); return modstato; } void con_reord(TRectype& soggetto, TRecord_array* controlli) { TDate data, prossdata; TString16 tipo, prosstipo; char modstato = ' '; int r_modifica = -1; // eventuale ultima riga di modifica id. int r_ultid = -1; // riga ultima idoneità int r_ultstato = -1; // riga ultimo stato valido char penultstato = ' '; // penultimo stato valido char ultstato = ' '; // ultimo stato valido TDate dataultstato(NULLDATE); // data ultimo stato valido for (int r=controlli->rows(); r>=1; r--) { const TRectype& row = controlli->row(r); tipo = row.get(CON_TIPOCON); modstato = modstato_tcs(tipo); if (modstato == 'M') { if (r_modifica == -1) r_modifica = r; } else { if ((modstato != ' ') && (r_ultstato == -1)) r_ultstato = r; else if ((modstato != ' ') && (penultstato == ' ')) penultstato = modstato; if ((modstato == 'I') && (r_ultid == -1)) r_ultid = r; } } TString16 id1 = ' '; TString16 id2 = ' '; TString16 id3 = ' '; TString16 id4 = ' '; int intsi = 0; int intaf = 0; tipo = ' '; prosstipo = ' '; data = TDate(NULLDATE); prossdata = TDate(NULLDATE); if (r_ultid != -1) { const TRectype& row = controlli->row(r_ultid); data = TDate(row.get(CON_DATACON)); tipo = row.get(CON_TIPOCON); id1 = row.get(CON_IDON1); id2 = row.get(CON_IDON2); id3 = row.get(CON_IDON3); id4 = row.get(CON_IDON4); intsi = row.get_int(CON_INTSI); intaf = row.get_int(CON_INTAF); if (r_modifica > r_ultid) { const TRectype& rowm = controlli->row(r_modifica); id1 = rowm.get(CON_IDON1); id2 = rowm.get(CON_IDON2); id3 = rowm.get(CON_IDON3); id4 = rowm.get(CON_IDON4); intsi = rowm.get_int(CON_INTSI); intaf = rowm.get_int(CON_INTAF); } } soggetto.put(SOG_DATAULTID,data); soggetto.put(SOG_TIPOULTID,tipo); soggetto.put(SOG_IDON1,id1); soggetto.put(SOG_IDON2,id2); soggetto.put(SOG_IDON3,id3); soggetto.put(SOG_IDON4,id4); const int intsisog = soggetto.get_int(SOG_INTSI); if (intsi > 0 || intsisog == 0) soggetto.put(SOG_INTSI,intsi); const int intafsog = soggetto.get_int(SOG_INTAF); if (intaf > 0 || intafsog == 0) soggetto.put(SOG_INTAF,intaf); tipo = ' '; if (r_ultstato != -1) { const TRectype& row = controlli->row(r_ultstato); dataultstato = TDate(row.get(CON_DATACON)); tipo = row.get(CON_TIPOCON); prosstipo = row.get(CON_PROSSTIPO); prossdata = TDate(row.get(CON_PROSSDATA)); ultstato = modstato_tcs(tipo); } soggetto.put(SOG_STATO,tipo); soggetto.put(SOG_DATASTATO,dataultstato); soggetto.put(SOG_PROS_STATO,prosstipo); soggetto.put(SOG_DATA_PROS,prossdata); don_datepross(soggetto); if ((penultstato == 'S') && ((ultstato == 'I') || (ultstato == 'F'))) { data = soggetto.get_date(SOG_DATAPROSSI); if (data < dataultstato && data.ok()) soggetto.put(SOG_DATAPROSSI,dataultstato); data = soggetto.get_date(SOG_DATAPROSAF); if (data < dataultstato && data.ok()) soggetto.put(SOG_DATAPROSAF,dataultstato); } if ((penultstato == '1') && (ultstato == 'F')) { data = soggetto.get_date(SOG_DATAPROSSI); if (data < dataultstato) soggetto.put(SOG_DATAPROSSI,dataultstato); } if ((penultstato == '2') && (ultstato == 'F')) { data = soggetto.get_date(SOG_DATAPROSAF); if (data < dataultstato) soggetto.put(SOG_DATAPROSAF,dataultstato); } } void ido_reord(TRectype& soggetto, TRecord_array* idoneita) { TDate dataido, finesos; TString16 tipoido, ido_sos; int intervallo; bool fattoSI = FALSE; bool fattoAF = FALSE; TString16 id1 = soggetto.get(SOG_IDON1); TString16 id2 = soggetto.get(SOG_IDON2); TString16 id3 = soggetto.get(SOG_IDON3); TString16 id4 = soggetto.get(SOG_IDON4); const TDate datastato = soggetto.get_date(SOG_DATASTATO); for (int r=idoneita->rows(); r>=1; r--) { const TRectype& row = idoneita->row(r); dataido = row.get_date(IDO_DATAIDO); if (dataido >= datastato) { tipoido = row.get(IDO_TIPOIDO); ido_sos = row.get(IDO_IDO_SOS); intervallo = row.get_int(IDO_INTERVALLO); finesos = row.get_date(IDO_FINESOS); if (tipoido == IDON_SI && !fattoSI) { fattoSI = TRUE; soggetto.put(SOG_DATASI,dataido); soggetto.put(SOG_STATOSI,ido_sos); soggetto.put(SOG_FINESOSSI,finesos); if (intervallo != 0 && ido_sos == IDONEITA) soggetto.put(SOG_INTSI,intervallo); // sistemare le idoneita idon1,2,3,4 } if (tipoido == IDON_AF && !fattoAF) { fattoAF = TRUE; soggetto.put(SOG_DATAAF,dataido); soggetto.put(SOG_STATOAF,ido_sos); soggetto.put(SOG_FINESOSAF,finesos); if (intervallo != 0 && ido_sos == IDONEITA) soggetto.put(SOG_INTAF,intervallo); // sistemare le idoneita idon1,2,3,4 } } } if (fattoSI || fattoAF) { TDate datastato = soggetto.get_date(SOG_DATASTATO); TDate datastatosi = soggetto.get_date(SOG_DATASI); TDate datastatoaf = soggetto.get_date(SOG_DATAAF); if (datastato < datastatosi || datastato < datastatoaf) { TString16 stato = soggetto.get(SOG_STATO); TString16 statosi = soggetto.get(SOG_STATOSI); TString16 statoaf = soggetto.get(SOG_STATOAF); if (statosi == SOSPENSIONE && statoaf == SOSPENSIONE) stato = SOSPENSIONE; else stato = IDONEITA; soggetto.put(SOG_STATO,stato); don_datepross(soggetto); } } else { soggetto.put(SOG_STATOSI," "); soggetto.put(SOG_DATASI,NULLDATE); soggetto.put(SOG_FINESOSSI,NULLDATE); soggetto.put(SOG_STATOAF," "); soggetto.put(SOG_DATAAF,NULLDATE); soggetto.put(SOG_FINESOSAF,NULLDATE); don_datepross(soggetto); } } void don_datepross(TRectype& soggetto) // calcola le date di prossima donazione in base a: donazioni, stato attuale, idoneità { char modstato = ' '; const TString16 stato = soggetto.get(SOG_STATO); // stato attuale const TString16 id1 = soggetto.get(SOG_IDON1); // idon. 1 const TString16 id2 = soggetto.get(SOG_IDON2); // idon. 2 const TString16 id3 = soggetto.get(SOG_IDON3); // idon. 3 const TString16 id4 = soggetto.get(SOG_IDON4); // idon. 4 const int intsi = soggetto.get_int(SOG_INTSI); // intervallo per SI const int intaf = soggetto.get_int(SOG_INTAF); // intervallo per AF const TDate dataultdon(soggetto.get_date(SOG_DATAULTDON)); // data ultima donazione const TString16 tipoultdon(soggetto.get(SOG_TIPOULTDON)); // tipo ultima donazione TDate datasi(NULLDATE); // data prossima si calcolata TDate dataaf(NULLDATE); // data prossima af calcolata TDate dataultsi(NULLDATE); // data ultima donazione si bool id_si = FALSE; // il soggetto è idoneo per si? bool id_af = FALSE; // il soggetto è idoneo per af? modstato = modstato_tcs(stato); if (modstato == 'I' || modstato == 'F' || modstato == '1' || modstato == '2') // il soggetto è idoneo { id_si = (is_idon(id1,id2,id3,id4,IDON_SI) && intsi != 0); // il soggetto è idoneo SI id_af = (is_idon(id1,id2,id3,id4,IDON_AF) && intaf != 0); // il soggetto è idoneo AF if (dataultdon.ok()) // se ha fatto almeno una donazione { if (is_donaz(tipoultdon,IDON_SI)) // se l'ultima donazione è una SI { if (id_si) { datasi=dataultdon; datasi+=intsi; } if (id_af) { dataaf=dataultdon; dataaf+=intaf; } } if (is_donaz(tipoultdon,IDON_AF)) // se l'ultima donazione è una AF { dataultsi = soggetto.get(SOG_DATAULTSI); if (id_si) { if (intaf != 0) { datasi=dataultdon; datasi+=intaf; } else { datasi=dataultdon; datasi+=intsi; } if (dataultsi.ok()) dataultsi+=intsi; if (dataultsi > datasi) datasi = dataultsi; } if (id_af) { dataaf=dataultdon; dataaf+=intaf; } } } else { if (id_si) datasi = soggetto.get_date(SOG_DATAULTID); if (id_af) dataaf = soggetto.get_date(SOG_DATAULTID); } } if (modstato == '1') datasi = NULLDATE; if (modstato == '2') dataaf = NULLDATE; soggetto.put(SOG_DATAPROSSI,datasi); soggetto.put(SOG_DATAPROSAF,dataaf); }