def test_match_exact_single_phrase_begin_and_end(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], self.rpdr_note, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) phrase_match = phrase_matches[0] self.assertEqual(1, phrase_match.extracted_value)
def test_match_space_surround2(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, ' ventilate ') note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) phrase_match = phrase_matches[0] self.assertEqual(1, phrase_match.extracted_value)
def test_extract_date_one_digit_day(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, 'date is 2-2-22') note_phrase_matches = extract_values._extract_phrase_from_notes( 2, ['date'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) self.assertEqual('2-2-22', phrase_matches[0].extracted_value)
def test_extract_numerical(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, 'ef 2.0') note_phrase_matches = extract_values._extract_phrase_from_notes( 1, ['ef'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) self.assertEqual(2.0, phrase_matches[0].extracted_value)
def test_match_beginning_punctuation_ignore_true(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, 'ventilate.') rpdr_note2.remove_punctuation_from_note() note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) phrase_match = phrase_matches[0] self.assertEqual(1, phrase_match.extracted_value)
def test_many_matches_same_phrase(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, 'ventilate ventilate alex alex alex ventilate, ventilate alex') note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(4, len(phrase_matches)) for phrase_match in phrase_matches: self.assertEqual(1, phrase_match.extracted_value)
def test_multiple_matches_different_phrase(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( {'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1'}, 'ventilate g-tube') note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate', 'g-tube'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(2, len(phrase_matches)) self.assertEqual(0, phrase_matches[0].match_start) self.assertEqual(10, phrase_matches[0].match_end) for phrase_match in phrase_matches: self.assertEqual(1, phrase_match.extracted_value)
def test_match_beginning_punctuation2(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( { 'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1' }, 'ventilate?') note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) phrase_match = phrase_matches[0] self.assertEqual(1, phrase_match.extracted_value)
def test_extract_multiple_numerical_multiple_phrases(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( { 'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1' }, 'ef 2.0 alex alex ef 20.0 alex ejection fraction 4.0') note_phrase_matches = extract_values._extract_phrase_from_notes( 1, ['ef', 'ejection fraction'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(3, len(phrase_matches)) self.assertEqual(2.0, phrase_matches[0].extracted_value) self.assertEqual(20.0, phrase_matches[1].extracted_value) self.assertEqual(4.0, phrase_matches[2].extracted_value)
def test_match_surrounded_by_punctuation_ignore_true_no_space(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( { 'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1' }, '(ventilate).') rpdr_note2.remove_punctuation_from_note() note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(1, len(phrase_matches)) phrase_match = phrase_matches[0] self.assertEqual(1, phrase_match.extracted_value)
def test_multiple_matches_different_phrase(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) rpdr_note2 = extract_values.RPDRNote( { 'EMPI': 'empi1', 'MRN_Type': 'mrn_type1', 'Report_Number': '1231', 'MRN': '1231', 'Report_Type': 'report_type1', 'Report_Description': 'report_description1' }, 'ventilate g-tube') note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['ventilate', 'g-tube'], rpdr_note2, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(2, len(phrase_matches)) self.assertEqual(0, phrase_matches[0].match_start) self.assertEqual(10, phrase_matches[0].match_end) for phrase_match in phrase_matches: self.assertEqual(1, phrase_match.extracted_value)
def test_dont_match_in_middle_of_longer_word(self): phrase_match_context = extract_values.PhraseMatchContexts(0, 0) note_phrase_matches = extract_values._extract_phrase_from_notes( 0, ['tila'], self.rpdr_note, phrase_match_context) phrase_matches = note_phrase_matches.phrase_matches self.assertEqual(0, len(phrase_matches))