Skip to content

Instantly share code, notes, and snippets.

@cmoesel
Last active April 26, 2022 00:22
Show Gist options
  • Save cmoesel/f6579b504a25491ed03f1f2d036545fd to your computer and use it in GitHub Desktop.
Save cmoesel/f6579b504a25491ed03f1f2d036545fd to your computer and use it in GitHub Desktop.
Patient Profile Exercise
/*
╭───────────────────────── PATIENT PROFILE TUTORIAL ──────────────────────────╮
│ Welcome to this introductory FSH tutorial exercise for building a simple │
│ patient profile. This exercise is designed to work in FSH Online: │
│ https://fshschool.org/FSHOnline/#/gist/f6579b504a25491ed03f1f2d036545fd │
│ │
│ To test your solution, click the "Convert to JSON" button. Check the bar │
│ at the bottom of the screen to see if your FSH had any problems. Open the │
│ console at the bottom to see full results and a random FSH pun! │
╰─────────────────────────────────────────────────────────────────────────────╯
────────────────────── STEP 1: DEFINE PROFILE METADATA ───────────────────────
To begin, create a new profile definition based on the "Patient" resource. The
profile should have the name "PatientProfile" and id "patient-profile". Add a
simple title and description as well.
See Defining Profiles in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#defining-profiles
When you're done, click "Convert to JSON" to see the results (and any errors).
You can continue on to step 2 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/9c47ed295938e66c9cd29c87eb7969e9
──────────────────────────────────────────────────────────────────────────────
*/
// Start your solution here
Profile:
/*
────────────────────── STEP 2: CARDINALITY CONSTRAINTS ───────────────────────
For this profile, we want to REQUIRE the name and gender elements. In FHIR,
we require elements by constraining their minimum cardinality to 1. Add some
FSH rules to your profile to set the name and gender min cardinalities to 1.
See Cardinality Rules in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#cardinality-rules
When you're done, click "Convert to JSON" to see the results (and any errors).
You can continue on to step 3 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/0e5b22c7f2069e0cd008ae30ccea094a
──────────────────────── STEP 3: MUST SUPPORT FLAGS ──────────────────────────
Implementation guides can mark elements as MUST SUPPORT to indicate that
clients or servers must support the elements in a meaningful way. The details
regarding what MUST SUPPORT actually means is defined by the IG.
Our profile wants to indicate that the following elements must be supported:
name, name.family, name.given, gender, and birthDate. Create and/or modify
your profile's rules to mark these elements as MUST SUPPORT.
See Flag Rules in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#flag-rules
Also note that you can specify cardinality AND flags in the same rule:
- http://hl7.org/fhir/uv/shorthand/reference.html#cardinality-rules
When you're done, click "Convert to JSON" to see the results (and any errors).
You can continue on to step 4 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/d931516c0c6823fbf6e964650fcd249d
──────────────────────── STEP 4: BIRTH SEX VALUE SET ─────────────────────────
A patient's gender might not reflect the sex assigned to them at birth. In
order to support this data, we will need to create a birth sex extension.
This extension should only allow certain codes, so we will need to define a
birth sex value set first. This value set will specify allowed BirthSex codes.
Define a value set named "BirthSex" with id "birthsex". Give the value set a
short title and description. The value set should include the following codes:
╭─ SYSTEM ───────────────────────────────────────────────────────┬─ CODE ────╮
│ http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender │ M │
│ http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender │ F │
│ http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender │ UN │
│ http://terminology.hl7.org/CodeSystem/v3-NullFlavor │ UNK │
╰────────────────────────────────────────────────────────────────┴───────────╯
Start by defining $GENDER and $NULL aliases for the code system URLs:
- http://hl7.org/fhir/uv/shorthand/reference.html#defining-aliases
Then see Defining Value Sets (and especially the examples) for value set
syntax. Note that you could include the $GENDER codes using three extensional
rules or one intensional rule. The $NULL code must use an extensional rule:
- http://hl7.org/fhir/uv/shorthand/reference.html#defining-value-sets
When you're done, click "Convert to JSON" to see the results (and any errors).
Since you're creating more than one item in FSH Online now, you'll need to use
the navigation on the right-hand side to choose which JSON definition to view.
You can continue on to step 5 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/95eab22f052975fc6d00170b6a69fc91
──────────────────────── STEP 5: BIRTH SEX EXTENSION ─────────────────────────
Define an extension named "BirthSexExtension" with id "birthsex-extension".
Give the extension a short title and description.
Constrain the "value[x]" element to only allow the CodeableConcept data type.
Also bind "value[x]" to your BirthSex value set (using strength: required)
See Defining Extensions in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#defining-extensions
To see how to constrain a type, see Type Rules:
- http://hl7.org/fhir/uv/shorthand/reference.html#type-rules
To see how to bind an element to a value set, see Binding Rules:
- http://hl7.org/fhir/uv/shorthand/reference.html#binding-rules
When you're done, click "Convert to JSON" to see the results (and any errors).
You can continue on to step 6 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/214ac4af4907ea24246050b51d7324f3
───────────────── STEP 6: ADD BIRTHSEX EXTENSION TO PROFILE ──────────────────
Now that you've defined a birth sex extension, you can add it to your profile.
Add the BirthSex extension to your profile, giving it a local name "birthsex".
The birth sex extension should be optional, but flagged as Must Support.
See Contains Rules for Extensions in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#contains-rules-for-extensions
When you're done, click "Convert to JSON" to see the results (and any errors).
You can continue on to step 6 in this window or open the solution URL in a
new tab to see the solution and continue from there:
- https://fshschool.org/FSHOnline/#/gist/54137a61b86cf2b28188fc87bdf81620
──────────────── STEP 7: CREATE EXAMPLE INSTANCE OF PROFILE ──────────────────
Let's finish by making an example that conforms to our profile. Create an
instance of PatientProfile in FSH named "PatientExample". Give the instance
a title and short description (used for documentation purposes only).
The patient should be named Sally Jones. Sally was born on October 26, 1972.
She was assigned female at birth and continues to identify as female today.
See Defining Instances in the FSH Spec:
- http://hl7.org/fhir/uv/shorthand/reference.html#defining-instances
For help referring to the extension, see Extension Paths:
- http://hl7.org/fhir/uv/shorthand/reference.html#extension-paths
When you're done, click "Convert to JSON" to see the results (and any errors).
Since you're creating more than one item in FSH Online now, you'll need to use
the navigation on the right-hand side to choose which JSON definition to view.
Congratulations! You're done! If you'd like, you can click the link icon in
your FSH editor to share your solution with a friend. Or download your FSH
and JSON files by clicking the "Save All" link in the header!
To check your work, take a look at the full solution here:
- https://fshschool.org/FSHOnline/#/gist/698322e8763e9fa6f04ed3da00f047ed
──────────────────────────────────────────────────────────────────────────────
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment