-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_data.py
More file actions
74 lines (69 loc) · 2.36 KB
/
Copy pathcreate_data.py
File metadata and controls
74 lines (69 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import helix
from helix.client import Query
from helix.types import Payload
import csv
from typing import List
from datetime import datetime
class create_data(Query):
def __init__(
self,
doctor_name: str,
doctor_city: str,
patient_name: str,
patient_age: int,
summary: str,
date: int,
):
super().__init__()
self.doctor_name = doctor_name
self.doctor_city = doctor_city
self.patient_name = patient_name
self.patient_age = patient_age
self.summary = summary
self.date = date
def query(self) -> List[Payload]:
return [{
"doctor_name": self.doctor_name,
"doctor_city": self.doctor_city,
"patient_name": self.patient_name,
"patient_age": self.patient_age,
"summary": self.summary,
"date": self.date,
}]
def response(self, response): return response
def read_patient_records(file_path):
patient_data = []
try:
with open(file_path, mode='r', encoding='utf-8') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
patient_tuple = (
row['Patient_Name'],
row['Hospital_City'],
row['Doctor_Name'],
int(row['Age']),
row['Doctor_Consultation_Desc'],
row['Timestamp'],
)
patient_data.append(patient_tuple)
return patient_data
except FileNotFoundError:
print(f"Error: The file '{file_path}' was not found.")
return []
except Exception as e:
print(f"Error: An unexpected error occurred: {e}")
return []
if __name__ == "__main__":
db = helix.Client(local=True)
file_path = "patients.csv"
patients = read_patient_records(file_path)
for patient in patients:
dt = datetime.strptime(patient[5], "%Y-%m-%d %H:%M:%S")
db.query(create_data(patient[2], patient[1], patient[0], patient[3], patient[4], int(dt.timestamp())))
print(f"Patient Name: {patient[0]}")
print(f"Hospital City: {patient[1]}")
print(f"Doctor Name: {patient[2]}")
print(f"Age: {patient[3]}")
print(f"Consultation Description: {patient[4]}")
print(f"Timestamp: {patient[5]}")
print("-" * 50)