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

Activity flow api changes. #2476

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Conversation

aditya-07
Copy link
Collaborator

@aditya-07 aditya-07 commented Mar 14, 2024

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2469

Description
Api for creating a flow to move a request through various phases of an ActivityFlow.

The class ActivityFlow has two main functionalities:

  1. Allow users to get access to the current Phase.
  2. Allow users to move to next phase of the activity flow.
  3. To move to the next phase, user may first call the api to create a draft Resource for the new phase and then start that phase. These correspond with the begin and end api of the ActivityFlow.
    e.g. ActivityFlow.draftPlan corresponds to beginPlan and ActivityFlow.startPlan corresponds to endPlan .

The Phase class has two distinct hierarchies RequestPhase and EventPhase each with unique apis to allow valid state transitions for Request based phases (Proposal, Plan and Order) and Event based phases (Perform) respectively.

ActivityFlow provides various ActivityFlow.of static api to help user create ActivityFlow for particular activities with particular request or event types.

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@aditya-07 aditya-07 marked this pull request as ready for review July 25, 2024 09:09
Copy link
Collaborator

@MJ1998 MJ1998 left a comment

Choose a reason for hiding this comment

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

This looks great!
Requesting few small changes .


import org.hl7.fhir.r4.model.Task

class CPGProposeDiagnosisTask(override val resource: Task) : CPGTaskRequest(resource) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly for other TaskRequest resources

Suggested change
class CPGProposeDiagnosisTask(override val resource: Task) : CPGTaskRequest(resource) {
class CPGProposeDiagnosisTaskRequest(override val resource: Task) : CPGTaskRequest(resource) {

enum class EventStatus(val code: String) {
PREPARATION("preparation"),
INPROGRESS("in-progress"),
CANCELLED("not-done"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
CANCELLED("not-done"),
CANCELLED("cancelled"),

COMPLETED("completed"),
ENTEREDINERROR("entered-in-error"),
STOPPED("stopped"),
DECLINED("decline"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
DECLINED("decline"),
DECLINED("declined"),

when (code) {
"preparation" -> PREPARATION
"in-progress" -> INPROGRESS
"not-done" -> CANCELLED
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"not-done" -> CANCELLED
"cancelled" -> CANCELLED

"completed" -> COMPLETED
"entered-in-error" -> ENTEREDINERROR
"stopped" -> STOPPED
"decline" -> DECLINED
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"decline" -> DECLINED
"declined" -> DECLINED


companion object {

fun of(code: String) =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This case is missing

Suggested change
fun of(code: String) =
"not-done" -> NOTDONE

@aditya-07 aditya-07 requested a review from a team as a code owner September 12, 2024 07:16
Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

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

can you add a page in the doc folder?

Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

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

just noting comments from bryn:

  1. Can we change "draft" to "prepare"
  2. Can we change "start" to "submit"
  3. Can we change "resume" in the test cases to "continue"?

Copy link
Collaborator

@MJ1998 MJ1998 left a comment

Choose a reason for hiding this comment

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

Thanks Aditya for the changes.
2 main concerns:-

  1. Should we consider making the operations asynchronous ? Since we are dealing with Repository it only makes sense to do the operations in a IO coroutine. Suggesting to make the initiate and update methods suspend functions.
  2. Do you think we should add a rollback api ? If there are errors in later phases one might want to rollback. To do this we could maintain a stack pf phases instead of only the currentPhase.

/**
* Creates a draft plan resource based on the state of the [currentPhase].
*
* @return [R] if the action is successful, error otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct the return kdoc.

Suggested change
* @return [R] if the action is successful, error otherwise.
* @return [Result]<R> containing the draft plan resource if the action is successful, [Result.failure] otherwise.

/**
* Creates a draft order resource based on the state of the [currentPhase].
*
* @return [R] if the action is successful, error otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct the return kdoc like above and other places.

@Suppress(
"UnstableApiUsage", /* Repository is marked @Beta */
)
class ActivityFlow<R : CPGRequestResource<*>, E : CPGEventResource<*>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you comment on thread-safety of this class ?

}

@Test
fun `order medication flow for medication dispense no test `(): Unit = runBlockingOnWorkerThread {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the same as order medication flow for medication dispense ?
I see a lot of duplicate codes. Can we reuse them ?

}

@Test
fun `draftPlan is success when flow is in proposal phase`(): Unit = runBlockingOnWorkerThread {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this is better ?

Suggested change
fun `draftPlan is success when flow is in proposal phase`(): Unit = runBlockingOnWorkerThread {
fun `preparePlan should succeed when in proposal phase`(): Unit = runBlockingOnWorkerThread {

}

@Test
fun `draftPlan is failure when flow is in plan phase`(): Unit = runBlockingOnWorkerThread {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly others ?

Suggested change
fun `draftPlan is failure when flow is in plan phase`(): Unit = runBlockingOnWorkerThread {
fun `preparePlan should fail when in plan phase`(): Unit = runBlockingOnWorkerThread {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR under Review
Development

Successfully merging this pull request may close these issues.

Activity flow api.
5 participants