Created
September 24, 2010 08:02
-
-
Save vagmi/595027 to your computer and use it in GitHub Desktop.
An alternative to the grails HIE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HIE Agent configuration file | |
# this is mocked up here. will come from the service | |
# id_maps[uhid] = phr_id | |
id_maps = {} | |
id_maps['xxxxx']='xxxxx@xxxxx' | |
# source setting | |
SOURCE_KEY = 'AVERYLONGGUID' | |
SOURCE_NAME = 'Apollo Site' | |
# HIE Server Details | |
HIE_SERVER = "http://test.hiwayhealthconnect.com" | |
# HIS Server Details | |
HIS_SERVER = 'IPORHOST' | |
HIS_DB='hmsdb' | |
HIS_USER='dbuser' | |
HIS_PASSWD = 'password' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .NET Stuff | |
import clr | |
import System | |
clr.AddReference("System.Data") | |
from System.Data import * | |
from System.Data.SqlClient import * | |
# IronPython Stuff | |
import json | |
from datetime import datetime | |
import config | |
import urllib | |
import urllib2 | |
conn_string = "Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;" % (config.HIS_SERVER,config.HIS_DB,config.HIS_USER,config.HIS_PASSWD) | |
dbconn = SqlConnection(conn_string) | |
# | |
# Icky schticky sql | |
# | |
normal_result_sql = """ | |
select preg.registration_no, inr.service_code, invsam.lab_regno, ios.Service_Name, inr.result, ulm.Unit_name, inr.min_value, inr.max_value, inr.result_date | |
from patient_registration preg inner join (investigation_sample_op invsam | |
inner join (investigation_normal_result_op inr | |
inner join item_of_service ios | |
on ((ios.Service_code=inr.service_code) and (ios.Report_Type='N'))) | |
on ((inr.service_code = invsam.service_code) | |
and (inr.lab_regno = invsam.lab_regno))) | |
on preg.registration_no = invsam.Registration_No inner join Unit_Lab_Master ulm on ulm.unit_code=inr.Unit_code | |
where preg.registration_no=@UHID""" | |
text_result_sql = """ | |
select itr.service_code, itr.lab_regno , ios.Service_Name, itr.formatstr,itr.result_date | |
from investigation_typical_result_op itr | |
inner join item_of_service ios | |
on ((itr.service_code = ios.Service_code) and (ios.Report_Type='F' or ios.Report_Type='T')) | |
inner join investigation_sample_op invsam on (invsam.lab_regno=itr.lab_regno and invsam.service_code = itr.service_code) | |
where invsam.Registration_No = @UHID | |
""" | |
# the worst is over | |
def process_normal(uhid): | |
normal_cmd = SqlCommand(normal_result_sql, dbconn) | |
normal_cmd.Parameters.Add("@UHID",SqlDbType.NVarChar) | |
normal_cmd.Parameters["@UHID"].Value = uhid | |
reader = normal_cmd.ExecuteReader() | |
results = [] | |
while(reader.Read()): | |
record = {} | |
record['dbid'] = str(reader['service_code'])+"|"+str(reader["lab_regno"]) | |
record['name'] = reader['Service_Name'] | |
record['result'] = str(reader['result']) + " " + reader["Unit_name"] + " max: " + str(reader["max_value"]) + " min: " + str(reader["min_value"]) | |
record['result_date'] = datetime(reader['result_date']).isoformat() | |
results.append(record) | |
reader.Close() | |
return results | |
def process_textual(uhid): | |
text_cmd = SqlCommand(text_result_sql, dbconn) | |
text_cmd.Parameters.Add("@UHID",SqlDbType.NVarChar) | |
text_cmd.Parameters["@UHID"].Value = uhid | |
reader = text_cmd.ExecuteReader() | |
results = [] | |
while(reader.Read()): | |
record = {} | |
record['dbid'] = str(reader['service_code'])+"|"+str(reader["lab_regno"]) | |
record['name'] = reader['Service_Name'] | |
record['result'] = reader['formatstr'] | |
record['result_date'] = datetime(reader['result_date']).isoformat() | |
results.append(record) | |
reader.Close() | |
return results | |
def send_to_server(data): | |
values = {} | |
values['data']=data | |
values = urllib.urlencode(values) | |
url = config.HIE_SERVER + "/api/import/hospitals/results" | |
req = urllib2.request(url,values) | |
resp = urllib2.urlopen(req) | |
return resp.read() | |
def main(): | |
dbconn.Open() | |
for uhid in config.id_maps.keys(): | |
import_record = {} | |
phr_id = config.id_maps[uhid] | |
results = [] | |
results.extend(process_normal(uhid)) | |
results.extend(process_textual(uhid)) | |
import_record['uhid']=uhid | |
import_record['source']=config.SOURCE_NAME | |
import_record['phr_id']=phr_id | |
import_record['results']=results | |
data=json.dumps(import_record) | |
print data | |
print "processing " + str(len(results)) + " results for " + phr_id | |
print send_to_server(data) | |
dbconn.Close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment