FHIR Resource Schema/Spec - hl7-fhir

How to get one single FHIR Schema for a Resource with all the parent and child attributes in the schema. When I looked into the FHIR Schema, it has lot of child Schemas inside each resource Schema, The Schema is defined at a entity level and not at a Resource level, A Resource is made of multiple child Schemas.
For Ex :
For Patient Resource, We have Patient.Schema under Patient.Schema we have HumanName.Schema.
Is there a Tool or Utility, that is available readily to build a JSON Specification at a Resource level from this multiple Parent and Child schema for a Resource ?
Or can we get a Resource JSON with all the available attributes (both parent and child attributes), So that we can build our own json schema from it ?

Related

Spring data JPA save() return less/incorrect child and parent association mapping fields [duplicate]

I'm developing a RESTful webservice with spring-data as its data access layer, backed by JPA/Hibernate.
It is very common to have relationships between domain entities. For example, imagine an entity Product which has a Category entity.
Now, when the client POSTs a Product representation to a JAX-RS method. That method is annotated with #Transactional to wrap every repository operation in a transaction. Of course, the client only sends the id of an already existing Category, not the whole representation, just a reference (the foreign key).
In that method, if I do this:
entity = repository.save(entity);
the variable entity now has a Category with only the id field set. This didn't surprise me. I wasn't expecting a save (SQL insert) to retrieve information on related objects. But I need the whole Product object and related entities to be able to return to the user.
Then I did this:
entity = repository.save(entity);
entity = repository.findOne(entity.getId());
that is, retrieve the object after persisting it, within the same transaction/session.
To my surprise, the variable entity didn't change anything. Actually, the database didn't even get a single select query.
This is related with Hibernate's cache. For some reason, when in the same transaction, a find does not retrieve the whole object graph if that object was previously persisted.
With Hibernate, the solution appears to be to use session.refresh(entity) (see this and this). Makes sense.
But how can I achieve this with spring data?
I would like to avoid to create repetitive custom repositories. I think that this functionality should be a part of spring data itslef (Some people already reported this in spring data's forum: thread1, thread2).
tl;dr
References between entities in the web layer need to be made explicit by using links and should not be hidden behind semi-populated object instances. References in the persistence layer are represented by object references. So there should be a dedicated step transforming one (the link) into the other (the fully populated object reference).
Details
It's an anti-pattern to hand around backend ids as such and assume the marshaling binding doing the right thing. So the clients should rather work with links and hand those to the server to indicate they want to establish a connection between an already existing resource and one about to be created.
So assuming you have the existing Category exposed via /categories/4711, you could post to your server:
POST /products
{ links : [ { rel : "category", href : "/categories/4711" } ],
// further product data
}
The server would the instantiate a new Product instance, populate it with additional data and eventually populate the associations as follows:
Identify properties to be populated by looking up the link relation types (e.g. the category property here.
Extract the backend identifier from the given URI
Use the according repository to lookup the related entity instance
Set it on the root entity
So in your example boiling down to:
Product product = new Product();
// populate primitive properties
product.setCategory(categoryRepository.findOne(4711));
productRepository.save(product);
Simply posting something like this to the server:
POST /products
{ category : {
id : 1, … },
…
}
is suboptimal for a lot of reasons:
You want the persistence provider to implicitly persist a Product instance and at the same time 'recognize' that the Category instance referred to (actually consisting of an id only) is not meant to be persisted but updated with the data of the already existing Category? That's quite a bit of magic I'd argue.
You essentially impose the data structure you use to POST to the server to the persistence layer by expecting it to transparently deal with the way you decided to do POSTs. That's not a responsibility of the persistence layer but the web layer. The whole purpose of a web layer is to mitigate between the characteristics of an HTTP based protocol using representations and links to a backend service.

Api Resource with multiple version of same model

If I need to have two different version (say one with name & id and another with name, id, xyz etc) of API Resource for the same model, do I need to create two different Resources for the same model? I can only see one method toArray() inside an API Resource.

GraphQL filtering based on parent context

I've read the docs and I cannot seem to figure out how to structure my GraphQL for a particular query. For my data I have:
child
|_ school
|_ class
A child has schools and schools have classes, but a child is only assigned to specific classes in a school.
I want to query a specific child to get only the classes they are in.
query={
child(id:$id){
schools{
name
classes{
name
}
}
}
}
I can technically filter the classes while resolving the schools field in the child type by looking deep down the fields but I wanted to clarify that this is still conforming to GraphQL. Should I be placing the classes as a field in the child type instead?
A child also have classes, so it makes sense to create a classes field in the child object. This, in addition to the classes field in the school object.
Of course you could also filter the classes while resolving it but it's just another extra work with no particular reason.
Since there is a direct relationship between a child and his classes it seems better for a child to have a classes field.

Core Data cross storage fetched property

I'm currently wrapping my head around some problem with Core Data.
I have one user model in its own store that I do not have any control over, as it gets shipped with a framework. A Persistent Store Coordinator, Managed Object Model and Context for this model gets created automatically and cannot be touched. In it, this model has a single user entity
On the other hand, I have a properties model with a properties entity in it that I have complete control over. In there I store properties for some user entities in the other store. Both user and property entities have an id attribute similar to a foreign key.
This model has it's own Persistent Store Cordinator, Managed Object Model and Context.
What I now want is to have the associated user entity as an attribute of the properties entity so I might be able to bind to key-paths similar to myproperty.user.someValueOfTheUserEntity (I'm aware that myproperty might be an array when using fetched properties).
However, as cross-store relationships are not supported I thought of using a weak relationship via Fetched Properties. That one would just have to match the two corresponding id attributes. I have created a Fetched Property for the user in Xcode and the required accessors in my properties entity's class file (As suggested in other questions, I'm treating the values returned by the Fetched Property as an array).
However, I'm unable to set a destination entity for the Fetched Property in Xcode, as the target entity resides in a completely different store. Would I also have to define my user entity in the properties store? If so, how does Core Data know that that entity shall be fetched not from my properties store but from the users store?
Some threads mentioned using configurations for this, but I cannot find any documentation that goes further than mentioning "use configurations for this".
Can somebody enlighten me on how to set up cross-storage fetched properties? #
You can use several persistent stores that share the same data model:
Use single data model (xcdatamodeld) and add all your entities
Create configurations (Editor/Add Configuration) for each "logical set" of
entities that should be stored in separate store file
Assign (Drag) entities to appropriate configurations
Add configured persistent stores to your context (see below)
Configure fetched properties
// 1. Add "static", read-only store
[coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:#"your static configuration name goes here..."
URL:storeUrl
options:#{
NSReadOnlyPersistentStoreOption: #(YES),
NSInferMappingModelAutomaticallyOption : #(YES)
}
error:&error];
// 2. Add "dynamic", writable content
[coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:#"your dynamic configuration name goes here..."
URL:storeUrl
options:#{
NSMigratePersistentStoresAutomaticallyOption: #(YES),
NSInferMappingModelAutomaticallyOption : #(YES)
}
error:&error];

How do I map two entities in ColdFusion ORM that are in different schemas?

I have two tables that exist in the same Oracle database system but different schemas, which I've mapped like this:
ABC.Store:
component schema="ABC" table="Stores"
{
property name="Id" fieldtype="id" generator="sequence" sequence="store_id_seq";
property name="Products" fieldtype="one-to-many" cfc="Product";
}
DEF.Product:
component schema="DEF" table="Products"
{
property name="Id" fieldtype="id" generator="sequence" sequence="product_id_seq";
}
I set my application's default datasource as this.datasource = "ABC" in application.cfc.
The problem I'm running into here is whenever I try to save a Product. ColdFusion spits out an error that says the sequence cannot be found for the Id property on Product. This is because the product_id_seq sequence is in the DEF schema, but ColdFusion is trying to find it in the ABC schema, even though I set the schema on the Product as DEF.
If I set the datasource attribute on Product to DEF, I then get an error that says the Products property on Store is unmapped. This is because, as the ColdFusion documentation states:
"Since a Hibernate configuration uses a single data source, all related CFCs (using ORM relationships) must have the same data source."
My question then is, how do I map the two tables in two different schemas, using a sequence as an ID generator?
I've been able to get it to work if I specify the schema for the sequence:
property name="Id" fieldtype="id" generator="sequence" sequence="def.product_id_seq";
But this is hard-coded and I'd like it to be dynamic and pull the schema name from a configuration bean.
The only way I've been able to get this to work seamlessly was to:
Create a single user in database, in this case MySQL, that had access to the desired schemas.
Setup and configure a single datasource in CFIDE that utilizes the newly created user for authentication.
Set the datasource attribute in all desired persistent objects to the newly created datasource.
Set the schema attribute in all desired persistent objects to reference the correct schema, or database. (the two are synonymous in ColdFusion ORM)
Note: Be sure to use full component path when referencing CFCs in your COM.

Resources