def test_duplicate_identifier(self):
        swagger_spec = swagger(self.app)
        identifier = Identifier(system='https://unique.org', value='abc123')
        data = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data['identifier'] = identifier.as_fhir()

        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data)
        assert response.status_code == 200

        # Submit a second, with the same identifier, expect error
        data2 = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data2['identifier'] = identifier.as_fhir()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data2)
        assert response.status_code == 409
        self.test_user = db.session.merge(self.test_user)
        assert self.test_user.questionnaire_responses.count() == 1

        # And a third, with just the id.value changed
        data3 = swagger_spec['definitions']['QuestionnaireResponse']['example']
        identifier.value = 'do-over'
        data3['identifier'] = identifier.as_fhir()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data3)
        assert response.status_code == 200
        self.test_user = db.session.merge(self.test_user)
        assert self.test_user.questionnaire_responses.count() == 2
Ejemplo n.º 2
0
    def test_duplicate_identifier(self):
        swagger_spec = swagger(self.app)
        identifier = Identifier(system='https://unique.org', value='abc123')
        data = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data['identifier'] = identifier.as_fhir()

        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data)
        assert response.status_code == 200

        # Submit a second, with the same identifier, expect error
        data2 = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data2['identifier'] = identifier.as_fhir()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data2)
        assert response.status_code == 409
        self.test_user = db.session.merge(self.test_user)
        assert self.test_user.questionnaire_responses.count() == 1

        # And a third, with just the id.value changed
        data3 = swagger_spec['definitions']['QuestionnaireResponse']['example']
        identifier.value = 'do-over'
        data3['identifier'] = identifier.as_fhir()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data3)
        assert response.status_code == 200
        self.test_user = db.session.merge(self.test_user)
        assert self.test_user.questionnaire_responses.count() == 2
Ejemplo n.º 3
0
    def test_organization_identifiers_update(self):
        with open(
                os.path.join(os.path.dirname(__file__),
                             'organization-example-gastro.json'),
                'r') as fhir_data:
            data = json.load(fhir_data)
        self.promote_user(role_name=ROLE.ADMIN.value)
        self.login()
        before = Organization.query.count()
        response = self.client.post('/api/organization',
                                    content_type='application/json',
                                    data=json.dumps(data))
        assert response.status_code == 200
        assert Organization.query.count() == before + 1

        # the gastro file contains a single identifier - add
        # a second one and PUT, expecting we get two total

        alias = Identifier(system=SHORTCUT_ALIAS,
                           value='foobar',
                           use='secondary')
        org = Organization.query.filter_by(name='Gastroenterology').one()
        data['identifier'].append(alias.as_fhir())
        response = self.client.put('/api/organization/{}'.format(org.id),
                                   content_type='application/json',
                                   data=json.dumps(data))
        assert response.status_code == 200

        # obtain the org from the db, check the identifiers
        org = Organization.query.filter_by(name='Gastroenterology').one()
        assert 2 == org.identifiers.count()
    def test_organization_identifiers_update(self):
        with open(os.path.join(
            os.path.dirname(__file__),
            'organization-example-gastro.json'), 'r'
        ) as fhir_data:
            data = json.load(fhir_data)
        self.promote_user(role_name=ROLE.ADMIN.value)
        self.login()
        before = Organization.query.count()
        response = self.client.post(
            '/api/organization', content_type='application/json',
            data=json.dumps(data))
        assert response.status_code == 200
        assert Organization.query.count() == before + 1

        # the gastro file contains a single identifier - add
        # a second one and PUT, expecting we get two total

        alias = Identifier(system=SHORTCUT_ALIAS, value='foobar',
                           use='secondary')
        org = Organization.query.filter_by(name='Gastroenterology').one()
        data['identifier'].append(alias.as_fhir())
        response = self.client.put(
            '/api/organization/{}'.format(org.id),
            content_type='application/json', data=json.dumps(data))
        assert response.status_code == 200

        # obtain the org from the db, check the identifiers
        org = Organization.query.filter_by(name='Gastroenterology').one()
        assert 2 == org.identifiers.count()
    def test_invalid_identifier(self):
        swagger_spec = swagger(self.app)
        identifier = Identifier(system=None, value='abc-123')
        data = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data['identifier'] = identifier.as_fhir()

        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data)
        assert response.status_code == 400
Ejemplo n.º 6
0
    def test_invalid_identifier(self):
        swagger_spec = swagger(self.app)
        identifier = Identifier(system=None, value='abc-123')
        data = swagger_spec['definitions']['QuestionnaireResponse']['example']
        data['identifier'] = identifier.as_fhir()

        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        response = self.client.post(
            '/api/patient/{}/assessment'.format(TEST_USER_ID), json=data)
        assert response.status_code == 400
Ejemplo n.º 7
0
 def test_ident_search(self):
     ident = Identifier(system='http://example.com', value='testy')
     ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
     with SessionScope(db):
         db.session.add(ident)
         db.session.add(ui)
         db.session.commit()
     self.promote_user(role_name=ROLE.PATIENT)
     self.login()
     ident = db.session.merge(ident)
     rv = self.client.get('/api/patient?identifier={}'.format(
         json.dumps(ident.as_fhir())),
                          follow_redirects=True)
     self.assert200(rv)
Ejemplo n.º 8
0
 def test_ident_nomatch_search(self):
     ident = Identifier(system='http://example.com', value='testy')
     ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
     with SessionScope(db):
         db.session.add(ident)
         db.session.add(ui)
         db.session.commit()
     self.promote_user(role_name=ROLE.PATIENT)
     self.login()
     ident = db.session.merge(ident)
     # modify the system to mis match
     id_str = json.dumps(ident.as_fhir()).replace("example.com",
                                                  "wrong-system.com")
     rv = self.client.get('/api/patient?identifier={}'.format(id_str),
                          follow_redirects=True)
     self.assert404(rv)
    def test_site_ids(self):
        # bless org w/ expected identifier type
        wanted_system = 'http://pcctc.org/'
        unwanted_system = 'http://other.org/'
        self.app.config['REPORTING_IDENTIFIER_SYSTEMS'] = [wanted_system]
        id_value = '146-11'
        org = Organization.query.filter(
            Organization.name == 'metastatic').one()
        id1 = Identifier(
            system=wanted_system, use='secondary', value=id_value)
        id2 = Identifier(
            system=unwanted_system, use='secondary', value=id_value)
        org.identifiers.append(id1)
        org.identifiers.append(id2)

        with SessionScope(db):
            db.session.commit()

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        mock_qr(instrument_id=instrument_id)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        id1 = db.session.merge(id1)
        assert 1 == len(bundle['entry'])
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider']))
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider'][0]
                    ['identifier']))
        assert (id1.as_fhir() ==
                bundle['entry'][0]['subject']['careProvider'][0]
                ['identifier'][0])
Ejemplo n.º 10
0
    def test_site_ids(self):
        # bless org w/ expected identifier type
        wanted_system = 'http://pcctc.org/'
        unwanted_system = 'http://other.org/'
        self.app.config['REPORTING_IDENTIFIER_SYSTEMS'] = [wanted_system]
        id_value = '146-11'
        org = Organization.query.filter(
            Organization.name == 'metastatic').one()
        id1 = Identifier(
            system=wanted_system, use='secondary', value=id_value)
        id2 = Identifier(
            system=unwanted_system, use='secondary', value=id_value)
        org.identifiers.append(id1)
        org.identifiers.append(id2)

        with SessionScope(db):
            db.session.commit()

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        mock_qr(instrument_id=instrument_id)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        id1 = db.session.merge(id1)
        assert 1 == len(bundle['entry'])
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider']))
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider'][0]
                    ['identifier']))
        assert (id1.as_fhir() ==
                bundle['entry'][0]['subject']['careProvider'][0]
                ['identifier'][0])
Ejemplo n.º 11
0
 def test_ident_search(self):
     ident = Identifier(system='http://example.com', value='testy')
     ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
     with SessionScope(db):
         db.session.add(ident)
         db.session.add(ui)
         db.session.commit()
     self.promote_user(role_name=ROLE.PATIENT.value)
     self.login()
     ident = db.session.merge(ident)
     response = self.client.get(
         '/api/patient/', follow_redirects=True,
         query_string={'identifier': json.dumps(ident.as_fhir()),
                       'patch_dstu2': True})
     assert response.status_code == 200
     assert response.json['resourceType'] == 'Bundle'
     assert response.json['total'] == 1
     assert (
         response.json['entry'][0]['resource'] ==
         Reference.patient(TEST_USER_ID).as_fhir())
Ejemplo n.º 12
0
 def test_ident_search(self):
     ident = Identifier(system='http://example.com', value='testy')
     ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
     with SessionScope(db):
         db.session.add(ident)
         db.session.add(ui)
         db.session.commit()
     self.promote_user(role_name=ROLE.PATIENT.value)
     self.login()
     ident = db.session.merge(ident)
     response = self.client.get('/api/patient/',
                                follow_redirects=True,
                                query_string={
                                    'identifier':
                                    json.dumps(ident.as_fhir()),
                                    'patch_dstu2': True
                                })
     assert response.status_code == 200
     assert response.json['resourceType'] == 'Bundle'
     assert response.json['total'] == 1
     assert (response.json['entry'][0]['resource'] == Reference.patient(
         TEST_USER_ID).as_fhir())
Ejemplo n.º 13
0
    def test_ident_nomatch_search(self):
        ident = Identifier(system='http://example.com', value='testy')
        ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
        with SessionScope(db):
            db.session.add(ident)
            db.session.add(ui)
            db.session.commit()
        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        ident = db.session.merge(ident)
        # modify the system to mis match
        id_str = json.dumps(ident.as_fhir()).replace(
            "example.com", "wrong-system.com")
        response = self.client.get('/api/patient/', query_string={
            'identifier': id_str,
            'patch_dstu2': True},
            follow_redirects=True)

        # expect empty bundle
        assert response.status_code == 200
        assert response.json['resourceType'] == 'Bundle'
        assert response.json['total'] == 0
Ejemplo n.º 14
0
    def test_ident_nomatch_search(self):
        ident = Identifier(system='http://example.com', value='testy')
        ui = UserIdentifier(identifier=ident, user_id=TEST_USER_ID)
        with SessionScope(db):
            db.session.add(ident)
            db.session.add(ui)
            db.session.commit()
        self.promote_user(role_name=ROLE.PATIENT.value)
        self.login()
        ident = db.session.merge(ident)
        # modify the system to mis match
        id_str = json.dumps(ident.as_fhir()).replace("example.com",
                                                     "wrong-system.com")
        response = self.client.get('/api/patient/',
                                   query_string={
                                       'identifier': id_str,
                                       'patch_dstu2': True
                                   },
                                   follow_redirects=True)

        # expect empty bundle
        assert response.status_code == 200
        assert response.json['resourceType'] == 'Bundle'
        assert response.json['total'] == 0