Skip to content

Commit

Permalink
feat: add date filter on conditions
Browse files Browse the repository at this point in the history
- adds date filter as a search param for conditions
  • Loading branch information
EspiraMarvin committed Dec 8, 2023
1 parent be73e16 commit a9eff40
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 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 @@ -8,6 +8,7 @@ extend type Query {
listPatientConditions(
patientID: ID!
encounterID: String
date: Date
pagination: Pagination!
): ConditionConnection

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.

6 changes: 5 additions & 1 deletion pkg/clinical/usecases/clinical/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func mapFHIRConditionToConditionDTO(condition domain.FHIRCondition) *dto.Conditi

// ListPatientConditions lists a patients conditions
// TODO: pagination
func (c UseCasesClinicalImpl) ListPatientConditions(ctx context.Context, patientID string, encounterID *string, pagination dto.Pagination) (*dto.ConditionConnection, error) {
func (c UseCasesClinicalImpl) ListPatientConditions(ctx context.Context, patientID string, encounterID *string, date *scalarutils.Date, pagination dto.Pagination) (*dto.ConditionConnection, error) {
_, err := uuid.Parse(patientID)
if err != nil {
return nil, fmt.Errorf("invalid patient id: %s", patientID)
Expand Down Expand Up @@ -212,6 +212,10 @@ func (c UseCasesClinicalImpl) ListPatientConditions(ctx context.Context, patient
params["encounter"] = encounterReference
}

if date != nil {
params["recorded-date"] = date.AsTime().Format(dateFormatStr)
}

conditionsResponse, err := c.infrastructure.FHIR.SearchFHIRCondition(ctx, params, *identifiers, pagination)
if err != nil {
return nil, err
Expand Down
17 changes: 16 additions & 1 deletion pkg/clinical/usecases/clinical/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func TestUseCasesClinicalImpl_ListPatientConditions(t *testing.T) {
ctx context.Context
patientID string
encounterID *string
date *scalarutils.Date
pagination dto.Pagination
}
tests := []struct {
Expand All @@ -491,6 +492,20 @@ func TestUseCasesClinicalImpl_ListPatientConditions(t *testing.T) {
},
wantErr: false,
},
{
name: "happy case: list conditions with date",
args: args{
ctx: context.Background(),
patientID: gofakeit.UUID(),
date: &scalarutils.Date{
Year: 2013,
Month: 12,
Day: 8,
},
pagination: dto.Pagination{},
},
wantErr: false,
},
{
name: "sad case: invalid patient id",
args: args{
Expand Down Expand Up @@ -569,7 +584,7 @@ func TestUseCasesClinicalImpl_ListPatientConditions(t *testing.T) {
}
}

got, err := c.ListPatientConditions(tt.args.ctx, tt.args.patientID, tt.args.encounterID, tt.args.pagination)
got, err := c.ListPatientConditions(tt.args.ctx, tt.args.patientID, tt.args.encounterID, tt.args.date, tt.args.pagination)
if (err != nil) != tt.wantErr {
t.Errorf("ListPatientConditions() 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 @@ -21,7 +21,7 @@ type Clinical interface {
EndEpisodeOfCare(ctx context.Context, id string) (*dto.EpisodeOfCare, error)

CreateCondition(ctx context.Context, input dto.ConditionInput) (*dto.Condition, error)
ListPatientConditions(ctx context.Context, patientID string, encounterID *string, pagination dto.Pagination) (*dto.ConditionConnection, error)
ListPatientConditions(ctx context.Context, patientID string, encounterID *string, date *scalarutils.Date, pagination dto.Pagination) (*dto.ConditionConnection, error)

PatientHealthTimeline(ctx context.Context, input dto.HealthTimelineInput) (*dto.HealthTimeline, error)
GetMedicalData(ctx context.Context, patientID string) (*dto.MedicalData, error)
Expand Down

0 comments on commit a9eff40

Please sign in to comment.