Skip to content

Commit

Permalink
fix: return test results as part of encounter associated resources
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Mar 4, 2024
1 parent 28d3217 commit 34e0bd4
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/clinical/application/dto/encounter_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ func CreateEncounterConnection(encounters []*Encounter, pageInfo PageInfo, total
type EncounterAssociatedResources struct {
RiskAssessment *RiskAssessment `json:"riskAssesment"`
Consent *Consent `json:"consent"`
Observation *Observation `json:"observation"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,33 @@ func NewFHIRMock() *FHIRMock {
}, nil
},
MockSearchFHIREncounterAllDataFn: func(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRResource, error) {
return &domain.PagedFHIRResource{}, nil
return &domain.PagedFHIRResource{
Resources: []map[string]interface{}{
{
"resourceType": "RiskAssessment",
"id": "1234",
"status": "final",
},
{
"resourceType": "Consent",
"id": "5678",
"provision": map[string]interface{}{
"type": "permit",
},
},
{
"resourceType": "Observation",
"id": "9012",
"status": "final",
"valueString": "Positive",
},
},
HasNextPage: false,
NextCursor: "",
HasPreviousPage: false,
PreviousCursor: "",
TotalCount: 0,
}, nil
},
}
}
Expand Down
74 changes: 74 additions & 0 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.

1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,5 @@ type RiskAssessmentPrediction {
type EncounterAssociatedResources {
riskAssessment: RiskAssessment
consent: Consent
observation: Observation
}
26 changes: 25 additions & 1 deletion pkg/clinical/usecases/clinical/encounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,17 @@ func (c *UseCasesClinicalImpl) GetEncounterAssociatedResources(ctx context.Conte
return nil, fmt.Errorf("failed to get tenant identifiers from context: %w", err)
}

includedResources := []string{
"RiskAssessment:encounter",
"Consent:data",
"Observation:encounter",
}

encounterSearchParams := map[string]interface{}{
"_id": encounterID,
"_sort": "date",
"_count": "1",
"_revinclude": []string{"RiskAssessment:encounter", "Consent:data"},
"_revinclude": includedResources,
}

encounterAllData, err := c.infrastructure.FHIR.SearchFHIREncounterAllData(ctx, encounterSearchParams, *identifiers, dto.Pagination{})
Expand Down Expand Up @@ -244,6 +250,24 @@ func (c *UseCasesClinicalImpl) GetEncounterAssociatedResources(ctx context.Conte
}

result.Consent = &consent

case "Observation":
var observation domain.FHIRObservation

observationBytes, err := json.Marshal(encounterData)
if err != nil {
return nil, err
}

if err := json.Unmarshal(observationBytes, &observation); err != nil {
return nil, err
}

result.Observation = &dto.Observation{
ID: *observation.ID,
Value: *observation.ValueString,
Status: dto.ObservationStatus(*observation.Status),
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/clinical/usecases/clinical/encounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ func TestUseCasesClinicalImpl_GetEncounterAssociatedResources(t *testing.T) {
},
wantErr: true,
},
{
name: "Sad Case - unable to search all fhir encounter data",
args: args{
ctx: ctx,
encounterID: uuid.New().String(),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -457,6 +465,11 @@ func TestUseCasesClinicalImpl_GetEncounterAssociatedResources(t *testing.T) {
return nil, fmt.Errorf("failed to get encounter")
}
}
if tt.name == "Sad Case - unable to search all fhir encounter data" {
fakeFHIR.MockSearchFHIREncounterAllDataFn = func(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRResource, error) {
return nil, fmt.Errorf("an error occurred")
}
}

got, err := u.GetEncounterAssociatedResources(tt.args.ctx, tt.args.encounterID)
if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit 34e0bd4

Please sign in to comment.