12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using FISLib.Vid;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Vinno.FIS.Sonopost.Common;
- namespace Vinno.FIS.Sonopost.Features.Dicom
- {
- public class UploadContent
- {
- /// <summary>
- /// Get file path.
- /// </summary>
- public string UploadFilePath { get; }
- /// <summary>
- /// Get vid type.
- /// </summary>
- public FISVidType VidType { get; }
- /// <summary>
- /// Get id.
- /// </summary>
- public string Id { get; }
- /// <summary>
- /// Get date.
- /// </summary>
- public string Date { get; }
- public bool IsVidFile { get; }
- public string ExamRecordId { get; }
- private UploadContent(string uploadFilePath, FISVidType vidType, string id, string date, bool isVidFile, string examRecordId)
- {
- UploadFilePath = uploadFilePath;
- VidType = vidType;
- Id = id;
- Date = date;
- IsVidFile = isVidFile;
- ExamRecordId = examRecordId;
- }
- /// <summary>
- /// Parse upload content.
- /// </summary>
- /// <param name="filePath">Dicom file path.</param>
- /// <returns>Upload content.</returns>
- public static UploadContent Parse(string filePath)
- {
- var fileInfo = new FileInfo(filePath);
- var fileName = fileInfo.Name;
- var names = fileName.Split('.');
- if (!ValidateFileNames(names))
- {
- return null;
- }
- names = names[0].Split('_');
- var dataType = names[1];
- bool isVid = false;
- string examRecordId = string.Empty;
- if (names.Length == 3)
- {
- isVid = false;
- }
- else if (names.Length == 4)
- {
- isVid = true;
- examRecordId = names[3];
- }
- else
- {
- return null;
- }
- if (string.IsNullOrWhiteSpace(dataType) || string.IsNullOrWhiteSpace(names[2]))
- {
- return null;
- }
- return Enum.TryParse(dataType, true, out FISVidType vidType)
- ? new UploadContent(filePath, vidType, names[0], names[2], isVid, examRecordId)
- : null;
- }
- private static bool ValidateFileNames(IReadOnlyList<string> names)
- {
- return names.Count == 2 && names[1] == SonopostConstants.VidFileName && names[0].Contains('_');
- }
- }
- }
|