Skip to content

Commit

Permalink
test: usecase unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Muchogoc committed Mar 13, 2023
1 parent c4fae09 commit 123ac31
Show file tree
Hide file tree
Showing 5 changed files with 702 additions and 122 deletions.
1 change: 0 additions & 1 deletion pkg/clinical/presentation/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Clinical interface {
FindOrganizationByID(ctx context.Context, organizationID string) (*domain.FHIROrganizationRelayPayload, error)

CreateFHIROrganization(ctx context.Context, input domain.FHIROrganizationInput) (*domain.FHIROrganizationRelayPayload, error)
PatientTimeline(ctx context.Context, patientID string, count int) ([]map[string]interface{}, error)
PatientHealthTimeline(ctx context.Context, input domain.HealthTimelineInput) (*domain.HealthTimeline, error)
GetMedicalData(ctx context.Context, patientID string) (*domain.MedicalData, error)
}
Expand Down
44 changes: 0 additions & 44 deletions pkg/clinical/usecases/clinical/config_test.go

This file was deleted.

24 changes: 8 additions & 16 deletions pkg/clinical/usecases/clinical/patient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

linq "github.com/ahmetb/go-linq/v3"
"github.com/google/uuid"
"github.com/savannahghi/clinical/pkg/clinical/application/common"
"github.com/savannahghi/clinical/pkg/clinical/application/common/helpers"
"github.com/savannahghi/clinical/pkg/clinical/application/utils"
Expand All @@ -15,20 +16,6 @@ import (
log "github.com/sirupsen/logrus"
)

// constants and defaults
const (
// LimitedProfileEncounterCount is the number of encounters to show when a
// patient has approved limited access to their health record
LimitedProfileEncounterCount = 5

RelationshipSystem = "http://terminology.hl7.org/CodeSystem/v2-0131"
RelationshipVersion = "2.9"
StringTimeParseMonthNameLayout = "2006-Jan-02"
StringTimeParseMonthNumberLayout = "2006-01-02"
SavannahAdminEmail = "SAVANNAH_ADMIN_EMAIL"
TwilioSMSNumberEnvVarName = "TWILIO_SMS_NUMBER"
)

// UseCasesClinicalImpl represents the patient usecase implementation
type UseCasesClinicalImpl struct {
infrastructure infrastructure.Infrastructure
Expand All @@ -43,7 +30,12 @@ func NewUseCasesClinicalImpl(infra infrastructure.Infrastructure) *UseCasesClini

// PatientTimeline return's the patient's historical timeline sorted in descending order i.e when it was first recorded
// The timeline consists of Allergies, Observations, Medication statement and Test results
func (c *UseCasesClinicalImpl) PatientTimeline(ctx context.Context, patientID string, count int) ([]map[string]interface{}, error) {
func (c *UseCasesClinicalImpl) PatientTimeline(ctx context.Context, patientID string) ([]map[string]interface{}, error) {
_, err := uuid.Parse(patientID)
if err != nil {
return nil, fmt.Errorf("invalid patient id: %s", patientID)
}

timeline := []map[string]interface{}{}
wg := &sync.WaitGroup{}
mut := &sync.Mutex{}
Expand Down Expand Up @@ -312,7 +304,7 @@ func (c *UseCasesClinicalImpl) GetMedicalData(ctx context.Context, patientID str
// PatientHealthTimeline return's the patient's historical timeline sorted in descending order i.e when it was first recorded
// The timeline consists of Allergies, Observations, Medication statement and Test results
func (c *UseCasesClinicalImpl) PatientHealthTimeline(ctx context.Context, input domain.HealthTimelineInput) (*domain.HealthTimeline, error) {
records, err := c.PatientTimeline(ctx, input.PatientID, 0)
records, err := c.PatientTimeline(ctx, input.PatientID)
if err != nil {
utils.ReportErrorToSentry(err)
return nil, fmt.Errorf("cannot retrieve patient timeline error: %w", err)
Expand Down

0 comments on commit 123ac31

Please sign in to comment.