FibriCheck
Search…
Examples
This page contains some examples to get you started on using the SDK. For completeness, every example includes the creation and authentication of the SDK. This is of course not necessary and should be

First time authentication to save token/tokenSecret

You can use your email/password combination initially to retrieve an OAuth1 token/secret combination which you can use on to reauthenticate when reloading the application. In this example @react-native-async-storage/async-storage is used, but you can use any persistent storage system.
1
import AsyncStorage from '@react-native-async-storage/async-storage';
2
3
(async () => {
4
const sdk = client({
5
consumerKey: '',
6
consumerSecret: '',
7
});
8
9
const tokenData = await sdk.authenticate({
10
email: '',
11
password: '',
12
});
13
14
AsyncStorage.setItem('tokenData', JSON.stringify(tokenData));
15
})();
Copied!
Afterwards you can use the stored tokenData to authenticate.
1
import AsyncStorage from '@react-native-async-storage/async-storage';
2
(async () => {
3
const tokenDataString = await AsyncStorage.getItem('tokenData');
4
const tokenData = JSON.parse(tokenDataString);
5
6
await sdk.authenticate({
7
token: tokenData.key,
8
tokenSecret: tokenData.secret,
9
});
10
})();
Copied!

Perform a measurement with the Camera SDK component

You can use the RNFibriCheckView exported from the @fibricheck/react-native-camera-sdk package to perform a measurement and hook up sdk.postMeasurement to post the data returned from the camera to the backend in the onMeasurementProcessed event.
  • It is highly recommended to provide the camera sdk version as a second argument, as shown in the example.
  • If you want to add a context to measurement, you need to add it before sending. We provided an example in the snippet below. The context is prefilled here, but needs to be completed by the user in the end product.
1
import client from '@fibricheck/javascript-sdk';
2
import { RNFibriCheckView } from '@fibricheck/react-native-camera-sdk';
3
import { useEffect, useState } from 'react';
4
5
const sdk = client({
6
consumerKey: '',
7
consumerSecret: '',
8
});
9
10
await sdk.authenticate({
11
token: '',
12
tokenSecret: '',
13
});
14
15
const App = () => {
16
const [cameraData, setCameraData] = useState();
17
const [context, setContext] = useState({
18
symptoms: [
19
'lightheaded',
20
'confused'
21
],
22
activity: 'sleeping',
23
});
24
25
async function postMeasurement(cameraData, context) {
26
const measurement = {
27
...cameraData,
28
context
29
};
30
await sdk.postMeasurement(measurement, RNFibriCheckView.version);
31
}
32
33
return (
34
<RNFibriCheckView
35
onHeartBeat={(heartRate) => {
36
console.log('heartRate', heartRate);
37
}}
38
onTimeRemaining={(seconds) => {
39
console.log('onTimeRemaining', seconds);
40
}}
41
onMeasurementProcessed={async (cameraData) => {
42
console.log('onMeasurementProcessed', cameraData);
43
setCameraData(cameraData);
44
}}
45
onFingerDetected={() => {
46
console.log('finger detected');
47
}}
48
/>
49
);
50
};
Copied!
In some rare cases, it can occur that the motion sensors don't provide the correct data. In such cases, the movement detection will kick in, although the user is not moving. A way to fix this, is to disable the motion sensors by setting the movementDetectionEnabled to false on for example a onLongPress

Register a new user

The following snippet shows how you can register a new user. You do not need authentication for registration.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
const user = await sdk.register({
9
firstName: 'John',
10
lastName: 'Doe',
11
12
password: 'Strong!987',
13
phoneNumber: '000000',
14
birthDay: '1970/01/01',
15
gender: 0, // 0 = Not known; 1 = Male; 2 = Female; 9 = Not applicable
16
country: 'JO', // or 'AE'
17
language: 'AR',
18
});
Copied!

Check for updated legal documents

When you use the authentication function, the second parameter should be a callback function (this can also be an arrow function). This function will be called when legal documents have been updated in the FibriCheck cloud and the end-user needs to reapprove these. Example showing how to hook changes to legal documents change with your application and calling the giveConsent function with the document after the user has approved these.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate(
9
{
10
password: '',
11
username: '',
12
},
13
function onConsentNeeded(legalDocumentsUpdated) {
14
/* Will return an array of objects with a key, version and url.
15
* ie.
16
* [{
17
* key: 'privacyPolicy',
18
* version: '1.5.0',
19
* url: 'https://fibricheck.com/privacyPolicy/150'
20
* }]
21
*/
22
23
legalDocumentsUpdated.forEach((document) => {
24
// 1. Request approval from the user
25
26
// 2. Pass the document back to the sdk
27
sdk.giveConsent(document);
28
});
29
},
30
);
Copied!

Fetch a measurement

Use the sdk.getMeasurement function to get a single measurement based on a id. Only measurements for the currently authenticated user can be requested.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate({
9
token: '',
10
tokenSecret: '',
11
});
12
13
const measurementId = '0000';
14
const measurement = await sdk.getMeasurement(measurementId);
Copied!

Fetching all your measurements

Using sdk.getMeasurements will return a paginated result with all measurements for the currently authenticated user. You can find the measurements under the data property. You can also use the next and previous functions present on the result to navigate through the user's measurents.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate({
9
token: '',
10
tokenSecret: '',
11
});
12
13
// Returns the first 20 measurements
14
const measurements = await sdk.getMeasurements();
15
16
// Returns the next 20 measurements
17
const nextMeasurements = await measurements.next();
Copied!

Request a measurement report and render the PDF

The sdk.getMeasurementReportUrl accepts a measurementId and will handle creation / fetching of the report. This function works great in combination with react-native-pdf or react-native-share
  • First time calling this function for a measurement, it will take a little longer as the cloud service will render the report. Once it's ready (~5s) the url where you can fetch it will be returned
  • Subsequent calls will be much faster, as the report is already rendered and the url will be returned almost instantly.
  • The pdf will always be rendered in the language of the user (this language is specified during Register a new user)
1
import client from '@fibricheck/javascript-sdk';
2
import Pdf from 'react-native-pdf';
3
4
const sdk = client({
5
consumerKey: '',
6
consumerSecret: '',
7
});
8
9
await sdk.authenticate({
10
token: '',
11
tokenSecret: '',
12
});
13
14
const measurementId = '0000';
15
16
const App = () => {
17
const [uri, setUri] = useState();
18
19
useEffect(() => {
20
(async () => {
21
const uri = await sdk.getReportUrl(measurementId);
22
setUri(uri);
23
})();
24
}, []);
25
26
return (
27
<Pdf
28
source={{
29
uri,
30
}}
31
/>
32
);
33
};
Copied!

Request all periodic reports

The sdk.getPeriodicReports method will retrieve all your periodic reports.
  • This method is a generator function that returns an iterator. This iterator can be called with .next() to retrieve the next 20 reports. Another way to do this, is by using the for await construction (as seen in the example)
  • In the periodic reports, the trigger field indicates for which period the report was made (7 days, 30 days or at the end of a prescription)
⚠️ To use this functionality, @babel/plugin-proposal-async-generator-functions is required. This plugin is included in @babel/preset-env.
1
import client from '@fibricheck/javascript-sdk';
2
3
interface PeriodicReport {
4
id: string;
5
status: string;
6
trigger: 'PERIOD_DAYS_PASSED_7' | 'PERIOD_DAYS_PASSED_30' | 'PRESCRIPTION_ENDED';
7
creationTimestamp: number;
8
}
9
10
const sdk = client({
11
consumerKey: '',
12
consumerSecret: '',
13
});
14
15
await sdk.authenticate({
16
token: '',
17
tokenSecret: '',
18
});
19
20
const reportsIterator = await sdk.getPeriodicReports();
21
22
for await (const reportsPage of reportsIterator) {
23
... /* PagedResult<PeriodReport> */
24
}
Copied!

Request a periodic report in PDF-format

The sdk.getPeriodicReportPdf method will retrieve a pdf-version of the periodic report.
  • This method takes the reportId as a parameter.
  • The pdf will always be rendered in the language of the user (this language is specified during Register a new user)
Here's an example of how to convert the response to a pdf using react-native-share:
1
import client from '@fibricheck/javascript-sdk';
2
import Share from 'react-native-share';
3
4
const sdk = client({
5
consumerKey: '',
6
consumerSecret: '',
7
});
8
9
await sdk.authenticate({
10
token: '',
11
tokenSecret: '',
12
});
13
14
const report = await sdk.getPeriodicReportPdf('62441ce00000000000000000');
15
const base64 = Buffer.from(file.data, 'binary').toString('base64');
16
const file = `data:application/pdf;base64,${base64}`;
17
const filename = file.headers['content-disposition'].split('filename="')[1].split('.pdf"')[0];
18
19
await Share.open({
20
title: filename,
21
type: 'application/pdf',
22
filename: filename,
23
url: file,
24
});
Copied!

Activating a prescription

The sdk.activatePrescription method will link the prescription to the user and activate it. This method takes the prescription'shash as a parameter.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate({
9
token: '',
10
tokenSecret: '',
11
});
12
13
await sdk.activatePrescription('1234567890');
Copied!