Health-GPS 3.0.0.0
Global Health Policy Simulation model (Health-GPS)
Loading...
Searching...
No Matches
jsonparser.h
Go to the documentation of this file.
1
11#pragma once
12#include "poco.h"
13#include "riskmodel.h"
14
15#include <nlohmann/json.hpp>
16#include <optional>
17
18namespace hgps::input {
20using json = nlohmann::json;
21
22//--------------------------------------------------------
23// Full risk factor model POCO types mapping
24//--------------------------------------------------------
25
26// Linear models
27void to_json(json &j, const CoefficientInfo &p);
28void from_json(const json &j, CoefficientInfo &p);
29
30void to_json(json &j, const LinearModelInfo &p);
31void from_json(const json &j, LinearModelInfo &p);
32
33// Hierarchical levels
34void to_json(json &j, const Array2Info &p);
35void from_json(const json &j, Array2Info &p);
36
37void to_json(json &j, const HierarchicalLevelInfo &p);
38void from_json(const json &j, HierarchicalLevelInfo &p);
39
40//--------------------------------------------------------
41// Configuration sections POCO types mapping
42//--------------------------------------------------------
43
44// Data file information
45void to_json(json &j, const FileInfo &p);
46
47// Settings Information
48void to_json(json &j, const SettingsInfo &p);
49void from_json(const json &j, SettingsInfo &p);
50
51// SES Model Information
52void to_json(json &j, const SESInfo &p);
53void from_json(const json &j, SESInfo &p);
54
55// MAHIMA: Income quintile factor means adjustment (see income_quintile_factor_means_plan.md; Phase
56// 2+ simulation behaviour).
57// Baseline model information (optional income-stratum factors-mean block is nested on
58// BaselineInfo)
59void to_json(json &j, const IncomeStratumFactorsMeanStratumEntry &p);
60void to_json(json &j, const IncomeStratumFactorsMeanConfig &p);
61void to_json(json &j, const BaselineInfo &p);
62
63// Lite risk factors models (Energy Balance Model)
64void to_json(json &j, const RiskFactorInfo &p);
65void from_json(const json &j, RiskFactorInfo &p);
66
67void to_json(json &j, const VariableInfo &p);
68void from_json(const json &j, VariableInfo &p);
69
70void to_json(json &j, const FactorDynamicEquationInfo &p);
71void from_json(const json &j, FactorDynamicEquationInfo &p);
72
73// Policy Scenario
74void to_json(json &j, const PolicyPeriodInfo &p);
75void from_json(const json &j, PolicyPeriodInfo &p);
76
77void to_json(json &j, const PolicyImpactInfo &p);
78void from_json(const json &j, PolicyImpactInfo &p);
79
80void to_json(json &j, const PolicyAdjustmentInfo &p);
81void from_json(const json &j, PolicyAdjustmentInfo &p);
82
83void to_json(json &j, const PolicyScenarioInfo &p);
84void from_json(const json &j, PolicyScenarioInfo &p);
85
86// Individual ID tracking config (MAHIMA: per-person CSV for same-person tracking)
87void to_json(json &j, const IndividualIdTrackingConfig &p);
88void from_json(const json &j, IndividualIdTrackingConfig &p);
89
90// Output information
91void to_json(json &j, const OutputInfo &p);
92void from_json(const json &j, OutputInfo &p);
93
94} // namespace hgps::input
95
96namespace hgps::core {
97using json = nlohmann::json;
98
99template <class T> void to_json(json &j, const Interval<T> &interval) {
100 j = json::array({interval.lower(), interval.upper()});
101}
102
103template <class T> void from_json(const json &j, Interval<T> &interval) {
104 const auto vec = j.get<std::vector<T>>();
105 if (vec.size() != 2) {
106 throw json::type_error::create(302, "Interval arrays must have only two elements", nullptr);
107 }
108
109 interval = Interval<T>{vec[0], vec[1]};
110}
111} // namespace hgps::core
112
113namespace std {
114
115// Optional parameters
116template <typename T> void to_json(nlohmann::json &j, const std::optional<T> &p) {
117 if (p) {
118 j = *p;
119 } else {
120 j = nullptr;
121 }
122}
123template <typename T> void from_json(const nlohmann::json &j, std::optional<T> &p) {
124 if (j.is_null()) {
125 p = std::nullopt;
126 } else {
127 p = j.get<T>();
128 }
129}
130
131} // namespace std
Numeric interval representation data type.
Definition interval.h:14
TYPE upper() const noexcept
Gets the interval upper bound.
Definition interval.h:35
TYPE lower() const noexcept
Gets the interval lower bound.
Definition interval.h:31
Top-level namespace for Health-GPS Core C++ API.
Definition analysis.h:7
nlohmann::json json
Definition jsonparser.h:97
void to_json(json &j, const Interval< T > &interval)
Definition jsonparser.h:99
void from_json(const nlohmann::json &j, Identifier &id)
Definition identifier.cpp:60
Data structures containing model parameters and configuration options.
Definition configuration.cpp:75
void to_json(json &j, const FileInfo &p)
Definition jsonparser.cpp:8
nlohmann::json json
JSON parser namespace alias.
Definition configuration.cpp:77
Global namespace.
Definition column_iterator.h:123
void to_json(nlohmann::json &j, const std::optional< T > &p)
Definition jsonparser.h:116