ehrtools / ehrtools/codelist-tools

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

Open
#61 0 comments 0 reactions 0 assignees View on GitHub
current priority
Dominant language
Rust
Stars
15
Forks
3
PR merge metrics
No merged PRs in 30d

Description

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:

```rust
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.

```rust
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.

2. 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:

```rust
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:

```rust
codelist.save_codelist("pneumonia.json");
```

3. 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.