Questa pagina spiega come abilitare l'API Healthcare Natural Language, configurare le autorizzazioni e chiamare il metodo analyzeEntities
per estrarre insight medici da testi medici.
Panoramica
L'API Healthcare Natural Language fornisce soluzioni di machine learning per ricavare insight da testi medici. L'API Healthcare Natural Language fa parte dell'API Cloud Healthcare. Per una panoramica dell'API Healthcare Natural Language, consulta la documentazione concettuale dell'API Healthcare Natural Language.
L'API Healthcare Natural Language analizza testi medici non strutturati, come cartelle cliniche o richieste di rimborso assicurativo. Quindi, genera una rappresentazione strutturata dei dati delle entità di conoscenza medica archiviate in queste origini dati per l'analisi e l'automazione downstream. Ad esempio, puoi:
- Estrai informazioni su concetti medici come malattie, farmaci, dispositivi medici, procedure e i relativi attributi clinicamente rilevanti
- Mappare i concetti medici a vocabolari medici standard come RxNorm, ICD-10, MeSH e SNOMED CT (solo per utenti di Stati Uniti e Regno Unito)
- Deriva approfondimenti medici dal testo e integrali con i prodotti di analisi dei dati in Google Cloud
Paesi in cui è disponibile il servizio
L'API Healthcare Natural Language è disponibile nelle seguenti località:
Nome della sede | Descrizione della sede |
---|---|
asia-south1 |
Mumbai, India |
australia-southeast1 |
Sydney, Australia |
europe-west2 |
Londra, Regno Unito |
europe-west4 |
Paesi Bassi |
northamerica-northeast1 |
Montréal, Canada |
us-central1 |
Iowa, Stati Uniti |
Abilitare l'API Healthcare Natural Language
Prima di iniziare a utilizzare l'API Healthcare Natural Language, devi abilitare l'API per il tuo progetto Google Cloud . Puoi utilizzare l'API Healthcare Natural Language senza abilitare o utilizzare le funzionalità dell'API Cloud Healthcare.
Per abilitare l'API, completa i seguenti passaggi:
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
Enable the Cloud Healthcare API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
Se utilizzi un provider di identità (IdP) esterno, devi prima accedere a gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init
Configurare le autorizzazioni
Per utilizzare le funzionalità descritte in questa guida, devi disporre dell'autorizzazione
healthcare.nlpservice.analyzeEntities
, inclusa nel ruolohealthcare.nlpServiceViewer
.Per assegnare questo ruolo, esegui il comando
gcloud projects add-iam-policy-binding
:gcloud projects add-iam-policy-binding PROJECT_ID \ --member serviceAccount:SERVICE_ACCOUNT_ID \ --role roles/healthcare.nlpServiceViewer
Estrazione di entità, relazioni e attributi contestuali
L'API Healthcare Natural Language utilizza modelli sensibili al contesto per estrarre entità mediche, relazioni e attributi contestuali. Ogni entità di testo viene estratta in una voce del dizionario medico. Per estrarre questo livello di approfondimenti medici dal testo medico, utilizza il metodo
projects.locations.services.nlp.analyzeEntities
.Per includere il vocabolario con licenza SNOMED CT nelle menzioni di entità, vedi Includere vocabolari con licenza.
Per estrarre approfondimenti medici da testi medici utilizzando l'API Healthcare Natural Language, crea una richiesta
POST
e specifica il testo di destinazione nel campodocumentContent
. La dimensione massima del testo medico è di 20.000 caratteri Unicode.Gli esempi riportati di seguito mostrano come utilizzare il metodo
analyzeEntities
per estrarre informazioni mediche dal testo medico "Insulin regimen 5 units IV will be administered for diabetes.".REST
Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
PROJECT_ID
: l'ID del tuo progetto Google CloudLOCATION
: la posizione del set di dati
Corpo JSON della richiesta:
{ "documentContent": "Insulin regimen 5 units IV will be administered for diabetes." }
Per inviare la richiesta, scegli una di queste opzioni:
curl
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:cat > request.json << 'EOF' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes." } EOF
Quindi esegui questo comando per inviare la richiesta REST:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"PowerShell
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:@' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes." } '@ | Out-File -FilePath request.json -Encoding utf8
Quindi esegui questo comando per inviare la richiesta REST:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand ContentSe la richiesta ha esito positivo, la risposta include le seguenti informazioni:
- Entità di conoscenza medica riconosciute
- Funzionalità
- Relazioni tra le entità riconosciute
- Attributi contestuali
- Mappature delle entità di conoscenza medica in terminologie standard
Per un elenco dei tipi di entità, attributi e relazioni supportati, consulta la sezione Funzionalità dell'API Healthcare Natural Language.
La seguente risposta identifica l'insulina terapeutica, l'entità con il codice
C581
nel sistema di terminologia NCI, come farmaco. La risposta include anche il punteggio di confidenza assegnato alla risposta. Per saperne di più sui campi di risposta, consulta la documentazione dianalyzeEntities
.Includi vocabolari concessi in licenza
Per impostazione predefinita, le risposte dell'API Healthcare Natural Language includono i vocabolari medici supportati.
Puoi includere il vocabolario SNOMED Clinical Terms, US Version (SNOMEDCT_US) nella risposta se la tua richiesta soddisfa i seguenti requisiti:
- La richiesta API ha origine negli Stati Uniti.
- Il campo
licensedVocabularies
nel corpo della richiesta ha il valoreSNOMEDCT_US
.
Se non hai bisogno del vocabolario SNOMED CT, nessuna di queste limitazioni si applica.
Il seguente esempio mostra come includere il vocabolario con licenza SNOMED CT nell'oggetto
LicensedVocabularies
per estrarre informazioni mediche dal testo medico "Insulin regimen 5 units IV will be administered for diabetes.".REST
Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
PROJECT_ID
: l'ID del tuo progetto Google CloudLOCATION
: la posizione del set di dati
Corpo JSON della richiesta:
{ "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "licensedVocabularies": [ "SNOMEDCT_US", "ICD10CM" ] }
Per inviare la richiesta, scegli una di queste opzioni:
curl
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:cat > request.json << 'EOF' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "licensedVocabularies": [ "SNOMEDCT_US", "ICD10CM" ] } EOF
Quindi esegui questo comando per inviare la richiesta REST:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"PowerShell
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:@' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "licensedVocabularies": [ "SNOMEDCT_US", "ICD10CM" ] } '@ | Out-File -FilePath request.json -Encoding utf8
Quindi esegui questo comando per inviare la richiesta REST:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand ContentSNOMEDCT_US
eICD10CM
. L'output è il seguente e i codici del vocabolario con licenza richiesti sono in grassetto:Estrai l'output come bundle FHIR R4
Puoi estrarre entità dal testo e mapparle a risorse ed elementi FHIR R4. Il bundle FHIR R4 risultante include tutte le entità, le menzioni di entità e le relazioni in formato JSON. Ad esempio, l'API Healthcare Natural Language mappa l'entità di base
PROBLEM
alla risorsa FHIR R4Condition
e l'entitàPROBLEM.ANATOMICAL_STRUCTURE
all'elemento FHIRCondition.bodySite
. Per un elenco di altri mapping, consulta Output dell'API Healthcare Natural Language come bundle FHIR.Gli esempi riportati di seguito mostrano come estrarre informazioni mediche dal testo medico "Insulin regimen 5 units IV will be administered for diabetes." (Regime insulinico 5 unità IV saranno somministrate per il diabete) in un bundle FHIR R4. Per maggiori informazioni, vedi l'oggetto
AlternativeOutputFormat
.REST
Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
PROJECT_ID
: l'ID del tuo progetto Google CloudLOCATION
: la posizione del set di dati
Corpo JSON della richiesta:
{ "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "alternativeOutputFormat": "FHIR_BUNDLE" }
Per inviare la richiesta, scegli una di queste opzioni:
curl
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:cat > request.json << 'EOF' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "alternativeOutputFormat": "FHIR_BUNDLE" } EOF
Quindi esegui questo comando per inviare la richiesta REST:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"PowerShell
Salva il corpo della richiesta in un file denominato
request.json
. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory corrente:@' { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "alternativeOutputFormat": "FHIR_BUNDLE" } '@ | Out-File -FilePath request.json -Encoding utf8
Quindi esegui questo comando per inviare la richiesta REST:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand Content- Le menzioni di entità riconosciute con le entità e le relative relazioni in un formato simile all'output in Estrazione di entità, relazioni e attributi contestuali.
- Una chiave
fhirBundle
contenente una risorsa bundle FHIR formattata come stringa. Il bundle FHIR include tutte le entità, le menzioni di entità e le relazioni in formato JSON.