Exemplo n.º 1
0
        public object MultiEditSubmitAftercare(Guid authorizing_doctor_id, Guid[] case_ids, Guid[] case_ids_to_submit, Guid[] deselected_ids, bool all_selected, string aftercare_performed_date, Guid aftercare_doctor_id, bool should_submit, FilterObject filter, string connectionString, string sessionTicket, out TransactionalInformation transaction)
        {
            var method = MethodInfo.GetCurrentMethod();
            var ipInfo = Util.GetIPInfo(HttpContext.Current.Request);

            transaction = new TransactionalInformation();
            var securityTicket = VerifySessionToken(sessionTicket);
            var data           = cls_Get_Account_Information_with_PracticeID.Invoke(connectionString, securityTicket).Result;
            var response       = new List <Guid>();
            var reportUrl      = "";
            var patient_ids    = new List <Guid>();

            try
            {
                var           dbConnection  = DBSQLSupport.CreateConnection(connectionString);
                DbTransaction dbTransaction = null;

                try
                {
                    dbConnection.Open();
                    dbTransaction = dbConnection.BeginTransaction();

                    var rangeParameters = GetRangeParameters(dbConnection, dbTransaction, securityTicket);

                    ElasticParameterObject filter_by = new ElasticParameterObject();
                    filter_by.date_from = filter.date_from;
                    filter_by.date_to   = filter.date_to;
                    filter_by.filter_by.filter_status = filter.filter_by.filter_status;
                    filter_by.filter_by.filter_type   = filter.filter_by.filter_type;
                    filter_by.search_params           = filter.search_params;

                    var case_id_list = new List <Guid>();
                    if (all_selected || deselected_ids.Length != 0)
                    {
                        if (String.IsNullOrEmpty(aftercare_performed_date))
                        {
                            var aftercares = Get_Aftercares.GetAftercaresFilteredIDs(filter_by, data.PracticeID.ToString(), Array.ConvertAll(deselected_ids, x => x.ToString()), authorizing_doctor_id == aftercare_doctor_id ? false : should_submit, data.AccountInformation.role.Contains("practice"), authorizing_doctor_id.ToString(), "treatment_date", false, rangeParameters, securityTicket);
                            for (var i = 0; i < aftercares.Length; i++)
                            {
                                var aftercare = aftercares[i];
                                case_id_list.Add(Guid.Parse(aftercare.case_id));
                                patient_ids.Add(Guid.Parse(aftercare.patient_id));
                            }
                        }
                        else
                        {
                            var aftercare_date = DateTime.ParseExact(aftercare_performed_date, "dd.MM.yyyy", new System.Globalization.CultureInfo("de", true));
                            var aftercares     = Get_Aftercares.GetAftercaresFilteredIDs(filter_by,
                                                                                         data.PracticeID.ToString(),
                                                                                         Array.ConvertAll(deselected_ids, x => x.ToString()),
                                                                                         authorizing_doctor_id == aftercare_doctor_id ? false : should_submit, data.AccountInformation.role.Contains("practice"), authorizing_doctor_id.ToString(),
                                                                                         "treatment_date", false, rangeParameters,
                                                                                         securityTicket).Where(ac => ac.treatment_date <= aftercare_date).ToArray();

                            for (var i = 0; i < aftercares.Length; i++)
                            {
                                var aftercare = aftercares[i];
                                case_id_list.Add(Guid.Parse(aftercare.case_id));
                                patient_ids.Add(Guid.Parse(aftercare.patient_id));
                            }
                        }
                    }
                    else
                    {
                        var aftercares = Get_Aftercares.GetAftercaresForIDArray(data.PracticeID, data.AccountInformation.role.Contains("practice"), Array.ConvertAll(case_ids, x => x.ToString()), should_submit, "", "treatment_date", false, securityTicket).ToArray();
                        for (var i = 0; i < aftercares.Length; i++)
                        {
                            var aftercare = aftercares[i];
                            case_id_list.Add(Guid.Parse(aftercare.case_id));
                            patient_ids.Add(Guid.Parse(aftercare.patient_id));
                        }
                    }

                    case_ids = case_id_list.ToArray();

                    CAS_SC_1425 submitted_case_data = null;

                    if (case_ids.Any())
                    {
                        if (!should_submit)
                        {
                            response = cls_Save_Case_Multi_Edit.Invoke(dbConnection, dbTransaction, new P_CAS_SCME_1741()
                            {
                                is_treatment             = false,
                                case_ids                 = case_ids,
                                aftercare_doctor_id      = aftercare_doctor_id,
                                practice_id              = data.PracticeID,
                                aftercare_performed_date = aftercare_performed_date
                            }, securityTicket).Result.ToList();
                        }
                        else
                        {
                            if (case_ids_to_submit.Any())
                            {
                                submitted_case_data = cls_Submit_Case.Invoke(dbConnection, dbTransaction, new P_CAS_SC_1425()
                                {
                                    case_ids                 = case_ids_to_submit,
                                    is_treatment             = false,
                                    practice_id              = data.PracticeID,
                                    date_of_performed_action = DateTime.Parse(aftercare_performed_date, culture, System.Globalization.DateTimeStyles.AssumeLocal),
                                    authorizing_doctor_id    = authorizing_doctor_id
                                }, securityTicket).Result;
                            }
                        }

                        if (submitted_case_data != null && !String.IsNullOrEmpty(submitted_case_data.pdf_report_url))
                        {
                            reportUrl = submitted_case_data.pdf_report_url;
                        }

                        var elasticRefresher = new ElasticRefresher(patient_ids, dbConnection, dbTransaction, securityTicket, true);
                        elasticRefresher.UpdateAftercare();
                        if (should_submit)
                        {
                            elasticRefresher.UpdateIvoms();
                        }

                        elasticRefresher.RebuildElastic();


                        Logger.LogDocAppInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, securityTicket, new AftercareMultiEditSubmitModel()
                        {
                            AftercareDoctorID      = aftercare_doctor_id,
                            AftercarePerformedDate = aftercare_performed_date,
                            AuthorizedByID         = authorizing_doctor_id,
                            CaseIDs         = case_ids,
                            CaseIDsToSubmit = case_ids_to_submit,
                            IsSubmit        = should_submit
                        }), data.PracticeName);

                        dbTransaction.Commit();

                        if (reportUrl != "")
                        {
                            return(reportUrl);
                        }
                    }
                }
                finally
                {
                    if (dbConnection.State == System.Data.ConnectionState.Open)
                    {
                        dbConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogDocAppInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, securityTicket, ex), data.PracticeName);

                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.IsAuthenicated = true;
                transaction.IsException    = true;
            }

            return(response.ToArray());
        }
Exemplo n.º 2
0
        public String SubmitAftercare(Guid authorizing_doctor_id, Guid case_id, string date_of_performed_action, string connectionString, string sessionTicket, out TransactionalInformation transaction, DbConnection dbConnection = null, DbTransaction dbTransaction = null)
        {
            var handle_connection  = dbConnection == null;
            var handle_transaction = dbTransaction == null;

            var method = MethodInfo.GetCurrentMethod();
            var ipInfo = Util.GetIPInfo(HttpContext.Current.Request);

            transaction = new TransactionalInformation();
            var report_url     = "";
            var securityTicket = VerifySessionToken(sessionTicket);
            var data           = cls_Get_Account_Information_with_PracticeID.Invoke(connectionString, securityTicket).Result;

            try
            {
                if (handle_connection)
                {
                    dbConnection = DBSQLSupport.CreateConnection(connectionString);
                }
                try
                {
                    if (handle_connection)
                    {
                        dbConnection.Open();
                    }

                    if (handle_transaction)
                    {
                        dbTransaction = dbConnection.BeginTransaction();
                    }

                    CAS_SC_1425 submitted_case_data = null;

                    var parameter = new P_CAS_SC_1425()
                    {
                        case_ids                 = new Guid[] { case_id },
                        is_treatment             = false,
                        practice_id              = data.PracticeID,
                        date_of_performed_action = DateTime.Parse(date_of_performed_action, culture, System.Globalization.DateTimeStyles.AssumeLocal),
                        authorizing_doctor_id    = authorizing_doctor_id
                    };

                    submitted_case_data = cls_Submit_Case.Invoke(dbConnection, dbTransaction, parameter, securityTicket).Result;

                    if (submitted_case_data != null)
                    {
                        if (!String.IsNullOrEmpty(submitted_case_data.pdf_report_url))
                        {
                            report_url = submitted_case_data.pdf_report_url;
                        }

                        var elasticRefresher = new ElasticRefresher(submitted_case_data.patient_ids, dbConnection, dbTransaction, securityTicket, true);
                        elasticRefresher
                        .UpdateAftercare()
                        .UpdateIvoms()
                        .RebuildElastic();
                    }

                    Logger.LogDocAppInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, securityTicket, parameter), data.PracticeName);

                    if (handle_transaction)
                    {
                        dbTransaction.Commit();
                    }
                }
                finally
                {
                    if (handle_connection)
                    {
                        dbConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogDocAppInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, securityTicket, ex), data.PracticeName);

                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.IsAuthenicated = true;
                transaction.IsException    = true;
            }

            return(report_url);
        }