Beispiel #1
0
        public void CreateUserAuthenticationMapping()
        {
            try
            {
                var dataSet = aHelper.GetAllUsers().Where(w => w.CPSiteId.Value == MigrationVariables.CurrentSiteId).ToList();
                RecordCount = dataSet.Count;

                foreach (var adUser in dataSet)
                {
                    aspnet_Membership  member;
                    aspnet_Users       aspUser;
                    UserAuthentication uAuth = null;
                    Guid appId           = nHelper.GetApplicationId("Diabetes Partner");
                    bool isAdmin         = (string.Equals(adUser.CliniProID, "admin", StringComparison.CurrentCultureIgnoreCase)) ? true : false;
                    bool isAdminSiteUser = false;

                    if (isAdmin)
                    {
                        switch (aHelper.GetCorporationName(adUser.CPSiteId))
                        {
                        case "Insulet":
                            appId = nHelper.GetApplicationId("OmniPod Partner");
                            break;

                        case "CliniProWeb":
                            appId = nHelper.GetApplicationId("CliniPro-Web");
                            break;

                        case "NuMedics":
                        default:
                            appId           = nHelper.GetApplicationId("Administration");
                            isAdminSiteUser = true;
                            break;
                        }
                    }

                    member  = aHelper.GetMembershipInfo(adUser.UserId);
                    aspUser = aHelper.GetAspUserInfo(adUser.UserId);

                    if (mHelper.HasUserMigrated(aspUser.UserName, member.UserId))
                    {
                        MappingStatistics.LogFailedMapping("None", "None", "Users", typeof(User), String.Empty, "User previously migrated.");
                        FailedCount++;
                    }
                    else
                    {
                        var userId = nHelper.ValidGuid(adUser.UserId);

                        uAuth = new UserAuthentication
                        {
                            ApplicationId              = appId,
                            UserId                     = userId,
                            Username                   = aspUser.UserName,
                            Password                   = member.Password,
                            PasswordQuestion           = member.PasswordQuestion,
                            PasswordAnswer             = member.PasswordAnswer,
                            PasswordAnswerFailureCount = member.FailedPasswordAnswerAttemptCount,
                            PasswordFailureCount       = member.FailedPasswordAttemptCount,
                            LastActivityDate           = aspUser.LastActivityDate,
                            LastLockOutDate            = member.LastLockoutDate,
                            IsApproved                 = member.IsApproved,
                            IsLockedOut                = member.IsLockedOut,
                            IsTempPassword             = member.IsTemp,
                            IsloggedIn                 = false,
                            LastUpdatedByUser          = userId
                        };

                        var user = new User
                        {
                            UserId            = userId,
                            AssignedUserTypes = new List <AssignedUserType> {
                                new AssignedUserType {
                                    UserId = userId, UserType = (isAdmin) ? (int)UserType.Clinician : (int)UserType.Patient
                                }
                            },
                            //UserType = (isAdmin) ? (int)UserType.Clinician : (int)UserType.Patient,
                            CreationDate = member.CreateDate
                        };

                        if (isAdminSiteUser)
                        {
                            user.AssignedUserTypes.Add(new AssignedUserType {
                                UserId = userId, UserType = (int)UserType.Admin
                            });
                        }

                        user.UserAuthentications.Add(uAuth);

                        // add user info to in-memery collection for use throughout application
                        MemoryMappings.AddPatientInfo(adUser.CPSiteId.Value, adUser.CliniProID, user.UserId);

                        if (CanAddToContext(user.UserId))
                        {
                            CompletedMappings.Add(user);
                        }
                        else
                        {
                            MappingStatistics.LogFailedMapping("None", "None", "Users", typeof(User), JsonConvert.SerializeObject(user), "User already exist in database.");
                            FailedCount++;
                        }
                    }
                }

                MappingStatistics.LogMappingStat("None", 0, "Users", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating User mapping.", e);
            }
        }
Beispiel #2
0
        public void CreatePatientMapping()
        {
            try
            {
                var dataSet = TableAgent.DataSet.Tables[FbTableName].Rows;
                RecordCount = TableAgent.RowCount;
                //Guid instId = nHelper.GetInstitutionId(MigrationVariables.CurrentSiteId);

                foreach (DataRow row in dataSet)
                {
                    User user = new User();

                    // get userid from old aspnetdb matching on patientid #####.#####
                    // if no userid then create new one for this patient
                    var patId  = row["KEYID"].ToString();
                    var uid    = aHelper.GetUserIdFromPatientId(patId);
                    var userId = (uid != Guid.Empty) ? uid : Guid.NewGuid();
                    userId = nHelper.ValidGuid(userId);

                    if (mHelper.HasPatientMigrated(patId))
                    {
                        MappingStatistics.LogFailedMapping("PATIENTS", patId, "Patients", typeof(Patient), String.Empty, "Patient previously migrated.");
                        FailedCount++;
                    }
                    else
                    {
                        var medRecId = (row["MEDICALRECORDIDENTIFIER"] is DBNull) ? String.Empty : row["MEDICALRECORDIDENTIFIER"].ToString();

                        if (!String.IsNullOrEmpty(medRecId) && !medRecId.StartsWith("PR_"))
                        {
                            MemoryMappings.AddMRID(new MedicalRecordIdentifier {
                                MRID = medRecId,
                                //InstitutionId = instId,
                                PatientUserId = userId
                            });
                        }

                        var pat = new Patient
                        {
                            UserId      = userId,
                            Firstname   = (row["FIRSTNAME"] is DBNull) ? String.Empty : row["FIRSTNAME"].ToString(),
                            Lastname    = (row["LASTNAME"] is DBNull) ? String.Empty : row["LASTNAME"].ToString(),
                            Middlename  = (row["MIDDLENAME"] is DBNull) ? String.Empty : row["MIDDLENAME"].ToString(),
                            Gender      = (row["GENDER"] is DBNull) ? 1 : (row["GENDER"].ToString().ToLower().StartsWith("m", StringComparison.CurrentCulture)) ? 2 : 3, //From the GlobalStandards database, 'Gender' table
                            DateofBirth = (row["DOB"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["DOB"].ToString()),
                            Email       = (row["EMAIL"] is DBNull) ? String.Empty : row["EMAIL"].ToString(),
                            //InstitutionId = instId,
                            LastUpdatedByUser = userId
                        };

                        var adr = new PatientAddress
                        {
                            Street1           = (row["STREET1"] is DBNull) ? String.Empty : row["STREET1"].ToString(),
                            Street2           = (row["STREET2"] is DBNull) ? String.Empty : row["STREET2"].ToString(),
                            Street3           = (row["STREET3"] is DBNull) ? String.Empty : row["STREET3"].ToString(),
                            City              = (row["CITY"] is DBNull) ? String.Empty : row["CITY"].ToString(),
                            County            = (row["COUNTY"] is DBNull) ? String.Empty : row["COUNTY"].ToString(),
                            State             = (row["STATE"] is DBNull) ? String.Empty : row["STATE"].ToString(),
                            Zip               = (row["ZIP"] is DBNull) ? String.Empty : row["ZIP"].ToString(),
                            Country           = (row["COUNTRY"] is DBNull) ? String.Empty : row["COUNTRY"].ToString(),
                            LastUpdatedByUser = userId
                        };

                        pat.PatientAddresses.Add(adr);

                        // must create clinipro user to store new userid for future usage
                        if (uid == Guid.Empty || uid != userId)
                        {
                            aHelper.CreateCliniProUser(userId, patId);

                            user.UserId = userId;
                            user.AssignedUserTypes.Add(new AssignedUserType {
                                UserId = userId, UserType = (int)UserType.Patient
                            });
                            user.CreationDate = DateTime.Now;

                            pat.User = user;
                        }

                        // add patient info to in-memery collection for use throughout application
                        MemoryMappings.AddPatientInfo(MigrationVariables.CurrentSiteId, patId, pat.UserId);

                        if (CanAddToContext(user.UserId))
                        {
                            CompletedMappings.Add(pat);
                        }
                        else
                        {
                            MappingStatistics.LogFailedMapping("PATIENTS", patId, "Patients", typeof(Patient), JsonConvert.SerializeObject(user), "Patient already exist in database.");
                            FailedCount++;
                        }
                    }
                }

                MappingStatistics.LogMappingStat("PATIENTS", RecordCount, "Patients", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating Patient mapping.", e);
            }
        }