Skip to content

Commit b3cdcf9

Browse files
committed
issue #424 - fixup Code subtypes
1. use `ValueSet.from` instead of `ValueSet.valueOf` which only works with the ValueSet.name filed (e.g. ADDRESS vs Address) 2. fix FHIRGeneratorBenchmark to match FHIRParserBenchmark 3. if we get an unexpected ValueSet in the `of` static factory helper, throw IllegalStateException instead of IllegalArgumentException since we should never get there unless someone hand-edits the generated class Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
1 parent 1f393dc commit b3cdcf9

248 files changed

Lines changed: 1020 additions & 1011 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRGeneratorBenchmark.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,59 @@
2626
import ca.uhn.fhir.context.FhirContext;
2727

2828
public class FHIRGeneratorBenchmark {
29+
static final Writer NOP_WRITER = BenchmarkUtil.createNOPWriter();
30+
31+
@State(Scope.Thread)
32+
public static class FHIRGenerators {
33+
FHIRGenerator jsonGenerator = FHIRGenerator.generator(Format.JSON);
34+
FHIRGenerator xmlGenerator = FHIRGenerator.generator(Format.XML);
35+
}
36+
2937
@State(Scope.Benchmark)
3038
public static class FHIRGeneratorState {
31-
public static final Writer NOP_WRITER = BenchmarkUtil.createNOPWriter();
39+
FhirContext context;
40+
Resource resource;
41+
IBaseResource baseResource;
3242

33-
public FhirContext context;
34-
public FHIRGenerator jsonGenerator;
35-
public FHIRGenerator xmlGenerator;
36-
public Resource resource;
37-
public IBaseResource baseResource;
43+
// JMH will inject the value into the annotated field before any Setup method is called.
44+
@Param({"valuesets"})
45+
public String exampleName;
3846

3947
@Setup
40-
public void setUp() throws Exception {
41-
context = FhirContext.forR4();
42-
jsonGenerator = FHIRGenerator.generator(Format.JSON);
43-
xmlGenerator = FHIRGenerator.generator(Format.XML);
48+
public void setUp() throws Exception {
49+
if (exampleName == null) {
50+
System.err.println("exampleName is null; if you're in Eclipse then make sure annotation processing is on and you've ran 'mvn clean package'.");
51+
System.exit(1);
52+
}
53+
54+
// us
55+
String JSON_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.JSON, exampleName);
4456
resource = FHIRParser.parser(Format.JSON).parse(new StringReader(JSON_SPEC_EXAMPLE));
57+
58+
// HAPI
59+
context = FhirContext.forR4();
4560
baseResource = context.newJsonParser().parseResource(new StringReader(JSON_SPEC_EXAMPLE));
4661
}
47-
48-
@Param({"test"})
49-
public String JSON_SPEC_EXAMPLE;
50-
51-
@Param({"test"})
52-
public String XML_SPEC_EXAMPLE;
5362
}
5463

5564
@Benchmark
56-
public void benchmarkJsonGenerator(FHIRGeneratorState state) throws Exception {
57-
state.jsonGenerator.generate(state.resource, FHIRGeneratorState.NOP_WRITER);
65+
public void benchmarkJsonGenerator(FHIRGenerators generators, FHIRGeneratorState state) throws Exception {
66+
generators.jsonGenerator.generate(state.resource, NOP_WRITER);
5867
}
5968

6069
@Benchmark
61-
public void benchmarkXMLGenerator(FHIRGeneratorState state) throws Exception {
62-
state.xmlGenerator.generate(state.resource, FHIRGeneratorState.NOP_WRITER);
70+
public void benchmarkXMLGenerator(FHIRGenerators generators, FHIRGeneratorState state) throws Exception {
71+
generators.xmlGenerator.generate(state.resource, NOP_WRITER);
6372
}
6473

6574
@Benchmark
6675
public void benchmarkHAPIJsonGenerator(FHIRGeneratorState state) throws Exception {
67-
state.context.newJsonParser().encodeResourceToWriter(state.baseResource, FHIRGeneratorState.NOP_WRITER);
76+
state.context.newJsonParser().encodeResourceToWriter(state.baseResource, NOP_WRITER);
6877
}
6978

7079
@Benchmark
7180
public void benchmarkHAPIXMLGenerator(FHIRGeneratorState state) throws Exception {
72-
state.context.newXmlParser().encodeResourceToWriter(state.baseResource, FHIRGeneratorState.NOP_WRITER);
81+
state.context.newXmlParser().encodeResourceToWriter(state.baseResource, NOP_WRITER);
7382
}
7483

7584
public static void main(String[] args) throws Exception {

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRParserBenchmark.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
public class FHIRParserBenchmark {
2929
@State(Scope.Thread)
3030
public static class FHIRParsers {
31-
public FHIRParser jsonParser = FHIRParser.parser(Format.JSON);
32-
public FHIRParser xmlParser = FHIRParser.parser(Format.XML);
31+
FHIRParser jsonParser = FHIRParser.parser(Format.JSON);
32+
FHIRParser xmlParser = FHIRParser.parser(Format.XML);
3333
}
3434

3535
@State(Scope.Benchmark)
3636
public static class FHIRParserState {
37-
public FhirContext context;
38-
public String JSON_SPEC_EXAMPLE;
39-
public String XML_SPEC_EXAMPLE;
37+
FhirContext context;
38+
String JSON_SPEC_EXAMPLE;
39+
String XML_SPEC_EXAMPLE;
4040

4141
// JMH will inject the value into the annotated field before any Setup method is called.
4242
@Param({"valuesets"})

fhir-model/src/main/java/com/ibm/fhir/model/type/code/AccountStatus.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ public static AccountStatus of(ValueSet value) {
6161
case UNKNOWN:
6262
return UNKNOWN;
6363
default:
64-
throw new IllegalArgumentException(value.name());
64+
throw new IllegalStateException(value.name());
6565
}
6666
}
6767

6868
public static AccountStatus of(java.lang.String value) {
69-
return of(ValueSet.valueOf(value));
69+
return of(ValueSet.from(value));
7070
}
7171

7272
public static String string(java.lang.String value) {
73-
return of(ValueSet.valueOf(value));
73+
return of(ValueSet.from(value));
7474
}
7575

7676
public static Code code(java.lang.String value) {
77-
return of(ValueSet.valueOf(value));
77+
return of(ValueSet.from(value));
7878
}
7979

8080
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionCardinalityBehavior.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public static ActionCardinalityBehavior of(ValueSet value) {
4040
case MULTIPLE:
4141
return MULTIPLE;
4242
default:
43-
throw new IllegalArgumentException(value.name());
43+
throw new IllegalStateException(value.name());
4444
}
4545
}
4646

4747
public static ActionCardinalityBehavior of(java.lang.String value) {
48-
return of(ValueSet.valueOf(value));
48+
return of(ValueSet.from(value));
4949
}
5050

5151
public static String string(java.lang.String value) {
52-
return of(ValueSet.valueOf(value));
52+
return of(ValueSet.from(value));
5353
}
5454

5555
public static Code code(java.lang.String value) {
56-
return of(ValueSet.valueOf(value));
56+
return of(ValueSet.from(value));
5757
}
5858

5959
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionConditionKind.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ public static ActionConditionKind of(ValueSet value) {
4747
case STOP:
4848
return STOP;
4949
default:
50-
throw new IllegalArgumentException(value.name());
50+
throw new IllegalStateException(value.name());
5151
}
5252
}
5353

5454
public static ActionConditionKind of(java.lang.String value) {
55-
return of(ValueSet.valueOf(value));
55+
return of(ValueSet.from(value));
5656
}
5757

5858
public static String string(java.lang.String value) {
59-
return of(ValueSet.valueOf(value));
59+
return of(ValueSet.from(value));
6060
}
6161

6262
public static Code code(java.lang.String value) {
63-
return of(ValueSet.valueOf(value));
63+
return of(ValueSet.from(value));
6464
}
6565

6666
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionGroupingBehavior.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ public static ActionGroupingBehavior of(ValueSet value) {
4747
case SENTENCE_GROUP:
4848
return SENTENCE_GROUP;
4949
default:
50-
throw new IllegalArgumentException(value.name());
50+
throw new IllegalStateException(value.name());
5151
}
5252
}
5353

5454
public static ActionGroupingBehavior of(java.lang.String value) {
55-
return of(ValueSet.valueOf(value));
55+
return of(ValueSet.from(value));
5656
}
5757

5858
public static String string(java.lang.String value) {
59-
return of(ValueSet.valueOf(value));
59+
return of(ValueSet.from(value));
6060
}
6161

6262
public static Code code(java.lang.String value) {
63-
return of(ValueSet.valueOf(value));
63+
return of(ValueSet.from(value));
6464
}
6565

6666
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionParticipantType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ public static ActionParticipantType of(ValueSet value) {
5454
case DEVICE:
5555
return DEVICE;
5656
default:
57-
throw new IllegalArgumentException(value.name());
57+
throw new IllegalStateException(value.name());
5858
}
5959
}
6060

6161
public static ActionParticipantType of(java.lang.String value) {
62-
return of(ValueSet.valueOf(value));
62+
return of(ValueSet.from(value));
6363
}
6464

6565
public static String string(java.lang.String value) {
66-
return of(ValueSet.valueOf(value));
66+
return of(ValueSet.from(value));
6767
}
6868

6969
public static Code code(java.lang.String value) {
70-
return of(ValueSet.valueOf(value));
70+
return of(ValueSet.from(value));
7171
}
7272

7373
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionPrecheckBehavior.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public static ActionPrecheckBehavior of(ValueSet value) {
4040
case NO:
4141
return NO;
4242
default:
43-
throw new IllegalArgumentException(value.name());
43+
throw new IllegalStateException(value.name());
4444
}
4545
}
4646

4747
public static ActionPrecheckBehavior of(java.lang.String value) {
48-
return of(ValueSet.valueOf(value));
48+
return of(ValueSet.from(value));
4949
}
5050

5151
public static String string(java.lang.String value) {
52-
return of(ValueSet.valueOf(value));
52+
return of(ValueSet.from(value));
5353
}
5454

5555
public static Code code(java.lang.String value) {
56-
return of(ValueSet.valueOf(value));
56+
return of(ValueSet.from(value));
5757
}
5858

5959
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionRelationshipType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ public static ActionRelationshipType of(ValueSet value) {
8989
case AFTER_END:
9090
return AFTER_END;
9191
default:
92-
throw new IllegalArgumentException(value.name());
92+
throw new IllegalStateException(value.name());
9393
}
9494
}
9595

9696
public static ActionRelationshipType of(java.lang.String value) {
97-
return of(ValueSet.valueOf(value));
97+
return of(ValueSet.from(value));
9898
}
9999

100100
public static String string(java.lang.String value) {
101-
return of(ValueSet.valueOf(value));
101+
return of(ValueSet.from(value));
102102
}
103103

104104
public static Code code(java.lang.String value) {
105-
return of(ValueSet.valueOf(value));
105+
return of(ValueSet.from(value));
106106
}
107107

108108
@Override

fhir-model/src/main/java/com/ibm/fhir/model/type/code/ActionRequiredBehavior.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ public static ActionRequiredBehavior of(ValueSet value) {
4747
case MUST_UNLESS_DOCUMENTED:
4848
return MUST_UNLESS_DOCUMENTED;
4949
default:
50-
throw new IllegalArgumentException(value.name());
50+
throw new IllegalStateException(value.name());
5151
}
5252
}
5353

5454
public static ActionRequiredBehavior of(java.lang.String value) {
55-
return of(ValueSet.valueOf(value));
55+
return of(ValueSet.from(value));
5656
}
5757

5858
public static String string(java.lang.String value) {
59-
return of(ValueSet.valueOf(value));
59+
return of(ValueSet.from(value));
6060
}
6161

6262
public static Code code(java.lang.String value) {
63-
return of(ValueSet.valueOf(value));
63+
return of(ValueSet.from(value));
6464
}
6565

6666
@Override

0 commit comments

Comments
 (0)