Creazione e gestione degli archivi HL7v2

Questa pagina spiega come creare, modificare, visualizzare ed eliminare gli archivi Health Level Seven Version 2.x (HL7v2). Gli archivi HL7v2 contengono messaggi HL7v2, che vengono utilizzati per trasmettere i dati clinici tra i sistemi.

creazione di un archivio HL7v2

Prima di poter generare un archivio HL7v2, devi creare un set di dati.

Quando crei un archivio HL7v2, specifica la versione del parser V3. Non puoi modificare la versione del parser dopo aver creato l'archivio HL7v2.

Gli esempi riportati di seguito mostrano come creare un archivio HL7v2 utilizzando l'analizzatore sintattico V3.

Console

  1. Nella console Google Cloud, vai alla pagina Set di dati.

    Vai a Set di dati

  2. Seleziona il set di dati in cui desideri creare l'archivio HL7v2. Viene visualizzata la pagina Set di dati.

  3. Fai clic su Crea datastore. Viene visualizzata la pagina Crea datastore.

  4. Nel menu Tipo, seleziona HL7v2.

  5. Nel campo ID, inserisci un nome per l'archivio HL7v2. Il nome deve essere univoco nel set di dati. Per ulteriori requisiti di denominazione, consulta Requisiti per le dimensioni e i caratteri consentiti.

  6. Tocca Avanti. Viene visualizzata la sezione Configura il tuo archivio HL7v2.

  7. Configura le seguenti impostazioni:

    1. Nella sezione Versione, lascia invariata la selezione predefinita V3.
    2. Per consentire la creazione e l'importazione di messaggi HL7v2 senza intestazione, seleziona Consenti intestazioni di messaggi null (MSH).
    3. Per impostare un carattere di terminazione dei segmenti personalizzato, fai clic su Imposta un carattere di terminazione dei segmenti personalizzato e inseriscilo nel campo Carattere di terminazione dei segmenti. Per saperne di più, consulta Impostare il carattere di terminazione dei segmenti.
    4. Per rifiutare i messaggi HL7v2 in arrivo con gli stessi byte non elaborati di un messaggio HL7v2 già esistente nell'archivio HL7v2, seleziona Rifiuta messaggi duplicati.
  8. Tocca Avanti. Viene visualizzata la sezione Ricevi notifiche Cloud Pub/Sub.

  9. Se vuoi ricevere notifiche Pub/Sub quando si verifica un evento clinico nel tuo archivio HL7v2, specifica l'argomento Pub/Sub. L'argomento deve esistere prima di poterlo configurare nell'archivio HL7v2.

  10. Tocca Avanti. Viene visualizzata la sezione Aggiungi etichette per organizzare i datastore.

  11. Per aggiungere una o più etichette chiave-valore all'archivio HL7v2, fai clic su Aggiungi etichetta. Per maggiori informazioni sulle etichette delle risorse, consulta Utilizzo delle etichette delle risorse.

  12. Fai clic su Crea. Viene visualizzata la pagina Set di dati, mentre l'archivio HL7v2 viene visualizzato nella tabella Datastore.

gcloud

Google Cloud CLI non supporta l'impostazione della versione del parser durante la creazione di un archivio HL7v2. Usa invece la console Google Cloud, curl, PowerShell o la tua lingua preferita.

REST

Per creare un archivio HL7v2, utilizza il metodo projects.locations.datasets.hl7V2Stores.create.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

Corpo JSON della richiesta:

{
  "parserConfig": {
    "version": "V3"
  }
}

Per inviare la richiesta, scegli una delle seguenti opzioni:

arricciatura

Salva il corpo della richiesta in un file denominato request.json. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory attuale:

cat > request.json << 'EOF'
{
  "parserConfig": {
    "version": "V3"
  }
}
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; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID"

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 attuale:

@'
{
  "parserConfig": {
    "version": "V3"
  }
}
'@  | 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; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID" | Select-Object -Expand Content

Explorer API

Copia il corpo della richiesta e apri la pagina di riferimento del metodo. Il riquadro Explorer API si apre sul lato destro della pagina. Puoi interagire con questo strumento per inviare richieste. Incolla il corpo della richiesta in questo strumento, compila gli altri campi obbligatori e fai clic su Esegui.

Dovresti ricevere una risposta JSON simile alla seguente:

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// createHL7V2Store creates an HL7V2 store.
func createHL7V2Store(w io.Writer, projectID, location, datasetID, hl7V2StoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores

	// Set the HL7v2 store parser version to V3.
	store := &healthcare.Hl7V2Store{ParserConfig: &healthcare.ParserConfig{Version: "V3"}}
	parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, location, datasetID)

	resp, err := storesService.Create(parent, store).Hl7V2StoreId(hl7V2StoreID).Do()
	if err != nil {
		return fmt.Errorf("Create: %w", err)
	}

	fmt.Fprintf(w, "Created HL7V2 store: %q\n", resp.Name)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
import com.google.api.services.healthcare.v1.model.ParserConfig;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Hl7v2StoreCreate {
  private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void hl7v2StoreCreate(String datasetName, String hl7v2StoreId) throws IOException {
    // String datasetName =
    // String.format(DATASET_NAME, "your-project-id", "your-region-id",
    // "your-dataset-id");
    // String hl7v2StoreId = "your-hl7v25-id"

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Configure the store to be created.
    Map<String, String> labels = new HashMap<>();
    labels.put("key1", "value1");
    labels.put("key2", "value2");
    Hl7V2Store content =
        new Hl7V2Store().setLabels(labels).setParserConfig(new ParserConfig().setVersion("V3"));

    // Create request and configure any parameters.
    Hl7V2Stores.Create request = client
        .projects()
        .locations()
        .datasets()
        .hl7V2Stores()
        .create(datasetName, content)
        .setHl7V2StoreId(hl7v2StoreId);

    // Execute the request and process the results.
    Hl7V2Store response = request.execute();
    System.out.println("Hl7V2Store store created: " + response.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see
    // https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration
    // to all requests.
    HttpRequestInitializer requestInitializer = request -> {
      new HttpCredentialsAdapter(credential).initialize(request);
      request.setConnectTimeout(60000); // 1 minute connect timeout
      request.setReadTimeout(60000); // 1 minute read timeout
    };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const createHl7v2Store = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const hl7v2StoreId = 'my-hl7v2-store';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {
    parent,
    hl7V2StoreId: hl7v2StoreId,
    resource: {
      parserConfig: {
        version: 'V3',
      },
    },
  };

  await healthcare.projects.locations.datasets.hl7V2Stores.create(request);
  console.log(`Created HL7v2 store: ${hl7v2StoreId}`);
};

createHl7v2Store();

Python

def create_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id):
    """Creates a new HL7v2 store within the parent dataset.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/hl7v2
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the HL7v2 store's parent dataset ID
    # hl7v2_store_id = 'my-hl7v2-store'  # replace with the HL7v2 store's ID
    hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )

    # Use the V3 parser. Immutable after HL7v2 store creation.
    body = {"parserConfig": {"version": "V3"}}

    request = (
        client.projects()
        .locations()
        .datasets()
        .hl7V2Stores()
        .create(parent=hl7v2_store_parent, body=body, hl7V2StoreId=hl7v2_store_id)
    )

    response = request.execute()
    print(f"Created HL7v2 store: {hl7v2_store_id}")
    return response

Utilizzare argomenti e filtri Pub/Sub

L'utilizzo di Pub/Sub e filtri con archivi HL7v2 è un caso d'uso comune, in particolare durante la trasmissione di messaggi HL7v2 su connessioni TCP/IP.

Alcuni degli esempi in questa pagina mostrano come configurare un argomento Pub/Sub esistente a cui l'API Cloud Healthcare invia notifiche di eventi clinici in un archivio HL7v2. Specificando un elenco di argomenti e filtri Pub/Sub esistenti, l'API Cloud Healthcare può inviare notifiche a più argomenti e puoi utilizzare i filtri per limitare le notifiche inviate. Per ulteriori informazioni su come configurare argomenti e filtri Pub/Sub, vedi Notifiche HL7v2 e Visualizzare notifiche HL7v2.

Modifica di un archivio HL7v2

I seguenti esempi mostrano come modificare l'elenco di argomenti e filtri Pub/Sub che l'API Cloud Healthcare utilizza per inviare notifiche relative alle modifiche all'archivio HL7v2.

Diversi esempi mostrano anche come modificare le etichette nell'archivio HL7v2.

Quando specifichi un argomento Pub/Sub, inserisci l'URI qualificato dell'argomento, come mostrato nell'esempio seguente:
projects/PROJECT_ID/topics/PUBSUB_TOPIC
Affinché le notifiche funzionino, devi concedere autorizzazioni aggiuntive all'account di servizio dell'agente di servizio Cloud Healthcare. Per ulteriori informazioni, consulta Autorizzazioni Pub/Sub per archivi DICOM, FHIR e HL7v2.

Console

Per modificare un archivio HL7v2, completa i seguenti passaggi:

  1. Nella console Google Cloud, vai alla pagina Set di dati.

    Vai a Set di dati

  2. Seleziona il set di dati contenente l'archivio HL7v2 che vuoi modificare.
  3. Nell'elenco Datastore, fai clic sul datastore da modificare.
  4. Per modificare la configurazione dell'archivio HL7v2, fai clic su Configurazione archivio HL7v2.

    Per ulteriori informazioni sulle opzioni di configurazione dell'archivio HL7v2, consulta Creazione di un archivio HL7v2.
  5. Se vuoi configurare un argomento Pub/Sub per il datastore, fai clic su Aggiungi argomento Pub/Sub e seleziona il nome dell'argomento. Quando specifichi un argomento Pub/Sub, inserisci l'URI qualificato dell'argomento, come mostrato nell'esempio seguente:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    
  6. Se hai aggiunto un argomento Pub/Sub, fai clic su Fine.
  7. Per aggiungere una o più etichette allo store, fai clic su Etichette, poi su Aggiungi etichetta e inserisci l'etichetta chiave/valore. Per saperne di più sulle etichette delle risorse, consulta Utilizzare le etichette delle risorse.
  8. Fai clic su Salva.

gcloud

L'interfaccia a riga di comando gcloud non supporta questa azione. Usa invece la console Google Cloud, curl, PowerShell o il tuo linguaggio preferito.

REST

Per modificare un archivio HL7v2, utilizza il metodo projects.locations.datasets.hl7V2Stores.patch.

Prima di eseguire gli esempi riportati di seguito, devi creare almeno un argomento Pub/Sub nel tuo progetto.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_ID: l'ID del tuo progetto Google Cloud
  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2
  • HL7V2_STORE_ID: l'ID store HL7v2
  • PUBSUB_TOPIC1: un argomento Pub/Sub in cui vengono pubblicati i messaggi quando si verifica un evento in un datastore
  • FILTER1: una stringa utilizzata per associare i messaggi pubblicati in PUBSUB_TOPIC1

    Consulta la pagina filter per alcuni esempi di valori di filtro validi.

  • PUBSUB_TOPIC2: un argomento Pub/Sub in cui vengono pubblicati i messaggi
  • FILTER2: una stringa utilizzata per associare i messaggi pubblicati in PUBSUB_TOPIC2
  • KEY1: la prima chiave di etichetta
  • VALUE1: il primo valore dell'etichetta
  • KEY2: la seconda chiave di etichetta
  • VALUE2: il secondo valore dell'etichetta

Corpo JSON della richiesta:

{
  'notificationConfigs': [
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC1',
      'filter' : 'FILTER1'
    },
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC2',
      'filter': 'FILTER2'
    },
  ],
  'labels': {
    'KEY1':'VALUE1',
    'KEY2':'VALUE2'
  }
}

Per inviare la richiesta, scegli una delle seguenti opzioni:

arricciatura

Salva il corpo della richiesta in un file denominato request.json. Esegui questo comando nel terminale per creare o sovrascrivere questo file nella directory attuale:

cat > request.json << 'EOF'
{
  'notificationConfigs': [
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC1',
      'filter' : 'FILTER1'
    },
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC2',
      'filter': 'FILTER2'
    },
  ],
  'labels': {
    'KEY1':'VALUE1',
    'KEY2':'VALUE2'
  }
}
EOF

Quindi esegui questo comando per inviare la richiesta REST:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID?updateMask=notificationConfigs,labels"

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 attuale:

@'
{
  'notificationConfigs': [
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC1',
      'filter' : 'FILTER1'
    },
    {
      'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC2',
      'filter': 'FILTER2'
    },
  ],
  'labels': {
    'KEY1':'VALUE1',
    'KEY2':'VALUE2'
  }
}
'@  | 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 PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID?updateMask=notificationConfigs,labels" | Select-Object -Expand Content

Explorer API

Copia il corpo della richiesta e apri la pagina di riferimento del metodo. Il riquadro Explorer API si apre sul lato destro della pagina. Puoi interagire con questo strumento per inviare richieste. Incolla il corpo della richiesta in questo strumento, compila gli altri campi obbligatori e fai clic su Esegui.

Dovresti ricevere una risposta JSON simile alla seguente:

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// patchHL7V2Store updates (patches) a HL7V2 store by updating its Pub/sub topic name.
func patchHL7V2Store(w io.Writer, projectID, location, datasetID, hl7v2StoreID, topicName string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s", projectID, location, datasetID, hl7v2StoreID)

	if _, err := storesService.Patch(name, &healthcare.Hl7V2Store{
		NotificationConfigs: []*healthcare.Hl7V2NotificationConfig{
			{
				PubsubTopic: topicName, // format is "projects/*/locations/*/topics/*"
			},
		},
	}).UpdateMask("notificationConfigs").Do(); err != nil {
		return fmt.Errorf("Patch: %w", err)
	}

	fmt.Fprintf(w, "Patched HL7V2 store %s with Pub/sub topic %s\n", datasetID, topicName)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2NotificationConfig;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Hl7v2StorePatch {
  private static final String HL7v2_NAME = "projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void patchHl7v2Store(String hl7v2StoreName, String pubsubTopic) throws IOException {
    // String hl7v2StoreName =
    //    String.format(
    //        HL7v2_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-hl7v2-id");
    // String pubsubTopic = "projects/your-project-id/topics/your-pubsub-topic";

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Fetch the initial state of the HL7v2 store.
    Hl7V2Stores.Get getRequest =
        client.projects().locations().datasets().hl7V2Stores().get(hl7v2StoreName);
    Hl7V2Store store = getRequest.execute();

    Hl7V2NotificationConfig notificationConfig = new Hl7V2NotificationConfig();
    notificationConfig.setPubsubTopic(pubsubTopic);
    List<Hl7V2NotificationConfig> notificationConfigs = new ArrayList<Hl7V2NotificationConfig>();
    notificationConfigs.add(notificationConfig);
    // Update the Hl7v2Store fields as needed as needed. For a full list of Hl7v2Store fields, see:
    // https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.hl7V2Store#Hl7v2Store
    store.setNotificationConfigs(notificationConfigs);

    // Create request and configure any parameters.
    Hl7V2Stores.Patch request =
        client
            .projects()
            .locations()
            .datasets()
            .hl7V2Stores()
            .patch(hl7v2StoreName, store)
            .setUpdateMask("notificationConfigs");

    // Execute the request and process the results.
    store = request.execute();
    System.out.println("HL7v2 store patched: \n" + store.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const patchHl7v2Store = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const hl7v2StoreId = 'my-hl7v2-store';
  // const pubsubTopic = 'my-topic'
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
  const request = {
    name,
    updateMask: 'notificationConfigs',
    resource: {
      notificationConfigs: [
        {
          pubsubTopic: `projects/${projectId}/topics/${pubsubTopic}`,
        },
      ],
    },
  };

  await healthcare.projects.locations.datasets.hl7V2Stores.patch(request);
  console.log(
    `Patched HL7v2 store ${hl7v2StoreId} with Cloud Pub/Sub topic ${pubsubTopic}`
  );
};

patchHl7v2Store();

Python

def patch_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id):
    """Updates the HL7v2 store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/hl7v2
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the HL7v2 store's parent dataset
    # hl7v2_store_id = 'my-hl7v2-store'  # replace with the HL7v2 store's ID
    hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    hl7v2_store_name = f"{hl7v2_store_parent}/hl7V2Stores/{hl7v2_store_id}"

    # TODO(developer): Replace with the full URI of an existing Pub/Sub topic
    patch = {"notificationConfigs": None}

    request = (
        client.projects()
        .locations()
        .datasets()
        .hl7V2Stores()
        .patch(name=hl7v2_store_name, updateMask="notificationConfigs", body=patch)
    )

    response = request.execute()
    print(f"Patched HL7v2 store {hl7v2_store_id} with Cloud Pub/Sub topic: None")
    return response

Recupero dei dettagli di un archivio HL7v2

Gli esempi riportati di seguito mostrano come recuperare i dettagli di un archivio HL7v2.

Console

Per visualizzare i dettagli di un archivio HL7v2:

  1. Nella console Google Cloud, vai alla pagina Set di dati.

    Vai a Set di dati

  2. Seleziona il set di dati contenente l'archivio HL7v2 che vuoi visualizzare.
  3. Fai clic sul nome dell'archivio HL7v2.
  4. La pagina Dettagli datastore mostra i dettagli dell'archivio HL7v2 selezionato.

gcloud

Per ottenere i dettagli su un archivio HL7v2, esegui il comando gcloud healthcare hl7v2-stores describe.

Prima di utilizzare uno qualsiasi dei dati di comando riportati di seguito, effettua le seguenti sostituzioni:

  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2
  • HL7V2_STORE_ID: l'ID store HL7v2

Esegui questo comando:

Linux, macOS o Cloud Shell

gcloud healthcare hl7v2-stores describe HL7V2_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare hl7v2-stores describe HL7V2_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare hl7v2-stores describe HL7V2_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION

Dovresti ricevere una risposta simile alla seguente.

Se nella risorsa Hl7V2Store hai configurato dei campi, questi vengono visualizzati anche nella risposta.

...
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID
...

REST

Per visualizzare i dettagli di un archivio HL7v2, utilizza il metodo projects.locations.datasets.hl7V2Stores.get.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_ID: l'ID del tuo progetto Google Cloud
  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2
  • HL7V2_STORE_ID: l'ID store HL7v2

Per inviare la richiesta, scegli una delle seguenti opzioni:

arricciatura

Esegui questo comando:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID"

PowerShell

Esegui questo comando:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID" | Select-Object -Expand Content

Explorer API

Apri la pagina di riferimento del metodo. Il riquadro Explorer API si apre sul lato destro della pagina. Puoi interagire con questo strumento per inviare richieste. Compila tutti i campi obbligatori e fai clic su Esegui.

Dovresti ricevere una risposta simile alla seguente.

Se nella risorsa Hl7V2Store hai configurato dei campi, questi vengono visualizzati anche nella risposta.

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// getHL7V2Store gets an HL7V2 store.
func getHL7V2Store(w io.Writer, projectID, location, datasetID, hl7v2StoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s", projectID, location, datasetID, hl7v2StoreID)

	store, err := storesService.Get(name).Do()
	if err != nil {
		return fmt.Errorf("Get: %w", err)
	}

	fmt.Fprintf(w, "Got HL7V2 store: %q\n", store.Name)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

public class Hl7v2StoreGet {
  private static final String HL7v2_NAME = "projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void hl7v2eStoreGet(String hl7v2StoreName) throws IOException {
    // String hl7v2StoreName =
    //    String.format(
    //        HL7v2_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-hl7v2-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Create request and configure any parameters.
    Hl7V2Stores.Get request =
        client.projects().locations().datasets().hl7V2Stores().get(hl7v2StoreName);

    // Execute the request and process the results.
    Hl7V2Store store = request.execute();
    System.out.println("HL7v2 store retrieved: \n" + store.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getHl7v2Store = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const hl7v2StoreId = 'my-hl7v2-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
  const request = {name};

  const hl7v2Store =
    await healthcare.projects.locations.datasets.hl7V2Stores.get(request);
  console.log(hl7v2Store.data);
};

getHl7v2Store();

Python

def get_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id):
    """Gets the specified HL7v2 store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/hl7v2
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the HL7v2 store's parent dataset
    # hl7v2_store_id = 'my-hl7v2-store'  # replace with the HL7v2 store's ID
    hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    hl7v2_store_name = f"{hl7v2_store_parent}/hl7V2Stores/{hl7v2_store_id}"

    hl7v2_stores = client.projects().locations().datasets().hl7V2Stores()
    hl7v2_store = hl7v2_stores.get(name=hl7v2_store_name).execute()

    print("Name: {}".format(hl7v2_store.get("name")))
    if hl7v2_store.get("notificationConfigs") is not None:
        print("Notification configs:")
        for notification_config in hl7v2_store.get("notificationConfigs"):
            print(
                "\tPub/Sub topic: {}".format(notification_config.get("pubsubTopic")),
                "\tFilter: {}".format(notification_config.get("filter")),
            )

    return hl7v2_store

Elenco degli archivi HL7v2 in un set di dati

Gli esempi riportati di seguito mostrano come elencare gli archivi HL7v2 in un set di dati.

Console

Per visualizzare i datastore in un set di dati:

  1. Nella console Google Cloud, vai alla pagina Set di dati.

    Vai a Set di dati

  2. Seleziona il set di dati contenente il datastore da visualizzare.

gcloud

Per elencare gli archivi HL7v2 in un set di dati, esegui il comando gcloud healthcare hl7v2-stores list.

Prima di utilizzare uno qualsiasi dei dati di comando riportati di seguito, effettua le seguenti sostituzioni:

  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2

Esegui questo comando:

Linux, macOS o Cloud Shell

gcloud healthcare hl7v2-stores list --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare hl7v2-stores list --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare hl7v2-stores list --dataset=DATASET_ID ^
  --location=LOCATION

Dovresti ricevere una risposta simile alla seguente.

Se nella risorsa Hl7V2Store hai configurato dei campi, questi vengono visualizzati anche nella risposta.

ID              LOCATION     TOPIC
HL7V2_STORE_ID  LOCATION     projects/PROJECT_ID/topics/PUBSUB_TOPIC                                   PUBSUB_TOPIC
...

REST

Per elencare gli archivi HL7v2 in un set di dati, utilizza il metodo projects.locations.datasets.hl7V2Stores.list.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_ID: l'ID del tuo progetto Google Cloud
  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2

Per inviare la richiesta, scegli una delle seguenti opzioni:

arricciatura

Esegui questo comando:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores"

PowerShell

Esegui questo comando:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores" | Select-Object -Expand Content

Explorer API

Apri la pagina di riferimento del metodo. Il riquadro Explorer API si apre sul lato destro della pagina. Puoi interagire con questo strumento per inviare richieste. Compila tutti i campi obbligatori e fai clic su Esegui.

Dovresti ricevere una risposta simile alla seguente.

Se nella risorsa Hl7V2Store hai configurato dei campi, questi vengono visualizzati anche nella risposta.

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// listHL7V2Stores prints a list of HL7V2 stores to w.
func listHL7V2Stores(w io.Writer, projectID, location, datasetID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores

	parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, location, datasetID)

	resp, err := storesService.List(parent).Do()
	if err != nil {
		return fmt.Errorf("Create: %w", err)
	}

	fmt.Fprintln(w, "HL7V2 stores:")
	for _, s := range resp.Hl7V2Stores {
		fmt.Fprintln(w, s.Name)
	}
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
import com.google.api.services.healthcare.v1.model.ListHl7V2StoresResponse;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Hl7v2StoreList {
  private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void hl7v2StoreList(String datasetName) throws IOException {
    // String datasetName =
    //     String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Results are paginated, so multiple queries may be required.
    String pageToken = null;
    List<Hl7V2Store> stores = new ArrayList<>();
    do {
      // Create request and configure any parameters.
      Hl7V2Stores.List request =
          client
              .projects()
              .locations()
              .datasets()
              .hl7V2Stores()
              .list(datasetName)
              .setPageSize(100) // Specify pageSize up to 1000
              .setPageToken(pageToken);

      // Execute response and collect results.
      ListHl7V2StoresResponse response = request.execute();
      stores.addAll(response.getHl7V2Stores());

      // Update the page token for the next request.
      pageToken = response.getNextPageToken();
    } while (pageToken != null);

    // Print results.
    System.out.printf("Retrieved %s HL7v2 stores: \n", stores.size());
    for (Hl7V2Store data : stores) {
      System.out.println("\t" + data.toPrettyString());
    }
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const listHl7v2Stores = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {parent};

  const hl7v2Stores =
    await healthcare.projects.locations.datasets.hl7V2Stores.list(request);
  console.log(hl7v2Stores.data);
};

listHl7v2Stores();

Python

def list_hl7v2_stores(project_id, location, dataset_id):
    """Lists the HL7v2 stores in the given dataset.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/hl7v2
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the HL7v2 store's parent dataset
    hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )

    hl7v2_stores = (
        client.projects()
        .locations()
        .datasets()
        .hl7V2Stores()
        .list(parent=hl7v2_store_parent)
        .execute()
        .get("hl7V2Stores", [])
    )

    for hl7v2_store in hl7v2_stores:
        print("HL7v2 store:\nName: {}".format(hl7v2_store.get("name")))
        if hl7v2_store.get("notificationConfigs") is not None:
            print("Notification configs:")
            for notification_config in hl7v2_store.get("notificationConfigs"):
                print(
                    "\tPub/Sub topic: {}".format(
                        notification_config.get("pubsubTopic")
                    ),
                    "\tFilter: {}".format(notification_config.get("filter")),
                )
    return hl7v2_stores

Eliminazione di un archivio HL7v2

Gli esempi riportati di seguito mostrano come eliminare un archivio HL7v2.

Console

Per eliminare un datastore:

  1. Nella console Google Cloud, vai alla pagina Set di dati.

    Vai a Set di dati

  2. Seleziona il set di dati contenente il datastore da eliminare.
  3. Scegli Elimina dall'elenco a discesa Azioni per il datastore da eliminare.
  4. Per confermare, digita il nome del datastore e fai clic su Elimina.

gcloud

Per eliminare un archivio HL7v2, esegui il comando gcloud healthcare hl7v2-stores delete.

Prima di utilizzare uno qualsiasi dei dati di comando riportati di seguito, effettua le seguenti sostituzioni:

  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2
  • HL7V2_STORE_ID: l'ID store HL7v2

Esegui questo comando:

Linux, macOS o Cloud Shell

gcloud healthcare hl7v2-stores delete HL7V2_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare hl7v2-stores delete HL7V2_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare hl7v2-stores delete HL7V2_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION
Per confermare, digita Y. Dovresti ricevere una risposta simile alla seguente.
Deleted hl7v2Store [HL7V2_STORE_ID].

REST

Per eliminare un archivio HL7v2, utilizza il metodo projects.locations.datasets.hl7V2Stores.delete.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_ID: l'ID del tuo progetto Google Cloud
  • LOCATION: la posizione del set di dati
  • DATASET_ID: il set di dati padre dell'archivio HL7v2
  • HL7V2_STORE_ID: l'ID store HL7v2

Per inviare la richiesta, scegli una delle seguenti opzioni:

arricciatura

Esegui questo comando:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID"

PowerShell

Esegui questo comando:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID" | Select-Object -Expand Content

Explorer API

Apri la pagina di riferimento del metodo. Il riquadro Explorer API si apre sul lato destro della pagina. Puoi interagire con questo strumento per inviare richieste. Compila tutti i campi obbligatori e fai clic su Esegui.

Dovresti ricevere una risposta JSON simile alla seguente:

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// deleteHL7V2Store deletes an HL7V2 store.
func deleteHL7V2Store(w io.Writer, projectID, location, datasetID, hl7V2StoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s", projectID, location, datasetID, hl7V2StoreID)

	if _, err := storesService.Delete(name).Do(); err != nil {
		return fmt.Errorf("Delete: %w", err)
	}

	fmt.Fprintf(w, "Deleted HL7V2 store: %q\n", name)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

public class Hl7v2StoreDelete {
  private static final String HL7v2_NAME = "projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void hl7v2StoreDelete(String hl7v2StoreName) throws IOException {
    // String hl7v2StoreName =
    //    String.format(
    //        HL7v2_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-hl7v2-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Create request and configure any parameters.
    Hl7V2Stores.Delete request =
        client.projects().locations().datasets().hl7V2Stores().delete(hl7v2StoreName);

    // Execute the request and process the results.
    request.execute();
    System.out.println("HL7v2 store deleted.");
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const deleteHl7v2Store = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const hl7v2StoreId = 'my-hl7v2-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
  const request = {name};

  await healthcare.projects.locations.datasets.hl7V2Stores.delete(request);
  console.log(`Deleted HL7v2 store: ${hl7v2StoreId}`);
};

deleteHl7v2Store();

Python

def delete_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id):
    """Deletes the specified HL7v2 store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/hl7v2
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the HL7v2 store's parent dataset
    # hl7v2_store_id = 'my-hl7v2-store'  # replace with the HL7v2 store's ID
    hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    hl7v2_store_name = f"{hl7v2_store_parent}/hl7V2Stores/{hl7v2_store_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .hl7V2Stores()
        .delete(name=hl7v2_store_name)
    )

    response = request.execute()
    print(f"Deleted HL7v2 store: {hl7v2_store_id}")
    return response

Passaggi successivi