Skip to content

Commit a545f10

Browse files
committed
Update the schema selection procedure. Added a few additional tests.
1 parent aa1c9b2 commit a545f10

File tree

8 files changed

+250694
-62
lines changed

8 files changed

+250694
-62
lines changed

TNMStagingCSharp/Resources/Test/TNM/TNM_V13_StagingTestLarge.txt/Combined.staging.test.Large.txt

Lines changed: 250614 additions & 0 deletions
Large diffs are not rendered by default.

TNMStagingCSharp/TNMStagingCSharp/Src/Staging/CS/CsSchemaLookup.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ public class CsSchemaLookup: SchemaLookup
2020
//========================================================================================================================
2121
public CsSchemaLookup(String site, String histology): base(site, histology)
2222
{
23-
}
24-
25-
//========================================================================================================================
26-
// Constructor
27-
// @param site primary site
28-
// @param histology histology
29-
// @param discriminator ssf25
30-
//========================================================================================================================
31-
public CsSchemaLookup(String site, String histology, String discriminator): base(site, histology)
32-
{
33-
setInput(CsStagingData.SSF25_KEY, discriminator);
34-
}
35-
36-
public override ReadOnlyCollection<String> getAllowedKeys()
37-
{
38-
return _ALLOWED_KEYS;
39-
}
4023
}
24+
25+
//========================================================================================================================
26+
// Constructor
27+
// @param site primary site
28+
// @param histology histology
29+
// @param discriminator ssf25
30+
//========================================================================================================================
31+
public CsSchemaLookup(String site, String histology, String discriminator): base(site, histology)
32+
{
33+
setInput(CsStagingData.SSF25_KEY, discriminator);
34+
}
35+
36+
public override ReadOnlyCollection<String> getAllowedKeys()
37+
{
38+
return _ALLOWED_KEYS;
39+
}
40+
}
4141
}
4242

4343

TNMStagingCSharp/TNMStagingCSharp/Src/Staging/SchemaLookup.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ public SchemaLookup(Dictionary<String, String> inputs)
3131
// @param histology histology
3232
public SchemaLookup(String site, String histology)
3333
{
34-
setInput(StagingData.PRIMARY_SITE_KEY, site);
35-
setInput(StagingData.HISTOLOGY_KEY, histology);
34+
if (site != null)
35+
if (site.Length > 0)
36+
setInput(StagingData.PRIMARY_SITE_KEY, site);
37+
if (histology != null)
38+
if (histology.Length > 0)
39+
setInput(StagingData.HISTOLOGY_KEY, histology);
3640
CreateHash();
3741
}
3842

@@ -43,6 +47,13 @@ public virtual ReadOnlyCollection<String> getAllowedKeys()
4347
return null;
4448
}
4549

50+
// Return a list of keys that are set.
51+
// @return a set of keys
52+
public HashSet<String> getKeys()
53+
{
54+
return new HashSet<String>(_inputs.Keys);
55+
}
56+
4657
// Return a Map of all inputs
4758
// @return a Map of all inputs
4859
public Dictionary<String, String> getInputs()

TNMStagingCSharp/TNMStagingCSharp/Src/Staging/StagingDataProvider.cs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,22 @@ public static StagingTable initTable(StagingTable table)
199199
return table;
200200
}
201201

202+
202203
// Return true if the site is valid
203204
// @param site primary site
204205
// @return true if the side is valid
205206
public bool isValidSite(String site)
206207
{
207208
bool valid = (site != null);
208-
209209
if (valid)
210210
{
211211
ITable table = getTable(PRIMARY_SITE_TABLE);
212212
if (table == null)
213213
throw new System.InvalidOperationException("Unable to locate " + PRIMARY_SITE_TABLE + " table");
214-
214+
215215
valid = getValidSites().Contains(site);
216-
}
217-
218-
return valid;
216+
}
217+
return valid;
219218
}
220219

221220
// Return true if the histology is valid
@@ -224,7 +223,6 @@ public bool isValidSite(String site)
224223
public bool isValidHistology(String histology)
225224
{
226225
bool valid = (histology != null);
227-
228226
if (valid)
229227
{
230228
ITable table = getTable(HISTOLOGY_TABLE);
@@ -233,7 +231,6 @@ public bool isValidHistology(String histology)
233231

234232
valid = getValidHistologies().Contains(histology);
235233
}
236-
237234
return valid;
238235
}
239236

@@ -436,53 +433,22 @@ private List<StagingSchema> getSchemas(SchemaLookup lookup)
436433
// site or histology must be supplied
437434
if (site != null || histology != null)
438435
{
439-
HashSet<String> keysToMatch = new HashSet<String>();
440-
441-
if (site != null)
442-
keysToMatch.Add(StagingData.PRIMARY_SITE_KEY);
443-
if (histology != null)
444-
keysToMatch.Add(StagingData.HISTOLOGY_KEY);
445-
446436
HashSet<String> lstSchemaIds = getSchemaIds();
447437

448-
// sometimes discriminator is a default value (like 988), so first search for site/hist only match even if discriminator was supplied
438+
// loop over selection table and match using only the supplied keys
449439
foreach (String schemaId in lstSchemaIds)
450440
{
451441
StagingSchema schema = (StagingSchema)(getDefinition(schemaId));
452442

453443
if (schema.getSchemaSelectionTable() != null)
454444
{
455445
StagingTable table = (StagingTable)(getTable(schema.getSchemaSelectionTable()));
456-
if (table != null && DecisionEngineFuncs.matchTable(table, lookup.getInputs(), keysToMatch) != null)
446+
if (table != null && DecisionEngineFuncs.matchTable(table, lookup.getInputs(), lookup.getKeys()) != null)
457447
matchedSchemas.Add(schema);
458448
}
459449
}
460-
461-
// if multiple matches were found on site/hist and a discriminator was supplied, trim down the list
462-
if (hasDiscriminator && matchedSchemas.Count > 1)
463-
{
464-
List<StagingSchema> trimmedMatches = new List<StagingSchema>(20);
465-
StagingTable table = null;
466-
StagingSchema schema = null;
467-
for (int i=0; i < matchedSchemas.Count; i++)
468-
{
469-
schema = matchedSchemas[i];
470-
if (schema.getSchemaSelectionTable() != null)
471-
{
472-
table = (StagingTable)(getTable(schema.getSchemaSelectionTable()));
473-
if (table != null && DecisionEngineFuncs.matchTable(table, lookup.getInputs()) != null)
474-
{
475-
trimmedMatches.Add(schema);
476-
}
477-
}
478-
}
479-
480-
matchedSchemas = trimmedMatches;
481-
}
482-
483450
}
484451

485-
486452
return matchedSchemas;
487453
}
488454

TNMStagingCSharp/TNMStaging_UnitTestApp/Src/Staging/CS/CSSchemaLookupTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
2+
using System;
3+
using System.Collections.Generic;
34
using TNMStagingCSharp.Src.Staging.CS;
45

56

@@ -22,6 +23,14 @@ public void testDescriminator()
2223
Assert.IsTrue(lookup.hasDiscriminator());
2324
}
2425

26+
[TestMethod]
27+
public void testGetKeys()
28+
{
29+
Assert.IsTrue((new CsSchemaLookup("C629", "9100").getKeys()).SetEquals(new HashSet<String>() { "site", "hist" }));
30+
Assert.IsTrue((new CsSchemaLookup("C629", "9100", "001").getKeys()).SetEquals(new HashSet<String>() { "site", "hist", "ssf25" }));
31+
}
32+
33+
2534
[TestMethod]
2635
[ExpectedException(typeof(System.InvalidOperationException))]
2736
public void testBadKey()

TNMStagingCSharp/TNMStaging_UnitTestApp/Src/Staging/CS/CSStagingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ public void testSchemaSelection()
158158
Assert.AreEqual(138, lookup[0].getSchemaNum());
159159

160160
// test searching on only site
161-
lookup = _STAGING.lookupSchema(new CsSchemaLookup("C401", null, null));
161+
lookup = _STAGING.lookupSchema(new CsSchemaLookup("C401", null));
162162
Assert.AreEqual(5, lookup.Count);
163163

164164
// test searching on only hist
165-
lookup = _STAGING.lookupSchema(new CsSchemaLookup(null, "9702", null));
165+
lookup = _STAGING.lookupSchema(new CsSchemaLookup(null, "9702"));
166166
Assert.AreEqual(2, lookup.Count);
167167

168168
// test that searching on only ssf25 returns no results
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
using TNMStagingCSharp.Src.Staging;
6+
7+
8+
namespace TNMStaging_UnitTestApp.Src.Staging
9+
{
10+
[TestClass]
11+
public class SchemaLookupTest
12+
{
13+
[TestMethod]
14+
public void testConstructorMissingValues()
15+
{
16+
Assert.IsTrue((new SchemaLookup().getKeys()).SetEquals(new HashSet<String>()));
17+
Assert.IsTrue((new SchemaLookup(null, null).getKeys()).SetEquals(new HashSet<String>()));
18+
Assert.IsTrue((new SchemaLookup("", null).getKeys()).SetEquals(new HashSet<String>()));
19+
Assert.IsTrue((new SchemaLookup(null, "").getKeys()).SetEquals(new HashSet<String>()));
20+
Assert.IsTrue((new SchemaLookup("", "").getKeys()).SetEquals(new HashSet<String>()));
21+
22+
Assert.IsTrue((new SchemaLookup("C629", null).getKeys()).SetEquals(new HashSet<String>() { "site"}));
23+
Assert.IsTrue((new SchemaLookup("C629", "").getKeys()).SetEquals(new HashSet<String>() { "site" }));
24+
Assert.IsTrue((new SchemaLookup(null, "9100").getKeys()).SetEquals(new HashSet<String>() { "hist" }));
25+
Assert.IsTrue((new SchemaLookup("", "9100").getKeys()).SetEquals(new HashSet<String>() { "hist" }));
26+
Assert.IsTrue((new SchemaLookup("C629", "9100").getKeys()).SetEquals(new HashSet<String>() { "site", "hist" }));
27+
28+
}
29+
30+
}
31+
}

TNMStagingCSharp/TNMStaging_UnitTestApp/TNMStaging_UnitTestApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<Compile Include="Properties\AssemblyInfo.cs" />
9696
<Compile Include="Src\Staging\ExternalStagingFileDataProviderTest.cs" />
9797
<Compile Include="Src\Staging\IntegrationUtils.cs" />
98+
<Compile Include="Src\Staging\SchemaLookupTest.cs" />
9899
<Compile Include="Src\Staging\StagingDataProviderTest.cs" />
99100
<Compile Include="Src\Staging\Entities\StagingSchemaInputTest.cs" />
100101
<Compile Include="Src\Staging\StagingStringRangeTest.cs" />

0 commit comments

Comments
 (0)