Nelly-Barret / BETTER-fairificator

The fairification tools for BETTER project.
https://www.better-health-project.eu/
0 stars 0 forks source link

Generate FHIR profiles from Python classes? (not Python classes from FHIR profiles) #32

Open Nelly-Barret opened 3 weeks ago

Nelly-Barret commented 3 weeks ago

When building a relational database, we usually:

  1. Design the conceptual model
  2. Transform the conceptual model in a logical model (PK/FK, tables for 0..n, etc)
  3. A software transforms the logical to a physical model (SQL script)
  4. The physical model is used to create a new database
  5. We design classes in whather language (Java, PHP, Python) reflecting the entities and relationships of the conceptual/logical models
  6. We insert data in the database with the help of the classes (which should match/reflect the logical/physical model)

For now, whenever I want to change something (an attribute, a type, etc) in the data model, I have to update the model it in many places:

Therefore, it is very hard to maintain all those "data models" (drawings, classes, UML, etc) up-to-date in all places.

One first thing could be to extract/get the physical model from the database itself, e.g., with the PyCharm database view

Now, the thing is to understand how to easily go from one another for the logical model, the Python classes and the FHIR entities.

With such a "transformator(FHIR profiles) -> conceptual model", we could change something in the FHIR profiles and immedialtely get the logical+physical models and even maybe the Python classes.

Nelly-Barret commented 3 weeks ago

After some thinking, it appears that there is no way to transform FHIR profiles to an MCD/MLD because (i) they need to be on a FHIR server to have access to the "original" resource types before applying the profiles, and (ii) FHIR is a standard, not a data model.

My current idea is to:

  1. Design, in an MD/MLD, the FHIR resource types that we need, i.e., Patient, Organization, Observation, etc. They will, in any case, not change.
  2. Apply some changes to create our own data model based on the model provided in 1.
  3. Generate a set of validation rules (https://www.mongodb.com/docs/manual/core/schema-validation/?utm_source=compass&utm_medium=product) to be used in MongoDB to ensure that inserted resource instances conform to our data model and prevent missing/added attributes/types in the Python classes representing the data model
  4. After all, when the data model does not change anymore, create the FHIR profiles based on what is in the data model and use that in the hospitals' FHIR servers.
Nelly-Barret commented 2 weeks ago

I think I need to go the other way around, i.e., generate the FHIR profiles from my Python classes. It seems that I can:

  1. Download the FHIR resources as JSON, as in https://build.fhir.org/observation.profile.json.html
  2. Get the list of class members in my Python classes
  3. Do the diff by:
    • set the cardinality min and max to 0 if the FHIR attribute is not present in the Python class
    • create extensions for each Python attribute which is not present in the (FHIR) JSON