Spaces:
Sleeping
Sleeping
coldn00dl3s
commited on
Commit
•
d0e9868
1
Parent(s):
9cd9f70
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,21 @@ import pandas as pd
|
|
3 |
import requests
|
4 |
import json
|
5 |
from datetime import datetime
|
|
|
6 |
|
7 |
st.title("FHIR Converter")
|
8 |
|
9 |
# Dropdown for conversion type
|
10 |
conversion_type = st.selectbox(
|
11 |
"Select Conversion Type",
|
12 |
-
["CSV to FHIR", "CCDA to FHIR","Clinical Notes to FHIR"]
|
13 |
)
|
14 |
|
15 |
# Dropdown for resource type
|
16 |
if conversion_type == "CSV to FHIR":
|
17 |
res_type = st.selectbox(
|
18 |
"Select Resource Type",
|
19 |
-
["Patient","CarePlan", "MedicationRequest", "Immunization", "Encounter", "Claim", "Procedure", "Observation"]
|
20 |
)
|
21 |
|
22 |
# File uploader for CSV file
|
@@ -84,7 +85,7 @@ if conversion_type == "CSV to FHIR":
|
|
84 |
elif conversion_type == "CCDA to FHIR":
|
85 |
res_type = st.selectbox(
|
86 |
"Select Resource Type",
|
87 |
-
["Patient", "Encounter", "Observation","MedicationRequest","Procedure","Immunization","Condition"]
|
88 |
)
|
89 |
|
90 |
cda_content = st.text_area("Enter CCDA Content in XML format")
|
@@ -111,28 +112,51 @@ elif conversion_type == "CCDA to FHIR":
|
|
111 |
st.error(f"An error occurred: {str(e)}")
|
112 |
if conversion_successful:
|
113 |
st.markdown("[Go to FHIR Validator](https://validator.fhir.org)", unsafe_allow_html=True)
|
114 |
-
elif conversion_type == "Clinical Notes to FHIR":
|
115 |
|
116 |
-
|
|
|
117 |
|
118 |
# Variables to store the result and state
|
119 |
result = st.empty()
|
120 |
conversion_successful = False
|
|
|
|
|
121 |
|
122 |
-
|
123 |
-
if st.button("Convert"):
|
124 |
try:
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
-
response = requests.post("https://fhir-api-9jsn.onrender.com/convert_notes", json=data)
|
128 |
-
if response.status_code == 200:
|
129 |
-
result_text = response.json().get("output", "")
|
130 |
-
if result_text:
|
131 |
-
result.success("Conversion successful!")
|
132 |
-
result.text_area("FHIR Output", result_text, height=400)
|
133 |
-
conversion_successful = True
|
134 |
-
else:
|
135 |
-
st.error(f"An error occurred: {response.json().get('error', 'Unknown error')}")
|
136 |
except Exception as e:
|
137 |
st.error(f"An error occurred: {str(e)}")
|
138 |
|
|
|
3 |
import requests
|
4 |
import json
|
5 |
from datetime import datetime
|
6 |
+
import PyPDF2
|
7 |
|
8 |
st.title("FHIR Converter")
|
9 |
|
10 |
# Dropdown for conversion type
|
11 |
conversion_type = st.selectbox(
|
12 |
"Select Conversion Type",
|
13 |
+
["CSV to FHIR", "CCDA to FHIR", "Clinical Notes to FHIR"]
|
14 |
)
|
15 |
|
16 |
# Dropdown for resource type
|
17 |
if conversion_type == "CSV to FHIR":
|
18 |
res_type = st.selectbox(
|
19 |
"Select Resource Type",
|
20 |
+
["Patient", "CarePlan", "MedicationRequest", "Immunization", "Encounter", "Claim", "Procedure", "Observation"]
|
21 |
)
|
22 |
|
23 |
# File uploader for CSV file
|
|
|
85 |
elif conversion_type == "CCDA to FHIR":
|
86 |
res_type = st.selectbox(
|
87 |
"Select Resource Type",
|
88 |
+
["Patient", "Encounter", "Observation", "MedicationRequest", "Procedure", "Immunization", "Condition"]
|
89 |
)
|
90 |
|
91 |
cda_content = st.text_area("Enter CCDA Content in XML format")
|
|
|
112 |
st.error(f"An error occurred: {str(e)}")
|
113 |
if conversion_successful:
|
114 |
st.markdown("[Go to FHIR Validator](https://validator.fhir.org)", unsafe_allow_html=True)
|
|
|
115 |
|
116 |
+
elif conversion_type == "Clinical Notes to FHIR":
|
117 |
+
uploaded_pdf = st.file_uploader("Upload PDF with Clinical Notes", type=["pdf"])
|
118 |
|
119 |
# Variables to store the result and state
|
120 |
result = st.empty()
|
121 |
conversion_successful = False
|
122 |
+
progress_bar = st.progress(0)
|
123 |
+
time_placeholder = st.empty()
|
124 |
|
125 |
+
if uploaded_pdf is not None and st.button("Convert"):
|
|
|
126 |
try:
|
127 |
+
# Extract text from PDF
|
128 |
+
pdf_reader = PyPDF2.PdfFileReader(uploaded_pdf)
|
129 |
+
paragraphs = []
|
130 |
+
for page_num in range(pdf_reader.getNumPages()):
|
131 |
+
page = pdf_reader.getPage(page_num)
|
132 |
+
text = page.extract_text()
|
133 |
+
paragraphs.extend(text.split("\n\n")) # Split by double newline for paragraph separation
|
134 |
+
|
135 |
+
# Send paragraphs to API
|
136 |
+
total_paragraphs = len(paragraphs)
|
137 |
+
start_time = datetime.now()
|
138 |
+
result_text = ""
|
139 |
+
|
140 |
+
for idx, paragraph in enumerate(paragraphs):
|
141 |
+
data = {"note_content": paragraph}
|
142 |
+
response = requests.post("https://fhir-api-9jsn.onrender.com/convert_notes", json=data)
|
143 |
+
|
144 |
+
if response.status_code == 200:
|
145 |
+
result_text += response.json().get("output", "") + "\n"
|
146 |
+
else:
|
147 |
+
st.error(f"An error occurred at paragraph {idx + 1}: {response.json().get('error', 'Unknown error')}")
|
148 |
+
break
|
149 |
+
|
150 |
+
# Update progress
|
151 |
+
elapsed_time = datetime.now() - start_time
|
152 |
+
progress_bar.progress(int(((idx + 1) / total_paragraphs) * 100))
|
153 |
+
time_placeholder.text(f"Time elapsed: {elapsed_time}")
|
154 |
+
|
155 |
+
if result_text:
|
156 |
+
result.success("Conversion successful!")
|
157 |
+
result.text_area("FHIR Output", result_text, height=400)
|
158 |
+
conversion_successful = True
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
except Exception as e:
|
161 |
st.error(f"An error occurred: {str(e)}")
|
162 |
|