Skip to content

Commit 330cce9

Browse files
committed
Added resource version to all Codings:
- Added resource version to PingProcessPluginDefinition - CodeSystems now include a method that returns a Coding based on a provided Code which always includes the resource version from the PingProcessPluginDefinition - Refactored uses of new Coding initialization to use the methods provided by the respective CodeSystem instead
1 parent 38bc906 commit 330cce9

File tree

7 files changed

+65
-23
lines changed

7 files changed

+65
-23
lines changed

src/main/java/dev/dsf/bpe/CodeSystem.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9+
import org.hl7.fhir.r4.model.Coding;
10+
911
public final class CodeSystem
1012
{
1113
private CodeSystem()
@@ -46,7 +48,6 @@ public T ofValue(String value)
4648
}
4749
}
4850

49-
5051
public static final class DsfPing
5152
{
5253
public static final String URL = "http://dsf.dev/fhir/CodeSystem/ping-v2";
@@ -55,6 +56,14 @@ private DsfPing()
5556
{
5657
}
5758

59+
public static Coding fromCode(Code code)
60+
{
61+
return new Coding()
62+
.setSystem(URL)
63+
.setCode(code.getValue())
64+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
65+
}
66+
5867
public enum Code implements SingleStringValueEnum
5968
{
6069
PING_STATUS("ping-status"),
@@ -95,6 +104,14 @@ private DsfPingStatus()
95104
{
96105
}
97106

107+
public static Coding fromCode(Code code)
108+
{
109+
return new Coding()
110+
.setSystem(URL)
111+
.setCode(code.getValue())
112+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
113+
}
114+
98115
public enum Code implements SingleStringValueEnum
99116
{
100117
COMPLETED("completed"),
@@ -129,6 +146,14 @@ private DsfPingUnits()
129146
{
130147
}
131148

149+
public static Coding fromCode(Code code)
150+
{
151+
return new Coding()
152+
.setSystem(URL)
153+
.setCode(code.toUcum())
154+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
155+
}
156+
132157
public enum Code
133158
{
134159
bps
@@ -320,6 +345,15 @@ private DsfPingError()
320345
{
321346
}
322347

348+
public static Coding fromConcept(Concept concept)
349+
{
350+
return new Coding()
351+
.setSystem(URL)
352+
.setCode(concept.getCode())
353+
.setDisplay(concept.getDisplay())
354+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
355+
}
356+
323357
public enum Concept
324358
{
325359
SEND_MESSAGE_HTTP_401(

src/main/java/dev/dsf/bpe/PingProcessPluginDefinition.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
public class PingProcessPluginDefinition implements ProcessPluginDefinition
1212
{
13-
public static final String VERSION = "2.0.0.0";
13+
public static final String RESOURCE_VERSION = "2.0";
14+
public static final String NON_RESOURCE_VERSION = "0.0";
15+
public static final String VERSION = RESOURCE_VERSION + "." + NON_RESOURCE_VERSION;
1416
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 9, 12);
1517

1618
@Override
@@ -25,6 +27,12 @@ public String getVersion()
2527
return VERSION;
2628
}
2729

30+
@Override
31+
public String getResourceVersion()
32+
{
33+
return RESOURCE_VERSION;
34+
}
35+
2836
@Override
2937
public LocalDate getReleaseDate()
3038
{

src/main/java/dev/dsf/bpe/ProcessError.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public static Extension toExtension(ProcessError error)
2525
extension.setUrl(ConstantsPing.STRUCTURE_DEFINITION_URL_EXTENSION_ERROR);
2626

2727
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_ERROR)
28-
.setValue(new Coding().setSystem(CodeSystem.DsfPingError.URL).setCode(error.concept.getCode())
29-
.setDisplay(error.concept.getDisplay()));
28+
.setValue(CodeSystem.DsfPingError.fromConcept(error.concept()));
3029
if (Objects.nonNull(error.potentialFixUrl))
3130
{
3231
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_POTENTIAL_FIX)
@@ -62,7 +61,7 @@ public static Task.TaskOutputComponent toTaskOutput(ProcessError error)
6261
{
6362
Task.TaskOutputComponent param = new Task.TaskOutputComponent();
6463

65-
param.getType().addCoding(new Coding(CodeSystem.DsfPing.URL, CodeSystem.DsfPing.Code.ERROR.getValue(), null));
64+
param.getType().addCoding(CodeSystem.DsfPing.fromCode(CodeSystem.DsfPing.Code.ERROR));
6665
param.addExtension(ProcessError.toExtension(error));
6766
Extension dataAbsentReason = new Extension()
6867
.setUrl("http://hl7.org/fhir/StructureDefinition/data-absent-reason")

src/main/java/dev/dsf/bpe/util/task/input/generator/DownloadResourceReferenceGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.hl7.fhir.r4.model.Task;
66

77
import dev.dsf.bpe.CodeSystem;
8+
import dev.dsf.bpe.PingProcessPluginDefinition;
89

910
public final class DownloadResourceReferenceGenerator
1011
{
@@ -17,8 +18,7 @@ public static Task.ParameterComponent create(String uri)
1718
Reference reference = new Reference(uri);
1819
reference.setType("Binary");
1920
Task.ParameterComponent param = new Task.ParameterComponent();
20-
param.setValue(reference).getType().addCoding(new Coding(CodeSystem.DsfPing.URL,
21-
CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_REFERENCE.getValue(), null));
21+
param.setValue(reference).getType().addCoding(CodeSystem.DsfPing.fromCode(CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_REFERENCE));
2222
return param;
2323
}
2424
}

src/main/java/dev/dsf/bpe/util/task/input/generator/DownloadResourceSizeGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ private DownloadResourceSizeGenerator()
1515
public static Task.ParameterComponent create(long sizeBytes)
1616
{
1717
Task.ParameterComponent param = new Task.ParameterComponent();
18-
param.setValue(new DecimalType(sizeBytes)).getType().addCoding(new Coding(CodeSystem.DsfPing.URL,
19-
CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_SIZE_BYTES.getValue(), null));
18+
param.setValue(new DecimalType(sizeBytes)).getType().addCoding(CodeSystem.DsfPing.fromCode(CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_SIZE_BYTES));
2019
return param;
2120
}
2221
}

src/main/java/dev/dsf/bpe/util/task/input/generator/ErrorInputComponentGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static Task.ParameterComponent create(ProcessError error)
2929
{
3030
Task.ParameterComponent param = new Task.ParameterComponent();
3131

32-
param.getType().addCoding(new Coding(CodeSystem.DsfPing.URL, CodeSystem.DsfPing.Code.ERROR.getValue(), null));
32+
param.getType().addCoding(CodeSystem.DsfPing.fromCode(CodeSystem.DsfPing.Code.ERROR));
3333
param.addExtension(ProcessError.toExtension(error));
3434
Extension dataAbsentReason = new Extension()
3535
.setUrl("http://hl7.org/fhir/StructureDefinition/data-absent-reason")

src/main/java/dev/dsf/bpe/util/task/output/generator/PingStatusGenerator.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import dev.dsf.bpe.CodeSystem;
1919
import dev.dsf.bpe.ConstantsPing;
20+
import dev.dsf.bpe.PingProcessPluginDefinition;
2021
import dev.dsf.bpe.ProcessError;
2122
import dev.dsf.bpe.v1.constants.NamingSystems.EndpointIdentifier;
2223
import dev.dsf.bpe.v1.constants.NamingSystems.OrganizationIdentifier;
@@ -101,11 +102,11 @@ private static TaskOutputComponent updatePongStatusOutput(TaskOutputComponent ou
101102
{
102103
if (hasStatusCodeSet(outputComponent))
103104
{
104-
updateStatus(outputComponent, CodeSystem.DsfPing.Code.PONG_STATUS.getValue(), statusCode.getValue());
105+
updateStatus(outputComponent, CodeSystem.DsfPing.Code.PONG_STATUS.getValue(), statusCode);
105106
}
106107
else
107108
{
108-
addStatus(outputComponent, CodeSystem.DsfPing.Code.PONG_STATUS.getValue(), statusCode.getValue());
109+
addStatus(outputComponent, CodeSystem.DsfPing.Code.PONG_STATUS, statusCode);
109110
}
110111

111112
return outputComponent;
@@ -261,26 +262,26 @@ private static boolean hasDownloadSpeedSet(TaskOutputComponent outputComponent)
261262
public static TaskOutputComponent createPingStatusOutput(Target target, CodeSystem.DsfPingStatus.Code statusCode,
262263
List<ProcessError> errors)
263264
{
264-
return createStatusOutput(target, CodeSystem.DsfPing.Code.PING_STATUS.getValue(), statusCode.getValue(), errors,
265+
return createStatusOutput(target, CodeSystem.DsfPing.Code.PING_STATUS, statusCode, errors,
265266
null, null, null, null, null);
266267
}
267268

268269
public static TaskOutputComponent createPingStatusOutput(Target target, CodeSystem.DsfPingStatus.Code statusCode,
269270
List<ProcessError> errors, BigDecimal downloadSpeed, BigDecimal uploadSpeed,
270271
CodeSystem.DsfPingUnits.Code unit)
271272
{
272-
return createStatusOutput(target, CodeSystem.DsfPing.Code.PING_STATUS.getValue(), statusCode.getValue(), errors,
273+
return createStatusOutput(target, CodeSystem.DsfPing.Code.PING_STATUS, statusCode, errors,
273274
downloadSpeed, uploadSpeed, unit.name(), CODESYSTEM_UCUM, unit.toUcum());
274275
}
275276

276277
public static TaskOutputComponent createPongStatusOutput(Target target, CodeSystem.DsfPingStatus.Code statusCode,
277278
List<ProcessError> errors)
278279
{
279-
return createStatusOutput(target, CodeSystem.DsfPing.Code.PONG_STATUS.getValue(), statusCode.getValue(), errors,
280+
return createStatusOutput(target, CodeSystem.DsfPing.Code.PONG_STATUS, statusCode, errors,
280281
null, null, null, null, null);
281282
}
282283

283-
private static TaskOutputComponent createStatusOutput(Target target, String outputParameter, String statusCode,
284+
private static TaskOutputComponent createStatusOutput(Target target, CodeSystem.DsfPing.Code outputParameter, CodeSystem.DsfPingStatus.Code statusCode,
284285
List<ProcessError> errors, BigDecimal downloadSpeed, BigDecimal uploadSpeed, String unit, String unitSystem,
285286
String unitCode)
286287
{
@@ -293,30 +294,31 @@ private static TaskOutputComponent createStatusOutput(Target target, String outp
293294
return output;
294295
}
295296

296-
private static TaskOutputComponent addStatus(TaskOutputComponent outputComponent, String outputParameter,
297-
String statusCode)
297+
private static TaskOutputComponent addStatus(TaskOutputComponent outputComponent, CodeSystem.DsfPing.Code outputParameter,
298+
CodeSystem.DsfPingStatus.Code statusCode)
298299
{
299300
if (outputParameter != null && statusCode != null)
300301
{
301-
outputComponent.setValue(new Coding().setSystem(CodeSystem.DsfPingStatus.URL).setCode(statusCode));
302-
outputComponent.getType().addCoding().setSystem(CodeSystem.DsfPing.URL).setCode(outputParameter);
302+
outputComponent.setValue(CodeSystem.DsfPingStatus.fromCode(statusCode));
303+
outputComponent.getType().addCoding(CodeSystem.DsfPing.fromCode(outputParameter));
303304
sortStatusOutputExtensions(outputComponent);
304305
}
305306

306307
return outputComponent;
307308
}
308309

309310
private static TaskOutputComponent updateStatus(TaskOutputComponent outputComponent, String outputParameter,
310-
String statusCode)
311+
CodeSystem.DsfPingStatus.Code statusCode)
311312
{
312313
Type valueType = outputComponent.getValue();
313314
if (valueType instanceof Coding coding)
314315
{
315-
coding.setSystem(CodeSystem.DsfPingStatus.URL).setCode(statusCode);
316+
coding.setSystem(CodeSystem.DsfPingStatus.URL).setCode(statusCode.getValue()).setVersion(
317+
PingProcessPluginDefinition.RESOURCE_VERSION);
316318
}
317319
else
318320
{
319-
outputComponent.setValue(new Coding().setSystem(CodeSystem.DsfPingStatus.URL).setCode(statusCode));
321+
outputComponent.setValue(CodeSystem.DsfPingStatus.fromCode(statusCode));
320322
}
321323

322324
List<Coding> outputTypeCodings = outputComponent.getType().getCoding();

0 commit comments

Comments
 (0)