def test_composite_key(self): known_coding = Coding( system=SNOMED, code='26294005', display='Radical prostatectomy (nerve-sparing)').add_if_not_found( True) mp = ModelPersistence( Coding, sequence_name='codings_id_seq', lookup_field=('system', 'code')) data = known_coding.as_fhir() # Modify only the `display` - composite keys should still match modified_data = data.copy() modified_data['display'] = 'Radical prostatectomy' modified = Coding.from_fhir(data) match, _ = mp.lookup_existing( new_obj=modified, new_data=modified_data) assert data == match.as_fhir() # Import and see the change updated = mp.update(modified_data) assert modified == updated # Export and verify serial = mp.serialize() assert modified_data in serial
def test_organization_put(self): self.promote_user(role_name=ROLE.ADMIN.value) self.login() with (open( os.path.join( os.path.dirname(__file__), 'organization-example-f001-burgers.json'), 'r') ) as fhir_data: data = json.load(fhir_data) # remove the id from the file - doesn't play well with ours data.pop('id') # Shove a nearly empty org in the db and then update via the api org = Organization(name='test') with SessionScope(db): db.session.add(org) db.session.commit() org = db.session.merge(org) org_id = org.id # prepopulate database with matching locale Coding.from_fhir({ 'code': 'en_AU', 'display': 'Australian English', 'system': "urn:ietf:bcp:47"}) response = self.client.put( '/api/organization/{}'.format(org_id), content_type='application/json', data=json.dumps(data)) assert response.status_code == 200 # Pull the updated db entry org = Organization.query.get(org_id) assert org.addresses[0].line1 == data['address'][0]['line'][0] assert org.addresses[1].line1 == data['address'][1]['line'][0] assert org.name == data['name'] assert org.phone == "022-655 2300"
def test_organization_put(self): self.promote_user(role_name=ROLE.ADMIN.value) self.login() with (open( os.path.join(os.path.dirname(__file__), 'organization-example-f001-burgers.json'), 'r')) as fhir_data: data = json.load(fhir_data) # remove the id from the file - doesn't play well with ours data.pop('id') # Shove a nearly empty org in the db and then update via the api org = Organization(name='test') with SessionScope(db): db.session.add(org) db.session.commit() org = db.session.merge(org) org_id = org.id # prepopulate database with matching locale Coding.from_fhir({ 'code': 'en_AU', 'display': 'Australian English', 'system': "urn:ietf:bcp:47" }) response = self.client.put('/api/organization/{}'.format(org_id), content_type='application/json', data=json.dumps(data)) assert response.status_code == 200 # Pull the updated db entry org = Organization.query.get(org_id) assert org.addresses[0].line1 == data['address'][0]['line'][0] assert org.addresses[1].line1 == data['address'][1]['line'][0] assert org.name == data['name'] assert org.phone == "022-655 2300"
def test_from_fhir(self): with (open( os.path.join(os.path.dirname(__file__), 'organization-example-f001-burgers.json'), 'r')) as fhir_data: data = json.load(fhir_data) # prepopulate database with matching locale Coding.from_fhir({ 'code': 'en_AU', 'display': 'Australian English', 'system': IETF_LANGUAGE_TAG }) org = Organization.from_fhir(data) assert org.addresses[0].line1 == data['address'][0]['line'][0] assert org.addresses[1].line1 == data['address'][1]['line'][0] assert org.name == data['name'] assert org.phone == "022-655 2300" assert org.use_specific_codings assert org.race_codings assert not org.ethnicity_codings assert org.locales.count() == 1 assert org.default_locale == "en_AU" assert org._timezone == "US/Pacific"
def test_from_fhir(self): with (open( os.path.join( os.path.dirname(__file__), 'organization-example-f001-burgers.json'), 'r') ) as fhir_data: data = json.load(fhir_data) # prepopulate database with matching locale Coding.from_fhir( {'code': 'en_AU', 'display': 'Australian English', 'system': IETF_LANGUAGE_TAG}) org = Organization.from_fhir(data) assert org.addresses[0].line1 == data['address'][0]['line'][0] assert org.addresses[1].line1 == data['address'][1]['line'][0] assert org.name == data['name'] assert org.phone == "022-655 2300" assert org.use_specific_codings assert org.race_codings assert not org.ethnicity_codings assert org.locales.count() == 1 assert org.default_locale == "en_AU" assert org._timezone == "US/Pacific"
def add_procedure(self, code='367336001', display='Chemotherapy', system=SNOMED, setdate=None): "Add procedure data into the db for the test user" with SessionScope(db): audit = Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID) procedure = Procedure(audit=audit) coding = Coding(system=system, code=code, display=display).add_if_not_found(True) code = CodeableConcept(codings=[coding,]).add_if_not_found(True) enc = Encounter(status='planned', auth_method='url_authenticated', user_id=TEST_USER_ID, start_time=datetime.utcnow()) db.session.add(enc) db.session.commit() enc = db.session.merge(enc) procedure.code = code procedure.user = db.session.merge(self.test_user) procedure.start_time = setdate or datetime.utcnow() procedure.end_time = datetime.utcnow() procedure.encounter = enc db.session.add(procedure) db.session.commit()
def test_display_lookup(self): # example used: Coding(system=SNOMED, code='707266006', # display='Androgen deprivation therapy').add_if_not_found(True) display = Coding.display_lookup(system=SNOMED, code='707266006') assert 'Androgen deprivation therapy' == display