Exemplo n.º 1
0
        public RichiestaRISDTO ChangeHL7StatusAndMessageRichiestaRIS(string richidid, string hl7_stato, string hl7_msg = null)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            RichiestaRISDTO updated = new RichiestaRISDTO();

            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 PRES ..."));

            RichiestaRISDTO got = GetRichiestaRISById(richidid);

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

            int res = 0;

            if (updated != null)
            {
                res++;
            }
            else
            {
                log.Info(string.Format("An Error occurred. Record not updated! PRESIDID: {0}", got.presidid));
            }
            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);
        }
Exemplo n.º 2
0
        public string SendMirthRequest(string richidid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            // 0. Check if pres exists and radios do
            RichiestaRISDTO rich  = GetRichiestaRISById(richidid);
            List <EsameDTO> esams = GetEsamiByRichiesta(richidid);

            if ((rich == null || esams == null) || (esams != null && esams.Count == 0))
            {
                string msg = string.Format("An Error occured! No PRES or RADIO 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.SendRISRequest(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);
        }
Exemplo n.º 3
0
        public bool ValidatePres(RichiestaRISDTO pres, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            bool validate = true;

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

            if (pres.preseven == null)
            {
                string msg = "PRESEVEN is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "PRES error: " + msg;
                }
                else
                {
                    errorString += "PRES error: " + msg;
                }
            }
            if (pres.prestipo == null)
            {
                string msg = "PRESTIPO is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "PRES error: " + msg;
                }
                else
                {
                    errorString += "PRES error: " + msg;
                }
            }
            if (pres.prespren == null)
            {
                string msg = "PRESPREN is Null!";
                validate = false;
                if (errorString != "")
                {
                    errorString += "\r\n" + "PRES error: " + msg;
                }
                else
                {
                    errorString += "PRES error: " + msg;
                }
            }

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

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

            return(validate);
        }
Exemplo n.º 4
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 PRES ..."));

            RichiestaRISDTO got = GetRichiestaRISById(richidid);

            got.hl7_stato = hl7_stato;
            got.hl7_msg   = hl7_msg != null ? hl7_msg : got.hl7_msg;
            RichiestaRISDTO updt = UpdateRichiestaRIS(got);

            int esamres = 0;

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

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

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

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

            foreach (EsameDTO got_ in gots)
            {
                EsameDTO updt_ = UpdateEsame(got_);
                if (updt_ != null)
                {
                    analsres++;
                }
                else
                {
                    log.Info(string.Format("An Error occurred. Record not updated! RADIOIDID: {0}", got_.radioidid));
                }
            }
            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);
        }
Exemplo n.º 5
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 PRES and RADIO exist
                RichiestaRISDTO chkRich   = bll.GetRichiestaRISById(richid);
                List <EsameDTO> chkRadios = bll.GetEsamiByRichiesta(richid);
                if (chkRich == null || chkRadios == null || (chkRadios != null && chkRadios.Count == 0))
                {
                    string msg = "Error! No Pres or Radio records found referring to RichID " + richid + "! 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(richid, IBLL.HL7StatesRichiestaRIS.Deleting);

                // 4. 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, IBLL.HL7StatesRichiestaRIS.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.HL7StatesRichiestaRIS.Deleted;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaRIS.Errored;
                }
                RichiestaRISDTO RichUpdt = bll.ChangeHL7StatusAndMessageRichiestaRIS(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.RadioID;
                        List <EsameDTO> RadioUpdts = bll.ChangeHL7StatusAndMessageEsami(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}", GeneralPurposeLib.LibString.TimeSpanToTimeHmsms(tw.Elapsed)));

            return(data);
        }
Exemplo n.º 6
0
        public string ScheduleNewRequest(RichiestaRISDTO rich, List <EsameDTO> radios, ref string errorString)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            string hl7_stato = IBLL.HL7StatesRichiestaRIS.Idle;
            string res       = null;

            RichiestaRISDTO presInserted   = null;
            List <EsameDTO> radiosInserted = null;

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

            try
            {
                if (rich == null || radios == null || (radios != null && radios.Count == 0))
                {
                    throw new Exception("Error! Request a null or void insertion of PRES and/or RADIO");
                }

                // Validation Pres!!!!
                if (!bll.ValidatePres(rich, 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);
                }

                // Check if Even Exists
                string    evenid = rich.preseven.ToString();
                EventoDTO even   = bll.GetEventoById(evenid);
                if (even == null)
                {
                    string msg = "Error! Even with evenidid: " + evenid + " doesn't exist! the Scheduling of the request will be aborted!";
                    log.Info(msg);
                    log.Error(msg);
                    throw new Exception(msg);
                }
                even = null;

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

                res = presInserted.presidid.ToString();

                radios.ForEach(p => { p.radiopres = int.Parse(res); p.hl7_stato = hl7_stato; });

                // Validation Radios!!!!
                if (!bll.ValidateRadios(radios, 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);
                }

                log.Info(string.Format("Insertion of {0} RADIO requested. Processing ...", radios.Count));
                radiosInserted = bll.AddEsami(radios);
                if ((radiosInserted == null) || (radiosInserted != null && radiosInserted.Count != radios.Count))
                {
                    throw new Exception("Error during RADIOs writing into the DB");
                }
                log.Info(string.Format("Inserted {0} RADIO successfully!", radiosInserted.Count));
                log.Info(string.Format("Inserted {0} records successfully!", radiosInserted.Count + 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 esamRB  = 0;
                int analsRB = 0;

                log.Info(string.Format("Rolling Back of the Insertions due an error occured ..."));
                // Rolling Back
                if (res != null)
                {
                    esamRB = bll.DeleteRichiestaRISById(res);
                    log.Info(string.Format("Rolled Back {0} PRES record. PRESIDID was {1}!", esamRB, res));
                    analsRB = bll.DeleteEsamiByRichiesta(res);
                    log.Info(string.Format("Rolled Back {0} RADIO records. RADIOPRES was {1}!", analsRB, res));
                }
                log.Info(string.Format("Rolled Back {0} records of {1} requested!", esamRB + analsRB, radios.Count + 1));
                res = null;
            }

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

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

            return(res);
        }
Exemplo n.º 7
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
                RichiestaRISDTO chkRich   = bll.GetRichiestaRISById(richid);
                List <EsameDTO> chkRadios = bll.GetEsamiByRichiesta(richid);
                if (chkRich == null || chkRadios == null || (chkRadios != null && chkRadios.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. Settare Stato a "SEDNING"
                int res = bll.ChangeHL7StatusAndMessageAll(richid, IBLL.HL7StatesRichiestaRIS.Sending, "");

                // 3. 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, IBLL.HL7StatesRichiestaRIS.Errored, msg);
                    // 3.e2 Restituire null
                    return(null);
                }
                // 3.1 Settare a SETN
                int snt = bll.ChangeHL7StatusAndMessageAll(richid, IBLL.HL7StatesRichiestaRIS.Sent, "");

                // 4. 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!");
                }

                // 5. Settare Stato a seconda della risposta
                string status = IBLL.HL7StatesRichiestaRIS.Sent;
                if (data.ACKCode != "AA")
                {
                    status = IBLL.HL7StatesRichiestaRIS.Errored;
                }

                RichiestaRISDTO RichUpdt = bll.ChangeHL7StatusAndMessageRichiestaRIS(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.RadioID;
                        List <EsameDTO> AnalUpdts = bll.ChangeHL7StatusAndMessageEsami(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);
            }

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

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

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