Skip to content

Logging Project: Split codelist save into save_codes, save_codelist and save_log #61

@CarolineMorton

Description

@CarolineMorton

Follow on to #58

Goal: Restructure the current Rust API so there are 3 clear save* methods, each with a clear purpose:

  1. Exporting codes
  2. Saving full metadata
  3. Persisting the log

Scope:

  1. Implement save_codes

This should include this:

save_codes(path: &str, include_terms: bool, include_comments: bool)

desired behaviour is that it outputs a list of codes a file format. For now, this should be save to csv but we need to build the mechansims and errors so that it takes the path, works out the file format, and then invokes the appropriate method. We will want JSON and CSV at a bare min.

codelist.save_codes(path="pneumonia.csv", include_terms=true, include_comments=true,)
codelist.save_codes(path="pneumonia.json", include_terms=true, include_comments=true)

The reason i think this is the way to go is that we can pass different files formats off to an error (does not support this file type), and we don't just add a lot more methods as we go along for each possible type.

  1. Implement save_codelist

This should save the entire codelist, including metadata such as:

  • Name, coding system, provenance string
  • Purposes, categories, contributors
  • Any other struct-level metadata we track

This should also use format-based dispatch:

save_codelist(path: &str)

Initially support JSON, with room to add formats like YAML later. This method should be the canonical way to persist the entire structure of a Codelist in a way that is reloadable into the library. CSV is not feasible here.

Example:

codelist.save_codelist("pneumonia.json");
  1. Implement save_log

This should persist the internal log to a file. For now, a simple plain-text format is sufficient, where each line is a log entry. Later we could allow structured logging formats like JSON lines or CSV.

codelist.save_log("pneumonia.log");

If a user tries to save to an unsupported extension, return a format-specific error. Probably we should just allow log and txt for now.

Thoughts
We may want to define a FileFormat enum internally (with from_path) to handle this logic more clealny.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions