שימוש ב-Healthcare Natural Language API

בדף הזה מוסבר איך להפעיל את Healthcare Natural Language API, להגדיר הרשאות ולקרוא לשיטה analyzeEntities כדי לחלץ תובנות רפואיות מטקסט רפואי.

סקירה כללית

‫Healthcare Natural Language API מספק פתרונות של למידת מכונה להפקת תובנות מטקסט רפואי. ‫Healthcare Natural Language API הוא חלק מ-Cloud Healthcare API. סקירה כללית של Healthcare Natural Language API זמינה במאמרי העזרה של Healthcare Natural Language API.

‫Healthcare Natural Language API מנתח טקסט רפואי לא מובנה, כמו תיקים רפואיים או תביעות ביטוח. לאחר מכן, הוא יוצר ייצוג של נתונים מובְנים של ישויות ידע רפואי שמאוחסנות במקורות הנתונים האלה, לצורך ניתוח ואוטומציה בהמשך. לדוגמה, אתם יכולים:

  • לחלץ מידע על מושגים רפואיים כמו מחלות, תרופות, מכשירים רפואיים, הליכים ומאפיינים רלוונטיים מבחינה קלינית
  • מיפוי של מושגים רפואיים למונחים רפואיים סטנדרטיים כמו RxNorm,‏ ICD-10,‏ MeSH ו-SNOMED CT (למשתמשים בארה"ב ובבריטניה בלבד)
  • הפקת תובנות רפואיות מטקסט ושילוב שלהן עם מוצרים לניתוח נתונים ב- Google Cloud

מיקומים זמינים

‫Healthcare Natural Language API זמין במיקומים הבאים:

שם המיקום תיאור המיקום
asia-south1 מומבאי, הודו
australia-southeast1 סידני, אוסטרליה
europe-west2 לונדון, בריטניה
europe-west4 הולנד
northamerica-northeast1 מונטריאול, קנדה
us-central1 איווה, ארה"ב

הפעלת Healthcare Natural Language API

לפני שמתחילים להשתמש ב-Healthcare Natural Language API, צריך להפעיל את ה-API בפרויקט Google Cloud . אפשר להשתמש ב-Healthcare Natural Language API בלי להפעיל או להשתמש בתכונות של Cloud Healthcare API.

כדי להפעיל את ה-API, מבצעים את השלבים הבאים:

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. 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.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  5. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  6. 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.

  7. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Verify that billing is enabled for your Google Cloud project.

  9. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. 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.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  10. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  11. 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.

  12. מפעילים את Cloud Healthcare API, אם הוא עדיין לא מופעל.

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, נדרשת ההרשאה serviceusage.services.enable. אם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד 'בעלים' (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד 'אדמין בממשק Service Usage' (roles/serviceusage.serviceUsageAdmin). איך מקצים תפקידים

    להפעלת ה-API

  13. התקינו את ה-CLI של Google Cloud.

  14. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  15. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init

הגדרת ההרשאות

כדי להשתמש בתכונות שבמדריך הזה, צריך את ההרשאה healthcare.nlpservice.analyzeEntities, שכלולה בתפקיד healthcare.nlpServiceViewer.

כדי להקצות את התפקיד הזה, מריצים את הפקודה gcloud projects add-iam-policy-binding:

gcloud projects add-iam-policy-binding PROJECT_ID \
    --member serviceAccount:SERVICE_ACCOUNT_ID \
    --role roles/healthcare.nlpServiceViewer

חילוץ ישויות, קשרים ומאפיינים הקשריים

‫Healthcare Natural Language API משתמש במודלים שמודעים להקשר כדי לחלץ ישויות רפואיות, קשרים ומאפיינים הקשריים. כל ישות טקסט מופקת לערך במילון רפואי. כדי לחלץ תובנות רפואיות ברמה הזו מטקסט רפואי, צריך להשתמש בשיטה projects.locations.services.nlp.analyzeEntities.

כדי לכלול את אוצר המילים ברישיון SNOMED CT באזכורים של הישויות, אפשר לעיין במאמר בנושא הכללת אוצר מילים ברישיון.

כדי לחלץ תובנות רפואיות מטקסט רפואי באמצעות Healthcare Natural Language API, שולחים בקשת POST ומציינים את טקסט היעד בשדה documentContent. הגודל המקסימלי של הטקסט הרפואי הוא 20,000 תווים ב-Unicode.

בדוגמאות הבאות מוצג שימוש במתודה analyzeEntities כדי לחלץ תובנות רפואיות מהטקסט הרפואי 'Insulin regimen 5 units IV will be administered for diabetes'.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud
  • ‫LOCATION: המיקום של מערך הנתונים

תוכן בקשת JSON:

{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

curl

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

cat > request.json << 'EOF'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}
EOF

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

@'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}
'@  | Out-File -FilePath request.json -Encoding utf8

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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

אם הבקשה מצליחה, התגובה כוללת את הפרטים הבאים:

  • ישויות של ידע רפואי שהמערכת מזהה
  • תכונות פונקציונליות
  • הקשרים בין הישויות שזוהו
  • מאפיינים לפי הקשר
  • מיפוי של ישויות ידע רפואי למינוחים סטנדרטיים

רשימה של סוגי ישויות, מאפיינים ויחסים נתמכים מופיעה במאמר תכונות של Healthcare Natural Language API.

התשובה הבאה מזהה את האינסולין הטיפולי, הישות עם הקוד C581 במערכת המינוח של NCI, כתרופה. התשובה כוללת גם את ציון רמת הביטחון שהוקצה לתשובה. מידע נוסף על שדות התגובה מופיע במאמרי העזרה בנושא analyzeEntities.

הכללת אוצר מילים ברישיון

כברירת מחדל, התשובות של Healthcare Natural Language API כוללות את המונחים הרפואיים הנתמכים.

אם הבקשה שלכם עומדת בדרישות הבאות, התשובה יכולה לכלול את אוצר המילים SNOMED Clinical Terms, US Version (SNOMEDCT_US):

  • בקשת ה-API מגיעה מארה"ב.
  • השדה licensedVocabularies בגוף הבקשה מכיל את הערך SNOMEDCT_US.

אם אתם לא צריכים את אוצר המילים של SNOMED CT, אף אחת מההגבלות האלה לא חלה עליכם.

בדוגמה הבאה אפשר לראות איך לכלול את אוצר המילים המורשה של SNOMED CT באובייקט LicensedVocabularies כדי לחלץ תובנות רפואיות מהטקסט הרפואי 'Insulin regimen 5 units IV will be administered for diabetes'.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud
  • ‫LOCATION: המיקום של מערך הנתונים

תוכן בקשת JSON:

{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "licensedVocabularies": [
    "SNOMEDCT_US",
    "ICD10CM"
  ]
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

curl

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

cat > request.json << 'EOF'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "licensedVocabularies": [
    "SNOMEDCT_US",
    "ICD10CM"
  ]
}
EOF

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

@'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "licensedVocabularies": [
    "SNOMEDCT_US",
    "ICD10CM"
  ]
}
'@  | Out-File -FilePath request.json -Encoding utf8

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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
אם הבקשה מצליחה, התשובה כוללת קודי אוצר מילים מתוך אוצר המילים המורשה SNOMEDCT_US ומתוך אוצר המילים המורשה ICD10CM. הפלט הוא הבא, וקודי אוצר המילים המורשים המבוקשים מודגשים:

חילוץ הפלט כחבילת FHIR R4

אתם יכולים לחלץ ישויות מטקסט ולמפות אותן למשאבים ולרכיבים של FHIR R4. חבילת FHIR R4 שמתקבלת כוללת את כל הישויות, ההתייחסויות לישויות והקשרים בפורמט JSON. לדוגמה, Healthcare Natural Language API ממפה את ישות הבסיס PROBLEM למשאב Condition FHIR R4 ואת הישות PROBLEM.ANATOMICAL_STRUCTURE לרכיב Condition.bodySite FHIR. רשימה של מיפויים אחרים מופיעה במאמר בנושא פלט של Healthcare Natural Language API כחבילת FHIR.

בדוגמאות הבאות אפשר לראות איך לחלץ תובנות רפואיות מהטקסט הרפואי 'Insulin regimen 5 units IV will be administered for diabetes' בחבילת FHIR R4. מידע נוסף זמין במאמר בנושא AlternativeOutputFormat.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud
  • ‫LOCATION: המיקום של מערך הנתונים

תוכן בקשת JSON:

{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "alternativeOutputFormat": "FHIR_BUNDLE"
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

curl

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

cat > request.json << 'EOF'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "alternativeOutputFormat": "FHIR_BUNDLE"
}
EOF

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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

שומרים את גוף הבקשה בקובץ בשם request.json. כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:

@'
{
  "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
  "alternativeOutputFormat": "FHIR_BUNDLE"
}
'@  | Out-File -FilePath request.json -Encoding utf8

לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-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
אם הבקשה מצליחה, התגובה מכילה אובייקט JSON עם הרשומות הבאות:
  • ההזכרות של הישויות שזוהו, עם הישויות והקשרים שלהן בפורמט שדומה לפורמט הפלט ב Extract entities, relations, and contextual attributes.
  • מפתח fhirBundle שמכיל משאב FHIR Bundle בפורמט מחרוזת. חבילת ה-FHIR כוללת את כל הישויות, את האזכורים של הישויות ואת הקשרים בפורמט JSON.