public static UserObject CreateUser(string name)
 {
     string[] names = name.Split(',');
     StringBuilder userId = new StringBuilder();
     if (names.Length > 1)
     {
         if (names[1].Trim().Length > 0)
             userId.Append(names[1].Trim().ToLower()[0]);
         userId.Append(names[0].Trim().ToLower());
     }
     else if (names.Length == 1)
     {
         userId.Append(names[0].Trim().ToLower());
     }
     else
     {
         userId.Append("risuser");
     }
     bool quit = false;
     int count = 1;
     UserObject user = null;
     do
     {
         user = new UserObject();
         user.LoginName.Value = userId.ToString();
         user.Load();
         if (!user.IsLoaded)
         {
             quit = true;
         }
         else
         {
             userId.Append(count.ToString());
             count++;
         }
     }
     while (!quit);
     user.Name.Value = name;
     user.Password.Value = "password";
     user.IsActive.Value = 1;
     user.Save();
     return user;
 }
 //not using this funciton. for the latest client hospital code will be passed on instead of ref phy
 private bool SetReferringPhysician(DICOMStudyObject dicomStudy,StudyObject risStudy)
 {
     //As our system is not being used to entrer work lists we can not pick up Referrring Physicians from our own worklist
     //therrefore the worklist code has been commented for now and we just create a user
     bool isSet = false;
     /*WorkListObject workList = new WorkListObject();
     workList.WorkListId.Value = dicomStudy.AccessionNumber.Value;
     workList.Load(GenericDataMigrator.AdminUserId);
     if (workList.IsLoaded)
     {
         risStudy.ReferringPhysicianId.Value = workList.RequestingPhysicianId.Value;
         isSet = true;
     }
     else*/
     if(dicomStudy.ReferringPhysician.Value != null)
     {
         UserObject user = new UserObject();
         user.Name.Value = dicomStudy.ReferringPhysician.Value;
         user.Load();
         if (!user.IsLoaded)
         {
             user = DatabaseUtility.CreateUser((string)dicomStudy.ReferringPhysician.Value);
             UserRoleObject userRole = new UserRoleObject();
             userRole.UserId.Value = user.GetPrimaryKey().Value;
             userRole.RoleId.Value = Constants.Roles.ReferringPhysician;
             userRole.Save();
         }
         risStudy.ReferringPhysicianId.Value = user.UserId.Value;
         //risStudy.ReferringPhysician.Value = dicomStudy.ReferringPhysician.Value;
         isSet = true;
     }
     return isSet;
 }
        private void AssignHospital(DICOMStudyObject dicomStudy, StudyObject risStudy)
        {
            if (dicomStudy.ReferringPhysician.Value != null)
            {
                string referringPhysician = "";
                string hospitalCode = "";
                foreach (char ch in dicomStudy.ReferringPhysician.Value.ToString().Replace("^", " ").ToCharArray())
                {
                    if (Char.IsDigit(ch))
                    {
                        hospitalCode += ch;
                    }
                    else
                    {
                        referringPhysician += ch;
                    }
                }
                if (hospitalCode.Length > 0)
                {
                    HospitalObject hospital = new HospitalObject();
                    hospital.Code.Value = hospitalCode;
                    hospital.Load();
                    if (hospital.IsLoaded)
                    {
                        risStudy.HospitalId.Value = hospital.HospitalId.Value;
                        risStudy.ClientId.Value = hospital.ClientId.Value;
                    }
                    if (referringPhysician.Length > 0)
                    {
                        UserObject user = new UserObject();
                        user.Name.Value = referringPhysician;
                        user.Load();
                        if (user.IsLoaded)
                        {
                            risStudy.ReferringPhysicianId.Value = user.UserId.Value;
                        }
                    }

                }
            }
        }