public static List <Protocol> GetProtocolsFromFolder(string folderPath) { var protocols = new List <Protocol>(); var filePaths = Directory.GetFiles(folderPath, "*.csv"); foreach (string filePath in filePaths) { var objectives = DvhObjective.ReadObjectivesFromCsv(filePath); var id = (objectives.First()).ProtocolId; var protocol = new Protocol(id, filePath, objectives); protocols.Add(protocol); } return(protocols); }
public static List <DvhObjective> ReadObjectivesFromCsv(string filePath) { List <DvhObjective> objectives = new List <DvhObjective>(); using (StreamReader sr = new StreamReader(filePath, Encoding.GetEncoding("shift_jis"))) { var csv = new CsvReader(sr); csv.Read(); csv.ReadHeader(); csv.Read(); csv.Configuration.MissingFieldFound = null; var protocolId = csv["Protocol ID"]; var originalProtocolId = csv["Original Protocol ID"]; if (string.IsNullOrEmpty(protocolId)) { throw new InvalidOperationException("Protocol ID is empty, file: " + filePath); } if (string.IsNullOrEmpty(originalProtocolId)) { originalProtocolId = protocolId; } csv.Read(); csv.ReadHeader(); while (csv.Read()) { string title = csv["Title"]; string structureName = csv["Structure Name"]; string objectiveType = csv["Objective Type"]; string targetType = csv["Target Type"]; string targetValue = csv["Target Value"]; string targetUnit = csv["Target Unit"]; string acceptableLimitValue = csv["Acceptable Limit Value"]; string argumentValue = csv["Argument Value"]; string argumentUnit = csv["Argument Unit"]; string remarks = csv["Remarks"]; string structureNameTps = csv["Structure Name TPS"]; var objectiveCsv = new ObjectiveCsv() { ProtocolId = protocolId, OriginalProtocolId = originalProtocolId, Title = title, StructureName = structureName, ObjectiveType = objectiveType, TargetType = targetType, TargetValue = targetValue, TargetUnit = targetUnit, AcceptableLimitValue = acceptableLimitValue, ArgumentValue = argumentValue, ArgumentUnit = argumentUnit, Remarks = remarks, StructureNameTps = structureNameTps }; var objective = new DvhObjective(objectiveCsv); objectives.Add(objective); } } return(objectives); }
public Protocol(string id, string filePath) { Id = id; FilePath = filePath; Objectives = DvhObjective.ReadObjectivesFromCsv(filePath); }