Skip to content

Commit 2678fb9

Browse files
committed
Issue #646 - Define a Narrative.EMPTY constant
Signed-off-by: Troy Biesterfeld <[email protected]>
1 parent b6b9cf0 commit 2678fb9

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

fhir-model/src/main/java/com/ibm/fhir/model/type/Narrative.java

+38-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019, 2020
2+
* (C) Copyright IBM Corp. 2019, 2021
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -38,6 +38,8 @@
3838
)
3939
@Generated("com.ibm.fhir.tools.CodeGenerator")
4040
public class Narrative extends Element {
41+
public static final Narrative EMPTY = builder().status(NarrativeStatus.EMPTY).div(Xhtml.from("Narrative text intentionally left empty")).build();
42+
4143
@Binding(
4244
bindingName = "NarrativeStatus",
4345
strength = BindingStrength.ValueSet.REQUIRED,
@@ -59,9 +61,9 @@ private Narrative(Builder builder) {
5961
}
6062

6163
/**
62-
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or
64+
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or
6365
* whether a human authored it and it may contain additional data.
64-
*
66+
*
6567
* @return
6668
* An immutable object of type {@link NarrativeStatus} that is non-null.
6769
*/
@@ -71,7 +73,7 @@ public NarrativeStatus getStatus() {
7173

7274
/**
7375
* The actual narrative content, a stripped down version of XHTML.
74-
*
76+
*
7577
* @return
7678
* An immutable object of type {@link Xhtml} that is non-null.
7779
*/
@@ -81,8 +83,8 @@ public Xhtml getDiv() {
8183

8284
@Override
8385
public boolean hasChildren() {
84-
return super.hasChildren() ||
85-
(status != null) ||
86+
return super.hasChildren() ||
87+
(status != null) ||
8688
(div != null);
8789
}
8890

@@ -114,19 +116,19 @@ public boolean equals(Object obj) {
114116
return false;
115117
}
116118
Narrative other = (Narrative) obj;
117-
return Objects.equals(id, other.id) &&
118-
Objects.equals(extension, other.extension) &&
119-
Objects.equals(status, other.status) &&
119+
return Objects.equals(id, other.id) &&
120+
Objects.equals(extension, other.extension) &&
121+
Objects.equals(status, other.status) &&
120122
Objects.equals(div, other.div);
121123
}
122124

123125
@Override
124126
public int hashCode() {
125127
int result = hashCode;
126128
if (result == 0) {
127-
result = Objects.hash(id,
128-
extension,
129-
status,
129+
result = Objects.hash(id,
130+
extension,
131+
status,
130132
div);
131133
hashCode = result;
132134
}
@@ -151,12 +153,12 @@ private Builder() {
151153
}
152154

153155
/**
154-
* Unique id for the element within a resource (for internal references). This may be any string value that does not
156+
* Unique id for the element within a resource (for internal references). This may be any string value that does not
155157
* contain spaces.
156-
*
158+
*
157159
* @param id
158160
* Unique id for inter-element referencing
159-
*
161+
*
160162
* @return
161163
* A reference to this Builder instance
162164
*/
@@ -166,16 +168,16 @@ public Builder id(java.lang.String id) {
166168
}
167169

168170
/**
169-
* May be used to represent additional information that is not part of the basic definition of the element. To make the
170-
* use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of
171-
* extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part
171+
* May be used to represent additional information that is not part of the basic definition of the element. To make the
172+
* use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of
173+
* extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part
172174
* of the definition of the extension.
173-
*
175+
*
174176
* <p>Adds new element(s) to the existing list
175-
*
177+
*
176178
* @param extension
177179
* Additional content defined by implementations
178-
*
180+
*
179181
* @return
180182
* A reference to this Builder instance
181183
*/
@@ -185,16 +187,16 @@ public Builder extension(Extension... extension) {
185187
}
186188

187189
/**
188-
* May be used to represent additional information that is not part of the basic definition of the element. To make the
189-
* use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of
190-
* extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part
190+
* May be used to represent additional information that is not part of the basic definition of the element. To make the
191+
* use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of
192+
* extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part
191193
* of the definition of the extension.
192-
*
194+
*
193195
* <p>Replaces the existing list with a new one containing elements from the Collection
194-
*
196+
*
195197
* @param extension
196198
* Additional content defined by implementations
197-
*
199+
*
198200
* @return
199201
* A reference to this Builder instance
200202
*/
@@ -204,14 +206,14 @@ public Builder extension(Collection<Extension> extension) {
204206
}
205207

206208
/**
207-
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or
209+
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or
208210
* whether a human authored it and it may contain additional data.
209-
*
211+
*
210212
* <p>This element is required.
211-
*
213+
*
212214
* @param status
213215
* generated | extensions | additional | empty
214-
*
216+
*
215217
* @return
216218
* A reference to this Builder instance
217219
*/
@@ -222,12 +224,12 @@ public Builder status(NarrativeStatus status) {
222224

223225
/**
224226
* The actual narrative content, a stripped down version of XHTML.
225-
*
227+
*
226228
* <p>This element is required.
227-
*
229+
*
228230
* @param div
229231
* Limited xhtml content
230-
*
232+
*
231233
* @return
232234
* A reference to this Builder instance
233235
*/
@@ -238,13 +240,13 @@ public Builder div(Xhtml div) {
238240

239241
/**
240242
* Build the {@link Narrative}
241-
*
243+
*
242244
* <p>Required elements:
243245
* <ul>
244246
* <li>status</li>
245247
* <li>div</li>
246248
* </ul>
247-
*
249+
*
248250
* @return
249251
* An immutable object of type {@link Narrative}
250252
* @throws IllegalStateException

fhir-model/src/test/java/com/ibm/fhir/model/test/EmptyResourceTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019
2+
* (C) Copyright IBM Corp. 2019, 2021
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,6 +10,7 @@
1010
import org.testng.annotations.Test;
1111

1212
import com.ibm.fhir.model.resource.Patient;
13+
import com.ibm.fhir.model.type.Narrative;
1314

1415
public class EmptyResourceTest {
1516
@Test
@@ -21,4 +22,9 @@ public void testEmptyPatient() {
2122
Assert.assertEquals(e.getMessage(), "global-1: All FHIR elements must have a @value or children");
2223
}
2324
}
25+
26+
@Test
27+
public void testPatientWithEmptyNarrative() {
28+
Patient.builder().text(Narrative.EMPTY).build();
29+
}
2430
}

fhir-tools/src/main/java/com/ibm/fhir/tools/CodeGenerator.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019, 2020
2+
* (C) Copyright IBM Corp. 2019, 2021
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -996,6 +996,10 @@ private void generateClass(JsonObject structureDefinition, List<String> paths, C
996996
cb.field(mods("private", "static", "final"), "int", "MIN_VALUE", "0").newLine();
997997
}
998998

999+
if (isNarrative(structureDefinition)) {
1000+
cb.field(mods("public", "static", "final"), "Narrative", "EMPTY", "builder().status(NarrativeStatus.EMPTY).div(Xhtml.from(" + quote("Narrative text intentionally left empty") + ")).build()").newLine();
1001+
}
1002+
9991003
if (isXhtml(structureDefinition)) {
10001004
cb.field(mods("private", "static", "final"), "java.lang.String", "DIV_OPEN", quote("<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">")).newLine();
10011005
cb.field(mods("private", "static", "final"), "java.lang.String", "DIV_CLOSE", quote("</div>")).newLine();
@@ -4275,6 +4279,10 @@ private boolean isUriSubtype(String className) {
42754279
return uriSubtypeClassNames.contains(className);
42764280
}
42774281

4282+
private boolean isNarrative(JsonObject structureDefinition) {
4283+
return "Narrative".equals(structureDefinition.getString("name"));
4284+
}
4285+
42784286
private boolean isXhtml(JsonObject structureDefinition) {
42794287
return "xhtml".equals(structureDefinition.getString("name"));
42804288
}

0 commit comments

Comments
 (0)