#include #include #include "atlib.h" #include "soggetti.h" #include "contsan.h" 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); soggetto.put(SOG_INTSI,intsi); 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) soggetto.put(SOG_DATAPROSSI,dataultstato); data = soggetto.get_date(SOG_DATAPROSAF); if (data < dataultstato) 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 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); }