When I tried to delete specified opt template,
ehrbase-260-ehrbase-1 | 2024-08-22 07:19:10.689
WARN [traceId=4d0a8ac1882d3349] 1 --- [io-8080-exec-21] o.e.c.exception.DefaultExceptionHandler :
Cannot delete template XXXX since it is used by at least one composition
So, how to find all the compositions using a specified opt template?
AQL should identify
SELECT
c/uid
FROM
EHR e
CONTAINS COMPOSITION c
WHERE
c/archetype_details/template_id = 'My template'
but there is also some Ehrbase .env lines that might help (not tested)
SYSTEM_ALLOW_TEMPLATE_OVERWRITE=true
ADMINAPI_ALLOWDELETEALL=true
1 Like
Great! Thanks, Ian. I’ll give it a try.
Got a 400 error:
Query run failure.
status_code=400
headers={'Vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '0', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Frame-Options': 'DENY', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 22 Aug 2024 07:59:39 GMT', 'Connection': 'close'}
text={"error":"Bad Request","message":"Not implemented: WHERE: path archetype_details/template_id only targets types that are not derived from DV_ORDERED and not primitive"}
Its /archetype_details/template_id/value
/archetype_details/template_id/ is the path to a Object of class TERMINOLOGY_ID (Base Types)
which has an attribute value which is a STRING
you can only put into a where paths which point to DV_ORDERED or primitive
which is what the error message tells you
1 Like
Thanks a lot, Stefanspiska.
The query give a 200.
The ResultSet is empty but the template still can’t be deleted.
{
"columns": [
{
"name": "#0",
"path": "c/uid"
}
],
"meta": {
"_created": "2024-08-22T09:01:39.657636485Z",
"_executed_aql": "SELECT c/uid FROM EHR e CONTAINS COMPOSITION c WHERE c/archetype_details/template_id/value = 'My Template Id'",
"_schema_version": "1.0.3",
"_type": "RESULTSET",
"resultsize": 0
},
"q": "SELECT c/uid FROM EHR e CONTAINS COMPOSITION c WHERE c/archetype_details/template_id/value = 'My Template Id'",
"rows": []
}
Finally, I had to delete the template (actually without any Composition instance) by SQL:
DELETE FROM ehr.template_store WHERE id='3c6e......';
@linforest In your example you posted “My Template ID”. Is this actually your template ID or is this something you overlooked to change in the AQL query?
Another thing: if you are not deleting the compositions through the Admin API, the compositions will only be “soft deleted”, which means they are persevered in the database and the references will still be around. This is desired system behavior most of the time (to ensure a complete audit trail and append-only database behavior) but will prevent you from deleting the template.
No, it’s only a placeholder for the actual template Id.
I see. I’ll re-create some demo data to familiarize myself with these features further. Thank you so much for your guidance!