I made a python script that goes throught a sql serve gets presciption records then after cleaning up the data I query it based on two parameters, all of this works by itself but now I wanted to make this into a application that others can interact. So, I tried to make a py-script application.
The problem:
- When I try to import the pypyodbc module which is what I use to access the sql server I get an error
ValueError: Couldn't find a pure Python 3 wheel for 'pypyodbc'. You can use 'micropip.install(..., keep_going=True)' to get a list of all packages with missing wheels
. - To solve this I tried the micropip method and install a pure python library but was not able to. Here is the code:
<html>
<head>
<!--<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />-->
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<py-env>
- pypyodbc
- pandas
</py-env>
<div>Type an sample input here</div>
<input type="text" id="test-input"/>
<input type="text" id="test-input2"/>
<button id="submit-button" type="submit" pys-onClick="my_function">OK</button>
<p id="test-output"></p>
<py-script>
def my_function(*args, **kwargs):
import pypyodbc
import pandas as pd
DRIVER_NAME='SQL SERVER'
SERVER_NAME=''
DATABASE_NAME=''
text = Element('test-input').element.value
text2=Element('test-input2').element.value
connection_string=f"""
DRIVER={{{DRIVER_NAME}}};
SERVER={SERVER_NAME};
DATABASE={DATABASE_NAME};
Trust_Connection=yes;
uid=;
pwd=;
"""
conn = pypyodbc.connect(connection_string)
sql_query="""
SELECT * FROM Visit_Prescription
"""
df_pres=pd.read_sql(sql_query,conn)
DRIVER_NAME='SQL SERVER'
SERVER_NAME=''
DATABASE_NAME=''
connection_string=f"""
DRIVER={{{DRIVER_NAME}}};
SERVER={SERVER_NAME};
DATABASE={DATABASE_NAME};
Trust_Connection=yes;
uid=;
pwd=;
"""
conn = pypyodbc.connect(connection_string)
sql_query="""
SELECT * FROM Visit_Diagnosis
"""
df_Dia=pd.read_sql(sql_query,conn)
df_pres=df_pres.drop(['drug_tradername','drug_form_package', 'scientific_code'], axis=1)
df_pres=df_pres.groupby(['permanent_visit_no','patient_visit_registered_date_time'])['drug_package_information'].apply(','.join).reset_index()
inner = pd.merge(left=df_Dia, right=df_pres, left_on='permanent_visit_no', right_on='permanent_visit_no')
inner=inner.drop(['patient_visit_basic_details_serial_no','permanent_visit_no','patient_visit_registered_date_time_x','diagdate','patient_visit_registered_date_time_y'],axis=1)
inner.drop_duplicates(inplace = True)
inner=inner.drop(['icd_principal_secondary','icd_code_description'],axis=1)
contain_values = inner[inner['icd_code'].str.contains('test-input')]
contain_values=contain_values[contain_values['drug_package_information'].str.contains('test-input2')]
pyscript.write('test-output',contain_values)
</py-script>
</body>
</html>
So, I need help in trying to figure out a way to import the pypyodbc library or even a new library that can access the microsoft sql server. I am very new to this and with pyscript being relatively new I am unable to find much information online. So, any and all help is welcome and much appreciated.