Commit 932254d3 authored by Aaron Bray's avatar Aaron Bray

Moving ASCII serialization form to JSON

parent 2ce5ff05
......@@ -52,7 +52,8 @@ add_jar(PulseJava ${JAVA_FILES}
"${CMAKE_SOURCE_DIR}/jar/jcommon-1.0.16.jar"
"${CMAKE_SOURCE_DIR}/jar/jdom-2.0.2.jar"
"${CMAKE_SOURCE_DIR}/jar/jfreechart-1.0.13.jar"
"${CMAKE_SOURCE_DIR}/jar/guava-11.0.2.jar"
"${CMAKE_SOURCE_DIR}/jar/gson-2.8.5.jar"
"${CMAKE_SOURCE_DIR}/jar/guava-26.0-jre.jar"
"${CMAKE_SOURCE_DIR}/jar/log4j-1.2.17.jar"
"${CMAKE_SOURCE_DIR}/jar/poi-3.13-20150929.jar"
"${CMAKE_SOURCE_DIR}/jar/poi-ooxml-3.13-20150929.jar"
......
This diff is collapsed.
This diff is collapsed.
{
"Name": "InitialStableState",
"Description": "Stabilize a patient and save out the engines state at time zero",
"StartType": {
"PatientConfiguration": {
"PatientFile": "StandardMale.pba"
}
},
"AnyAction": [{
"Serialize": {
}
}]
}
\ No newline at end of file
Name: "InitialStableState"
Description: "Stabilize a patient and save out the engines state at time zero"
StartType { PatientConfiguration { PatientFile:"StandardMale.pba" } }
AnyAction
{
Serialize { }
}
{
}
\ No newline at end of file
#This will change the time step
#TimeStep {
# ScalarTime { Value: 0.02 Unit: "s" }
#}
{
"Name": "Vitals Monitor",
"Description": "Data associated with a vitals monitor.",
"StartType": { "PatientConfiguration": { "PatientFile": "StandardMale.pba" } },
"DataRequestManager": {
"DataRequest": [{
{"DecimalFormat":{"Precision":2}, "Category":"Physiology", "PropertyName":"HeartRate", "Unit":"1/min"},
{"DecimalFormat":{"Precision":1}, "Category":"Physiology", "PropertyName":"ArterialPressure", "Unit":"mmHg"},
{"DecimalFormat":{"Precision":1}, "Category":"Physiology", "PropertyName":"MeanArterialPressure", "Unit":"mmHg"},
{"DecimalFormat":{} , "Category":"Physiology", "PropertyName":"SystolicArterialPressure", "Unit":"mmHg"},
{"DecimalFormat":{"Precision":1}, "Category":"Physiology", "PropertyName":"DiastolicArterialPressure", "Unit":"mmHg"},
{"DecimalFormat":{"Precision":3}, "Category":"Physiology", "PropertyName":"OxygenSaturation", "Unit":"unitless"},
{"DecimalFormat":{"Precision":4}, "Category":"Physiology", "PropertyName":"EndTidalCarbonDioxideFraction", "Unit":"unitless"},
{"DecimalFormat":{"Precision":2}, "Category":"Physiology", "PropertyName":"RespirationRate", "Unit":"1/min"},
{"DecimalFormat":{"Precision":1}, "Category":"Physiology", "PropertyName":"SkinTemperature", "Unit":"degC"},
{"DecimalFormat":{} , "Category":"GasCompartment", "CompartmentName":"Carina", "SubstanceName":"Oxygen", "PropertyName":"PartialPressure", "Unit":"cmH2O"},
}]}
"AnyAction": [{
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 5.0,
"Unit": "min"
}
}
}
}]
}
\ No newline at end of file
Name: "Vitals Monitor"
Description: "Data associated with a vitals monitor."
StartType { PatientConfiguration { PatientFile:"StandardMale.pba" } }
DataRequestManager
{
DataRequest { Category:ECG PropertyName:"Lead3ElectricPotential" Unit:"mV" DecimalFormat{Precision:3} }
DataRequest { Category:Physiology PropertyName:"HeartRate" Unit:"1/min" DecimalFormat{Precision:2} }
DataRequest { Category:Physiology PropertyName:"ArterialPressure" Unit:"mmHg" DecimalFormat{Precision:1} }
DataRequest { Category:Physiology PropertyName:"MeanArterialPressure" Unit:"mmHg" DecimalFormat{Precision:1} }
DataRequest { Category:Physiology PropertyName:"SystolicArterialPressure" Unit:"mmHg" DecimalFormat{Precision:1} }
DataRequest { Category:Physiology PropertyName:"DiastolicArterialPressure" Unit:"mmHg" DecimalFormat{Precision:1} }
DataRequest { Category:Physiology PropertyName:"OxygenSaturation" Unit:"unitless" DecimalFormat{Precision:3} }
DataRequest { Category:Physiology PropertyName:"EndTidalCarbonDioxidePressure" Unit:"mmHg" DecimalFormat{Precision:4} }
DataRequest { Category:Physiology PropertyName:"RespirationRate" Unit:"1/min" DecimalFormat{Precision:2} }
DataRequest { Category:Physiology PropertyName:"SkinTemperature" Unit:"degC" DecimalFormat{Precision:1} }
DataRequest { Category:GasCompartment CompartmentName:"Carina" SubstanceName:"CarbonDioxide" PropertyName:"PartialPressure" Unit:"mmHg" DecimalFormat{Precision:1} }
}
# Segment 1: Initialization
AnyAction
{
AdvanceTime
{
Time { ScalarTime {Value: 5.0 Unit: "min"} }
}
}
\ No newline at end of file
......@@ -27,7 +27,8 @@ set(JAVA_CLASSPATH Pulse.jar
"@CMAKE_SOURCE_DIR@/jar/jcommon-1.0.16.jar"
"@CMAKE_SOURCE_DIR@/jar/jdom-2.0.2.jar"
"@CMAKE_SOURCE_DIR@/jar/jfreechart-1.0.13.jar"
"@CMAKE_SOURCE_DIR@/jar/guava-11.0.2.jar"
"@CMAKE_SOURCE_DIR@/jar/gson-2.8.5.jar"
"@CMAKE_SOURCE_DIR@/jar/guava-26.0-jre.jar"
"@CMAKE_SOURCE_DIR@/jar/log4j-1.2.17.jar"
"@CMAKE_SOURCE_DIR@/jar/poi-3.13-20150929.jar"
"@CMAKE_SOURCE_DIR@/jar/poi-ooxml-3.13-20150929.jar"
......
......@@ -4,7 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/DataModelBindings"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/commons-logging-1.2.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/guava-11.0.2.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/javassist-3.16.1-GA.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/jcommon-1.0.16.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/jdom-2.0.2.jar"/>
......@@ -17,5 +16,7 @@
<classpathentry kind="var" path="SOURCE_DIR/jar/reflections-0.9.9-RC1-uberjar.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/xmlbeans-2.6.0.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/zip4j-1.3.1.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/gson-2.8.5.jar"/>
<classpathentry kind="var" path="SOURCE_DIR/jar/guava-26.0-jre.jar"/>
<classpathentry kind="output" path="build/java"/>
</classpath>
......@@ -116,7 +116,7 @@ struct CommonDataModelException : public std::runtime_error
#include "Macros.h"
#include "utils/Logger.h"
enum SerializationFormat { BINARY = 0, ASCII };
enum SerializationFormat { BINARY = 0, JSON };
// General Enums
// Keep enums in sync with appropriate schema/cdm/Enums.proto file !!
......
......@@ -96,7 +96,7 @@ public:
//--------------------------------------------------------------------------------------------------
/// \brief
/// locates the pba patient file and reads in the values.
/// locates the json patient file and reads in the values.
///
/// This will create an engine that you can send instructions (patient,actions,conditions) to dynamically.
/// The return value will indicate success failure of the creation of the engine.
......
......@@ -4,12 +4,12 @@
#include "stdafx.h"
#include "io/protobuf/PBCircuit.h"
#include "io/protobuf/PBProperties.h"
#include "io/protobuf/PBUtils.h"
#include "circuit/electrical/SEElectricalCircuit.h"
#include "circuit/fluid/SEFluidCircuit.h"
#include "circuit/thermal/SEThermalCircuit.h"
#include "circuit/SECircuitManager.h"
#include "bind/cpp/cdm/Circuit.pb.h"
#include <google/protobuf/text_format.h>
template<CIRCUIT_PATH_TEMPLATE>
......@@ -122,7 +122,7 @@ bool PBCircuit::LoadCircuitManagerFile(SECircuitManager& mgr, const std::string&
cdm::CircuitManagerData src;
std::ifstream file_stream(filename, std::ios::in);
std::string fmsg((std::istreambuf_iterator<char>(file_stream)), std::istreambuf_iterator<char>());
if (!google::protobuf::TextFormat::ParseFromString(fmsg, &src))
if (!PBUtils::SerializeFromString(fmsg, src, JSON))
return false;
PBCircuit::Load(src, mgr);
return true;
......@@ -136,7 +136,7 @@ void PBCircuit::SaveCircuitManagerFile(const SECircuitManager& mgr, const std::s
{
std::string content;
cdm::CircuitManagerData* src = PBCircuit::Unload(mgr);
google::protobuf::TextFormat::PrintToString(*src, &content);
PBUtils::SerializeToString(*src, content, JSON);
std::ofstream ascii_ostream(filename, std::ios::out | std::ios::trunc);
ascii_ostream << content;
ascii_ostream.flush();
......
......@@ -5,6 +5,7 @@
#include "io/protobuf/PBCompartment.h"
#include "io/protobuf/PBSubstanceQuantity.h"
#include "io/protobuf/PBProperties.h"
#include "io/protobuf/PBUtils.h"
#include "compartment/SECompartment.h"
#include "compartment/SECompartmentGraph.h"
#include "compartment/SECompartmentLink.h"
......@@ -22,7 +23,6 @@
#include "circuit/thermal/SEThermalCircuitPath.h"
#include "substance/SESubstance.h"
#include "substance/SESubstanceManager.h"
#include <google/protobuf/text_format.h>
#include "bind/cpp/cdm/Compartment.pb.h"
void PBCompartment::Serialize(const cdm::CompartmentData& src, SECompartment& dst)
......@@ -51,7 +51,7 @@ bool PBCompartment::LoadCompartmentManagerFile(SECompartmentManager& mgr, const
cdm::CompartmentManagerData src;
std::ifstream file_stream(filename, std::ios::in);
std::string fmsg((std::istreambuf_iterator<char>(file_stream)), std::istreambuf_iterator<char>());
if (!google::protobuf::TextFormat::ParseFromString(fmsg, &src))
if (!PBUtils::SerializeFromString(fmsg, src, JSON))
return false;
PBCompartment::Load(src, mgr, circuits);
return true;
......@@ -65,7 +65,7 @@ void PBCompartment::SaveCompartmentManagerFile(const SECompartmentManager& mgr,
{
std::string content;
cdm::CompartmentManagerData* src = PBCompartment::Unload(mgr);
google::protobuf::TextFormat::PrintToString(*src, &content);
PBUtils::SerializeToString(*src, content,JSON);
std::ofstream ascii_ostream(filename, std::ios::out | std::ios::trunc);
ascii_ostream << content;
ascii_ostream.flush();
......@@ -320,7 +320,7 @@ void PBCompartment::Serialize(const SEFluidCompartment<FLUID_COMPARTMENT_TYPES>&
dst.mutable_compartment()->add_child(child->GetName());
for (SEFluidCircuitNode* nodes : src.m_Nodes.GetNodes())
dst.mutable_compartment()->add_node(nodes->GetName());
// Even if you have children or nodes, I am unloading everything, this makes the pba actually usefull...
// Even if you have children or nodes, I am unloading everything, this makes the json actually usefull...
if (src.HasInFlow())
dst.set_allocated_inflow(PBProperty::Unload(src.GetInFlow()));
if (src.HasOutFlow())
......@@ -372,7 +372,7 @@ void PBCompartment::Serialize(const SEFluidCompartmentLink<FLUID_COMPARTMENT_LIN
dst.mutable_link()->set_path(src.m_Path->GetName());
// Yeah, I know
// But, these will only modify member variables if they are being used as temporary variables
// Even if you have a path, I am unloading everything, this makes the pba actually usefull...
// Even if you have a path, I am unloading everything, this makes the json actually usefull...
SEFluidCompartmentLink<FLUID_COMPARTMENT_LINK_TYPES>& mutable_src = const_cast<SEFluidCompartmentLink<FLUID_COMPARTMENT_LINK_TYPES>&>(src);
if (src.HasFlow())
dst.set_allocated_flow(PBProperty::Unload(mutable_src.GetFlow()));
......@@ -654,7 +654,7 @@ void PBCompartment::Serialize(const SEThermalCompartment& src, cdm::ThermalCompa
dst.mutable_compartment()->add_child(child->GetName());
for (SEThermalCircuitNode* nodes : src.m_Nodes.GetNodes())
dst.mutable_compartment()->add_node(nodes->GetName());
// Even if you have children or nodes, I am unloading everything, this makes the pba actually usefull...
// Even if you have children or nodes, I am unloading everything, this makes the json actually usefull...
if (src.HasHeatTransferRateIn())
dst.set_allocated_heattransferratein(PBProperty::Unload(src.GetHeatTransferRateIn()));
if (src.HasHeatTransferRateOut())
......@@ -715,7 +715,7 @@ void PBCompartment::Serialize(const SEThermalCompartmentLink& src, cdm::ThermalC
dst.mutable_link()->set_path(src.m_Path->GetName());
// Yeah, I know
// But, these will only modify member variables if they are being used as temporary variables
// Even if you have a path, I am unloading everything, this makes the pba actually usefull...
// Even if you have a path, I am unloading everything, this makes the json actually usefull...
SEThermalCompartmentLink& mutable_src = const_cast<SEThermalCompartmentLink&>(src);
if (src.HasHeatTransferRate())
dst.set_allocated_heattransferrate(PBProperty::Unload(mutable_src.GetHeatTransferRate()));
......
......@@ -6,7 +6,6 @@
#include "io/protobuf/PBActions.h"
#include "io/protobuf/PBEngine.h"
#include "io/protobuf/PBUtils.h"
#include <google/protobuf/text_format.h>
#include "bind/cpp/cdm/Scenario.pb.h"
#include "scenario/SEScenario.h"
#include "utils/FileUtils.h"
......
......@@ -11,24 +11,25 @@ void MyLogHandler(google::protobuf::LogLevel level, const char* filename, int li
std::cout << message;
}
bool PBUtils::SerializeToString(const google::protobuf::Message& data, std::string& output, SerializationFormat m)
bool PBUtils::SerializeToString(const google::protobuf::Message& src, std::string& output, SerializationFormat m)
{
if (m == ASCII)
if (m == JSON)
{
google::protobuf::SetLogHandler(MyLogHandler);
return google::protobuf::TextFormat::PrintToString(data, &output);
return google::protobuf::util::MessageToJsonString(src, &output).ok();
//return google::protobuf::TextFormat::PrintToString(data, &output);
}
else
return data.SerializeToString(&output);
return src.SerializeToString(&output);
}
bool PBUtils::SerializeFromString(const std::string& src, google::protobuf::Message& dst, SerializationFormat m)
{
if (m == ASCII)
if (m == JSON)
{
google::protobuf::SetLogHandler(MyLogHandler);
if (!google::protobuf::TextFormat::ParseFromString(src, &dst))
if (!google::protobuf::util::JsonStringToMessage(src, &dst).ok())
if (!google::protobuf::util::JsonStringToMessage(src, &dst).ok())
if (!google::protobuf::TextFormat::ParseFromString(src, &dst))
return false;
return true;
}
......
......@@ -14,8 +14,8 @@ public:
virtual void Clear(); //clear memory
bool SerializeToString(std::string& output, SerializationFormat m=BINARY) const;
bool SerializeToFile(const std::string& filename, SerializationFormat m=ASCII) const;
bool SerializeToString(std::string& output, SerializationFormat m) const;
bool SerializeToFile(const std::string& filename, SerializationFormat m) const;
virtual bool HasHematocrit() const;
virtual SEScalar0To1& GetHematocrit();
......
......@@ -39,7 +39,7 @@ bool SEScenarioExec::Execute(const std::string& scenarioFile, const std::string&
SEScenario scenario(m_Engine.GetSubstanceManager());
try
{
scenario.SerializeFromFile(scenarioFile,ASCII);
scenario.SerializeFromFile(scenarioFile,JSON);
}
catch (CommonDataModelException& ex)
{
......@@ -79,7 +79,7 @@ bool SEScenarioExec::Execute(const SEScenario& scenario, const std::string& resu
// Initialize the engine with a state or initial parameters
if (scenario.HasEngineStateFile())
{
m_Engine.SerializeFromFile(scenario.GetEngineStateFile(),ASCII);
m_Engine.SerializeFromFile(scenario.GetEngineStateFile(),JSON);
// WE ARE OVERWRITING ANY DATA REQUESTS IN THE STATE WITH WHATS IN THE SCENARIO!!!
// Make a copy of the data requests, note this clears out data requests from the engine
m_Engine.GetEngineTracker()->GetDataRequestManager().Copy(scenario.GetDataRequestManager(), m_Engine.GetSubstanceManager());
......
......@@ -246,7 +246,7 @@ bool SESubstanceManager::LoadSubstanceDirectory(const std::string& data_dir)
DIR *sdir;
DIR *cdir;
struct dirent *ent;
std::string ext = ".pba";
std::string ext = ".json";
#if defined(_WIN32)
sdir = opendir(std::string(data_dir + "/substances/").c_str());
......@@ -268,7 +268,7 @@ bool SESubstanceManager::LoadSubstanceDirectory(const std::string& data_dir)
try
{
SESubstance* sub = new SESubstance(GetLogger());
if (!sub->SerializeFromFile(ss.str(), ASCII))
if (!sub->SerializeFromFile(ss.str(), JSON))
{
delete sub;
Error("Unable to read substance " + ss.str());
......@@ -308,7 +308,7 @@ bool SESubstanceManager::LoadSubstanceDirectory(const std::string& data_dir)
try
{
SESubstanceCompound* cmpd = new SESubstanceCompound(GetLogger());
if (!cmpd->SerializeFromFile(ss.str(), *this, ASCII))
if (!cmpd->SerializeFromFile(ss.str(), *this, JSON))
{
delete cmpd;
Error("Unable to read substance compound " + ss.str());
......
......@@ -100,7 +100,7 @@ bool SEEnvironment::ProcessChange(const SEInitialEnvironmentConditions& change)
GetConditions().Merge(*change.GetConditions());
else if (change.HasConditionsFile())
{
if (!GetConditions().SerializeFromFile(change.GetConditionsFile(),ASCII))// Does NOT merge file in data, Should we?
if (!GetConditions().SerializeFromFile(change.GetConditionsFile(),JSON))// Does NOT merge file in data, Should we?
{
/// \error Unable to read Configuration Action file
Error("Could not read provided SEInitialEnvironment file", "SEEnvironment::ProcessChange");
......@@ -119,7 +119,7 @@ bool SEEnvironment::ProcessChange(const SEChangeEnvironmentConditions& change)
GetConditions().Merge(*change.GetConditions());
else if (change.HasConditionsFile())
{
if (!GetConditions().SerializeFromFile(change.GetConditionsFile(),ASCII))// Does NOT merge file in data, Should we?
if (!GetConditions().SerializeFromFile(change.GetConditionsFile(),JSON))// Does NOT merge file in data, Should we?
{
/// \error Unable to read Configuration Action file
Error("Could not read provided SEEnvironmentChange file", "SEEnvironment::ProcessChange");
......
......@@ -116,7 +116,7 @@ void SEAnesthesiaMachine::ProcessConfiguration(const SEAnesthesiaMachineConfigur
if (config.HasConfiguration())
Merge(*config.GetConfiguration());
else if (config.HasConfigurationFile())
if (!SerializeFromFile(config.GetConfigurationFile(),ASCII)) // Does NOT merge file in data, Should we ?
if (!SerializeFromFile(config.GetConfigurationFile(),JSON)) // Does NOT merge file in data, Should we ?
Error("Unable to load configuration file", "SEAnesthesiaMachine::ProcessConfiguration");
StateChange();
}
......
......@@ -94,7 +94,7 @@ void SEInhaler::ProcessConfiguration(const SEInhalerConfiguration& config)
if (config.HasConfiguration())
Merge(*config.GetConfiguration());
else if (config.HasConfigurationFile())
if (!SerializeFromFile(config.GetConfigurationFile(),ASCII))// Does NOT merge file in data, Should we?
if (!SerializeFromFile(config.GetConfigurationFile(),JSON))// Does NOT merge file in data, Should we?
Error("Unable to load configuration file", "SEInhaler::ProcessConfiguration");
StateChange();
}
......
......@@ -91,7 +91,7 @@ bool WriteFile(const std::string& content, const std::string& filename, Serializ
{
if (!CreateFilePath(filename))
return false;
if (m == ASCII)
if (m == JSON)
{
std::ofstream ascii_ostream(filename, std::ios::out | std::ios::trunc);
ascii_ostream << content;
......
......@@ -4,14 +4,10 @@ package com.kitware.physiology.datamodel.engine;
import java.util.*;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.*;
import com.google.protobuf.util.*;
import com.kitware.physiology.cdm.Engine.DynamicStabilizationData;
import com.kitware.physiology.cdm.PatientNutrition.NutritionData;
import com.kitware.physiology.cdm.Enums.eSwitch;
import com.kitware.physiology.datamodel.patient.nutrition.SENutrition;
import com.kitware.physiology.datamodel.properties.SEScalarTime;
import com.kitware.physiology.utilities.FileUtils;
public class SEDynamicStabilization
......@@ -34,15 +30,15 @@ public class SEDynamicStabilization
this.conditionConvergence.clear();
}
public void readFile(String fileName) throws ParseException
public void readFile(String fileName) throws InvalidProtocolBufferException
{
DynamicStabilizationData.Builder builder = DynamicStabilizationData.newBuilder();
TextFormat.getParser().merge(FileUtils.readFile(fileName), builder);
JsonFormat.parser().merge(FileUtils.readFile(fileName), builder);
SEDynamicStabilization.load(builder.build(), this);
}
public void writeFile(String fileName)
public void writeFile(String fileName) throws InvalidProtocolBufferException
{
FileUtils.writeFile(fileName, SEDynamicStabilization.unload(this).toString());
FileUtils.writeFile(fileName, JsonFormat.printer().print(SEDynamicStabilization.unload(this)));
}
public static void load(DynamicStabilizationData src, SEDynamicStabilization dst)
......
......@@ -4,8 +4,8 @@ package com.kitware.physiology.datamodel.engine;
import java.util.*;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.*;
import com.google.protobuf.util.*;
import com.kitware.physiology.cdm.Engine.TimedStabilizationData;
import com.kitware.physiology.cdm.Enums.eSwitch;
......@@ -34,15 +34,15 @@ public class SETimedStabilization
this.conditionStabilizationTimes.clear();
}
public void readFile(String fileName) throws ParseException
public void readFile(String fileName) throws InvalidProtocolBufferException
{
TimedStabilizationData.Builder builder = TimedStabilizationData.newBuilder();
TextFormat.getParser().merge(FileUtils.readFile(fileName), builder);
JsonFormat.parser().merge(FileUtils.readFile(fileName), builder);
SETimedStabilization.load(builder.build(), this);
}
public void writeFile(String fileName)
public void writeFile(String fileName) throws InvalidProtocolBufferException
{
FileUtils.writeFile(fileName, SETimedStabilization.unload(this).toString());
FileUtils.writeFile(fileName, JsonFormat.printer().print(SETimedStabilization.unload(this)));
}
public static void load(TimedStabilizationData src, SETimedStabilization dst)
......
......@@ -6,9 +6,8 @@ import java.util.*;
import com.kitware.physiology.datamodel.properties.*;
import com.kitware.physiology.utilities.FileUtils;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.util.*;
import com.google.protobuf.InvalidProtocolBufferException;
import com.kitware.physiology.cdm.PatientEnums.ePatient.*;
import com.kitware.physiology.cdm.Patient.PatientData;
......@@ -117,15 +116,15 @@ public class SEPatient
events.clear();
}
public void readFile(String fileName) throws ParseException
public void readFile(String fileName) throws InvalidProtocolBufferException
{
PatientData.Builder builder = PatientData.newBuilder();
TextFormat.getParser().merge(FileUtils.readFile(fileName), builder);
JsonFormat.parser().merge(FileUtils.readFile(fileName), builder);
SEPatient.load(builder.build(), this);
}
public void writeFile(String fileName)
public void writeFile(String fileName) throws InvalidProtocolBufferException
{
FileUtils.writeFile(fileName, SEPatient.unload(this).toString());
FileUtils.writeFile(fileName, JsonFormat.printer().print(SEPatient.unload(this)));
}
public static void load(PatientData src, SEPatient dst)
......
......@@ -2,8 +2,8 @@
See accompanying NOTICE file for details.*/
package com.kitware.physiology.datamodel.patient.assessments;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.*;
import com.google.protobuf.util.*;
import com.kitware.physiology.cdm.PatientAssessments.CompleteBloodCountData;
import com.kitware.physiology.datamodel.properties.*;
......@@ -54,15 +54,15 @@ public class SECompleteBloodCount extends SEPatientAssessment
this.whiteBloodCellCount.invalidate();
}
public void readFile(String fileName) throws ParseException
public void readFile(String fileName) throws InvalidProtocolBufferException
{
CompleteBloodCountData.Builder builder = CompleteBloodCountData.newBuilder();
TextFormat.getParser().merge(FileUtils.readFile(fileName), builder);
JsonFormat.parser().merge(FileUtils.readFile(fileName), builder);
SECompleteBloodCount.load(builder.build(), this);
}
public void writeFile(String fileName)
public void writeFile(String fileName) throws InvalidProtocolBufferException
{
FileUtils.writeFile(fileName, SECompleteBloodCount.unload(this).toString());
FileUtils.writeFile(fileName, JsonFormat.printer().print(SECompleteBloodCount.unload(this)));
}
public static void load(CompleteBloodCountData src, SECompleteBloodCount dst)
......
......@@ -2,8 +2,8 @@
See accompanying NOTICE file for details.*/
package com.kitware.physiology.datamodel.patient.assessments;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.*;
import com.google.protobuf.util.*;
import com.kitware.physiology.cdm.PatientAssessments.ComprehensiveMetabolicPanelData;
import com.kitware.physiology.datamodel.properties.*;
......@@ -78,15 +78,15 @@ public class SEComprehensiveMetabolicPanel extends SEPatientAssessment
this.totalProtein.invalidate();
}
public void readFile(String fileName) throws ParseException
public void readFile(String fileName) throws InvalidProtocolBufferException
{
ComprehensiveMetabolicPanelData.Builder builder = ComprehensiveMetabolicPanelData.newBuilder();
TextFormat.getParser().merge(FileUtils.readFile(fileName), builder);
JsonFormat.parser().merge(FileUtils.readFile(fileName), builder);
SEComprehensiveMetabolicPanel.load(builder.build(), this);
}
public void writeFile(String fileName)
public void writeFile(String fileName) throws InvalidProtocolBufferException
{
FileUtils.writeFile(fileName, SEComprehensiveMetabolicPanel.unload(this).toString());
FileUtils.writeFile(fileName, JsonFormat.printer().print(SEComprehensiveMetabolicPanel.unload(this)));
}
public static void load(ComprehensiveMetabolicPanelData src, SEComprehensiveMetabolicPanel dst)
......
......@@ -5,10 +5,9 @@ package com.kitware.physiology.datamodel.patient.assessments;
import org.jfree.util.Log;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.kitware.physiology.cdm.PatientAssessments.PatientAssessmentData;
import com.kitware.physiology.cdm.PatientAssessments.PulmonaryFunctionTestData;
import com.kitware.physiology.utilities.FileUtils;
......@@ -38,7 +37,7 @@ public abstract class SEPatientAssessment
}
public static SEPatientAssessment readAssessment(String fileName) throws ParseException
public static SEPatientAssessment readAssessment(String fileName) throws InvalidProtocolBufferException
{
try
{
......@@ -46,7 +45,7 @@ public abstract class SEPatientAssessment
cbc.readFile(fileName);
return cbc;
}
catch(ParseException ex){}
catch(InvalidProtocolBufferException ex){}
try
{
......@@ -54,7 +53,7 @@ public abstract class SEPatientAssessment
cmp.readFile(fileName);
return cmp;
}
catch(ParseException ex){}
catch(InvalidProtocolBufferException ex){}
try
{
......@@ -62,22 +61,22 @@ public abstract class SEPatientAssessment
pft.readFile(fileName);
return pft;
}
catch(ParseException ex){}
catch(InvalidProtocolBufferException ex){}
SEUrinalysis u = new SEUrinalysis();
u.readFile(fileName);
return u;
}
public static boolean writeAssement(String fileName, SEPatientAssessment ass)
public static boolean writeAssement(String fileName, SEPatientAssessment ass) throws InvalidProtocolBufferException
{
if(ass instanceof SECompleteBloodCount)
return FileUtils.writeFile(fileName, SECompleteBloodCount.unload((SECompleteBloodCount)ass).toString());
return FileUtils.writeFile(fileName, JsonFormat.printer().print(SECompleteBloodCount.unload((SECompleteBloodCount)ass)));
if(ass instanceof SEComprehensiveMetabolicPanel)
return FileUtils.writeFile(fileName, SEComprehensiveMetabolicPanel.unload((SEComprehensiveMetabolicPanel)ass).toString());
return FileUtils.writeFile(fileName, JsonFormat.printer().print(SEComprehensiveMetabolicPanel.unload((SEComprehensiveMetabolicPanel)ass)));
if(ass instanceof SEPulmonaryFunctionTest)
return FileUtils.writeFile(fileName, SEPulmonaryFunctionTest.unload((SEPulmonaryFunctionTest)ass).toString());
return FileUtils.writeFile(fileName, JsonFormat.printer().print(SEPulmonaryFunctionTest.unload((SEPulmonaryFunctionTest)ass)));
if(ass instanceof SEUrinalysis)
return FileUtils.writeFile(fileName, SEUrinalysis.unload((SEUrinalysis)ass).toString());
return FileUtils.writeFile(fileName, JsonFormat.printer().print(SEUrinalysis.unload((SEUrinalysis)ass)));
Log.error("No write support for assesment of class "+ass.getClass().getName());
return false;
}
......
......@@ -2,8 +2,8 @@
See accompanying NOTICE file for details.*/
package com.kitware.physiology.datamodel.patient.assessments;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
import com.google.protobuf.*;
import com.google.protobuf.util.*;