示例#1
0
        public List <MemberServiceDetailSingleton> Preview(Application application)
        {
            List <MemberServiceDetailSingleton> previewResults = new List <MemberServiceDetailSingleton> ();

            MemberServiceDetailSingleton detailResult;

            System.Data.DataTable resultsTable;

            String sqlStatement = String.Empty;

            foreach (MedicalServices.Definitions.ServiceSingletonDefinition currentDefinition in definitions)
            {
                if ((currentDefinition.Enabled) && (currentDefinition.DataSourceType != Mercury.Server.Core.MedicalServices.Enumerations.ServiceDataSourceType.Custom))
                {
                    sqlStatement = currentDefinition.SqlStatement;

                    if (!String.IsNullOrEmpty(sqlStatement))
                    {
                        sqlStatement = sqlStatement.Replace("SELECT", "SELECT TOP 10");

                        resultsTable = application.EnvironmentDatabase.SelectDataTable(sqlStatement, 0);

                        foreach (System.Data.DataRow currentRow in resultsTable.Rows)
                        {
                            detailResult = new MemberServiceDetailSingleton(0, currentDefinition.Id);

                            detailResult.MapDataFields(currentRow);

                            previewResults.Add(detailResult);
                        }
                    }
                }
            }

            return(previewResults);
        }
示例#2
0
        public Boolean Process(Application application)
        {
            Boolean success = true;

            DateTime newLastPaidDate = LastPaidDate;

            Boolean lastPaidDateChanged = false;

            Int64 memberServiceId;

            MemberService memberService;

            MemberServiceDetailSingleton memberServiceDetail;


            Int64 memberMetricId;

            Metrics.MemberMetric memberMetric = null;


            System.Data.DataTable resultsTable;

            String selectStatement = String.Empty;

            String procedureStatement = String.Empty;

            Metrics.Metric labMetric = null;


            base.ProcessLog_StartProcess();

            foreach (MedicalServices.Definitions.ServiceSingletonDefinition currentDefinition in definitions)
            {
                if (currentDefinition.Enabled)
                {
                    if (currentDefinition.DataSourceType == Enumerations.ServiceDataSourceType.Lab)
                    {
                        labMetric = application.MetricGet(currentDefinition.LabMetricId);
                    }

                    selectStatement = currentDefinition.SqlStatement;

                    if (!String.IsNullOrEmpty(selectStatement))
                    {
                        if (currentDefinition.DataSourceType != Mercury.Server.Core.MedicalServices.Enumerations.ServiceDataSourceType.Custom)
                        {
                            selectStatement = selectStatement + "  AND (Claim.PaidDate >= '" + LastPaidDate.ToString("MM/dd/yyyy") + "') AND (Claim.MemberId IS NOT NULL) ORDER BY PaidDate";
                        }

                        else
                        {
                            selectStatement = selectStatement + " '" + LastPaidDate.ToString("MM/dd/yyyy") + "'";
                        }

                        resultsTable = application.EnvironmentDatabase.SelectDataTable(selectStatement, 0);

                        foreach (System.Data.DataRow currentRow in resultsTable.Rows)
                        {
                            memberServiceId = application.MemberServiceGetId((Int64)currentRow["MemberId"], Id, (DateTime)currentRow["EventDate"]);

                            if (memberServiceId == 0)
                            {
                                memberService = new MemberService(application);

                                memberService.MemberId = (Int64)currentRow["MemberId"];

                                memberService.ServiceId = Id;

                                memberService.EventDate = (DateTime)currentRow["EventDate"];

                                memberService.AddedManually = false;

                                success = memberService.Save(application);

                                memberServiceId = memberService.Id;
                            }

                            if ((success) && (memberServiceId != 0))
                            {
                                memberServiceDetail = new MemberServiceDetailSingleton(memberServiceId, currentDefinition.Id);

                                memberServiceDetail.MapDataFields(currentRow);

                                // THE STORED PROCEDURE IS RESPONSIBLE FOR ENSURING NO

                                // DUPLICATE DETAIL ROWS EXISTS UPON INSERT

                                success = memberServiceDetail.Save(application);

                                if (newLastPaidDate < (DateTime)currentRow["PaidDate"])
                                {
                                    newLastPaidDate = (DateTime)currentRow["PaidDate"];

                                    lastPaidDateChanged = true;
                                }
                            }

                            // IF THIS IS LAB AND THE LAB HAS AN ASSOCIATED METRIC VALUE, TRY TO CREATE THE MEMBER METRIC

                            if ((currentDefinition.DataSourceType == Enumerations.ServiceDataSourceType.Lab) && (labMetric != null) && !(currentRow ["LabValue"] is DBNull))
                            {
                                memberMetricId = application.MemberMetricGetId((Int64)currentRow["MemberId"], labMetric.Id, (DateTime)currentRow["EventDate"]);

                                if (memberMetricId == 0)
                                {
                                    memberMetric = new Metrics.MemberMetric(application);

                                    memberMetric.MemberId = (Int64)currentRow["MemberId"];

                                    memberMetric.MetricId = labMetric.Id;

                                    memberMetric.EventDate = (DateTime)currentRow["EventDate"];

                                    memberMetric.MetricValue = Convert.ToDecimal(currentRow["LabValue"]);

                                    memberMetric.AddedManually = false;

                                    success = memberMetric.Save(application);

                                    memberMetricId = memberMetric.Id;
                                }

                                else
                                {
                                    System.Diagnostics.Debug.WriteLine(labMetric.Name);
                                }
                            }

                            if (!success)
                            {
                                break;
                            }
                        }
                    }
                }

                if (!success)
                {
                    break;
                }
            }

            if ((success) && (lastPaidDateChanged))
            {
                // TAKE LAST FOUND PAID DATE AND ADD ONE DAY

                // SINCE THE QUERY LOOKS FOR PAID DATE >=

                LastPaidDate = newLastPaidDate.AddDays(1);

                UpdateLastPaidDate();
            }

            base.ProcessLog_StopProcess((success) ? "Success" : "Failure", "");

            return(success);
        }