diff --git a/server/.openapi-generator/VERSION b/server/.openapi-generator/VERSION index 28cbf7c..32f3eaa 100644 --- a/server/.openapi-generator/VERSION +++ b/server/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0 \ No newline at end of file +5.0.1 \ No newline at end of file diff --git a/server/openapi_server/controllers/text_date_annotation_controller.py b/server/openapi_server/controllers/text_date_annotation_controller.py index bdf7269..179cc59 100644 --- a/server/openapi_server/controllers/text_date_annotation_controller.py +++ b/server/openapi_server/controllers/text_date_annotation_controller.py @@ -1,3 +1,5 @@ +import calendar + import connexion import re @@ -9,6 +11,10 @@ TextDateAnnotationResponse # noqa: E501 +MONTH_NUMBERS = {name: str(number).zfill(2) for + number, name in enumerate(calendar.month_name)} + + def create_text_date_annotations(): # noqa: E501 """Annotate dates in a clinical note @@ -29,22 +35,27 @@ def create_text_date_annotations(): # noqa: E501 matches = re.finditer( "([1-9]|0[1-9]|1[0-2])(/)([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])" + "(/)(19[0-9][0-9]|20[0-9][0-9])", note._text) - add_date_annotation(annotations, matches, "MM/DD/YYYY") + add_date_annotation(annotations, matches, "MM/DD/YYYY", + lambda match: match.expand(r'\5-\1-\3')) matches = re.finditer( "([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(\\.)([1-9]|0[1-9]|" + "1[0-2])(\\.)(19[0-9][0-9]|20[0-9][0-9])", note._text) - add_date_annotation(annotations, matches, "DD.MM.YYYY") + add_date_annotation(annotations, matches, "DD.MM.YYYY", + lambda match: match.expand(r'\5-\3-\1')) matches = re.finditer( "([1-9][1-9][0-9][0-9]|2[0-9][0-9][0-9])", note._text) - add_date_annotation(annotations, matches, "YYYY") + add_date_annotation(annotations, matches, "YYYY", + lambda match: match.expand(r'\1')) matches = re.finditer( "(January|February|March|April|May|June|July|August|" + "September|October|November|December)", note._text, re.IGNORECASE) - add_date_annotation(annotations, matches, "MMMM") + add_date_annotation(annotations, matches, "MMMM", + lambda match: + '--'+MONTH_NUMBERS[match.group(1)]) res = TextDateAnnotationResponse(annotations) status = 200 @@ -54,7 +65,7 @@ def create_text_date_annotations(): # noqa: E501 return res, status -def add_date_annotation(annotations, matches, date_format): +def add_date_annotation(annotations, matches, date_format, formatter): """ Converts matches to TextDateAnnotation objects and adds them to the annotations array specified. @@ -65,5 +76,6 @@ def add_date_annotation(annotations, matches, date_format): length=len(match[0]), text=match[0], date_format=date_format, + date=formatter(match), confidence=95.5 )) diff --git a/server/openapi_server/models/text_date_annotation.py b/server/openapi_server/models/text_date_annotation.py index 8b879f1..33df1b9 100644 --- a/server/openapi_server/models/text_date_annotation.py +++ b/server/openapi_server/models/text_date_annotation.py @@ -19,7 +19,7 @@ class TextDateAnnotation(Model): Do not edit the class manually. """ - def __init__(self, start=None, length=None, text=None, confidence=None, date_format=None): # noqa: E501 + def __init__(self, start=None, length=None, text=None, confidence=None, date=None, date_format=None): # noqa: E501 """TextDateAnnotation - a model defined in OpenAPI :param start: The start of this TextDateAnnotation. # noqa: E501 @@ -30,6 +30,8 @@ def __init__(self, start=None, length=None, text=None, confidence=None, date_for :type text: str :param confidence: The confidence of this TextDateAnnotation. # noqa: E501 :type confidence: float + :param date: The date of this TextDateAnnotation. # noqa: E501 + :type date: date :param date_format: The date_format of this TextDateAnnotation. # noqa: E501 :type date_format: str """ @@ -38,6 +40,7 @@ def __init__(self, start=None, length=None, text=None, confidence=None, date_for 'length': int, 'text': str, 'confidence': float, + 'date': date, 'date_format': str } @@ -46,6 +49,7 @@ def __init__(self, start=None, length=None, text=None, confidence=None, date_for 'length': 'length', 'text': 'text', 'confidence': 'confidence', + 'date': 'date', 'date_format': 'dateFormat' } @@ -53,6 +57,7 @@ def __init__(self, start=None, length=None, text=None, confidence=None, date_for self._length = length self._text = text self._confidence = confidence + self._date = date self._date_format = date_format @classmethod @@ -170,6 +175,29 @@ def confidence(self, confidence): self._confidence = confidence + @property + def date(self): + """Gets the date of this TextDateAnnotation. + + The date contained in the annotation # noqa: E501 + + :return: The date of this TextDateAnnotation. + :rtype: date + """ + return self._date + + @date.setter + def date(self, date): + """Sets the date of this TextDateAnnotation. + + The date contained in the annotation # noqa: E501 + + :param date: The date of this TextDateAnnotation. + :type date: date + """ + + self._date = date + @property def date_format(self): """Gets the date_format of this TextDateAnnotation. diff --git a/server/openapi_server/models/text_date_annotation_all_of.py b/server/openapi_server/models/text_date_annotation_all_of.py index e10e9c6..30deeaa 100644 --- a/server/openapi_server/models/text_date_annotation_all_of.py +++ b/server/openapi_server/models/text_date_annotation_all_of.py @@ -15,20 +15,25 @@ class TextDateAnnotationAllOf(Model): Do not edit the class manually. """ - def __init__(self, date_format=None): # noqa: E501 + def __init__(self, date=None, date_format=None): # noqa: E501 """TextDateAnnotationAllOf - a model defined in OpenAPI + :param date: The date of this TextDateAnnotationAllOf. # noqa: E501 + :type date: date :param date_format: The date_format of this TextDateAnnotationAllOf. # noqa: E501 :type date_format: str """ self.openapi_types = { + 'date': date, 'date_format': str } self.attribute_map = { + 'date': 'date', 'date_format': 'dateFormat' } + self._date = date self._date_format = date_format @classmethod @@ -42,6 +47,29 @@ def from_dict(cls, dikt) -> 'TextDateAnnotationAllOf': """ return util.deserialize_model(dikt, cls) + @property + def date(self): + """Gets the date of this TextDateAnnotationAllOf. + + The date contained in the annotation # noqa: E501 + + :return: The date of this TextDateAnnotationAllOf. + :rtype: date + """ + return self._date + + @date.setter + def date(self, date): + """Sets the date of this TextDateAnnotationAllOf. + + The date contained in the annotation # noqa: E501 + + :param date: The date of this TextDateAnnotationAllOf. + :type date: date + """ + + self._date = date + @property def date_format(self): """Gets the date_format of this TextDateAnnotationAllOf. diff --git a/server/openapi_server/openapi/openapi.yaml b/server/openapi_server/openapi/openapi.yaml index 05d003a..7d4b90c 100644 --- a/server/openapi_server/openapi/openapi.yaml +++ b/server/openapi_server/openapi/openapi.yaml @@ -491,6 +491,10 @@ components: type: object TextDateAnnotation_allOf: properties: + date: + description: The date contained in the annotation + format: date + type: string dateFormat: description: Date format (ISO 8601) example: MM/DD/YYYY diff --git a/server/openapi_server/test/integration/test_text_date_annotation_controller.py b/server/openapi_server/test/integration/test_text_date_annotation_controller.py index f501c38..1ce3454 100644 --- a/server/openapi_server/test/integration/test_text_date_annotation_controller.py +++ b/server/openapi_server/test/integration/test_text_date_annotation_controller.py @@ -21,7 +21,10 @@ def test_create_text_date_annotations(self): "identifier": "awesome-note", "noteType": "loinc:LP29684-5", "patientId": "awesome-patient", - "text": "On 12/26/2020, Ms. Chloe Price met with Dr. Prescott." + "text": + "On 12/26/2020, Ms. Chloe Price met with Dr. Prescott. She" + " mentioned that she was born in May of 1987. " + "Specifically, she was born on 11.4.1987." } } headers = { @@ -34,6 +37,19 @@ def test_create_text_date_annotations(self): headers=headers, data=json.dumps(text_date_annotation_request), content_type='application/json') + annotations = response.json['textDateAnnotations'] + self.assertTrue( + any(annotation['date'] == '2020' and + annotation['dateFormat'] == 'YYYY' + for annotation in annotations)) + self.assertTrue( + any(annotation['date'] == '2020-12-26' and + annotation['dateFormat'] == 'MM/DD/YYYY' + for annotation in annotations)) + self.assertTrue( + any(annotation['date'] == '--05' and + annotation['text'] == 'May' + for annotation in annotations)) self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))