Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { google } from 'googleapis';
  2. import * as fs from 'fs';
  3.  
  4. const healthcare = google.healthcare({
  5.   version: 'v1',
  6.   auth: new google.auth.GoogleAuth({
  7.     scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  8.   }),
  9. });
  10.  
  11. const projectID = 'TODO_PROJECT';
  12. const location = 'TODO_LOCATION';
  13. const datasetID = 'TODO_DATASET';
  14.  
  15. const sourceStoreID = 'TODO_SOURCE';
  16. const destStoreID = 'TODO_DEST';
  17.  
  18. const inputFile = 'multipart-request.file';
  19.  
  20. const sourceStore = `projects/${projectID}/locations/${location}/datasets/${datasetID}/dicomStores/${sourceStoreID}`;
  21. const destinationStore = `projects/${projectID}/locations/${location}/datasets/${datasetID}/dicomStores/${destStoreID}`;
  22.  
  23. async function waitForOperation(name) {
  24.   while (true) {
  25.     const op = await healthcare.projects.locations.datasets.operations.get({
  26.       name,
  27.     });
  28.     if (op.data.done) {
  29.       console.log(op.data);
  30.       return
  31.     }
  32.   }
  33. }
  34.  
  35. async function main() {
  36.   console.log('running');
  37.   try {
  38.     const input = fs.createReadStream(inputFile);
  39.  
  40.     const res = await healthcare.projects.locations.datasets.dicomStores.storeInstances(
  41.       {
  42.         parent: sourceStore,
  43.         dicomWebPath: 'studies',
  44.         requestBody: input,
  45.       },
  46.       {
  47.         headers: {
  48.           'Content-Type': 'multipart/related; type="application/dicom+json"; boundary=DICOMwebBoundary',
  49.           Accept: 'application/dicom+json',
  50.         },
  51.       })
  52.     console.log(res.data);
  53.  
  54.     const op = await healthcare.projects.locations.datasets.dicomStores.deidentify({
  55.       sourceStore: sourceStore,
  56.       destinationStore: destinationStore,
  57.       resource: {
  58.         config: {
  59.           dicom: {
  60.             filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
  61.           },
  62.           text: {
  63.             transformations: [
  64.               {
  65.                 infoTypes: ['PERSON_NAME'],
  66.                 characterMaskConfig: { maskingCharacter: '*' }
  67.               },
  68.             ]
  69.           },
  70.           image: {
  71.             textRedactionMode: 'REDACT_SENSITIVE_TEXT',
  72.           },
  73.         },
  74.         filterConfig: {},
  75.       },
  76.     });
  77.  
  78.     await waitForOperation(op.data.name);
  79.  
  80.     const instances = await healthcare.projects.locations.datasets.dicomStores.searchForInstances(
  81.       {
  82.         parent: destinationStore,
  83.         dicomWebPath: 'instances',
  84.       },
  85.       {
  86.         headers: {
  87.           'Accept': 'application/dicom+json,multipart/related'
  88.         }
  89.       })
  90.     console.log(JSON.stringify(instances.data));
  91.   } catch (e) {
  92.     console.error(e);
  93.   }
  94. };
  95.  
  96. await main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement