Database Fhir model and hapi-fhir-jpaserver-example

2,744 views
Skip to first unread message

Domenico Martino

unread,
Oct 5, 2015, 4:19:52 AM10/5/15
to HAPI FHIR
Hi,
I wanto to use Fhir standard for one of my project.
I would like to know if with the database of hapi-fhir-jpaserver-example I can store all the information of all Fhir resources.

Thank you very much.

Bests Regards,
Domenico

James Agnew

unread,
Oct 5, 2015, 8:53:08 AM10/5/15
to Domenico Martino, HAPI FHIR
Hi Domenico,

Yup, the JPA server will store and index all resources that are a part of FHIR DSTU2.

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/7faffb89-6f9f-4bcf-a50c-c702b4dea845%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dom

unread,
Oct 5, 2015, 8:59:54 AM10/5/15
to HAPI FHIR, martinod...@gmail.com
But in the database of hapi-fhir-jpaserver-example there is not a table for every resource of FHIR DSTU2.
I don't understand how it's possible to store all the attributes of every FHIR DSTU2 resource.

James Agnew

unread,
Oct 5, 2015, 9:06:54 AM10/5/15
to Dom, HAPI FHIR
Hi Dominico,

The design of the JPA module is based around storing the resources as document blobs, not as individual columns in tables. As such, we are able to store all of the resources in a single table. It is the index tables (HFJ_SPIDX_*) that are the important part which makes it actually work.

Cheers,
James


Dom

unread,
Oct 5, 2015, 9:41:32 AM10/5/15
to HAPI FHIR, martinod...@gmail.com
Dear James Agnew,
thank you so much for your help. I'm new of Fhir and Hapi and for this reason I have not yet experienced.
I need your advice: I have a database of the health facility and I want to design a JPA module (with HAPI), how should I proceed? I should create a table for every FHIR DSTU2 or storing the resources as document blobs as made in  hapi-fhir-jpaserver-example.

Best regards,
Domenico

Dom

unread,
Oct 5, 2015, 11:03:13 AM10/5/15
to HAPI FHIR, martinod...@gmail.com
Dear James Agnew,
I have some curiosity:
1) What is the advantage of storing the resources as document blobs in the JPA module and not as a classic JPA module (with a table for every FHIR-DSTU2 resource)?
2) If I change the reference implementation using a JPA module without blobs, can I still use the HAPI library?

I am very interested in logic used in HAPI.

Thank you very much!

Best regards,
Domenico

Lars Kristian Roland

unread,
Oct 6, 2015, 11:52:26 AM10/6/15
to HAPI FHIR, martinod...@gmail.com
Hi,

this is slightly off-topic, but is there an example of a configuration which saves the data in an external db? The example seems to store it in an in-memory-database, and this is slightly more difficult to see the results of. If there was a postgres example for example, it'd be easier to see the actual results in the table? It's probably a no-brainer for someone who's used to it? 

As for the questions, I guess 1) could be that storing as blobs is more flexible, in regards to extensions, changed specifications over time etc. As a drawback, searching for compartments etc could be more difficult. One could perhaps store compartment-info and other specific searchable info alongside the blob to provide faster compartment-support, while keeping the blob for having the original content? 

As for 2), I think you can change the storage implementation itself and use HAPI-FHIR on top still. I think you'll find the code in the hapi-fhir-jpaserver-base project, which has various DAO (data access objects) defining how things are stored. I guess you could modify that, or reimplement parts of it. 

Best regards, 
Lars

Dom

unread,
Oct 6, 2015, 4:45:42 PM10/6/15
to HAPI FHIR, martinod...@gmail.com
Hi Lars Kristian Roland,
in hapi-fhir-jpaserver-example you can use any database supported by Hibernate (Postgres, Mysql and so on).
To do this you must change the file src/main/webapp/WEB-INF/xsd/hapi-fhir-server-database-config.xml with the parameters of the database you want to use. Moreover you must change the Derby driver name with the name of the database you want to use in the class DerbyInit ( Class.forName("your database driver name")) in the package ca.uhn.fhir.jpa.demo (path src/main/java).

If you want to use as database MySQL the file hapi-fhir-server-database-config.xml is the following:


<!-- 
This file configures the database connection for the HAPI JPA Server.
-->

<!--
The following bean configures the database connection. The 'url' property value
of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the
server should save resources in a directory called "jpaserver_derby_files".
A URL to a remote database could also be placed here, along with login credentials
and other properties supported by BasicDataSource.
-->
<bean id="myPersistenceDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="url" value="jdbc:mysql://localhost:3306/hapiFhir" />
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="username" value="your database username"/>
<property name="password" value="your database password"/>
</bean>
<!--
Hibernate can be configured with other dialects if you wish to connect to another
database (e.g. Postgres). Consult the Hibernate documentation to see a list of
available dialects. 
-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myPersistenceDataSource" />
<property name="persistenceXmlLocation" value="classpath:META-INF/fhirtest_persistence.xml" />
<property name="persistenceUnitName" value="FHIR_UT" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
<!--  <property name="databasePlatform" value="org.hibernate.dialect.DerbyTenSevenDialect" /> -->
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>

</beans>

While the name of the driver in the class DerbyInit is:
Class.forName("com.mysql.jdbc.driver");

If you want to use as application server APACHE TOMCAT you must add the driver of mysql (file .jar) in the folder "lib" of tomcat.

Now if you deploy the application it should work successfully with the new DataBase MySQL.

Best regards,
Domenico

Bill de Beaubien

unread,
Oct 8, 2015, 8:50:36 AM10/8/15
to Lars Kristian Roland, HAPI FHIR, martinod...@gmail.com
hapi-fhir-jpaserver-example stores the results in an apache derby database, though the location of the database is perhaps not where one might expect, and I'm not sure if it'll vary depending on how you actually run the server (I normally run it under tomcat from inside of intellij). On my system, the derby files end up under the jdk directory i've set up for the project (c:\java\jdk1.8.0_25\bin\jpaserver_derby_files)

Bill

Donald H French

unread,
Nov 6, 2015, 2:09:15 PM11/6/15
to HAPI FHIR, martinod...@gmail.com
I used this modification and the Derby database seems to still be being used.  Each time I attempt to run I notice there is one more patient shown on the console.  I have tried the same changes for postgres and get the same thing. The database does not show up in postgres.  I am sure I am doing something wrong however I am looking for help.

Don

Lars Kristian Roland

unread,
Nov 6, 2015, 2:28:28 PM11/6/15
to Donald H French, HAPI FHIR, martinod...@gmail.com
Hi Don,

with offline help I managed to get the server up and running with mysql. You'll find that project project here:


It may help you.

Best regards,
Lars

--
You received this message because you are subscribed to a topic in the Google Groups "HAPI FHIR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hapi-fhir/jgI3HAOMsfg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hapi-fhir+...@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Lars Kristian Roland

pka...@gmail.com

unread,
May 25, 2016, 5:41:55 AM5/25/16
to HAPI FHIR, dhfr...@vertisoft.com, martinod...@gmail.com
Being new to HAPI and FHIR, is the fhirserver that is in bit bucket a full reference implementation ?  What I am looking for is a fully qualified schema that supports the FHIR spec.  Thank you !

Lars Kristian Roland

unread,
May 25, 2016, 5:58:56 AM5/25/16
to pka...@gmail.com, Domenico Martino, Donald H French, HAPI FHIR

The bit bucket version is old. Use the original Github hapi-fhir repo as your basis.

Lars

Peter Kasson

unread,
May 25, 2016, 5:59:48 AM5/25/16
to Lars Kristian Roland, Domenico Martino, Donald H French, HAPI FHIR
And that can be used to generate  a schema, for example, in MySQL or other engines ?

Lars Kristian Roland

unread,
May 25, 2016, 7:56:22 AM5/25/16
to Peter Kasson, Domenico Martino, Donald H French, HAPI FHIR
Yes. The JPA-project on HAPI-FHIR (https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jpaserver-example) comes with its own data-model, which can be configured (using JPA/Hibernate) to run towards different databases such as mysql, oracle, postgres etc, with a data model that comes with that project. HAPI-FHIR can also be used in other configurations, where you take more control of the storage model yourself (but then you have to implement more). If you take https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jpaserver-example as a basis and then copy over relevant bits of code from the bitbucket project, you can configure this to run towards mysql, hibernate etc. I'm not sure that storage model is recommended for high-scale production as it is, but that'd be your own responsibility, and in general HAPI-FHIR seems like really solid code and a good project. 

Best regards,
Lars
Reply all
Reply to author
Forward
Message has been deleted
0 new messages