Guest User

Untitled

a guest
Oct 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. from sqlalchemy import create_engine, Table, MetaData, Column, Integer, String, DateTime
  2. from sqlalchemy.ext.declarative import declarative_base
  3. import json
  4. from pprint import pprint
  5. from uuid import uuid1
  6. from dateutil import parser as dateparser
  7.  
  8. metadata = MetaData()
  9. # Base = declarative_base()
  10. engine = create_engine("mysql+pymysql://synuser:password@localhost/synthea",
  11. isolation_level="READ UNCOMMITTED")
  12.  
  13. immunizationsTable = Table('IMMUNIZATIONS', metadata,
  14. Column("UUID", String(45), primary_key=True),
  15. Column("DATE", DateTime, nullable=True),
  16. Column("STATUS", String(32)),
  17. Column("PATIENT_UUID", String(45)))
  18.  
  19. # immunizationsTable.create(engine)
  20.  
  21. with open('../data/0a/0a2/0a295b75-2441-45e1-88b9-17605d8a255a.json') as data_file:
  22. data = json.load(data_file)
  23.  
  24. immunizations = [entry for entry in data['entry'] if entry['resource']['resourceType'] == 'Immunization']
  25.  
  26. connection = engine.connect()
  27. trans = connection.begin()
  28. for immunization in immunizations:
  29. resource = immunization['resource']
  30. status = resource['status']
  31. date = dateparser.parse(resource['date']) # datetime(2010-06-) from `2010-06-13T13:55:41-04:00`
  32. patient_uuid = resource['patient']['reference']
  33. connection.execute(
  34. immunizationsTable.insert().values(UUID=uuid1().urn, DATE=date, STATUS=status, PATIENT_UUID=patient_uuid)
  35. )
  36. trans.commit()
  37.  
  38.  
  39.  
  40. #
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. # t.create(engine)
  49.  
  50. #
  51. # class User(Base):
  52. # __tablename__ = 'users'
  53. #
  54. # id = Column(Integer, primary_key=True)
  55. # name = Column(String,le)
  56. # fullname = Column(String)
  57. # password = Column(String)
  58. #
  59. # def __repr__(self):
  60. # return "<User(name='%s', fullname='%s', password='%s')>" % (
  61. # self.name, self.fullname, self.password)
  62. #
  63. #
  64. # Base.metadata.create_all(engine)
Add Comment
Please, Sign In to add comment