Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::Forms Namespace Reference

Namespaces

 UI
 

Classes

class  CheckboxesQuestion
 A Question whose possible responses are represented by checkboxes. More...
 
class  DropdownQuestion
 A Question whose possible responses are represented by a combo box. More...
 
class  Form
 A form consisting of questions possibly divided into multiple sections/pages. More...
 
class  IQuestionFactory
 Register subclasses of Question to create instances of them based on their type string. More...
 
class  LinearScaleQuestion
 A Question whose possible responses are represented by a discrete linear scale. More...
 
class  MultipleChoiceQuestion
 A Question whose possible responses are represented by radio buttons. More...
 
class  ParagraphQuestion
 A Question whose possible response is multi-line free text. More...
 
class  Question
 Abstract base class for all types of questions used in a Form. More...
 
class  QuestionWithOptions
 Base class for questions with options to choose from as response. More...
 
class  QuestionWithOtherOption
 Base class for questions with options that may also have a free text option. More...
 
class  ScreenshotQuestion
 A Question whose responses are screenshot image files. More...
 
class  ShortAnswerQuestion
 A Question whose possible response is a short single-line free text. More...
 
class  TextQuestion
 Abstract base class for questions with a single free-text response. More...
 
class  ModuleActivator
 Module activator for the Forms module. More...
 
class  QuestionFactory
 Default implementation of IQuestionFactory using prototype-based creation. More...
 

Functions

MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, CheckboxesQuestion &q)
 Deserialize a CheckboxesQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const CheckboxesQuestion &q)
 Serialize a CheckboxesQuestion to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, DropdownQuestion &q)
 Deserialize a DropdownQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const DropdownQuestion &q)
 Serialize a DropdownQuestion to JSON. More...
 
MITKFORMS_EXPORT void SubmitToCSV (const Form &form, const fs::path &csvPath)
 Submit form responses to a CSV file. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, Form &f)
 Deserialize a Form from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const Form &f)
 Serialize a Form to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, LinearScaleQuestion &q)
 Deserialize a LinearScaleQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const LinearScaleQuestion &q)
 Serialize a LinearScaleQuestion to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, MultipleChoiceQuestion &q)
 Deserialize a MultipleChoiceQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const MultipleChoiceQuestion &q)
 Serialize a MultipleChoiceQuestion to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, ParagraphQuestion &q)
 Deserialize a ParagraphQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const ParagraphQuestion &q)
 Serialize a ParagraphQuestion to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, Question &q)
 Deserialize from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const Question &q)
 Serialize to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, QuestionWithOptions &q)
 Deserialize a QuestionWithOptions from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const QuestionWithOptions &q)
 Serialize a QuestionWithOptions to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, QuestionWithOtherOption &q)
 Deserialize a QuestionWithOtherOption from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const QuestionWithOtherOption &q)
 Serialize a QuestionWithOtherOption to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, ScreenshotQuestion &q)
 Deserialize a ScreenshotQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const ScreenshotQuestion &q)
 Serialize a ScreenshotQuestion to JSON. More...
 
MITKFORMS_EXPORT void from_json (const nlohmann::ordered_json &j, ShortAnswerQuestion &q)
 Deserialize a ShortAnswerQuestion from JSON. More...
 
MITKFORMS_EXPORT void to_json (nlohmann::ordered_json &j, const ShortAnswerQuestion &q)
 Serialize a ShortAnswerQuestion to JSON. More...
 

Function Documentation

◆ from_json() [1/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
CheckboxesQuestion &  q 
)

Deserialize a CheckboxesQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe CheckboxesQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const CheckboxesQuestion&)

◆ from_json() [2/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
DropdownQuestion &  q 
)

Deserialize a DropdownQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe DropdownQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const DropdownQuestion&)

◆ from_json() [3/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
Form &  f 
)

Deserialize a Form from JSON.

Expects the JSON to contain a "FileFormat" field set to "MITK Form" and a "Version" field set to 1. Questions are created via IQuestionFactory based on their "Type" field.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]fThe Form object to populate.
Exceptions
mitk::ExceptionIf the file format or version is invalid.
See also
to_json(nlohmann::ordered_json&, const Form&)

◆ from_json() [4/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
LinearScaleQuestion &  q 
)

Deserialize a LinearScaleQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe LinearScaleQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const LinearScaleQuestion&)

◆ from_json() [5/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
MultipleChoiceQuestion &  q 
)

Deserialize a MultipleChoiceQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe MultipleChoiceQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const MultipleChoiceQuestion&)

◆ from_json() [6/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
ParagraphQuestion &  q 
)

Deserialize a ParagraphQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe ParagraphQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const ParagraphQuestion&)

◆ from_json() [7/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
Question &  q 
)

Deserialize from JSON.

Polymorphism and the use of base class pointers make it necessary to implement serialization through member functions. Using the pure native approach of the "JSON for Modern C++" library via free functions would lead to partially serialized instances of derived classes.

The actual implementation can and should still be located in a from_json() free function but we also need the indirection through a corresponding member function.

Overloaded functions for derived Question classes should reuse their base class versions of the function.

void mitk::Forms::from_json(const ordered_json& j, RhetoricalQuestion& q)
{
from_json(j, static_cast<Question&>(q));
// TODO: Deserialization of members exclusive to the derived class...
}
MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json &j, CheckboxesQuestion &q)
Deserialize a CheckboxesQuestion from JSON.
Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe Question object to populate.
See also
Question::FromJSON()

◆ from_json() [8/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
QuestionWithOptions &  q 
)

Deserialize a QuestionWithOptions from JSON.

Deserializes the base Question fields and the "Options" array.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe QuestionWithOptions object to populate.
See also
to_json(nlohmann::ordered_json&, const QuestionWithOptions&)

◆ from_json() [9/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
QuestionWithOtherOption &  q 
)

Deserialize a QuestionWithOtherOption from JSON.

Deserializes the QuestionWithOptions fields and enables the "Other" option if the "Other" key is present and true.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe QuestionWithOtherOption object to populate.
See also
to_json(nlohmann::ordered_json&, const QuestionWithOtherOption&)

◆ from_json() [10/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
ScreenshotQuestion &  q 
)

Deserialize a ScreenshotQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe ScreenshotQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const ScreenshotQuestion&)

◆ from_json() [11/11]

MITKFORMS_EXPORT void mitk::Forms::from_json ( const nlohmann::ordered_json &  j,
ShortAnswerQuestion &  q 
)

Deserialize a ShortAnswerQuestion from JSON.

Parameters
[in]jThe JSON object to deserialize from.
[in,out]qThe ShortAnswerQuestion to populate.
See also
to_json(nlohmann::ordered_json&, const ShortAnswerQuestion&)

◆ SubmitToCSV()

MITKFORMS_EXPORT void mitk::Forms::SubmitToCSV ( const Form &  form,
const fs::path &  csvPath 
)

Submit form responses to a CSV file.

If the CSV file does not exist, it is created with a header row containing a timestamp column, supplement columns, and a column for each question. If the file already exists, a new row of responses is appended.

Questions whose HasFileResponses() returns true have their files copied via SubmitFileResponses() and the resulting relative paths are written instead.

Parameters
[in]formThe form whose responses are submitted.
[in]csvPathThe path to the CSV file.
Exceptions
mitk::ExceptionIf the CSV file cannot be opened or created.
See also
Form, Question::HasFileResponses(), Question::SubmitFileResponses()

◆ to_json() [1/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const CheckboxesQuestion &  q 
)

Serialize a CheckboxesQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe CheckboxesQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, CheckboxesQuestion&)

◆ to_json() [2/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const DropdownQuestion &  q 
)

Serialize a DropdownQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe DropdownQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, DropdownQuestion&)

◆ to_json() [3/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const Form &  f 
)

Serialize a Form to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]fThe Form object to serialize.
See also
from_json(const nlohmann::ordered_json&, Form&)

◆ to_json() [4/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const LinearScaleQuestion &  q 
)

Serialize a LinearScaleQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe LinearScaleQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, LinearScaleQuestion&)

◆ to_json() [5/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const MultipleChoiceQuestion &  q 
)

Serialize a MultipleChoiceQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe MultipleChoiceQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, MultipleChoiceQuestion&)

◆ to_json() [6/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const ParagraphQuestion &  q 
)

Serialize a ParagraphQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe ParagraphQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, ParagraphQuestion&)

◆ to_json() [7/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const Question &  q 
)

Serialize to JSON.

Polymorphism and the use of base class pointers make it necessary to implement serialization through member functions. Using the pure native approach of the "JSON for Modern C++" library via free functions would lead to partially serialized instances of derived classes.

The actual implementation can and should still be located in a to_json() free function but we also need the indirection through a corresponding member function.

Overloaded functions for derived Question classes should reuse their base class versions of the function.

void mitk::Forms::to_json(nlohmann::ordered_json& j, const RhetoricalQuestion& q)
{
to_json(j, static_cast<Question&>(q));
// TODO: Serialization of members exclusive to the derived class...
}
MITKFORMS_EXPORT void to_json(nlohmann::ordered_json &j, const CheckboxesQuestion &q)
Serialize a CheckboxesQuestion to JSON.
Parameters
[out]jThe JSON object to serialize into.
[in]qThe Question object to serialize.
See also
Question::ToJSON()

◆ to_json() [8/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const QuestionWithOptions &  q 
)

Serialize a QuestionWithOptions to JSON.

Serializes the base Question fields and the "Options" array.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe QuestionWithOptions object to serialize.
See also
from_json(const nlohmann::ordered_json&, QuestionWithOptions&)

◆ to_json() [9/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const QuestionWithOtherOption &  q 
)

Serialize a QuestionWithOtherOption to JSON.

Serializes the QuestionWithOptions fields and adds an "Other" key if enabled.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe QuestionWithOtherOption object to serialize.
See also
from_json(const nlohmann::ordered_json&, QuestionWithOtherOption&)

◆ to_json() [10/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const ScreenshotQuestion &  q 
)

Serialize a ScreenshotQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe ScreenshotQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, ScreenshotQuestion&)

◆ to_json() [11/11]

MITKFORMS_EXPORT void mitk::Forms::to_json ( nlohmann::ordered_json &  j,
const ShortAnswerQuestion &  q 
)

Serialize a ShortAnswerQuestion to JSON.

Parameters
[out]jThe JSON object to serialize into.
[in]qThe ShortAnswerQuestion to serialize.
See also
from_json(const nlohmann::ordered_json&, ShortAnswerQuestion&)