Skip to content

Commit

Permalink
feat: append notes to composition section
Browse files Browse the repository at this point in the history
- adds appending various notes to the composition section
  • Loading branch information
EspiraMarvin committed Jan 15, 2024
1 parent abc9738 commit ad319ef
Show file tree
Hide file tree
Showing 20 changed files with 1,814 additions and 87 deletions.
1 change: 0 additions & 1 deletion gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ models:
PatchPatientInput:
model:
- github.com/savannahghi/clinical/pkg/clinical/application/dto.PatientInput

Date:
model:
- "github.com/savannahghi/scalarutils.Date"
15 changes: 15 additions & 0 deletions pkg/clinical/application/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ const (

// LOINCAssessmentPlanCode defines LOINC assessment plan note terminology code
LOINCAssessmentPlanCode = "51847-2"

// LOINCHistoryOfPresentingIllness defines LOINC history of presenting illness note terminology code
LOINCHistoryOfPresentingIllness = "10164-2"

// LOINCSocialHistory defines LOINC social history note terminology code
LOINCSocialHistory = "29762-2"

// LOINCFamilyHistory defines LOINC family history note terminology code
LOINCFamilyHistory = "10157-6"

// LOINCExamination defines LOINC Examination note terminology code
LOINCExamination = "29545-1"

// LOINCPLANOFCARE defines LOINC Plan of care note terminology code
LOINCPLANOFCARE = "18776-5"
)

// DefaultIdentifier assigns a patient a code to function as their
Expand Down
1 change: 1 addition & 0 deletions pkg/clinical/application/dto/composition_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Composition struct {
EncounterID string `json:"encounterID,omitempty"`
Date *scalarutils.Date `json:"date"`
Author string `json:"author,omitempty"`
Section []*Section `json:"section"`
}

// CompositionEdge is a composition edge
Expand Down
7 changes: 6 additions & 1 deletion pkg/clinical/application/dto/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ const (
type CompositionCategory string

const (
AssessmentAndPlan CompositionCategory = "ASSESSMENT_PLAN"
AssessmentAndPlan CompositionCategory = "ASSESSMENT_PLAN"
HistoryOfPresentingIllness CompositionCategory = "HISTORY_OF_PRESENTING_ILLNESS"
SocialHistory CompositionCategory = "SOCIAL_HISTORY"
FamilyHistory CompositionCategory = "FAMILY_HISTORY"
Examination CompositionCategory = "EXAMINATION"
PlanOfCare CompositionCategory = "PLAN_OF_CARE"
)

// Type enum represents type composition attribute
Expand Down
19 changes: 19 additions & 0 deletions pkg/clinical/application/dto/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,22 @@ type CompositionInput struct {
Status CompositionStatusEnum `json:"status"`
Note string `json:"note"`
}

// PatchCompositionInput models the patch composition input
type PatchCompositionInput struct {
Type CompositionType `json:"type"`
Category CompositionCategory `json:"category"`
Status CompositionStatusEnum `json:"status"`
Note string `json:"note"`
Section []*SectionInput `json:"section"`
}

// SectionInput models the composition section input
type SectionInput struct {
ID string `json:"id,omitempty"`
Title string `json:"title"`
Code string `json:"code"`
Author string `json:"author"`
Text string `json:"text"`
Section []*SectionInput `json:"section"`
}
10 changes: 10 additions & 0 deletions pkg/clinical/application/dto/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,13 @@ func CreateMediaConnection(mediaList []*Media, pageInfo PageInfo, total int) Med

return connection
}

// Section defines a composition section output model
type Section struct {
ID *string `json:"id,omitempty"`
Title *string `json:"title,omitempty"`
Code *string `json:"code,omitempty"`
Author *string `json:"author,omitempty"`
Text string `json:"text,omitempty"`
Section []*Section `json:"section,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/clinical/domain/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ type FHIRCompositionInput struct {
Section []*FHIRCompositionSectionInput `json:"section,omitempty"`

// Meta stores more information about the resource
Meta FHIRMetaInput `json:"meta,omitempty"`
Meta *FHIRMetaInput `json:"meta,omitempty"`

// Extension is an optional element that provides additional information not captured in the basic resource definition
Extension []*FHIRExtension `json:"extension,omitempty"`
Expand Down
41 changes: 35 additions & 6 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func (fh StoreImpl) CreateFHIRComposition(_ context.Context, input domain.FHIRCo

// UpdateFHIRComposition updates a FHIRComposition instance
// The resource must have its ID set.
func (fh StoreImpl) UpdateFHIRComposition(_ context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error) {
func (fh StoreImpl) UpdateFHIRComposition(_ context.Context, input domain.FHIRCompositionInput) (*domain.FHIRComposition, error) {
if input.ID == nil {
return nil, fmt.Errorf("can't update with a nil ID")
}
Expand All @@ -882,11 +882,7 @@ func (fh StoreImpl) UpdateFHIRComposition(_ context.Context, input domain.FHIRCo
return nil, fmt.Errorf("unable to create/update %s resource: %w", compositionResourceType, err)
}

output := &domain.FHIRCompositionRelayPayload{
Resource: resource,
}

return output, nil
return resource, nil
}

// DeleteFHIRComposition deletes the FHIRComposition identified by the supplied ID
Expand Down Expand Up @@ -1620,3 +1616,36 @@ func (fh StoreImpl) SearchFHIRPatient(_ context.Context, searchParams string, te

return &output, nil
}

// GetFHIRComposition retrieves instances of FHIRComposition by ID
func (fh StoreImpl) GetFHIRComposition(_ context.Context, id string) (*domain.FHIRCompositionRelayPayload, error) {
resource := &domain.FHIRComposition{}

err := fh.Dataset.GetFHIRResource(compositionResourceType, id, resource)
if err != nil {
return nil, fmt.Errorf("unable to get %s with ID %s, err: %w", compositionResourceType, id, err)
}

payload := &domain.FHIRCompositionRelayPayload{
Resource: resource,
}

return payload, nil
}

// PatchFHIRComposition is used to patch a composition resource
func (fh StoreImpl) PatchFHIRComposition(_ context.Context, id string, input domain.FHIRCompositionInput) (*domain.FHIRComposition, error) {
payload, err := converterandformatter.StructToMap(input)
if err != nil {
return nil, fmt.Errorf("unable to turn %s input into a map: %w", compositionResourceType, err)
}

resource := &domain.FHIRComposition{}

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

return resource, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,57 @@ func TestStoreImpl_CreateFHIRComposition(t *testing.T) {
})
}
}
func TestStoreImpl_GetFHIRComposition(t *testing.T) {

type args struct {
ctx context.Context
id string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "happy case: get composition",
args: args{
ctx: context.Background(),
id: uuid.NewString(),
},
wantErr: false,
},
{
name: "sad case: error retrieving fhir resource",
args: args{
ctx: context.Background(),
id: uuid.NewString(),
},
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: error retrieving fhir resource" {
dataset.MockGetFHIRResourceFn = func(resourceType, fhirResourceID string, resource interface{}) error {
return fmt.Errorf("an error occurred")
}
}

got, err := fh.GetFHIRComposition(tt.args.ctx, tt.args.id)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.GetFHIRComposition() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && got == nil {
t.Errorf("expected a response but got: %v", got)
return
}
})
}
}

func TestStoreImpl_UpdateFHIRComposition(t *testing.T) {

Expand Down

0 comments on commit ad319ef

Please sign in to comment.