コード例 #1
0
        public AddUserResponse AddUser(AddUserRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.UserDetail, "UserDetail");

            var userDetail  = request.UserDetail;
            var accountType = (userDetail.AccountType != null)
                                ? EnumUtils.GetEnumValue <UserAccountType>(userDetail.AccountType)
                                : UserAccountType.U;    // default account type is U if not specified

            // is the current user authorized to create user accounts of this type?
            EnsureCurrentUserAuthorizedToManage(accountType);

            if (!UserName.IsLegalUserName(userDetail.UserName))
            {
                throw new RequestValidationException("Illegal account name.");
            }

            // create new user
            var userInfo = new UserInfo(
                accountType,
                userDetail.UserName,
                userDetail.DisplayName,
                userDetail.EmailAddress,
                userDetail.ValidFrom,
                userDetail.ValidUntil);

            var password = GetNewAccountPassword(accountType, request.Password);
            var user     = User.CreateNewUser(userInfo, password, new HashedSet <AuthorityGroup>());

            // copy other info such as authority groups from request
            var assembler = new UserAssembler();

            assembler.UpdateUser(user, request.UserDetail, PersistenceContext);

            // save
            PersistenceContext.Lock(user, DirtyState.New);
            PersistenceContext.SynchState();

            return(new AddUserResponse(user.GetRef(), assembler.GetUserSummary(user)));
        }
コード例 #2
0
        public AddCannedTextResponse AddCannedText(AddCannedTextRequest request)
        {
            CheckCannedTextWriteAccess(request.Detail);

            if (string.IsNullOrEmpty(request.Detail.Name))
            {
                throw new RequestValidationException(SR.ExceptionCannedTextNameRequired);
            }

            if (string.IsNullOrEmpty(request.Detail.Category))
            {
                throw new RequestValidationException(SR.ExceptionCannedTextCategoryRequired);
            }

            var assembler  = new CannedTextAssembler();
            var cannedText = assembler.CreateCannedText(request.Detail, this.CurrentUserStaff, this.PersistenceContext);

            PersistenceContext.Lock(cannedText, DirtyState.New);
            PersistenceContext.SynchState();

            return(new AddCannedTextResponse(assembler.GetCannedTextSummary(cannedText, this.PersistenceContext)));
        }
コード例 #3
0
        public ImportSettingsGroupResponse ImportSettingsGroup(ImportSettingsGroupRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.Group, "Group");

            var broker = PersistenceContext.GetBroker <IConfigurationSettingsGroupBroker>();

            var where = ConfigurationSettingsGroup.GetCriteria(request.Group);
            var group = CollectionUtils.FirstElement(broker.Find(where));

            if (group == null)
            {
                // group doesn't exist, need to create it
                group = new ConfigurationSettingsGroup();
                group.UpdateFromDescriptor(request.Group);
                PersistenceContext.Lock(group, DirtyState.New);
            }
            else
            {
                // update group from descriptor
                group.UpdateFromDescriptor(request.Group);
            }

            if (request.Properties != null)
            {
                // update properties
                group.SettingsProperties.Clear();
                foreach (var descriptor in request.Properties)
                {
                    var property = new ConfigurationSettingsProperty();
                    property.UpdateFromDescriptor(descriptor);
                    group.SettingsProperties.Add(property);
                }
            }

            PersistenceContext.SynchState();

            return(new ImportSettingsGroupResponse());
        }
コード例 #4
0
        public AddExternalPractitionerResponse AddExternalPractitioner(AddExternalPractitionerRequest request)
        {
            var prac = new ExternalPractitioner();

            var assembler = new ExternalPractitionerAssembler();

            assembler.UpdateExternalPractitioner(request.PractitionerDetail, prac, PersistenceContext);

            prac.MarkEdited();
            var userCanVerify = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification);

            if (request.MarkVerified && userCanVerify)
            {
                prac.MarkVerified();
            }

            PersistenceContext.Lock(prac, DirtyState.New);

            // ensure the new prac is assigned an OID before using it in the return value
            PersistenceContext.SynchState();

            return(new AddExternalPractitionerResponse(assembler.CreateExternalPractitionerSummary(prac, PersistenceContext)));
        }
コード例 #5
0
        public UpdateAuthorityGroupResponse UpdateAuthorityGroup(UpdateAuthorityGroupRequest request)
        {
            var authorityGroup = PersistenceContext.Load <AuthorityGroup>(request.AuthorityGroupDetail.AuthorityGroupRef);

            if (authorityGroup.DataGroup && !request.AuthorityGroupDetail.DataGroup)
            {
                var user = GetUser(Thread.CurrentPrincipal.Identity.Name, PersistenceContext);
                if (!user.Password.Verify(request.Password))
                {
                    // the error message is deliberately vague
                    throw new UserAccessDeniedException();
                }
            }

            // set properties from request
            var assembler = new AuthorityGroupAssembler();

            assembler.UpdateAuthorityGroup(authorityGroup, request.AuthorityGroupDetail, PersistenceContext);

            PersistenceContext.SynchState();

            return(new UpdateAuthorityGroupResponse(assembler.CreateAuthorityGroupSummary(authorityGroup)));
        }
コード例 #6
0
ファイル: StaffAdminService.cs プロジェクト: hksonngan/Xian
        public DeleteStaffResponse DeleteStaff(DeleteStaffRequest request)
        {
            try
            {
                var broker = PersistenceContext.GetBroker <IStaffBroker>();
                var item   = broker.Load(request.StaffRef, EntityLoadFlags.Proxy);

                //bug #3324: because StaffGroup owns the collection, need to iterate over each group
                //and manually remove this staff
                var groups = new List <StaffGroup>(item.Groups);
                foreach (var group in groups)
                {
                    group.RemoveMember(item);
                }

                broker.Delete(item);
                PersistenceContext.SynchState();
                return(new DeleteStaffResponse());
            }
            catch (PersistenceException)
            {
                throw new RequestValidationException(string.Format(SR.ExceptionFailedToDelete, TerminologyTranslator.Translate(typeof(Staff))));
            }
        }
コード例 #7
0
        public RemoveValueResponse RemoveValue(RemoveValueRequest request)
        {
            Type enumClass = null;

            try
            {
                enumClass = GetEnumClass(request.AssemblyQualifiedClassName);

                // Client side should enforce this.  But just in case it does not.
                if (IsSoftEnum(enumClass) == false)
                {
                    throw new RequestValidationException(SR.ExceptionUnableToDeleteHardEnumeration);
                }

                var broker = PersistenceContext.GetBroker <IEnumBroker>();
                broker.RemoveValue(enumClass, request.Value.Code);
                PersistenceContext.SynchState();
                return(new RemoveValueResponse());
            }
            catch (PersistenceException)
            {
                throw new RequestValidationException(string.Format(SR.ExceptionFailedToDelete, TerminologyTranslator.Translate(enumClass)));
            }
        }
コード例 #8
0
        public AddAuthorityGroupResponse AddAuthorityGroup(AddAuthorityGroupRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.AuthorityGroupDetail, "AuthorityGroupDetail");

            if (request.AuthorityGroupDetail.BuiltIn)
            {
                throw new RequestValidationException(SR.MessageCannotManageBuiltInAuthorityGroups);
            }

            // create new group
            var authorityGroup = new AuthorityGroup();

            // set properties from request
            var assembler = new AuthorityGroupAssembler();

            assembler.UpdateAuthorityGroup(authorityGroup, request.AuthorityGroupDetail, PersistenceContext);

            // save
            PersistenceContext.Lock(authorityGroup, DirtyState.New);
            PersistenceContext.SynchState();

            return(new AddAuthorityGroupResponse(assembler.CreateAuthorityGroupSummary(authorityGroup)));
        }
コード例 #9
0
        public MergeExternalPractitionerResponse MergeExternalPractitioner(MergeExternalPractitionerRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.LeftPractitionerRef, "LeftPractitionerRef");
            Platform.CheckMemberIsSet(request.RightPractitionerRef, "RightPractitionerRef");

            var left  = PersistenceContext.Load <ExternalPractitioner>(request.LeftPractitionerRef, EntityLoadFlags.Proxy);
            var right = PersistenceContext.Load <ExternalPractitioner>(request.RightPractitionerRef, EntityLoadFlags.Proxy);

            // if we are only doing a cost estimate, exit here without modifying any data
            if (request.EstimateCostOnly)
            {
                var cost = EstimateAffectedRecords(right, left);
                return(new MergeExternalPractitionerResponse(cost));
            }

            // unpack the request, loading all required entities
            var nameAssembler = new PersonNameAssembler();
            var name          = new PersonName();

            nameAssembler.UpdatePersonName(request.Name, name);

            var defaultContactPoint = request.DefaultContactPointRef != null?
                                      PersistenceContext.Load <ExternalPractitionerContactPoint>(request.DefaultContactPointRef) : null;

            var deactivatedContactPoints = request.DeactivatedContactPointRefs == null ? new List <ExternalPractitionerContactPoint>() :
                                           CollectionUtils.Map(request.DeactivatedContactPointRefs,
                                                               (EntityRef cpRef) => PersistenceContext.Load <ExternalPractitionerContactPoint>(cpRef));

            var cpReplacements = CollectionUtils.Map(request.ContactPointReplacements ?? (new Dictionary <EntityRef, EntityRef>()),
                                                     kvp => new KeyValuePair <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>(
                                                         PersistenceContext.Load <ExternalPractitionerContactPoint>(kvp.Key, EntityLoadFlags.Proxy),
                                                         PersistenceContext.Load <ExternalPractitionerContactPoint>(kvp.Value, EntityLoadFlags.Proxy)));


            // merge the practitioners
            var result = ExternalPractitioner.MergePractitioners(left, right,
                                                                 name,
                                                                 request.LicenseNumber,
                                                                 request.BillingNumber,
                                                                 request.ExtendedProperties,
                                                                 defaultContactPoint,
                                                                 deactivatedContactPoints,
                                                                 cpReplacements
                                                                 );

            PersistenceContext.Lock(result, DirtyState.New);

            // if user has verify permission, verify the result
            if (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification))
            {
                result.MarkVerified();
            }

            // queue work items to migrate orders and visits
            foreach (var practitioner in new[] { right, left })
            {
                var queueItem = MergeWorkQueueItem.Create(practitioner.GetRef());
                PersistenceContext.Lock(queueItem, DirtyState.New);
            }

            PersistenceContext.SynchState();

            var assembler = new ExternalPractitionerAssembler();

            return(new MergeExternalPractitionerResponse(assembler.CreateExternalPractitionerSummary(result, this.PersistenceContext)));
        }
コード例 #10
0
        public MergeDuplicateContactPointResponse MergeDuplicateContactPoint(MergeDuplicateContactPointRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.RetainedContactPointRef, "RetainedContactPointRef");
            Platform.CheckMemberIsSet(request.ReplacedContactPointRef, "ReplacedContactPointRef");

            var dest = PersistenceContext.Load <ExternalPractitionerContactPoint>(request.RetainedContactPointRef, EntityLoadFlags.Proxy);
            var src  = PersistenceContext.Load <ExternalPractitionerContactPoint>(request.ReplacedContactPointRef, EntityLoadFlags.Proxy);

            // if we are only doing a cost estimate, exit here without modifying any data
            if (request.EstimateCostOnly)
            {
                // compute cost estimate.  Need to include affected records of both src and dest, because both will be merged and deactivated.
                var cost = EstimateAffectedRecords(dest, src);
                return(new MergeDuplicateContactPointResponse(cost));
            }

            // combine all phone numbers and addresses, expiring those from the src object
            var allPhoneNumbers = CollectionUtils.Concat(
                CloneAndExpire(dest.TelephoneNumbers, tn => tn.ValidRange, false),
                CloneAndExpire(src.TelephoneNumbers, tn => tn.ValidRange, true));
            var allAddresses = CollectionUtils.Concat(
                CloneAndExpire(dest.Addresses, tn => tn.ValidRange, false),
                CloneAndExpire(src.Addresses, tn => tn.ValidRange, true));
            var allEmailAddresses = CollectionUtils.Concat(
                CloneAndExpire(dest.EmailAddresses, tn => tn.ValidRange, false),
                CloneAndExpire(src.EmailAddresses, tn => tn.ValidRange, true));

            // merge contact points
            var result = ExternalPractitionerContactPoint.MergeContactPoints(
                dest,
                src,
                dest.Name,
                dest.Description,
                dest.PreferredResultCommunicationMode,
                dest.InformationAuthority,
                allPhoneNumbers,
                allAddresses,
                allEmailAddresses);

            PersistenceContext.Lock(result, DirtyState.New);

            // if user has verify permission, verify the practitioner
            if (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification))
            {
                result.Practitioner.MarkVerified();
            }

            // queue work items to migrate orders
            foreach (var contactPoint in new[] { src, dest })
            {
                var queueItem = MergeWorkQueueItem.Create(contactPoint.GetRef());
                PersistenceContext.Lock(queueItem, DirtyState.New);
            }

            PersistenceContext.SynchState();

            var assembler = new ExternalPractitionerAssembler();

            return(new MergeDuplicateContactPointResponse(assembler.CreateExternalPractitionerContactPointSummary(result)));
        }