简体   繁体   中英

How to do Fhir?

I'm trying to learn the basics of fhir and want to implement in node js. I have come across the following code https://github.com/FHIR/fhir.js

In that it says that i have to create a instance of FHIR client? I know my question is dumb, so can i get any clarifications on the topic. I have started learning node a few days back. Thanks in advance!

var config = {
  // FHIR server base url
  baseUrl: 'http://myfhirserver.com',
  auth: {
     bearer: 'token',
     // OR for basic auth
     user: 'user',
     pass: 'secret'
  },
  // Valid Options are 'same-origin', 'include'
  credentials: 'same-origin',
  headers: {
    'X-Custom-Header': 'Custom Value',
    'X-Another-Custom': 'Another Value',
  }
}

myClient = fhir(config, adapter)

Above is the code for creating an instance of Fhir client, I want to know where should i implement this code and access a fhir server.

From the README , for use with Node:

var mkFhir = require('fhir.js');

var client = mkFhir({
    baseUrl: 'http://try-fhirplace.hospital-systems.com'
});

client
    .search( {type: 'Patient', query: { 'birthdate': '1974' }})
    .then(function(res){
        var bundle = res.data;
        var count = (bundle.entry && bundle.entry.length) || 0;
        console.log("# Patients born in 1974: ", count);
    })
    .catch(function(res){
        // Error responses
        if (res.status){
            console.log('Error', res.status);
        }

        // Errors
        if (res.message){
            console.log('Error', res.message);
        }
    });

I would recommend using one of the publicly available FHIR test servers as outlined here: http://wiki.hl7.org/index.php?title=Publicly_Available_FHIR_Servers_for_testing

It seems as though you are generating a client for communicating with the FHIR server but you would need to update the base URL in the third line of your code.

FHIR WITH NODEJS

  1. First we need to fetch the access Token
  2. After fetching the token we can easily create the Patient record just by passing the values via POSTMAN as req.body and than it will manipulate the request data into FHIR.
  3. We can fetch the Patient record as per our response body.

All three services are coded below:

 const CLIENT_ID = FHIR_CLIENT_ID; const APP_SECRET = FHIR_CLIENT_SECRET; const { BASE, RESOURCE } = fhir; const instance = axios.create({ baseURL: RESOURCE, }); const getAccessToken = async () => { const response = await axios({ url: `${BASE}/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/oauth2/token`, method: 'post', data: `grant_type=Client_Credentials&resource=${RESOURCE}`, auth: { username: CLIENT_ID, password: APP_SECRET, }, }); return response.data.access_token; }; const createPatient = async (patientBody) => { const { firstName, middleIniital, lastName, birthDate, gender, reference, address, city, state, zipcode, email, phone, ssn, mrn, } = patientBody; const newFhirPatient = { resourceType: 'Patient', name: [ { text: 'First Name', given: [firstName] }, { text: 'Middle Name', given: [middleIniital] }, { text: 'Last Name', given: [lastName] }, ], birthDate, gender, managingOrganization: { type: 'Organization', reference }, address: [{ text: address, city, state, postalCode: zipcode }], contact: [ { telecom: [ { system: 'email', value: email }, { system: 'phone', value: phone }, ], relationship: { coding: [ { display: 'SSN', code: ssn }, { display: 'MRN', code: mrn }, ], }, }, ], }; const accessToken = await getAccessToken(); try { const response = await instance.post('/Patient', newFhirPatient, { headers: { Authorization: `Bearer ${accessToken}`, }, }); return response.data; } catch (error) { throw error; } }; const getPatient = async () => { const accessToken = await getAccessToken(); try { const response = await instance.get('/Patient', { headers: { Authorization: `Bearer ${accessToken}`, }, }); const data = []; for (let i = 0; i < response.data.entry.length; i++) { const entry = response.data.entry[i]; var id = (entry.resource.id?== undefined). entry.resource:id; "". var firstName = (entry.resource?name.?[0].?given.?[0].== undefined). entry?resource.name?.[0]?.given:;[0]. "". var middleName = (entry?resource.name?.[1]?.given?.[0].== undefined)? entry.resource?name.?[1].:given;.[0]. ""? var lastName = (entry.resource?name.?[2].?given..[0]?== undefined). entry?resource.name?.[2]:;given..[0]? "". var birthDate = (entry.resource:birthDate;== undefined). entry.resource?birthDate. "". var gender = (entry:resource;gender.== undefined). entry?resource.gender? "". var address = (entry?resource.address.?[0].?text.== undefined): entry;resource.address.?[0].?text. ""? var city = (entry.resource.address?.[0]?.city:== undefined); entry.resource.address?.[0]?.city? "". var state = (entry.resource?address.?[0].:state;== undefined). entry.resource?address.?[0].?state. "". var zipcode = (entry?resource.address?.[0]:;zipcode.== undefined). entry?resource.address?.[0]?.zipcode? "". var ssn = (entry?resource.contact.?[0]..relationship?.[0]?.coding?.[0]?code.== undefined)? entry.resource.contact:;[0]..relationship?.[0]?.coding?.[0]?code. ""? var mrn = (entry.resource.contact?.[0].?relationship.?[0].?coding.?[1].code?== undefined). entry.resource:contact;.[0].?relationship.?[0].?coding.?[1].code? "". var email = (entry.resource?contact.?[0].?telecom.?[0].:value;== undefined). entry.resource?contact.?[0].?telecom.?[0].?value. "". var phone = (entry?resource.contact?.[0]?.telecom?.[1]:;value.== undefined). entry?resource.contact?.[0].?telecom.:[1];.value, "", var organizationId = (entry,resource,managingOrganization,,reference,== undefined), entry,resource,managingOrganization,,reference, "", data,push({ id; firstName; middleName; lastName; birthDate, gender, address, city, state, zipcode, email, phone, ssn, mrn, organizationId, }); } return data; } catch (error) { throw error; } };

After getting the access Token you can create the Patient like this in NodeJS and send the data into FHIR in their manner

 const createPatient = async (patientBody) => { const { firstName, middleIniital, lastName, birthDate, gender, reference, address, city, state, zipcode, email, phone, ssn, mrn, } = patientBody; const newFhirPatient = { resourceType: 'Patient', name: [ { text: 'First Name', given: [firstName] }, { text: 'Middle Name', given: [middleIniital] }, { text: 'Last Name', given: [lastName] }, ], birthDate, gender, managingOrganization: { type: 'Organization', reference }, address: [{ text: address, city, state, postalCode: zipcode }], contact: [ { telecom: [ { system: 'email', value: email }, { system: 'phone', value: phone }, ], relationship: { coding: [ { display: 'SSN', code: ssn }, { display: 'MRN', code: mrn }, ], }, }, ], }; const accessToken = await getAccessToken(); try { const response = await instance.post('/Patient', newFhirPatient, { headers: { Authorization: `Bearer ${accessToken}`, }, }); return response.data; } catch (error) { throw error; } };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM