File size: 2,544 Bytes
1a3b3aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
from outcome_switch.ctgov import find_nctid, get_registry_outcomes, reformat_outcomes


_EMPTY_STRING = ""
# NCT REGEX extraction tests
_TEXT_WITH_ONE_NCT = """blablabla nct id is NCT04647656 blabla"""
_TEXT_WITH_TWO_NCT = """blablabla nct id is NCT04647656 blabla NCT06562582 bla"""
_TEXT_WITHOUT_NCT = "blablabla blablabla"

# NCT REGISTRY API tests
_CORRECT_NCT = "NCT04647656"
_INCORRECT_NCT = "PRN03216548"

# REGISTRY outcomes reformatting test
_CTGOV_OUTCOMES = {
    "primaryOutcomes": [
        {
            "measure": "Cognitive health assessment (NeuroTrax)",
            "description": "Memory, attention and information process will be evaluated using the NeuroTrax computerized cognitive evaluation battery.",
            "timeFrame": "Baseline, 2 months",
        }
    ],
    "secondaryOutcomes": [
        {
            "measure": "Brain perfusion",
            "description": "Cerebral blood volume and flow will be measured using perfusion MRI protocol Dynamic susceptibility contrast (DSC).",
            "timeFrame": "Baseline, 2 months",
        }
    ],
}

class NctidFinderTest(unittest.TestCase) :

    def test_text_with_one_nct(self):
        self.assertEqual(find_nctid(_TEXT_WITH_ONE_NCT), "NCT04647656")
    
    def test_text_with_two_nct(self):
        self.assertEqual(find_nctid(_TEXT_WITH_TWO_NCT), "NCT04647656")
    
    def test_text_without_nct(self):
        self.assertIsNone(find_nctid(_TEXT_WITHOUT_NCT))
    
    def test_empty_string(self):
        self.assertIsNone(find_nctid(_EMPTY_STRING))
    
    def test_none_input(self):
        self.assertIsNone(find_nctid(None))

class CtgovExtractionTest(unittest.TestCase) :
    
    def test_correct_nct(self):
        self.assertIsNotNone(get_registry_outcomes(_CORRECT_NCT))
    
    def test_incorrect_nct(self):
        self.assertIsNone(get_registry_outcomes(_INCORRECT_NCT))
    
    def test_empty_string(self):
        self.assertIsNone(get_registry_outcomes(_EMPTY_STRING))

class CtgovReformatTest(unittest.TestCase) :

    def test_correct_reformat_outcomes(self):
        self.assertIsInstance(reformat_outcomes(_CTGOV_OUTCOMES), list)
        self.assertEqual(len(reformat_outcomes(_CTGOV_OUTCOMES)), 2)
        self.assertIsInstance(reformat_outcomes(_CTGOV_OUTCOMES)[0], dict)
        self.assertIsInstance(reformat_outcomes(_CTGOV_OUTCOMES)[1], dict)
        self.assertEqual(reformat_outcomes(_CTGOV_OUTCOMES)[0]["type"], "primary")
        self.assertEqual(reformat_outcomes(_CTGOV_OUTCOMES)[1]["type"], "secondary")