Skip to content

Add option to export as CSV #5

@EwanRoycroft

Description

@EwanRoycroft

It would be useful to be able to export as a CSV to share with healthcare professionals.

I've made a node script to do this:

const converter = require("json-2-csv");
const fs = require("fs");

const input = require("./backup20230818T2113110100.json");

const flat = [];

const newRow = (date, time, logType, details) => ({
    date,
    time,
    logType,
    details,
});

for (const day of input?.days) {
    // TODO: symptomOverviews
    for (const symptom of day.symptoms) {
        for (const log of symptom?.logs) {
            flat.push(
                newRow(
                    day.date,
                    log.time,
                    "symptom",
                    `${log.key}, intensity: ${log.pain}/5`,
                ),
            );
        }
    }
    for (const log of day.logs) {
        flat.push(newRow(day.date, log.time, "note", log.key));
    }
    for (const med of day.meds) {
        flat.push(newRow(day.date, med.time, "medication", med.key));
    }
    for (const meal of day.meals) {
        flat.push(
            newRow(
                day.date,
                meal.time,
                "meal",
                meal.detail ? `${meal.key}. ${meal.detail}` : meal.key,
            ),
        );
    }
    // TODO: wakeUp and goToBed
}

flat.sort((a, b) => {
    const dateTime = (n) => new Date(`${n.date}T${n.time}:00Z`);
    return dateTime(b) - dateTime(a);
});

const output = converter.json2csv(flat);

fs.writeFileSync("./diary.csv", output);

To use, save the backup from the app, and copy it to your working folder as backup.json. Save the script above as convert.js.

Then, run:

npm install json-2-csv@5.0.1
node ./convert.js

The output will be saved as diary.csv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions