How to Get the Current User


This sample will demonstrate how to retrieve the current user within an app, using the SMART on FHIR JavaScript client.

SMART on FHIR Authorization

Request Authorization

In order to receive the current user, you must request the openid and profile scopes.

    client_id: "my_client_id",
    redirect_uri: "",
    scope: "patient/*.read openid profile"

Authorization Success

After successful authorization, retrieve the resulting SMART FHIR client. The current user's fully qualified FHIR URL is on the FHIR client at userId. 


Authorization Success
var currentUserFhirUrl;
	currentUserFhirUrl = fhirClient.userId;

Query User FHIR Resource

Retrieve the User's FHIR resource (patient, practitioner, etc).

Query Resource
var userIdSections = currentUserFhirUrl.split("/");

$.when({type: userIdSections[userIdSections.length-2], id: userIdSections[userIdSections.length-1]}))

        var user = {name:""};
		if ( === "Patient") {
    		var patientName = && &&[0]; = patientName.given.join(" ") + " " +" ").trim();
		}  =;