Add BundleUtil utility method (#2356)
This commit is contained in:
parent
92669b29da
commit
273a5bbbd7
|
@ -233,7 +233,7 @@ public class BundleUtil {
|
|||
* All 3 might be null - That's ok because we still want to know the
|
||||
* order in the original bundle.
|
||||
*/
|
||||
BundleEntryMutator mutator = new BundleEntryMutator(nextEntry, requestChildDef, requestChildContentsDef);
|
||||
BundleEntryMutator mutator = new BundleEntryMutator(theContext, nextEntry, requestChildDef, requestChildContentsDef, entryChildContentsDef);
|
||||
ModifiableBundleEntry entry = new ModifiableBundleEntry(new BundleEntryParts(fullUrl, requestType, url, resource, conditionalUrl), mutator);
|
||||
theProcessor.accept(entry);
|
||||
}
|
||||
|
|
|
@ -31,11 +31,15 @@ public class BundleEntryMutator {
|
|||
private final IBase myEntry;
|
||||
private final BaseRuntimeChildDefinition myRequestChildDef;
|
||||
private final BaseRuntimeElementCompositeDefinition<?> myRequestChildContentsDef;
|
||||
private final FhirContext myFhirContext;
|
||||
private final BaseRuntimeElementCompositeDefinition<?> myEntryDefinition;
|
||||
|
||||
public BundleEntryMutator(IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition<?> theRequestChildContentsDef) {
|
||||
public BundleEntryMutator(FhirContext theFhirContext, IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition<?> theChildContentsDef, BaseRuntimeElementCompositeDefinition<?> theEntryDefinition) {
|
||||
myFhirContext = theFhirContext;
|
||||
myEntry = theEntry;
|
||||
myRequestChildDef = theRequestChildDef;
|
||||
myRequestChildContentsDef = theRequestChildContentsDef;
|
||||
myRequestChildContentsDef = theChildContentsDef;
|
||||
myEntryDefinition = theEntryDefinition;
|
||||
}
|
||||
|
||||
void setRequestUrl(FhirContext theFhirContext, String theRequestUrl) {
|
||||
|
@ -45,4 +49,13 @@ public class BundleEntryMutator {
|
|||
requestUrlChildDef.getMutator().addValue(nextRequest, url);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setFullUrl(String theFullUrl) {
|
||||
IPrimitiveType<String> value = (IPrimitiveType<String>) myFhirContext.getElementDefinition("uri").newInstance();
|
||||
value.setValue(theFullUrl);
|
||||
|
||||
BaseRuntimeChildDefinition fullUrlChild = myEntryDefinition.getChildByName("fullUrl");
|
||||
fullUrlChild.getMutator().setValue(myEntry, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,4 +58,5 @@ public class BundleEntryParts {
|
|||
public String getUrl() {
|
||||
return myUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,4 +51,8 @@ public class ModifiableBundleEntry {
|
|||
public IBaseResource getResource() {
|
||||
return myBundleEntryParts.getResource();
|
||||
}
|
||||
|
||||
public void setFullUrl(String theFullUrl) {
|
||||
myBundleEntryMutator.setFullUrl(theFullUrl);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,10 +65,23 @@ public class BundleUtilTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProcessEntries() {
|
||||
public void testProcessEntriesSetRequestUrl() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.setType(Bundle.BundleType.TRANSACTION);
|
||||
bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl("Patient");
|
||||
|
||||
Consumer<ModifiableBundleEntry> consumer = e -> e.setFullUrl("http://hello/Patient/123");
|
||||
BundleUtil.processEntries(ourCtx, bundle, consumer);
|
||||
|
||||
assertEquals("http://hello/Patient/123", bundle.getEntryFirstRep().getFullUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessEntriesSetFullUrl() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.setType(Bundle.BundleType.TRANSACTION);
|
||||
bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.GET).setUrl("Observation");
|
||||
|
||||
Consumer<ModifiableBundleEntry> consumer = e -> e.setRequestUrl(ourCtx, e.getRequestUrl() + "?foo=bar");
|
||||
BundleUtil.processEntries(ourCtx, bundle, consumer);
|
||||
assertEquals("Observation?foo=bar", bundle.getEntryFirstRep().getRequest().getUrl());
|
||||
|
|
Loading…
Reference in New Issue