Skip to content

Commit

Permalink
fix: fetch facility by ID from health CRM. (#977)
Browse files Browse the repository at this point in the history
- remove the action of checking if the facility existed in MCH

Signed-off-by: Kathurima Kimathi <[email protected]>
  • Loading branch information
KathurimaKimathi authored Nov 29, 2023
1 parent ae1c807 commit 00eada7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
16 changes: 1 addition & 15 deletions pkg/mycarehub/usecases/facility/facility.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,12 @@ func (f *UseCaseFacilityImpl) RetrieveFacility(ctx context.Context, id *string,
if id == nil {
return nil, fmt.Errorf("facility id cannot be nil")
}
output, err := f.Query.RetrieveFacility(ctx, id, isActive)
output, err := f.HealthCRM.GetCRMFacilityByID(ctx, *id)
if err != nil {
helpers.ReportErrorToSentry(err)
return nil, err
}

for _, identifier := range output.Identifiers {
if identifier.Type == enums.FacilityIdentifierTypeHealthCRM {
// Get facility Business hours
facilityObj, err := f.HealthCRM.GetCRMFacilityByID(ctx, identifier.Value)
if err != nil {
helpers.ReportErrorToSentry(err)
return nil, err
}

output.Services = facilityObj.Services
output.BusinessHours = facilityObj.BusinessHours
}
}

return output, nil
}

Expand Down
23 changes: 1 addition & 22 deletions pkg/mycarehub/usecases/facility/facility_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,9 @@ func TestUseCaseFacilityImpl_RetrieveFacility_Unittest(t *testing.T) {
},
wantErr: true,
},
{
name: "Sad case - unable to get facility business hours",
args: args{
ctx: ctx,
id: &ID,
isActive: false,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeFacility := mock.NewFacilityUsecaseMock()

fakeDB := pgMock.NewPostgresMock()
fakePubsub := pubsubMock.NewPubsubServiceMock()
fakeExt := extensionMock.NewFakeExtension()
Expand All @@ -86,19 +75,9 @@ func TestUseCaseFacilityImpl_RetrieveFacility_Unittest(t *testing.T) {

f := facility.NewFacilityUsecase(fakeDB, fakeDB, fakeDB, fakeDB, fakePubsub, fakeExt, fakeHealthCRM, fakeServiceRequest)

if tt.name == "Sad case - no id" {
fakeFacility.MockRetrieveFacilityFn = func(ctx context.Context, id *string, isActive bool) (*domain.Facility, error) {
return nil, fmt.Errorf("an error occurred while retrieving facility")
}
}
if tt.name == "Sad case - unable to retrieve facility by id" {
fakeDB.MockRetrieveFacilityFn = func(ctx context.Context, id *string, isActive bool) (*domain.Facility, error) {
return nil, fmt.Errorf("error")
}
}
if tt.name == "Sad case - unable to get facility business hours" {
fakeHealthCRM.MockGetCRMFacilityByIDFn = func(ctx context.Context, id string) (*domain.Facility, error) {
return nil, fmt.Errorf("error")
return nil, errors.New("error")
}
}

Expand Down

0 comments on commit 00eada7

Please sign in to comment.