ceckenrode commited on
Commit
f5db2d8
1 Parent(s): 9be2a9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -26
app.py CHANGED
@@ -24,14 +24,11 @@ basedir = os.path.dirname(__file__)
24
  #dataOMS = pd.read_csv(basedir + "\\" + f'SnomedOMS.csv')
25
  #dataICD10 = pd.read_csv(basedir + "\\" + f'ICD10Diagnosis.csv')
26
 
27
- filepath = '/Users/konyeach/src/Biomed_NLP_AI/'
28
-
29
  dataLOINC = pd.read_csv(f'LoincTableCore.csv')
30
  dataPanels = pd.read_csv(f'PanelsAndForms-ACW1208Labeled.csv')
31
  dataSNOMED = pd.read_csv(f'sct2_TextDefinition_Full-en_US1000124_20220901.txt',sep='\t')
32
  dataOMS = pd.read_csv(f'SnomedOMS.csv')
33
- dataICD10 = pd.read_csv(f'ICD10Diagnosis.csv')
34
- dataASMT = pd.read_csv(f'TemplateInfoMessage.csv')
35
 
36
  dir_path = os.path.dirname(os.path.realpath(__file__))
37
  EXAMPLES = {}
@@ -79,14 +76,6 @@ def MatchICD10(name):
79
  swith=data.loc[data['Description'].str.contains(name, case=False, na=False)]
80
  return swith
81
 
82
- def MatchASMT(name):
83
- #basedir = os.path.dirname(__file__)
84
- pd.set_option("display.max_rows", None)
85
- #data = pd.read_csv(basedir + "\\" + f'LoincTableCore.csv')    
86
- data = dataLOINC
87
- swith=data.loc[data['AssessmentInfo'].str.contains(name, case=False, na=False)]
88
- return swith
89
-
90
  def SaveResult(text, outputfileName):
91
  #try:
92
  basedir = os.path.dirname(__file__)
@@ -112,7 +101,7 @@ def SaveResult(text, outputfileName):
112
  def loadFile(filename):
113
  try:
114
  basedir = os.path.dirname(__file__)
115
- loadPath = basedir + "/" + filename
116
 
117
  print("Loading: " + loadPath)
118
 
@@ -132,8 +121,7 @@ def loadFile(filename):
132
 
133
  def get_today_filename():
134
  from datetime import datetime
135
- # date = datetime.now().strftime("%Y_%m_%d-%I.%M.%S.%p")
136
- date = datetime.now().strftime("%Y_%m_%d-%I")
137
  #print(f"filename_{date}") 'filename_2023_01_12-03-29-22_AM'
138
  return f"MedNER_{date}.csv"
139
 
@@ -152,7 +140,8 @@ def group_by_entity(raw):
152
  myEntityGroup = ent["entity_group"]
153
  print("Found entity group type: " + myEntityGroup)
154
 
155
- if (myEntityGroup in ['Sign_symptom', 'Detailed_description', 'History', 'Activity', 'Medication' ]):
 
156
  eterm = ent["word"].replace('#','')
157
  minlength = 3
158
  if len(eterm) > minlength:
@@ -163,7 +152,6 @@ def group_by_entity(raw):
163
  g3=MatchSNOMED(eterm)
164
  g4=MatchOMS(eterm)
165
  g5=MatchICD10(eterm)
166
- g6=MatchASMT(eterm)
167
  sAll = ""
168
 
169
  print("Saving to output file " + outputFile)
@@ -208,13 +196,6 @@ def group_by_entity(raw):
208
  s5 = ("ICD10," + myEntityGroup + "," + eterm + ",descriptions of ," + g52 + "," + g51 + ", Label,Value, Label,Value, Label,Value ")
209
  if g51 != 'Series([] )': SaveResult(s5, outputFile)
210
 
211
- #ASMT
212
- g61 = g6['ID'].to_string().replace(","," ").replace("\n"," ")
213
- g62 = g6['AssessmentName'].to_string().replace(","," ").replace("\n"," ")
214
- g63 = g6['AssessmentInfo'].to_string().replace(","," ").replace("\n"," ")
215
- s6 = ("ASMT," + myEntityGroup + "," + eterm + ",assessment info ," + g62 + "," + g63 + ", Label,Value, Label,Value, Label,Value  ")
216
- if g63 != 'Series([]  )': SaveResult(s6, outputFile)
217
-
218
  except ValueError as err:
219
  raise ValueError("Error in group by entity \n" + format_tb(err.__traceback__)[0] + err.args[0] + "\nEnd of error message.") from None
220
 
@@ -247,7 +228,6 @@ def ner(text):
247
  }
248
 
249
  outputFile = group_by_entity(raw)
250
- # print("print" + " " + outputFile)
251
  label = EXAMPLES.get(text, "Unknown")
252
  outputDataframe = pd.read_csv(outputFile)
253
  return (ner_content, outputDataframe, outputFile)
@@ -286,4 +266,4 @@ with demo:
286
  gr.Examples(examples, inputs=input)
287
  input.change(fn=ner, inputs=input, outputs=output)
288
  #layout="vertical"
289
- demo.launch(debug=True)
 
24
  #dataOMS = pd.read_csv(basedir + "\\" + f'SnomedOMS.csv')
25
  #dataICD10 = pd.read_csv(basedir + "\\" + f'ICD10Diagnosis.csv')
26
 
 
 
27
  dataLOINC = pd.read_csv(f'LoincTableCore.csv')
28
  dataPanels = pd.read_csv(f'PanelsAndForms-ACW1208Labeled.csv')
29
  dataSNOMED = pd.read_csv(f'sct2_TextDefinition_Full-en_US1000124_20220901.txt',sep='\t')
30
  dataOMS = pd.read_csv(f'SnomedOMS.csv')
31
+ dataICD10 = pd.read_csv(f'ICD10Diagnosis.csv')
 
32
 
33
  dir_path = os.path.dirname(os.path.realpath(__file__))
34
  EXAMPLES = {}
 
76
  swith=data.loc[data['Description'].str.contains(name, case=False, na=False)]
77
  return swith
78
 
 
 
 
 
 
 
 
 
79
  def SaveResult(text, outputfileName):
80
  #try:
81
  basedir = os.path.dirname(__file__)
 
101
  def loadFile(filename):
102
  try:
103
  basedir = os.path.dirname(__file__)
104
+ loadPath = basedir + "\\" + filename
105
 
106
  print("Loading: " + loadPath)
107
 
 
121
 
122
  def get_today_filename():
123
  from datetime import datetime
124
+ date = datetime.now().strftime("%Y_%m_%d-%I.%M.%S.%p")
 
125
  #print(f"filename_{date}") 'filename_2023_01_12-03-29-22_AM'
126
  return f"MedNER_{date}.csv"
127
 
 
140
  myEntityGroup = ent["entity_group"]
141
  print("Found entity group type: " + myEntityGroup)
142
 
143
+ # if (myEntityGroup in ['Sign_symptom', 'Detailed_description', 'History', 'Activity', 'Medication', 'DISEASE_DISORDER' ]):
144
+ if (myEntityGroup not in ['Match All']):
145
  eterm = ent["word"].replace('#','')
146
  minlength = 3
147
  if len(eterm) > minlength:
 
152
  g3=MatchSNOMED(eterm)
153
  g4=MatchOMS(eterm)
154
  g5=MatchICD10(eterm)
 
155
  sAll = ""
156
 
157
  print("Saving to output file " + outputFile)
 
196
  s5 = ("ICD10," + myEntityGroup + "," + eterm + ",descriptions of ," + g52 + "," + g51 + ", Label,Value, Label,Value, Label,Value ")
197
  if g51 != 'Series([] )': SaveResult(s5, outputFile)
198
 
 
 
 
 
 
 
 
199
  except ValueError as err:
200
  raise ValueError("Error in group by entity \n" + format_tb(err.__traceback__)[0] + err.args[0] + "\nEnd of error message.") from None
201
 
 
228
  }
229
 
230
  outputFile = group_by_entity(raw)
 
231
  label = EXAMPLES.get(text, "Unknown")
232
  outputDataframe = pd.read_csv(outputFile)
233
  return (ner_content, outputDataframe, outputFile)
 
266
  gr.Examples(examples, inputs=input)
267
  input.change(fn=ner, inputs=input, outputs=output)
268
  #layout="vertical"
269
+ demo.launch(debug=True)