daily pastebin goal
93%
SHARE
TWEET

Untitled

a guest Nov 6th, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Imports
  2. import sqlalchemy
  3. import pandas as pd
  4. import pyodbc
  5. import uuid
  6. import csv
  7. import psycopg2
  8.  
  9. #mssql connection
  10. sql_conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.168.5.81;DATABASE=Eremedylive;UID=sa;PWD=1234567aA')
  11. query = "select * FROM op_billing"
  12.  
  13.  
  14. #postgresql connection
  15. conn = psycopg2.connect(host="192.168.5.86",database="nbi_women", user="healthix_user", password="goldcrack_db@1020#!")
  16. engine = sqlalchemy.create_engine('postgresql://healthix_user:goldcrack_db@1020#!@192.168.5.86:5432/nbi_women')
  17.  
  18. df = pd.read_sql(query, sql_conn)
  19. print df
  20.  
  21. df1 = df[['CREDIT_COMPANY_ID','PATIENT_ID','CREDIT_COMPANY_SCHEME_ID','SCHEME_MEMBER_ID','VISIT_ID','PATIENT_ID','VISIT_TYPE',
  22. 'CENTER_ID','CREATED_DATE','CREATED_BY','MODIFIED_DATE','CREDIT_COMPANY_ID','CO_PAY']]
  23. print df1
  24.  
  25. df1.to_csv('opbill.csv', sep='\t', index=False)
  26. #df2 = pd.read_csv("opbill.csv")
  27. cols = ['insurance_company','member_number','scheme_name','member','visit_number','patient_number','visit_type','provider','created',
  28. 'created_by','modified','payers','k_gross_amount']
  29. df1.columns = cols
  30. print df1
  31. df1.to_csv('modifiedopbill.csv', sep='\t', index=False)
  32. #Read modified.csv appending uuid4() field
  33. fin = open('modifiedopbill.csv', 'rb')
  34. fout = open('uuidmodifiedopbill.csv', 'w')
  35.  
  36. reader = csv.reader(fin, delimiter=',', quotechar='"')
  37. writer = csv.writer(fout, delimiter=',', quotechar='"')
  38.  
  39. firstrow = True
  40. for row in reader:
  41.     if firstrow:
  42.         row.append('id')
  43.         firstrow = False
  44.     else:
  45.         row.append(uuid.uuid4())
  46.     writer.writerow(row)
  47.  
  48. df2 = pd.read_csv("uuidmodifiedopbill.csv")
  49.  
  50. df2.to_sql(name='claims_claim', con=engine, if_exists='replace',index=False)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top