I can't do a valid body to "Create CONTRIBUTION" of EHR API

I have this body:

{
“uid”: {
“value”: “6eb91861-faa9-4989-a811-078f674d570a”
},
“versions”: [
{
“_type”: “VERSIONED_COMPOSITION”,
“lifecycle_state”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “532”
},
“data”: {
“_type”: “COMPOSITION”,
“name”: {
“_type”: “DV_TEXT”,
“value”: “alex”
},
“archetype_node_id”: “openEHR-EHR-COMPOSITION.encounter.v1”,
“language”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “en”
},
“territory”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “ES”
},
“category”: {
“_type”: “DV_CODED_TEXT”,
“value”: “animal”,
“defining_code”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “433”
}
},
“context”: {
“start_time”: {
“_type”: “DV_DATA_TIME”,
“value”: “2023-02-16T11:14:29.007Z”
},
“setting”: {
“_type”: “DV_CODED_TEXT”,
“value”: “Primària”,
“defining_code”: {
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “228”
}
}
},
“composer”: {
“_type”: “PARTY_IDENTIFIED”,
“name”: “Joan”
},
“content”:
},
“commit_audit”: {
“_type”: “AUDIT_DETAILS”,
“change_type”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “249”
},
“committer”: {
“_type”: “PARTY_SELF”
}
}
}
],
“audit”: {
“_type”: “AUDIT_DETAILS”,
“change_type”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “249”
},
“committer”: {
“_type”: “PARTY_SELF”
}
}
}

Anyone can find or knows what kind of error are maybe happening?

PD: In POSTMAN this petition returns 500 Internal Server Error.

Thanks!

Doing another try, I found this response:

Body:
“versions”: [{“_type”:“VERSIONED_EHR_STATUS”, “lifecycle_state”:{“terminology_id”:“22”, “code_string”:“complete”}, “data”:{“_type”:“EHR_STATUS”, “name”:“A user name”, “archetype_node_id”:“22”, “subject”:{“_type”:“PARTY_SELF”, “external_ref”:{“_type”:“PARTY_REF”,“namespace”:“PARTY”,“type”:“PARTY3”,“id”:{“_type”:“GENERIC_ID”,“value”:“31”, “shceme”:“NEW”}}, “is_queryble”:“true”, “is_modifiable”:“true”}},“commit_audit”:{“_type”:“UPDATE_AUDIT”,“change_type”:{“terminology_id”:“22”,“code_string”:“modification”,“commiter”:{“_type”:“PARTY_SELF”, “external_ref”:{“_type”:“PARTY_REF”,“namespace”:“PARTY”,“type”:“PARTY3”,“id”:{“_type”:“GENERIC_ID”,“value”:“31”, “shceme”:“NEW”}}, “is_queryble”:“true”, “is_modifiable”:“true”}}}}],
“audit”: {
“_type”: “AUDIT_DETAILS”,
“change_type”: {
“value”: “creation”,
“defining_code”: {
“terminology_id”: “openehr”,
“code_string”: “249”
}
},
“description”: “Description text”,
“committer”: {
“_type”: “PARTY_IDENTIFIED”,
“name”: “A user name”
},
“time_committed”: {
“_type”: “DV_DATE_TIME”,
“value”: “2023-02-16T11:01:54Z”
},
“system_id”:“22”
}
}

Response:
{ “error”: “Bad Request”, “message”: “Wrong input. At least one VERSION in this contribution is invalid.”}

Why it’s not a valid VERSION?

Thanks!

Hi Miguel,

Which CDR are you using? Also, It is pretty unusual to create an EHR Contribution. Can you provide the whole API call as a curl ?

I can see a typo in your JSON e.g. is_queryble → is_queryable

Thanks for your response. I corrected the queryable error, but nothing new.
I’m using Postman and I do not know how find the url of the API.

This is the url of the API’s specification, EHR API: EHR API openEHR specs
You can download API from this url.

Thanks another time!

Are you trying to create a new EHR object i.e register a patient with the CDR? Again, please tell us which CDR you are using, as there are occasionally some subtle differences

If so, you should not be using the CONTRIBUTION call (that is for multiple Compositions) but the Create EHR call

In Postman, to generate a cURL copy of the call you ate making - press the </> button on the right hand menu, and select cURL - (make sure you remove anys cred before you post!.

I’m using EHRBase, I think this is the CDR. I don’t know what does it mean “cred”, can you explain me pls?

Thanks!!

Sorry cred = credentials username, password!!

What is it that you are actually trying to do?

I’m trying to create a simple Contribution, maybe with any content.
This is the cURL without cred:

–header ‘Prefer: return=representation’
–header ‘Content-Type: application/json’
–header ‘Accept: application/json’
–data ‘{
“uid”: {
“value”: “6eb91861-faa9-4989-a811-078f674d570a”
},
“versions”: [
{
“_type”: “VERSIONED_COMPOSITION”,
“lifecycle_state”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “532”
},
“data”: {
“_type”: “COMPOSITION”,
“name”: {
“_type”: “DV_TEXT”,
“value”: “alex”
},
“archetype_node_id”: “openEHR-EHR-COMPOSITION.encounter.v1”,
“language”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “en”
},
“territory”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “ES”
},
“category”: {
“_type”: “DV_CODED_TEXT”,
“value”: “animal”,
“defining_code”: {
“_type”: “CODE_PHRASE”,
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “433”
}
},
“context”: {
“start_time”: {
“_type”: “DV_DATA_TIME”,
“value”: “2023-02-16T11:14:29.007Z”
},
“setting”: {
“_type”: “DV_CODED_TEXT”,
“value”: “Primària”,
“defining_code”: {
“terminology_id”: {
“_type”: “TERMINOLOGY_ID”,
“value”: “openehr”
},
“code_string”: “228”
}
}
},
“composer”: {
“_type”: “PARTY_IDENTIFIED”,
“name”: “Joan”
},
“content”:
},
“commit_audit”: {
“_type”: “AUDIT_DETAILS”,
“change_type”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “249”
},
“committer”: {
“_type”: “PARTY_SELF”
}
}
}
],
“audit”: {
“_type”: “AUDIT_DETAILS”,
“change_type”: {
“_type”: “TERMINOLOGY_CODE”,
“terminology_id”: “openehr”,
“code_string”: “249”
},
“committer”: {
“_type”: “PARTY_SELF”
}
}
}’

Should be DV_DATE_TIME

If you are trying to commit or update a single composition, it is much easier to use the POST o r PUT / composition call (it creates a Contribution wrapper for you)

You also need to define a templateId as otherwise the CDR does not know what to validate your composition against.

So back to the question !!

Are you trying to

  1. Create a new composition?
  2. Update an existing composition?

It is actually very unsusal to need to create or work with Contributions directly.

In any case you need to define the target templateId and have that template uploaded to the CDR, even if as in your case, there is no actual content defined.

Thanks for the correction :slight_smile:

I know that it’s more easier to upload a composition using its POST and its PUT, but I’m trying and practising with Contributions now. This is why i need to create a minimal Contribution.

Can you send me a complete example to create one?

PD: I want to create a new Composition with this Contribution.

Thanks!!!

So start with getting the composition to commit via POST, to check you have that structure correct - you are definitely missing the templateId.

and the template itself needs to be registered with the CDR via Upload template.

Ok, thanks for your time!!!

I will try this.

Thanks for all.

If you are still having problems, p[lease share the template .opt file, and the Composition json here as otherwise it is impossible for us to check.

You might find @pablo 's openEHR Toolkit helpful for testing the structures. https://toolkit.cabolabs.com/

1 Like

It’s difficult to create examples by hand, as Ian said, you can use the openEHR Toolkit online or the SDK locally GitHub - ppazos/openEHR-OPT: Java/Groovy Support of openEHR Operational Templates, Refernce Model, Data Generators and other tools for www.CaboLabs.com projects

It takes a valid OPT and tries to generate a valid JSON or XML instance based on that OPT. Then you can commit the generated document. In some cases you would need minimal changes, in most cases it works directly with the generated document.

Note the SDK also has parsers so you can load the documents and manipulate them in memory by code.