Tonic commited on
Commit
efa4352
·
unverified ·
1 Parent(s): 5372c12

add callback manager , model app

Browse files
Files changed (2) hide show
  1. callbackmanager.py +14 -9
  2. meldrx.py +9 -7
callbackmanager.py CHANGED
@@ -1,20 +1,28 @@
1
  import gradio as gr
2
  from meldrx import MeldRxAPI
3
  import json
 
4
 
5
  # CallbackManager class to handle OAuth callbacks
6
  class CallbackManager:
7
- def __init__(self, client_id: str, redirect_uri: str, workspace_id: str, client_secret: str = None):
8
  """
9
  Initialize the CallbackManager with MeldRx API credentials.
 
10
 
11
  Args:
12
- client_id (str): The client ID from MeldRx Developer Portal.
13
  redirect_uri (str): The redirect URI for the Gradio app (e.g., Space URL + /callback).
14
- workspace_id (str): The workspace slug/ID.
15
  client_secret (str, optional): The client secret (for confidential clients).
16
  """
17
- self.api = MeldRxAPI(client_id, redirect_uri, workspace_id, client_secret)
 
 
 
 
 
 
 
 
18
  self.auth_code = None
19
  self.access_token = None
20
 
@@ -39,7 +47,7 @@ class CallbackManager:
39
  return json.dumps(patients, indent=2) if patients else "No patient data returned."
40
  return "Failed to retrieve patient data."
41
 
42
- # Discharge form display function
43
  def display_form(
44
  first_name, last_name, middle_initial, dob, age, sex, address, city, state, zip_code,
45
  doctor_first_name, doctor_last_name, doctor_middle_initial, hospital_name, doctor_address,
@@ -80,15 +88,12 @@ def display_form(
80
  """
81
  return form
82
 
83
- # Initialize CallbackManager with your credentials
84
  CALLBACK_MANAGER = CallbackManager(
85
- client_id="your_client_id", # Replace with actual client ID
86
  redirect_uri="https://multitransformer-discharge-guard.hf.space/callback",
87
- workspace_id="your_workspace_id", # Replace with actual workspace ID
88
  client_secret=None # Replace with actual secret if using a confidential client
89
  )
90
 
91
- # Gradio interface
92
  with gr.Blocks() as demo:
93
  gr.Markdown("# Patient Discharge Form with MeldRx Integration")
94
 
 
1
  import gradio as gr
2
  from meldrx import MeldRxAPI
3
  import json
4
+ import os
5
 
6
  # CallbackManager class to handle OAuth callbacks
7
  class CallbackManager:
8
+ def __init__(self, redirect_uri: str, client_secret: str = None):
9
  """
10
  Initialize the CallbackManager with MeldRx API credentials.
11
+ The client_id and workspace_id are retrieved from environment variables APPID and WORKSPACE_URL.
12
 
13
  Args:
 
14
  redirect_uri (str): The redirect URI for the Gradio app (e.g., Space URL + /callback).
 
15
  client_secret (str, optional): The client secret (for confidential clients).
16
  """
17
+ client_id = os.getenv("APPID") # Retrieve client_id from APPID secret
18
+ if not client_id:
19
+ raise ValueError("APPID environment variable not set. Please configure it in your Space secrets.")
20
+
21
+ workspace_id = os.getenv("WORKSPACE_URL") # Retrieve workspace_id from WORKSPACE_URL secret
22
+ if not workspace_id:
23
+ raise ValueError("WORKSPACE_URL environment variable not set. Please configure it in your Space secrets.")
24
+
25
+ self.api = MeldRxAPI(client_id, client_secret, workspace_id, redirect_uri)
26
  self.auth_code = None
27
  self.access_token = None
28
 
 
47
  return json.dumps(patients, indent=2) if patients else "No patient data returned."
48
  return "Failed to retrieve patient data."
49
 
50
+ # Discharge form display function (unchanged)
51
  def display_form(
52
  first_name, last_name, middle_initial, dob, age, sex, address, city, state, zip_code,
53
  doctor_first_name, doctor_last_name, doctor_middle_initial, hospital_name, doctor_address,
 
88
  """
89
  return form
90
 
 
91
  CALLBACK_MANAGER = CallbackManager(
 
92
  redirect_uri="https://multitransformer-discharge-guard.hf.space/callback",
 
93
  client_secret=None # Replace with actual secret if using a confidential client
94
  )
95
 
96
+ # Gradio interface (unchanged)
97
  with gr.Blocks() as demo:
98
  gr.Markdown("# Patient Discharge Form with MeldRx Integration")
99
 
meldrx.py CHANGED
@@ -9,23 +9,25 @@ class MeldRxAPI:
9
  and interact with encounter data.
10
  """
11
 
12
- def __init__(self, client_id: str, client_secret: str, workspace_id: str):
13
  """
14
- Initialize the MeldRxAPI class with client credentials and workspace ID.
15
 
16
- Args:
17
- client_id (str): The client ID (App ID) obtained from MeldRx Developer Portal.
18
- client_secret (str): The client secret for authentication.
19
- workspace_id (str): The workspace slug/ID to interact with.
20
  """
21
  self.base_url = "https://app.meldrx.com"
22
  self.api_base_url = f"{self.base_url}/api"
23
  self.fhir_base_url = f"{self.api_base_url}/fhir/{workspace_id}"
24
- self.mips_base_url = f"{self.base_url}/mms-api" # MIPS API base URL
25
  self.token_url = f"{self.base_url}/connect/token"
 
26
  self.client_id = client_id
27
  self.client_secret = client_secret
28
  self.workspace_id = workspace_id
 
29
  self.access_token = None
30
  self.session = requests.Session()
31
 
 
9
  and interact with encounter data.
10
  """
11
 
12
+ def __init__(self, client_id: str, client_secret: str, workspace_id: str, redirect_uri: str):
13
  """
14
+ Initialize the MeldRxAPI class with client credentials and workspace ID.
15
 
16
+ Args:
17
+ client_id (str): The client ID (App ID) obtained from MeldRx Developer Portal.
18
+ client_secret (str): The client secret for authentication.
19
+ workspace_id (str): The workspace slug/ID to interact with.
20
  """
21
  self.base_url = "https://app.meldrx.com"
22
  self.api_base_url = f"{self.base_url}/api"
23
  self.fhir_base_url = f"{self.api_base_url}/fhir/{workspace_id}"
24
+ self.mips_base_url = f"{self.base_url}/mms-api"
25
  self.token_url = f"{self.base_url}/connect/token"
26
+ self.authorize_url = f"{self.base_url}/connect/authorize"
27
  self.client_id = client_id
28
  self.client_secret = client_secret
29
  self.workspace_id = workspace_id
30
+ self.redirect_uri = redirect_uri
31
  self.access_token = None
32
  self.session = requests.Session()
33