Esempio n. 1
0
    def test_has_enrollments(self, req, db_session, config, check_csrf_token):
        """
        It should not allow deletion of a study if it has enrollments
        (unless administrator)
        """
        from datetime import date
        from pyramid.httpexceptions import HTTPForbidden
        from occams_studies import models

        study = models.Study(name=u'somestudy',
                             title=u'Some Study',
                             short_title=u'sstudy',
                             code=u'000',
                             consent_date=date.today())

        enrollment = models.Enrollment(study=study,
                                       consent_date=date.today(),
                                       patient=models.Patient(site=models.Site(
                                           name='ucsd', title=u'UCSD'),
                                                              pid=u'12345'))

        db_session.add_all([study, enrollment])
        db_session.flush()

        # Should not be able to delete if not an admin
        config.testing_securitypolicy(permissive=False)
        with pytest.raises(HTTPForbidden):
            self._call_fut(study, req)

        config.testing_securitypolicy(permissive=True)
        self._call_fut(study, req)
        assert 0 == db_session.query(models.Study).count()
Esempio n. 2
0
    def test_by_enrollment_number(self, req, db_session):
        """
        It should be able to search by Enrollment Number
        """
        from datetime import date
        from occams_studies import models
        from webob.multidict import MultiDict

        study = models.Study(name=u'somestudy',
                             title=u'Some Study',
                             short_title=u'sstudy',
                             code=u'000',
                             consent_date=date.today())
        site_la = models.Site(name=u'la', title=u'LA')
        patient = models.Patient(site=site_la,
                                 pid=u'12345',
                                 enrollments=[
                                     models.Enrollment(
                                         study=study,
                                         reference_number=u'xyz',
                                         consent_date=date.today())
                                 ])
        db_session.add_all([site_la, patient])
        db_session.flush()

        req.GET = MultiDict([('query', u'xyz')])
        res = self._call_fut(models.PatientFactory(req), req)
        assert patient.pid == res['patients'][0]['pid']
Esempio n. 3
0
    def test_data_with_early_test(self, db_session, study_code):
        """
        It should output earlytest ids (for backwards-compatibilty)
        """
        from datetime import date
        from occams_studies import models

        plan = self._create_one(db_session)

        patient = models.Patient(
            pid=u'xxx-xxx',
            site=models.Site(name=u'someplace', title=u'Some Place'),
            enrollments=[
                models.Enrollment(consent_date=date.today(),
                                  reference_number=u'76C000000',
                                  study=models.Study(name=u'some_study',
                                                     code=study_code,
                                                     consent_date=date.today(),
                                                     short_title=u'smstdy',
                                                     title=u'Some Study'))
            ])

        db_session.add(patient)

        query = plan.data()
        data = query.one()._asdict()
        assert data['early_id'] == patient.enrollments[0].reference_number
Esempio n. 4
0
    def test_enrollment(self, db_session):
        """
        It should add enrollment-specific metadata to the report
        """
        from datetime import date, timedelta
        from occams_datastore import models as datastore
        from occams_studies import models
        from occams_studies.exports.schema import SchemaPlan

        schema = datastore.Schema(name=u'termination',
                                  title=u'Termination',
                                  publish_date=date.today(),
                                  attributes={
                                      'foo':
                                      datastore.Attribute(
                                          name='foo',
                                          title=u'',
                                          type='string',
                                          order=0,
                                      )
                                  })
        entity = datastore.Entity(schema=schema, collect_date=date.today())
        patient = models.Patient(site=models.Site(name='ucsd', title=u'UCSD'),
                                 pid=u'12345',
                                 entities=[entity])
        study = models.Study(name=u'cooties',
                             short_title=u'CTY',
                             code=u'999',
                             consent_date=date.today() - timedelta(365),
                             title=u'Cooties')
        enrollment = models.Enrollment(
            patient=patient,
            study=study,
            consent_date=date.today() - timedelta(5),
            latest_consent_date=date.today() - timedelta(3),
            termination_date=date.today(),
            entities=[entity])
        db_session.add_all([schema, entity, patient, study, enrollment])

        plan = SchemaPlan.from_schema(db_session, schema.name)
        codebook = list(plan.codebook())
        query = plan.data()
        codebook_columns = [c['field'] for c in codebook]
        data_columns = [c['name'] for c in query.column_descriptions]
        record = query.one()
        assert sorted(codebook_columns) == sorted(data_columns)
        assert record.site == patient.site.name
        assert record.pid == patient.pid
        assert record.enrollment == enrollment.study.name
        assert record.enrollment_ids == str(enrollment.id)
        assert record.visit_cycles is None
        assert record.collect_date == entity.collect_date
Esempio n. 5
0
    def populate(self, app, db_session):
        import transaction
        from occams_studies import models as studies
        from occams_datastore import models as datastore
        from datetime import date

        # Any view-dependent data goes here
        # Webtests will use a different scope for its transaction
        with transaction.manager:
            user = datastore.User(key=USERID)
            db_session.info['blame'] = user
            db_session.add(user)
            db_session.flush()
            site = studies.Site(name=u'UCSD',
                                title=u'UCSD',
                                description=u'UCSD Campus',
                                create_date=date.today())

            patient = studies.Patient(initials=u'ian',
                                      nurse=u'*****@*****.**',
                                      site=site,
                                      pid=u'123')

            form = datastore.Schema(name=u'test_schema',
                                    title=u'test_title',
                                    publish_date=date(2015, 1, 1))

            study = studies.Study(name=u'test_study',
                                  code=u'test_code',
                                  consent_date=date(2014, 12, 23),
                                  is_randomized=False,
                                  title=u'test_title',
                                  short_title=u'test_short',
                                  schemata=set([form]))

            state = (db_session.query(
                datastore.State).filter_by(name=u'pending-entry').one())

            db_session.add(
                datastore.Entity(state=state,
                                 schema=form,
                                 collect_date=date(2015, 2, 1)))

            db_session.add(
                studies.Enrollment(patient=patient,
                                   study=study,
                                   consent_date=date(2014, 12, 22)))
Esempio n. 6
0
    def test_cascade_forms(self, req, db_session, check_csrf_token):
        """
        It should remove all visit-associated forms.
        """
        from datetime import date
        from occams_datastore import models as datastore
        from occams_studies import models

        schema = datastore.Schema(name=u'sample',
                                  title=u'Some Sample',
                                  publish_date=date.today())

        study = models.Study(name=u'somestudy',
                             title=u'Some Study',
                             short_title=u'sstudy',
                             code=u'000',
                             consent_date=date.today())

        cycle = models.Cycle(name=u'week-10', title=u'Week 10', week=10)

        study.cycles.append(cycle)

        patient = models.Patient(site=models.Site(name=u'ucsd', title=u'UCSD'),
                                 pid=u'12345')

        enrollment = models.Enrollment(study=study,
                                       patient=patient,
                                       consent_date=date.today())

        visit = models.Visit(patient=patient,
                             cycles=[cycle],
                             visit_date=date.today())

        visit.entities.add(
            datastore.Entity(schema=schema, collect_date=date.today()))

        db_session.add_all([patient, enrollment, study, visit])
        db_session.flush()

        visit_id = visit.id

        self._call_fut(visit, req)

        assert db_session.query(models.Visit).get(visit_id) is None
        assert 0 == db_session.query(datastore.Entity).count()
Esempio n. 7
0
    def test_has_visits(self, req, db_session, config):
        """
        It should not allow deletion of a cycle if it has visit
        (unless administrator)
        """
        from datetime import date
        from pyramid.httpexceptions import HTTPForbidden
        from occams_studies import models

        cycle = models.Cycle(name='week-1', title=u'Week 1', week=1)

        study = models.Study(name=u'somestudy',
                             title=u'Some Study',
                             short_title=u'sstudy',
                             code=u'000',
                             consent_date=date.today(),
                             cycles=[cycle])

        patient = models.Patient(site=models.Site(name='ucsd', title=u'UCSD'),
                                 pid=u'12345')

        enrollment = models.Enrollment(study=study,
                                       consent_date=date.today(),
                                       patient=patient)

        visit = models.Visit(patient=patient,
                             visit_date=date.today(),
                             cycles=[cycle])

        db_session.add_all([study, enrollment, visit])
        db_session.flush()

        # Should not be able to delete if not an admin
        config.testing_securitypolicy(permissive=False)
        with pytest.raises(HTTPForbidden):
            self._call_fut(cycle, req)

        config.testing_securitypolicy(permissive=True)
        self._call_fut(cycle, req)
        assert 0 == study.cycles.count()
Esempio n. 8
0
    def populate(self, app, db_session):
        import transaction
        from occams_studies import models as studies
        from occams_datastore import models as datastore
        from datetime import date

        # Any view-dependent data goes here
        # Webtests will use a different scope for its transaction
        with transaction.manager:
            user = datastore.User(key=USERID)
            db_session.info['blame'] = user
            db_session.add(user)
            db_session.flush()
            site = studies.Site(name=u'UCSD',
                                title=u'UCSD',
                                description=u'UCSD Campus',
                                create_date=date.today())

            patient = studies.Patient(initials=u'ian',
                                      nurse=u'*****@*****.**',
                                      site=site,
                                      pid=u'123')

            study = studies.Study(
                name=u'test_study',
                code=u'test_code',
                consent_date=date(2014, 12, 23),
                is_randomized=False,
                title=u'test_title',
                short_title=u'test_short',
            )

            db_session.add(
                studies.Enrollment(patient=patient,
                                   study=study,
                                   consent_date=date(2014, 12, 22)))
Esempio n. 9
0
    def test_rand(self, db_session):
        """
        It should add randomization-specific metadata to the report
        """
        from datetime import date, timedelta
        from occams_datastore import models as datastore
        from occams_studies import models
        from occams_studies.exports.schema import SchemaPlan

        schema = datastore.Schema(name=u'vitals',
                                  title=u'Vitals',
                                  publish_date=date.today(),
                                  attributes={
                                      'foo':
                                      datastore.Attribute(
                                          name='foo',
                                          title=u'',
                                          type='string',
                                          order=0,
                                      )
                                  })
        entity = datastore.Entity(collect_date=date.today(), schema=schema)
        patient = models.Patient(site=models.Site(name='ucsd', title=u'UCSD'),
                                 pid=u'12345',
                                 entities=[entity])
        study = models.Study(name=u'study1',
                             short_title=u'S1',
                             code=u'001',
                             consent_date=date.today() - timedelta(365),
                             title=u'Study 1')
        armga = models.Arm(name=u'groupa', title=u'GROUP A', study=study)
        stratum = models.Stratum(study=study,
                                 arm=armga,
                                 block_number=12384,
                                 randid=u'8484',
                                 patient=patient,
                                 entities=[entity])
        enrollment = models.Enrollment(
            patient=patient,
            study=study,
            consent_date=date.today() - timedelta(5),
            latest_consent_date=date.today() - timedelta(3),
            termination_date=date.today(),
            entities=[entity])
        db_session.add_all([schema, entity, patient, enrollment, stratum])
        db_session.flush()

        plan = SchemaPlan.from_schema(db_session, schema.name)
        codebook = list(plan.codebook())
        query = plan.data()
        codebook_columns = [c['field'] for c in codebook]
        data_columns = [c['name'] for c in query.column_descriptions]
        record = query.one()
        assert sorted(codebook_columns) == sorted(data_columns)
        assert record.site == patient.site.name
        assert record.pid == patient.pid
        assert record.enrollment == enrollment.study.name
        assert record.enrollment_ids == str(enrollment.id)
        assert record.collect_date == entity.collect_date
        assert record.block_number == stratum.block_number
        assert record.arm_name == stratum.arm.title
        assert record.randid == stratum.randid