Projects‎ > ‎nttmuClinical.NET‎ > ‎

Developers


API Reference

The nttmuClinical.NET API Reference can be accessed online directly (available at here) or be downloaded using this link.

Developer Guide

For each component of nttmuClinical.NET, we provide a unit test code to illustrate the usage of the library. The runnable example project can be download at here.

Section heading recognition

string record = I2b22014Utilities.GetRawText(@"C:\220-01.xml");
SectionRecognizer sr = SectionRecognizer.GetInstance(@"C:\sampleSet1.model", 
        @"C:\bag_dist.txt", @"C:\MedPost", @"C:\SecTag_concepts.csv");
List<SectionInfo> secInfos = sr.Recognize(record);
int expectedSectionCount = 7;
Assert.AreEqual(expectedSectionCount, secInfos.Count);

string[] expectedSectionTitles = new string[] { "Assessment and Plan", 
        "Physical Exam", "Allergies", "Medications", "Problems", 
        "Narrative History", "Record date:"};
int[,] coveredLineNumbers = new int[,] { { 117, 118, 132 }, { 113, 114, 115 },
        {103, 107,109}, {100, 97, 72}, {33, 66, 43}, {7, 12, 26}, {4, 4, 3}};
for (int i = 0; i < expectedSectionTitles.Length; i++)
{
    Assert.AreEqual(expectedSectionTitles[i], secInfos[i].Heading);
    for (int j = 0; j < coveredLineNumbers.GetLength(1); j++)
    {
        Assert.IsTrue(secInfos[i].CoveredLineNumbers.Contains(
            coveredLineNumbers[i,j]));
    }
}

Record format detection

SectionRecognizer sr = SectionRecognizer.GetInstance(@"C:\i2b22014_model", 
        @"C:\bag_dist.txt", @"C:\MedPost", @"C:\SecTag_concepts.csv");
FormatDetector fd = new FormatDetector(sr);
string record = I2b22014Utilities.GetRawText(@"C:\220-01.xml");
RecordFormat expectedFormat = RecordFormat.DischargeSummary;
Assert.AreEqual(expectedFormat, fd.Detect(record));
record = I2b22014Utilities.GetRawText(@"C:\228-02.xml");
expectedFormat = RecordFormat.Email;
Assert.AreEqual(expectedFormat, fd.Detect(record));

Smoking status classification

MedPost mp = new MedPost(@"C:\MedPost");
SectionRecognizer sr = SectionRecognizer.GetInstance(@"C:\i2b22014_model", 
        @"C:\bag_dist.txt", @"C:\SecTag_concepts.csv", mp);
SmokingStatusClassifier ssc = new SmokingStatusClassifier(@"C:\smokingterms.txt",        @"C:\Parser\englishPCFG.ser.gz", mp, sr);
string record = I2b22014Utilities.GetRawText(@"C:\220-01.xml");
SmokingStatus expectedStatus = SmokingStatus.Current;
Assert.AreEqual(expectedStatus, ssc.Classify(record));
record = I2b22014Utilities.GetRawText(@"C:\220-02.xml");
expectedStatus = SmokingStatus.Past;
Assert.AreEqual(expectedStatus, ssc.Classify(record));
record = I2b22014Utilities.GetRawText(@"C:\100-05.xml");
expectedStatus = SmokingStatus.Unknow;
Assert.AreEqual(expectedStatus, ssc.Classify(record));

Risk factor recognition

MedPost mp = new MedPost(@"C:\MedPost");
SectionRecognizer sr = SectionRecognizer.GetInstance(
        @"C:\i2b22014_model", 
        @"C:\bag_dist.txt", 
        @"C:\SecTag_concepts.csv", 
        mp);            
string record = I2b22014Utilities.GetRawText(@"C:\220-04.xml");
CompositeRiskFactorRecognizer recognizer = 
       new CompositeRiskFactorRecognizer(mp, sr);
Assert.IsEmpty(recognizer.Recognize(record));

// Test add
recognizer.Add(new HighBloodPressureRecognizer());
List<RiskFactorInfo> riskfactors = recognizer.Recognize(record);
int expectedRiskFactorCounts = 1; 
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
int expectedStartIndex = 3215;
int expectedEndIndex = 3236;
Indicator expectedIndicator = Indicator.HTN_HighBloodPressure;
string expectedText = "BLOOD PRESSURE 148/76";
string expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>()
    .EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);

recognizer.Add(new BMIRecognizer());
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 2;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 3215;
expectedEndIndex = 3236;
expectedIndicator = Indicator.HTN_HighBloodPressure;
expectedText = "BLOOD PRESSURE 148/76";
expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>()
    .EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);
expectedStartIndex = 3277;
expectedEndIndex = 3285;
expectedIndicator = Indicator.OBES_BMI;
expectedText = "BMI 36.3";
expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>()
    .EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>()
           .Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

RiskFactorRecognizer ldlRecognizer = new HighLDLRecognizer();
recognizer.Add(ldlRecognizer);
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 3;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 4131;
expectedEndIndex = 4161;
expectedIndicator = Indicator.HLP_LDL;
expectedText = "Cholesterol-LDL 12/16/2070 108";
expectedSection = "Health Maintenance";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

recognizer.Add(new HighA1cRecognizer());
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 4;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 4262;
expectedEndIndex = 4283;
expectedIndicator = Indicator.DM_A1C;
expectedText = "HbA1c 12/16/2070 6.50";
expectedSection = "Health Maintenance";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);


record = I2b22014Utilities.GetRawText(@"C:\221-01.xml");
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 5457;
expectedEndIndex = 5483;
expectedIndicator = Indicator.HLP_LDL;
expectedText = "LDL (Ultra)            123";
expectedSection = "LABS:";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

// Test remove
recognizer.Remove(ldlRecognizer);
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 0;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
recognizer.Add(new HighGlucoseRecognizer());
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 3062;
expectedEndIndex = 3088;
expectedIndicator = Indicator.DM_HighGlucose;
expectedText = "Glucose                157";
expectedSection = "LABS:";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>()
    .EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);


record = I2b22014Utilities.GetRawText(@"C:\243-01.xml");
recognizer.Add(new HighCholesterolRecognizer());
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 1446;
expectedEndIndex = 1454;
expectedIndicator = Indicator.HLD_CHOL;
expectedText = "been 263";
expectedSection = "PLAN:";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);


recognizer = new CompositeRiskFactorRecognizer(mp, sr);
record = I2b22014Utilities.GetRawText(@"C:\220-01.xml");
recognizer.Add(CADEventRecognizer.GetInstance(@"C:\cad_event.txt", mp));
riskfactors = recognizer.Recognize(record);
expectedRiskFactorCounts = 2;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedStartIndex = 1018;
expectedEndIndex = 1023;
expectedIndicator = Indicator.CAD_EVENT;
expectedText = "stent";
expectedSection = "Problems";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);
expectedStartIndex = 1011;
expectedEndIndex = 1015;
expectedIndicator = Indicator.CAD_EVENT;
expectedText = "SEMI";
expectedSection = "Problems";            
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

Time attribute assignment

MedPost mp = new MedPost(@"C:\MedPost");
SectionRecognizer sr = SectionRecognizer.GetInstance(@"C:\i2b22014_model", 
    @"C:\bag_dist.txt", @"C:\SecTag_concepts.csv", mp);
string record = I2b22014Utilities.GetRawText(@"C:\220-04.xml");
FormatDetector fd = new FormatDetector(sr);
RecordFormat expectedFormat = RecordFormat.DischargeSummary;
Assert.AreEqual(expectedFormat, fd.Detect(record));

CompositeRiskFactorRecognizer recognizer = 
    new CompositeRiskFactorRecognizer(mp, sr);
Assert.IsEmpty(recognizer.Recognize(record));

LexicalizedParser lp = LexicalizedParser.loadModel(
    @"C:\Parser\englishPCFG.ser.gz");
TimeAttributeAssignmentSectionStrategy sectionStrategy = 
    new TimeAttributeAssignmentSectionStrategy(mp, sr, lp);
List<RiskFactorInfo> riskfactors = sectionStrategy.Assign(record, recognizer);
Assert.IsEmpty(riskfactors);

recognizer.Add(new HighBloodPressureRecognizer());
riskfactors = sectionStrategy.Assign(record, recognizer);
int expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
int expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, 
    riskfactors.First<RiskFactorInfo>().TimeAttributes.Count);
TimeAttribute expectedTimeAttribute = TimeAttribute.DCT_DURING;
Assert.AreEqual(expectedTimeAttribute, 
    riskfactors.First<RiskFactorInfo>().TimeAttributes.First<TimeAttribute>());
int expectedStartIndex = 3215;
int expectedEndIndex = 3236;
Indicator expectedIndicator = Indicator.HTN_HighBloodPressure;
string expectedText = "BLOOD PRESSURE 148/76";
string expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, 
    riskfactors.First<RiskFactorInfo>().StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex); 
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);

recognizer.Add(new BMIRecognizer());
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 2;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_DURING;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 3215;
expectedEndIndex = 3236;
expectedIndicator = Indicator.HTN_HighBloodPressure;
expectedText = "BLOOD PRESSURE 148/76";
expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);
Assert.AreEqual(expectedDCTCounts, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.Count);
Assert.AreEqual(expectedTimeAttribute, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 3277;
expectedEndIndex = 3285;
expectedIndicator = Indicator.OBES_BMI;
expectedText = "BMI 36.3";
expectedSection = "Physical Exam";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

DateTime dct = SectionRecognizer.GetRecordDate(sr.Recognize(record), record);
string expectedDCT = "2072/7/27";
Assert.AreEqual(expectedDCT, dct.ToShortDateString());

RiskFactorRecognizer ldlRecognizer = new HighLDLRecognizer();
recognizer.Add(ldlRecognizer);
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 3;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 4131;
expectedEndIndex = 4161;
expectedIndicator = Indicator.HLP_LDL;
expectedText = "Cholesterol-LDL 12/16/2070 108";
expectedSection = "Health Maintenance";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

recognizer.Add(new HighA1cRecognizer());
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 4;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 4262;
expectedEndIndex = 4283;
expectedIndicator = Indicator.DM_A1C;
expectedText = "HbA1c 12/16/2070 6.50";
expectedSection = "Health Maintenance";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

record = I2b22014Utilities.GetRawText(@"C:\221-01.xml");
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 5457;
expectedEndIndex = 5483;
expectedIndicator = Indicator.HLP_LDL;
expectedText = "LDL (Ultra)            123";
expectedSection = "LABS:";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);

// Test remove
recognizer.Remove(ldlRecognizer);
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 0;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);

recognizer.Add(new HighGlucoseRecognizer());
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 3062;
expectedEndIndex = 3088;
expectedIndicator = Indicator.DM_HighGlucose;
expectedText = "Glucose                157";
expectedSection = "LABS:";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);


record = I2b22014Utilities.GetRawText(@"C:\243-01.xml");
recognizer.Add(new HighCholesterolRecognizer());
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 1446;
expectedEndIndex = 1454;
expectedIndicator = Indicator.HLD_CHOL;
expectedText = "been 263";
expectedSection = "PLAN:";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);


recognizer = new CompositeRiskFactorRecognizer(mp, sr);
record = I2b22014Utilities.GetRawText(@"C:\220-01.xml");
recognizer.Add(CADEventRecognizer.GetInstance(@"C:\cad_event.txt", mp));
riskfactors = sectionStrategy.Assign(record, recognizer);
expectedRiskFactorCounts = 2;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 1018;
expectedEndIndex = 1023;
expectedIndicator = Indicator.CAD_EVENT;
expectedText = "stent";
expectedSection = "Problems";
Assert.AreEqual(expectedStartIndex, riskfactors.First<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);
expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.Count);
expectedTimeAttribute = TimeAttribute.DCT_BEFORE;
Assert.AreEqual(expectedTimeAttribute, riskfactors.Last<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
expectedStartIndex = 1011;
expectedEndIndex = 1015;
expectedIndicator = Indicator.CAD_EVENT;
expectedText = "SEMI";
expectedSection = "Problems";
Assert.AreEqual(expectedStartIndex, riskfactors.Last<RiskFactorInfo>()
    .StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.Last<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.Last<RiskFactorInfo>().Indicator);
Assert.AreEqual(expectedText, riskfactors.Last<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.Last<RiskFactorInfo>()
    .SectionHeading);


MedPost mp = new MedPost(@"C:\MedPost");
SectionRecognizer sr = SectionRecognizer.GetInstance(@"C:\i2b22014_model", 
    @"C:\bag_dist.txt", @"C:\SecTag_concepts.csv", mp);
string record = I2b22014Utilities.GetRawText(@"C:\228-05.xml");
FormatDetector fd = new FormatDetector(sr);
RecordFormat expectedFormat = RecordFormat.Email;
Assert.AreEqual(expectedFormat, fd.Detect(record));

CompositeRiskFactorRecognizer recognizer = 
    new CompositeRiskFactorRecognizer(mp, sr);
Assert.IsEmpty(recognizer.Recognize(record));

TimeAttributeAssignmentParagraphStrategy paragraphStrategy = 
    new TimeAttributeAssignmentParagraphStrategy(mp, sr);
List<RiskFactorInfo> riskfactors = paragraphStrategy.Assign(record, recognizer);
Assert.IsEmpty(riskfactors);

recognizer.Add(new HighBloodPressureRecognizer());
riskfactors = paragraphStrategy.Assign(record, recognizer);
int expectedRiskFactorCounts = 1;
Assert.AreEqual(expectedRiskFactorCounts, riskfactors.Count);
int expectedDCTCounts = 1;
Assert.AreEqual(expectedDCTCounts, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.Count);
TimeAttribute expectedTimeAttribute = TimeAttribute.DCT_DURING;
Assert.AreEqual(expectedTimeAttribute, riskfactors.First<RiskFactorInfo>()
    .TimeAttributes.First<TimeAttribute>());
string expectedTimeAttributeString = "during DCT";
Assert.AreEqual(expectedTimeAttributeString, 
                StringEnum.GetStringValue(riskfactors.First<RiskFactorInfo>()
                    .TimeAttributes.First<TimeAttribute>()));
int expectedStartIndex = 1640;
int expectedEndIndex = 1658;
Indicator expectedIndicator = Indicator.HTN_HighBloodPressure;
string expectedText = "pressure is 140/60";
string expectedSection = SectionInfo.UNKNOWN;
Assert.AreEqual(expectedStartIndex, 
                riskfactors.First<RiskFactorInfo>().StartIndex);
Assert.AreEqual(expectedEndIndex, riskfactors.First<RiskFactorInfo>().EndIndex);
Assert.AreEqual(expectedIndicator, riskfactors.First<RiskFactorInfo>()
    .Indicator);
Assert.AreEqual(expectedText, riskfactors.First<RiskFactorInfo>().Text);
Assert.AreEqual(expectedSection, riskfactors.First<RiskFactorInfo>()
    .SectionHeading);

Unit Test Codes

A Nunit test project is provided for reference. The download link is here.
ċ
tmuClinical.NETTest_project.zip
(186k)
Hongjie Dai,
Aug 31, 2014, 11:11 PM
ċ
tmuClinicalNET.zip
(207k)
Hongjie Dai,
Aug 31, 2014, 9:28 PM
Comments