Spaces:
Sleeping
Sleeping
File size: 1,066 Bytes
53a6315 5dc04ad 53a6315 f49d5d2 53a6315 5dc04ad 2ae3913 5dc04ad 53a6315 5dc04ad 53a6315 5dc04ad f49d5d2 5dc04ad | 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 | from contextlib import contextmanager
import pandas as pd
class DataService(object):
@contextmanager
def build(self):
data_service = None
try:
data_service = DefaultDataService()
yield data_service
finally:
if data_service: data_service.close()
def close(self):
raise Exception("Should not use the base class")
def get_patients(self) -> list[str]:
raise Exception("Should not use the base class")
class DefaultDataService(DataService):
def __init__(self):
self._dataset_url = "https://huggingface.co/datasets/iscg34/finalproject/raw/main/patient_encounters1_notes.csv"
self._initialized = False
def initialize(func):
def wrapper(self):
if not self._initialized:
self._df = pd.read_csv(self._dataset_url)
self._initialized = True
return func(self)
return wrapper
def close(self):
#raise Exception("Not implemented")
pass
@initialize
def get_patients(self) -> list[str]:
col = self._df["FIRST"]
u = col.unique()
l = u.tolist()
return l |