void TemplateTree_DragOver(object sender, DragEventArgs e) { Point point = TemplateTree.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(point.X, point.Y); e.Effect = DragDropEffects.Move; }
public static TemplateTree ToViewModel(this IEnumerable <Template> templates) { var result = new TemplateTree(); templates.ToList().ForEach(result.AddTemplate); return(result); }
private void TemplateTree_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { Point point = TemplateTree.PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragEnter(TemplateTree.Handle, point.X, point.Y); e.Effect = DragDropEffects.Move; }
public IActionResult Index(int id) { var list = _context.FormTemplate.Where(x => x.InstId == id).ToList(); TemplateTree tree = new TemplateTree(); tree.Id = id; tree.name = "制度1"; foreach (var cid in list.GroupBy(x => x.CtrlId).Select(x => x.Key).ToList()) { Ctrl ctrl = new Ctrl(); ctrl.Id = cid; tree.CtrlList.Add(ctrl); //检查 foreach (var checkid in list.Where(x => x.CtrlId == cid).GroupBy(x => x.CheckId).Select(x => x.Key).ToList()) { Check checkenitty = new Check(); checkenitty.Id = checkid; ctrl.CheckList.Add(checkenitty); //指标 foreach (var item in list.Where(x => x.CheckId == checkid).GroupBy(x => x.NormId).Select(x => x.Key).ToList()) { Norm nomr = new Norm { Id = item, Name = "指标" + item.ToString() }; checkenitty.NormList.Add(nomr); } } } return(View(tree)); }
private Dictionary<string, HashSet<int>> _sopInstanceUidAndFrameNumber; // if specified, annotation is created for these SOP Instances with the specified frame numbers only. The images must belong to the same series. #endregion Fields #region Constructors public AimAnnotationCreationContext(AnnotationKind annotationKind, TemplateTree.StandardCodeSequence annotationTypeCode, TemplateTree.AimTemplateTree templateTree, int seriesNumber) { Platform.CheckForNullReference(annotationTypeCode, "annotationTypeCode"); Platform.CheckForNullReference(templateTree, "templateTree"); _annotationKind = annotationKind; _annotationTypeCode = annotationTypeCode; _templateTree = templateTree; _seriesNumber = seriesNumber; _includeCalculations = true; }
private void TemplateTree_MouseUp(object sender, MouseEventArgs e) { if (Yqun.Common.ContextCache.ApplicationContext.Current.IsAdministrator) { if (e.Button == MouseButtons.Right) { Point pt = TemplateTree.PointToClient(Cursor.Position); TreeNode Node = TemplateTree.HitTest(pt).Node; TemplateTree.SelectedNode = Node; ModelContextMenu.Show(TemplateTree, pt); } } }
public bool AddTemplate(TemplateTree templateInfo) { if (templateInfo.IsTemplate) { PKS_KTEMPLATE template = new PKS_KTEMPLATE(); template.CODE = templateInfo.Code; template.ISDEFAULT = templateInfo.IsDefault; template.KTEMPLATECATEGORYID = templateInfo.TemplateCategoryId; template.NAME = templateInfo.Name; template.TEMPLATE = templateInfo.Template; if (templateInfo.Id > 0) { template.Id = templateInfo.Id; template.LASTUPDATEDDATE = DateTime.Now; _kTemplateRepository.Update(template); } else { template.CREATEDDATE = DateTime.Now; _kTemplateRepository.Add(template); } } else { PKS_KTEMPLATE_CATEGORY category = new PKS_KTEMPLATE_CATEGORY(); category.CODE = templateInfo.Code; category.SUBSYSTEMID = templateInfo.SubSystemId; category.NAME = templateInfo.Name; category.KTEMPLATEURLID = templateInfo.TemplateUrlId; category.INSTANCECLASS = templateInfo.InstanceClass; if (templateInfo.Id > 0) { category.Id = templateInfo.Id; _kTCategoryRepository.Update(category); } else { _kTCategoryRepository.Add(category); } } return(true); }
void TemplateTree_ItemDrag(object sender, ItemDragEventArgs e) { TreeNode Node = e.Item as TreeNode; Boolean IsModule = Convert.ToBoolean(Node.Tag); if (IsModule) { dragNode = e.Item as TreeNode; TemplateTree.SelectedNode = dragNode; int imageWidth = dragNode.Bounds.Size.Width + TemplateTree.Indent; imageListDrag.Images.Clear(); imageListDrag.ImageSize = new Size(imageWidth > 255 ? 255 : imageWidth, dragNode.Bounds.Height); Bitmap bmp = new Bitmap(dragNode.Bounds.Width + TemplateTree.Indent, dragNode.Bounds.Height); Graphics gfx = Graphics.FromImage(bmp); gfx.DrawImage(imageList1.Images[dragNode.ImageIndex], 0, 0); gfx.DrawString(dragNode.Text, TemplateTree.Font, new SolidBrush(TemplateTree.ForeColor), (float)TemplateTree.Indent, 1.0f); imageListDrag.Images.Add(bmp); Point p = TemplateTree.PointToClient(Control.MousePosition); int dx = p.X + TemplateTree.Indent - dragNode.Bounds.Left; int dy = p.Y - dragNode.Bounds.Top; if (DragHelper.ImageList_BeginDrag(imageListDrag.Handle, 0, dx, dy)) { TemplateTree.DoDragDrop(bmp, DragDropEffects.Move); DragHelper.ImageList_EndDrag(); } } else { return; } }
private async Task <List <TemplateTree> > LoadMenuTree(string selectedCode = null) { var temp = (await _dbContext.WorkflowTemplate. Where(x => x.IsDeleted == CommonEnum.IsDeleted.No && x.Status == CommonEnum.Status.Normal).ToListAsync()). Select(x => new TemplateTree { Code = x.Code, ParentCode = x.ParentCode, Title = x.Name }).ToList(); var root = new TemplateTree { Title = "顶级模板", Code = null, ParentCode = null }; temp.Insert(0, root); var tree = temp.BuildTree(selectedCode); return(tree); }
public ActionResult Instance(int id) { var list = _context.FormTemplate.Where(x => x.InstId == id).ToList(); TemplateTree tree = new TemplateTree(); int isid = _context.FormInstance.FirstOrDefault(x => x.InstId == id).Id; var normList = _context.FormValue.Where(x => x.InstId == isid).ToList(); tree.Id = id; tree.name = "制度1"; foreach (var cid in list.GroupBy(x => x.CtrlId).Select(x => x.Key).ToList()) { Ctrl ctrl = new Ctrl(); ctrl.Id = cid; tree.CtrlList.Add(ctrl); //检查 foreach (var checkid in list.Where(x => x.CtrlId == cid).GroupBy(x => x.CheckId).Select(x => x.Key).ToList()) { Check checkenitty = new Check(); checkenitty.Id = checkid; ctrl.CheckList.Add(checkenitty); //指标 foreach (var item in list.Where(x => x.CheckId == checkid).Select(x => x.NormId).ToList()) { var formValue = normList.FirstOrDefault(x => x.NormId == item); string name = formValue == null ? "" : formValue.ValueString; Norm nomr = new Norm { Id = item, Name = name }; checkenitty.NormList.Add(nomr); } } } return(View(tree)); }
public static bool AimDotNetScaleEqualsTemplateTreeScaleLevel(aim4_dotnet.Scale a, TemplateTree.ScaleLevel b) { return a.Value == b.Value; }
public static bool AimDotNetNonQuantifiableEqualsTemplateTreeNonQuantifiable(aim4_dotnet.NonQuantifiable a, TemplateTree.StandardCodedTerm b) { return a.TypeCode != null && String.Equals(a.TypeCode.CodeValue, b.CodeValue) && String.Equals(a.TypeCode.CodeMeaning, b.CodeMeaning) && String.Equals(a.TypeCode.CodingSchemeDesignator, b.CodingSchemeDesignator) && StringEquals(a.TypeCode.CodingSchemeVersion, b.CodingSchemeVersion); }
private static List<aim4_dotnet.iso_21090.CD> ToNativeCodeList(TemplateTree.StandardCodeSequence standardCodeSequence) { if (standardCodeSequence == null) return null; var codeList = new List<aim4_dotnet.iso_21090.CD> { new aim4_dotnet.iso_21090.CD { CodeMeaning = standardCodeSequence.CodeMeaning, CodeValue = standardCodeSequence.CodeValue, CodingSchemeDesignator = standardCodeSequence.CodingSchemeDesignator, CodingSchemeVersion = standardCodeSequence.CodingSchemeVersion } }; return codeList; }
private static aim4_dotnet.iso_21090.CD ToNativeCode(TemplateTree.StandardCodeSequence standardCodeSequence) { if (standardCodeSequence == null) return null; return new aim4_dotnet.iso_21090.CD { CodeMeaning = standardCodeSequence.CodeMeaning, CodeValue = standardCodeSequence.CodeValue, CodingSchemeDesignator = standardCodeSequence.CodingSchemeDesignator, CodingSchemeVersion = standardCodeSequence.CodingSchemeVersion }; }
/// <summary> /// Determines whether there is a path in the standardValidTerm tree that matches the given codeList /// </summary> /// <param name="standardValidTerm">Tempalate's StandardValidTerm to compare</param> /// <param name="codeList">code array to compare</param> /// <returns><code>true</code> if <paramref name="codeList"/> is a complete match to a path in the <paramref name="standardValidTerm"/>; false - if does not match</returns> private static bool DoTheyMatch(TemplateTree.StandardValidTerm standardValidTerm, List<aim4_dotnet.iso_21090.CD> codeList) { if (standardValidTerm == null) return codeList.IsNullOrEmpty(); if (codeList.IsNullOrEmpty()) return false; if (DoTheyMatch(standardValidTerm.StandardCodeSequence, codeList[0])) { if (standardValidTerm.StandardValidTerms.IsNullOrEmpty()) return codeList.Count == 1; if (codeList.Count == 1) return false; // Recursively check whether a child StandardValidTerm matches the rest of the codes in the list var reducedCodeList = codeList.GetRange(1, codeList.Count - 1); return standardValidTerm.StandardValidTerms.Any(validTerm => DoTheyMatch(validTerm, reducedCodeList)); } return false; }
public bool SaveTemplate(TemplateTree templateTree, List <FragmentModel> fragmentModels, List <CatalogueInfo> catalogueInfos) { //模板 int templateId = templateTree.Id; var kTemplate = _kTemplateRepository.GetQuery().FirstOrDefault(item => item.Id == templateId); if (kTemplate == null) { throw new Exception("模板不存在"); } _kTemplateRepository.BeginTrans(); kTemplate.TEMPLATE = templateTree.Template; kTemplate.LASTUPDATEDDATE = DateTime.Now; _kTemplateRepository.Update(kTemplate, false); //知识片段 var db_fragments = _kFragmentRepository.GetQuery() .Where(item => item.KTEMPLATEID == templateId) .ToList(); foreach (var item in db_fragments) { _kFragmentRepository.Delete(item, false); } List <PKS_KFRAGMENT> toAddFragments = new List <PKS_KFRAGMENT>(); foreach (var fragmentModel in fragmentModels) { PKS_KFRAGMENT fragment = new PKS_KFRAGMENT(); fragment.KTEMPLATEID = templateId; fragment.TITLE = fragmentModel.Title; fragment.QUERYPARAMETER = fragmentModel.QueryParameter; fragment.COMPONENTPARAMETER = fragmentModel.ComponentParameter; fragment.HTMLTEXT = fragmentModel.Htmltext; fragment.KFRAGMENTTYPEID = fragmentModel.FragmentTypeId; fragment.PLACEHOLDERID = fragmentModel.PlaceholderId; fragment.CREATEDDATE = DateTime.Now; toAddFragments.Add(fragment); } if (toAddFragments.Any()) { _kFragmentRepository.AddRange(toAddFragments, false); } //目录 var db_catalogues = _kTCatalogueRepository.GetQuery() .Where(item => item.KTEMPLATEID == templateId) .ToList(); db_catalogues.ForEach(item => { _kTCatalogueRepository.Delete(item, false); }); List <PKS_KTEMPLATE_CATALOGUE> rootCatalogues = new List <PKS_KTEMPLATE_CATALOGUE>(); var rootCatalogueInfos = catalogueInfos.Where(item => string.IsNullOrWhiteSpace(item.ParentNodeId) || item.ParentNodeId == "0"); foreach (var catalogueInfo in rootCatalogueInfos) { PKS_KTEMPLATE_CATALOGUE catalogue = new PKS_KTEMPLATE_CATALOGUE(); catalogue.Id = 0; catalogue.CODE = catalogueInfo.Code; catalogue.NAME = catalogueInfo.Name; catalogue.LEVELNUMBER = catalogueInfo.LevelNumber; catalogue.ORDERNUMBER = catalogueInfo.OrderNumber; catalogue.KTEMPLATEID = catalogueInfo.TemplateId; catalogue.PLACEHOLDERID = catalogueInfo.PlaceHolderId; catalogue.CREATEDDATE = DateTime.Now; catalogueInfo.Catalogue = catalogue; BuildChildCatalogue(catalogue, catalogueInfo, catalogueInfos); rootCatalogues.Add(catalogue); } if (rootCatalogues.Any()) { _kTCatalogueRepository.AddRange(rootCatalogues, false); } //SaveCatalogues2(templateId, catalogueInfos); _kTemplateRepository.Submit(); _kTemplateRepository.EndTrans(); //更新知识片段的CatalogueId foreach (var fragment in toAddFragments) { var placeHolderId = fragment.PLACEHOLDERID; var catalogueInfo = catalogueInfos.Where(item => item.Catalogue != null && item.PlaceHolderId == placeHolderId).FirstOrDefault(); if (catalogueInfo != null) { fragment.KTEMPLATECATALOGUEID = catalogueInfo.Catalogue.Id; fragment.MPLACEHOLDERID = placeHolderId; _kFragmentRepository.Update(fragment); } else { var fragmentModel = fragmentModels.FirstOrDefault(item => item.PlaceholderId == placeHolderId); if (fragmentModel != null) { var catalogNodeId = fragmentModel.CatalogueNodeId; if (!string.IsNullOrWhiteSpace(catalogNodeId)) { var cat = catalogueInfos.FirstOrDefault(item => string.Equals(item.PlaceHolderId, catalogNodeId, StringComparison.OrdinalIgnoreCase)); fragment.KTEMPLATECATALOGUEID = cat.Catalogue.Id; fragment.MPLACEHOLDERID = catalogNodeId; _kFragmentRepository.Update(fragment); } } } } return(true); }
public static aim_dotnet.ImagingObservation ToImagingObservation(TemplateTree.StandardCodeSequence codeSequence, string label) { return codeSequence == null ? null : new aim_dotnet.ImagingObservation { CodeValue = codeSequence.CodeValue, CodeMeaning = codeSequence.CodeMeaning, CodingSchemeDesignator = codeSequence.CodingSchemeDesignator, CodingSchemeVersion = codeSequence.CodingSchemeVersion, Label = label }; }
public static aim_dotnet.Inference ToInference(TemplateTree.StandardCodeSequence codeSequence) { return codeSequence == null ? null : new aim_dotnet.Inference { CodeValue = codeSequence.CodeValue, CodeMeaning = codeSequence.CodeMeaning, CodingSchemeDesignator = codeSequence.CodingSchemeDesignator, CodingSchemeVersion = codeSequence.CodingSchemeVersion }; }
public static aim_dotnet.AnatomicEntity ToAnatomicEntity(TemplateTree.StandardCodeSequence codeSequence, string label) { return codeSequence == null ? null : new aim_dotnet.AnatomicEntity { CodeValue = codeSequence.CodeValue, CodeMeaning = codeSequence.CodeMeaning, CodingSchemeDesignator = codeSequence.CodingSchemeDesignator, CodingSchemeVersion = codeSequence.CodingSchemeVersion, Label = label }; }
public static List<aim_dotnet.ICharacteristicQuantification> ToCharacteristicQuantifications( TemplateTree.CharacteristicQuantificationAllowedTerm allowedTerm) { var selectedQuantifications = new List<aim_dotnet.ICharacteristicQuantification>(); foreach (var characteristicQuantification in allowedTerm.CharacteristicQuantifications) { double? confidence = null; if (characteristicQuantification.HasConfidence) confidence = characteristicQuantification.ConfidenceValue; // NonQuantifiable if (characteristicQuantification.SelectedNonQuantifiable != null) { var codeSequence = characteristicQuantification.SelectedNonQuantifiable; selectedQuantifications.Add( new aim_dotnet.NonQuantifiable { Name = characteristicQuantification.Name, CodeValue = codeSequence.CodeValue, CodeMeaning = codeSequence.CodeMeaning, CodingSchemeDesignator = codeSequence.CodingSchemeDesignator, CodingSchemeVersion = codeSequence.CodingSchemeVersion, AnnotatorConfidence = confidence } ); } else { if (characteristicQuantification is TemplateTree.AimTemplateTreeNumericalQuantification) { var numericalQuantification = (TemplateTree.AimTemplateTreeNumericalQuantification)characteristicQuantification; if (numericalQuantification.SelectedNumerical != null) selectedQuantifications.Add( new aim_dotnet.Numerical { Name = characteristicQuantification.Name, Value = numericalQuantification.SelectedNumerical.Value.Value, Operator = ToAimComparisonOperator( numericalQuantification.SelectedNumerical.Value.Operator), UcumString = numericalQuantification.SelectedNumerical.Value.UcumString, AnnotatorConfidence = confidence }); } if (characteristicQuantification is TemplateTree.AimTemplateTreeQuantileQuantification) { var quantileQuantification = (TemplateTree.AimTemplateTreeQuantileQuantification)characteristicQuantification; if (quantileQuantification.SelectedBin != null) selectedQuantifications.Add( new aim_dotnet.Quantile { Name = characteristicQuantification.Name, Bin = quantileQuantification.SelectedBin.Value, AnnotatorConfidence = confidence }); } if (characteristicQuantification is TemplateTree.AimTemplateTreeScaleQuantification) { var scaleQuantification = (TemplateTree.AimTemplateTreeScaleQuantification) characteristicQuantification; if (scaleQuantification.SelectedScaleLevel != null) selectedQuantifications.Add( new aim_dotnet.Scale { Name = characteristicQuantification.Name, Value = scaleQuantification.SelectedScaleLevel.Value.Value, Description = scaleQuantification.SelectedScaleLevel.Value.ValueDescription, Comment = scaleQuantification.SelectedScaleLevel.Value.ValueLabel, AnnotatorConfidence = confidence }); } if (characteristicQuantification is TemplateTree.AimTemplateTreeIntervalQuantification) { var intervalQuantification = (TemplateTree.AimTemplateTreeIntervalQuantification) characteristicQuantification; if (intervalQuantification.SelectedInterval != null) selectedQuantifications.Add( new aim_dotnet.Interval { Name = characteristicQuantification.Name, MinValue = intervalQuantification.SelectedInterval.Value.MinValue, MaxValue = intervalQuantification.SelectedInterval.Value.MaxValue, MinOperator = ToAimComparisonOperator( intervalQuantification.SelectedInterval.Value.MinOperator), MaxOperator = ToAimComparisonOperator( intervalQuantification.SelectedInterval.Value.MaxOperator), UcumString = intervalQuantification.SelectedInterval.Value.UcumString, AnnotatorConfidence = confidence }); } } } return selectedQuantifications; }
public static aim_dotnet.ComparisonOperatorIdentifier ToAimComparisonOperator(TemplateTree.ComparisonOperator comparisonOperator) { var aimOperator = aim_dotnet.ComparisonOperatorIdentifier.None; switch (comparisonOperator) { case TemplateTree.ComparisonOperator.Equal: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.Equal; break; case TemplateTree.ComparisonOperator.GreaterThan: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.GreaterThan; break; case TemplateTree.ComparisonOperator.GreaterThanEqual: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.GreaterThanEqual; break; case TemplateTree.ComparisonOperator.LessThan: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.LessThan; break; case TemplateTree.ComparisonOperator.LessThanEqual: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.LessThanEqual; break; case TemplateTree.ComparisonOperator.NotEqual: aimOperator = aim_dotnet.ComparisonOperatorIdentifier.NotEqual; break; } return aimOperator; }
public static Dictionary<int, List<aim_dotnet.ImagingObservationCharacteristic>> SelectedImagingObservationCharacteristicsDictionary(TemplateTree.AimTemplateTreeImagingObservationNode imagingObservation) { return imagingObservation.SelectedImagingObservationCharacteristicTreeNodes.ToDictionary(ioc => ioc.ItemNumber, ioc => new List<aim_dotnet.ImagingObservationCharacteristic>(SelectedImagingObservationCharacteristics(ioc))); }
public static TemplateTree.AimTemplateTree AimAnnotationToAimTemplateTree(Aim3AnnotationInstance annotationInstance, TemplateTree.AimTemplateTree template) { if (annotationInstance == null || annotationInstance.AimAnnotation == null) return null; var annotation = annotationInstance.AimAnnotation; if (annotation.AnatomyEntityCollection != null) { foreach (var ae in annotation.AnatomyEntityCollection) { if (IsNullCodeSequence(ToStandardCodeSequence(ae))) continue; TemplateTree.AimTemplateTreeAnatomicEntityNode matchingTreeNode = template.TemplateNodes.OfType<TemplateTree.AimTemplateTreeAnatomicEntityNode>().FirstOrDefault(treeAe => treeAe.Label == ae.Label); if (matchingTreeNode != null) { TemplateTree.AimTemplateTreeAllowedTerm matchingAllowedTerm = matchingTreeNode.AllowedTerms.FirstOrDefault(treeAe => ToStandardCodeSequence(treeAe).CodeValue == ae.CodeValue); if (matchingAllowedTerm != null) { matchingAllowedTerm.Selected = true; } else return null; if (matchingTreeNode.HasConfidence && ae.AnnotatorConfidence.HasValue) matchingTreeNode.ConfidenceValue = ae.AnnotatorConfidence.Value; } else return null; if (ae.AnatomicEntityCharacteristicCollection != null) { foreach (var aec in ae.AnatomicEntityCharacteristicCollection) { if (IsNullCodeSequence(ToStandardCodeSequence(aec))) continue; TemplateTree.AimTemplateTreeAnatomicEntityCharacteristicNode matchingAecTreeNode = matchingTreeNode.AnatomicEntityCharacteristicTreeNodes.FirstOrDefault(treeAec => treeAec.Label == aec.Label); if (matchingAecTreeNode != null) { TemplateTree.CharacteristicQuantificationAllowedTerm matchingAllowedTerm = matchingAecTreeNode.CharacteristicQuantificationAllowedTerms.FirstOrDefault(treeAec => ToStandardCodeSequence(treeAec).CodeValue == aec.CodeValue); if (matchingAllowedTerm != null) { matchingAllowedTerm.Selected = true; foreach (var quantification in matchingAllowedTerm.CharacteristicQuantifications) { if (ReadBackCharacteristicQuantificationFromAnnotation(aec.CharacteristicQuantificationCollection, quantification) == null) return null; } } else return null; if (matchingAecTreeNode.HasConfidence && aec.AnnotatorConfidence.HasValue) matchingAecTreeNode.ConfidenceValue = aec.AnnotatorConfidence.Value; } else return null; } } } } if (annotation.ImagingObservationCollection != null) { foreach (var io in annotation.ImagingObservationCollection) { if (IsNullCodeSequence(ToStandardCodeSequence(io))) continue; TemplateTree.AimTemplateTreeImagingObservationNode matchingTreeNode = template.TemplateNodes.OfType<TemplateTree.AimTemplateTreeImagingObservationNode>().FirstOrDefault( treeIo => treeIo.Label == io.Label); if (matchingTreeNode != null) { TemplateTree.AimTemplateTreeAllowedTerm matchingAllowedTerm = matchingTreeNode.AllowedTerms.FirstOrDefault( treeIo => ToStandardCodeSequence(treeIo).CodeValue == io.CodeValue); if (matchingAllowedTerm != null) { matchingAllowedTerm.Selected = true; } else return null; if (matchingTreeNode.HasConfidence && io.AnnotatorConfidence.HasValue) matchingTreeNode.ConfidenceValue = io.AnnotatorConfidence.Value; } else return null; if (io.ImagingObservationCharacteristicCollection != null) { foreach (var ioc in io.ImagingObservationCharacteristicCollection) { if (IsNullCodeSequence(ToStandardCodeSequence(ioc))) continue; TemplateTree.AimTemplateTreeImagingObservationCharacteristicNode matchingIocTreeNode = matchingTreeNode.ImagingObservationCharacteristicTreeNodes.FirstOrDefault( treeIoc => treeIoc.Label == ioc.Label); if (matchingIocTreeNode != null) { TemplateTree.CharacteristicQuantificationAllowedTerm matchingAllowedTerm = matchingIocTreeNode.CharacteristicQuantificationAllowedTerms.FirstOrDefault( treeIoc => ToStandardCodeSequence(treeIoc).CodeValue == ioc.CodeValue); if (matchingAllowedTerm != null) { matchingAllowedTerm.Selected = true; foreach (var quantification in matchingAllowedTerm.CharacteristicQuantifications) { if (ReadBackCharacteristicQuantificationFromAnnotation(ioc.CharacteristicQuantificationCollection, quantification) == null) return null; } } else return null; if (matchingIocTreeNode.HasConfidence && ioc.AnnotatorConfidence.HasValue) matchingIocTreeNode.ConfidenceValue = ioc.AnnotatorConfidence.Value; } else return null; } } } } if (annotation.CalculationCollection != null) { //foreach (var calc in annotation.CalculationCollection) //{ // AimTemplateTreeCalculationNode matchingTreeNode = // template.TemplateNodes.OfType<AimTemplateTreeCalculationNode>().FirstOrDefault( // treeCalc => treeCalc.Label == calc.Description); // if (matchingTreeNode != null) // { // AimTemplateTreeCalculationType matchingCalculationType = // matchingTreeNode.CalculationTypes.FirstOrDefault( // treeCalc => ToStandardCodeSequence(treeCalc).CodeValue == calc.CodeValue); // if (matchingCalculationType != null) // { // matchingTreeNode.SelectedCalculationType = matchingCalculationType; // } // else // return null; // //if (matchingTreeNode.HasConfidence && calc..HasValue) // // matchingTreeNode.ConfidenceValue = calc.AnnotatorConfidence.Value; // } // else // return null; //} } if (annotation.InferenceCollection != null) { foreach (var inference in annotation.InferenceCollection) { if (IsNullCodeSequence(ToStandardCodeSequence(inference))) continue; foreach (var inferenceNode in template.TemplateNodes.OfType<TemplateTree.AimTemplateTreeInferenceNode>()) { TemplateTree.AimTemplateTreeAllowedTerm matchingAllowedTerm = inferenceNode.AllowedTerms.FirstOrDefault( term => ToStandardCodeSequence(term).CodeValue == inference.CodeValue); if (matchingAllowedTerm != null) matchingAllowedTerm.Selected = true; } } } template.Markup.Clear(); if (annotation is aim_dotnet.ImageAnnotation) { var imageAnnotation = (aim_dotnet.ImageAnnotation)annotation; var annotationName = string.IsNullOrEmpty(imageAnnotation.Name) ? "" : imageAnnotation.Name; if (imageAnnotation.GeometricShapeCollection != null) { foreach (var geometricShape in imageAnnotation.GeometricShapeCollection) { var markup = ToMarkup(geometricShape, annotationName); if (markup != null) template.Markup.Add(markup); } } if (imageAnnotation.TextAnnotationCollection != null) { foreach (var textAnnotation in imageAnnotation.TextAnnotationCollection) { if (textAnnotation.ConnectorPoints != null && textAnnotation.ConnectorPoints.SpatialCoordinateCollection != null) { var calloutText = AimHelpers.FormatPointCalloutText(annotationName, textAnnotation.Text); switch (textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count) { case 1: { var markup = new TemplateTree.MarkupPoint(); markup.Name = annotationName; markup.IncludeInAnnotation = textAnnotation.ConnectorPoints.IsIncludeFlag; markup.Point = AimNativeConverter.AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); markup.CalloutText = calloutText; markup.CalloutLocation = new PointF(markup.Point.X, markup.Point.Y); SetMarkupImageReference(markup, textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); markup.UseCrosshair = AimSettings.Default.UseCrosshairsForTextCallouts; template.Markup.Add(markup); } break; case 2: { var markup = new TemplateTree.MarkupPoint(); markup.Name = annotationName; markup.IncludeInAnnotation = textAnnotation.ConnectorPoints.IsIncludeFlag; markup.Point = AimNativeConverter.AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); markup.CalloutText = calloutText; markup.CalloutLocation = AimNativeConverter.AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[1]); SetMarkupImageReference(markup, textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); markup.UseCrosshair = AimSettings.Default.UseCrosshairsForTextCallouts; template.Markup.Add(markup); } break; default: Platform.Log(LogLevel.Error, "TextAnnotation has [{0}] Connector Points", textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count); break; } } } } } return template; }
public static List<aim_dotnet.ImagingObservationCharacteristic> SelectedImagingObservationCharacteristics(TemplateTree.AimTemplateTreeImagingObservationCharacteristicNode node) { var imagingObservationCharacteristics = new List<aim_dotnet.ImagingObservationCharacteristic>(); var selectedCharacteristicQuantifications = new Dictionary<TemplateTree.StandardValidTerm, List<aim_dotnet.ICharacteristicQuantification>>(); foreach (TemplateTree.CharacteristicQuantificationAllowedTerm term in node.SelectedCharacteristicQuantificationAllowedTerms) { bool valid = true; foreach (var quantification in term.CharacteristicQuantifications) if (!quantification.Valid) valid = false; if (valid) selectedCharacteristicQuantifications.Add(term, ToCharacteristicQuantifications(term)); } if (selectedCharacteristicQuantifications.Count > 0) { foreach (var selectedCharacteristicQuantification in selectedCharacteristicQuantifications) { double? confidence = null; if (node.HasConfidence) confidence = node.ConfidenceValue; var characteristicCode = ToStandardCodeSequence(selectedCharacteristicQuantification.Key); imagingObservationCharacteristics.Add( new aim_dotnet.ImagingObservationCharacteristic { CodeValue = characteristicCode.CodeValue, CodeMeaning = characteristicCode.CodeMeaning, CodingSchemeDesignator = characteristicCode.CodingSchemeDesignator, CodingSchemeVersion = characteristicCode.CodingSchemeVersion, Label = node.Label, AnnotatorConfidence = confidence, CharacteristicQuantificationCollection = selectedCharacteristicQuantification.Value }); } } else { if (node.SelectedCharacteristicQuantificationAllowedTerms == null || node.SelectedCharacteristicQuantificationAllowedTerms.Count == 0) { // Provide default NULL answer when answers are optional if (node.MinCardinality == 0) { imagingObservationCharacteristics.Add( new aim_dotnet.ImagingObservationCharacteristic { CodeValue = AimAnnotationComponent.NullCodeValue.CodeValue, CodeMeaning = AimAnnotationComponent.NullCodeValue.CodeMeaning, CodingSchemeDesignator = AimAnnotationComponent.NullCodeValue.CodingSchemeDesignator, CodingSchemeVersion = AimAnnotationComponent.NullCodeValue.CodingSchemeVersion, Label = node.Label }); } } else { foreach (var validTerm in node.SelectedCharacteristicQuantificationAllowedTerms) { double? confidence = null; if (node.HasConfidence) confidence = node.ConfidenceValue; var codeSequence = ToStandardCodeSequence(validTerm); imagingObservationCharacteristics.Add( new aim_dotnet.ImagingObservationCharacteristic { CodeValue = codeSequence.CodeValue, CodeMeaning = codeSequence.CodeMeaning, CodingSchemeDesignator = codeSequence.CodingSchemeDesignator, CodingSchemeVersion = codeSequence.CodingSchemeVersion, Label = node.Label, AnnotatorConfidence = confidence }); } } } return imagingObservationCharacteristics; }
public static List<aim_dotnet.AnatomicEntity> ToSelectedAnatomicEntitiesList(TemplateTree.AimTemplateTreeAnatomicEntityNode node) { var selectedAnatomicEntities = new List<aim_dotnet.AnatomicEntity>(); bool isValid = node.Valid; foreach (var term in node.SelectedAllowedTerms) { string label = node.Label; if (node.QuestionType != null) label = node.QuestionType.StandardCodeSequence.CodeMeaning; var anatomicEntity = ToAnatomicEntity(ToStandardCodeSequence(term), label); if (node.HasConfidence) { anatomicEntity.AnnotatorConfidence = node.ConfidenceValue; } //node var selectedAnatomicEntityCharacteristics = SelectedAnatomicEntityCharacteristicsDictionary(node); // Sort characteristics first according to their ItemNumber List<int> anatomicEntityCharacteristicIndices = CollectionUtils.Sort(selectedAnatomicEntityCharacteristics.Keys, (i1, i2) => i1.CompareTo(i2)); foreach (int characteristicIndex in anatomicEntityCharacteristicIndices) { // Find definition of the selected characteristic in the component int index = characteristicIndex; TemplateTree.AimTemplateTreeAnatomicEntityCharacteristicNode templateAnatomicEntityCharacteristic = CollectionUtils.SelectFirst(node.AnatomicEntityCharacteristicTreeNodes, item => item.ItemNumber == index); isValid = templateAnatomicEntityCharacteristic != null && selectedAnatomicEntityCharacteristics[characteristicIndex].Count >= Math.Min(templateAnatomicEntityCharacteristic.CharacteristicQuantificationAllowedTerms.Count, templateAnatomicEntityCharacteristic.MinCardinality) && selectedAnatomicEntityCharacteristics[characteristicIndex].Count <= templateAnatomicEntityCharacteristic.MaxCardinality; if (!isValid) break; // Put all Anatomic Entity Characteristics into a single collection anatomicEntity.AnatomicEntityCharacteristicCollection = CollectionUtils.Concat<aim_dotnet.AnatomicEntityCharacteristic>( anatomicEntity.AnatomicEntityCharacteristicCollection ?? new List<aim_dotnet.AnatomicEntityCharacteristic>(), selectedAnatomicEntityCharacteristics[characteristicIndex] ); } if (!isValid) break; selectedAnatomicEntities.Add(anatomicEntity); } return selectedAnatomicEntities; }
/// <summary> /// Recursevely traverses given <paramref name="validTerm"/> and appends Code Meanings to the given <paramref name="sb"/>. /// This effectively flattens <paramref name="validTerm"/> to a string. /// </summary> /// <param name="validTerm">Standard Valid Term to traverse</param> /// <param name="sb">String Builder taht receives the values</param> public static StringBuilder ToStringBuilder(TemplateTree.StandardValidTerm validTerm, StringBuilder sb) { if (validTerm == null || sb == null) return sb; if (sb.Length > 0) sb.Append(" "); sb.Append(validTerm.StandardCodeSequence.CodeMeaning); // Traverse the tree in-order foreach (TemplateTree.StandardValidTerm standardValidTerm in validTerm.StandardValidTerms) ToStringBuilder(standardValidTerm, sb); return sb; }
private void ContextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { TemplateTree.Update(); }
public static List<aim_dotnet.Inference> ToSelectedInferencesList(TemplateTree.AimTemplateTreeInferenceNode node) { var inferences = new List<aim_dotnet.Inference>(); bool isValid = node.Valid; double? confidence = null; if (node.HasConfidence) confidence = node.ConfidenceValue; foreach (var term in node.SelectedAllowedTerms) { var standardCodeSequence = ToStandardCodeSequence(term); inferences.Add( new aim_dotnet.Inference() { AnnotatorConfidence = confidence, CodeMeaning = standardCodeSequence.CodeMeaning, CodeValue = standardCodeSequence.CodeValue, CodingSchemeDesignator = standardCodeSequence.CodingSchemeDesignator, CodingSchemeVersion = standardCodeSequence.CodingSchemeVersion }); } foreach (var inference in inferences) inference.ImageEvidence = true; return inferences; }
/// <summary> /// Matches an AimTempalteTreeCharacteristicQuantification from to a characteristic quantification from aim_dotnet.annotation /// ICharacteristicQuantification collection /// </summary> /// <param name="annotationCharacteristicQuantifications"></param> /// <param name="templateTreeCharacteristicQuantification"></param> /// <returns></returns> public static TemplateTree.AimTemplateTreeCharacteristicQuantification ReadBackCharacteristicQuantificationFromAnnotation(List<aim_dotnet.ICharacteristicQuantification> annotationCharacteristicQuantifications, TemplateTree.AimTemplateTreeCharacteristicQuantification templateTreeCharacteristicQuantification) { if (annotationCharacteristicQuantifications != null && annotationCharacteristicQuantifications.Count > 0) { aim_dotnet.NonQuantifiable nonQuantifiable = annotationCharacteristicQuantifications.OfType <aim_dotnet.NonQuantifiable>().FirstOrDefault(); if (nonQuantifiable != null) { TemplateTree.StandardCodedTerm matchingNonQuantifiable = templateTreeCharacteristicQuantification.NonQuantifiables.FirstOrDefault( nonQuant => AimDotNetNonQuantifiableEqualsTemplateTreeNonQuantifiable( nonQuantifiable, nonQuant)); if (matchingNonQuantifiable != null) templateTreeCharacteristicQuantification.SelectedNonQuantifiable = matchingNonQuantifiable; } else { if (templateTreeCharacteristicQuantification is TemplateTree.AimTemplateTreeScaleQuantification) { var scaleQuantification = templateTreeCharacteristicQuantification as TemplateTree.AimTemplateTreeScaleQuantification; aim_dotnet.Scale matchingScale = annotationCharacteristicQuantifications.OfType <aim_dotnet.Scale>() .FirstOrDefault(); if (matchingScale != null) { TemplateTree.ScaleLevel matchingTreeScaleLevel = scaleQuantification.Scale.ScaleLevels.FirstOrDefault( scaleLevel => AimDotNetScaleEqualsTemplateTreeScaleLevel( matchingScale, scaleLevel)); scaleQuantification.SelectedScaleLevel = matchingTreeScaleLevel; } else return null; } if (templateTreeCharacteristicQuantification is TemplateTree.AimTemplateTreeQuantileQuantification) { var quantileQuantification = templateTreeCharacteristicQuantification as TemplateTree.AimTemplateTreeQuantileQuantification; var quantile = annotationCharacteristicQuantifications.OfType <aim_dotnet.Quantile>().FirstOrDefault(); if (quantile != null) quantileQuantification.SelectedBin = quantile.Bin; else return null; } if (templateTreeCharacteristicQuantification is TemplateTree.AimTemplateTreeIntervalQuantification) { var intervalQuantification = templateTreeCharacteristicQuantification as TemplateTree.AimTemplateTreeIntervalQuantification; aim_dotnet.Interval matchingInterval = annotationCharacteristicQuantifications.OfType <aim_dotnet.Interval>(). FirstOrDefault(); if (matchingInterval != null) { TemplateTree.Interval matchingTreeInterval = intervalQuantification.Intervals.FirstOrDefault( interval => AimDotNetIntervalEqualsTemplateTreeInterval( matchingInterval, interval)); intervalQuantification.SelectedInterval = matchingTreeInterval; } else return null; } if (templateTreeCharacteristicQuantification is TemplateTree.AimTemplateTreeNumericalQuantification) { var numericalQuantification = templateTreeCharacteristicQuantification as TemplateTree.AimTemplateTreeNumericalQuantification; aim_dotnet.Numerical matchingNumerical = annotationCharacteristicQuantifications.OfType <aim_dotnet.Numerical>(). FirstOrDefault(); if (matchingNumerical != null) { TemplateTree.Numerical matchingTreeNumerical = numericalQuantification.Numericals.FirstOrDefault( numerical => AimDotNetNumericalEqualsTemplateTreeNumerical( matchingNumerical, numerical)); numericalQuantification.SelectedNumerical = matchingTreeNumerical; } else return null; } } } return templateTreeCharacteristicQuantification; }
/// <summary> /// Recursively flattens a hierarchy of valid terms into a single StandardCodeSequence /// by concatenating the codeValue and codeMeaning fields. /// </summary> /// <param name="standardValidTerm"></param> /// <returns></returns> private static TemplateTree.StandardCodeSequence CollapseStandardValidTerm(TemplateTree.StandardValidTerm standardValidTerm) { string codeValue = standardValidTerm.StandardCodeSequence.CodeValue; string codingSchemeDesignator = standardValidTerm.StandardCodeSequence.CodingSchemeDesignator; string codingSchemeVersion = standardValidTerm.StandardCodeSequence.CodingSchemeVersion; string codeMeaning = standardValidTerm.StandardCodeSequence.CodeMeaning; const string delimiter = ", "; if (standardValidTerm.StandardValidTerms.Count > 0) codingSchemeDesignator = COLLAPSED_VALID_TERM_CODING_SCHEME_DESIGNATOR; foreach (TemplateTree.StandardValidTerm childStandardValidTerm in standardValidTerm.StandardValidTerms) { TemplateTree.StandardCodeSequence standardCodeSequence = CollapseStandardValidTerm(childStandardValidTerm); if (!string.IsNullOrEmpty(standardCodeSequence.CodeValue)) codeValue += delimiter + standardCodeSequence.CodeValue; if (!string.IsNullOrEmpty(standardCodeSequence.CodeMeaning)) codeMeaning += delimiter + standardCodeSequence.CodeMeaning; } return new TemplateTree.StandardCodeSequence(codeValue, codeMeaning, codingSchemeDesignator, codingSchemeVersion); }
public static List<aim_dotnet.ImagingObservation> ToSelectedImagingObservationList(TemplateTree.AimTemplateTreeImagingObservationNode node) { var imagingObservations = new List<aim_dotnet.ImagingObservation>(); bool isValid = node.Valid; foreach (var term in node.SelectedAllowedTerms) { var imagingObservation = ToImagingObservation(ToStandardCodeSequence(term), node.Label); if (node.HasConfidence) { imagingObservation.AnnotatorConfidence = node.ConfidenceValue; } //node var selectedImagingObservationCharacteristics = SelectedImagingObservationCharacteristicsDictionary(node); // Sort characteristics first according to their ItemNumber List<int> imagingObservationCharacteristicIndices = CollectionUtils.Sort(selectedImagingObservationCharacteristics.Keys, (i1, i2) => i1.CompareTo(i2)); foreach (int characteristicIndex in imagingObservationCharacteristicIndices) { // Find definition of the selected characteristic in the component int index = characteristicIndex; TemplateTree.AimTemplateTreeImagingObservationCharacteristicNode templateImagingObservationCharacteristic = CollectionUtils.SelectFirst(node.ImagingObservationCharacteristicTreeNodes, item => item.ItemNumber == index); isValid = templateImagingObservationCharacteristic != null && selectedImagingObservationCharacteristics[characteristicIndex].Count >= Math.Min(templateImagingObservationCharacteristic.CharacteristicQuantificationAllowedTerms.Count, templateImagingObservationCharacteristic.MinCardinality) && selectedImagingObservationCharacteristics[characteristicIndex].Count <= templateImagingObservationCharacteristic.MaxCardinality; if (!isValid) break; // Put all Anatomic Entity Characteristics into a single collection imagingObservation.ImagingObservationCharacteristicCollection = CollectionUtils.Concat<aim_dotnet.ImagingObservationCharacteristic>( imagingObservation.ImagingObservationCharacteristicCollection ?? new List<aim_dotnet.ImagingObservationCharacteristic>(), selectedImagingObservationCharacteristics[characteristicIndex] ); } if (!isValid) break; imagingObservations.Add(imagingObservation); } return imagingObservations; }
private static bool DoTheyMatch(TemplateTree.StandardCodeSequence standardCodeSequence, aim4_dotnet.iso_21090.CD code) { if (standardCodeSequence == null) return code == null; if (code == null) return false; return string.Equals(standardCodeSequence.CodeMeaning, code.CodeMeaning) && string.Equals(standardCodeSequence.CodeValue, code.CodeValue) && string.Equals(standardCodeSequence.CodingSchemeDesignator, code.CodingSchemeDesignator) && StringEquals(standardCodeSequence.CodingSchemeVersion, code.CodingSchemeVersion); }
public static bool IsNullCodeSequence(TemplateTree.StandardCodeSequence codeSequence) { if (codeSequence == null) return true; if (codeSequence.CodeMeaning == AimAnnotationComponent.NullCodeValue.CodeMeaning && codeSequence.CodeValue == AimAnnotationComponent.NullCodeValue.CodeValue) return true; return false; }
private static List<aim4_dotnet.iso_21090.CD> ToNativeCodeList(TemplateTree.StandardValidTerm standardValidTerm) { if (standardValidTerm == null || standardValidTerm.StandardCodeSequence == null) return null; var codeList = ToNativeCodeList(standardValidTerm.StandardCodeSequence); foreach (var validTerm in standardValidTerm.StandardValidTerms) { if (validTerm == null) continue; var subCodeList = ToNativeCodeList(validTerm); if (subCodeList != null) codeList.AddRange(subCodeList); } return codeList; }
// Retrieves SOP Instance UID and Referenced Frame Number from the coordinate private static void SetMarkupImageReference(TemplateTree.IMarkup markup, aim_dotnet.ISpatialCoordinate spatialCoordinate) { if (spatialCoordinate.CoordinateType == aim_dotnet.SpatialCoordinateType.SPATIAL_COORD_2D) { var twoDSpatialCoord = spatialCoordinate as aim_dotnet.TwoDimensionSpatialCoordinate; if (twoDSpatialCoord != null) { Debug.Assert(twoDSpatialCoord.ReferencedFrameNumber > 0, "Referenced Frame Number must be positive"); markup.PresentationImageUid = twoDSpatialCoord.ImageReferenceUID; markup.FrameNumber = twoDSpatialCoord.ReferencedFrameNumber; } } else { Debug.Assert(false, "Setting image references is not implemented for 3D"); } }
public static bool AimDotNetIntervalEqualsTemplateTreeInterval(aim4_dotnet.Interval a, TemplateTree.Interval b) { return a.MinValue == b.MinValue && a.MaxValue == b.MaxValue && a.MinOperator == ToAimComparisonOperator(b.MinOperator) && a.MaxOperator == ToAimComparisonOperator(b.MaxOperator) && a.UcumString == b.UcumString; }
protected override async Task <List <int> > SaveExecuteAsync(List <NotificationTemplateForSave> entities, bool returnIds) { #region Validation var definitionedCollections = new string[] { nameof(Document), nameof(Resource), nameof(Agent), nameof(Lookup) }; foreach (var(entity, index) in entities.Indexed()) { if (entity.Cardinality == Cardinalities.Bulk) { // ListExpression if (string.IsNullOrWhiteSpace(entity.ListExpression)) { var path = $"[{index}].{nameof(entity.ListExpression)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_ListExpression"]]; ModelState.AddError(path, msg); } else { try { TemplexBase.Parse(entity.ListExpression); } catch { var path = $"[{index}].{nameof(entity.ListExpression)}"; var msg = _localizer["Error_InvalidTemplateExpression0", entity.ListExpression]; ModelState.AddError(path, msg); } } // AddressExpression if (string.IsNullOrWhiteSpace(entity.AddressExpression)) { var path = $"[{index}].{nameof(entity.AddressExpression)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_AddressExpression"]]; ModelState.AddError(path, msg); } else { try { TemplexBase.Parse(entity.AddressExpression); } catch { var path = $"[{index}].{nameof(entity.AddressExpression)}"; var msg = _localizer["Error_InvalidTemplateExpression0", entity.AddressExpression]; ModelState.AddError(path, msg); } } } if (entity.Trigger == Triggers.Automatic) { // Schedule if (string.IsNullOrWhiteSpace(entity.Schedule)) { var path = $"[{index}].{nameof(entity.Schedule)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_Schedule"]]; ModelState.AddError(path, msg); } else { string faultyCron = null; try { var crons = entity.Schedule.Split(';') .Where(e => !string.IsNullOrWhiteSpace(e)) .Select(e => e.Trim()); foreach (var cron in crons) { faultyCron = cron; CronExpression.Parse(cron); } } catch { var path = $"[{index}].{nameof(entity.Schedule)}"; var msg = _localizer["Error_InvalidCronExpression0", faultyCron]; ModelState.AddError(path, msg); } } if (string.IsNullOrWhiteSpace(entity.ConditionExpression)) { // Doesn't matter } else { try { TemplexBase.Parse(entity.ConditionExpression); } catch { var path = $"[{index}].{nameof(entity.ConditionExpression)}"; var msg = _localizer["Error_InvalidTemplateExpression0", entity.ConditionExpression]; ModelState.AddError(path, msg); } } } if (entity.Trigger == Triggers.Manual) { // Usage if (string.IsNullOrWhiteSpace(entity.Usage)) { var path = $"[{index}].{nameof(entity.Usage)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["Template_Usage"]]; ModelState.AddError(path, msg); } else if (entity.Usage == TemplateUsages.FromSearchAndDetails || entity.Usage == TemplateUsages.FromDetails) { if (string.IsNullOrWhiteSpace(entity.Collection)) { var path = $"[{index}].{nameof(entity.Collection)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["Template_Collection"]]; ModelState.AddError(path, msg); } else { if (definitionedCollections.Contains(entity.Collection)) { // DefinitionId is required when querying by Id if (entity.Usage == TemplateUsages.FromDetails && entity.DefinitionId == null) { var path = $"[{index}].{nameof(entity.DefinitionId)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["Template_DefinitionId"]]; ModelState.AddError(path, msg); } } else { entity.DefinitionId = null; } } } else if (entity.Usage == TemplateUsages.FromReport) { if (entity.ReportDefinitionId == null) { var path = $"[{index}].{nameof(entity.ReportDefinitionId)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["Template_ReportDefinitionId"]]; ModelState.AddError(path, msg); } } // TODO Check that DefinitionId is compatible with Collection } if (entity.Channel == Channels.Email) { // Subject if (string.IsNullOrWhiteSpace(entity.Subject)) { var path = $"[{index}].{nameof(entity.Subject)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_Subject"]]; ModelState.AddError(path, msg); } else { try { TemplateTree.Parse(entity.Subject); } catch { var path = $"[{index}].{nameof(entity.Subject)}"; var msg = _localizer["Error_InvalidTemplate"]; ModelState.AddError(path, msg); } } } // Body if (!string.IsNullOrWhiteSpace(entity.Body)) { if (entity.Channel == Channels.Sms) { const int maxSmsExpressionLength = 1024; if (entity.Body.Length > maxSmsExpressionLength) { var path = $"[{index}].{nameof(entity.Body)}"; var msg = _localizer[ErrorMessages.Error_Field0LengthMaximumOf1, _localizer["Template_Body"], maxSmsExpressionLength]; ModelState.AddError(path, msg); } } try { TemplateTree.Parse(entity.Body); } catch { var path = $"[{index}].{nameof(entity.Body)}"; var msg = _localizer["Error_InvalidTemplate"]; ModelState.AddError(path, msg); } } // Caption try { TemplateTree.Parse(entity.Caption); } catch { var path = $"[{index}].{nameof(entity.Caption)}"; var msg = _localizer["Error_InvalidTemplate"]; ModelState.AddError(path, msg); } var duplicateKeys = entity .Parameters .Select(e => e.Key) .GroupBy(e => e) .Where(e => e.Count() > 1) .Select(e => e.FirstOrDefault()) .ToHashSet(); // Parameters foreach (var(parameter, parameterIndex) in entity.Parameters.Indexed()) { if (!TemplexVariable.IsValidVariableName(parameter.Key)) { var path = $"[{index}].{nameof(entity.Parameters)}[{parameterIndex}].{nameof(parameter.Key)}"; var msg = "Invalid Key. Valid keys contain only alphanumeric characters, dollar symbols, and underscores and do not start with a number."; ModelState.AddError(path, msg); } else if (duplicateKeys.Contains(parameter.Key)) { var path = $"[{index}].{nameof(entity.Parameters)}[{parameterIndex}].{nameof(parameter.Key)}"; var msg = $"The Key '{parameter.Key}' is used more than once."; ModelState.AddError(path, msg); } } // Attachments foreach (var(attachment, attachmentIndex) in entity.Attachments.Indexed()) { if (!string.IsNullOrWhiteSpace(attachment.ContextOverride)) { try { TemplexBase.Parse(attachment.ContextOverride); } catch { var path = $"[{index}].{nameof(entity.Attachments)}[{attachmentIndex}].{nameof(attachment.ContextOverride)}"; var msg = _localizer["Error_InvalidTemplateExpression0", attachment.ContextOverride]; ModelState.AddError(path, msg); } } if (!string.IsNullOrWhiteSpace(attachment.DownloadNameOverride)) { try { TemplateTree.Parse(attachment.DownloadNameOverride); } catch { var path = $"[{index}].{nameof(entity.Attachments)}[{attachmentIndex}].{nameof(attachment.DownloadNameOverride)}"; var msg = _localizer["Error_InvalidTemplate0", attachment.DownloadNameOverride]; ModelState.AddError(path, msg); } } } // Subscribers foreach (var(subscriber, subscriberIndex) in entity.Subscribers.Indexed()) { if (subscriber.AddressType == AddressTypes.User) { if (subscriber.UserId == null) { var path = $"[{index}].{nameof(entity.Subscribers)}[{subscriberIndex}].{nameof(subscriber.UserId)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_User"]]; ModelState.AddError(path, msg); } } if (subscriber.AddressType == AddressTypes.Text) { if (entity.Channel == Channels.Email) { if (string.IsNullOrWhiteSpace(subscriber.Email)) { var path = $"[{index}].{nameof(entity.Subscribers)}[{subscriberIndex}].{nameof(subscriber.Email)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_Email"]]; ModelState.AddError(path, msg); } else { try { TemplateTree.Parse(subscriber.Email); } catch { var path = $"[{index}].{nameof(entity.Subscribers)}[{subscriberIndex}].{nameof(subscriber.Email)}"; var msg = _localizer["Error_InvalidTemplate"]; ModelState.AddError(path, msg); } } } if (entity.Channel == Channels.Sms) { if (string.IsNullOrWhiteSpace(subscriber.Phone)) { var path = $"[{index}].{nameof(entity.Subscribers)}[{subscriberIndex}].{nameof(subscriber.Phone)}"; var msg = _localizer[ErrorMessages.Error_Field0IsRequired, _localizer["NotificationTemplate_Phone"]]; ModelState.AddError(path, msg); } else { try { TemplateTree.Parse(subscriber.Phone); } catch { var path = $"[{index}].{nameof(entity.Subscribers)}[{subscriberIndex}].{nameof(subscriber.Phone)}"; var msg = _localizer["Error_InvalidTemplate"]; ModelState.AddError(path, msg); } } } } } } #endregion SaveOutput result = await _behavior.Repository.NotificationTemplates__Save( entities : entities, returnIds : returnIds, validateOnly : ModelState.IsError, top : ModelState.RemainingErrors, userId : UserId); AddErrorsAndThrowIfInvalid(result.Errors); return(result.Ids); }
public static bool AimDotNetNumericalEqualsTemplateTreeNumerical(aim4_dotnet.Numerical a, TemplateTree.Numerical b) { return a.Value == b.Value && a.UcumString == b.UcumString && a.Operator == ToAimComparisonOperator(b.Operator); }
protected override void OnInit(EventArgs e) { _treeControl = new TemplateTree(); _treeControl.RootFolder = WAFContext.PathFromRootToAppFolder; _treeControl.AllowSelect = true; _treeControl.AllowDrag = false; _treeControl.DblClick += new EventHandler(_treeControl_DblClick); pnlLeft.Controls.Add(_treeControl); cntFrm.CommandClick += new EventHandler<CommandArgument>(cntFrm_CommandClick); WAFPanel p1 = new WAFPanel(); p1.Width = Unit.Percentage(100); p1.Height = Unit.Pixel(26); p1.Border = false; p1.Margin = true; MainButton saveAspx = new MainButton(); saveAspx.Click += new EventHandler(saveAspx_Click); saveAspx.Text = Local.Text("Web.WAF.Edit.Templates.TemplatesSaveChanges"); p1.Controls.Add(saveAspx); tabASPXFile.Controls.Add(p1); _aspxFileEditor = new CodeEditor(); _aspxFileEditor.Width = Unit.Percentage(100); _aspxFileEditor.Height = Unit.Percentage(100); _aspxFileEditor.Language = "html"; tabASPXFile.Controls.Add(_aspxFileEditor); WAFPanel p2 = new WAFPanel(); p2.Width = Unit.Percentage(100); p2.Height = Unit.Pixel(26); p2.Border = false; p2.Margin = true; MainButton saveCodebehind = new MainButton(); saveCodebehind.Click += new EventHandler(saveCodebehind_Click); saveCodebehind.Text = Local.Text("Web.WAF.Edit.Templates.TemplatesSaveChanges"); _codebehindEditor = new CodeEditor(); _codebehindEditor.Width = Unit.Percentage(100); _codebehindEditor.Height = Unit.Percentage(100); _codebehindEditor.Language = "cs"; tabCodebindFile.Controls.Add(p2); tabCodebindFile.Controls.Add(_codebehindEditor); p2.Controls.Add(saveCodebehind); TemplatesMaster.ViewChanged += new EventHandler<MainMenuItem>(TemplatesMaster_ViewChanged); btnCreateTemplate.Click += new EventHandler(btnCreateTemplate_Click); if (!IsPostBack && Request["Open"] != null) { CKeyNLR key = new CKeyNLR(Request["Open"]); cntFrm.ContentKey = key; tabbedView.Visible = true; Template s = WAFContext.Session.GetContent<Template>(key); string treeKey = s.Filepath + "." + s.NodeId + "."; if (WAFRuntime.FileSystem.FileExists(WAFContext.PathFromRootToAppFolder + s.Filepath)) { treeKey += "match#"; } else { treeKey += "onlyContent#"; } _treeControl.SetSelected(treeKey); _treeControl.Refresh(); updateCodeEditors(s.Filepath); cntFrm.Refresh(); } base.OnInit(e); }
/// <summary> /// Returns a StandardCodeSequence from a recursively collapsed or flattened StandardValidTerm. /// </summary> /// <param name="standardValidTerm"></param> /// <returns></returns> public static TemplateTree.StandardCodeSequence ToStandardCodeSequence(TemplateTree.StandardValidTerm standardValidTerm) { const int codeValueLength = 16; const int codeMeaningLength = 64; TemplateTree.StandardCodeSequence standardCodeSequence = CollapseStandardValidTerm(standardValidTerm); string codeValue = standardCodeSequence.CodeValue; string codeMeaning = standardCodeSequence.CodeMeaning; string codingSchemeDesignator = standardCodeSequence.CodingSchemeDesignator; string codingSchemeVersion = standardCodeSequence.CodingSchemeVersion; if (standardValidTerm.StandardValidTerms.Count > 0) { codeValue = ToHex(codeValue); if (codeValue.Length > codeValueLength) codeValue = codeValue.Substring(0, codeValueLength); if (codeMeaning.Length > codeMeaningLength) codeMeaning = codeMeaning.Substring(0, codeMeaningLength); } return new TemplateTree.StandardCodeSequence( codeValue, codeMeaning, codingSchemeDesignator, codingSchemeVersion); }
public static Dictionary<int, List<aim_dotnet.AnatomicEntityCharacteristic>> SelectedAnatomicEntityCharacteristicsDictionary(TemplateTree.AimTemplateTreeAnatomicEntityNode anatomicEntity) { return anatomicEntity.SelectedAnatomicEntityCharacteristicTreeNodes.ToDictionary(aec => aec.ItemNumber, aec => new List<aim_dotnet.AnatomicEntityCharacteristic>(SelectedAnatomicEntityCharacteristics(aec))); }