Fixed test failures
This commit is contained in:
parent
6b387fa0a9
commit
dd47c71f44
|
@ -218,6 +218,13 @@ public final class TerserUtil {
|
|||
mergeFields(theTerser, theResource, childDefinition, theFromFieldValues, theToFieldValues);
|
||||
}
|
||||
|
||||
public static void setFieldByFhirPath(FhirContext theFhirContext, FhirTerser theTerser, String theFhirPath, IBaseResource theResource, IBase theValue) {
|
||||
List<IBase> theFromFieldValues = theTerser.getValues(theResource, theFhirPath, true, false);
|
||||
for (IBase theFromFieldValue : theFromFieldValues) {
|
||||
theTerser.cloneInto(theFromFieldValue, theValue, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void replaceField(IBaseResource theFrom, IBaseResource theTo, BaseRuntimeChildDefinition childDefinition) {
|
||||
childDefinition.getAccessor().getFirstValueOrNull(theFrom).ifPresent(v -> {
|
||||
childDefinition.getMutator().setValue(theTo, v);
|
||||
|
|
|
@ -30,12 +30,24 @@ public class TerserUtilHelper {
|
|||
myResource = theResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets string field at the specified FHIR path
|
||||
*
|
||||
* @param theField The FHIR Path to set the values at
|
||||
* @param theValue The string value to be set
|
||||
* @return Returns current instance
|
||||
*/
|
||||
public TerserUtilHelper setField(String theField, String theValue) {
|
||||
IBase value = TerserUtil.newElement(myContext, "string", theValue);
|
||||
TerserUtil.setField(myContext, getTerser(), theField, myResource, value);
|
||||
IBase value = newStringElement(theValue);
|
||||
TerserUtil.setFieldByFhirPath(myContext, getTerser(), theField, myResource, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected IBase newStringElement(String theValue) {
|
||||
IBase value = TerserUtil.newElement(myContext, "string", theValue);
|
||||
return value;
|
||||
}
|
||||
|
||||
public List<IBase> getFieldValues(String theField) {
|
||||
return TerserUtil.getValues(myContext, myResource, theField);
|
||||
}
|
||||
|
@ -66,6 +78,10 @@ public class TerserUtilHelper {
|
|||
return myContext.getResourceDefinition(myResource);
|
||||
}
|
||||
|
||||
public IBase newElement(String theElementName) {
|
||||
return TerserUtil.newElement(myContext, theElementName);
|
||||
}
|
||||
|
||||
public FhirContext getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
|
|
@ -37,20 +37,20 @@ class TerserUtilTest {
|
|||
|
||||
@Test
|
||||
void testCloneEidIntoResourceViaHelper() {
|
||||
TerserUtilHelper idHelper = TerserUtilHelper.newHelper(ourFhirContext, "Identifier");
|
||||
idHelper
|
||||
.setField("system", "http://org.com/sys")
|
||||
.setField("value", "123");
|
||||
|
||||
TerserUtilHelper p1Helper = TerserUtilHelper.newHelper(ourFhirContext, "Patient");
|
||||
p1Helper.setField("identifier", idHelper.getResource());
|
||||
p1Helper.setField("identifier.system", "http://org.com/sys");
|
||||
p1Helper.setField("identifier.value", "123");
|
||||
|
||||
TerserUtilHelper p2Helper = TerserUtilHelper.newHelper(ourFhirContext, "Patient");
|
||||
RuntimeResourceDefinition definition = p1Helper.getResourceDefinition();
|
||||
TerserUtil.cloneEidIntoResource(ourFhirContext, definition.getChildByName("identifier"), idHelper.getResource(), p2Helper.getResource());
|
||||
TerserUtil.cloneEidIntoResource(ourFhirContext, definition.getChildByName("identifier"), p1Helper.getResource(), p2Helper.getResource());
|
||||
|
||||
assertEquals(1, p2Helper.getFieldValues("identifier").size());
|
||||
assertEquals(p1Helper.getFieldValues("identifier").get(0), p2Helper.getFieldValues("identifier").get(0));
|
||||
|
||||
Identifier id1 = (Identifier) p1Helper.getFieldValues("identifier").get(0);
|
||||
Identifier id2 = (Identifier) p2Helper.getFieldValues("identifier").get(0);
|
||||
assertTrue(id1.equalsDeep(id2));
|
||||
assertFalse(id1.equals(id2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue