# How many FOLDER trees can be associated with the same EHR
**Category:** [RM](https://discourse.openehr.org/c/rm/42)
**Created:** 2024-09-27 09:39 UTC
**Views:** 148
**Replies:** 16
**URL:** https://discourse.openehr.org/t/how-many-folder-trees-can-be-associated-with-the-same-ehr/5754
---
## Post #1 by @linforest
How many FOLDER trees can be associated with the same EHR at the same time?
In other words, *EHR 0..1 FOLDER_tree* OR *EHR 0..n FOLDER_tree*?
[Figure 20. High-level Structure of the openEHR EHR](https://specifications.openehr.org/releases/BASE/latest/architecture_overview.html#_the_ehr)

This figure seems to imply a single EHR could have more than one folder trees at the same time.
For an EHR already having a Directory FOLDER, when trying to POST an second FOLDER tree JSON to EHRBase Server via openEHR Tool, I got the following error (409):
```
{"error":"Conflict","message":"EHR with id 80a71040-3d37-42f3-a86a-ce5405138ce0 already contains a directory."}
```

---
## Post #2 by @thomas.beale
You can [see here](https://specifications.openehr.org/releases/RM/development/UML/diagrams/RM-ehr.svg) that `EHR.folders` has cardinality `*`.
---
## Post #3 by @stefanspiska
The directory endpoint access the directory of the ehr which is the first folder :
https://specifications.openehr.org/releases/RM/development/ehr.html#_ehr_class
" **directory**: Optional directory structure for this EHR. If present, this is a reference to the first member of `folders` ."
---
## Post #4 by @linforest
Thank you very much, @thomas.beale and @stefanspiska. Forgive me please. Honestly, I'm still confused about: What kind of folder hierarchy a single EHR can have, i.e., mono-/multi-hierarchy? What is the relationship between directory and folders? Two separate but related attributes of the EHR class? Or is Directory just a synonym of the very first folder (root) in the first folder tree? Especially the cardinality of the attribute *folders*, **0..1**, looks strange for me.

Now I can understand the 409 error above because I was trying to POST a second directory, violating its cardinality *0..1*. Am I correct?
---
## Post #5 by @stefanspiska
Directory is just a reference to folders[0]
So post Directory is create folders[0] which gives you an error if already exist.
I belive at one time only Directory existed and folders was added late and then Directory became simple folders[0] die first element in the list.
---
## Post #6 by @linforest
[quote="stefanspiska, post:5, topic:5754"]
Directory is just a reference to folders[0]
[/quote]
Thanks, @stefanspiska. I see, it's a reference relationship.
For **folders[0]**, the index **[0]** means threre can exist more than one folder tree side-by-side?
---
## Post #7 by @linforest
Another confusing stuff for me is: there is no POST /Update/Delete operations for folders on the openEHR Tool UI:
```
Directory
```
---
## Post #8 by @sebastian.garde
[quote="linforest, post:4, topic:5754"]
Especially the cardinality of the attribute *folders*, **0…1**, looks strange for me.
[/quote]
I think you find this strange because what you have circled is NOT the cardinality, but just the existence (or occurrences) of the *folders* attribute, i.e. *folders* may or may not exist (aka is optional).
Then, *if* it exists, the *cardinality* of the folders List is *, i.e. the folders List can contain any number of OBJECT_REFs (each pointing to the root of a Folder structure, with the first member being the "directory").
Hope this clarifies this bit.
---
## Post #9 by @linforest
[quote="sebastian.garde, post:8, topic:5754"]
NOT the cardinality, but just the existence (or occurrences) of the *folders* attribute
[/quote]
Indeed, I was confusing the two attributes of the EHR class with the "physical" folder structures.
@sebastian.garde Thanks a lot for your clarification.
---
## Post #10 by @thomas.beale
[quote="linforest, post:4, topic:5754"]
Now I can understand the 409 error above because I was trying to POST a second directory, violating its cardinality *0…1*. Am I correct?
[/quote]
That 0..1 means optionality, not cardinality. It means there could be not even a folders container. if there is something there, it is a List, which is a container, i.e. 0..* items.
---
## Post #11 by @sebastian.iancu
Some other useful info: the EHR.folders was added in RM 1.1.0, previously we only had EHR.directory. The REST specs is lagging behind, as it does not have yet operation for folders. What you see there ion EHRbase is just the REST for directory “resource”. This missing piece of specs is anyway planned to be addressed soon, and hopefully it will be also supported by CDRs.
---
## Post #12 by @linforest
It gets vividly clearer and more interesting. Thank you so much, @thomas.beale and @thomas.beale.
---
## Post #13 by @Lucas
Interesting post and very helpful, as I am still struggling to understand how folders can be used in openEHR, and now I also know why there is no REST API call for such folders.
I am curious to learn how **"administrative cases"** and **"medical episodes"** are managed in openEHR. Here are the definitions of both terms for context:
* **Administrative Case**: This organizes a patient's medical treatment from an administrative viewpoint. It includes multiple hospitalizations or outpatient treatments at different times that are grouped under a single administrative case for billing, insurance, or other management purposes.
* **Medical Episode**: This organizes a patient's medical treatment from a clinical perspective. It may include various hospitalizations or outpatient treatments, potentially spread across different administrative cases, but grouped based on a specific clinical condition or treatment process.
---
## Post #14 by @Colin_Sutton
These would be AQL queries providing details for a report that will update as the case or episode progresses. Could they have a generic structure?
---
## Post #15 by @Lucas
I hope, that I interpreted your answer as a response to my post :sweat_smile:
Based on your insight, this means, that the organization of administrative cases and medical episodes need to be managed in the application using predefined AQL queries (logic layer) and not at the openEHR using associations or tags (persistence level).
Can you tell me, if I did understand your insight correctly?
---
## Post #16 by @stefanspiska
@Lucas
Folders allow grouping of Composition into logical groups so yes you could use that to modele say a episode of care see: https://discourse.openehr.org/t/representation-of-episodes-of-care-and-encounters-in-folders/226
---
## Post #17 by @linforest
On the Spec page for the [EHR Model](https://specifications.openehr.org/releases/RM/latest/ehr.html#:~:text=The%20folders%20structures%20can%20be%20used%20in%20the%20EHR%20to), there is a [figure](https://specifications.openehr.org/releases/RM/latest/ehr/diagrams/folders_for_indexing.svg) that shows examples for using folders to organize episode data.

---
**Canonical:** https://discourse.openehr.org/t/how-many-folder-trees-can-be-associated-with-the-same-ehr/5754
**Original content:** https://discourse.openehr.org/t/how-many-folder-trees-can-be-associated-with-the-same-ehr/5754