How to retrieve ehrid in ehrbase

Supposedly I created an ehr and posted several compositions how do I retrieve the ehrid ?

From the openehr api I see only the method "get ehr summary from subject_id and subject_namespace " (https://specifications.openehr.org/releases/ITS-REST/latest/ehr.html#ehr-ehr-get-1) but I tested it in ehrbase and received:
{“error”:“No EHR with supplied subject parameters found”,“status”:“Not Found”}

while In the docker console it’s written:
org.ehrbase.dao.access.jooq.EhrAccess : Could not retrieve EHR for party:null

maybe @birger.haarbrandt you can answer that?

See the REST API create EHR call - you will get an EHR_STATUS back, containing the id.

if I use the rest create ehr (the post method you linked) I get a new ehrid every time I call it
example
first call:
{‘Vary’: ‘Origin, Access-Control-Request-Method, Access-Control-Request-Headers’, ‘Location’: ‘http://ab24ef12f672:8080/ehrbase/rest/openehr/v1/ehr/66739727-34f5-4a0e-b25b-765875dcb24e’, ‘ETag’: ‘“66739727-34f5-4a0e-b25b-765875dcb24e”’, ‘Last-Modified’: ‘Fri, 02 Jan 1970 10:12:04 GMT’, ‘X-Content-Type-Options’: ‘nosniff’, ‘X-XSS-Protection’: ‘1; mode=block’, ‘Cache-Control’: ‘no-cache, no-store, max-age=0, must-revalidate’, ‘Pragma’: ‘no-cache’, ‘Expires’: ‘0’, ‘X-Frame-Options’: ‘DENY’, ‘Date’: ‘Wed, 07 Oct 2020 10:17:46 GMT’, ‘Keep-Alive’: ‘timeout=60’, ‘Connection’: ‘keep-alive’}

second time:
{‘Vary’: ‘Origin, Access-Control-Request-Method, Access-Control-Request-Headers’, ‘Location’: ‘http://ab24ef12f672:8080/ehrbase/rest/openehr/v1/ehr/15be4e0c-e2f4-4c9b-a9b5-3bf31b11b103’, ‘ETag’: ‘“15be4e0c-e2f4-4c9b-a9b5-3bf31b11b103”’, ‘Last-Modified’: ‘Fri, 02 Jan 1970 10:12:04 GMT’, ‘X-Content-Type-Options’: ‘nosniff’, ‘X-XSS-Protection’: ‘1; mode=block’, ‘Cache-Control’: ‘no-cache, no-store, max-age=0, must-revalidate’, ‘Pragma’: ‘no-cache’, ‘Expires’: ‘0’, ‘X-Frame-Options’: ‘DENY’, ‘Date’: ‘Wed, 07 Oct 2020 10:19:57 GMT’, ‘Keep-Alive’: ‘timeout=60’, ‘Connection’: ‘keep-alive’}

are those alias of the first ehrid*? is it meant to work this way?

*with first ehrid I mean the ehrid I obtained the first time I created an ehr with that specified subject_id and subject_namespace

Each call to ‘create ehr’ is indeed intended to create a new EHR :slight_smile:

Can you post the call you are making - did you remember to set the subject namespace in both this call and the original CreateEHR call

curl --location --request GET 'http://18.132.59.3:65535/ehrbase/rest/openehr/v1/ehr?subject_id=99999990000001&subject_namespace=uk.nhs.nhs_number' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \

--header 'Authorization: Basic XXXX' \
--data-raw ''

CreateEHR call (uk.nhs.number is the namespace I use);

curl --location --request POST 'http://18.132.59.3:65535/ehrbase/rest/openehr/v1/ehr' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'PREFER: representation=minimal' \
--header 'Authorization: Basic XXX' \
--data-raw '{
  "_type": "EHR_STATUS",
  "subject": {
    "external_ref": {
      "id": {
        "_type": "GENERIC_ID",
        "value": "99999990000001",
        "scheme": "uk.nhs.nhs_number"
      },
      "namespace": "uk.nhs.nhs_number",
      "type": "PERSON"
    }
  },
  "is_modifiable": "true",
  "is_queryable": "true"
}'

Probably I didn’t explain it very well.
Let’s say I have a patient named patient1 (subject_id) in my environment crs4(subject_namespace) and I create an ehr for that patient and post some compositions. Later I want to add more compositions and I need the ehrid to do it. I don’t want to create multiple ehrids for the same person.
So how can I retrieve the previously created ehrid ?

That’s it above - can you post your code / curl call if it is still not working?

1 Like

Yes Ian:
I use python notebooks to do my tests. So the code for the ehr creation (that goes well) is:
myparams= {‘subject_id’:‘patient1’,‘subject_namespace’:‘CRS4’}
ehrs = client.post(EHR_SERVER_BASE_URL + ‘ehr’, params=myparams)

when I want to retrieve the erhid from the subject_id and subject_namespace the call is:
myparams={‘subject_id’:‘patient1’,‘subject_namespace’:‘CRS4’}
ehrs = client.get(EHR_SERVER_BASE_URL + ‘ehr’, params=myparams)

so basically the same call with get instead of post. But the latter fails as I reported in the firs post.

You need to pass the subjectID and namespace in the original POST body, not as parameters.

{
  "_type": "EHR_STATUS",
  "subject": {
    "external_ref": {
      "id": {
        "_type": "GENERIC_ID",
        "value": "{{subjectId}}",
        "scheme": "{{subjectNamespace}}"
      },
      "namespace": "{{subjectNamespace}}",
      "type": "PERSON"
    }
  },
  "is_modifiable": "true",
  "is_queryable": "true"
}

I suspect the second use of namespace is redundant/wrong!

As always You are right Ian !!!
I did as you told and it works. I just had to add, with respect to your POST body, name and archetype_node_id.
thanks

1 Like