Polaris FHIR Implementation Guide
1.9.2 - ci-build

Polaris FHIR Implementation Guide - Local Development build (v1.9.2) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

Resource Profile: PolarisCoreAppState - FSH Source

Active as of 2025-10-08

FSH source of the polaris-core-appstate resource profile.

Raw FSH | Download

// PolarisCoreAppState.fsh 

// A resource that allows arbitrary name-value data to be associated with most FHIR resources (patient, document, organization, etc).

// Initially identified through CPAR and CII use cases, this profile addresses the general need for external applications / integrations / apps to store settings-type data in the FHIR repository.

// @Aaron Aston found an excellent existing standard to support application state that we propose using:

// Persisting App State (Experimental) - SMART App Launch v2.2.0
// https://build.fhir.org/ig/HL7/smart-app-launch/app-state.html


Alias: $PolarisCoreAppState = https://fhir.apps.health/StructureDefinition/polaris-core-appstate

// Pattern for App State Code System URL
Invariant:      app-state-system-inv
Description:    "AppState coding.system must match Polaris CodeSystem URL rules."
Severity:       #error
Expression:     "system.matches('https://fhir.apps.health/CodeSystem/[a-zA-Z0-9.-]+-app-state')"

// Profile Definition
// @intro
// Defines a profile on the Basic resource for representing external
// application state as namespaced name-value pairs in Polaris.
//
// Based on smart-app-state approach. 
Profile:        PolarisCoreAppState
Parent:         Basic
Id:             polaris-core-appstate
Title:          "Polaris App State Core"
Description:    "A profile for representing external application state in Polaris."
* ^url        = $PolarisCoreAppState // Canonical URL from alias
* ^status     = #active
* ^publisher  = "Polaris Project"

// --- Element Constraints ---

* . ^short      = "Polaris App State Core"
* . ^definition = """
  Represents application state information for Polaris applications, capturing key details
  like state type, content, and associated resources using standard Polaris references.
  Uses instance-specific identifiers for tracking application state across systems.
  """

* meta.source 0..1 MS
* meta.source ^short = "Identifies EMR instance & pipeline version the resource came from"
* meta.source ^definition = "A URI that identifies the EMR pipeline and version from which this resource originated.  This tells you which EMR instance (recommend using the instance identifier), and the version of the pipeline code/transformations."
  
* text 0..1 MS // Narrative element with human-readable summary
* text ^short = "Narrative"
* text ^definition = "A human-readable narrative summary of the PolarisCoreAppState resource for human interpretation."  

// App State does not require an 'identifier'
* identifier 0..1 MS
* identifier ^short = "Business identifier for app state"
* identifier ^definition = "Optional identifier for this application state entry."
* identifier ^comment = "Most app state entries are identified by their code and subject rather than explicit identifiers."

// Code: Identifies the semantic type & namespace of the state.
* code 1..1 MS
* code ^short = "Type and namespace of application state"
* code ^definition = "Identifies what kind of application state this represents and which application namespace it belongs to."
* code ^comment = "The code acts as both a type discriminator and namespace identifier for the state data."
* code.coding 1..1 MS
* code.coding ^short = "Coded type of state"
* code.coding ^definition = "The coded representation of the application state type."
* code.coding obeys app-state-system-inv
* code.coding.system 1..1 MS
* code.coding.system ^short = "Application-specific CodeSystem URL"
* code.coding.system ^definition = "Must follow pattern: https://fhir.apps.health/CodeSystem/[app-name]-app-state"
* code.coding.code 1..1 MS
* code.coding.code ^short = "Specific state type code"
* code.coding.code ^definition = "The specific type of state within the application's namespace."
* code.coding.display MS
* code.coding.display ^short = "Human-readable state type name"
* code.text MS
* code.text ^short = "Plain text description of state type"

// Subject: Links state to Patient, PractitionerRole, DocumentReference, Org, etc. SU.
* subject 1..1 SU
* subject ^short = "Resource this state is associated with"
* subject ^definition = "The FHIR resource (Patient, PractitionerRole, Organization, etc.) that this application state is associated with."
* subject ^comment = "Application state is always linked to a specific resource for context."
* subject only Reference(PolarisCorePatient or PolarisCorePractitionerRole or PolarisCoreOrganization)
* subject.reference MS
* subject.reference ^short = "Reference to the associated resource"
* subject.type MS
* subject.type ^short = "Type of resource referenced"
* subject.display MS
* subject.display ^short = "Display name of referenced resource"

// Extension: Holds the state value.  Uses different extensions for each type.
* extension 1..* MS
* extension ^short = "The actual state value(s) - can have an arbitrary number of state values"
* extension ^definition = "Contains the application state values using type-specific extensions (string, boolean, etc.)."
* extension ^comment = "Different extension types support different value data types."
* extension.url 1..1 MS
* extension.url ^short = "Extension type URL"
* extension.url ^definition = "Identifies which type of value extension is being used (string, boolean, etc.)."


// @intro
// A String-valued parameter to store in a Polaris application state entry.
Extension: AppStateStringValue
Parent:    Extension
Id:        app-state-string-value
Title:          "App State String Value Extension Core"
Description:
  """
  A simple extension to hold the value of a Polaris application-state entry as a string.
  """
* ^url = "https://fhir.apps.health/StructureDefinition/app-state-string-value" 
* ^context.type = #element
* ^context.expression = "Basic"

* valueString 1..1 MS
* valueString ^short = "String state value"
* valueString ^definition = "The application state value as a string."
* valueString ^comment = "Can contain any string data including JSON, XML, or plain text."


Extension: AppStateBooleanValue
Parent:    Extension
Id:        app-state-boolean-value
Title:          "App State Boolean Value Extension Core"
Description:
  """
  A simple extension to hold the value of a Polaris application-state entry as a boolean.
  """
* ^url = "https://fhir.apps.health/StructureDefinition/app-state-boolean-value" 
* ^context.type = #element
* ^context.expression = "Basic"

* valueBoolean 1..1 MS
* valueBoolean ^short = "Boolean state value"
* valueBoolean ^definition = "The application state value as a boolean (true/false)."
* valueBoolean ^comment = "Used for flags, toggles, and binary state values."