Skip to content

Commit c85e0dd

Browse files
noerogfhinkel
authored andcommitted
CHC API: Use client library for storing DICOM instance (#1518)
1 parent c73e56e commit c85e0dd

File tree

3 files changed

+72
-130
lines changed

3 files changed

+72
-130
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2019, Google, LLC
3+
* Licensed under the Apache License, Version 2.0 (the `License`);
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an `AS IS` BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/* eslint-disable no-warning-comments */
17+
18+
'use strict';
19+
20+
const main = (
21+
projectId = process.env.GCLOUD_PROJECT,
22+
cloudRegion = 'us-central1',
23+
datasetId,
24+
dicomStoreId,
25+
dcmFile
26+
) => {
27+
// [START healthcare_dicomweb_store_instance]
28+
const {google} = require('googleapis');
29+
const healthcare = google.healthcare('v1beta1');
30+
const fs = require('fs');
31+
const binaryData = fs.createReadStream(dcmFile);
32+
33+
const dicomWebStoreInstance = async () => {
34+
const auth = await google.auth.getClient({
35+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
36+
});
37+
google.options({
38+
auth,
39+
headers: {
40+
'Content-Type': 'application/dicom',
41+
Accept: 'application/dicom+json',
42+
},
43+
});
44+
45+
// TODO(developer): uncomment these lines before running the sample
46+
// const cloudRegion = 'us-central1';
47+
// const projectId = 'adjective-noun-123';
48+
// const datasetId = 'my-dataset';
49+
// const dicomStoreId = 'my-dicom-store';
50+
// const dcmFile = 'file.dcm';
51+
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/dicomStores/${dicomStoreId}`;
52+
const dicomWebPath = `studies`;
53+
const request = {
54+
parent,
55+
dicomWebPath,
56+
requestBody: binaryData,
57+
};
58+
59+
const instance = await healthcare.projects.locations.datasets.dicomStores.storeInstances(
60+
request
61+
);
62+
console.log(`Stored DICOM instance:\n`, JSON.stringify(instance.data));
63+
};
64+
65+
dicomWebStoreInstance();
66+
// [END healthcare_dicomweb_store_instance]
67+
};
68+
69+
// node dicomWebStoreInstance.js <projectId> <cloudRegion> <datasetId> <dicomStoreId> <dcmFile>
70+
main(...process.argv.slice(2));

healthcare/dicom/dicomweb.js

Lines changed: 0 additions & 128 deletions
This file was deleted.

healthcare/dicom/system-test/dicomweb.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ after(async () => {
6565

6666
it('should store a DICOM instance', async () => {
6767
const output = await tools.runAsync(
68-
`node dicomweb.js dicomWebStoreInstance ${datasetId} ${dicomStoreId} ${dcmFile}`,
68+
`node dicomWebStoreInstance.js ${projectId} ${cloudRegion} ${datasetId} ${dicomStoreId} ${dcmFile}`,
6969
cwd
7070
);
71-
assert.ok(output.includes('Stored instance'));
71+
assert.ok(output.includes('Stored DICOM instance'));
7272
});
7373

7474
it('should search DICOM instances', async () => {

0 commit comments

Comments
 (0)