Skip to content

Commit

Permalink
feat: generate signed url for referral reports
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
Salaton authored and KathurimaKimathi committed Apr 5, 2024
1 parent e2c108f commit 3d4fa00
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 104 deletions.
3 changes: 2 additions & 1 deletion pkg/clinical/application/dto/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ type Media struct {
ID string `json:"id,omitempty"`
PatientID string `json:"patientID,omitempty"`
PatientName string `json:"patientName,omitempty"`
URL string `json:"url,omitempty"`
MediaLink string `json:"mediaLink,omitempty"`
Name string `json:"name,omitempty"`
ContentType string `json:"contentType,omitempty"`
SignedURL string `json:"signedURL,omitempty"`
}

// MediaEdge is an media connection edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/brianvoe/gofakeit"
"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/dto"
"github.com/savannahghi/clinical/pkg/clinical/domain"
"github.com/savannahghi/firebasetools"
"github.com/savannahghi/scalarutils"
"github.com/ttacon/libphonenumber"
)

// FHIRMock struct implements mocks of FHIR methods.
Expand Down Expand Up @@ -1548,6 +1550,7 @@ func NewFHIRMock() *FHIRMock {
patientName := gofakeit.Name()
gender := domain.PatientGenderEnumFemale
phoneNumber := gofakeit.Phone()
system := scalarutils.URI(helpers.IDIdentifierSystem)
return &domain.FHIRPatientRelayPayload{
Resource: &domain.FHIRPatient{
ID: &patientID,
Expand All @@ -1567,6 +1570,14 @@ func NewFHIRMock() *FHIRMock {
Value: &phoneNumber,
},
},
Identifier: []*domain.FHIRIdentifier{
{
ID: &patientID,
Use: domain.IdentifierUseEnumOfficial,
System: &system,
Value: "12345",
},
},
},
}, nil
},
Expand Down Expand Up @@ -2172,6 +2183,7 @@ func NewFHIRMock() *FHIRMock {
},
MockGetFHIRServiceRequestFn: func(_ context.Context, id string) (*domain.FHIRServiceRequestRelayPayload, error) {
resourceID := uuid.New().String()
note := scalarutils.Markdown("test note")
return &domain.FHIRServiceRequestRelayPayload{
Resource: &domain.FHIRServiceRequest{
ID: &resourceID,
Expand All @@ -2193,6 +2205,24 @@ func NewFHIRMock() *FHIRMock {
},
},
},
{
URL: "http://savannahghi.org/fhir/StructureDefinition/referred-facility",
Extension: []domain.Extension{
{
URL: "facilityCounty",
ValueString: "Nairobi",
},
},
},
{
URL: "http://savannahghi.org/fhir/StructureDefinition/referred-facility",
Extension: []domain.Extension{
{
URL: "facilityContact",
ValueString: libphonenumber.PhoneNumber_CountryCodeSource_name[254],
},
},
},
{
URL: "http://savannahghi.org/fhir/StructureDefinition/referred-specialist",
Extension: []domain.Extension{
Expand All @@ -2203,6 +2233,12 @@ func NewFHIRMock() *FHIRMock {
},
},
},
Note: []*domain.FHIRAnnotation{
{
Time: &time.Time{},
Text: &note,
},
},
},
}, nil
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewFakeUploadMock() *FakeUpload {
return &FakeUpload{
MockUploadMediaFn: func(ctx context.Context, name string, file io.Reader, contentType string) (*dto.Media, error) {
return &dto.Media{
URL: "https://google.com",
MediaLink: "https://google.com",
}, nil
},
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/clinical/infrastructure/services/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,21 @@ func (u *ServiceUploadImpl) UploadMedia(ctx context.Context, name string, file i
return nil, err
}

// obtain a URL that lets anyone read or write an object for a limited time
signedURL, err := u.Client.Bucket(bucketName).SignedURL(name, &storage.SignedURLOptions{
Method: "GET",
Expires: time.Now().Add(48 * time.Hour),
Scheme: storage.SigningSchemeV4,
})
if err != nil {
return nil, err
}

output := &dto.Media{
URL: url.MediaLink,
MediaLink: url.MediaLink,
Name: url.Name,
ContentType: url.ContentType,
SignedURL: signedURL,
}

return output, nil
Expand Down
96 changes: 76 additions & 20 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.

2 changes: 1 addition & 1 deletion pkg/clinical/presentation/graph/inputs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ input DiagnosticReportInput {
input MediaInput {
id: ID!
name: String!
url: String!
mediaLink: String!
}

input ReferralInput {
Expand Down
3 changes: 2 additions & 1 deletion pkg/clinical/presentation/graph/types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ type ObservationConnection {
type Media {
id: String!
name: String!
url: String!
mediaLink: String!
contentType: String!
signedURL: String
}

type MediaEdge {
Expand Down
Loading

0 comments on commit 3d4fa00

Please sign in to comment.