Пример #1
0
        private TermMaster GetTermMaster(TermMaster request)
        {
            var        id    = request?.Id;
            TermMaster ret   = null;
            var        query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <TermMaster>(currentUser, "TermMaster", request.Select);

            DocEntityTermMaster entity = null;

            if (id.HasValue)
            {
                entity = DocEntityTermMaster.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No TermMaster found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
Пример #2
0
        public TermMaster Post(TermMaster request)
        {
            if (request == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null.");
            }

            request.Select = request.Select ?? new List <string>();

            TermMaster ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "TermMaster"))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    ret = _AssignValues(request, DocConstantPermission.ADD, ssn);
                });
            }
            return(ret);
        }
Пример #3
0
        public void Delete(TermMaster request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityTermMaster.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No TermMaster could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

                    if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route.");
                    }

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.TERMMASTER);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Пример #4
0
        public TermMaster Patch(TermMaster request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the TermMaster to patch.");
            }

            request.Select = request.Select ?? new List <string>();

            TermMaster ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
Пример #5
0
 public TermMaster Put(TermMaster request)
 {
     return(Patch(request));
 }
Пример #6
0
        public TermMaster Post(TermMasterCopy request)
        {
            TermMaster ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTermMaster.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pBioPortal = entity.BioPortal;
                    if (!DocTools.IsNullOrEmpty(pBioPortal))
                    {
                        pBioPortal += " (Copy)";
                    }
                    var pCategories = entity.Categories.ToList();
                    var pCUI        = entity.CUI;
                    if (!DocTools.IsNullOrEmpty(pCUI))
                    {
                        pCUI += " (Copy)";
                    }
                    var pEnum   = entity.Enum;
                    var pMedDRA = entity.MedDRA;
                    if (!DocTools.IsNullOrEmpty(pMedDRA))
                    {
                        pMedDRA += " (Copy)";
                    }
                    var pName = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pRxNorm = entity.RxNorm;
                    if (!DocTools.IsNullOrEmpty(pRxNorm))
                    {
                        pRxNorm += " (Copy)";
                    }
                    var pSNOWMED = entity.SNOWMED;
                    if (!DocTools.IsNullOrEmpty(pSNOWMED))
                    {
                        pSNOWMED += " (Copy)";
                    }
                    var pSynonyms = entity.Synonyms.ToList();
                    var pTUI      = entity.TUI;
                    if (!DocTools.IsNullOrEmpty(pTUI))
                    {
                        pTUI += " (Copy)";
                    }
                    var pURI = entity.URI;
                    if (!DocTools.IsNullOrEmpty(pURI))
                    {
                        pURI += " (Copy)";
                    }
                    var copy = new DocEntityTermMaster(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , BioPortal = pBioPortal
                        , CUI       = pCUI
                        , Enum      = pEnum
                        , MedDRA    = pMedDRA
                        , Name      = pName
                        , RxNorm    = pRxNorm
                        , SNOWMED   = pSNOWMED
                        , TUI       = pTUI
                        , URI       = pURI
                    };
                    foreach (var item in pCategories)
                    {
                        entity.Categories.Add(item);
                    }

                    foreach (var item in pSynonyms)
                    {
                        entity.Synonyms.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
Пример #7
0
        private TermMaster _AssignValues(TermMaster request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "TermMaster"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            TermMaster ret = null;

            request = _InitAssignValues <TermMaster>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <TermMaster>(DocConstantModelName.TERMMASTER, nameof(TermMaster), request);

            //First, assign all the variables, do database lookups and conversions
            var pBioPortal  = request.BioPortal;
            var pCategories = GetVariable <TermCategory>(request, nameof(request.Categories), request.Categories?.ToList(), request.CategoriesIds?.ToList());
            var pCUI        = request.CUI;
            var pEnum       = DocEntityLookupTableEnum.Get(request.Enum);
            var pMedDRA     = request.MedDRA;
            var pName       = request.Name;
            var pRxNorm     = request.RxNorm;
            var pSNOWMED    = request.SNOWMED;
            var pSynonyms   = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList());
            var pTUI        = request.TUI;
            var pURI        = request.URI;
            var pArchived   = true == request.Archived;
            var pLocked     = request.Locked;

            var entity = InitEntity <DocEntityTermMaster, TermMaster>(request, permission, session);

            if (AllowPatchValue <TermMaster, bool>(request, DocConstantModelName.TERMMASTER, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pBioPortal, permission, nameof(request.BioPortal), pBioPortal != entity.BioPortal))
            {
                entity.BioPortal = pBioPortal;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pCUI, permission, nameof(request.CUI), pCUI != entity.CUI))
            {
                entity.CUI = pCUI;
            }
            if (AllowPatchValue <TermMaster, DocEntityLookupTableEnum>(request, DocConstantModelName.TERMMASTER, pEnum, permission, nameof(request.Enum), pEnum != entity.Enum))
            {
                entity.Enum = pEnum;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pMedDRA, permission, nameof(request.MedDRA), pMedDRA != entity.MedDRA))
            {
                entity.MedDRA = pMedDRA;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pRxNorm, permission, nameof(request.RxNorm), pRxNorm != entity.RxNorm))
            {
                entity.RxNorm = pRxNorm;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pSNOWMED, permission, nameof(request.SNOWMED), pSNOWMED != entity.SNOWMED))
            {
                entity.SNOWMED = pSNOWMED;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pTUI, permission, nameof(request.TUI), pTUI != entity.TUI))
            {
                entity.TUI = pTUI;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pURI, permission, nameof(request.URI), pURI != entity.URI))
            {
                entity.URI = pURI;
            }
            if (request.Locked && AllowPatchValue <TermMaster, bool>(request, DocConstantModelName.TERMMASTER, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <TermMaster, DocEntityTermMaster, TermCategory, DocEntityTermCategory>(request, entity, pCategories, permission, nameof(request.Categories)));
            idsToInvalidate.AddRange(PatchCollection <TermMaster, DocEntityTermMaster, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.TERMMASTER);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <TermMaster>(currentUser, nameof(TermMaster), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.TERMMASTER);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.TERMMASTER, cacheExpires);

            return(ret);
        }
Пример #8
0
 public object Get(TermMaster request) => GetEntityWithCache <TermMaster>(DocConstantModelName.TERMMASTER, request, GetTermMaster);