-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added docs for Activity flow #2735
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# ActivityFlow | ||
|
||
The `ActivityFlow` class manages the workflow of clinical recommendations according to the [FHIR Clinical Practice Guidelines (CPG) specification](https://build.fhir.org/ig/HL7/cqf-recommendations/activityflow.html#activity-lifecycle---request-phases-proposal-plan-order). It implements an activity flow as defined in the FHIR CPG IG, allowing you to guide clinical recommendations through various phases (proposal, plan, order, perform). | ||
|
||
You can start new workflows with an appropriate request resource from the generated [CarePlan](Generate-A-Care-Plan.md) or resume existing ones from any phase. | ||
|
||
**Important Considerations:** | ||
|
||
* **Thread Safety:** The `ActivityFlow` is not thread-safe. Concurrent changes from multiple threads may lead to unexpected behavior. | ||
* **Blocking Operations:** Some methods of `ActivityFlow` and its associated `Phase` interface may block the caller thread. Ensure these are called from a worker thread to avoid UI freezes. | ||
|
||
## Creating an ActivityFlow | ||
|
||
Use the appropriate `ActivityFlow.of()` factory function to create an instance. You can start anew flow with a `CPGRequestResource` or resume an existing flow from a `CPGRequestResource` or `CPGEventResource` based on the current state. | ||
|
||
**Example:** | ||
```kotlin | ||
val request = CPGMedicationRequest( medicationRequestGeneratedByCarePlan) | ||
val flow = ActivityFlow.of(repository, request) | ||
``` | ||
|
||
## Navigating Phases | ||
|
||
An `ActivityFlow` progresses through a series of phases, represented by the `Phase` class. Access the current phase using `getCurrentPhase()`. | ||
|
||
**Example:** | ||
```kotlin | ||
when (val phase = flow.getCurrentPhase( )) { | ||
is Phase.ProposalPhase -> { /* Handle proposal phase */ } | ||
is Phase.PlanPhase -> { /* Handle plan phase */ } | ||
// ... other phases | ||
} | ||
``` | ||
|
||
## Transitioning Between Phases | ||
|
||
`ActivityFlow` provides functions to prepare and initiate the next phase: | ||
|
||
* **`prepare...()`:** Creates a new request or event for the next phase without persisting changes. | ||
* **`initiate...()`:** Creates a new phase based on the provided request/event and persists changes to the repository. | ||
|
||
**Example:** | ||
```kotlin | ||
val preparedPlan = flow.preparePlan().getOrThrow( ) | ||
// ... modify preparedPlan | ||
val planPhase = flow.initiatePlan(preparedPlan).getOrThrow( ) | ||
``` | ||
|
||
## Transitioning to Perform Phase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. say that perform is a special phase that needs an event |
||
|
||
The `preparePerform()` function requires the event type as a parameter since the perform phase can create different event resources. | ||
|
||
**Example:** | ||
```kotlin | ||
val preparedPerformEvent = flow.preparePerform( CPGMedicationDispenseEvent::class.java).getOrThrow() | ||
// ... update preparedPerformEvent | ||
val performPhase = flow.initiatePerform( preparedPerformEvent). getOrThrow( ) | ||
``` | ||
|
||
## Updating States in a Phase | ||
|
||
* **`RequestPhase`:** (`ProposalPhase`, `PlanPhase`, `OrderPhase`) allows updating the request state using `update()`. | ||
* **`EventPhase`:** (`PerformPhase`) allows updating the event state using `update()` and completing the phase using `complete()`. | ||
|
||
## Factory Functions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have a section called api list, and list the factory functions and other functions - or, if these are covered and clear enough from previous sections, we don't ahve to have this separate list. or maybe these can be part of the diagram if you can squeeze them in. |
||
|
||
* `ActivityFlow.of(...)`: Various overloads for creating `ActivityFlow` instances with different resource types. Refer to the code for specific usage. | ||
|
||
## Public Methods | ||
|
||
* `getCurrentPhase()`: Returns the current `Phase` of the workflow. | ||
* `preparePlan()`: Prepares a plan resource. | ||
* `initiatePlan(...)`: Initiates the plan phase. | ||
* `prepareOrder()`: Prepares an order resource. | ||
* `initiateOrder(...)`: Initiates the order phase. | ||
* `preparePerform(...)`: Prepares an event resource for the perform phase. | ||
* `initiatePerform(...)`: Initiates the perform phase. | ||
|
||
## Additional Resources | ||
|
||
* [FHIR Clinical Practice Guidelines IG](https://build.fhir.org/ig/HL7/cqf-recommendations/) | ||
* [Activity Flow](https://build.fhir.org/ig/HL7/cqf-recommendations/activityflow.html#activity-flow) | ||
* [Activity Profiles](https://build.fhir.org/ig/HL7/cqf-recommendations/activityflow.html) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ Future features of the library will provide support for Tasking and other Workfl | |
* [Evaluate a Measure](Evaluate-a-Measure.md) | ||
* [Evaluate a Library](Evaluate-a-Library.md) | ||
* [Compile CQL](Compile-and-Execute-CQL.md) | ||
* [Run an Activity Flow](Run-an-Activity-Flow.md) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would put this after generate care plan, and before evaluate measure. actually maybe separate this list into 2. one list includes care plan generation, activity flow, and measure - and we can call it workflow guides.... and another list including the other two, maybe call it "other operations" or soemthign similar? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a short paragraph on top of this page in the right order to describe this step in between generation of care plan and the measure evaluation. |
||
|
||
## Data safety | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have a simple diagram to explain the phases. no need to discuss the intents of the phases (we're trying to hide those things from developers) but just the phases and transitions.
but also - add something about the fact that this api makes it easy for you to implement the activity flow - because we manage the resources, and manage the intents and statuses to make sure they are compliant with the cpg ig.