Skip to content

Commit

Permalink
refactor: add tenant identifiers when creating FHIR document referenc…
Browse files Browse the repository at this point in the history
…e resource

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Apr 11, 2024
1 parent 3cac70f commit 840737b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/clinical/usecases/clinical/referral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
TerminologySystem: common.ReferralNoteLOINCTerminologySystem,
}

_, err = c.CreateDocumentReference(ctx, payload)
err = c.CreateDocumentReference(ctx, payload)
if err != nil {
utils.ReportErrorToSentry(err)
return nil, err
Expand All @@ -267,11 +267,11 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
}

// CreateDocumentReference is a helper method to abstract the creation of a document reference
func (c *UseCasesClinicalImpl) CreateDocumentReference(ctx context.Context, payload *DocumentReferencePayload) (bool, error) {
func (c *UseCasesClinicalImpl) CreateDocumentReference(ctx context.Context, payload *DocumentReferencePayload) error {
concept, err := c.GetConcept(ctx, dto.TerminologySourceLOINC, payload.TerminologySystem)
if err != nil {
utils.ReportErrorToSentry(err)
return true, err
return err
}

finalDocStatus := domain.CompositionStatusEnumFinal
Expand Down Expand Up @@ -305,11 +305,20 @@ func (c *UseCasesClinicalImpl) CreateDocumentReference(ctx context.Context, payl
},
}

tags, err := c.GetTenantMetaTags(ctx)
if err != nil {
return err
}

documentReference.Meta = &domain.FHIRMetaInput{
Tag: tags,
}

_, err = c.infrastructure.FHIR.CreateFHIRDocumentReference(ctx, documentReference)
if err != nil {
utils.ReportErrorToSentry(err)
return true, err
return err
}

return false, nil
return nil
}
13 changes: 13 additions & 0 deletions pkg/clinical/usecases/clinical/referral_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
},
wantErr: true,
},
{
name: "Sad Case - unable to get tenant meta tags",
args: args{
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -138,6 +146,11 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
return nil, fmt.Errorf("failed to get organization")
}
}
if tt.name == "Sad Case - unable to get tenant meta tags" {
fakeExt.MockGetTenantIdentifiersFn = func(ctx context.Context) (*dto.TenantIdentifiers, error) {
return nil, fmt.Errorf("failed to get tenant identifiers")
}
}

if _, err := c.GenerateReferralReportPDF(tt.args.ctx, tt.args.serviceRequestID); (err != nil) != tt.wantErr {
t.Errorf("UseCasesClinicalImpl.GenerateReferralReportPDF() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit 840737b

Please sign in to comment.