Ejemplo n.º 1
0
        public PazienteDTO RetrievePazi(string paziid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            log.Info(string.Format("Starting ..."));

            PazienteDTO pazi = null;

            pazi = bll.GetPazienteById(paziid);

            tw.Stop();
            log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));

            return(pazi);
        }
Ejemplo n.º 2
0
        public bool StoreNewRequest(RichiestaLISDTO rich, List <AnalisiDTO> anals, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            log.Info(string.Format("Starting ..."));

            string hl7_stato = IBLL.HL7StatesRichiestaLIS.Idle;
            bool   stored    = true;

            string res    = null;
            string resExt = null;

            RichiestaLISDTO   richInserted  = null;
            List <AnalisiDTO> analsInserted = null;

            if (errorString == null)
            {
                errorString = "";
            }

            try
            {
                // Validation of Rich!!!!
                if (!this.ValidateRich(rich, ref errorString))
                {
                    string msg = "Validation of Rich Failure! Check the error string for figuring out the issue!";
                    log.Info(msg + "\r\n" + errorString);
                    log.Error(msg + "\r\n" + errorString);
                    throw new Exception(msg);
                }

                // Unique ID of Paziente Checking and Inserting
                log.Info(string.Format("PAZI's existence checking ..."));
                string pLName = rich.pazinome != null?rich.pazinome.Trim() : null;

                string pFName = rich.pazicogn != null?rich.pazicogn.Trim() : null;

                string pSex = rich.pazisess != null?rich.pazisess.Trim() : null;

                string pBDate = rich.pazidata != null && rich.pazidata.HasValue ? rich.pazidata.Value.ToShortDateString() : null;
                string pCofi  = rich.pazicofi != null?rich.pazicofi.Trim() : null;

                log.Info(string.Format("Nome: {0} - Cognome: {1} - Sesso: {2} - Data di Nascita: {3} - Codice Fiscale: {4}", pLName, pFName, pSex, pBDate, pCofi));
                List <PazienteDTO> pazis = this.GetPazienteBy5IdentityFields(pFName, pLName, pSex, rich.pazidata.Value, pCofi);
                int paziInsertedRows     = 0;
                int paziunico            = 0;
                if (pazis != null && pazis.Count > 0)
                {
                    log.Info(string.Format("PAZI: {0} {1} exists! {2} related record(s) found!", pFName, pLName, pazis.Count));
                    foreach (PazienteDTO pazi in pazis)
                    {
                        log.Info(string.Format("PAZIIDID: {0}", pazi.paziidid));
                        if (pazi.paziidid.Value > paziunico)
                        {
                            paziunico = pazi.paziidid.Value;
                        }
                    }
                    log.Info(string.Format("Paziunico chose is: {0}!", paziunico));
                }
                else
                {
                    log.Info(string.Format("PAZI not found! Inserting of the requested PAZI. Processing ..."));
                    PazienteDTO paziToInsert = new PazienteDTO();
                    paziToInsert.pazicogn   = rich.pazicogn;
                    paziToInsert.pazinome   = rich.pazinome;
                    paziToInsert.pazisess   = rich.pazisess;
                    paziToInsert.pazidata   = rich.pazidata;
                    paziToInsert.pazicofi   = rich.pazicofi;
                    paziToInsert.pazitele   = rich.pazitele;
                    paziToInsert.paziteam   = rich.paziteam;
                    paziToInsert.paziviaa   = rich.paziCoRe_via;
                    paziToInsert.paziprov   = rich.paziPrRe_txt;
                    paziToInsert.pazicomu   = rich.paziCoRe_txt;
                    paziToInsert.pazictnz   = rich.paziNaNa_cod;
                    paziToInsert.paziasll   = rich.paziAsl_cod;
                    paziToInsert.nominativo = rich.pazicogn + ", " + rich.pazinome;
                    PazienteDTO paziInserted = this.AddPaziente(paziToInsert);
                    if (paziInserted == null)
                    {
                        throw new Exception("Error during PAZI writing into the DB.");
                    }
                    paziunico = paziInserted.paziidid.Value;
                    log.Info(string.Format("Paziunico got is: {0}!", paziunico));
                    log.Info(string.Format("PAZI Inserted. Got {0} ID!", paziunico));
                    paziToInsert = null;
                    paziInserted = null;
                }

                // Rich Inserting
                rich.hl7_stato   = hl7_stato;
                rich.paziidunico = paziunico;
                log.Info(string.Format("RICH Inserting ..."));
                richInserted = this.AddRichiestaLIS(rich);
                if (richInserted == null)
                {
                    throw new Exception("Error during RICH writing into the DB.");
                }
                log.Info(string.Format("RICH Inserted. Got {0} as ID and {1} as IDExt!", richInserted.id, richInserted.richidid));

                res    = richInserted.id.ToString();
                resExt = richInserted.richidid;

                //anals.ForEach(p => { p.analesam = int.Parse(res); p.hl7_stato = hl7_stato; });
                anals.ForEach(p => { p.analrich = resExt; p.hl7_stato = hl7_stato; });

                // Validation of Anals!!!!
                if (!this.ValidateAnals(anals, ref errorString))
                {
                    string msg = "Validation of Anals Failure! Check the error string for figuring out the issue!";
                    log.Info(msg + "\r\n" + errorString);
                    log.Error(msg + "\r\n" + errorString);
                    throw new Exception(msg);
                }

                log.Info(string.Format("Inserting of {0} ANAL requested. Processing ...", anals.Count));
                analsInserted = this.AddAnalisis(anals);
                if ((analsInserted == null) || (analsInserted != null && analsInserted.Count != anals.Count))
                {
                    throw new Exception("Error during ANALs writing into the DB.");
                }
                log.Info(string.Format("Inserted {0} ANAL successfully!", analsInserted.Count));

                log.Info(string.Format("Inserted {0} records successfully!", analsInserted.Count + 1 + paziInsertedRows));
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);

                if (errorString == "")
                {
                    errorString = msg + "\r\n" + ex.Message;
                }
                else
                {
                    errorString += "\r\n" + msg + "\r\n" + ex.Message;
                }

                int richRB  = 0;
                int analsRB = 0;

                log.Info(string.Format("Rolling Back of the Insertings due an error occured ..."));
                // Rolling Back
                if (res != null)
                {
                    richRB = this.DeleteRichiestaLISById(res);
                    log.Info(string.Format("Rolled Back {0} RIC record. ID was {1} and RICHIDID was {2}!", richRB, res, resExt));
                    analsRB = this.DeleteAnalisisByIdRichiestaExt(resExt);
                    log.Info(string.Format("Rolled Back {0} ANAL records. ANALRICH was {1}!", analsRB, resExt));
                }
                log.Info(string.Format("Rolled Back {0} records of {1} requested!", richRB + analsRB, anals.Count + 1));
                stored = false;
            }

            tw.Stop();
            log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));

            if (errorString == "")
            {
                errorString = null;
            }

            return(stored);
        }