Skip to content

Commit

Permalink
list patient's compositions (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
EspiraMarvin committed Oct 19, 2023
1 parent b47a7a7 commit 3e6e888
Show file tree
Hide file tree
Showing 15 changed files with 937 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pkg/clinical/application/dto/allergy_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type AllergyConnection struct {
PageInfo PageInfo
}

// CreateConditionConnection creates a connection that follows the GraphQl Cursor Connection Specification
// CreateAllergyConnection creates a connection that follows the GraphQl Cursor Connection Specification
func CreateAllergyConnection(allergies []*Allergy, pageInfo PageInfo, total int) AllergyConnection {
connection := AllergyConnection{
TotalCount: total,
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/application/dto/composition_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type CompositionConnection struct {
PageInfo PageInfo
}

// CreateConditionConnection creates a connection that follows the GraphQl Cursor Connection Specification
// CreateCompositionConnection creates a connection that follows the GraphQl Cursor Connection Specification
func CreateCompositionConnection(compositions []Composition, pageInfo PageInfo, total int) CompositionConnection {
connection := CompositionConnection{
TotalCount: total,
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/application/dto/observation_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ObservationConnection struct {
PageInfo PageInfo
}

// CreateConditionConnection creates a connection that follows the GraphQl Cursor Connection Specification
// CreateObservationConnection creates a connection that follows the GraphQl Cursor Connection Specification
func CreateObservationConnection(observations []*Observation, pageInfo PageInfo, total int) ObservationConnection {
connection := ObservationConnection{
TotalCount: total,
Expand Down
10 changes: 10 additions & 0 deletions pkg/clinical/domain/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ type FHIRCompositionRelayEdge struct {
Node *FHIRComposition `json:"node,omitempty"`
}

// PagedFHIRComposition ...
type PagedFHIRComposition struct {
Compositions []FHIRComposition
HasNextPage bool
NextCursor string
HasPreviousPage bool
PreviousCursor string
TotalCount int
}

// FHIRCompositionRelayPayload is used to return single instances of Composition
type FHIRCompositionRelayPayload struct {
Resource *FHIRComposition `json:"resource,omitempty"`
Expand Down
17 changes: 11 additions & 6 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,21 @@ func (fh StoreImpl) UpdateFHIRAllergyIntolerance(_ context.Context, input domain
}

// SearchFHIRComposition provides a search API for FHIRComposition
func (fh StoreImpl) SearchFHIRComposition(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRCompositionRelayConnection, error) {
output := domain.FHIRCompositionRelayConnection{}

func (fh StoreImpl) SearchFHIRComposition(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRComposition, error) {
resources, err := fh.Dataset.SearchFHIRResource(compositionResourceType, params, tenant, pagination)
if err != nil {
return nil, err
}

output := domain.PagedFHIRComposition{
Compositions: []domain.FHIRComposition{},
HasNextPage: resources.HasNextPage,
NextCursor: resources.NextCursor,
HasPreviousPage: resources.HasPreviousPage,
PreviousCursor: resources.PreviousCursor,
TotalCount: resources.TotalCount,
}

for _, result := range resources.Resources {
var resource domain.FHIRComposition

Expand All @@ -835,9 +842,7 @@ func (fh StoreImpl) SearchFHIRComposition(_ context.Context, params map[string]i
"server error: Unable to unmarshal %s: %w", compositionResourceType, err)
}

output.Edges = append(output.Edges, &domain.FHIRCompositionRelayEdge{
Node: &resource,
})
output.Compositions = append(output.Compositions, resource)
}

return &output, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type FHIRMock struct {
MockSearchFHIRAllergyIntoleranceFn func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRAllergy, error)
MockCreateFHIRAllergyIntoleranceFn func(ctx context.Context, input domain.FHIRAllergyIntoleranceInput) (*domain.FHIRAllergyIntoleranceRelayPayload, error)
MockUpdateFHIRAllergyIntoleranceFn func(ctx context.Context, input domain.FHIRAllergyIntoleranceInput) (*domain.FHIRAllergyIntoleranceRelayPayload, error)
MockSearchFHIRCompositionFn func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRCompositionRelayConnection, error)
MockSearchFHIRCompositionFn func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRComposition, error)
MockCreateFHIRCompositionFn func(ctx context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error)
MockUpdateFHIRCompositionFn func(ctx context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error)
MockDeleteFHIRCompositionFn func(ctx context.Context, id string) (bool, error)
Expand Down Expand Up @@ -649,8 +649,112 @@ func NewFHIRMock() *FHIRMock {
MockUpdateFHIRAllergyIntoleranceFn: func(ctx context.Context, input domain.FHIRAllergyIntoleranceInput) (*domain.FHIRAllergyIntoleranceRelayPayload, error) {
return &domain.FHIRAllergyIntoleranceRelayPayload{}, nil
},
MockSearchFHIRCompositionFn: func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRCompositionRelayConnection, error) {
return &domain.FHIRCompositionRelayConnection{}, nil
MockSearchFHIRCompositionFn: func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRComposition, error) {
id := gofakeit.UUID()
compositionTitle := gofakeit.Name() + "assessment note"
typeSystem := scalarutils.URI("http://hl7.org/fhir/ValueSet/doc-typecodes")
categorySystem := scalarutils.URI("http://hl7.org/fhir/ValueSet/referenced-item-category")
category := "Assessment + plan"
compositionType := "Progress note"
compositionCategory := "Treatment Plan"
compositionStatus := "active"
note := scalarutils.Markdown("Fever Fever")
PatientRef := "Patient/" + uuid.NewString()
patientType := "Patient"
organizationRef := "Organization/" + uuid.NewString()
compositionSectionTextStatus := "generated"

composition := domain.FHIRComposition{
ID: &id,
Text: &domain.FHIRNarrative{
ID: &id,
Status: (*domain.NarrativeStatusEnum)(&compositionSectionTextStatus),
Div: scalarutils.XHTML(note),
},
Identifier: &domain.FHIRIdentifier{},
Status: (*domain.CompositionStatusEnum)(&compositionStatus),
Type: &domain.FHIRCodeableConcept{
ID: new(string),
Coding: []*domain.FHIRCoding{
{
ID: &id,
System: &typeSystem,
Code: scalarutils.Code(string(common.LOINCProgressNoteCode)),
Display: compositionType,
},
},
Text: compositionType,
},
Category: []*domain.FHIRCodeableConcept{
{
ID: new(string),
Coding: []*domain.FHIRCoding{
{
ID: &id,
System: &categorySystem,
Version: new(string),
Code: scalarutils.Code(string(common.LOINCAssessmentPlanCode)),
Display: category,
},
},
Text: compositionCategory,
},
},
Subject: &domain.FHIRReference{
ID: &id,
Reference: &PatientRef,
Type: (*scalarutils.URI)(&patientType),
},
Encounter: &domain.FHIRReference{
ID: &id,
},
Date: &scalarutils.Date{
Year: 2023,
Month: 9,
Day: 25,
},
Author: []*domain.FHIRReference{
{
Reference: &organizationRef,
},
},
Title: &compositionTitle,
Section: []*domain.FHIRCompositionSection{
{
ID: &id,
Title: &compositionCategory,
Code: &domain.FHIRCodeableConceptInput{
ID: new(string),
Coding: []*domain.FHIRCodingInput{
{
ID: &id,
System: &categorySystem,
Version: new(string),
Code: scalarutils.Code(string(common.LOINCAssessmentPlanCode)),
Display: category,
},
},
Text: "Assessment + plan",
},
Author: []*domain.FHIRReference{
{
Reference: new(string),
},
},
Text: &domain.FHIRNarrative{
ID: &id,
Status: (*domain.NarrativeStatusEnum)(&compositionSectionTextStatus),
Div: scalarutils.XHTML(note),
},
},
},
}

return &domain.PagedFHIRComposition{
Compositions: []domain.FHIRComposition{composition},
HasNextPage: false,
HasPreviousPage: false,
}, nil
},
MockCreateFHIRCompositionFn: func(ctx context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error) {
UUID := uuid.New().String()
Expand Down Expand Up @@ -1414,7 +1518,7 @@ func (fh *FHIRMock) UpdateFHIRAllergyIntolerance(ctx context.Context, input doma
}

// SearchFHIRComposition is a mock implementation of SearchFHIRComposition method
func (fh *FHIRMock) SearchFHIRComposition(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRCompositionRelayConnection, error) {
func (fh *FHIRMock) SearchFHIRComposition(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRComposition, error) {
return fh.MockSearchFHIRCompositionFn(ctx, params, tenant, pagination)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ extend type Query {
pagination: Pagination!
): ConditionConnection

# Compositions
listPatientCompositions(
patientID: ID!
pagination: Pagination!
): CompositionConnection

# Encounter
listPatientEncounters(
patientID: String!
Expand Down
6 changes: 6 additions & 0 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.

Loading

0 comments on commit 3e6e888

Please sign in to comment.