///|
fn assumption_json(item : Assumption) -> String {
"{" +
"\"statement\":" +
json_string(item.statement) +
",\"impact\":" +
json_string(item.impact) +
"}"
}
///|
fn input_json(item : InputValue) -> String {
"{" +
"\"name\":" +
json_string(item.name) +
",\"value\":" +
json_string(item.value) +
",\"unit\":" +
json_option(item.unit) +
",\"note\":" +
json_option(item.note) +
"}"
}
///|
fn formula_json(item : FormulaNote) -> String {
"{" +
"\"name\":" +
json_string(item.name) +
",\"expression\":" +
json_string(item.expression) +
",\"explanation\":" +
json_string(item.explanation) +
"}"
}
///|
fn result_json(item : ResultValue) -> String {
"{" +
"\"name\":" +
json_string(item.name) +
",\"value\":" +
json_string(item.value) +
",\"unit\":" +
json_option(item.unit) +
",\"status\":" +
json_string(result_status_name(item.status)) +
",\"note\":" +
json_option(item.note) +
"}"
}
///|
fn warning_json(item : WarningNote) -> String {
"{" +
"\"code\":" +
json_string(item.code) +
",\"severity\":" +
json_string(severity_name(item.severity)) +
",\"summary\":" +
json_string(item.summary) +
",\"action\":" +
json_string(item.action) +
"}"
}
///|
fn source_json(item : SourceRef) -> String {
"{" +
"\"label\":" +
json_string(item.label) +
",\"kind\":" +
json_string(source_kind_name(item.kind)) +
",\"url\":" +
json_option(item.url) +
",\"license\":" +
json_option(item.license) +
",\"note\":" +
json_option(item.note) +
"}"
}
///|
fn section_json(item : ReportSection) -> String {
"{" +
"\"title\":" +
json_string(item.title) +
",\"kind\":" +
json_string(section_kind_name(item.kind)) +
",\"body\":" +
json_string(item.body) +
"}"
}
///|
pub fn ChemReport::to_json(self : ChemReport) -> String {
"{" +
"\"metadata\":{" +
"\"report_id\":" +
json_string(self.metadata.report_id) +
",\"title\":" +
json_string(self.metadata.title) +
",\"process_unit\":" +
json_string(self.metadata.process_unit) +
",\"scenario\":" +
json_string(self.metadata.scenario) +
",\"generated_at\":" +
json_string(self.metadata.generated_at) +
",\"tool_version\":" +
json_string(self.metadata.tool_version) +
"}," +
"\"summary\":" +
json_string(self.summary) +
",\"assumptions\":" +
json_array([ for item in self.assumptions => assumption_json(item) ]) +
",\"inputs\":" +
json_array([ for item in self.inputs => input_json(item) ]) +
",\"formulas\":" +
json_array([ for item in self.formulas => formula_json(item) ]) +
",\"results\":" +
json_array([ for item in self.results => result_json(item) ]) +
",\"warnings\":" +
json_array([ for item in self.warnings => warning_json(item) ]) +
",\"sources\":" +
json_array([ for item in self.sources => source_json(item) ]) +
",\"sections\":" +
json_array([ for item in self.sections => section_json(item) ]) +
",\"tags\":" +
json_array([ for item in self.tags => json_string(item) ]) +
"}"
}
///|
pub fn ChemReport::render_all_formats(self : ChemReport) -> ExportBundle {
{ markdown: self.to_markdown(), html: self.to_html(), json: self.to_json() }
}