Skip to content

Commit f563e9c

Browse files
AD1306VK-SMILECDRGary
authored
Update fhir terser (#7135)
* add fieldExists * minor update * minor update * deadspace addition * spotless * add verbose logging options to maven-spotless-apply hook in pre-commit configuration * Revert "add verbose logging options to maven-spotless-apply hook in pre-commit configuration" This reverts commit d8fcf60. * Revert "spotless" This reverts commit 9ad1494. * Revert "deadspace addition" This reverts commit 5d4b2f5. * Revert "minor update" This reverts commit fcda416. * Revert "minor update" This reverts commit b8fabde. --------- Co-authored-by: Vadim Karantayer <[email protected]> Co-authored-by: Gary <[email protected]>
1 parent 8c30b1a commit f563e9c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,17 @@ public void addElements(IBase theTarget, String thePath, Collection<String> theV
17821782
}
17831783
}
17841784

1785+
/**
1786+
* Checks if the field exists on the resource
1787+
*
1788+
* @param theFieldName Name of the field to check
1789+
* @param theResource Resource instance to check
1790+
* @return Returns true if resource definition has a child with the specified name and false otherwise
1791+
*/
1792+
public boolean fieldExists(String theFieldName, IBaseResource theResource) {
1793+
return myContext.getResourceDefinition(theResource).getChildByName(theFieldName) != null;
1794+
}
1795+
17851796
/**
17861797
* Clones a resource object, copying all data elements from theSource into a new copy of the same type.
17871798
* <p>

hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/FhirTerserR4Test.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,13 @@ void copyingAndParsingCreatesDuplicateContainedResources() {
16031603
assertEquals(1, parsedCopy.getContained().size());
16041604
}
16051605

1606+
@Test
1607+
void testFieldExists() {
1608+
final FhirTerser fhirTerser = myCtx.newTerser();
1609+
assertThat(fhirTerser.fieldExists("identifier", new Patient())).isTrue();
1610+
assertThat(fhirTerser.fieldExists("identifier", new Provenance())).isFalse();
1611+
}
1612+
16061613
/**
16071614
* See http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
16081615
*/

0 commit comments

Comments
 (0)