2.7Transaction Builder

 

The TransactionBuilder (JavaDoc) can be used to construct FHIR Transaction Bundles.

Note that this class is a work in progress! It does not yet support all transaction features. We will add more features over time, and document them here. Pull requests are welcomed.

2.7.1Resource Create

 

To add an update (aka PUT) operation to a transaction bundle

// Create a TransactionBuilder
TransactionBuilder builder = new TransactionBuilder(myFhirContext);

// Create a Patient to create
Patient patient = new Patient();
patient.setActive(true);

// Add the patient as a create (aka POST) to the Bundle
builder.addCreateEntry(patient);

// Execute the transaction
IBaseBundle outcome = myFhirClient.transaction().withBundle(builder.getBundle()).execute();

Conditional Create

If you want to perform a conditional create:

// Create a TransactionBuilder
TransactionBuilder builder = new TransactionBuilder(myFhirContext);

// Create a Patient to create
Patient patient = new Patient();
patient.setActive(true);
patient.addIdentifier().setSystem("http://foo").setValue("bar");

// Add the patient as a create (aka POST) to the Bundle
builder.addCreateEntry(patient).conditional("Patient?identifier=http://foo|bar");

// Execute the transaction
IBaseBundle outcome = myFhirClient.transaction().withBundle(builder.getBundle()).execute();

2.7.2Resource Updates

 

To add an update (aka PUT) operation to a transaction bundle

// Create a TransactionBuilder
TransactionBuilder builder = new TransactionBuilder(myFhirContext);

// Create a Patient to update
Patient patient = new Patient();
patient.setId("http://foo/Patient/123");
patient.setActive(true);

// Add the patient as an update (aka PUT) to the Bundle
builder.addUpdateEntry(patient);

// Execute the transaction
IBaseBundle outcome = myFhirClient.transaction().withBundle(builder.getBundle()).execute();

Conditional Update

If you want to perform a conditional update:

// Create a TransactionBuilder
TransactionBuilder builder = new TransactionBuilder(myFhirContext);

// Create a Patient to update
Patient patient = new Patient();
patient.setActive(true);
patient.addIdentifier().setSystem("http://foo").setValue("bar");

// Add the patient as an update (aka PUT) to the Bundle
builder.addUpdateEntry(patient).conditional("Patient?identifier=http://foo|bar");

// Execute the transaction
IBaseBundle outcome = myFhirClient.transaction().withBundle(builder.getBundle()).execute();