Skip to content

Commit

Permalink
chore: modify consent api to accept deny reason
Browse files Browse the repository at this point in the history
  • Loading branch information
allansifuna committed Jan 30, 2024
1 parent 2eb9765 commit 639a72e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
7 changes: 4 additions & 3 deletions pkg/clinical/application/dto/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ type SectionInput struct {

// ConsentInput models the consent input
type ConsentInput struct {
Status ConsentStatusEnum `json:"status"`
Provision ConsentProvisionTypeEnum `json:"provision,omitempty"`
PatientID string `json:"patientID,omitempty"`
Status ConsentStatusEnum `json:"status"`
Provision ConsentProvisionTypeEnum `json:"provision,omitempty"`
PatientID string `json:"patientID,omitempty"`
DenyReason string `json:"denyReason,omitempty"`
}

// QuestionnaireResponse models input for questionnaire response resource in fhir
Expand Down
3 changes: 2 additions & 1 deletion pkg/clinical/domain/consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/savannahghi/clinical/pkg/clinical/application/dto"
)

// Consent models a fhir consent resource
// Consent models a fhir consent resource.
type FHIRConsent struct {
ID *string `json:"id,omitempty"`
Status *dto.ConsentStatusEnum `json:"status"`
Expand All @@ -14,6 +14,7 @@ type FHIRConsent struct {
Provision *FHIRConsentProvision `json:"provision,omitempty"`
Patient *FHIRReference `json:"patient,omitempty"`
Meta *FHIRMetaInput `json:"meta,omitempty"`
Extension []FHIRExtension `json:"extension,omitempty"`
}

// ConsentProvision models a fhir consent provision
Expand Down
12 changes: 11 additions & 1 deletion pkg/clinical/presentation/graph/generated/generated.go

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

1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/inputs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ input ConsentInput{
status: ConsentStatusEnum!
provision: ConsentProvisionTypeEnum!
patientID: String!
denyReason: String
}

input ReferenceInput {
Expand Down
11 changes: 11 additions & 0 deletions pkg/clinical/usecases/clinical/consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func (u *UseCasesClinicalImpl) RecordConsent(ctx context.Context, input dto.Cons
Tag: tags,
}

extension := &domain.FHIRExtension{
URL: "https://www.hl7.org/fhir/datatypes.html#markdown",
Extension: []domain.Extension{
{
URL: "https://www.hl7.org/fhir/datatypes.html#markdown",
ValueMarkdown: input.DenyReason,
},
},
}

consent := domain.FHIRConsent{
Provision: consentProvision,
Status: &input.Status,
Expand All @@ -63,6 +73,7 @@ func (u *UseCasesClinicalImpl) RecordConsent(ctx context.Context, input dto.Cons
Category: []*domain.FHIRCodeableConcept{category},
PolicyRule: policyRule,
Meta: &consentMeta,
Extension: []domain.FHIRExtension{*extension},
}

resp, err := u.infrastructure.FHIR.CreateFHIRConsent(ctx, consent)
Expand Down
22 changes: 13 additions & 9 deletions pkg/clinical/usecases/clinical/consent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ func TestUseCasesClinicalImpl_RecordConsent(t *testing.T) {
args: args{
ctx: context.Background(),
input: dto.ConsentInput{
PatientID: ID,
Provision: dto.ConsentProvisionTypeEnum(provisionType),
Status: dto.ConsentStatusEnum(status),
PatientID: ID,
Provision: dto.ConsentProvisionTypeEnum(provisionType),
Status: dto.ConsentStatusEnum(status),
DenyReason: "",
},
},
wantErr: false,
Expand All @@ -49,8 +50,9 @@ func TestUseCasesClinicalImpl_RecordConsent(t *testing.T) {
args: args{
ctx: context.Background(),
input: dto.ConsentInput{
PatientID: ID,
Status: dto.ConsentStatusEnum(status),
PatientID: ID,
Status: dto.ConsentStatusEnum(status),
DenyReason: "",
},
},
wantErr: true,
Expand All @@ -60,8 +62,9 @@ func TestUseCasesClinicalImpl_RecordConsent(t *testing.T) {
args: args{
ctx: context.Background(),
input: dto.ConsentInput{
PatientID: "",
Status: dto.ConsentStatusEnum(status),
PatientID: "",
Status: dto.ConsentStatusEnum(status),
DenyReason: "",
},
},
wantErr: true,
Expand All @@ -71,8 +74,9 @@ func TestUseCasesClinicalImpl_RecordConsent(t *testing.T) {
args: args{
ctx: nil,
input: dto.ConsentInput{
PatientID: "",
Status: dto.ConsentStatusEnum(status),
PatientID: "",
Status: dto.ConsentStatusEnum(status),
DenyReason: "",
},
},
wantErr: true,
Expand Down

0 comments on commit 639a72e

Please sign in to comment.