# Contribution in general and how to post them in EHRBase

**URL:** https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241
**Category:** Platform
**Tags:** ehrbase
**Created:** [20 January 2021 15:57 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241 "2021-01-20T15:57:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![surfer](https://discourse.openehr.org/user_avatar/discourse.openehr.org/surfer/32/2326_2.png) [@surfer](https://discourse.openehr.org/u/surfer)
#### Post date: [20 January 2021 15:57 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/1 "2021-01-20T15:57:20Z")

</div>

Hi,  
I’d like to learn how/when to use the contributions. Due to my ignorance my questions are very basic and maybe naive.  
1)The first thing is that I don’t have any example of contribution, to learn from, other than the one in the API openEHR specification [[EHR API](https://specifications.openehr.org/releases/ITS-REST/latest/ehr.html#contribution)] .  
Do you have a meaningful example of a contribution?  
2)Then I was wondering what’s the difference between posting a composition and posting a contribution with the same composition inside or as well if I should use the REST put to update a composition or should I update it through a contribution. What’s the recommended approach?  
3)How do you post a contribution to EHRBase? I tried with the contribution I mentioned before with no success.

---

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [20 January 2021 16:16 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/2 "2021-01-20T16:16:53Z")

</div>

Here is a bit of explanatory background on Contributions:

- [openEHR Architecture Overview - Versioning](https://specifications.openehr.org/releases/BASE/latest/architecture_overview.html#_versioning_2)
- [EHR spec](https://specifications.openehr.org/releases/RM/latest/ehr.html#_change_control_in_the_ehr)

Short summary of the concepts:

- a Contribution is the same idea as a [change set](https://en.wikipedia.org/wiki/Changeset) in versioning theory - a collection of all changes to be committed at one time to some repository or file system.
- whenever anything is committed to the openEHR EHR, a Contribution is created, whether you are explicitly aware of it or not.
- ideally, a repository should advance from one valid state to the next in contribution steps - i.e. no commit should create an invalid state.

An API that supports Contributions should enable you to commit multiple changes in one set, i.e.

- updated Compositions - e.g. Medications list, Problem List.
- new Encounter Composition
- even logical deletes (rare in openEHR)

hope this helps.

---

<div class="post-metadata">

### Author: ![surfer](https://discourse.openehr.org/user_avatar/discourse.openehr.org/surfer/32/2326_2.png) [@surfer](https://discourse.openehr.org/u/surfer)
#### Post date: [20 January 2021 17:10 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/3 "2021-01-20T17:10:26Z")

</div>

thank you Mr Beale,  
I just read them and returning to point 2) in the original post if i understood it correctly there’s no difference in the two approaches. I mean if I have only a composition to create I can do it through the composition API or through the contribution API with AUDIT\_DETAILS.change\_type set to create. There’s not a preferred approach.  
But what happens if I post a contribution where multiple action occur and one fails? Being change-set means that everything in the contribution is rejected or the action that fails is removed and the rest form an accepted contribution?

---

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [20 January 2021 17:22 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/4 "2021-01-20T17:22:44Z")

</div>

If you just want to commit a single Composition, which is a common thing to need to do in many situations, then the Composition API will be easier. It will cause a Contribution to be created for you.

If you try to commit a Contribution, and it contains one item that doesn’t validate against its template, the Contribution will fail. But the same can happen with just a single Composition.

It might be useful for us to think about an additional API that can validate structures before trying to do a commit.

---

<div class="post-metadata">

### Author: ![surfer](https://discourse.openehr.org/user_avatar/discourse.openehr.org/surfer/32/2326_2.png) [@surfer](https://discourse.openehr.org/u/surfer)
#### Post date: [20 January 2021 19:10 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/5 "2021-01-20T19:10:55Z")

</div>

and for point 1) and 3) that is I would need an example of a contribution accepted by EHRBase, @birger.haarbrandt can you help me? As I tried the example composition from the openEHR specification and tried to overcome the errors that comes out with no success.

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [20 January 2021 19:36 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/6 "2021-01-20T19:36:07Z")

</div>

Hi @surfer,

you will find some examples in our integration tests: [https://github.com/ehrbase/ehrbase/tree/develop/tests/robot/\_resources/test\_data\_sets/contributions/valid](https://github.com/ehrbase/ehrbase/tree/develop/tests/robot/_resources/test_data_sets/contributions/valid)

If I remember correctly there were still some variations between the serializations. This should hopefully be resolved and completely standardized. Hope this helps!

---

<div class="post-metadata">

### Author: ![surfer](https://discourse.openehr.org/user_avatar/discourse.openehr.org/surfer/32/2326_2.png) [@surfer](https://discourse.openehr.org/u/surfer)
#### Post date: [20 January 2021 20:27 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/7 "2021-01-20T20:27:52Z")

</div>

yeah. It sure helps. thanks  
And the parameters and headers are the ones in [https://specifications.openehr.org/releases/ITS-REST/latest/ehr.html#contribution](https://specifications.openehr.org/releases/ITS-REST/latest/ehr.html#contribution) , aren’t they?

---

<div class="post-metadata">

### Author: ![jake.smolka](https://discourse.openehr.org/user_avatar/discourse.openehr.org/jake.smolka/32/2870_2.png) [@jake.smolka](https://discourse.openehr.org/u/jake.smolka)
#### Post date: [21 January 2021 15:15 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/8 "2021-01-21T15:15:44Z")

</div>

Hey @surfer!

Here’s a working example from our integration tests to get you started, if it didn’t work out yet.

Precondition: Create an EHR and remember the `EHR_ID`.

To get EHRbase prepared for this example contribution and the compositions it contains you first need to upload the required template. Create a POST request to `http://localhost:8080/ehrbase/rest/openehr/v1/definition/template/adl1.4` and set the headers

- `Content-Type` = `application/xml` because the body payload will be XML.
- `prefer` = `return=representation` if you want the uploaded template directly returned to you.

Add the following body payload to the request:  
[obs\_eva.en.v1.xml](https://discourse.openehr.org/uploads/short-url/iD9wFTGSX7JhfkNP8ror7CjTKwU.xml) (17.2 KB)

Execute the request. The response should have a `201 Created` status and the template as body.

(Note: This step obviously depends on the content of the contribution. For instance, if a contribution modifies an EHR\_STATUS objects no specific template is required. If it adds or modifies a different kind of composition the matching template is required, instead of the one I provided.)

For the contribution itself:

Create a `POST` request pointing at the endpoint URI `http://localhost:8080/ehrbase/rest/openehr/v1/ehr/{{ehrId}}/contribution`.

The following headers are important

- `Content-Type` = `application/json` because the body payload is json.
- `prefer` = `return=representation` if you want the created objects directly returned to you.

Add the following body payload to the request:  
[request-body-payload.json](https://discourse.openehr.org/uploads/short-url/g7xhhqejyzk7RtOrg53Z6rAo1GO.json) (15.5 KB)

This example contains two compositions, which should now be successfully created, after executing the request. The response should have a `201 Created` status and an overview of the objects in the body.

Hope this helps you getting started!

---

<div class="post-metadata">

### Author: ![surfer](https://discourse.openehr.org/user_avatar/discourse.openehr.org/surfer/32/2326_2.png) [@surfer](https://discourse.openehr.org/u/surfer)
#### Post date: [22 January 2021 07:57 UTC](https://discourse.openehr.org/t/contribution-in-general-and-how-to-post-them-in-ehrbase/1241/9 "2021-01-22T07:57:32Z")

</div>

thank you. it should help a lot indeed
