def test_practioner(self): p = self.add_practitioner() p_ref = Reference.practitioner(p.id) assert p_ref.as_fhir()['display'] == 'first last' assert (p_ref.as_fhir()['reference'] == 'api/practitioner/12345?system={}'.format(US_NPI))
def test_demographicsPUT(self): # race / ethnicity require the SLOW addition of concepts to db self.add_concepts() # clinic reference requires pre-existing organization self.shallow_org_tree() (org_id, org_name), (org2_id, org2_name) = [ (org.id, org.name) for org in Organization.query.filter( Organization.id > 0).limit(2)] pract = self.add_practitioner(first_name='Indiana', last_name='Jones') pract_id = pract.id family = 'User' given = 'Test' dob = '1999-01-31' dod = '2027-12-31T09:10:00+00:00' gender = 'Male' phone = "867-5309" alt_phone = "555-5555" data = {"name": {"family": family, "given": given}, "resourceType": "Patient", "birthDate": dob, "deceasedDateTime": dod, "gender": gender, "telecom": [ { "system": "phone", "use": "mobile", "value": phone, }, { "system": "phone", "use": "home", "value": alt_phone, }, { "system": 'email', 'value': '__no_email__' }], "extension": [{ "url": "http://hl7.org/fhir/StructureDefinition/us-core-race", "valueCodeableConcept": { "coding": [{ "system": "http://hl7.org/fhir/v3/Race", "code": "1096-7"}]}}, {"url": "http://hl7.org/fhir/StructureDefinition/us-core-" "ethnicity", "valueCodeableConcept": { "coding": [{ "system": "http://hl7.org/fhir/v3/Ethnicity", "code": "2162-6"}]}} ], "careProvider": [ {"reference": "Organization/{}".format(org_id)}, {"reference": "api/organization/{}".format(org2_id)}, {"reference": "Practitioner/{}".format(pract_id)}, ] } self.login() response = self.client.put( '/api/demographics/%s' % TEST_USER_ID, content_type='application/json', data=json.dumps(data)) assert response.status_code == 200 fhir = response.json for item in fhir['telecom']: if item['system'] == 'phone': if item['use'] == 'home': assert alt_phone == item['value'] elif item['use'] == 'mobile': assert phone == item['value'] else: self.fail( 'unexpected telecom use: {}'.format(item['use'])) else: self.fail( 'unexpected telecom system: {}'.format(item['system'])) assert fhir['birthDate'] == dob assert fhir['deceasedDateTime'] == dod assert fhir['gender'] == gender.lower() assert fhir['name']['family'] == family assert fhir['name']['given'] == given # ignore added timezone and empty extensions assert 2 == len([ext for ext in fhir['extension'] if 'valueCodeableConcept' in ext]) assert 3 == len(fhir['careProvider']) assert ( Reference.practitioner(pract_id).as_fhir() in fhir['careProvider']) user = db.session.merge(self.test_user) assert user._email.startswith('__no_email__') assert user.email is None assert user.first_name == given assert user.last_name == family assert ['2162-6'] == [c.code for c in user.ethnicities] assert ['1096-7'] == [c.code for c in user.races] assert len(user.organizations) == 2 assert user.organizations[0].name == org_name assert user.organizations[1].name == org2_name assert user.practitioner_id == pract_id
def test_demographicsPUT(self): # race / ethnicity require the SLOW addition of concepts to db self.add_concepts() # clinic reference requires pre-existing organization self.shallow_org_tree() (org_id, org_name), (org2_id, org2_name) = [ (org.id, org.name) for org in Organization.query.filter(Organization.id > 0).limit(2) ] pract = self.add_practitioner(first_name='Indiana', last_name='Jones') pract_id = pract.id family = 'User' given = 'Test' dob = '1999-01-31' dod = '2027-12-31T09:10:00+00:00' gender = 'Male' phone = "867-5309" alt_phone = "555-5555" data = { "name": { "family": family, "given": given }, "resourceType": "Patient", "birthDate": dob, "deceasedDateTime": dod, "gender": gender, "telecom": [{ "system": "phone", "use": "mobile", "value": phone, }, { "system": "phone", "use": "home", "value": alt_phone, }, { "system": 'email', 'value': '__no_email__' }], "extension": [{ "url": "http://hl7.org/fhir/StructureDefinition/us-core-race", "valueCodeableConcept": { "coding": [{ "system": "http://hl7.org/fhir/v3/Race", "code": "1096-7" }] } }, { "url": "http://hl7.org/fhir/StructureDefinition/us-core-" "ethnicity", "valueCodeableConcept": { "coding": [{ "system": "http://hl7.org/fhir/v3/Ethnicity", "code": "2162-6" }] } }], "careProvider": [ { "reference": "Organization/{}".format(org_id) }, { "reference": "api/organization/{}".format(org2_id) }, { "reference": "Practitioner/{}".format(pract_id) }, ] } self.login() response = self.client.put('/api/demographics/%s' % TEST_USER_ID, content_type='application/json', data=json.dumps(data)) assert response.status_code == 200 fhir = response.json for item in fhir['telecom']: if item['system'] == 'phone': if item['use'] == 'home': assert alt_phone == item['value'] elif item['use'] == 'mobile': assert phone == item['value'] else: self.fail('unexpected telecom use: {}'.format(item['use'])) else: self.fail('unexpected telecom system: {}'.format( item['system'])) assert fhir['birthDate'] == dob assert fhir['deceasedDateTime'] == dod assert fhir['gender'] == gender.lower() assert fhir['name']['family'] == family assert fhir['name']['given'] == given # ignore added timezone and empty extensions assert 2 == len([ ext for ext in fhir['extension'] if 'valueCodeableConcept' in ext ]) assert 3 == len(fhir['careProvider']) assert (Reference.practitioner(pract_id).as_fhir() in fhir['careProvider']) user = db.session.merge(self.test_user) assert user._email.startswith('__no_email__') assert user.email is None assert user.first_name == given assert user.last_name == family assert ['2162-6'] == [c.code for c in user.ethnicities] assert ['1096-7'] == [c.code for c in user.races] assert len(user.organizations) == 2 assert user.organizations[0].name == org_name assert user.organizations[1].name == org2_name assert user.practitioner_id == pract_id