Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAls89 committed Mar 24, 2020
1 parent 94671a1 commit 76cc181
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
##Helper function for yielding on batch fetch
def stream_json(entities):
logger.info("streaming started")
#number_id = 112
try:
first = True
yield '['
for i, row in enumerate(entities):
if not first:
yield ','
else:
first = False
#yield json.dumps({'alt_id': f'{number_id}'})
#yield ','
first = False
yield json.dumps(row)
#number_id + 1
yield ']'
except Exception as e:
logger.error(f"Exiting with error : {e}")
Expand All @@ -54,19 +50,8 @@ def parse(self, stream):
l = list(Dotdictify(root_element).get(self._xml_path))
else:
l = [Dotdictify(root_element).get(self._xml_path)]

else:
try:
imbedded_xml = xmltodict.parse("<html>" + root_element["ichicsr"]["safetyreport"]["patient"]["parent"]["parentmedicalrelevanttext"] + "</html>")
root_element["ichicsr"]["safetyreport"]["patient"]["parent"]["parentmedicalrelevanttext"] = imbedded_xml["html"]
except TypeError as e:
logger.info(f"None imbedded xml defined. Failing with error: {e}")
except ExpatError as e:
logger.info(f"None imbedded xml defined. Failing with error: {e}")
except KeyError as e:
logger.info(f"None imbedded xml element of {e}")
except UnboundLocalError as e:
logger.info(f"None imbedded xml element of {e}")

l = [root_element]

if self._updated_path is not None:
Expand Down Expand Up @@ -102,7 +87,6 @@ def get_folder():
for xml_file in xml_to_dict['files']:
try:
parsed_xml = parser.parse(str(xml_file))
#logger.info(f"Printing content of parsed xml : {parsed_xml}")
xml_content.append(parsed_xml[0])
except Exception as e:
logger.info(f"Skipping xml file with error : {e}")
Expand Down

0 comments on commit 76cc181

Please sign in to comment.