|
@@ -36,6 +36,7 @@ using WingInterfaceLibrary.Interface.DBInterface;
|
|
|
using WingInterfaceLibrary.Request.DBRequest;
|
|
|
using WingInterfaceLibrary.DTO.DiagnosisResult;
|
|
|
using WingInterfaceLibrary.Request.RemedicalAISelected;
|
|
|
+using ContourModifyUtils;
|
|
|
|
|
|
namespace WingAIDiagnosisService.Service
|
|
|
{
|
|
@@ -76,6 +77,10 @@ namespace WingAIDiagnosisService.Service
|
|
|
InitAISystem();
|
|
|
|
|
|
_recognizeCarotidTypeCanBeUse = _recognizeCarotidType.Initialization();
|
|
|
+ var keyPointDistanceThreshold = ConfigurationManager.GetParammeter<IntParameter>("AI", "ContourInterval").Value;
|
|
|
+ var dragStartPointCatchDistanceThreshold = ConfigurationManager.GetParammeter<IntParameter>("AI", "ContourInterval").Value;
|
|
|
+ ContourModifyHelper.KeyPointDistanceThreshold = keyPointDistanceThreshold;
|
|
|
+ ContourModifyHelper.DragStartPointCatchDistanceThreshold = dragStartPointCatchDistanceThreshold;
|
|
|
}
|
|
|
|
|
|
private void InitAISystem()
|
|
@@ -227,7 +232,7 @@ namespace WingAIDiagnosisService.Service
|
|
|
Logger.WriteLineWarn($"AIService DiagnosisReport err, {ex}");
|
|
|
}
|
|
|
return new DiagnosisReportResult();
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -238,7 +243,64 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<GetDiagnosisEnumItemsResult> GetDiagnosisEnumItemsAsync(GetDiagnosisEnumItemsRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var diagnosisItems = new List<EnumItemDTO>();
|
|
|
+
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisBreastLabelEnum), "Breast", new List<string> { "BIRads1" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisLiverLabelEnum), "Liver", new List<string> { "BIRads1" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(AIThyroidLabelEnum), "Thyroid", new List<string> { "TIRADS0" }));
|
|
|
+
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesShapeValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesOrientationValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesEchoPatternValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesLesionBoundaryValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesMarginValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumCalcificationsValue), "Calcification"));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesLiverShapeValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesLiverBoundaryValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesLiverEchoTextureValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesThyroidEchoPatternValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesThyroidShapeValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesThyroidMarginValue)));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(EnumDesThyroidEchogenicFociValue)));
|
|
|
+
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisBreastLabelEnum), "BreastLocalLesion", includeFields: new List<string> { "Lipomyoma", "BIRads2", "BIRads3" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisBreastLabelEnum), "BreastDiffuseLesion", includeFields: new List<string> { "BIRads4A", "BIRads4B", "BIRads4C", "BIRads5" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisLiverLabelEnum), "LiverLocalLesion", includeFields: new List<string> { "Hyperechoic", "HHE", "CYST", "PossibleCancer" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(DiagnosisLiverLabelEnum), "LiverDiffuseLesion", includeFields: new List<string> { "FattyLiver", "DiffuseLesions", "Cirrhosis", "PCLD" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(AIThyroidLabelEnum), "ThyroidLocalLesion", includeFields: new List<string> { "TIRADS2", "TIRADS3", "TIRADS4a", "TIRADS4b", "TIRADS4c", "TIRADS5" }));
|
|
|
+ diagnosisItems.Add(GetEnumItem(typeof(AIThyroidLabelEnum), "ThyroidDiffuseLesion", includeFields: new List<string> { "DiffuseDisease" }));
|
|
|
+
|
|
|
+ var resultData = new GetDiagnosisEnumItemsResult { Source = diagnosisItems };
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
+ }
|
|
|
+
|
|
|
+ private EnumItemDTO GetEnumItem(Type enumType, string keyCode = "", List<string> excludeFields = null, List<string> includeFields = null)
|
|
|
+ {
|
|
|
+ keyCode = !string.IsNullOrWhiteSpace(keyCode) ? keyCode : enumType.Name.ToString().Replace("EnumDes", "").Replace("Enum", "").Replace("Value", "");
|
|
|
+ var enumNames = Enum.GetNames(enumType).ToList();
|
|
|
+ if (excludeFields != null && excludeFields.Any())
|
|
|
+ {
|
|
|
+ enumNames = enumNames.Except(excludeFields).ToList();
|
|
|
+ }
|
|
|
+ if (includeFields != null && includeFields.Any())
|
|
|
+ {
|
|
|
+ enumNames = enumNames.Intersect(includeFields).ToList();
|
|
|
+ }
|
|
|
+ var children = new List<EnumFieldDTO>();
|
|
|
+ foreach (var val in enumNames)
|
|
|
+ {
|
|
|
+ var id = (int)enumType.GetField(val).GetValue(val);
|
|
|
+ children.Add(new EnumFieldDTO
|
|
|
+ {
|
|
|
+ Id = id,
|
|
|
+ Value = val,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return new EnumItemDTO
|
|
|
+ {
|
|
|
+ Code = keyCode,
|
|
|
+ Children = children,
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
|
|
@@ -250,7 +312,22 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<List<DiagnosisKeyPointDTO>> GetKeyPointsOfContourAsync(GetKeyPointsOfContourRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var contourPoints = request.Contours.Select(c => new Point2D
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y
|
|
|
+ }).ToArray();
|
|
|
+ var ls = request.LesionSize;
|
|
|
+ var horizontalP1 = new Point2D(ls.HorizontalPoint1.X, ls.HorizontalPoint1.Y);
|
|
|
+ var horizontalP2 = new Point2D(ls.HorizontalPoint2.X, ls.HorizontalPoint2.Y);
|
|
|
+ var verticalP1 = new Point2D(ls.VerticalPoint1.X, ls.VerticalPoint1.Y);
|
|
|
+ var verticalP2 = new Point2D(ls.VerticalPoint2.X, ls.VerticalPoint2.Y);
|
|
|
+ var lesionSize = new LesionSize(horizontalP1, horizontalP2, verticalP1, verticalP2);
|
|
|
+
|
|
|
+
|
|
|
+ var aiResult = ContourModifyHelper.KeyPointsOfContour(contourPoints, lesionSize);
|
|
|
+ var resultData = KeyPointToDto(aiResult);
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -262,7 +339,15 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<List<int>> AffectedKeyPointsByDragActionAsync(AffectedKeyPointsByDragActionRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var origKeyPoints = request.KeyPoints.Select(c => new KeyPointInfo
|
|
|
+ {
|
|
|
+ Type = (EnumKeyPointType)c.Type,
|
|
|
+ IndexInContour = c.IndexInContour,
|
|
|
+ Point = new Point2D(c.Point.X, c.Point.Y)
|
|
|
+ }).ToArray();
|
|
|
+ var mousePoint = new Point2D(request.MousePoint.X, request.MousePoint.Y);
|
|
|
+ var resultData = ContourModifyHelper.AffectedKeyPointsByDragAction(origKeyPoints, mousePoint).ToList();
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -274,7 +359,31 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<ContourAndKeyPointsAfterDragResult> ContourAndKeyPointsAfterDragAsync(ContourAndKeyPointsAfterDragRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var origContourPoints = request.Contours.Select(c => new Point2D
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y
|
|
|
+ }).ToArray();
|
|
|
+ var origKeyPoints = request.KeyPoints.Select(c => new KeyPointInfo
|
|
|
+ {
|
|
|
+ Type = (EnumKeyPointType)c.Type,
|
|
|
+ IndexInContour = c.IndexInContour,
|
|
|
+ Point = new Point2D(c.Point.X, c.Point.Y)
|
|
|
+ }).ToArray();
|
|
|
+ var dragStartPoint = new Point2D(request.StartPoint.X, request.StartPoint.Y);
|
|
|
+ var dragEndPoint = new Point2D(request.EndPoint.X, request.EndPoint.Y);
|
|
|
+ ContourModifyHelper.ContourAndKeyPointsAfterDrag(origContourPoints, origKeyPoints, dragStartPoint, dragEndPoint
|
|
|
+ , out Point2D[] dstContourPoints, out KeyPointInfo[] dstKeyPoints, out int[] affectedKeyPointIndexes);
|
|
|
+
|
|
|
+ var dstContours = PointToDto(dstContourPoints);
|
|
|
+ var dstKeys = KeyPointToDto(dstKeyPoints);
|
|
|
+ var resultData = new ContourAndKeyPointsAfterDragResult
|
|
|
+ {
|
|
|
+ DstContours = dstContours,
|
|
|
+ DstKeyPoints = dstKeys,
|
|
|
+ AffectedKeyPointIndexes = affectedKeyPointIndexes.ToList(),
|
|
|
+ };
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -286,7 +395,19 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<MinimumDistanceToContourPointsResult> MinimumDistanceToContourPointsAsync(MinimumDistanceToContourPointsRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var origContourPoints = request.ContourPoints.Select(c => new Point2D
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y
|
|
|
+ }).ToArray();
|
|
|
+ var mousePoint = new Point2D(request.MousePoint.X, request.MousePoint.Y);
|
|
|
+ var distance = ContourModifyHelper.MinimumDistanceToContourPoints(origContourPoints, mousePoint, out int closestPointIndex);
|
|
|
+ var resultData = new MinimumDistanceToContourPointsResult
|
|
|
+ {
|
|
|
+ DistanceCaught = distance,
|
|
|
+ ClosestPointIndex = closestPointIndex,
|
|
|
+ };
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -298,7 +419,40 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<ContourMergeResult> ContourMergeAsync(ContourMergeRequest request)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var origContourPoints = request.ContourPoints.Select(c => new Point2D
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y
|
|
|
+ }).ToArray();
|
|
|
+ var ls = request.LesionSize;
|
|
|
+ var horizontalP1 = new Point2D(ls.HorizontalPoint1.X, ls.HorizontalPoint1.Y);
|
|
|
+ var horizontalP2 = new Point2D(ls.HorizontalPoint2.X, ls.HorizontalPoint2.Y);
|
|
|
+ var verticalP1 = new Point2D(ls.VerticalPoint1.X, ls.VerticalPoint1.Y);
|
|
|
+ var verticalP2 = new Point2D(ls.VerticalPoint2.X, ls.VerticalPoint2.Y);
|
|
|
+ var lesionSize = new LesionSize(horizontalP1, horizontalP2, verticalP1, verticalP2);
|
|
|
+
|
|
|
+
|
|
|
+ var drawingNewContourPoints = request.DrawingNewContourPoints.Select(c => new Point2D
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y
|
|
|
+ }).ToArray();
|
|
|
+ var aiResult = ContourModifyHelper.ContourMerge(origContourPoints, lesionSize, drawingNewContourPoints, out Point2D[] dstContourPoints, out LesionSize dstLesionSize);
|
|
|
+ var dstContours = PointToDto(dstContourPoints);
|
|
|
+ var resultData = new ContourMergeResult
|
|
|
+ {
|
|
|
+ DstContours = dstContours,
|
|
|
+ DstLesionSize = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisLesionSize
|
|
|
+ {
|
|
|
+ HorizontalPoint1 = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D { X = dstLesionSize.HorizontalPoint1.X, Y = dstLesionSize.HorizontalPoint1.Y },
|
|
|
+ HorizontalPoint2 = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D { X = dstLesionSize.HorizontalPoint2.X, Y = dstLesionSize.HorizontalPoint2.Y },
|
|
|
+ VerticalPoint1 = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D { X = dstLesionSize.VerticalPoint1.X, Y = dstLesionSize.VerticalPoint1.Y },
|
|
|
+ VerticalPoint2 = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D { X = dstLesionSize.VerticalPoint2.X, Y = dstLesionSize.VerticalPoint2.Y },
|
|
|
+ HorizontalLengthInPixel = dstLesionSize.HorizontalLengthInPixel,
|
|
|
+ VerticalLengthInPixel = dstLesionSize.VerticalLengthInPixel,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ return await Task.FromResult(resultData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -975,6 +1129,39 @@ namespace WingAIDiagnosisService.Service
|
|
|
throw ex;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private List<WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D> PointToDto(Point2D[] points)
|
|
|
+ {
|
|
|
+ var dstContours = new List<WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D>();
|
|
|
+ foreach (var p in points)
|
|
|
+ {
|
|
|
+ dstContours.Add(new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D
|
|
|
+ {
|
|
|
+ X = p.X,
|
|
|
+ Y = p.Y
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return dstContours;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<DiagnosisKeyPointDTO> KeyPointToDto(KeyPointInfo[] points)
|
|
|
+ {
|
|
|
+ var dstKeys = new List<DiagnosisKeyPointDTO>();
|
|
|
+ foreach (var point in points)
|
|
|
+ {
|
|
|
+ dstKeys.Add(new DiagnosisKeyPointDTO
|
|
|
+ {
|
|
|
+ Type = (DiagnosisKeyPointType)point.Type,
|
|
|
+ IndexInContour = point.IndexInContour,
|
|
|
+ Point = new WingInterfaceLibrary.DTO.Comment.AIDiagnosisPoint2D
|
|
|
+ {
|
|
|
+ X = point.Point.X,
|
|
|
+ Y = point.Point.Y,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return dstKeys;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|