Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions docs/use/WFL/Run-an-Activity-Flow.md
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add a section for the phase apis.

and then, maybe these different phrase transition apis can be grouped under the same heading in constrast with the phase apis.

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.
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved

## 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)
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
```

## 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
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved

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
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved

* **`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
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved

* `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)
1 change: 1 addition & 0 deletions docs/use/WFL/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved

## Data safety

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ nav:
- use/WFL/Evaluate-a-Measure.md
- use/WFL/Evaluate-a-Library.md
- use/WFL/Compile-and-Execute-CQL.md
- use/WFL/Run-an-Activity-Flow.md
- use/extensions.md
- API Doc: use/api.md
- Use Snapshots: use/snapshots.md
Expand Down
Loading