def test_from_string_content(self): with open( os.path.join(os.path.dirname(__file__), 'fixtures', 'NCT00985114.xml'), 'rb') as fh: content = fh.read() study = ClinicalStudy.from_content(content) self.assertEqual('NCT00985114', study.nct_id)
def test_local_file_remote_schema(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema study = ClinicalStudy.from_file( os.path.join(os.path.dirname(__file__), 'fixtures', 'NCT00985114.xml')) donk.assert_called() self.assertEqual('NCT00985114', study.nct_id)
def get_study(self, nct_id): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(nct_id) study = ClinicalStudy.from_nctid(nct_id) return study
def test_parsed_exclusion_534(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get('NCT02536534') study = ClinicalStudy.from_nctid('NCT02536534') content = study.eligibility.criteria processed = process_eligibility(content) self.assertEqual(4, len(processed.get('exclusion')))
def test_study_types(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema for study_id, study_type in (('NCT02348489', 'Interventional'), ('NCT01565668', 'Interventional'), ('NCT02536534', 'Observational')): with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(study_id) study = ClinicalStudy.from_nctid(study_id) self.assertEqual(study.study_type, study_type)
def test_study_phases(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema for study_id, phase in (('NCT02348489', 'Phase 3'), ('NCT01565668', 'Phase 2'), ('NCT02536534', 'N/A')): with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(study_id) study = ClinicalStudy.from_nctid(study_id) self.assertEqual(study.phase, phase)
def test_study_conditions(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema for study_id, condition in (('NCT02348489', [ 'Leukemia, Myeloid, Acute' ]), ('NCT01565668', ['Leukemia, Myeloid, Acute']), ('NCT02536534', ['Hypertension, Pulmonary'])): with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(study_id) study = ClinicalStudy.from_nctid(study_id) self.assertEqual(study.conditions(), condition)
def test_parsed_exclusion_668(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get('NCT01565668') study = ClinicalStudy.from_nctid('NCT01565668') content = study.eligibility.criteria processed = process_eligibility(content) self.assertEqual(18, len(processed.get('exclusion'))) criterion = '- Subject has any medical, psychiatric, addictive or other kind of disorder which compromises ' \ 'the ability of the subject to give written informed consent and/or to comply with procedures' self.assertEqual(criterion, processed.get('exclusion')[-1])
def test_brief_summary(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get('NCT02536534') study = ClinicalStudy.from_nctid('NCT02536534') desc = 'Evaluate the correlation between activity level (monitored by Fitbit Flex remote activity tracker) ' \ 'and 6-minute walk distance (6MWD) (performed by investigator) in patients with Pulmonary Arterial ' \ 'Hypertension (PAH) or Chronic Thromboembolic Pulmonary Hypertension (CTEPH) over 6 months in ' \ 'routine clinical practice settings.' content = study.brief_summary self.assertEqual(desc, content)
def test_last_known_status(self): """ Test the last known status """ with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema for study_id, overall_status in (('NCT02348489', ''), ('NCT01565668', ''), ('NCT02536534', '')): with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(study_id) study = ClinicalStudy.from_nctid(study_id) self.assertEqual(study.last_known_status, overall_status)
def test_study_status(self): """ Test the Overall Status """ with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema for study_id, overall_status in (('NCT02348489', 'Active, not recruiting'), ('NCT01565668', 'Completed'), ('NCT02536534', 'Completed')): with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get(study_id) study = ClinicalStudy.from_nctid(study_id) self.assertEqual(study.status, overall_status)
def test_detailed_description(self): with mock.patch('clinical_trials.clinical_study.get_schema') as donk: donk.return_value = self.schema with mock.patch( "clinical_trials.clinical_study.get_study") as dink: dink.return_value = self.cache.get('NCT02536534') study = ClinicalStudy.from_nctid('NCT02536534') desc = "Remote patient monitoring can lead to improved patient outcomes, including improved quality of " \ "life, reduced readmissions, earlier treatment for symptoms detected prior to schedule in-office " \ "follow-up visits, improved communications with care providers, increased participation in " \ "self-management of disease, and an improved knowledge of their medical conditions . In patients " \ "with PAH, daily activity level, as measured using a physical activity monitor for seven " \ "consecutive days, correlated with 6-minute walk distance (6MWD). The monitor used in the " \ "aforementioned PAH study was positioned on the patients' right upper arm with an armband, " \ "as opposed to the more popular and more comfortable wristbands used today, such as the Fitbit " \ "Flex. Although the aforementioned PAH study did show a correlation between activity level " \ "monitoring and 6MWD, the patients were monitored for only seven days. " \ "It is still unknown whether " \ "this correlation would exist over a longer trial period and whether patients, their caregivers, " \ "and clinicians would find activity level monitoring useful in helping manage PH." content = study.detailed_description self.assertEqual(desc, content)
def build_status(status): if status in ("Active, not recruiting", "Enrolling by invitation", "Recruiting"): return 'in-progress' elif status in ("Completed"): return 'completed' elif status in ("Suspended", "Terminated"): return 'suspended' elif status in ("Terminated", "Withdrawn"): return 'stopped' else: return 'draft' if __name__ == "__main__": ct = ClinicalStudy.from_file("examples/NCT02348489.xml", local_schema=True) locations = [build_location(x) for x in ct.locations] foci = build_focus(ct.mesh_terms) print([x.as_json() for x in foci]) keywords = build_keyword(ct.keywords) print([x.as_json() for x in keywords]) identifiers = build_identifiers(ct.nct_id, ct.study_id, ct.secondary_id) print([x.as_json() for x in identifiers]) package = bundle.Bundle() package.type = "document" package.identifier = identifier.Identifier( dict(use='official', system="https://clinicaltrials.gov/ct2/show/", value=ct.nct_id)) entries = [] for location in locations:
def test_missing_file(self): with self.assertRaises(ValueError) as exc: study = ClinicalStudy.from_file("Some/missing/path") self.assertEqual("File Some/missing/path not found", str(exc.exception))
def test_local_file_local_schema(self): study = ClinicalStudy.from_file(os.path.join(os.path.dirname(__file__), 'fixtures', 'NCT00985114.xml'), local_schema=True) self.assertEqual('NCT00985114', study.nct_id)