Rhizome Careplan demonstrator

Timelines For Care

by phollott

HTML

<script src="https://phollott.github.io/lib/TimelineJS/js/timeline.js"></script>
<script src="https://phollott.github.io/lib/TimelineJS/js/storyjs-embed.js"></script>
<link rel="stylesheet" href="https://phollott.github.io/lib/TimelineJS/css/timeline.css">
<div id="my-timeline"></div>
<script type="text/javascript">
    var fhirbundle = {
	"resourceType":"Bundle",
	"title":"Search on resources in collection 'CarePlan'",
	"id":"urn:uuid:a3b96f42-c1ef-45a6-b077-9a75892ddbb0",
	"updated":"2015-04-28T20:52:00.5151116+00:00",
	"author":[{"name":"Furore Spark FHIR server","uri":"http://fhir.furore.com"}],
	"totalResults":"10",
	"link":[
		{"rel":"self","href":"http://spark.furore.com/fhir/_snapshot?id=38d4e506-95f1-48a0-83bd-dade7d5a56e7"},
		{"rel":"first","href":"http://spark.furore.com/fhir/_snapshot?id=38d4e506-95f1-48a0-83bd-dade7d5a56e7"},
		{"rel":"last","href":"http://spark.furore.com/fhir/_snapshot?id=38d4e506-95f1-48a0-83bd-dade7d5a56e7"},
		{"rel":"fhir-base","href":"http://spark.furore.com/fhir"}
	],
	"entry":[{
		"title": "Questionnaire Entry",
		"id": "https://fhir.healthintersections.com.au/open/Questionnaire/3142",
		"link": [
			{"rel": "self", "href": "https://fhir.healthintersections.com.au/open/Questionnaire/3142/_history/1"}
		],
		"updated": "2014-11-04T00:09:57Z",
		"author": [
			{"name": "Anonymous (130.216.120.1)"}
		],
		"published": "2014-12-14T01:46:21Z",
		"content": {
			"resourceType": "Questionnaire",
			"text": {
				"status": "generated",
				"div": '<svg version="1.1" id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="250" height="250"><defs><marker id="markerArrow" markerWidth="13" markerHeight="13" refx="2" refy="6" orient="auto"><path d="M2,2 L2,8 L7,6 L2,4" /></marker></defs><rect id="question1" width="100" height="100" x="10" y="10" class="frame" /><g transform="translate(45 48)"><rect rx="3" ry="3" width="25" height="14" style="fill:none;stroke:...

JavaScript

$(document).ready(function () {

    var fhircareplan = fhirbundle.entry[1].content
    function getGoal(goalId) {
        for (g in fhircareplan.goal) {
            if ("#"+fhircareplan.goal[g].id == goalId) {
                return fhircareplan.goal[g].description
            }
        }
    }
    
    function getConcerns(concern) {
        var arr = []
        for (c in concern) {
            if (concern.hasOwnProperty(c)) {
                arr.push(concern[c].display)
            }
        }
        return arr.join(", ")
    }
    
    function formatDate(date) {
       return date.replace(/-/g,',') 
    }

    function getDates(activity) {
        var arr = []
        for (a in activity) {
            if (activity.hasOwnProperty(a)) {
                var act = activity[a]
                var date = {
                        "headline": act.simple.details,
                        "text": "<p>"+act.notes+"</p>",
                        "startDate": formatDate( act.simple.timingPeriod.start)
                    }
                if (act.actionResulting) {
                    date.asset = {
                        "media": act.actionResulting[0].reference/*,
                        "thumbnail":"optional-32x32px.jpg",
                        "credit":"Credit Name Goes Here",
                        "caption":"Caption text goes here" */
                    }
                }
 //               date.tag = getGoal(act.simple.extension[0].valueUri)
                arr.push(date)
            }
        }
 //       alert(JSON.stringify(arr))
        return arr        
    }
    
    var dataObject = { "timeline": {
        "headline": fhircareplan.patient.display,
        "type": "default",
        "text": "<p>Careplan: "+getConcerns(fhircareplan.concern)+"<br><br><button onclick='alert(JSON.stringify(fhirbundle))'>Show FHIR</button></p>",
        "startDate": formatDate(fhircareplan.modified),
        "date": getDates(fhircareplan.activity)
        }
    };

   ...