Getting infusion real time data - TREP-LABS/realdrip-backend GitHub Wiki

There are some realtime information of an infusion needed by the platform clients(web and mobile app) e.g flowRate, percentageDispensed, timeToFinish e.t.c. These pieces of information are measured and saved in a firebase realtime database by the RealDrip Device. You can use the deviceID in the infusion data(from the API response) to access the realtime information recorded by the device on firebase. For example, let's say we want to get the realtime information of this infusion in the client application:

{
  "_id": "5dbad66374df3900221a55f5",
  // ...other fields
  "deviceId": "5db23403347ab06cc7bfd8a2",
}

First, we would establish a connection(read-only) to the firebase realtime database, after that, we can use the deviceId to locate the device document to read on firebase, then set up event listeners to know when the data changes. This is a simplistic implementation with firebase Javascript SDK(s):

// Assuming we've already configured our firebase app and the firebase database is in scope.
function getDeviceData(deviceID, callBack) { 
  firebase.database().ref(`/devices/${deviceID}`).on('value', function (snapshot) {
    const data = snapshot.val();
    callBack(data);
  });
}

The callBack function would be executed everytime the data changes.

You would need the firebase credentials to establish a read-only connection to the real-time database, you can reach out to the team lead for this. Make sure to also reach out to whoever is managing the device realtime database to confirm the structure of the data the device is storing.