Skip to content

Commit

Permalink
feat: get questionnaire by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Feb 1, 2024
1 parent 27768dd commit ae17403
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/clinical/domain/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,8 @@ type FHIRUsageContext struct {
ValueRange *FHIRRange `json:"valueRange,omitempty" mapstructure:"valueRange"`
ValueReference *FHIRReference `json:"valueReference,omitempty" mapstructure:"valueReference"`
}

// FHIRQuestionnaireRelayPayload is used to return a single instance of Questionnaire
type FHIRQuestionnaireRelayPayload struct {
Resource *FHIRQuestionnaire `json:"resource,omitempty"`
}
16 changes: 16 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1793,3 +1793,19 @@ func (fh StoreImpl) CreateFHIRRiskAssessment(_ context.Context, input *domain.FH
Resource: resource,
}, nil
}

// GetFHIRQuestionnaire retrieves instances of FHIRQuestionnaire by ID
func (fh StoreImpl) GetFHIRQuestionnaire(_ context.Context, id string) (*domain.FHIRQuestionnaireRelayPayload, error) {
resource := &domain.FHIRQuestionnaire{}

err := fh.Dataset.GetFHIRResource(questionnaireResourceType, id, resource)
if err != nil {
return nil, fmt.Errorf("unable to get %s with ID %s, err: %w", questionnaireResourceType, id, err)
}

payload := &domain.FHIRQuestionnaireRelayPayload{
Resource: resource,
}

return payload, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -4825,3 +4825,50 @@ func TestStoreImpl_CreateFHIRRiskAssessment(t *testing.T) {
})
}
}

func TestStoreImpl_GetFHIRQuestionnaire(t *testing.T) {

type args struct {
ctx context.Context
id string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: Successfully get questionnaire",
args: args{
ctx: context.Background(),
id: uuid.New().String(),
},
wantErr: false,
},
{
name: "Sad case: Fail to get questionnaire by ID",
args: args{
ctx: context.Background(),
id: "",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dataset := fakeDataset.NewFakeFHIRRepositoryMock()
fh := FHIR.NewFHIRStoreImpl(dataset)

if tt.name == "Sad case: Fail to get questionnaire by ID" {
dataset.MockGetFHIRResourceFn = func(resourceType, fhirResourceID string, resource interface{}) error {
return fmt.Errorf("an error occurred")
}
}
_, err := fh.GetFHIRQuestionnaire(tt.args.ctx, tt.args.id)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.GetFHIRQuestionnaire() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type FHIRMock struct {
MockCreateFHIRConsentFn func(ctx context.Context, input domain.FHIRConsent) (*domain.FHIRConsent, error)
MockCreateFHIRQuestionnaireResponseFn func(ctx context.Context, input *domain.FHIRQuestionnaireResponse) (*domain.FHIRQuestionnaireResponse, error)
MockCreateFHIRRiskAssessmentFn func(ctx context.Context, input *domain.FHIRRiskAssessment) (*domain.FHIRRiskAssessmentRelayPayload, error)
MockGetFHIRQuestionnaireFn func(ctx context.Context, id string) (*domain.FHIRQuestionnaireRelayPayload, error)
}

// NewFHIRMock initializes a new instance of FHIR mock
Expand Down Expand Up @@ -1904,6 +1905,32 @@ func NewFHIRMock() *FHIRMock {
Resource: input,
}, nil
},
MockGetFHIRQuestionnaireFn: func(ctx context.Context, id string) (*domain.FHIRQuestionnaireRelayPayload, error) {
resource := &domain.FHIRQuestionnaire{
ID: new(string),
Meta: &domain.FHIRMetaInput{},
ImplicitRules: new(string),
Language: new(string),
Text: &domain.FHIRNarrative{},
Extension: []*domain.Extension{},
ModifierExtension: []*domain.Extension{},
Identifier: []*domain.FHIRIdentifier{},
Version: new(string),
Name: new(string),
Title: new(string),
DerivedFrom: []*string{},
Experimental: new(bool),
Publisher: new(string),
Description: new(string),
UseContext: &domain.FHIRUsageContext{},
Jurisdiction: []*domain.FHIRCodeableConcept{},
Purpose: new(string),
EffectivePeriod: &domain.FHIRPeriod{},
Code: []*domain.FHIRCoding{},
Item: []*domain.FHIRQuestionnaireItem{},
}
return &domain.FHIRQuestionnaireRelayPayload{Resource: resource}, nil
},
}
}

Expand Down Expand Up @@ -2231,3 +2258,8 @@ func (fh *FHIRMock) CreateFHIRQuestionnaireResponse(ctx context.Context, input *
func (fh *FHIRMock) CreateFHIRRiskAssessment(ctx context.Context, input *domain.FHIRRiskAssessment) (*domain.FHIRRiskAssessmentRelayPayload, error) {
return fh.MockCreateFHIRRiskAssessmentFn(ctx, input)
}

// GetFHIRQuestionnaire retrieves an instance of FHIRQuestionnaire by ID
func (fh *FHIRMock) GetFHIRQuestionnaire(ctx context.Context, id string) (*domain.FHIRQuestionnaireRelayPayload, error) {
return fh.MockGetFHIRQuestionnaireFn(ctx, id)
}
1 change: 1 addition & 0 deletions pkg/clinical/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type FHIRMedia interface {
}

type FHIRQuestionnaire interface {
GetFHIRQuestionnaire(ctx context.Context, id string) (*domain.FHIRQuestionnaireRelayPayload, error)
CreateFHIRQuestionnaire(ctx context.Context, input *domain.FHIRQuestionnaire) (*domain.FHIRQuestionnaire, error)
ListFHIRQuestionnaire(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRQuestionnaires, error)
}
Expand Down

0 comments on commit ae17403

Please sign in to comment.