Skip to content

Commit

Permalink
feat: implement create organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Mar 23, 2022
1 parent c2888de commit bf93601
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
3 changes: 3 additions & 0 deletions pkg/clinical/application/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const (

//TestOrderTopicName is the topic for publishing a patient's test order
TestOrderTopicName = "test.order.create"

// OrganizationTopicName is the topic where organization(facility) details are published to
OrganizationTopicName = "organization.create"
)

// DefaultIdentifier assigns a patient a code to function as their
Expand Down
12 changes: 12 additions & 0 deletions pkg/clinical/application/dto/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ type CreatePatientPubSubMessage struct {
CHV string `json:"chv"`
Caregiver string `json:"caregiver"`
}

// CreateFacilityPubSubMessage models the details of healthcare facilities that are on myCareHub platform.
// This will be used to create a FHIR organization
type CreateFacilityPubSubMessage struct {
ID *string `json:"id"`
Name string `json:"name"`
Code int `json:"code"`
Phone string `json:"phone"`
Active bool `json:"active"`
County string `json:"county"`
Description string `json:"description"`
}
21 changes: 12 additions & 9 deletions pkg/clinical/infrastructure/services/pubsub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,27 @@ type ServicePubsub interface {

// ServicePubSubMessaging is used to send and receive pubsub notifications
type ServicePubSubMessaging struct {
client *pubsub.Client
baseExt extensions.BaseExtension
infra infrastructure.Infrastructure
usecases usecases.ClinicalUseCase
client *pubsub.Client
baseExt extensions.BaseExtension
infra infrastructure.Infrastructure
patient usecases.ClinicalUseCase
fhir usecases.FHIRUseCase
}

// NewServicePubSubMessaging returns a new instance of pubsub
func NewServicePubSubMessaging(
client *pubsub.Client,
baseExt extensions.BaseExtension,
infra infrastructure.Infrastructure,
usecases usecases.ClinicalUseCase,
patient usecases.ClinicalUseCase,
fhir usecases.FHIRUseCase,
) (*ServicePubSubMessaging, error) {
s := &ServicePubSubMessaging{
client: client,
baseExt: baseExt,
infra: infra,
usecases: usecases,
client: client,
baseExt: baseExt,
infra: infra,
patient: patient,
fhir: fhir,
}

ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func InitializeTestPubSub(t *testing.T) (*pubsubmessaging.ServicePubSubMessaging
baseExtension,
infrastructure,
usecases,
usecases,
)
if err != nil {
return nil, fmt.Errorf("failed to initialize pubsub messaging service: %w", err)
Expand Down
40 changes: 39 additions & 1 deletion pkg/clinical/infrastructure/services/pubsub/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
Active: profile.Active,
}

patient, err := ps.usecases.RegisterPatient(ctx, payload)
patient, err := ps.patient.RegisterPatient(ctx, payload)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand All @@ -90,6 +90,44 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
}, http.StatusBadRequest)
return
}

case ps.AddPubSubNamespace(common.OrganizationTopicName, ClinicalServiceName):
var data dto.CreateFacilityPubSubMessage
err := json.Unmarshal(message.Message.Data, &data)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}

use := domain.ContactPointUseEnumWork
rank := int64(1)
phoneSystem := domain.ContactPointSystemEnumPhone
input := domain.FHIROrganizationInput{
ID: data.ID,
Active: &data.Active,
Name: &data.Name,
Telecom: []*domain.FHIRContactPointInput{
{
System: &phoneSystem,
Value: &data.Phone,
Use: &use,
Rank: &rank,
Period: common.DefaultPeriodInput(),
},
},
}

_, err = ps.fhir.CreateFHIROrganization(ctx, input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}
}

resp := map[string]string{"Status": "Success"}
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Router(ctx context.Context) (*mux.Router, error) {
usecases := usecases.NewUsecasesInteractor(infrastructure)
h := rest.NewPresentationHandlers(infrastructure, usecases)

pubSub, err := pubsubmessaging.NewServicePubSubMessaging(pubSubClient, baseExtension, infrastructure, usecases)
pubSub, err := pubsubmessaging.NewServicePubSubMessaging(pubSubClient, baseExtension, infrastructure, usecases, usecases)
if err != nil {
return nil, fmt.Errorf("failed to initialize pubsub messaging service: %v", err)
}
Expand Down

0 comments on commit bf93601

Please sign in to comment.