Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public MirthResponseDTO ORLParser(string raw)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

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

            MirthResponseDTO data = new MirthResponseDTO();

            log.Info(string.Format("HL7 Message To Process:\n{0}", raw));

            log.Info(string.Format("HL7 Message Processing ... "));

            try
            {
                log.Info(string.Format("MSA Recovering ..."));
                // 1. Get MSA Segment
                string   msa    = LibString.GetAllValuesSegments(raw, "MSA")[0];
                string[] msaobj = msa.Split('|');
                data.ACKCode = msaobj[1];
                data.MsgID   = msaobj[2];
                data.ACKDesc = msaobj.Length > 3 ? msaobj[2] : null;
                switch (data.ACKCode)
                {
                case "AA":
                    data.Errored  = false;
                    data.Accepted = true;
                    data.Refused  = false;
                    break;

                case "AE":
                    data.Errored  = true;
                    data.Accepted = false;
                    data.Refused  = false;
                    break;

                case "AR":
                    data.Errored  = false;
                    data.Accepted = false;
                    data.Refused  = true;
                    break;
                }
                log.Info(string.Format("MSA Recovered"));

                // 2. Get ERR Segment
                log.Info(string.Format("ERR Recovering ..."));
                List <string> errs = LibString.GetAllValuesSegments(raw, "ERR");
                if (errs != null)
                {
                    data.ERRMsg = errs[0];
                }
                log.Info(string.Format("ERR Recovered"));
                // 3. Get ORC Segment
                log.Info(string.Format("ORC Recovering ..."));
                List <string> orcs = LibString.GetAllValuesSegments(raw, "ORC");
                if (orcs != null)
                {
                    foreach (string orc in orcs)
                    {
                        try
                        {
                            string[]  ocrobj   = orc.Split('|');
                            ORCStatus ORC      = new ORCStatus();
                            string[]  esIdanId = ocrobj[2].Split('-');
                            ORC.PresID  = esIdanId[0];
                            ORC.RadioID = esIdanId[1];
                            ORC.Status  = ocrobj[1];
                            string desc = null;
                            switch (ORC.Status)
                            {
                            case "OK":
                                desc = "Inserimento/Cancellazione eseguito con successo";
                                break;

                            case "RQ":
                                desc = "Modifica Eseguita con successo";
                                break;

                            case "UA":
                                desc = "Impossibile Inserire";
                                break;

                            case "UC":
                                desc = "Impossibile Cancellare";
                                break;

                            case "UM":
                                desc = "Impossibile Modificare";
                                break;
                            }
                            ORC.Description = desc;
                            if (data.ORCStatus == null)
                            {
                                data.ORCStatus = new List <ORCStatus>();
                            }
                            data.ORCStatus.Add(ORC);
                        }
                        catch (Exception)
                        {
                            string msg = "Exception During ORC info processing! HL7 Segment errored: " + orc;
                            throw new Exception(msg);
                        }
                    }
                }
                log.Info(string.Format("ORC Recovered", data.ORCStatus.Count));

                log.Info(string.Format("HL7 Message processing Complete! A DTO object has been built!"));
            }
            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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo 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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }