Skip to content

Commit

Permalink
feat: patch FHIR service request resource
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Apr 8, 2024
1 parent 87c40ec commit 3ee9765
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,3 +2069,22 @@ func (fh StoreImpl) CreateFHIRSubscription(_ context.Context, subscription *doma

return fhirSubscription, nil
}

// PatchFHIRServiceRequest is used to update the specified fhir service request resource
func (fh StoreImpl) PatchFHIRServiceRequest(ctx context.Context, id string, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error) {
payload, err := converterandformatter.StructToMap(input)
if err != nil {
return nil, fmt.Errorf("unable to turn %s input into a map: %w", serviceRequestResourceType, err)
}

resource := &domain.FHIRServiceRequest{}

err = fh.Dataset.PatchFHIRResource(serviceRequestResourceType, id, payload, resource)
if err != nil {
return nil, fmt.Errorf("unable to patch %s resource: %w", serviceRequestResourceType, err)
}

return &domain.FHIRServiceRequestRelayPayload{
Resource: resource,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -5257,3 +5257,69 @@ func TestStoreImpl_CreateFHIRSubscription(t *testing.T) {
})
}
}

func TestStoreImpl_PatchFHIRServiceRequest(t *testing.T) {
type args struct {
ctx context.Context
id string
input domain.FHIRServiceRequestInput
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: patch service request",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
input: domain.FHIRServiceRequestInput{
ID: new(string),
BodySite: []*domain.FHIRCodeableConceptInput{},
Note: []*domain.FHIRAnnotationInput{},
PatientInstruction: new(string),
RelevantHistory: []*domain.FHIRReferenceInput{},
Meta: domain.FHIRMetaInput{},
Extension: []*domain.FHIRExtension{},
},
},
wantErr: false,
},
{
name: "Sad case: unable to patch service request",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
input: domain.FHIRServiceRequestInput{
ID: new(string),
BodySite: []*domain.FHIRCodeableConceptInput{},
Note: []*domain.FHIRAnnotationInput{},
PatientInstruction: new(string),
RelevantHistory: []*domain.FHIRReferenceInput{},
Meta: domain.FHIRMetaInput{},
Extension: []*domain.FHIRExtension{},
},
},
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: unable to patch service request" {
dataset.MockPatchFHIRResourceFn = func(resourceType string, id string, payload map[string]interface{}, resource interface{}) error {
return fmt.Errorf("an error occurred")
}
}

_, err := fh.PatchFHIRServiceRequest(tt.args.ctx, tt.args.id, tt.args.input)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.PatchFHIRServiceRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type FHIRMock struct {
MockGetFHIRPatientEverythingFn func(ctx context.Context, id string, params map[string]interface{}) (*domain.PagedFHIRResource, error)
MockGetFHIRServiceRequestFn func(_ context.Context, id string) (*domain.FHIRServiceRequestRelayPayload, error)
MockCreateFHIRSubscriptionFn func(_ context.Context, subscription *domain.FHIRSubscriptionInput) (*domain.FHIRSubscription, error)
MockPatchFHIRServiceRequestFn func(ctx context.Context, id string, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error)
}

// NewFHIRMock initializes a new instance of FHIR mock
Expand Down Expand Up @@ -469,6 +470,38 @@ func NewFHIRMock() *FHIRMock {
MockUpgradeEpisodeFn: func(ctx context.Context, input domain.OTPEpisodeUpgradeInput) (*domain.EpisodeOfCarePayload, error) {
return &domain.EpisodeOfCarePayload{}, nil
},
MockPatchFHIRServiceRequestFn: func(ctx context.Context, id string, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error) {
ID := gofakeit.UUID()
startTime := scalarutils.DateTime(time.Now().Format("2006-01-02T15:04:05+03:00"))
return &domain.FHIRServiceRequestRelayPayload{
Resource: &domain.FHIRServiceRequest{
ID: &ID,
Status: "active",
Intent: "order",
Category: []*domain.FHIRCodeableConcept{},
Priority: "urgent",
DoNotPerform: new(bool),
Subject: &domain.FHIRReference{
ID: &ID,
Reference: new(string),
Display: "",
},
Encounter: &domain.FHIRReference{
ID: &ID,
Reference: new(string),
Display: "",
},
AuthoredOn: &startTime,
Note: []*domain.FHIRAnnotation{
{
Time: &time.Time{},
Text: (*scalarutils.Markdown)(&ID),
},
},
Meta: &domain.FHIRMeta{},
},
}, nil
},
MockSearchEpisodeEncounterFn: func(ctx context.Context, episodeReference string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIREncounter, error) {
id := gofakeit.UUID()
return &domain.PagedFHIREncounter{
Expand Down Expand Up @@ -2629,3 +2662,8 @@ func (fh *FHIRMock) GetFHIRServiceRequest(ctx context.Context, id string) (*doma
func (fh *FHIRMock) CreateFHIRSubscription(ctx context.Context, subscription *domain.FHIRSubscriptionInput) (*domain.FHIRSubscription, error) {
return fh.MockCreateFHIRSubscriptionFn(ctx, subscription)
}

// PatchFHIRServiceRequest mocks the implementation of mocking patching service request
func (fh *FHIRMock) PatchFHIRServiceRequest(ctx context.Context, id string, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error) {
return fh.MockPatchFHIRServiceRequestFn(ctx, id, input)
}
1 change: 1 addition & 0 deletions pkg/clinical/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type FHIRServiceRequest interface {
CreateFHIRServiceRequest(ctx context.Context, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error)
DeleteFHIRServiceRequest(ctx context.Context, id string) (bool, error)
GetFHIRServiceRequest(ctx context.Context, id string) (*domain.FHIRServiceRequestRelayPayload, error)
PatchFHIRServiceRequest(ctx context.Context, id string, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error)
}
type FHIRMedicationRequest interface {
SearchFHIRMedicationRequest(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRMedicationRequestRelayConnection, error)
Expand Down

0 comments on commit 3ee9765

Please sign in to comment.