コード例 #1
0
 def testNote(self):
     """Test Note"""
     # FIXME: construct object with mandatory attributes with example values
     # model = Note()  # noqa: E501
     Note(identifier=NoteId("identifier"),
          text="text",
          type="type",
          patient_id=PatientId('patient-1'))
コード例 #2
0
 def testNoteCreateRequest(self):
     """Test NoteCreateRequest"""
     # FIXME: construct object with mandatory attributes with example values
     # model = NoteCreateRequest()  # noqa: E501
     NoteCreateRequest(
         text="amazing text",
         type="type note",
         patient_id=PatientId("patient_id")
     )
コード例 #3
0
 def testPageOfNotes(self):
     """Test PageOfNotes"""
     # FIXME: construct object with mandatory attributes with example values
     # model = PageOfNotes()  # noqa: E501
     PageOfNotes(
         offset=PageOffset(10),
         limit=PageLimit(10),
         links=ResponsePageMetadataLinks(next="next"),
         total_results=30,
         notes=[Note(identifier=NoteId("identifier"),
                     text="text", type="type",
                     patient_id=PatientId('patient-1'))]
     )
コード例 #4
0

ANNOTATOR_TYPE_MAP = {
    'nlpsandbox:physical-address-annotator':
    ('text_physical_address', 'textPhysicalAddressAnnotations'),
    'nlpsandbox:person-name-annotator':
    ('text_person_name', 'textPersonNameAnnotations'),
    'nlpsandbox:date-annotator': ('text_date', 'textDateAnnotations'),
    'nlpsandbox:contact-annotator': ('text_contact', 'textContactAnnotations'),
    'nlpsandbox:id-annotator': ('text_id', 'textIdAnnotations'),
}

SAMPLE_NOTE = Note(
    type="loinc:LP29684-5",
    identifier=NoteId("snote"),
    patient_id=PatientId("abc123"),
    text="Mary Williamson came back from Seattle yesterday, 12 December 2013.")

SAMPLE_NOTE_ANNOTATIONS = {
    'text_date': [{
        'confidence': 95,
        'dateFormat': 'YYYY',
        'length': 4,
        'start': 62,
        'text': '2013'
    }, {
        'confidence': 95,
        'dateFormat': 'MMMM',
        'length': 8,
        'start': 53,
        'text': 'December'
コード例 #5
0
def create_deidentified_notes(deidentify_request=None):  # noqa: E501
    """Deidentify a clinical note

    Returns the deidentified note # noqa: E501

    :param deidentify_request:
    :type deidentify_request: dict | bytes

    :rtype: DeidentifyResponse
    """
    if connexion.request.is_json:
        deid_request = DeidentifyRequest.from_dict(
            connexion.request.get_json())
        note = deid_request.note

        # Make set of all annotation types in the de-id request
        all_annotation_types = {
            annotation_type
            for annotation_types in [
                deid_step.annotation_types
                for deid_step in deid_request.deidentification_steps
            ] for annotation_type in annotation_types
        }

        config = Config()
        # Annotations is a dict[key: list[str]]
        annotations = {
            'text_date': [],
            'text_person_name': [],
            'text_location': [],
            'text_contact': [],
            'text_id': []
        }

        # Convert to NLPSandboxClient's Note object
        client_note = client.Note(identifier=NoteId(note.identifier),
                                  text=note.text,
                                  type=note.type,
                                  patient_id=PatientId(note.patient_id))

        if 'text_date' in all_annotation_types:
            annotations['text_date'] = client.annotate_note(
                host=config.date_annotator_api_url,
                note=client_note,
                tool_type='nlpsandbox:date-annotator')['textDateAnnotations']
        if 'text_person_name' in all_annotation_types:
            annotations['text_person_name'] = client.annotate_note(
                host=config.person_name_annotator_api_url,
                note=client_note,
                tool_type='nlpsandbox:person-name-annotator'
            )['textPersonNameAnnotations']
        if 'text_location' in all_annotation_types:
            annotations['text_location'] = client.annotate_note(
                host=config.location_annotator_api_url,
                note=client_note,
                tool_type='nlpsandbox:location-annotator'
            )['textLocationAnnotations']
        if 'text_contact' in all_annotation_types:
            annotations['text_contact'] = client.annotate_note(
                host=config.contact_annotator_api_url,
                note=client_note,
                tool_type='nlpsandbox:contact-annotator'
            )['textContactAnnotations']
        if 'text_id' in all_annotation_types:
            annotations['text_id'] = client.annotate_note(
                host=config.id_annotator_api_url,
                note=client_note,
                tool_type='nlpsandbox:id-annotator')['textIdAnnotations']

        # De-identify note
        deidentified_note = \
            Note.from_dict({note.attribute_map[key]: value for key, value
                            in note.to_dict().items()})
        deidentified_annotations = \
            {key: value.copy() for key, value in annotations.items()}

        deid_config: DeidentificationStep
        for deid_config in deid_request.deidentification_steps:
            if deid_config.masking_char_config is not None:
                masking_char = \
                    deid_config.masking_char_config.masking_char
                deidentified_note, deidentified_annotations = \
                    apply_masking_char(
                        deidentified_note,
                        deidentified_annotations,
                        deid_config.confidence_threshold,
                        deid_config.annotation_types,
                        masking_char
                    )
            elif deid_config.redact_config \
                    is not None:
                deidentified_note, deidentified_annotations = apply_redaction(
                    deidentified_note, deidentified_annotations,
                    deid_config.confidence_threshold,
                    deid_config.annotation_types)
            elif deid_config.annotation_type_mask_config \
                    is not None:
                deidentified_note, deidentified_annotations = \
                    apply_annotation_type(
                        deidentified_note,
                        deidentified_annotations,
                        deid_config.confidence_threshold,
                        deid_config.annotation_types
                    )
            else:
                return "No supported de-identification method supported in " \
                       "request: '%s'" % (
                           str(deid_config.to_dict()),), 400

        deidentify_response = DeidentifyResponse(
            deidentified_note=deidentified_note,
            original_annotations=AnnotationSet(
                text_date_annotations=annotations['text_date'],
                text_person_name_annotations=annotations['text_person_name'],
                text_location_annotations=annotations['text_location'],
                text_contact_annotations=annotations['text_contact'],
                text_id_annotations=annotations['text_id'],
            ),
            deidentified_annotations=AnnotationSet(
                text_date_annotations=deidentified_annotations['text_date'],
                text_person_name_annotations=deidentified_annotations[
                    'text_person_name'],
                text_location_annotations=deidentified_annotations[
                    'text_location'],
                text_contact_annotations=deidentified_annotations[
                    'text_contact'],
                text_id_annotations=deidentified_annotations['text_id'],
            ))
        return deidentify_response, 200
コード例 #6
0
 def testPatientId(self):
     """Test PatientId"""
     PatientId("patient-1")
コード例 #7
0
 def testPatient(self):
     """Test Patient"""
     # FIXME: construct object with mandatory attributes with example values
     # model = Patient()  # noqa: E501
     Patient(identifier=PatientId("patient-id"), gender="male")