Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }