Skip to content

Commit 4e719ba

Browse files
authored
Merge branch 'prakhar-ai:main' into main
2 parents b3f6663 + c0d9e1a commit 4e719ba

File tree

1,888 files changed

+1566
-384446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,888 files changed

+1566
-384446
lines changed

1.png

-124 KB
Binary file not shown.

Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
gunicorn = "*"
8+
9+
[dev-packages]
10+
11+
[requires]
12+
python_version = "3.9"

Pipfile.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Presentation.pdf

3.05 MB
Binary file not shown.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn wsgi:app

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# InstantMD
22

3-
Instant MD is a Investigation, Medication and Chief complaint recognition application using NLP
4-
53
![GitHub last commit](https://img.shields.io/github/last-commit/prakhar-ai/InstantMD)
64
![GitHub contributors](https://img.shields.io/github/contributors/prakhar-ai/InstantMD)
75

8-
![alt text](https://github.com/prakhar-ai/InstantMD/blob/main/1.png?raw=true)
6+
:trophy: <em>Winner of the HealthCare Track at the MINeD Hackathon</em>
7+
8+
Instant MD is a Investigation, Medication and Chief Complaint recognition application using NLP
9+
10+
## Screenshots
11+
12+
13+
![alt text](https://github.com/prakhar-ai/InstantMD/blob/main/appimage2.png?raw=true)
14+
15+
![alt text](https://github.com/prakhar-ai/InstantMD/blob/main/appimage.png?raw=true)
916

1017
## Installation
1118

@@ -33,6 +40,29 @@ $ pip install -r requirements.txt
3340
```
3441
$ python app.py
3542
```
43+
## Hackathon Details
44+
45+
### College: Nirma University
46+
47+
### Team
48+
#### DeepBlue
49+
* Prakhar Jain
50+
* Nikhil Rajput
51+
* Parth Desai
52+
* Parth Panchal
53+
* Nora Surani
54+
55+
### Libraries Used
56+
57+
All libraries versions used are listed in [requirements.txt](https://github.com/prakhar-ai/InstantMD/blob/main/requirements.txt)
58+
59+
### Approach Used
60+
61+
Our NLP approach uses both text and sentence tokenization.
62+
63+
**No third party NLP libraries were used for the project and all pattern matching was done through Regex**
64+
65+
This helps us serve results instantly as opposed to using popular libraries like nltk or spacy, giving us the name **InstantMD**. We preserving sentence structure while also searching the tokenized words. We can then extract symptoms using a list of [symptom keywords](https://github.com/prakhar-ai/InstantMD/blob/main/symptom_list.txt) and the chief complaint by matching with the part of the anatomy that the patient is experiencing symptoms in. This is done through the [anatomy keywords](https://github.com/prakhar-ai/InstantMD/blob/main/anatomy_list.txt). Other factors are similarly extracted using keywords and rules designed by us and implemented through Regex.
3666

3767
## Problem Statement
3868
### Abstract

__init__.py

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
from flask import Flask, render_template, url_for, request, redirect
2+
from flask_sqlalchemy import SQLAlchemy
3+
import re
4+
app = Flask(__name__)
5+
6+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
7+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
8+
db = SQLAlchemy(app)
9+
10+
class PatientData(db.Model):
11+
id = db.Column(db.Integer, primary_key=True)
12+
name = db.Column(db.String(100))
13+
gender = db.Column(db.String(5))
14+
story = db.Column(db.String(2000))
15+
complaint = db.Column(db.String(300))
16+
symptoms = db.Column(db.String(200))
17+
duration = db.Column(db.String(200))
18+
severity = db.Column(db.String(200))
19+
asymptom = db.Column(db.String(200))
20+
afactors = db.Column(db.String(300))
21+
rfactors = db.Column(db.String(300))
22+
23+
24+
@app.route("/")
25+
@app.route("/home")
26+
def home():
27+
return render_template('home.html', active='home')
28+
29+
30+
@app.route("/evaluate")
31+
def evaluate():
32+
return render_template('evaluate.html', title='Evaluation', active='evaluate')
33+
34+
@app.route("/database")
35+
def database():
36+
Patientlist = PatientData.query.all()
37+
return render_template('database.html', title='Database', active='database',Patientlist=Patientlist)
38+
39+
@app.route("/statistics")
40+
def statistics():
41+
return render_template('statistics.html', title='Statistics', active='statistics')
42+
43+
44+
@app.route("/howitworks")
45+
def howitworks():
46+
return render_template('howitworks.html', title='How it works', active='howitworks')
47+
48+
49+
@app.route("/credits")
50+
def credits():
51+
return render_template('creditspage.html', title='Credits', active='credits')
52+
53+
@app.route("/add", methods=["POST"])
54+
def add():
55+
story = request.form.get("story")
56+
gender = request.form.get("gender")
57+
name = request.form.get("fullname")
58+
complaint = request.form.get("complaint")
59+
symptoms = request.form.get("symptoms")
60+
duration = request.form.get("duration")
61+
severity = request.form.get("severity")
62+
asymptom = request.form.get("asymptom")
63+
rfactor = request.form.get("rfactor")
64+
afactor = request.form.get("afactor")
65+
new_data = PatientData(story=story, name=name, gender=gender, complaint=complaint,symptoms=symptoms,duration=duration,severity=severity,asymptom=asymptom,rfactors=rfactor,afactors=afactor)
66+
db.session.add(new_data)
67+
db.session.commit()
68+
return redirect(url_for("database"))
69+
70+
@app.route("/report", methods=["POST"])
71+
def report():
72+
story = request.form.get("story")
73+
gender = request.form.get("gender")
74+
name = request.form.get("fullname")
75+
# need to integrate InstaMD function from classification.ipynb here
76+
# This route is called from "evaluate.html" and renders "report.html" with results
77+
def InstantMD(story,gender,name):
78+
symptom_list = []
79+
with open('symptom_list.txt', 'r') as filehandle:
80+
for line in filehandle:
81+
symptom = line[:-1]
82+
symptom_list.append(symptom)
83+
anatomy_list = []
84+
with open('anatomy_list.txt', 'r') as filehandle:
85+
for line in filehandle:
86+
anatomy = line[:-1]
87+
anatomy_list.append(anatomy)
88+
89+
Symptoms = {}
90+
Anatomy = {}
91+
92+
story = story.replace(',', '.').replace('?', '.')
93+
sentences = story.split('.')
94+
95+
word_list = []
96+
for i in sentences:
97+
words = i.split(" ")
98+
word_list = word_list + words
99+
100+
while("" in word_list) :
101+
word_list.remove("")
102+
103+
104+
for i in symptom_list:
105+
if((' ' in i) == True):
106+
if story.count(i)>0:
107+
Symptoms[i] = story.count(i)
108+
109+
for i in symptom_list:
110+
if word_list.count(i)>0:
111+
Symptoms[i] = word_list.count(i)
112+
113+
for i in anatomy_list:
114+
if word_list.count(i)>0:
115+
Anatomy [i] = word_list.count(i)
116+
117+
number_dict = {"one":"1","two":"2","three":"3","four":"4","five":"5","six":"6","seven":"7","eight":"8","nine":"9"}
118+
for i in range(len(word_list)):
119+
if word_list[i] in list(number_dict.keys()):
120+
word_list[i] = number_dict[word_list[i]]
121+
122+
chief_complaint_final = ""
123+
duration_final = ""
124+
aggravating_factor_final = ""
125+
relieving_factor_final = ""
126+
associated_symptom_final= ""
127+
severity_final = ""
128+
symptoms_final = ""
129+
130+
aggrevating_factor_keywords = ["increase","increases","increasing","rise","rises","becomes more",]
131+
relieving_factor_keywords = ["decreases", "decrease" , "decreasing" , "lessens" , "less" , "subsides", "subside","better"]
132+
133+
duration_list_postfix = ["month","year","week","day","months","years","weeks","days"]
134+
135+
136+
for i in sentences:
137+
symptoms = set(Symptoms.keys())
138+
anatomy = set(Anatomy.keys())
139+
words = set(i.split(" "))
140+
if len(symptoms & words)!=0 and len(anatomy & words)!=0:
141+
chief_complaint_final = ' and '.join(list(symptoms & words)) + ", area: " + " and ".join(list(anatomy & words))
142+
break
143+
144+
if (chief_complaint_final == ""):
145+
chief_complaint_final = max(Symptoms, key=Symptoms.get)
146+
147+
symptoms_final = list(Symptoms.keys())
148+
149+
for i in duration_list_postfix:
150+
if i in word_list:
151+
index = word_list.index(i) - 1
152+
duration_final = word_list[index] + " " + word_list[index + 1]
153+
break
154+
155+
def get_aggravating_factor():
156+
for i in sentences:
157+
words = set(i.split(" "))
158+
for keyword in aggrevating_factor_keywords:
159+
if keyword in words:
160+
result = re.search(keyword + '(.*)and', i)
161+
if(result == None):
162+
result = re.search(keyword + '(.*)', i)
163+
return keyword + result.group(1)
164+
165+
166+
def get_relieving_factor():
167+
for i in sentences:
168+
words = set(i.split(" "))
169+
for keyword in relieving_factor_keywords:
170+
if keyword in words:
171+
result = re.search(keyword + '(.*)', i)
172+
return keyword + result.group(1)
173+
174+
175+
def get_associated_symptom():
176+
for i in sentences:
177+
words = set(i.split(" "))
178+
keyword = "also"
179+
if keyword in words:
180+
result = re.search(keyword + '(.*)', i)
181+
return result.group(1)
182+
183+
def get_severity():
184+
if "mild" in word_list:
185+
return "mild"
186+
elif "moderate" in word_list:
187+
return "moderate"
188+
elif "severe" in word_list:
189+
return "severe"
190+
elif story.count("pain")>1:
191+
return "severe"
192+
elif story.count("pain")==1:
193+
return "severe"
194+
else:
195+
return "mild"
196+
197+
aggravating_factor_final = get_aggravating_factor()
198+
relieving_factor_final = get_relieving_factor()
199+
associated_symptom_final= get_associated_symptom()
200+
severity_final = get_severity()
201+
202+
report_dict = {
203+
"Symptoms" : symptoms_final,
204+
"Chief Complaint": chief_complaint_final,
205+
"Duration" : duration_final,
206+
"Aggravating Factor" : aggravating_factor_final,
207+
"Relieving Factor" : relieving_factor_final,
208+
"Associated Symptom" : associated_symptom_final,
209+
"Severity": severity_final,
210+
"Story" : story,
211+
"Gender" : gender,
212+
"Name" : name
213+
}
214+
return report_dict
215+
216+
217+
report_dict = InstantMD(story,gender,name)
218+
return render_template('report.html', title='Report', active='report',report_dict=report_dict)
219+
220+
221+
if __name__ == "__main__":
222+
db.create_all()
223+
app.run(debug=True)

anatomy_list.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
head
2+
ear
3+
face
4+
forehead
5+
cheek
6+
chin
7+
eye
8+
nose
9+
nostril
10+
mouth
11+
lip
12+
tongue
13+
tooth
14+
neck
15+
teeth
16+
trunk
17+
thorax
18+
abdomen
19+
pelvis
20+
back
21+
upper limb
22+
pectoral girdle
23+
shoulder
24+
arm
25+
axilla
26+
elbow
27+
forearm
28+
wrist
29+
hand
30+
finger
31+
thumb
32+
lower limb
33+
pelvic girdle
34+
leg
35+
buttocks
36+
buttock
37+
hip
38+
thigh
39+
knee
40+
calf
41+
foot
42+
ankle
43+
heel
44+
toe
45+
sole
46+
cavities
47+
cranial cavity
48+
spinal cavity
49+
thoracic cavity
50+
abdominopelvic cavity
51+
abdominal cavity
52+
pelvic cavity
53+
palm
54+
skin
55+
stomach
56+
chest
57+
gums
58+
abdomin
59+
groin

0 commit comments

Comments
 (0)