@@ -72,7 +72,7 @@ def normalize_match(self, match):
7272# frequency = a (1 if once, 2 if twice), period = 1, periodUnit = b (normalize to d, wk, mo, yr)
7373# NOTE: 'daily' won't match this pattern because it requires specific times *per* day
7474class FrequencyXTimesPerDay (FrequencyParser ):
75- pattern = r'(?P<frequency>' + RE_RANGE + r'\s* (?:time(?:s)?|x|nights|days)|once|twice)\s* (?:per|a|each|every|\/)\s* (?P<period_unit>day|week|month|year|d\b|w\b|mon|m\b|yr)'
75+ pattern = r'(?P<frequency>' + RE_RANGE + r'\s? (?:time(?:s)?|x|nights|days)|once|twice)\s? (?:per|a|each|every|\/)\s? (?P<period_unit>day|week|wk\b |month|year|d\b|w\b|mon|m\b|yr)'
7676 def normalize_match (self , match ):
7777 frequency = frequency_max = match .group ('frequency' )
7878 if (frequency ):
@@ -95,7 +95,7 @@ def normalize_match(self, match):
9595# frequency = a[0], frequencyMax = a[1], period = 1, periodUnit = b (normalize to d, wk, mo, yr)
9696# frequency = a (1 if once, 2 if twice, 1 if null), period = 1, periodUnit = b (normalize to d, wk, mo, yr)
9797class FrequencyXTimesDaily (FrequencyParser ):
98- pattern = r'(?:(?P<frequency>' + RE_RANGE + r'\s?(?:time(?:s)?|x)|once|twice)(?: \ba\b| per)?\s?)(?P<period_unit>day|\bd \b|daily|dialy|weekly|monthly|yearly|\bhs\b)'
98+ pattern = r'(?:(?P<frequency>' + RE_RANGE + r'\s?(?:time(?:s)?|x)|once|twice)(?: \ba\b| per)?\s?)(?P<period_unit>day|d \b|daily|dialy|weekly|monthly|yearly|\bhs\b)'
9999 def normalize_match (self , match ):
100100 frequency = frequency_max = match .group ('frequency' )
101101 if (frequency ):
@@ -112,11 +112,11 @@ def normalize_match(self, match):
112112
113113
114114# daily | nightly | weekly | monthly | yearly
115- # NOTE: this is where 'daily' matches
115+ # NOTE: this is where 'daily' matches
116116# frequency = a[0], frequencyMax = a[1], period = 1, periodUnit = b (normalize to d, wk, mo, yr)
117117# frequency = a (1 if once, 2 if twice, 1 if null), period = 1, periodUnit = b (normalize to d, wk, mo, yr)
118118class FrequencyDaily (FrequencyParser ):
119- pattern = r'(?P<period_unit>day| \bd\b|daily|dialy|weekly|monthly|yearly|\bhs\b)'
119+ pattern = r'(?P<period_unit>\bd\b|daily|dialy|weekly|monthly|yearly|\bhs\b)'
120120 def normalize_match (self , match ):
121121 frequency = 1
122122 period = 1
@@ -129,13 +129,13 @@ def normalize_match(self, match):
129129
130130
131131# every | each | per | q
132- # [other]
132+ # [other]
133133# day | week | month | morning | afternoon | evening | night | hs
134134# TODO: combine with the qpm/qhs/qday/qdaily group above (not sure if this still applies)
135135# frequency = 1, period = 1 (or 2 if a is not null), periodUnit = b (normalize to d, wk, mo), [when = b (normalize to MORN, AFT, EVE, etc]
136136# NOTE: moved below FrequencyDaily because "per day" was taking precedence in max daily dose text
137137class FrequencyEveryDay (FrequencyParser ):
138- pattern = r'(?:every|each|q|per)\s?(?P<period>other\b|o\b )?\s* (?:day (?:in the|at)\s?)?(?P<period_unit>hour|day|week|month|morning|afternoon|evening at bedtime|bedtime|evening|night|hs\b |pm\b |am\b |d\b)'
138+ pattern = r'(?:every|each|q|per|\ba )\s?(?P<period>other\b|o)?\s? (?:day (?:in the|at)\s?)?(?P<period_unit>hour|day|week|wk\b| month|morning(?! and) |afternoon|evening at bedtime|bedtime|evening|night|hs|pm|am|d\b)'
139139 def normalize_match (self , match ):
140140 frequency = 1
141141 period = 2 if match .group ('period' ) else 1
@@ -151,7 +151,7 @@ def normalize_match(self, match):
151151# Monday, Tuesday, Wednesday, and Friday
152152# dayOfWeek = a
153153class FrequencySpecificDayOfWeek (FrequencyParser ):
154- pattern = r'(?:every|on|q)\s+ (?P<day_of_week>(?:(?:\s* (?:and|&|\+|,)\s*)* (?:' + RE_DAYS_OF_WEEK + '))+)'
154+ pattern = r'(?:every|on|q)\s? (?P<day_of_week>(?:(?:\s? (?:and|&|\+|,|\s )\s?)? (?:' + RE_DAYS_OF_WEEK + '))+)'
155155 def normalize_match (self , match ):
156156 # TODO: normalize days of week to be comma or pipe delimited - tuesday and thursday -> tuesday|thursday or tuesday,thursday
157157 day_of_week = match .group ('day_of_week' )
@@ -166,7 +166,7 @@ def normalize_match(self, match):
166166# morning | evening | afternoon
167167# frequency = 1, when = a
168168class FrequencyInTheX (FrequencyParser ):
169- pattern = r'in the\s* (morning|evening|afternoon)'
169+ pattern = r'in the\s? (morning|evening|afternoon)'
170170 def normalize_match (self , match ):
171171 frequency = 1
172172 period = 1
@@ -197,7 +197,7 @@ def normalize_match(self, match):
197197# one time only
198198# count = 1
199199class FrequencyOneTime (FrequencyParser ):
200- pattern = r'(?:x\s?1\b(?!day| day|d\b| d\b|week| week|w\b| w\b|month| month|mon|m\b| m\b| mon\b)|(?:1|one) time(?: only)?(?! daily| per)|for (?:1|one) dose|once$ |once in imaging|at (?:the )?(?:first|1st) (?:onset:sign) of symptoms)'
200+ pattern = r'(?:x\s?1\b(?!day| day|d\b| d\b|week| week|w\b| w\b|month| month|mon|m\b| m\b| mon\b)|(?:1|one) time(?: only)?(?! daily| per)|for (?:1|one) dose|once|once in imaging|before transfusion|(?:one|1) hour prior to (?:dental )?appointment |at (?:the )?(?:first|1st) (?:onset:sign) of symptoms)'
201201 def normalize_match (self , match ):
202202 count = 1
203203 frequency_text_start , frequency_text_end = match .span ()
@@ -208,12 +208,11 @@ def normalize_match(self, match):
208208
209209
210210class FrequencyAsDirected (FrequencyParser ):
211- pattern = r'as directed(?: on package)?|ad lib|as instructed|see admin instructions|see notes'
211+ pattern = r'as directed(?: on package)?|ad lib|as dir\b|as instructed|see admin instructions|follow package directions| see notes|sliding scale|per package instructions '
212212 def normalize_match (self , match ):
213- # TODO: how to capture just text?
214- # text = 'as directed'
215213 frequency_text_start , frequency_text_end = match .span ()
216- frequency_text = match .group (0 )
214+ # frequency_text = match.group(0)
215+ frequency_text = 'as directed'
217216 frequency_readable = frequency_text
218217 # TODO: normalize text numbers to integer numbers - maybe make separate normalize_period_unit function that also hits the text_to_int function?
219218 return self .generate_match ({'frequency_text_start' : frequency_text_start , 'frequency_text_end' : frequency_text_end , 'frequency_text' : frequency_text , 'frequency_readable' : frequency_readable })
@@ -236,5 +235,5 @@ def normalize_match(self, match):
236235 FrequencyAtBedtime (),
237236 FrequencyOneTime (),
238237 # NOTE: removing this parser for DRX implementation - may consider adding back
239- # FrequencyAsDirected(),
238+ FrequencyAsDirected (),
240239]
0 commit comments