Skip to content

Commit

Permalink
query compositions with encounterID
Browse files Browse the repository at this point in the history
  • Loading branch information
EspiraMarvin committed Dec 5, 2023
1 parent e7906ed commit 5e9253b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extend type Query {
# Compositions
listPatientCompositions(
patientID: ID!
encounterID: String
pagination: Pagination!
): CompositionConnection

Expand Down
4 changes: 2 additions & 2 deletions pkg/clinical/presentation/graph/clinical.resolvers.go

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

24 changes: 17 additions & 7 deletions pkg/clinical/presentation/graph/generated/generated.go

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

8 changes: 6 additions & 2 deletions pkg/clinical/usecases/clinical/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (c *UseCasesClinicalImpl) CreateComposition(ctx context.Context, input dto.

encounterRef := fmt.Sprintf("Encounter/%s", *encounter.Resource.ID)
encounterType := scalarutils.URI("Encounter")

organizationRef := fmt.Sprintf("Organization/%s", identifiers.OrganizationID)

today := time.Now()
Expand Down Expand Up @@ -174,7 +173,7 @@ func mapFHIRCompositionToCompositionDTO(composition domain.FHIRComposition) *dto
}

// ListPatientCompositions lists a patient's compositions
func (c UseCasesClinicalImpl) ListPatientCompositions(ctx context.Context, patientID string, pagination dto.Pagination) (*dto.CompositionConnection, error) {
func (c UseCasesClinicalImpl) ListPatientCompositions(ctx context.Context, patientID string, encounterID *string, pagination dto.Pagination) (*dto.CompositionConnection, error) {
_, err := uuid.Parse(patientID)
if err != nil {
return nil, fmt.Errorf("invalid patient id: %s", patientID)
Expand All @@ -201,6 +200,11 @@ func (c UseCasesClinicalImpl) ListPatientCompositions(ctx context.Context, patie
"_sort": "date",
}

if encounterID != nil {
encounterReference := fmt.Sprintf("Encounter/%s", *encounterID)
params["encounter"] = encounterReference
}

compositionsResponse, err := c.infrastructure.FHIR.SearchFHIRComposition(ctx, params, *identifiers, pagination)
if err != nil {
return nil, err
Expand Down
20 changes: 16 additions & 4 deletions pkg/clinical/usecases/clinical/composition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,12 @@ func TestUseCasesClinicalImpl_CreateComposition(t *testing.T) {

func TestUseCasesClinicalImpl_ListPatientCompositions(t *testing.T) {
first := 3
EncounterID := uuid.New().String()
type args struct {
ctx context.Context
patientID string
pagination dto.Pagination
ctx context.Context
patientID string
encounterID *string
pagination dto.Pagination
}
tests := []struct {
name string
Expand All @@ -342,6 +344,16 @@ func TestUseCasesClinicalImpl_ListPatientCompositions(t *testing.T) {
},
wantErr: false,
},
{
name: "happy case: list compositions with encounterID",
args: args{
ctx: context.Background(),
patientID: gofakeit.UUID(),
encounterID: &EncounterID,
pagination: dto.Pagination{},
},
wantErr: false,
},
{
name: "sad case: invalid patient id",
args: args{
Expand Down Expand Up @@ -425,7 +437,7 @@ func TestUseCasesClinicalImpl_ListPatientCompositions(t *testing.T) {
return nil, fmt.Errorf("failed to find condition")
}
}
got, err := c.ListPatientCompositions(tt.args.ctx, tt.args.patientID, tt.args.pagination)
got, err := c.ListPatientCompositions(tt.args.ctx, tt.args.patientID, tt.args.encounterID, tt.args.pagination)
if (err != nil) != tt.wantErr {
t.Errorf("ListPatientCompositions() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/usecases/usecases.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Clinical interface {
ListPatientMedia(ctx context.Context, patientID string, pagination dto.Pagination) (*dto.MediaConnection, error)

CreateComposition(ctx context.Context, input dto.CompositionInput) (*dto.Composition, error)
ListPatientCompositions(ctx context.Context, patientID string, pagination dto.Pagination) (*dto.CompositionConnection, error)
ListPatientCompositions(ctx context.Context, patientID string, encounterID *string, pagination dto.Pagination) (*dto.CompositionConnection, error)
}

// Interactor is an implementation of the usecases interface
Expand Down

0 comments on commit 5e9253b

Please sign in to comment.