|
1 | 1 | package dev.dsf.bpe; |
2 | 2 |
|
3 | 3 | import java.io.Serializable; |
| 4 | +import java.util.List; |
4 | 5 | import java.util.Objects; |
| 6 | +import java.util.stream.Collectors; |
5 | 7 |
|
| 8 | +import org.hl7.fhir.r4.model.CodeType; |
6 | 9 | import org.hl7.fhir.r4.model.Coding; |
7 | 10 | import org.hl7.fhir.r4.model.Extension; |
8 | 11 | import org.hl7.fhir.r4.model.StringType; |
| 12 | +import org.hl7.fhir.r4.model.Task; |
9 | 13 | import org.hl7.fhir.r4.model.UrlType; |
10 | 14 |
|
11 | 15 | //todo: remove process and processStep + CodeSystems, make message never contain e.getMessage() becaus security |
@@ -70,4 +74,26 @@ public static ProcessError toError(Extension extension) |
70 | 74 |
|
71 | 75 | return new ProcessError(processCode, stepCode, action, potentialFixUrl, message); |
72 | 76 | } |
| 77 | + |
| 78 | + public static List<Task.TaskOutputComponent> toTaskOutput(List<ProcessError> errors) |
| 79 | + { |
| 80 | + if (errors == null || errors.isEmpty()) |
| 81 | + return List.of(); |
| 82 | + return errors.stream().map(ProcessError::toTaskOutput).collect(Collectors.toList()); |
| 83 | + } |
| 84 | + |
| 85 | + public static Task.TaskOutputComponent toTaskOutput(ProcessError error) |
| 86 | + { |
| 87 | + Task.TaskOutputComponent param = new Task.TaskOutputComponent(); |
| 88 | + |
| 89 | + param.getType().addCoding(new Coding(CodeSystem.DsfPing.URL, CodeSystem.DsfPing.Code.ERROR.getValue(), null)); |
| 90 | + param.addExtension(ProcessError.toExtension(error)); |
| 91 | + Extension dataAbsentReason = new Extension() |
| 92 | + .setUrl("http://hl7.org/fhir/StructureDefinition/data-absent-reason") |
| 93 | + .setValue(new CodeType("not-applicable")); |
| 94 | + param.setValue(new StringType()); |
| 95 | + param.getValue().addExtension(dataAbsentReason); |
| 96 | + |
| 97 | + return param; |
| 98 | + } |
73 | 99 | } |
0 commit comments