Example #1
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);
        }