Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.0.1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import calendar

import connexion
import re

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
))
30 changes: 29 additions & 1 deletion server/openapi_server/models/text_date_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
"""
Expand All @@ -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
}

Expand All @@ -46,13 +49,15 @@ def __init__(self, start=None, length=None, text=None, confidence=None, date_for
'length': 'length',
'text': 'text',
'confidence': 'confidence',
'date': 'date',
'date_format': 'dateFormat'
}

self._start = start
self._length = length
self._text = text
self._confidence = confidence
self._date = date
self._date_format = date_format

@classmethod
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 29 additions & 1 deletion server/openapi_server/models/text_date_annotation_all_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions server/openapi_server/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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'))

Expand Down