FHIR is a standard for health care data exchange, published by HL7®. HAPI FHIR is an open source implementation which is very easily to integrate (http://hapifhir.io/). The database size is increasing if you want to keep history of all changes in fhir resources. So if you may want to clean up somehow the database by old versions of resources, you can use the following store procedure to accomplish this:

DROP PROCEDURE IF EXISTS delete_old_versions $$
CREATE DEFINER=`root`@`%` PROCEDURE `delete_old_versions`()
BEGIN 
  DECLARE res_id_ BIGINT;
  DECLARE res_ver_ BIGINT;
  DECLARE done INT DEFAULT 0;

  DECLARE curs CURSOR FOR SELECT res_id FROM hfj_resource;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  
  OPEN curs;

  read_loop: LOOP
    FETCH curs INTO res_id_;
    IF done = 1 THEN 
	   LEAVE read_loop;
    END IF;
	delete from hfj_res_ver where res_id=res_id_ and res_ver not in (SELECT RES_VER FROM hfj_resource where res_id= res_id_);
  END LOOP;
END $$
DELIMITER;

By admin

2 thoughts on “HAPI FHIR handle resource versions”

Comments are closed.