Skip to content

Commit

Permalink
Merge pull request #7 from HicServices/feature/lgtm-fixes
Browse files Browse the repository at this point in the history
Fix some LGTM alerts, bump dependencies
  • Loading branch information
jas88 authored Aug 18, 2020
2 parents bc68e6a + eea08fd commit d8123ae
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 72 deletions.
7 changes: 4 additions & 3 deletions BadDicom/BadDicom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -40,9 +41,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="fo-dicom.NetCore" Version="4.0.5" />
<PackageReference Include="HIC.DicomTypeTranslation" Version="2.2.2" />
<PackageReference Include="YamlDotNet" Version="8.1.1" />
<PackageReference Include="fo-dicom.NetCore" Version="4.0.6" />
<PackageReference Include="HIC.DicomTypeTranslation" Version="2.3.1" />
<PackageReference Include="YamlDotNet" Version="8.1.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
2 changes: 1 addition & 1 deletion BadDicom/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static int RunDatabaseTarget(TargetDatabase configDatabase, ProgramOptio
for (int i = 0; i < batchSize; i++)
{
var batch = i;
tasks[i] = new Task(() =>
tasks[i] = new Task(() => // lgtm[cs/local-not-disposed]
{
RunBatch(identifiers,opts,r,batches[batch],uploaders[batch]);

Expand Down
2 changes: 1 addition & 1 deletion BadMedicine.Dicom/BadMedicine.Dicom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="fo-dicom.NetCore" Version="4.0.5" />
<PackageReference Include="fo-dicom.NetCore" Version="4.0.6" />
<PackageReference Include="HIC.BadMedicine" Version="0.1.6" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BadMedicine.Dicom/BadMedicine.Dicom.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<tags>Dicom,Test Data,Random,Synthetic Data,Health</tags>
<dependencies>
<dependency id="MathNet.Numerics" version="4.9.1" exclude="Build,Analyzers" />
<dependency id="fo-dicom.NetCore" version="4.0.5" />
<dependency id="fo-dicom.NetCore" version="4.0.6" />
<dependency id="HIC.BadMedicine" version="0.1.6" />
<dependency id="System.Drawing.Common" version="4.7.0" />
</dependencies>
Expand Down
3 changes: 1 addition & 2 deletions BadMedicine.Dicom/DicomDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public override object[] GenerateTestDataRow(Person p)
//don't generate more than the maximum number of images
if (MaximumImages-- <= 0)
{
study = null;
break;
}
else
Expand Down Expand Up @@ -166,7 +165,7 @@ public DicomDataset[] GenerateStudyImages(Person p, out Study study)
//generate a study
study = new Study(this,p,GetRandomModality(r),r);

return study.SelectMany(series=>series).Select(image=>image).ToArray();
return study.SelectMany(series=>series).ToArray();
}

/// <summary>
Expand Down
84 changes: 44 additions & 40 deletions BadMedicine.Dicom/DicomDataGeneratorStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,56 +100,60 @@ public string GetRandomAccessionNumber(Random r)

private void InitializeModalityFrequency(Random r)
{
DataTable dt = new DataTable();
dt.Columns.Add("Frequency", typeof(int));
dt.Columns.Add("AverageSeriesPerStudy", typeof(double));
dt.Columns.Add("StandardDeviationSeriesPerStudy", typeof(double));
dt.Columns.Add("AverageImagesPerSeries", typeof(double));
dt.Columns.Add("StandardDeviationImagesPerSeries", typeof(double));

DicomDataGenerator.EmbeddedCsvToDataTable(typeof(DicomDataGenerator), "DicomDataGeneratorModalities.csv",dt);

ModalityFrequency = new BucketList<ModalityStats>();

int idx=0;
foreach(DataRow dr in dt.Rows)
using (DataTable dt = new DataTable())
{
string modality = (string)dr["Modality"];
ModalityFrequency.Add((int) dr["Frequency"],
new ModalityStats(
modality,
(double)dr["AverageSeriesPerStudy"],
(double)dr["StandardDeviationSeriesPerStudy"],
(double)dr["AverageImagesPerSeries"],
(double)dr["StandardDeviationImagesPerSeries"],
r
));

ModalityIndexes.Add(modality,idx++);

dt.Columns.Add("Frequency", typeof(int));
dt.Columns.Add("AverageSeriesPerStudy", typeof(double));
dt.Columns.Add("StandardDeviationSeriesPerStudy", typeof(double));
dt.Columns.Add("AverageImagesPerSeries", typeof(double));
dt.Columns.Add("StandardDeviationImagesPerSeries", typeof(double));

DicomDataGenerator.EmbeddedCsvToDataTable(typeof(DicomDataGenerator), "DicomDataGeneratorModalities.csv", dt);

ModalityFrequency = new BucketList<ModalityStats>();

int idx = 0;
foreach (DataRow dr in dt.Rows)
{
string modality = (string)dr["Modality"];
ModalityFrequency.Add((int)dr["Frequency"],
new ModalityStats(
modality,
(double)dr["AverageSeriesPerStudy"],
(double)dr["StandardDeviationSeriesPerStudy"],
(double)dr["AverageImagesPerSeries"],
(double)dr["StandardDeviationImagesPerSeries"],
r
));

ModalityIndexes.Add(modality, idx++);
}
}

}

private void InitializeTagValuesByModalityAndTag()
{
DataTable dt = new DataTable();
dt.Columns.Add("Frequency", typeof(int));

DicomDataGenerator.EmbeddedCsvToDataTable(typeof(DicomDataGenerator), "DicomDataGeneratorTags.csv",dt);

foreach (DataRow dr in dt.Rows)
using (DataTable dt = new DataTable())
{
var modality = (string)dr["Modality"];
var tag = DicomDictionary.Default[(string) dr["Tag"]];
dt.Columns.Add("Frequency", typeof(int));

DicomDataGenerator.EmbeddedCsvToDataTable(typeof(DicomDataGenerator), "DicomDataGeneratorTags.csv", dt);

foreach (DataRow dr in dt.Rows)
{
var modality = (string)dr["Modality"];
var tag = DicomDictionary.Default[(string)dr["Tag"]];

if(!TagValuesByModalityAndTag.ContainsKey(modality))
TagValuesByModalityAndTag.Add(modality,new Dictionary<DicomTag, BucketList<string>>());
if (!TagValuesByModalityAndTag.ContainsKey(modality))
TagValuesByModalityAndTag.Add(modality, new Dictionary<DicomTag, BucketList<string>>());

if(!TagValuesByModalityAndTag[modality].ContainsKey(tag))
TagValuesByModalityAndTag[modality].Add(tag,new BucketList<string>());
if (!TagValuesByModalityAndTag[modality].ContainsKey(tag))
TagValuesByModalityAndTag[modality].Add(tag, new BucketList<string>());

int frequency = (int) dr["Frequency"];
TagValuesByModalityAndTag[modality][tag].Add(frequency,(string)dr["Value"]);
int frequency = (int)dr["Frequency"];
TagValuesByModalityAndTag[modality][tag].Add(frequency, (string)dr["Value"]);
}
}
}

Expand Down
45 changes: 24 additions & 21 deletions BadMedicine.Dicom/PixelDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace BadMedicine.Dicom
{
/// <summary>
/// Handels drawing image data directly into the dicom file
/// Handles drawing image data directly into the dicom file
/// </summary>
internal class PixelDrawer
{
Expand All @@ -18,30 +18,33 @@ internal class PixelDrawer

internal void DrawBlackBoxWithWhiteText(DicomDataset ds, int width, int height, string msg)
{
var bitmap = new Bitmap(500,500);
using(var g = Graphics.FromImage(bitmap))
using (var bitmap = new Bitmap(500, 500))
{
g.FillRectangle(blackBrush,0,0,width,height);
g.DrawString(msg,new Font(FontFamily.GenericMonospace,12),whiteBrush,250,100);
}

byte[] pixels = GetPixels(bitmap, out int rows, out int columns);
MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);

ds.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation .Rgb .Value );
ds.Add(DicomTag.Rows, (ushort)rows);
ds.Add(DicomTag.Columns, (ushort)columns);
ds.Add(DicomTag.BitsAllocated,(ushort)8);
using (var g = Graphics.FromImage(bitmap))
{
g.FillRectangle(blackBrush, 0, 0, width, height);
using (var font = new Font(FontFamily.GenericMonospace, 12))
g.DrawString(msg, font, whiteBrush, 250, 100);
}

byte[] pixels = GetPixels(bitmap, out int rows, out int columns);
MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);

DicomPixelData pixelData = DicomPixelData.Create(ds, true);
pixelData.BitsStored = 8;
pixelData.SamplesPerPixel = 3;
pixelData.HighBit = 7;
pixelData.PixelRepresentation = 0;
pixelData.PlanarConfiguration = 0;
pixelData.AddFrame(buffer);
ds.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb.Value);
ds.Add(DicomTag.Rows, (ushort)rows);
ds.Add(DicomTag.Columns, (ushort)columns);
ds.Add(DicomTag.BitsAllocated, (ushort)8);

DicomPixelData pixelData = DicomPixelData.Create(ds, true);
pixelData.BitsStored = 8;
pixelData.SamplesPerPixel = 3;
pixelData.HighBit = 7;
pixelData.PixelRepresentation = 0;
pixelData.PlanarConfiguration = 0;
pixelData.AddFrame(buffer);
}
}

private static byte[] GetPixels(Bitmap image, out int rows, out int columns)
{
rows = image.Height;
Expand Down
7 changes: 4 additions & 3 deletions Packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
| Package | Source Code | Version | License | Purpose | Additional Risk Assessment |
| ------- | ------------| --------| ------- | ------- | -------------------------- |
| HIC.BadMedicine | [GitHub](https://github.com/HicServices/BadMedicine) | [0.1.6](https://www.nuget.org/packages/HIC.BadMedicine/0.1.6) | [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.html) | Handles generating baseline random data (patient date of birth, CHI numberts etc)| |
| fo-dicom.NetCore | [GitHub](https://github.com/fo-dicom/fo-dicom) |[4.0.5](https://www.nuget.org/packages/fo-dicom.NetCore/4.0.5)|[MS-PL](https://opensource.org/licenses/MS-PL) | Handles reading/writing dicom tags from dicom datasets | |
| fo-dicom.NetCore | [GitHub](https://github.com/fo-dicom/fo-dicom) |[4.0.6](https://www.nuget.org/packages/fo-dicom.NetCore/4.0.6)|[MS-PL](https://opensource.org/licenses/MS-PL) | Handles reading/writing dicom tags from dicom datasets | |
| Microsoft.SourceLink.GitHub | [GitHub](https://github.com/dotnet/sourcelink) | [1.0.0](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub/1.0.0) | [Apache License 2.0](https://github.com/dotnet/sourcelink/blob/master/License.txt) | Enables source debugging of project nuget package| |
| Microsoft.NETCore.App | [GitHub](https://github.com/dotnet/runtime) | [2.2.8](https://www.nuget.org/packages/Microsoft.NETCore.App/2.2.8) |[MIT](https://opensource.org/licenses/MIT) | | .Net Core API|
| System.Drawing.Common | [GitHub](https://github.com/dotnet/corefx) | [4.7.0](https://www.nuget.org/packages/System.Drawing.Common/4.7.0) |[MIT](https://opensource.org/licenses/MIT) | Enables working with Bitmap resources | |
| HIC.DicomTypeTranslation | [GitHub](https://github.com/HicServices/DicomTypeTranslation) | [2.2.2](https://www.nuget.org/packages/HIC.DicomTypeTranslation/2.2.2) | [GPL 3.0](https://github.com/HicServices/DicomTypeTranslation/blob/master/LICENSE) | | |
| YamlDotNet | [GitHub](https://github.com/aaubry/YamlDotNet) | [8.1.1](https://www.nuget.org/packages/YamlDotNet/8.1.1) | [MIT](https://opensource.org/licenses/MIT) |Loading configuration files|
| HIC.DicomTypeTranslation | [GitHub](https://github.com/HicServices/DicomTypeTranslation) | [2.3.1](https://www.nuget.org/packages/HIC.DicomTypeTranslation/2.3.1) | [GPL 3.0](https://github.com/HicServices/DicomTypeTranslation/blob/master/LICENSE) | | |
| YamlDotNet | [GitHub](https://github.com/aaubry/YamlDotNet) | [8.1.2](https://www.nuget.org/packages/YamlDotNet/8.1.2) | [MIT](https://opensource.org/licenses/MIT) |Loading configuration files|
| CommandLineParser | [GitHub](https://github.com/commandlineparser/commandline) | [2.8.0](https://www.nuget.org/packages/CommandLineParser/2.8.0) | [MIT](https://opensource.org/licenses/MIT) | Allows command line arguments for main client application and CLI executables |
| [Nunit](https://nunit.org/) |[GitHub](https://github.com/nunit/nunit) | [3.12.0](https://www.nuget.org/packages/NUnit/3.12.0) | [MIT](https://opensource.org/licenses/MIT) | Unit testing |
| NUnit3TestAdapter | [GitHub](https://github.com/nunit/nunit3-vs-adapter)| [3.16.1](https://www.nuget.org/packages/NUnit3TestAdapter/3.16.1) | [MIT](https://opensource.org/licenses/MIT) | Run unit tests from within Visual Studio |
Expand Down

0 comments on commit d8123ae

Please sign in to comment.