Convert Contents to String

23 views
Skip to first unread message

Will Saunders

unread,
Oct 11, 2018, 2:53:09 PM10/11/18
to Cerner FHIR Developers
I'm trying to save my FHIR Resource to a text file.   I'm thinking I need a better way than patient.tostring(); to convert the contents of my patient object into a string.  When I change 
 fileContent += patient.tostring();
to 
 fileContent += "Test";
a file with the word Test is successfully created so that leads me to belie I just need a better way to convert the convert the contents of my patient object into a string.

Any ideas?
 
 function onReady(smart)  {
     if (smart.hasOwnProperty('patient')) {
       var patient = smart.patient;
       var pt = patient.read();
       var obv = smart.patient.api.fetchAll({
                   type: 'Observation',
                   query: {
                     code: {
                       $or: ['http://loinc.org|8302-2', 'http://loinc.org|8462-4',
                             'http://loinc.org|8480-6', 'http://loinc.org|2085-9',
                             'http://loinc.org|2089-1', 'http://loinc.org|55284-4',
                             'http://loinc.org|29463-7']
                     }
                   }
                 });
             
       $.when(pt, obv).fail(onError);

        $.when(pt, obv).done(function(patient, obv) {
         
       let fileContent = "data:text/csv;charset=utf-8,";
       fileContent += patient.tostring();
       
       var encodedUri = encodeURI(fileContent);
       window.open(encodedUri);
         
}
}


Michele Mottini

unread,
Oct 11, 2018, 3:17:52 PM10/11/18
to Cerner FHIR Developers
Maybe use `JSON.stringfy(patient)` ? It will give you the patient as a JSON string.

  - Michele
  CareEvolution Inc

Will Saunders

unread,
Oct 11, 2018, 3:34:22 PM10/11/18
to Cerner FHIR Developers
Well `JSON.stringfy(patient)` did not work but `JSON.stringify(patient)` did ;).  Thank you! 
Reply all
Reply to author
Forward
0 new messages