Exemplo n.º 1
0
 def test_contactpoint_from_fhir(self):
     data = {
         "system": "phone",
         "use": "work",
         "rank": 1,
         "value": "867-5309"
     }
     cp = ContactPoint.from_fhir(data)
     assert cp.system == "phone"
     assert cp.value == "867-5309"
Exemplo n.º 2
0
 def test_contactpoint_from_fhir(self):
     data = {
         "system": "phone",
         "use": "work",
         "rank": 1,
         "value": "867-5309"
     }
     cp = ContactPoint.from_fhir(data)
     self.assertEquals(cp.system, "phone")
     self.assertEquals(cp.value, "867-5309")
Exemplo n.º 3
0
 def test_contactpoint_from_fhir(self):
     data = {
         "system": "phone",
         "use": "work",
         "rank": 1,
         "value": "867-5309"
     }
     cp = ContactPoint.from_fhir(data)
     assert cp.system == "phone"
     assert cp.value == "867-5309"
Exemplo n.º 4
0
def upgrade():
    # create contact_points table
    op.create_table(
        'contact_points', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('cp_sys',
                  postgresql.ENUM('phone',
                                  'fax',
                                  'email',
                                  'pager',
                                  'url',
                                  'sms',
                                  'other',
                                  name='cp_sys'),
                  nullable=False),
        sa.Column('cp_use',
                  postgresql.ENUM('home',
                                  'work',
                                  'temp',
                                  'old',
                                  'mobile',
                                  name='cp_use'),
                  nullable=True), sa.Column('value', sa.Text(), nullable=True),
        sa.Column('rank', sa.Integer(), nullable=True),
        sa.PrimaryKeyConstraint('id'))

    # add new phone_id columns
    op.add_column(u'users',
                  sa.Column('alt_phone_id', sa.Integer(), nullable=True))
    op.add_column(u'users', sa.Column('phone_id', sa.Integer(), nullable=True))
    op.create_foreign_key('user_alt_phone_contact_point',
                          'users',
                          'contact_points', ['alt_phone_id'], ['id'],
                          ondelete='cascade')
    op.create_foreign_key('user_phone_contact_point',
                          'users',
                          'contact_points', ['phone_id'], ['id'],
                          ondelete='cascade')

    op.add_column(u'organizations',
                  sa.Column('phone_id', sa.Integer(), nullable=True))
    op.create_foreign_key('org_phone_contact_point',
                          'organizations',
                          'contact_points', ['phone_id'], ['id'],
                          ondelete='cascade')

    # migrate data from old phone columns to new contact_point objects
    bind = op.get_bind()
    session = Session(bind=bind)

    for user_id, phone in session.execute(
            "SELECT id, phone FROM users where phone != ''"):
        cp = ContactPoint(system='phone', use='mobile', value=phone)
        session.add(cp)
        session.commit()
        cp = session.merge(cp)
        session.execute('UPDATE users SET phone_id = {} where id = {}'.format(
            cp.id, user_id))

    for org_id, phone in session.execute(
            "SELECT id, phone FROM organizations where phone != ''"):
        cp = ContactPoint(system='phone', use='work', value=phone)
        session.add(cp)
        session.commit()
        cp = session.merge(cp)
        session.execute(
            'UPDATE organizations SET phone_id = {} where id = {}'.format(
                cp.id, org_id))

    # drop old phone columns
    op.drop_column(u'users', 'phone')
    op.drop_column(u'organizations', 'phone')
Exemplo n.º 5
0
 def test_contactpoint_as_fhir(self):
     cp = ContactPoint(system='phone', use='work', value='867-5309')
     data = cp.as_fhir()
     self.assertEquals(len(data), 3)
     self.assertEquals(data['value'], '867-5309')
Exemplo n.º 6
0
 def test_telecom_cp_dict(self):
     cp = ContactPoint(system='phone', use='work', value='123-4567')
     tc = Telecom(email='*****@*****.**', contact_points=[cp])
     data = tc.cp_dict()
     self.assertEquals(len(data), 1)
     self.assertEquals(data.get(('phone', 'work')), '123-4567')
Exemplo n.º 7
0
 def test_telecom_as_fhir(self):
     cp = ContactPoint(system='phone', use='work', value='123-4567')
     tc = Telecom(email='*****@*****.**', contact_points=[cp])
     data = tc.as_fhir()
     self.assertEquals(len(data), 2)
Exemplo n.º 8
0
 def test_contactpoint_as_fhir(self):
     cp = ContactPoint(system='phone', use='work', value='867-5309')
     data = cp.as_fhir()
     assert len(data) == 3
     assert data['value'] == '867-5309'
Exemplo n.º 9
0
 def test_contactpoint_as_fhir(self):
     cp = ContactPoint(system='phone', use='work', value='867-5309')
     data = cp.as_fhir()
     assert len(data) == 3
     assert data['value'] == '867-5309'