Skip to content

Commit

Permalink
feat: get patient everything
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 13, 2024
1 parent 789c60f commit 01716f7
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,3 +1893,20 @@ func (fh StoreImpl) CreateFHIRDiagnosticReport(_ context.Context, input *domain.

return resource, nil
}

// GetFHIRPatientEverything is used to retrieve all patient related information
func (fh StoreImpl) GetFHIRPatientEverything(ctx context.Context, id string) (map[string]interface{}, error) {
patientEverythingBs, err := fh.Dataset.GetFHIRPatientAllData(id)
if err != nil {
return nil, fmt.Errorf("unable to get patient's compartment: %w", err)
}

var patientEverything map[string]interface{}

err = json.Unmarshal(patientEverythingBs, &patientEverything)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal patient everything")
}

return patientEverything, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -4977,3 +4977,131 @@ func TestStoreImpl_SearchFHIRRiskAssessment(t *testing.T) {
})
}
}

func TestStoreImpl_GetFHIRPatientEverything(t *testing.T) {
type args struct {
ctx context.Context
id string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: fetch patient everything",
args: args{
ctx: context.Background(),
id: "1",
},
wantErr: false,
},
{
name: "Sad case: unable to fetch patient everything",
args: args{
ctx: context.Background(),
id: "1",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dataset := fakeDataset.NewFakeFHIRRepositoryMock()
fh := FHIR.NewFHIRStoreImpl(dataset)

if tt.name == "Happy case: fetch patient everything" {
dataset.MockGetFHIRPatientAllDataFn = func(fhirResourceID string) ([]byte, error) {
data := map[string]interface{}{
"entry": []map[string]interface{}{
{
"resource": map[string]interface{}{
"resourceType": "EpisodeOfCare",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Observation",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "AllergyIntolerance",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "ServiceRequest",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "MedicationRequest",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Condition",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Encounter",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Composition",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "MedicationStatement",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Medication",
"id": gofakeit.UUID(),
},
},
{
"resource": map[string]interface{}{
"resourceType": "Patient",
"id": gofakeit.UUID(),
},
},
},
}

bs, err := json.Marshal(data)
if err != nil {
return nil, err
}

return bs, err
}
}
if tt.name == "Sad case: unable to fetch patient everything" {
dataset.MockGetFHIRPatientAllDataFn = func(fhirResourceID string) ([]byte, error) {
return nil, fmt.Errorf("an error occurred")
}
}

_, err := fh.GetFHIRPatientEverything(tt.args.ctx, tt.args.id)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.GetFHIRPatientEverything() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,116 @@ func NewFakeFHIRRepositoryMock() *FakeFHIRRepository {
return nil
},
MockGetFHIRPatientAllDataFn: func(fhirResourceID string) ([]byte, error) {
bs, err := json.Marshal("m")
bs, err := json.Marshal(`
"getPatientEverything": {
"entry": [
{
"fullUrl": "https://healthcare.googleapis.com/v1/projects/speedy-lattice-334/locations/europe-west4/datasets/clinical-testing/fhirStores/clinical-testing/fhir/Patient/2051cdba-6f88-405b-aa51-56e28b75b941",
"resource": {
"active": true,
"birthDate": "2024-03-12",
"gender": "male",
"id": "2051cdba-6f88-405b-aa51-56e28b75b941",
"identifier": [
{
"period": {
"end": "2124-05-27T15:16:04+03:00",
"start": "2024-03-12T15:16:04+03:00"
},
"system": "healthcloud.msisdn",
"type": {
"coding": [
{
"code": "+254701128276",
"display": "+254701128276",
"system": "healthcloud.iddocument",
"userSelected": true,
"version": "0.0.1"
}
],
"text": "+254701128276"
},
"use": "official",
"value": "+254701128276"
}
],
"language": "EN",
"managingOrganization": {
"display": "Chuka",
"id": "8f5c7e78-5d3e-401f-9148-95b4698bfbde",
"reference": "Organization/8f5c7e78-5d3e-401f-9148-95b4698bfbde",
"type": "Organization"
},
"maritalStatus": {
"coding": [
{
"display": "unknown",
"userSelected": true
}
],
"text": "unknown"
},
"meta": {
"lastUpdated": "2024-03-12T15:16:05.080533+00:00",
"tag": [
{
"code": "85e4b0d3-1d69-47ba-b265-579d125f18e5",
"display": "Oregon Health Services",
"system": "http://mycarehub/tenant-identification/organisation",
"userSelected": false,
"version": "1.0"
},
{
"code": "8f5c7e78-5d3e-401f-9148-95b4698bfbde",
"display": "Chuka",
"system": "http://mycarehub/tenant-identification/facility",
"userSelected": false,
"version": "1.0"
}
],
"versionId": "MTcxMDI1NjU2NTA4MDUzMzAwMA"
},
"name": [
{
"family": "Koome",
"given": [
"Brian"
],
"period": {
"end": "2124-05-27T15:16:04+03:00",
"start": "2024-03-12T15:16:04+03:00"
},
"text": "Koome, Brian ",
"use": "official"
}
],
"resourceType": "Patient",
"telecom": [
{
"period": {
"end": "2124-05-27T15:16:04+03:00",
"start": "2024-03-12T15:16:04+03:00"
},
"rank": 2,
"system": "phone",
"use": "home",
"value": "+254701128276"
}
]
}
}
],
"link": [
{
"relation": "next",
"url": "https://healthcare.googleapis.com/v1/projects/speedy-lattice-334/locations/europe-west4/datasets/clinical-testing/fhirStores/clinical-testing/fhir/Patient/2051cdba-6f88-405b-aa51-56e28b75b941/$everything?_count=1&_page_token=CpoBcHJvamVjdHMvc3BlZWR5LWxhdHRpY2UtMzM0L2xvY2F0aW9ucy9ldXJvcGUtd2VzdDQvZGF0YXNldHMvY2xpbmljYWwtdGVzdGluZy9maGlyU3RvcmVzL2NsaW5pY2FsLXRlc3RpbmcvZmhpci9QYXRpZW50LzIwNTFjZGJhLTZmODgtNDA1Yi1hYTUxLTU2ZTI4Yjc1Yjk0MSAB"
}
],
"resourceType": "Bundle",
"total": 4,
"type": "searchset"
}
}`)
if err != nil {
return nil, fmt.Errorf("unable to marshal map to JSON: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type FHIRMock struct {
MockGetFHIRQuestionnaireResponseFn func(ctx context.Context, id string) (*domain.FHIRQuestionnaireResponseRelayPayload, error)
MockCreateFHIRDiagnosticReportFn func(_ context.Context, input *domain.FHIRDiagnosticReportInput) (*domain.FHIRDiagnosticReport, error)
MockSearchFHIREncounterAllDataFn func(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRResource, error)
MockGetFHIRPatientEverythingFn func(ctx context.Context, id string) (map[string]interface{}, error)
}

// NewFHIRMock initializes a new instance of FHIR mock
Expand Down Expand Up @@ -2090,6 +2091,15 @@ func NewFHIRMock() *FHIRMock {
TotalCount: 0,
}, nil
},
MockGetFHIRPatientEverythingFn: func(ctx context.Context, id string) (map[string]interface{}, error) {
return map[string]interface{}{
"resourceType": "Patient",
"active": true,
"birthDate": "2024-03-12",
"gender": "male",
"id": "1",
}, nil
},
}
}

Expand Down Expand Up @@ -2442,3 +2452,8 @@ func (fh *FHIRMock) CreateFHIRDiagnosticReport(ctx context.Context, input *domai
func (fh *FHIRMock) SearchFHIREncounterAllData(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRResource, error) {
return fh.MockSearchFHIREncounterAllDataFn(ctx, params, tenant, pagination)
}

// GetFHIRPatientEverything mocks the implementation of getting all the patient information
func (fh *FHIRMock) GetFHIRPatientEverything(ctx context.Context, id string) (map[string]interface{}, error) {
return fh.MockGetFHIRPatientEverythingFn(ctx, id)
}
2 changes: 2 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ extend type Query {
encounterID: String!
screeningType: ScreeningTypeEnum!
): String!

getPatientEverything(patientID: String!): Map!
}

extend type Mutation {
Expand Down
7 changes: 7 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 01716f7

Please sign in to comment.