Skip to content

Commit

Permalink
feat: create a document resource
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <[email protected]>
  • Loading branch information
KathurimaKimathi committed Apr 8, 2024
1 parent 188ea86 commit b084f1e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
riskAssessmentResourceType = "RiskAssessment"
diagnosticReportResourceType = "DiagnosticReport"
subscriptionResourceType = "Subscription"
documentReferenceResourceType = "DocumentReference"
)

// Dataset ...
Expand Down Expand Up @@ -2069,3 +2070,20 @@ func (fh StoreImpl) CreateFHIRSubscription(_ context.Context, subscription *doma

return fhirSubscription, nil
}

// CreateFHIRDocumentReference method is used to create a document reference resource that provides a reference to a document of any kind for any purpose.
func (fh StoreImpl) CreateFHIRDocumentReference(ctx context.Context, input *domain.FHIRDocumentReferenceInput) (*domain.FHIRDocumentReference, error) {

Check failure on line 2075 in pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReferenceInput

Check failure on line 2075 in pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReference
payload, err := converterandformatter.StructToMap(input)
if err != nil {
return nil, fmt.Errorf("unable to turn %s input into a map: %w", documentReferenceResourceType, err)
}

resource := &domain.FHIRDocumentReference{}

Check failure on line 2081 in pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReference (typecheck)

err = fh.Dataset.CreateFHIRResource(documentReferenceResourceType, payload, resource)
if err != nil {
return nil, fmt.Errorf("unable to create %s resource: %w", documentReferenceResourceType, err)
}

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

func TestStoreImpl_CreateFHIRDocumentReference(t *testing.T) {
type args struct {
ctx context.Context
input *domain.FHIRDocumentReferenceInput
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: create a document reference",
args: args{
ctx: context.Background(),
input: &domain.FHIRDocumentReferenceInput{},
},
wantErr: false,
},
{
name: "Sad case: unable to create a document reference",
args: args{
ctx: context.Background(),
input: &domain.FHIRDocumentReferenceInput{},
},
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 create a document reference" {
dataset.MockCreateFHIRResourceFn = func(resourceType string, payload map[string]interface{}, resource interface{}) error {
return fmt.Errorf("an error occurred")
}
}

_, err := fh.CreateFHIRDocumentReference(tt.args.ctx, tt.args.input)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.CreateFHIRDocumentReference() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
5 changes: 5 additions & 0 deletions pkg/clinical/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,8 @@ type FHIRDiagnosticReport interface {
type FHIRSubscription interface {
CreateFHIRSubscription(_ context.Context, input *domain.FHIRSubscriptionInput) (*domain.FHIRSubscription, error)
}

// FHIRDocumentReference interface contains the method signatures for the various action to be performed against the FHIR Document Reference resource
type FHIRDocumentReference interface {
CreateFHIRDocumentReference(ctx context.Context, input *domain.FHIRDocumentReferenceInput) (*domain.FHIRDocumentReference, error)

Check failure on line 154 in pkg/clinical/repository/repository.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReferenceInput

Check failure on line 154 in pkg/clinical/repository/repository.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReference (typecheck)

Check failure on line 154 in pkg/clinical/repository/repository.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReferenceInput

Check failure on line 154 in pkg/clinical/repository/repository.go

View workflow job for this annotation

GitHub Actions / golangci (1.21.x, ubuntu-latest)

undefined: domain.FHIRDocumentReference) (typecheck)
}

0 comments on commit b084f1e

Please sign in to comment.