Skip to content

Latest commit

 

History

History
108 lines (76 loc) · 2.29 KB

File metadata and controls

108 lines (76 loc) · 2.29 KB

Getting Started

Installation

As a library

Add to your Cargo.toml:

[dependencies]
ge-healthcare-muse = "0.1.0"

As a CLI tool

cargo install ge-healthcare-muse

From source

git clone https://github.com/sixarm/ge-healthcare-muse-rust-crate.git
cd ge-healthcare-muse-rust-crate
cargo build --release

The binary will be at target/release/ge-healthcare-muse.

Quick start: CLI

Convert MUSE XML to JSON

ge-healthcare-muse convert --input patient-ecg.xml --output patient-ecg.json

Convert JSON back to MUSE XML

ge-healthcare-muse convert --input patient-ecg.json --output patient-ecg.xml

View a file summary

ge-healthcare-muse info --input patient-ecg.xml

Validate a file

ge-healthcare-muse validate --input patient-ecg.xml --verify-crc

Quick start: Library

use ge_healthcare_muse::{io_xml, io_json, RestingEcg};
use std::path::Path;

fn main() -> Result<(), ge_healthcare_muse::MuseError> {
    // Read a MUSE XML file
    let ecg = io_xml::read_xml_file(Path::new("patient-ecg.xml"))?;

    // Access patient data
    println!("Patient ID: {}", ecg.patient_demographics.patient_id);
    if let Some(ref name) = ecg.patient_demographics.last_name {
        println!("Last name: {}", name);
    }

    // Convert to JSON
    let json = io_json::to_json(&ecg)?;
    println!("{}", json);

    // Write as JSON file
    io_json::write_json_file(Path::new("patient-ecg.json"), &ecg)?;

    Ok(())
}

Quick start: Round-trip conversion

use ge_healthcare_muse::{io_xml, io_json};
use std::path::Path;

fn main() -> Result<(), ge_healthcare_muse::MuseError> {
    // XML -> Struct -> JSON -> Struct -> XML
    let ecg1 = io_xml::read_xml_file(Path::new("input.xml"))?;
    let json = io_json::to_json(&ecg1)?;
    let ecg2 = io_json::from_json(&json)?;
    let xml = io_xml::to_xml(&ecg2)?;

    // ecg1 and ecg2 are structurally equal
    assert_eq!(ecg1, ecg2);

    Ok(())
}

What's next