burnedikt / diasend-nightscout-bridge

Synchronize your diasend data to nightscout.
MIT License
18 stars 18 forks source link

Get historical data from Diasend #45

Closed atomphil closed 1 year ago

atomphil commented 1 year ago

Is there a way to retrieve older (or all) data from Diasend? I would like to have the data before the installation of Nighscout (in this case Diasend goes back to 25.01.2023, so it's manageable) and the gaps that occurred due to interruptions in the logging in NS, but were closed in Diasend by later loading, available in Nightcout. This would improve the reports from Nightscout Reporter.

burnedikt commented 1 year ago

It's definitely possible but it requires putting together a script manually using the functions provided by the library. In essence it should look something like the following as that's the core code for synchronizing all events between two dates / times:

import { synchronizeGlucoseRecords } from "./adapter/glucose";
import { synchronizeTreatmentRecords } from "./adapter/treatments";
import { fetchPatientRecords } from "./diasend";

const startDateForSynchronization = new Date(2022, 12, 01);
const endDateForSynchronization = new Date(2023, 01, 25);
const nightscoutClient = getNightscoutHttpClient();

// fetch diasend records between the lower time limit and "now"
const records = await fetchPatientRecords({
  dateFrom: startDateForSynchronization,
  dateTo: endDateForSynchronization,
});

// process records depending on type and synchronize them to nightscout
await Promise.all([
  // handle glucose records
  synchronizeGlucoseRecords(filteredRecords, {
    nightscoutClient,
  }),
  // handle insulin boli, carbs and temp basal rates
  synchronizeTreatmentRecords(filteredRecords, {
    nightscoutClient,
  }),
]);

Disclaimer: It should also prevent re-importing already existing events to nightscout but I am not sure.

Also, large timespans may not work, so might make sense to start with smaller timespans first.

widmann commented 1 year ago

You may export your data for a given period from Diasend in Excel format and import to Nightscout using NightscoutLoader.