@@ -28,8 +28,6 @@ const main = (
2828 const searchFhirResourcesPost = async ( ) => {
2929 const auth = new GoogleAuth ( {
3030 scopes : 'https://www.googleapis.com/auth/cloud-platform' ,
31- // Set application/fhir+json header because this is a POST request.
32- headers : { 'Content-Type' : 'application/fhir+json' } ,
3331 } ) ;
3432 // TODO(developer): uncomment these lines before running the sample
3533 // const cloudRegion = 'us-central1';
@@ -44,11 +42,27 @@ const main = (
4442 // Patient with the last name "Smith", set resourceType to "Patient" and
4543 // specify the following params:
4644 // params = {'family:exact' : 'Smith'};
47- const client = await auth . getClient ( ) ;
48- const response = await client . request ( { url, method : 'POST' , params} ) ;
49- const resources = response . data . entry ;
50- console . log ( `Resources found: ${ resources . length } ` ) ;
51- console . log ( JSON . stringify ( resources , null , 2 ) ) ;
45+
46+ try {
47+ const client = await auth . getClient ( ) ;
48+ const response = await client . request ( {
49+ url,
50+ method : 'POST' ,
51+ headers : {
52+ 'Content-Type' : 'application/fhir+json' ,
53+ } ,
54+ params,
55+ responseType : 'json' ,
56+ } ) ;
57+ const resources = response . data . entry || [ ] ;
58+ console . log ( 'Resources found: ' + resources . length ) ;
59+ console . log ( JSON . stringify ( resources , null , 2 ) ) ;
60+ } catch ( error ) {
61+ console . error (
62+ `Error searching ${ resourceType } resources:` ,
63+ error . response ? error . response . data : error . message
64+ ) ;
65+ }
5266 } ;
5367
5468 searchFhirResourcesPost ( ) ;
0 commit comments