Пример #1
0
        public void UpdateReportTemplateTest()
        {
            var templateName = RandomHelper.GenerateString();
            var modalityType = RandomHelper.GenerateString();
            var bodyPart     = RandomHelper.GenerateString();
            var gender       = RandomHelper.GenerateString();
            var wygText      = RandomHelper.GenerateString();
            var wysText      = RandomHelper.GenerateString();
            ReportTemplateDto newReportTemplateDto = new ReportTemplateDto
            {
                TemplateName = templateName,
                ModalityType = modalityType,
                BodyPart     = bodyPart,
                Gender       = gender,
                WYGText      = wygText,
                WYSText      = wysText
            };
            ReportTemplateDto reportTemplateDto = _reportTemplateService.CreateReportTemplate(newReportTemplateDto, _userID);

            Assert.AreNotEqual(null, reportTemplateDto);

            var newTemplateName = RandomHelper.GenerateString();

            reportTemplateDto.TemplateName = newTemplateName;
            ReportTemplateDto updateReportTemplateDto = _reportTemplateService.UpdateReportTemplate(reportTemplateDto, _userID);

            Assert.AreEqual(newTemplateName, updateReportTemplateDto.TemplateName);
        }
Пример #2
0
        public void DeleteTemplateByIDTest()
        {
            var templateName = RandomHelper.GenerateString();
            var modalityType = RandomHelper.GenerateString();
            var bodyPart     = RandomHelper.GenerateString();
            var gender       = RandomHelper.GenerateString();
            var wygText      = RandomHelper.GenerateString();
            var wysText      = RandomHelper.GenerateString();
            ReportTemplateDto newReportTemplateDto = new ReportTemplateDto
            {
                TemplateName = templateName,
                ModalityType = modalityType,
                BodyPart     = bodyPart,
                Gender       = gender,
                WYGText      = wygText,
                WYSText      = wysText
            };
            ReportTemplateDto reportTemplateDto = _reportTemplateService.CreateReportTemplate(newReportTemplateDto, _userID);

            Assert.AreNotEqual(null, reportTemplateDto);

            bool result = _reportTemplateService.DeleteTemplateByID(reportTemplateDto.UniqueID);

            Assert.AreEqual(true, result);
        }
Пример #3
0
        public IHttpActionResult IsDuplicatedTemplateName([FromBody] ReportTemplateDto reportTemplateDto)
        {
            var user   = base.CurrentUser();
            var result = _ReportTemplateService.IsDuplicatedTemplateName(reportTemplateDto, user.UniqueID);

            return(Ok(result));
        }
Пример #4
0
        public void UpdateToRisTemplate(ReportTemplateDto template)
        {
            try
            {
                var tmpdirc = new ReportTemplateDirec();
                var tmp     = new ReportTemplate();
                var dirc    = GetRisReportTemplateDircParentId(template.ModalityType, template.BodyPart);

                tmpdirc = _dbContext.Set <ReportTemplateDirec>().FirstOrDefault(t => t.TemplateID == template.UniqueID);
                if (tmpdirc == null)
                {
                    AddToRisTemplate(template);
                }
                else
                {
                    tmpdirc.ItemName = template.TemplateName;
                    tmpdirc.ParentID = dirc.UniqueID;

                    tmp = _dbContext.Set <ReportTemplate>().FirstOrDefault(t => t.UniqueID == tmpdirc.TemplateID);
                    tmp.TemplateName = template.TemplateName;
                    tmp.BodyPart     = template.BodyPart;
                    tmp.ModalityType = template.ModalityType;

                    _dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // ignored
            }
        }
Пример #5
0
        public ReportTemplateDto UpdateReportTemplate(ReportTemplateDto reportTemplateDto, string userID)
        {
            ReportTemplateDirec reportTemplateDirec = _dbContext.Set <ReportTemplateDirec>().Where(p => p.TemplateID == reportTemplateDto.UniqueID).FirstOrDefault();

            if (reportTemplateDto.IsPositive == null)
            {
                reportTemplateDto.IsPositive = 0;
            }
            if (reportTemplateDirec != null)
            {
                reportTemplateDirec.ItemName = reportTemplateDto.TemplateName;
                ReportTemplateDirec reportTemplateDirecDup = _dbContext.Set <ReportTemplateDirec>().Where(p => p.UserID == reportTemplateDirec.UserID && p.ItemName == reportTemplateDto.TemplateName).FirstOrDefault();
                if (reportTemplateDirecDup != null)
                {
                    if (reportTemplateDirecDup.UniqueID != reportTemplateDirec.UniqueID)
                    {
                        return(null);
                    }
                }

                ReportTemplate reportTemplateOld = _dbContext.Set <ReportTemplate>().Where(p => p.UniqueID == reportTemplateDto.UniqueID).FirstOrDefault();
                if (reportTemplateOld != null)
                {
                    //reportTemplateOld.TemplateName = reportTemplateDto.TemplateName;
                    //reportTemplateOld.ModalityType = reportTemplateDto.ModalityType;
                    //reportTemplateOld.BodyPart = reportTemplateDto.BodyPart;
                    //reportTemplateOld.Gender = reportTemplateDto.Gender;
                    //reportTemplateOld.WYS = ReportMapper.GetBytes(reportTemplateDto.WYSText);
                    //reportTemplateOld.WYG = ReportMapper.GetBytes(reportTemplateDto.WYGText);

                    reportTemplateOld.TemplateName = reportTemplateDto.TemplateName;
                    reportTemplateOld.ModalityType = reportTemplateDto.ModalityType;
                    reportTemplateOld.BodyPart     = reportTemplateDto.BodyPart;
                    reportTemplateOld.Gender       = reportTemplateDto.Gender;
                    reportTemplateOld.WYS          = ReportMapper.GetBytes(reportTemplateDto.WYSText == null ? "" : reportTemplateDto.WYSText);
                    reportTemplateOld.WYG          = ReportMapper.GetBytes(reportTemplateDto.WYGText == null ? "" : reportTemplateDto.WYSText);

                    reportTemplateOld.ShortcutCode  = reportTemplateDto.ShortcutCode == null ? reportTemplateOld.ShortcutCode : reportTemplateDto.ShortcutCode;
                    reportTemplateOld.ACRCode       = reportTemplateDto.ACRCode == null ? reportTemplateOld.ACRCode : reportTemplateDto.ACRCode;
                    reportTemplateOld.DoctorAdvice  = reportTemplateDto.DoctorAdvice == null ? reportTemplateOld.DoctorAdvice : reportTemplateDto.DoctorAdvice;
                    reportTemplateOld.BodyCategory  = reportTemplateDto.BodyCategory == null ? reportTemplateOld.BodyCategory : reportTemplateDto.BodyCategory;
                    reportTemplateOld.IsPositive    = reportTemplateDto.IsPositive == null ? reportTemplateOld.IsPositive : reportTemplateDto.IsPositive;
                    reportTemplateOld.CheckItemName = string.IsNullOrEmpty(reportTemplateDto.CheckItemName)? reportTemplateOld.CheckItemName: reportTemplateDto.CheckItemName;

                    _dbContext.SaveChanges();
                }
            }

            ReportTemplate reportTemplate = _dbContext.Set <ReportTemplate>().Where(p => p.UniqueID == reportTemplateDto.UniqueID).FirstOrDefault();

            if (reportTemplate != null)
            {
                return(Mapper.Map <ReportTemplate, ReportTemplateDto>(reportTemplate));
            }

            return(null);
        }
Пример #6
0
        public IHttpActionResult UpdatePublicReportTemplate([FromBody] ReportTemplateDto reportTemplateDto)
        {
            var user   = base.CurrentUser();
            var result = _ReportTemplateService.UpdatePublicReportTemplate(reportTemplateDto, user.UniqueID);

            if (result != null)
            {
                return(Ok(result));
            }
            return(NotFound());
        }
        public async Task <IActionResult> Post([FromRoute] string orgRoleId, [FromBody] ReportTemplateVM reportTemplateVM)
        {
            if (string.IsNullOrWhiteSpace(orgRoleId) || string.IsNullOrEmpty(orgRoleId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest,
                                  new BadRequestError($"'{nameof(orgRoleId)}' cannot be null or whitespace")));
            }


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            OrganizationRole organizationRole = organizationRoleService
                                                .Get <OrganizationRole>(orgRole => orgRole.Id == orgRoleId, asNoTracking: true);

            if (organizationRole == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new NotFoundError($"OrganizationRole not found")));
            }

            User user = await GetCurrentUser();

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound,
                                  new NotFoundError("Current user not found")));
            }

            ReportTemplateDto reportTemplateDto = _typeAdapter.Adapt <ReportTemplateVM, ReportTemplateDto>(reportTemplateVM);

            var reportTemplateCreationDto = new ReportTemplateCreationDto
            {
                UserId            = user.Id,
                ReportTemplateDto = reportTemplateDto
            };

            ReportTemplate reportTemplate = reportTemplateService.Add(reportTemplateCreationDto);

            _unitOfWork.SaveChanges();

            return(CreatedAtAction(
                       actionName: nameof(Get),
                       routeValues: new
            {
                version = $"{HttpContext.GetRequestedApiVersion()}",
                orgRoleId = organizationRole.Id,
                templateId = reportTemplate.Id
            },
                       value: reportTemplate.Id));
        }
Пример #8
0
        /// <summary>
        /// 创建全局模板
        /// </summary>
        /// <param name="reportTemplateDto"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public ReportTemplateDto CreatePublicReportTemplate(ReportTemplateDto reportTemplateDto, string userID)
        {
            reportTemplateDto.UniqueID = Guid.NewGuid().ToString();
            if (reportTemplateDto.IsPositive == null)
            {
                reportTemplateDto.IsPositive = 0;
            }

            ReportTemplateDirec reportTemplateDirec = _dbContext.Set <ReportTemplateDirec>().Where(p => p.UserID == userID && p.ItemName == reportTemplateDto.TemplateName).FirstOrDefault();

            if (reportTemplateDirec == null)
            {
                ReportTemplateDirec reportTemplateDirecNew = new ReportTemplateDirec();
                reportTemplateDirecNew.UniqueID      = Guid.NewGuid().ToString();
                reportTemplateDirecNew.ParentID      = reportTemplateDto.ParentID;
                reportTemplateDirecNew.TemplateID    = reportTemplateDto.UniqueID;
                reportTemplateDirecNew.UserID        = "";
                reportTemplateDirecNew.ItemName      = reportTemplateDto.TemplateName;
                reportTemplateDirecNew.Leaf          = 1;
                reportTemplateDirecNew.DirectoryType = "report";
                reportTemplateDirecNew.Domain        = reportTemplateDto.Domain;
                reportTemplateDirecNew.Type          = reportTemplateDto.Type;//0
                reportTemplateDirecNew.Depth         = -1;
                reportTemplateDirecNew.ItemOrder     = 0;

                List <ReportTemplateDirec> reportTemplateDirecList = _dbContext.Set <ReportTemplateDirec>().Where(p => p.ParentID == reportTemplateDto.ParentID).OrderByDescending(p => p.ItemOrder).ToList();
                if (reportTemplateDirecList.Count > 0)
                {
                    if (reportTemplateDirecList[0].ItemOrder.HasValue)
                    {
                        reportTemplateDirecNew.ItemOrder = reportTemplateDirecList[0].ItemOrder + 1;
                    }
                }
                var report = Mapper.Map <ReportTemplateDto, ReportTemplate>(reportTemplateDto);
                _dbContext.Set <ReportTemplate>().Add(report);
                _dbContext.Set <ReportTemplateDirec>().Add(reportTemplateDirecNew);
                _dbContext.SaveChanges();
            }
            else
            {
                return(null);
            }

            ReportTemplate reportTemplate = _dbContext.Set <ReportTemplate>().Where(p => p.UniqueID == reportTemplateDto.UniqueID).FirstOrDefault();

            if (reportTemplate != null)
            {
                return(Mapper.Map <ReportTemplate, ReportTemplateDto>(reportTemplate));
            }

            return(null);
        }
Пример #9
0
        public IHttpActionResult AddtoRisTemplate(string template)
        {
            JavaScriptSerializer sa = new JavaScriptSerializer();
            var tml = sa.Deserialize <ReportTemplateDto>(template);
            ReportTemplateDto newReportTemplateDto = new ReportTemplateDto
            {
                TemplateName = tml.TemplateName,
                ModalityType = tml.ModalityType,
                BodyPart     = tml.BodyPart
            };

            _structuredReportService.AddToRisTemplate(newReportTemplateDto);
            return(Ok(true));
        }
Пример #10
0
        public bool IsDuplicatedTemplateName(ReportTemplateDto reportTemplateDto, string userID)
        {
            ReportTemplateDirec reportTemplateDirec = _dbContext.Set <ReportTemplateDirec>().Where(p => p.UserID == userID && p.ItemName == reportTemplateDto.TemplateName).FirstOrDefault();

            if (reportTemplateDto.UniqueID == null)
            {
                reportTemplateDto.UniqueID = "";
            }
            if (reportTemplateDirec != null && reportTemplateDirec.TemplateID.ToLower() != reportTemplateDto.UniqueID.ToLower())
            {
                return(true);
            }

            return(false);
        }
Пример #11
0
        /// <summary>
        ///  Save SR report template into ris report tempalte
        /// </summary>
        /// <param name="template"></param>
        public void AddToRisTemplate(ReportTemplateDto template)
        {
            try
            {
                var tmpdirc = new ReportTemplateDirec();
                var tmp     = new ReportTemplate();
                var dirc    = GetRisReportTemplateDircParentId(template.ModalityType, template.BodyPart);

                if (dirc != null)
                {
                    _dbContext.Set <ReportTemplateDirec>().Add(tmpdirc);
                    tmpdirc.ItemName      = template.TemplateName;
                    tmpdirc.UniqueID      = Guid.NewGuid().ToString();
                    tmpdirc.ParentID      = dirc.UniqueID;
                    tmpdirc.Depth         = 0;
                    tmpdirc.ItemOrder     = GetRisReportTemplateDirecMaxOrderNumber(dirc.UniqueID) + 1;
                    tmpdirc.Leaf          = 1;
                    tmpdirc.TemplateID    = Guid.NewGuid().ToString();
                    tmpdirc.DirectoryType = "report";
                    tmpdirc.Domain        = dirc.Domain;
                    tmpdirc.Type          = 0;

                    _dbContext.Set <ReportTemplate>().Add(tmp);
                    tmp.UniqueID      = tmpdirc.TemplateID;
                    tmp.TemplateName  = template.TemplateName;
                    tmp.ModalityType  = template.ModalityType;
                    tmp.BodyPart      = template.BodyPart;
                    tmp.WYG           = new byte[0];
                    tmp.WYS           = new byte[0];
                    tmp.AppendInfo    = new byte[0];
                    tmp.TechInfo      = new byte[0];
                    tmp.CheckItemName = "";
                    tmp.BodyCategory  = "";
                    tmp.Domain        = tmpdirc.Domain;
                    tmp.Gender        = "";
                    tmp.IsPositive    = 0;

                    _dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // ignored
            }
        }
        public async Task <IActionResult> Put([FromRoute] string OrgRoleId, [FromRoute] string templateId, [FromBody] ReportTemplateVM reportTemplateVM)
        {
            if (string.IsNullOrEmpty(OrgRoleId) || string.IsNullOrWhiteSpace(OrgRoleId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest,
                                  new BadRequestError($"{nameof(OrgRoleId)} Parameter cant be null")));
            }

            if (string.IsNullOrEmpty(templateId) || string.IsNullOrWhiteSpace(templateId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest,
                                  new BadRequestError($"{nameof(templateId)} Parameter cant be null")));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            OrganizationRole organizationRole = organizationRoleService
                                                .Get <OrganizationRole>(orgRole => orgRole.Id == OrgRoleId);

            if (organizationRole == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound,
                                  new NotFoundError($"OrganizationRole not found")));
            }

            User user = await GetCurrentUser();

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new NotFoundError("current User not found")));
            }

            ReportTemplateDto reportTemplateDto = _typeAdapter.Adapt <ReportTemplateVM, ReportTemplateDto>(reportTemplateVM);

            var reportTemplateUpdateDto = new ReportTemplateUpdateDto
            {
                UserId             = user.Id,
                ReportTemplateId   = templateId,
                ReportTemplatedDto = reportTemplateDto
            };

            try
            {
                reportTemplateService.Update(reportTemplateUpdateDto);

                if (_unitOfWork.SaveChanges() < 0)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest,
                                      new BadRequestError("Error when trying to update a template")));
                }

                return(StatusCode(StatusCodes.Status200OK));
            }
            catch (InvalidOperationException ex)
            {
                return(StatusCode(StatusCodes.Status400BadRequest,
                                  new BadRequestError(ex.Message)));
            }
        }
Пример #13
0
 public CreateReportTemplate(ReportTemplateDto reportTemplate)
 => ReportTemplate = reportTemplate;
 public void Deconstruct(out string userId, out ReportTemplateDto reportTemplateDto)
 {
     userId            = UserId;
     reportTemplateDto = ReportTemplateDto;
 }