feat: pipeline T2A - anonymisation, extraction CIM-10 et intégration edsnlp
Pipeline complet de traitement de documents médicaux PDF : - Extraction texte (pdfplumber) et classification (Trackare/CRH) - Anonymisation multi-couche (regex + NER CamemBERT + sweep) - Extraction médicale CIM-10 hybride : edsnlp (AP-HP) enrichit les diagnostics, médicaments (codes ATC via Romedi) et négation, avec fallback regex pour les patterns spécifiques - Fix sentencepiece pinné à <0.2.0 pour compatibilité CamemBERT Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
126
tests/test_extraction.py
Normal file
126
tests/test_extraction.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""Tests pour le module d'extraction."""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.extraction.document_classifier import classify
|
||||
from src.extraction.crh_parser import parse_crh
|
||||
from src.extraction.trackare_parser import parse_trackare, _clean_person_name
|
||||
|
||||
|
||||
class TestDocumentClassifier:
|
||||
def test_classify_trackare(self):
|
||||
text = """CENTRE HOSPITALIER COTE BASQUE
|
||||
Dossier Patient
|
||||
Détails des patients
|
||||
Nom de naissance: CLIER IPP: 01306172
|
||||
Détails épisode
|
||||
Episode No: 23042753
|
||||
Signes Vitaux"""
|
||||
assert classify(text) == "trackare"
|
||||
|
||||
def test_classify_crh(self):
|
||||
text = """N° Finess CENTRE HOSPITALIER COTE BASQUE
|
||||
Pôle Spécialités Médicales
|
||||
Service de Gastro-Entérologie
|
||||
Mon cher confrère,
|
||||
Votre patiente a été hospitalisée"""
|
||||
assert classify(text) == "crh"
|
||||
|
||||
def test_classify_trackare_by_ipp(self):
|
||||
text = "IPP: 12345678 Episode No: 87654321"
|
||||
assert classify(text) == "trackare"
|
||||
|
||||
|
||||
class TestCRHParser:
|
||||
def test_parse_patient_info(self):
|
||||
text = """MME NARBAIS AUDREY
|
||||
MAISON IRREXELAIA
|
||||
64430 ST ETIENNE DE BAIGORRY
|
||||
|
||||
Mon cher confrère,
|
||||
Votre patiente NARBAIS Audrey née le 23/02/1980 a été hospitalisée
|
||||
du 25/02/2023 au 03/03/2023 pour le motif suivant:
|
||||
Pancréatite aiguë lithiasique"""
|
||||
result = parse_crh(text)
|
||||
|
||||
assert result["patient"]["nom_complet"] == "NARBAIS AUDREY"
|
||||
assert result["patient"]["sexe"] == "F"
|
||||
assert result["patient"]["date_naissance"] == "23/02/1980"
|
||||
|
||||
def test_parse_sejour(self):
|
||||
text = """Votre patiente née le 23/02/1980 a été hospitalisée
|
||||
du 25/02/2023 au 03/03/2023 pour le motif suivant:
|
||||
Pancréatite aiguë"""
|
||||
result = parse_crh(text)
|
||||
|
||||
assert result["sejour"]["date_entree"] == "25/02/2023"
|
||||
assert result["sejour"]["date_sortie"] == "03/03/2023"
|
||||
|
||||
def test_parse_medecins(self):
|
||||
text = "Dr PUJOS. Dr F. AUDEMAR. Docteur DUTREY Sarah."
|
||||
result = parse_crh(text)
|
||||
|
||||
assert any("PUJOS" in m for m in result["medecins"])
|
||||
assert any("AUDEMAR" in m for m in result["medecins"])
|
||||
|
||||
|
||||
class TestTrackareParser:
|
||||
def test_parse_patient_info(self):
|
||||
text = """Nom de naissance: CLIER IPP: 01306172
|
||||
Nom et Prénom: NARBAIS AUDREY Date de naissance: 23/02/1980
|
||||
Sexe: Féminin Lieu de naissance: CHAMPIGNY SUR MARNE
|
||||
Adresse: MAISON IRREXELAIA QUARTIER AUZO TTIPI Ville de résidence: ST ETIENNE DE BAIGORRY
|
||||
Code Postal: 64430
|
||||
Episode No: 23042753
|
||||
Date d'admission: 25/02/2023 Heure d'admission: 03:07
|
||||
Date de sortie: 03/03/2023
|
||||
Taille: 162 cm - Poids: 90.2 kg - IMC: 34.370"""
|
||||
result = parse_trackare(text)
|
||||
|
||||
assert result["patient"]["nom_naissance"] == "CLIER"
|
||||
assert result["patient"]["nom_prenom"] == "NARBAIS AUDREY"
|
||||
assert result["patient"]["ipp"] == "01306172"
|
||||
assert result["patient"]["sexe"] == "F"
|
||||
assert result["patient"]["date_naissance"] == "23/02/1980"
|
||||
assert result["patient"]["imc"] == 34.370
|
||||
assert result["sejour"]["episode"] == "23042753"
|
||||
assert result["sejour"]["date_entree"] == "25/02/2023"
|
||||
|
||||
def test_parse_diagnostics(self):
|
||||
text = """Diagnostic aux urgences
|
||||
Type Etat Code Date
|
||||
Principal actif K80.5 Calcul des canaux biliaires (sans angiocholite ni cholécystite) [CMA2] 25/02/2023 05:27"""
|
||||
result = parse_trackare(text)
|
||||
|
||||
assert len(result["diagnostics"]) >= 1
|
||||
assert result["diagnostics"][0]["code_cim10"] == "K80.5"
|
||||
assert result["diagnostics"][0]["type"] == "Principal"
|
||||
|
||||
def test_parse_vitals(self):
|
||||
text = """Poids/Taille
|
||||
Taille [cm] 162,00
|
||||
Poids [kg] 90,20
|
||||
Indice
|
||||
de masse 34.370"""
|
||||
result = parse_trackare(text)
|
||||
|
||||
assert result["signes_vitaux"]["taille_cm"] == 162.0
|
||||
assert result["signes_vitaux"]["poids_kg"] >= 90.0
|
||||
assert result["signes_vitaux"]["imc"] == 34.370
|
||||
|
||||
|
||||
class TestCleanPersonName:
|
||||
def test_clean_simple(self):
|
||||
assert _clean_person_name("Sarah DUTREY") == "Sarah DUTREY"
|
||||
|
||||
def test_clean_with_noise(self):
|
||||
assert _clean_person_name("Sarah DUTREY une complication") == "Sarah DUTREY"
|
||||
|
||||
def test_clean_multiline(self):
|
||||
assert _clean_person_name("Sarah\nDUTREY") == "Sarah DUTREY"
|
||||
|
||||
def test_clean_medical_term(self):
|
||||
assert _clean_person_name("Bilirubine") == ""
|
||||
|
||||
def test_clean_empty(self):
|
||||
assert _clean_person_name("") == ""
|
||||
Reference in New Issue
Block a user