Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public DvhObjective(ObjectiveCsv objectiveCsv)
        {
            ProtocolId         = objectiveCsv.ProtocolId;
            OriginalProtocolId = objectiveCsv.OriginalProtocolId;
            Title         = objectiveCsv.Title;
            StructureName = objectiveCsv.StructureName;
            ObjectiveType = (DvhObjectiveType)Enum.Parse(typeof(DvhObjectiveType), objectiveCsv.ObjectiveType);
            TargetType    = (DvhTargetType)Enum.Parse(typeof(DvhTargetType), objectiveCsv.TargetType);
            ArgumentValue = string.IsNullOrEmpty(objectiveCsv.ArgumentValue) ? 0.0 : double.Parse(objectiveCsv.ArgumentValue);
            TargetValue   = double.Parse(objectiveCsv.TargetValue);

            // If Acceptable Limit is not given, set to -1
            AcceptableLimitValue = string.IsNullOrEmpty(objectiveCsv.AcceptableLimitValue) ? -1 : double.Parse(objectiveCsv.AcceptableLimitValue);
            Remarks = objectiveCsv.Remarks;

            StructureNameTps = objectiveCsv.StructureNameTps;

            string argumentUnit = objectiveCsv.ArgumentUnit;

            if (argumentUnit == "%")
            {
                argumentUnit = "Percent";
            }
            string targetUnit = objectiveCsv.TargetUnit;;

            if (targetUnit == "%")
            {
                targetUnit = "Percent";
            }

            switch (TargetType)
            {
            case DvhTargetType.Dose:
                DoseUnit   = (DvhDoseUnit)Enum.Parse(typeof(DvhDoseUnit), targetUnit);
                VolumeUnit = string.IsNullOrEmpty(argumentUnit) ? DvhVolumeUnit.None : (DvhVolumeUnit)Enum.Parse(typeof(DvhVolumeUnit), argumentUnit);
                if (DoseUnit == DvhDoseUnit.Percent)
                {
                    TargetUnit = DvhPresentationType.Rel;
                }
                else
                {
                    TargetUnit = DvhPresentationType.Abs;
                }

                if (VolumeUnit == DvhVolumeUnit.Percent)
                {
                    ArgumentUnit = DvhPresentationType.Rel;
                }
                else if (VolumeUnit == DvhVolumeUnit.None)
                {
                    ArgumentUnit = DvhPresentationType.None;
                }
                else
                {
                    ArgumentUnit = DvhPresentationType.Abs;
                }
                break;

            case DvhTargetType.Volume:
                DoseUnit   = string.IsNullOrEmpty(argumentUnit) ? DvhDoseUnit.None : (DvhDoseUnit)Enum.Parse(typeof(DvhDoseUnit), argumentUnit);
                VolumeUnit = (DvhVolumeUnit)Enum.Parse(typeof(DvhVolumeUnit), targetUnit);
                if (VolumeUnit == DvhVolumeUnit.Percent)
                {
                    TargetUnit = DvhPresentationType.Rel;
                }
                else
                {
                    TargetUnit = DvhPresentationType.Abs;
                }

                if (DoseUnit == DvhDoseUnit.Percent)
                {
                    ArgumentUnit = DvhPresentationType.Rel;
                }
                else if (DoseUnit == DvhDoseUnit.None)
                {
                    ArgumentUnit = DvhPresentationType.None;
                }
                else
                {
                    ArgumentUnit = DvhPresentationType.Abs;
                }
                break;
            }
        }