Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to export as CSV #5

Open
EwanRoycroft opened this issue Nov 6, 2023 · 0 comments
Open

Add option to export as CSV #5

EwanRoycroft opened this issue Nov 6, 2023 · 0 comments

Comments

@EwanRoycroft
Copy link

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 [email protected]
node ./convert.js

The output will be saved as diary.csv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant