MCPcopy Create free account
hub / github.com/MITK/MITK / SubmitToCSV

Method SubmitToCSV

Modules/Forms/src/mitkForm.cpp:191–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191void mitk::Forms::SubmitToCSV(const Form& form, const fs::path& csvPath)
192{
193 std::ofstream csvFile;
194
195 if (fs::exists(csvPath))
196 {
197 csvFile.open(csvPath, std::ofstream::app);
198
199 if (!csvFile.is_open())
200 mitkThrow() << "Could not open file \"" << csvPath << "\"!";
201 }
202 else
203 {
204 csvFile.open(csvPath);
205
206 if (!csvFile.is_open())
207 mitkThrow() << "Could not create file \"" << csvPath << "\"!";
208
209 csvFile << "\"Timestamp\"";
210
211 for (const auto& [key, value] : form.GetSupplements())
212 csvFile << ",\"" << key << '"';
213
214 for (const auto& section : form)
215 {
216 for (const auto* question : section.GetQuestions())
217 {
218 csvFile << ",\"" << question->GetQuestionText() << '"';
219 }
220 }
221
222 csvFile << '\n';
223 }
224
225 csvFile << '"' << GetCurrentISO8601DateTime() << '"';
226
227 for (const auto& [key, value] : form.GetSupplements())
228 csvFile << ",\"" << value << '"';
229
230 for (const auto& section : form)
231 {
232 for (const auto* question : section.GetQuestions())
233 {
234 csvFile << ",\"";
235 bool isFirstResponse = true;
236
237 std::vector<std::string> responses;
238
239 if (question->HasFileResponses())
240 {
241 auto paths = question->SubmitFileResponses(csvPath.parent_path());
242
243 for (const auto& path : paths)
244 {
245 auto posixPath = path.string();
246 std::replace(posixPath.begin(), posixPath.end(), '\\', '/');
247 responses.push_back(posixPath);
248 }

Callers

nothing calls this directly

Calls 9

GetQuestionsMethod · 0.80
GetQuestionTextMethod · 0.80
openMethod · 0.45
HasFileResponsesMethod · 0.45
SubmitFileResponsesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetResponsesAsStringsMethod · 0.45

Tested by

no test coverage detected