fork download
  1. import re
  2. files = ["""Functional Assessment: Patient currently displays the following functional limitations and would benefit from treatment to maximize functional use and pain reduction: Range of Motion: limited . ADLs: limited . Gait: limited . Stairs: limited . Squatting: limited . Work participation status: limited . Current Status: The patient's current status is improving.
  3.  
  4. Location: Right side
  5. output: limited | Right side""","""
  6. Functional Assessment: Patient currently displays the following functional limitations and would benefit from treatment to maximize functional use and pain reduction: Range of Motion:
  7. painful
  8. and
  9. limited
  10.  
  11. Strength:
  12. limited """]
  13. reg = re.compile(r'\b(Location|Range of Motion):\s*([^\W_].*?)\s*(?=(?:\.\s*)?[^\W\d_]+:|\Z)', re.S | re.M)
  14. for file in files:
  15. flag = False
  16. tmp = ""
  17. for line in file.splitlines():
  18. if line.startswith("Functional Assessment:"):
  19. tmp = tmp + line + "\n"
  20. flag = not flag
  21. elif flag:
  22. tmp = tmp + line + "\n"
  23. #print(tmp)
  24. print(dict(list(reg.findall(tmp))))
  25.  
  26.  
  27.  
Success #stdin #stdout 0.04s 9660KB
stdin
Standard input is empty
stdout
{'Location': 'Right side', 'Range of Motion': 'limited'}
{'Range of Motion': 'painful \nand\nlimited'}