-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into update-reference-…
…indexes
- Loading branch information
Showing
9 changed files
with
187 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Demo App | ||
|
||
The *Workflow Demo* app demonstrates the capabilities of CarePlan Generation API and the Activity Flow API. The app has a Patient card in the top showing the details and a carousel in the bottom with each card representing a particular phase of the activity flow. | ||
|
||
To run this app in Android Studio, [create a run/debug configuration](https://developer.android.com/studio/run/rundebugconfig) for the `workflow_demo` module using the [Android App](https://developer.android.com/studio/run/rundebugconfig#android-application) template and run the app using the configuration. | ||
|
||
Alternatively, run the following command to build and install the debug APK on your device/emulator: | ||
|
||
```shell | ||
./gradlew :workflow_demo:installDebug | ||
``` | ||
|
||
## Instructions | ||
1. Click on the **Initialize** button to install the required dependencies for an activity flow. The dependencies are already bundled in the assets folder of the workflow demo app. After the dependencies are successfully installed, **Start** Button becomes enabled in the _Proposal_ card. | ||
2. Now, click on the **Start** to generate a CarePlan which intern has a _Proposal_ Resource. This resource is then used by the app to create a new Activity Flow and the _Proposal_ card now shows the details of the resource with the **Start** button disabled now. The carousel auto moves to the next Phase Card i.e. _Plan_. | ||
3. Repeat step 2 to move forward through the phases. | ||
4. To restart the Activity click **Restart** Flow that removes all the resources related to the flow and moves the app back to step 2. | ||
5. The overflow menu on the action bar may be used to switch between various Activities supported in the demo app. | ||
|
||
![Workflow Demo](workflow_demo_app.gif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# ActivityFlow | ||
|
||
![Activity Flow](activity_flow.svg) | ||
|
||
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 repository = FhirEngineRepository(FhirContext.forR4Cached(), fhirEngine) | ||
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 the 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 | ||
|
||
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()`. | ||
```kotlin | ||
proposalPhase.update( | ||
proposalPhase.getRequestResource().apply { setStatus(Status.ACTIVE) } | ||
) | ||
``` | ||
* **`EventPhase`:** (`PerformPhase`) allows updating the event state using `update()` and completing the phase using `complete()`. | ||
```kotlin | ||
performPhase.update( | ||
performPhase.getEventResource().apply { setStatus(EventStatus.COMPLETED) } | ||
) | ||
``` | ||
## API List | ||
### Factory functions | ||
|
||
* `ActivityFlow.of(...)`: Various overloads for creating `ActivityFlow` instances with different resource types. Refer to the code for specific usage. | ||
|
||
### Phase transition API | ||
|
||
* `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. | ||
|
||
### Other API | ||
* `getCurrentPhase()`: Returns the current `Phase` of the workflow. | ||
|
||
### Request phase API | ||
|
||
* `getRequestResource()`: Returns a copy of resource. | ||
* `update(..)`: Updates the resource. | ||
* `suspend(..)`: Suspends the phase. | ||
* `resume(..)`: Resumes the phase. | ||
* `enteredInError(..)`: Marks the request entered-in-error. | ||
* `reject(..)`: Rejects the phase. | ||
|
||
### Event phase API | ||
|
||
* `getEventResource()`: Returns a copy of resource. | ||
* `update(..)`: Updates the resource. | ||
* `suspend(..)`: Suspends the phase. | ||
* `resume(..)`: Resumes the phase. | ||
* `enteredInError(..)`: Marks the event entered-in-error. | ||
* `start(..)`: Starts the event. | ||
* `notDone(..)`: Marks the event not-done. | ||
* `stop(..)`: Stop the event. | ||
* `complete(..)`: Marks the event as complete. | ||
|
||
|
||
## Supported activities | ||
The library currently doesn't implement all of the activities outlined in the [activity profiles](https://build.fhir.org/ig/HL7/cqf-recommendations/profiles.html#activity-profiles). New activities may be added as per the requirement from the application developers. | ||
|
||
| Activity | Request | Event | | ||
|--------------------|-------------------------|-----------------------| | ||
| Send a message | CPGCommunicationRequest | CPGCommunication | | ||
| Order a medication | CPGMedicationRequest | CPGMedicationDispense | | ||
|
||
## 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/profiles.html#activity-profiles) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters