public Boolean Process()
        {
            Boolean success = true;

            String selectStatement = String.Empty;

            System.Data.DataTable resultsTable;


            Int64 memberServiceId;

            MemberService memberService;

            MemberServiceDetailSet memberServiceDetail;


            if (!Enabled)
            {
                return(false);
            }


            base.ProcessLog_StartProcess();

            switch (SetType)
            {
            case Mercury.Server.Core.MedicalServices.Enumerations.ServiceSetType.Union:

                #region Union Set

                foreach (MedicalServices.Definitions.ServiceSetDefinition currentDefinition in ActiveDefinitions)
                {
                    if (currentDefinition.Enabled)
                    {
                        selectStatement = currentDefinition.SqlStatement;

                        if (!String.IsNullOrEmpty(selectStatement))
                        {
                            resultsTable = base.application.EnvironmentDatabase.SelectDataTable(selectStatement, 0);

                            foreach (System.Data.DataRow currentRow in resultsTable.Rows)
                            {
                                memberServiceId = base.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(base.application);

                                    memberServiceId = memberService.Id;
                                }

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

                                    memberServiceDetail.MapDataFields(currentRow);

                                    success = memberServiceDetail.Save(base.application);
                                }

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

                    if (!success)
                    {
                        break;
                    }
                }


                #endregion

                break;

            case Mercury.Server.Core.MedicalServices.Enumerations.ServiceSetType.Intersection:

                if (definitions.Count >= 4)
                {
                    success = ProcessIntersectionSetLarge();
                }

                else
                {
                    success = ProcessIntersectionSet(String.Empty, true);
                }

                break;
            }

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

            return(success);
        }
Exemple #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);
        }
        protected Boolean ProcessIntersectionSet(String forStatement, Boolean outputStep)
        {
            Boolean success = true;

            String procedureStatement = String.Empty;

            Int32 currentPass = 0;

            Int64 currentRowIndex = 0;

            System.Data.DataTable memberServiceTable = new System.Data.DataTable();

            System.Diagnostics.Debug.WriteLine("\r\n\r\n ----- " + Name + " -----");

            try {
                do
                {
                    currentPass = currentPass + 1;


                    if (String.IsNullOrEmpty(forStatement))
                    {
                        procedureStatement = String.Empty;

                        procedureStatement = procedureStatement + IntersectionSetMemberServiceSql();

                        procedureStatement = procedureStatement + IntersectionSetMemberServiceSortedSql();

                        procedureStatement = procedureStatement + IntersectionSetMemberServiceFilteredSql();
                    }

                    else
                    {
                        procedureStatement = forStatement;
                    }


                    System.Diagnostics.Debug.WriteLine(procedureStatement);

                    if (outputStep)
                    {
                        base.ProcessStep_StartStep("Service Set", Name + ": " + currentPass, procedureStatement);
                    }

                    memberServiceTable = base.application.EnvironmentDatabase.SelectDataTable(procedureStatement, 86400);

                    if (base.application.EnvironmentDatabase.LastException != null)
                    {
                        throw base.application.EnvironmentDatabase.LastException;
                    }

                    currentRowIndex = 0;

                    foreach (System.Data.DataRow currentRow in memberServiceTable.Rows)
                    {
                        currentRowIndex = currentRowIndex + 1;

                        MemberService memberService = new MemberService(application);

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

                        memberService.ServiceId = Id;

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

                        memberService.AddedManually = false;

                        success = memberService.Save(base.application);

                        if (success)
                        {
                            for (Int32 currentDefinition = 1; currentDefinition <= ActiveDefinitions.Count; currentDefinition++)
                            {
                                String fieldPrefix = "Service" + currentDefinition.ToString() + "_";


                                // THE BELOW SHOULD BE COLUMN "SetDefinitionId" VERSUS "ServiceSetDefinitionId" FROM DYNAMIC SQL

                                MemberServiceDetailSet memberServiceDetail = new MemberServiceDetailSet(memberService.Id, (Int64)currentRow[fieldPrefix + "SetDefinitionId"]);

                                memberServiceDetail.MemberId = memberService.MemberId;

                                memberServiceDetail.DetailMemberServiceId = (Int64)currentRow[fieldPrefix + "MemberServiceId"];

                                memberServiceDetail.EventDate = (DateTime)currentRow[fieldPrefix + "EventDate"];

                                memberServiceDetail.ParentServiceId = Id;

                                memberServiceDetail.ServiceId = (Int64)currentRow[fieldPrefix + "ServiceId"];

                                memberServiceDetail.ServiceName = (String)currentRow[fieldPrefix + "ServiceName"];

                                memberServiceDetail.ServiceType = (Mercury.Server.Core.MedicalServices.Enumerations.MedicalServiceType)(Int32) currentRow[fieldPrefix + "ServiceType"];

                                success = memberServiceDetail.Save(base.application);

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

                    if (outputStep)
                    {
                        base.ProcessStep_StopStep((success) ? "Success: " + memberServiceTable.Rows.Count.ToString() : "Failure", "");
                    }

                    if (!success)
                    {
                        break;
                    }
                } while (memberServiceTable.Rows.Count != 0);
            }

            catch (Exception executionException) {
                success = false;

                base.application.SetLastException(executionException);

                if (outputStep)
                {
                    base.ProcessStep_StopStep((success) ? "Success: " + memberServiceTable.Rows.Count.ToString() : "Failure", executionException.Message);
                }
            }

            return(success);
        }