예제 #1
0
        public string SendMirthRequest(string richidid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            string data = null;

            try
            {
                // 0. Check if rich exists and labels do
                RichiestaLISDTO rich = GetRichiestaLISByIdExt(richidid);
                if (rich == null)
                {
                    string msg = string.Format("An Error occured! No RICH idext {0} found into the DB. Operation Aborted!", richidid);
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                string id = rich.id.Value.ToString();
                log.Info("External Request ID " + richidid + " - Internal Request ID " + id);

                List <AnalisiDTO> anals = GetAnalisisByRichiestaExt(richidid);

                if (anals == null || (anals != null && anals.Count == 0))
                {
                    string msg = string.Format("An Error occured! No ANAL related to idExt {0} found into the DB. Operation Aborted!", richidid);
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                // 1. Call DAL.SendMirthREquest()
                data = this.dal.SendLISRequest(richidid);
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }
            finally
            {
                tw.Stop();
                log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));
            }

            return(data);
        }
예제 #2
0
        public RichiestaLISDTO RetrieveRich(string richid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            RichiestaLISDTO rich = null;

            rich = bll.GetRichiestaLISById(richid);

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

            return(rich);
        }
예제 #3
0
        public RichiestaLISDTO ChangeHL7StatusAndMessageRichiestaLIS(string richidid, string hl7_stato, string hl7_msg = null)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            RichiestaLISDTO updated = new RichiestaLISDTO();

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

            string msg_ = "Status updating with 'hl7_stato'-> " + hl7_stato;

            if (hl7_msg != null)
            {
                msg_ += " and 'hl7_msg'-> " + hl7_msg;
            }
            log.Info(string.Format(msg_));

            log.Info(string.Format("Updating ESAM ..."));

            RichiestaLISDTO got = GetRichiestaLISById(richidid);

            got.hl7_stato = hl7_stato;
            got.hl7_msg   = hl7_msg != null ? hl7_msg : got.hl7_msg;
            updated       = UpdateRichiestaLIS(got);

            int res = 0;

            if (updated != null)
            {
                res++;
            }
            else
            {
                log.Info(string.Format("An Error occurred. Record not updated! ESAMIDID: {0}", got.esamidid));
            }
            log.Info(string.Format("Updated {0}/{1} record!", res, 1));

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

            return(updated);
        }
예제 #4
0
        public string SendMirthRequest(string richidid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            // 0. Check if esam exists and labels do
            RichiestaLISDTO   esam  = GetRichiestaLISById(richidid);
            List <AnalisiDTO> anals = GetAnalisisByRichiesta(richidid);

            if ((esam == null || anals == null) || (anals != null && anals.Count == 0))
            {
                string msg = string.Format("An Error occured! No ESAM or ANAL related to id {0} found into the DB. Operation Aborted!", richidid);
                log.Info(msg);
                log.Error(msg);
                return(null);
            }

            string data = null;

            try
            {
                // 1. Call DAL.SendMirthREquest()
                data = this.dal.SendLISRequest(richidid);
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }
            finally
            {
                tw.Stop();
                log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));
            }

            return(data);
        }
예제 #5
0
파일: LIS.cs 프로젝트: GitMAGI/LISPluginGen
        public MirthResponseDTO NewRequest(RichiestaLISDTO rich, List <AnalisiDTO> anals, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = null;

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

            try
            {
                if (!bll.StoreNewRequest(rich, anals, ref errorString))
                {
                    throw new Exception(errorString);
                }
                data = bll.SubmitNewRequest(rich.richidid, ref errorString);
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

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

            return(data);
        }
예제 #6
0
파일: LIS.cs 프로젝트: GitMAGI/LISPluginGen
        public RichiestaLISDTO GetRichiestaByIdExt(string richid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            RichiestaLISDTO rich = null;

            rich = bll.GetRichiestaLISByIdExt(richid);
            if (rich == null)
            {
                string msg = string.Format("No Rich with ID: {0} found. The operation will be aborted!", richid);
                log.Info(msg);
            }

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

            return(rich);
        }
예제 #7
0
파일: LIS.cs 프로젝트: GitMAGI/LISPluginGen
        public List <RisultatoDTO> RetrieveResults(string richidext_, ref string errorString, bool?forceUpdating = null)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            List <RisultatoDTO> riss = null;

            try
            {
                RichiestaLISDTO rich = bll.GetRichiestaLISByIdExt(richidext_);
                if (rich == null)
                {
                    string msg = string.Format("No Rich with ID: {0} found. The operation will be aborted!", richidext_);
                    log.Info(msg);
                    throw new Exception(msg);
                }

                rich = null;

                log.Info("External Request ID " + richidext_);

                log.Info("Searching for Analysis' related to Request ID Ext " + richidext_ + " ...");
                List <AnalisiDTO> anals = bll.GetAnalisisByRichiestaExt(richidext_);
                log.Info(string.Format("Found {0} Analysis' related to Request ID Ext {1}.", anals != null ? anals.Count : 0, richidext_));
                foreach (AnalisiDTO anal in anals)
                {
                    log.Info("Searching for Results related to Analysis ID " + anal.analidid.Value.ToString() + " ...");
                    List <RisultatoDTO> anres = bll.GetRisultatiByAnalId(anal.analidid.Value.ToString());
                    if (anres != null && anres.Count > 0)
                    {
                        log.Info(string.Format("Found {0} Results related to Analysis ID {1}.", anres, anal.analidid.Value.ToString()));
                        //0. Check if updating is set to Forced!
                        if (forceUpdating != null)
                        {
                            //0.1 If it is Updating is true
                            if (forceUpdating.Value)
                            {
                                log.Info("Requested a forced updating of the Raw Results!");

                                //1. Get Updated Risultati
                                log.Info("Searching for Raw Results related to Request IDExt - Analysis ID " + richidext_ + "-" + anal.analidid.Value.ToString() + " ...");
                                List <RisultatoDTO> anresUpdt = bll.GetRisultatiByEsamAnalId(richidext_ + "-" + anal.analidid.Value.ToString());
                                log.Info(string.Format("Found {0} Raw Results related to Request IDExt - Analysis ID : {1}-{2}.", anresUpdt != null ? anresUpdt.Count : 0, richidext_, anal.analidid.Value.ToString()));
                                if (anresUpdt != null && anresUpdt.Count > 0)
                                {
                                    //2. Delete Old Risultati
                                    int removedRes = bll.DeleteRisultatiByIdAnalisi(anal.analidid.Value.ToString());
                                    log.Info(string.Format("Removed {0} Result items related to AnalId: {1}", removedRes, anal.analidid.Value.ToString()));
                                    //3. Write New Risultati
                                    List <RisultatoDTO> updts = bll.AddRisultati(anresUpdt);
                                    log.Info(string.Format("{0} Raw Results Converted and Written into DB. They are Related to Analysis ID {1}. ANRE ID are '{2}'.", updts != null ? updts.Count : 0, anal.analidid.Value.ToString(), updts != null ? string.Join(", ", updts.Select(p => p.anreidid).ToList().ToArray()) : ""));
                                }

                                log.Info("Forced updating of Results Completed!");
                            }
                        }

                        //1. Check if Analisi is "Executed"
                        //1.1 If not, Update Analisi to "Executed"
                        log.Info(string.Format("HL7 Status of Analysis with ID {0}, is '{1}'. HL7 Message is '{2}'.", anal.analidid.Value.ToString(), anal.hl7_stato, anal.hl7_msg));
                        if (anal.hl7_stato != IBLL.HL7StatesAnalisi.Executed)
                        {
                            List <AnalisiDTO> tmp = bll.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                            {
                                anal.analidid.Value.ToString()
                            }, IBLL.HL7StatesAnalisi.Executed, "Risultati Ottenuti");
                            log.Info(string.Format("HL7 Status of Analysis with ID {0}, has been updated to '{1}'.", anal.analidid.Value.ToString(), tmp != null ? tmp.First().hl7_stato : "--error occurred--"));
                        }
                        //2. Add to Collection
                        if (riss == null)
                        {
                            riss = new List <RisultatoDTO>();
                        }
                        riss.AddRange(anres);
                        log.Info(string.Format("{0} Results related to Analysis ID {1}, has been added to the Results Collection (actually {2} total items).", anres.Count, anal.analidid.Value.ToString(), riss.Count));
                    }
                    else
                    {
                        log.Info(string.Format("Found No Results related to Analysis ID {0}.", anal.analidid.Value.ToString()));
                        log.Info("Searching for Raw Results related to Request IDExt - Analysis ID " + richidext_ + "-" + anal.analidid.Value.ToString() + " ...");
                        List <RisultatoDTO> anresNew = bll.GetRisultatiByEsamAnalId(richidext_ + "-" + anal.analidid.Value.ToString());
                        log.Info(string.Format("Found {0} Raw Results related to Request IDExt - Analysis ID : {1}-{2}.", anresNew != null ? anresNew.Count : 0, richidext_, anal.analidid.Value.ToString()));
                        if (anresNew != null && anresNew.Count > 0)
                        {
                            //1. Add new Risultato as Executed
                            List <RisultatoDTO> news = bll.AddRisultati(anresNew);
                            log.Info(string.Format("{0} Raw Results Converted and Written into DB. They are Related to Analysis ID {1}. ANRE ID are '{2}'.", news != null ? news.Count : 0, anal.analidid.Value.ToString(), news != null ? string.Join(", ", news.Select(p => p.anreidid).ToList().ToArray()) : ""));
                            //2. Update Analisi to "Executed"
                            log.Info(string.Format("HL7 Status of Analysis with ID {0}, is '{1}'. HL7 Message is '{2}'.", anal.analidid.Value.ToString(), anal.hl7_stato, anal.hl7_msg));
                            List <AnalisiDTO> tmp = bll.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                            {
                                anal.analidid.Value.ToString()
                            }, IBLL.HL7StatesAnalisi.Executed, "Risultati Ottenuti");
                            log.Info(string.Format("HL7 Status of Analysis with ID {0}, has been updated to '{1}'.", anal.analidid.Value.ToString(), tmp != null ? tmp.First().hl7_stato : "--error occurred--"));
                            //3. Add to Collection
                            if (news != null && news.Count > 0)
                            {
                                if (riss == null)
                                {
                                    riss = new List <RisultatoDTO>();
                                }
                                riss.AddRange(news);
                                log.Info(string.Format("{0} Results related to Analysis ID {1}, has been added to the Results Collection (actually {2} total items).", news.Count, anal.analidid.Value.ToString(), riss.Count));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

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

            return(riss);
        }
예제 #8
0
파일: LIS.cs 프로젝트: GitMAGI/LISPluginGen
        public MirthResponseDTO CancelRequest(string richidExt_, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = null;

            try
            {
                // 1. Check if Canceling is allowed
                if (!bll.CheckIfCancelingIsAllowed(richidExt_, ref errorString))
                {
                    string msg = string.Format("Canceling of the request with id {0} is denied! errorString: {1}", richidExt_, errorString);
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }

                // 2. Check if ESAM and ANAL exist
                RichiestaLISDTO   chkEsam  = bll.GetRichiestaLISByIdExt(richidExt_);
                List <AnalisiDTO> chkAnals = bll.GetAnalisisByRichiestaExt(richidExt_);
                if (chkEsam == null || chkAnals == null || (chkAnals != null && chkAnals.Count == 0))
                {
                    string msg = "Error! No Esam or Anal records found referring to EsamID " + richidExt_ + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                // 3. Settare Stato a "DELETNG"
                int res = bll.ChangeHL7StatusAndMessageAll(richidExt_, IBLL.HL7StatesRichiestaLIS.Deleting);

                // 4. Invio a Mirth
                string hl7orl = bll.SendMirthRequest(richidExt_);
                if (hl7orl == null)
                {
                    string msg = "Mirth Returned an Error!";
                    errorString = msg;
                    // 4.e1 Cambiare stato in errato
                    int err = bll.ChangeHL7StatusAndMessageAll(richidExt_, IBLL.HL7StatesRichiestaLIS.Errored, msg);
                    // 4.e2 Restituire null
                    return(null);
                }

                // 5. Estrarre i dati dalla risposta di Mirth
                data = bll.ORLParser(hl7orl);

                // 6. Settare Stato a seconda della risposta
                string status = IBLL.HL7StatesRichiestaLIS.Deleted;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaLIS.Errored;
                }
                string          richDesc = data.ERRMsg != null ? data.ERRMsg : data.ACKDesc;
                RichiestaLISDTO RichUpdt = bll.ChangeHL7StatusAndMessageRichiestaLIS(richidExt_, status, richDesc);

                List <ORCStatus> orcs = data.ORCStatus;
                if (orcs != null)
                {
                    foreach (ORCStatus orc in orcs)
                    {
                        string            desc      = orc.Description;
                        string            stat      = orc.Status;
                        string            analid    = orc.AnalID;
                        List <AnalisiDTO> AnalUpdts = bll.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                        {
                            analid
                        }, stat, desc);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

            return(data);
        }
예제 #9
0
        public bool CheckIfCancelingIsAllowed(string richid, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            bool res = true;

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

            RichiestaLISDTO rich = this.GetRichiestaLISByIdExt(richid);

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

                string msg = string.Format("Error! No Rich found with IDExt: {0}", richid);

                log.Info(string.Format(msg));
                log.Error(string.Format(msg));

                if (errorString != "")
                {
                    errorString += "\r\n" + msg;
                }
                else
                {
                    errorString += msg;
                }

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

                return(false);
            }

            string id = rich.id.Value.ToString();

            log.Info("External Request ID " + richid + " - Internal Request ID " + id);

            RefertoDTO refe = this.GetRefertoByIdRichiestaExt(richid);

            if (refe == null)
            {
                List <AnalisiDTO> anals = this.GetAnalisisByRichiestaExt(richid);
                foreach (AnalisiDTO anal in anals)
                {
                    List <RisultatoDTO> riss = this.GetRisultatiByAnalId(anal.analidid.Value.ToString());
                    if (riss != null)
                    {
                        string report = string.Format("Analisi {0} già eseguita! Impossibile Cancellare!", anal.analidid.Value.ToString());
                        res = false;
                        if (errorString != "")
                        {
                            errorString += "\r\n" + report;
                        }
                        else
                        {
                            errorString += report;
                        }
                    }
                }
            }
            else
            {
                string report = string.Format("Rich {0} (IDExt: {1}) già refertato! Id referto {2}!", id, richid, refe.refeidid);
                res = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + report;
                }
                else
                {
                    errorString += report;
                }
            }

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

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

            return(res);
        }
예제 #10
0
        public string ScheduleNewRequest(EventoDTO even, PrestazioneDTO pres, RichiestaLISDTO esam, List <AnalisiDTO> anals, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            string hl7_stato = IBLL.HL7StatesRichiestaLIS.Idle;
            string evenIdStr = null;
            string esamIdStr = null;
            string presIdStr = null;

            EventoDTO         evenInserted  = null;
            PrestazioneDTO    presInserted  = null;
            RichiestaLISDTO   esamInserted  = null;
            List <AnalisiDTO> analsInserted = null;

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

            try
            {
                if (even == null || esam == null || anals == null || (anals != null && anals.Count == 0))
                {
                    throw new Exception("Error! Request a null or void insertion of EVEN and/or ESAM and/or ANAL.");
                }

                // Validation Even!!!!
                if (!bll.ValidateEven(even, ref errorString))
                {
                    string msg = "Validation Even 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);
                }

                // Check if Epis exists!!!!
                log.Info(string.Format("Checking EPIS '{0}' exists ...", even.evenepis));
                EpisodioDTO epis = bll.GetEpisodioById(even.evenepis.ToString());
                if (epis == null)
                {
                    string msg = string.Format("EPIS Checking Failure! EPIS '{0}' not Found!", even.evenepis);
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }
                epis = null;
                log.Info(string.Format("Checking EPIS '{0}' succeded!", even.evenepis));

                // Create Even
                log.Info(string.Format("EVEN Insertion ..."));
                even.evenidid = null;
                evenInserted  = bll.AddEvento(even);
                if (evenInserted == null)
                {
                    throw new Exception("Error during EVEN writing into the DB.");
                }
                log.Info(string.Format("EVEN Inserted. Got {0} EVENIDID!", evenInserted.evenidid));

                evenIdStr = evenInserted.evenidid.ToString();

                pres.preseven = evenInserted.evenidid;
                log.Info(string.Format("PRES foreign key PRESEVEN updated!"));
                // Validation Pres!!!!
                if (!bll.ValidatePres(pres, ref errorString))
                {
                    string msg = "Validation Pres 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);
                }

                pres.hl7_stato = hl7_stato;

                // Create Pres
                log.Info(string.Format("PRES Insertion ..."));
                presInserted = bll.AddPrestazione(pres);
                if (presInserted == null)
                {
                    throw new Exception("Error during PRES writing into the DB.");
                }
                log.Info(string.Format("PRES Inserted. Got {0} PRESIDID!", presInserted.presidid));

                presIdStr = presInserted.presidid.ToString();

                esam.esameven = evenInserted.evenidid;
                // Validation Esam!!!!
                if (!bll.ValidateEsam(esam, ref errorString))
                {
                    string msg = "Validation Esam 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("ESAM foreign key ESAMEVEN updated!"));
                esam.hl7_stato = hl7_stato;

                // Create Esam
                log.Info(string.Format("ESAM Insertion ..."));
                esamInserted = bll.AddRichiestaLIS(esam);
                if (esamInserted == null)
                {
                    throw new Exception("Error during ESAM writing into the DB.");
                }
                log.Info(string.Format("ESAM Inserted. Got {0} ESAMIDID!", esamInserted.esamidid));

                esamIdStr = esamInserted.esamidid.ToString();

                anals.ForEach(p => { p.analesam = int.Parse(esamIdStr); p.hl7_stato = hl7_stato; });

                // Validation Anals!!!!
                if (!bll.ValidateAnals(anals, ref errorString))
                {
                    string msg = "Validation 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);
                }

                // Create Anals
                log.Info(string.Format("Insertion of {0} ANAL requested. Processing ...", anals.Count));
                analsInserted = bll.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 Total Number Of Records Inserted! 1 for Esam, 1 for PRES and n for ANAL(s)
                log.Info(string.Format("Inserted {0} records successfully!", analsInserted.Count + 1 + 1));
            }
            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 evenRB  = 0;
                int presRB  = 0;
                int esamRB  = 0;
                int analsRB = 0;

                log.Info(string.Format("Rolling Back of the Insertions due an error occured ..."));
                // Rolling Back
                if (evenIdStr != null)
                {
                    evenRB = bll.DeleteEventoById(evenIdStr);
                    log.Info(string.Format("Rolled Back {0} EVEN record. EVENIDID was {1}!", evenRB, evenIdStr));
                }
                if (presIdStr != null)
                {
                    presRB = bll.DeletePrestazioneById(presIdStr);
                    log.Info(string.Format("Rolled Back {0} PRES record. PRESIDID was {1}!", presRB, presIdStr));
                }
                if (esamIdStr != null)
                {
                    esamRB = bll.DeleteRichiestaLISById(esamIdStr);
                    log.Info(string.Format("Rolled Back {0} ESAM record. ESAMIDID was {1}!", esamRB, esamIdStr));
                    analsRB = bll.DeleteAnalisiByRichiesta(esamIdStr);
                    log.Info(string.Format("Rolled Back {0} ANAL records. ANALESAM was {1}!", analsRB, esamIdStr));
                }

                log.Info(string.Format("Rolled Back {0} records of {1} requested!", evenRB + presRB + esamRB + analsRB, anals.Count + 1 + 1 + 1));
                esamIdStr = null;
            }

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

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

            return(esamIdStr);
        }
예제 #11
0
        public bool ValidateRich(RichiestaLISDTO rich, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            bool validate = true;

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

            if (rich.episodioid == null)
            {
                string msg = "EPISODIOID is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            if (rich.pazicogn == null || rich.pazicogn == "")
            {
                string msg = "PAZICOGN is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            if (rich.pazinome == null || rich.pazinome == "")
            {
                string msg = "PAZINOME is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            if (rich.pazidata == null)
            {
                string msg = "PAZIDATA is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            if (rich.pazicofi == null || rich.pazicofi == "")
            {
                string msg = "PAZICOFI is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            else
            {
                if (rich.pazicofi.Length != 16)
                {
                    string msg = string.Format("PAZICOFI length is Invalid!");
                    validate = false;
                    if (errorString != "")
                    {
                        errorString += "\r\n" + "RichiestaLIS error: " + msg;
                    }
                    else
                    {
                        errorString += "RichiestaLIS error: " + msg;
                    }
                }
            }
            if (rich.pazisess == null || rich.pazisess == "")
            {
                string msg = "PAZISESS is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "RichiestaLIS error: " + msg;
                }
                else
                {
                    errorString += "RichiestaLIS error: " + msg;
                }
            }
            else
            {
                if (rich.pazisess.ToUpper() != "M" && rich.pazisess.ToUpper() != "F")
                {
                    string msg = string.Format("PAZISESS '{0}' is Invalid!", rich.pazisess);
                    validate = false;
                    if (errorString != "")
                    {
                        errorString += "\r\n" + "RichiestaLIS error: " + msg;
                    }
                    else
                    {
                        errorString += "RichiestaLIS error: " + msg;
                    }
                }
            }

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

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

            return(validate);
        }
예제 #12
0
        public int ChangeHL7StatusAndMessageAll(string richidid, string hl7_stato, string hl7_msg = null)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            int res = 0;

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

            string msg_ = "Status updating with 'hl7_stato' -> " + hl7_stato;

            if (hl7_msg != null)
            {
                msg_ += " and 'hl7_msg' -> " + hl7_msg;
            }
            log.Info(string.Format(msg_));
            log.Info(string.Format("Updating RICH ..."));

            RichiestaLISDTO got = GetRichiestaLISByIdExt(richidid);

            if (got == null)
            {
                log.Info(string.Format("An Error occurred. Rich bot found! IDExt: {0}", richidid));
                tw.Stop();
                log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));
                return(0);
            }

            string id = got.id.Value.ToString();

            got.hl7_stato = hl7_stato;
            got.hl7_msg   = hl7_msg != null ? hl7_msg : got.hl7_msg;
            RichiestaLISDTO updt = UpdateRichiestaLIS(got);

            int richres = 0;

            if (updt != null)
            {
                richres++;
            }
            else
            {
                log.Info(string.Format("An Error occurred. Record not updated! ID: {0}", got.id));
            }
            res = richres;

            log.Info(string.Format("Updated {0}/{1} record!", richres, 1));

            log.Info(string.Format("Updating ANAL ..."));
            List <AnalisiDTO> gots = GetAnalisisByRichiestaExt(richidid);

            gots.ForEach(p => { p.hl7_stato = hl7_stato; p.hl7_msg = hl7_msg != null ? hl7_msg : p.hl7_msg; });
            int analsres = 0;

            foreach (AnalisiDTO got_ in gots)
            {
                AnalisiDTO updt_ = UpdateAnalisi(got_);
                if (updt_ != null)
                {
                    analsres++;
                }
                else
                {
                    log.Info(string.Format("An Error occurred. Record not updated! ANALIDID: {0}", got_.analidid));
                }
            }
            res += analsres;
            log.Info(string.Format("Updated {0}/{1} record!", analsres, gots.Count));

            log.Info(string.Format("Updated {0} record overall!", res));

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

            return(res);
        }
예제 #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting .... ");

            LIS lis = new LIS();

            RichiestaLISDTO rich = new RichiestaLISDTO();

            rich.episodioid = 100202;

            rich.paziid      = "8475512";
            rich.paziidunico = 0;

            rich.pazicofi = "TSSTTS83C15R345J";
            rich.pazicogn = "TestCognome";
            rich.pazinome = "TestNome";
            rich.pazidata = Convert.ToDateTime("1983-03-15");
            rich.pazisess = "M";

            rich.richidid = "e9re0vkv904gm9bm";

            rich.accedatetime = Convert.ToDateTime("2017-01-09 11:25:00.000");
            rich.evendata     = DateTime.Now;
            rich.prendata     = Convert.ToDateTime("2017-02-01 12:05:00.000");
            rich.quesmed      = "Interrogarsi per vivere";
            rich.repaid       = "43";
            rich.repanome     = "Medicina Generale";

            rich.tiporicovero = "Incognito";
            rich.urgente      = 1;

            rich.medicofi = "TSTSTS56E12L498F";
            rich.medicogn = "PersTestCognomne";
            rich.mediid   = "4552";
            rich.medinome = "PersTestNome";

            rich.paziteam = "10121200054548465";
            rich.pazitele = null;

            rich.paziAsl_cod  = null;
            rich.paziAsl_txt  = null;
            rich.paziCoDo_cap = null;
            rich.paziCoDo_cod = null;
            rich.paziCoDo_txt = null;
            rich.paziCoDo_via = null;
            rich.paziCoNa_cap = null;
            rich.paziCoNa_cod = null;
            rich.paziCoNa_txt = null;
            rich.paziCoRe_cap = null;
            rich.paziCoRe_cod = null;
            rich.paziCoRe_txt = null;
            rich.paziCoRe_via = null;
            rich.paziCoRf_cap = null;
            rich.paziCoRf_cod = null;
            rich.paziCoRf_txt = null;
            rich.paziCoRf_via = null;
            rich.paziNaDo_cod = null;
            rich.paziNaDo_txt = null;
            rich.paziNaNa_cod = null;
            rich.paziNaNa_txt = null;
            rich.paziNaRe_cod = null;
            rich.paziNaRe_txt = null;
            rich.paziNaRf_cod = null;
            rich.paziNaRf_txt = null;
            rich.paziPrDo_cod = null;
            rich.paziPrDo_txt = null;
            rich.paziPrNa_cod = null;
            rich.paziPrNa_txt = null;
            rich.paziPrRe_cod = null;
            rich.paziPrRe_txt = null;
            rich.paziPrRf_cod = null;
            rich.paziPrRf_txt = null;

            List <AnalisiDTO> anals = new List <AnalisiDTO>()
            {
                new AnalisiDTO()
                {
                    analrich = rich.richidid,
                    analcodi = "EMO",
                    analnome = "Emocromo",
                    analinvi = 0,
                    analflro = 0,
                },
                new AnalisiDTO()
                {
                    analrich = rich.richidid,
                    analcodi = "BIL",
                    analnome = "Bilirubina a Pompa",
                    analinvi = 0,
                    analflro = 0,
                }
            };

            string err = null;

            //MirthResponseDTO respAdd = lis.NewRequest(rich, anals, ref err);

            List <RisultatoDTO> res = lis.RetrieveResults(rich.richidid, ref err, true);

            //bool chk = lis.CheckIfCancelingIsAllowed(rich.richidid, ref err);

            //MirthResponseDTO respCanceling = lis.CancelRequest(rich.richidid, ref err);

            Console.WriteLine("Press a Key to Complete!");
            Console.ReadKey();
            Console.WriteLine("Completed!");
        }
예제 #14
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            EventoDTO even = new EventoDTO()
            {
                evenepis = 112986,
                evenreri = 17,
                eventipo = 1,
                evenperi = 306,
                evenrees = 22,
                evendata = Convert.ToDateTime("2017-01-01T00:10:34"),
                evenrepp = 0,
                evendaef = Convert.ToDateTime("2017-01-01T02:45:01"),
            };

            PrestazioneDTO pres = new PrestazioneDTO()
            {
                presstat = 0,
                prestipo = 217,
                presurge = true,
                prespren = Convert.ToDateTime("2017-01-06T18:00:00"),
                presrico = 6,
                presflcc = 0,
                prespers = "MARTELLA LUCIANO",
                preserog = 0,
                presannu = 0,
            };

            RichiestaLISDTO esam = new RichiestaLISDTO()
            {
                esamtipo = 0,
                esampren = DateTime.Now,
            };

            List <AnalisiDTO> anals = new List <AnalisiDTO>()
            {
                new AnalisiDTO()
                {
                    analcodi = "EMO",
                    analnome = "EMOCROMO",
                    analflro = 0,
                    analinvi = 0,
                    analextb = "235",
                },
                new AnalisiDTO()
                {
                    analcodi = "AMI",
                    analnome = "AMILASI",
                    analflro = 0,
                    analinvi = 0,
                    analextb = "273",
                },
                new AnalisiDTO()
                {
                    analcodi = "BIF",
                    analnome = "BILIRUBINA DIRETTA",
                    analflro = 0,
                    analinvi = 0,
                    analextb = "281",
                },
            };

            string errs = null;

            LISPlugin.LIS lis = new LISPlugin.LIS();

            string richid = lis.ScheduleNewRequest(even, pres, esam, anals, ref errs);
            //string richid = "8682285";

            MirthResponseDTO resp = lis.SubmitNewRequest(richid, ref errs);

            //PrestazioneDTO pres_ = lis.RetrievePresByEven("2182273");

            //PazienteDTO pazi = lis.RetrievePazi("571010");

            List <RisultatoDTO> riss = lis.RetrieveResults(richid, ref errs, true);

            /*
             * string evenid = "2182265";
             * string richid = "8682284";
             * string analid1 = "4645449";
             * string analid2 = "4645450";
             * string analid3 = "4645451";
             */

            //List<RichiestaLISDTO> richs = lis.Check4Exams(evenid);
            //List<AnalisiDTO> anals_ = lis.Check4Analysis(richid);

            //MirthResponseDTO resp = lis.SubmitNewRequest(richid, ref errs);
            //List<LabelDTO> labes = lis.Check4Labels(richid);

            //List<RisultatoDTO> riss = lis.RetrieveResults(richid, ref errs);

            //List<RisultatoDTO> riss = lis.Check4Results(analid1);

            //bool cnl = lis.CheckIfCancelingIsAllowed(richid, ref errs);

            /*
             * List<int> red = null;
             *
             * int r = 0;
             * if (red != null && red.Count > 0)
             *  r = 1;
             */

            //RefertoDTO refe = lis.Check4Report(richid);

            sw.Stop();

            Console.WriteLine("ElapsedTime {0}\n\n", sw.Elapsed);

            Console.WriteLine("Press a key to Close!");
            Console.ReadKey();
        }
예제 #15
0
        public MirthResponseDTO CancelRequest(string richid, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = null;

            try
            {
                // 0. Check if richid is a numeric Value
                int richid_int = 0;
                if (!int.TryParse(richid, out richid_int))
                {
                    string msg = string.Format("ID of the riquest is not an integer string. {0} is not a valid ID for this context!", richid);
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }

                // 1. Check if Canceling is allowed
                if (CheckIfCancelingIsAllowed(richid, ref errorString))
                {
                    string msg = string.Format("Canceling of the request with id {0} is denied! errorString: {1}", richid, errorString);
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }

                // 2. Check if ESAM and ANAL exist
                RichiestaLISDTO   chkEsam  = bll.GetRichiestaLISById(richid);
                List <AnalisiDTO> chkAnals = bll.GetAnalisisByRichiesta(richid);
                if (chkEsam == null || chkAnals == null || (chkAnals != null && chkAnals.Count == 0))
                {
                    string msg = "Error! No Esam or Anal records found referring to EsamID " + richid + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                // 3. Check if PRES exists
                if (!chkEsam.esameven.HasValue)
                {
                    string msg = "Error! Found an EsamEven NULL referring to EsamID " + richid + "!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }
                PrestazioneDTO chkPres = bll.GetPrestazioneByEvento(chkEsam.esameven.Value.ToString());
                if (chkPres == null)
                {
                    string msg = "Error! No Pres record found referring to EvenID " + chkEsam.esameven.Value.ToString() + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }
                string presidid = chkPres.presidid.Value.ToString();

                // 4. Settare Stato a "DELETNG"
                int res = bll.ChangeHL7StatusAndMessageAll(richid, presidid, IBLL.HL7StatesRichiestaLIS.Deleting);

                // 5. Invio a Mirth
                string hl7orl = bll.SendMirthRequest(richid);
                if (hl7orl == null)
                {
                    string msg = "Mirth Returned an Error!";
                    errorString = msg;
                    // 4.e1 Cambiare stato in errato
                    int err = bll.ChangeHL7StatusAndMessageAll(richid, presidid, IBLL.HL7StatesRichiestaLIS.Errored, msg);
                    // 4.e2 Restituire null
                    return(null);
                }

                // 6. Estrarre i dati dalla risposta di Mirth
                data = bll.ORLParser(hl7orl);

                // 7. Settare Stato a seconda della risposta
                string status = IBLL.HL7StatesRichiestaLIS.Deleted;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaLIS.Errored;
                }
                RichiestaLISDTO RichUpdt = bll.ChangeHL7StatusAndMessageRichiestaLIS(richid, status, data.ACKDesc);
                PrestazioneDTO  PresUpdt = bll.ChangeHL7StatusAndMessagePrestazione(presidid, status, data.ACKDesc);

                List <ORCStatus> orcs = data.ORCStatus;
                if (orcs != null)
                {
                    foreach (ORCStatus orc in orcs)
                    {
                        string            desc      = orc.Description;
                        string            stat      = orc.Status;
                        string            analid    = orc.AnalID;
                        List <AnalisiDTO> AnalUpdts = bll.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                        {
                            analid
                        }, stat, desc);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

            return(data);
        }
예제 #16
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);
        }
예제 #17
0
        public int ChangeHL7StatusAndMessageAll(string richidid, string presidid, string hl7_stato, string hl7_msg = null)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            int res = 0;

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

            string msg_ = "Status updating with 'hl7_stato'-> " + hl7_stato;

            if (hl7_msg != null)
            {
                msg_ += " and 'hl7_msg'-> " + hl7_msg;
            }
            log.Info(string.Format(msg_));
            log.Info(string.Format("Updating ESAM ..."));

            RichiestaLISDTO got = GetRichiestaLISById(richidid);

            got.hl7_stato = hl7_stato;
            got.hl7_msg   = hl7_msg != null ? hl7_msg : got.hl7_msg;
            RichiestaLISDTO updt = UpdateRichiestaLIS(got);

            int esamres = 0;

            if (updt != null)
            {
                esamres++;
            }
            else
            {
                log.Info(string.Format("An Error occurred. Record not updated! ESAMIDID: {0}", got.esamidid));
            }
            res += esamres;

            log.Info(string.Format("Updated {0}/{1} record!", esamres, 1));

            log.Info(string.Format("Updating PRES ..."));

            PrestazioneDTO got2 = GetPrestazioneById(presidid);

            got2.hl7_stato = hl7_stato;
            got2.hl7_msg   = hl7_msg != null ? hl7_msg : got2.hl7_msg;
            PrestazioneDTO updt1 = UpdatePrestazione(got2);

            int presres = 0;

            if (updt1 != null)
            {
                presres++;
            }
            else
            {
                log.Info(string.Format("An Error occurred. Record not updated! PRESIDID: {0}", got2.presidid));
            }
            res += presres;

            log.Info(string.Format("Updated {0}/{1} record!", presres, 1));

            log.Info(string.Format("Updating ANAL ..."));
            List <AnalisiDTO> gots = GetAnalisisByRichiesta(richidid);

            gots.ForEach(p => { p.hl7_stato = hl7_stato; p.hl7_msg = hl7_msg != null ? hl7_msg : p.hl7_msg; });
            int analsres = 0;

            foreach (AnalisiDTO got_ in gots)
            {
                AnalisiDTO updt_ = UpdateAnalisi(got_);
                if (updt_ != null)
                {
                    analsres++;
                }
                else
                {
                    log.Info(string.Format("An Error occurred. Record not updated! ANALIDID: {0}", got_.analidid));
                }
            }
            res += analsres;
            log.Info(string.Format("Updated {0}/{1} record!", analsres, gots.Count));

            log.Info(string.Format("Updated {0} record overall!", res));

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

            return(res);
        }
예제 #18
0
        public MirthResponseDTO SubmitNewRequest(string richid, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = null;

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

            try
            {
                // 1. Check if Rich and ANAL exist
                RichiestaLISDTO chkRich = this.GetRichiestaLISByIdExt(richid);
                if (chkRich == null)
                {
                    string msg = "Error! No Rich record found referring to IDExt " + richid + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                /*
                 * string id = chkRich.id.Value.ToString();
                 * log.Info("External Request ID " + richid + " - Internal Request ID " + id);
                 * int id_int = 0;
                 * if (!int.TryParse(id, out id_int))
                 * {
                 *  string msg = string.Format("ID of the riquest is not an integer string. {0} is not a valid ID for this context!", id);
                 *  errorString = msg;
                 *  log.Info(msg);
                 *  log.Error(msg);
                 *  throw new Exception(msg);
                 * }
                 */

                List <AnalisiDTO> chkAnals = this.GetAnalisisByRichiestaExt(richid);
                if (chkAnals == null || (chkAnals != null && chkAnals.Count == 0))
                {
                    string msg = "Error! No Anal records found referring to AnalRich " + richid + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                // 2. Settare Stato a "SEDNING"
                int res = this.ChangeHL7StatusAndMessageAll(richid, IBLL.HL7StatesRichiestaLIS.Sending, "");

                // 3. Invio a Mirth
                string hl7orl = this.SendMirthRequest(richid);
                if (hl7orl == null)
                {
                    string msg = "Mirth Returned an Error!";
                    errorString = msg;
                    // 3.e1 Cambiare stato in errato
                    int err = this.ChangeHL7StatusAndMessageAll(richid, IBLL.HL7StatesRichiestaLIS.Errored, msg);
                    // 3.e2 Restituire null
                    return(null);
                }
                // 3.1 Settare a SENT
                int snt = this.ChangeHL7StatusAndMessageAll(richid, IBLL.HL7StatesRichiestaLIS.Sent, "");

                // 4. Estrarre i dati dalla risposta di Mirth
                log.Info("Mirth Data Response Extraction ...");
                data = this.ORLParser(hl7orl);
                if (data == null)
                {
                    string emsg = "Mirth Data Response Extraction failed!";
                    if (errorString == "")
                    {
                        errorString = emsg;
                    }
                    else
                    {
                        errorString += "\n\r" + emsg;
                    }
                    log.Info(emsg);
                    log.Error(emsg);
                }
                else
                {
                    log.Info("Mirth Data Response Successfully extracted!");
                }

                // 5. Settare Stato a seconda della risposta
                string status = IBLL.HL7StatesRichiestaLIS.Sent;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaLIS.Errored;
                }
                else
                {
                    if (data.Labes != null)
                    {
                        status = IBLL.HL7StatesRichiestaLIS.Labelled;
                    }
                    else
                    {
                        string msg = "An Error Occurred! No Lables Retrieved By the Remote LAB!";
                        errorString = msg;
                        log.Info(msg);
                        log.Error(msg);
                        return(null);
                    }
                }
                RichiestaLISDTO RichUpdt = this.ChangeHL7StatusAndMessageRichiestaLIS(richid, status, data.ACKDesc);

                List <ORCStatus> orcs = data.ORCStatus;
                if (orcs != null)
                {
                    foreach (ORCStatus orc in orcs)
                    {
                        string            desc      = orc.Description;
                        string            stat      = orc.Status;
                        string            analid    = orc.AnalID;
                        List <AnalisiDTO> AnalUpdts = this.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                        {
                            analid
                        }, stat, desc);
                    }
                }

                // 6. Scrivere Labels nel DB
                if (data.Labes != null)
                {
                    data.Labes.ForEach(p => { p.laberich = richid; });
                    List <LabelDTO> stored = this.StoreLabels(data.Labes);
                    if (stored == null)
                    {
                        string msg = "An Error Occurred! Labels successfully retrieved by the remote LAB, but they haven't been stored into the local DB! The Rich ID is " + richid;
                        errorString = msg;
                        log.Info(msg);
                        log.Error(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

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

            // 7. Restituire il DTO
            return(data);
        }
예제 #19
0
        public bool ValidateEsam(RichiestaLISDTO esam, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            bool validate = true;

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

            /*
             * string richid = esam.esamidid.ToString();
             * if (esam.esamidid == null)
             * {
             *  string msg = "ESAMIDID is Null!";
             *  validate = false;
             *  if(errorString != "")
             *      errorString += "\r\n" + "ESAMIDID " + richid + ": " + msg;
             *  else
             *      errorString += "ESAMIDID " + richid + ": " + msg;
             * }*/
            if (esam.esameven == null)
            {
                string msg = "ESAMEVEN is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "ESAM error: " + msg;
                }
                else
                {
                    errorString += "ESAM error: " + msg;
                }
            }
            if (esam.esamtipo == null)
            {
                string msg = "ESAMTIPO is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "ESAM error: " + msg;
                }
                else
                {
                    errorString += "ESAM error: " + msg;
                }
            }
            if (esam.esampren == null)
            {
                string msg = "ESAMPREN is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "ESAM error: " + msg;
                }
                else
                {
                    errorString += "ESAM error: " + msg;
                }
            }

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

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

            return(validate);
        }
예제 #20
0
        public MirthResponseDTO SubmitNewRequest(string richid, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = null;

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

            try
            {
                // 0. Check if richid is a numeric Value
                int richid_int = 0;
                if (!int.TryParse(richid, out richid_int))
                {
                    string msg = string.Format("ID of the riquest is not an integer string. {0} is not a valid ID for this context!", richid);
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }

                // 1. Check if ESAM and ANAL exist
                RichiestaLISDTO   chkEsam  = bll.GetRichiestaLISById(richid);
                List <AnalisiDTO> chkAnals = bll.GetAnalisisByRichiesta(richid);
                if (chkEsam == null || chkAnals == null || (chkAnals != null && chkAnals.Count == 0))
                {
                    string msg = "Error! No Esam or Anal records found referring to EsamID " + richid + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }

                // 2. Check if PRES exists
                if (!chkEsam.esameven.HasValue)
                {
                    string msg = "Error! Found an EsamEven NULL referring to EsamID " + richid + "!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }
                PrestazioneDTO chkPres = bll.GetPrestazioneByEvento(chkEsam.esameven.Value.ToString());
                if (chkPres == null)
                {
                    string msg = "Error! No Pres record found referring to EvenID " + chkEsam.esameven.Value.ToString() + "! A request must be Scheduled first!";
                    errorString = msg;
                    log.Info(msg);
                    log.Error(msg);
                    return(null);
                }
                string presidid = chkPres.presidid.Value.ToString();

                // 3. Settare Stato a "SEDNING"
                int res = bll.ChangeHL7StatusAndMessageAll(richid, presidid, IBLL.HL7StatesRichiestaLIS.Sending, "");

                // 4. Invio a Mirth
                string hl7orl = bll.SendMirthRequest(richid);
                if (hl7orl == null)
                {
                    string msg = "Mirth Returned an Error!";
                    errorString = msg;
                    // 3.e1 Cambiare stato in errato
                    int err = bll.ChangeHL7StatusAndMessageAll(richid, presidid, IBLL.HL7StatesRichiestaLIS.Errored, msg);
                    // 3.e2 Restituire null
                    return(null);
                }
                // 4.1 Settare a SENT
                int snt = bll.ChangeHL7StatusAndMessageAll(richid, presidid, IBLL.HL7StatesRichiestaLIS.Sent, "");

                // 5. Estrarre i dati dalla risposta di Mirth
                log.Info("Mirth Data Response Extraction ...");
                data = bll.ORLParser(hl7orl);
                if (data == null)
                {
                    string emsg = "Mirth Data Response Extraction failed!";
                    if (errorString == "")
                    {
                        errorString = emsg;
                    }
                    else
                    {
                        errorString += "\n\r" + emsg;
                    }
                    log.Info(emsg);
                    log.Error(emsg);
                }
                else
                {
                    log.Info("Mirth Data Response Successfully extracted!");
                }

                // 6. Settare Stato a seconda della risposta
                string status = IBLL.HL7StatesRichiestaLIS.Sent;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaLIS.Errored;
                }
                else
                {
                    if (data.Labes != null)
                    {
                        status = IBLL.HL7StatesRichiestaLIS.Labelled;
                    }
                    else
                    {
                        string msg = "An Error Occurred! No Lables Retrieved By the Remote LAB!";
                        errorString = msg;
                        log.Info(msg);
                        log.Error(msg);
                        return(null);
                    }
                }
                RichiestaLISDTO RichUpdt = bll.ChangeHL7StatusAndMessageRichiestaLIS(richid, status, data.ACKDesc);
                PrestazioneDTO  PresUpdt = bll.ChangeHL7StatusAndMessagePrestazione(presidid, status, data.ACKDesc);

                List <ORCStatus> orcs = data.ORCStatus;
                if (orcs != null)
                {
                    foreach (ORCStatus orc in orcs)
                    {
                        string            desc      = orc.Description;
                        string            stat      = orc.Status;
                        string            analid    = orc.AnalID;
                        List <AnalisiDTO> AnalUpdts = bll.ChangeHL7StatusAndMessageAnalisis(new List <string>()
                        {
                            analid
                        }, stat, desc);
                    }
                }

                // 7. Scrivere Labels nel DB
                if (data.Labes != null)
                {
                    data.Labes.ForEach(p => p.labeesam = richid_int);
                    List <LabelDTO> stored = bll.StoreLabels(data.Labes);
                    if (stored == null)
                    {
                        string msg = "An Error Occurred! Labels successfully retrieved by the remote LAB, but they haven't been sotred into the local DB! The EsamIDID is " + richid;
                        errorString = msg;
                        log.Info(msg);
                        log.Error(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

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

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

            // 8. Restituire il DTO
            return(data);
        }