| 189 | } |
| 190 | |
| 191 | void 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 | } |
nothing calls this directly
no test coverage detected