Skip to content

Commit

Permalink
fix: consent update
Browse files Browse the repository at this point in the history
- use enums instead of booleans for consent to accept or revoke consent

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
KathurimaKimathi authored and maxwellgithinji committed May 23, 2023
1 parent 2ec7eb3 commit 8719e79
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 41 deletions.
18 changes: 17 additions & 1 deletion fixtures/caregivers_caregiver_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@
relationship_type: FATHER
caregiver_consent: ACCEPTED
caregiver_consent_at: 2021-11-22 21:16:29.23639+03
client_consent: REJECTED
client_consent: REJECTED

- caregiver_id: {{.test_caregiver_id_to_update}}
client_id: {{.test_client_to_update}}
active: true
created: 2021-11-22 21:16:29.23639+03
created_by: NULL
updated: 2021-11-22 21:16:29.23639+03
updated_by: NULL
deleted_at: NULL
organisation_id: {{.test_organisation_id}}
assigned_by: {{.staff_id}}
program_id: {{.test_program_id}}
relationship_type: FATHER
caregiver_consent: ACCEPTED
caregiver_consent_at: 2021-11-22 21:16:29.23639+03
client_consent: ACCEPTED
14 changes: 14 additions & 0 deletions fixtures/clients_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,17 @@
program_id: {{.test_program_id}}
current_facility_id: {{.test_facility_id}}
user_id: {{.user_with_roles_id}}

- id: {{.test_client_to_update}}
created: 2021-11-22 21:16:29.23639+03
updated: 2021-11-22 21:16:29.23639+03
active: true
client_types: '{PMTCT}'
enrollment_date: 2021-11-22 21:16:29.23639+03
fhir_patient_id: {{.test_client_to_update}}
emr_health_record_id: 29b30a42-cbb8-4573-aedb-c539602d04fc
counselled: true
organisation_id: {{.test_organisation_id}}
program_id: {{.test_program_id2}}
current_facility_id: {{.test_facility_id}}
user_id: {{.test_user_without_caregiver}}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (
testClientToAddToAnotherProgram = "01bd8f8d-a1f6-45cf-973d-afb9bde23d87"
clientWithRolesID = "79b0aae0-1c42-4b2b-8920-12f7c05dddd9"
testClientToAssignToCaregiver = "4a9552c7-ddbb-423c-89b6-626099087b37"
testClientToUpdateConsent = "5f579d05-0df4-431d-8f70-6f7c76feb925"

contactID = "bdc22436-e314-43f2-bb39-ba1ab332f9b0"
identifierID = "bcbdaf68-3d36-4365-b575-4182d6749af5"
Expand Down Expand Up @@ -113,6 +114,7 @@ var (
testClientCaregiver1 = "28b20a42-cbb8-4553-aedb-c575602d04fc"
testCaregiverOrg2ID = "4e4ef3d2-eb26-407a-82c3-31243dc923cd"
caregiverWithRolesID = "484831c5-9b63-4580-9aef-4bffb4bdd230"
testCaregiverID3 = "96b20a42-cbb8-4553-aedb-c593602d04fc"

//Terms
termsText = "Test terms"
Expand Down Expand Up @@ -403,9 +405,10 @@ func TestMain(m *testing.M) {
"security_question_response_id4": securityQuestionResponseID4,
"user_id_to_add_caregiver": userIDtoAddCaregiver,

"test_caregiver_id": testCaregiverID,
"test_caregiver_org_2_id": testCaregiverOrg2ID,
"caregiver_with_roles_id": caregiverWithRolesID,
"test_caregiver_id": testCaregiverID,
"test_caregiver_org_2_id": testCaregiverOrg2ID,
"caregiver_with_roles_id": caregiverWithRolesID,
"test_caregiver_id_to_update": testCaregiverID3,

"staff_number": staffNumber,
"clients_service_request_id": clientsServiceRequestID,
Expand All @@ -423,6 +426,7 @@ func TestMain(m *testing.M) {
"test_client_id": clientID,
"test_client_id_same_user_different_program": clientSameUserDifferentProgramID,
"test_client_id_different_user_same_program": clientDifferentUserSameProgramID,
"test_client_to_update": testClientToUpdateConsent,

"can_invite_user_permission": canInviteUserPermissionID,
"can_resolve_service_request": canEditOwnRolePermissionID,
Expand Down
28 changes: 14 additions & 14 deletions pkg/mycarehub/presentation/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/mycarehub/presentation/graph/user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extend type Mutation {
assignCaregiver(input: ClientCaregiverInput!): Boolean!
removeFacilitiesFromStaffProfile(staffID: ID!, facilities: [ID!]!): Boolean!
registerExistingUserAsStaff(input: ExistingUserStaffInput!): StaffRegistrationOutput!
consentToAClientCaregiver(clientID: ID!, caregiverID: ID!, consent: Boolean!): Boolean!
consentToManagingClient(caregiverID: ID!, clientID: ID!, consent: Boolean! ): Boolean!
consentToAClientCaregiver(clientID: ID!, caregiverID: ID!, consent: ConsentState!): Boolean!
consentToManagingClient(caregiverID: ID!, clientID: ID!, consent: ConsentState!): Boolean!
registerExistingUserAsClient(input: ExistingUserClientInput!): ClientRegistrationOutput!
setCaregiverCurrentClient(clientID: ID!): ClientProfile!
setCaregiverCurrentFacility(clientID: ID!, facilityID: ID!): Facility!
Expand Down
4 changes: 2 additions & 2 deletions pkg/mycarehub/presentation/graph/user.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/mycarehub/usecases/user/mock/user_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type UserUseCaseMock struct {
MockRegisterClientAsCaregiverFn func(ctx context.Context, clientID string, caregiverNumber string) (*domain.CaregiverProfile, error)
MockGetCaregiverManagedClientsFn func(ctx context.Context, userID string, input dto.PaginationsInput) (*dto.ManagedClientOutputPage, error)
MockListClientsCaregiversFn func(ctx context.Context, clientID string, pagination *dto.PaginationsInput) (*dto.CaregiverProfileOutputPage, error)
MockConsentToAClientCaregiverFn func(ctx context.Context, clientID string, caregiverID string, consent bool) (bool, error)
MockConsentToManagingClientFn func(ctx context.Context, caregiverID string, clientID string, consent bool) (bool, error)
MockConsentToAClientCaregiverFn func(ctx context.Context, clientID string, caregiverID string, consent enums.ConsentState) (bool, error)
MockConsentToManagingClientFn func(ctx context.Context, caregiverID string, clientID string, consent enums.ConsentState) (bool, error)
MockRegisterExistingUserAsStaffFn func(ctx context.Context, input dto.ExistingUserStaffInput) (*dto.StaffRegistrationOutput, error)
MockGetStaffFacilitiesFn func(ctx context.Context, staffID string, paginationInput dto.PaginationsInput) (*dto.FacilityOutputPage, error)
MockGetClientFacilitiesFn func(ctx context.Context, clientID string, paginationInput dto.PaginationsInput) (*dto.FacilityOutputPage, error)
Expand Down Expand Up @@ -333,7 +333,7 @@ func NewUserUseCaseMock() *UserUseCaseMock {
MockUpdateUserProfileFn: func(ctx context.Context, userID string, cccNumber, username, phoneNumber *string, programID string, flavour feedlib.Flavour, email *string) (bool, error) {
return true, nil
},
MockConsentToAClientCaregiverFn: func(ctx context.Context, clientID string, caregiverID string, consent bool) (bool, error) {
MockConsentToAClientCaregiverFn: func(ctx context.Context, clientID string, caregiverID string, consent enums.ConsentState) (bool, error) {
return true, nil
},
MockRegisteredFacilityPatientsFn: func(ctx context.Context, input dto.PatientSyncPayload) (*dto.PatientSyncResponse, error) {
Expand Down Expand Up @@ -471,7 +471,7 @@ func NewUserUseCaseMock() *UserUseCaseMock {
MockAddFacilitiesToStaffProfileFn: func(ctx context.Context, staffID string, facilities []string) (bool, error) {
return true, nil
},
MockConsentToManagingClientFn: func(ctx context.Context, caregiverID string, clientID string, consent bool) (bool, error) {
MockConsentToManagingClientFn: func(ctx context.Context, caregiverID string, clientID string, consent enums.ConsentState) (bool, error) {
return true, nil
},
MockAddFacilitiesToClientProfileFn: func(ctx context.Context, clientID string, facilities []string) (bool, error) {
Expand Down Expand Up @@ -768,12 +768,12 @@ func (f *UserUseCaseMock) ListClientsCaregivers(ctx context.Context, clientID st
}

// ConsentToAClientCaregiver mocks the implementation of a client acknowledging to having a certain caregiver assigned to them.
func (f *UserUseCaseMock) ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent bool) (bool, error) {
func (f *UserUseCaseMock) ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent enums.ConsentState) (bool, error) {
return f.MockConsentToAClientCaregiverFn(ctx, clientID, caregiverID, consent)
}

// ConsentToManagingClient mock the implementation of a caregiver acknowledging or offering their consent to act on behalf of the client.
func (f *UserUseCaseMock) ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent bool) (bool, error) {
func (f *UserUseCaseMock) ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent enums.ConsentState) (bool, error) {
return f.MockConsentToManagingClientFn(ctx, caregiverID, clientID, consent)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/mycarehub/usecases/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ type IClientCaregiver interface {
TransferClientToFacility(ctx context.Context, clientID *string, facilityID *string) (bool, error)
AssignCaregiver(ctx context.Context, input dto.ClientCaregiverInput) (bool, error)
ListClientsCaregivers(ctx context.Context, clientID string, pagination *dto.PaginationsInput) (*dto.CaregiverProfileOutputPage, error)
ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent bool) (bool, error)
ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent bool) (bool, error)
ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent enums.ConsentState) (bool, error)
ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent enums.ConsentState) (bool, error)
SetCaregiverCurrentClient(ctx context.Context, clientID string) (*domain.ClientProfile, error)
SetCaregiverCurrentFacility(ctx context.Context, caregiverID string, facilityID string) (*domain.Facility, error)
RegisterExistingUserAsCaregiver(ctx context.Context, userID string, caregiverNumber string) (*domain.CaregiverProfile, error)
Expand Down Expand Up @@ -2027,7 +2027,7 @@ func (us *UseCasesUserImpl) ListClientsCaregivers(ctx context.Context, clientID
}

// ConsentToAClientCaregiver is used to mark whether the client has acknowledged to having a certain caregiver assigned to them
func (us *UseCasesUserImpl) ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent bool) (bool, error) {
func (us *UseCasesUserImpl) ConsentToAClientCaregiver(ctx context.Context, clientID string, caregiverID string, consent enums.ConsentState) (bool, error) {
caregiverClient := &domain.CaregiverClient{
ClientID: clientID,
CaregiverID: caregiverID,
Expand All @@ -2047,7 +2047,7 @@ func (us *UseCasesUserImpl) ConsentToAClientCaregiver(ctx context.Context, clien
}

// ConsentToManagingClient is used to update caregiver as having consented to offer their service to a caregiver
func (us *UseCasesUserImpl) ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent bool) (bool, error) {
func (us *UseCasesUserImpl) ConsentToManagingClient(ctx context.Context, caregiverID string, clientID string, consent enums.ConsentState) (bool, error) {
caregiverClient := &domain.CaregiverClient{
CaregiverID: caregiverID,
ClientID: clientID,
Expand Down
12 changes: 6 additions & 6 deletions pkg/mycarehub/usecases/user/user_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5183,7 +5183,7 @@ func TestUseCasesUserImpl_ConsentToAClientCaregiver(t *testing.T) {
ctx context.Context
clientID string
caregiverID string
consent bool
consent enums.ConsentState
}
tests := []struct {
name string
Expand All @@ -5197,7 +5197,7 @@ func TestUseCasesUserImpl_ConsentToAClientCaregiver(t *testing.T) {
ctx: context.Background(),
clientID: uuid.NewString(),
caregiverID: uuid.NewString(),
consent: true,
consent: enums.ConsentStateAccepted,
},
want: true,
wantErr: false,
Expand All @@ -5207,7 +5207,7 @@ func TestUseCasesUserImpl_ConsentToAClientCaregiver(t *testing.T) {
args: args{
ctx: context.Background(),
clientID: uuid.NewString(),
consent: true,
consent: enums.ConsentStateAccepted,
},
want: false,
wantErr: true,
Expand Down Expand Up @@ -5248,7 +5248,7 @@ func TestUseCasesUserImpl_ConsentToManagingClient(t *testing.T) {
ctx context.Context
caregiverID string
clientID string
consent bool
consent enums.ConsentState
}
tests := []struct {
name string
Expand All @@ -5262,7 +5262,7 @@ func TestUseCasesUserImpl_ConsentToManagingClient(t *testing.T) {
ctx: context.Background(),
caregiverID: uuid.NewString(),
clientID: uuid.NewString(),
consent: true,
consent: enums.ConsentStateAccepted,
},
want: true,
wantErr: false,
Expand All @@ -5273,7 +5273,7 @@ func TestUseCasesUserImpl_ConsentToManagingClient(t *testing.T) {
ctx: context.Background(),
caregiverID: uuid.NewString(),
clientID: uuid.NewString(),
consent: true,
consent: enums.ConsentStateAccepted,
},
want: false,
wantErr: true,
Expand Down

0 comments on commit 8719e79

Please sign in to comment.