Skip to content

Commit

Permalink
refactor: combine clinical and fhir usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Jan 27, 2023
1 parent 5709e0e commit 60fdd25
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 948 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@ RUN apk add --no-cache ca-certificates
COPY --from=builder /app/server /server
COPY --from=builder /app/deps.yaml /deps.yaml

COPY --from=builder /app/pkg/clinical/application/authorization/rbac_model.conf /app/pkg/clinical/application/authorization/rbac_model.conf
COPY --from=builder /app/pkg/clinical/application/authorization/data/rbac_policy.csv /app/pkg/clinical/application/authorization/data/rbac_policy.csv

# Run the web service on container startup.
CMD ["/server"]
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/ahmetb/go-linq/v3 v3.2.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/brianvoe/gofakeit v3.18.0+incompatible
github.com/casbin/casbin/v2 v2.44.3
github.com/getsentry/sentry-go v0.13.0
github.com/google/uuid v1.3.0
github.com/gorilla/handlers v1.5.1
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
Expand All @@ -117,8 +115,6 @@ github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zK
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/brianvoe/gofakeit v3.18.0+incompatible h1:wDOmHc9DLG4nRjUVVaxA+CEglKOW72Y5+4WNxUIkjM8=
github.com/brianvoe/gofakeit v3.18.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc=
github.com/casbin/casbin/v2 v2.44.3 h1:tPP1YypfG2fqe7S2zivYuD11yc+/mc0GXJe/sDVbb1U=
github.com/casbin/casbin/v2 v2.44.3/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0 h1:t/LhUZLVitR1Ow2YOnduCsavhwFUklBMoGVYUCqmCqk=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
58 changes: 2 additions & 56 deletions pkg/clinical/infrastructure/datastore/fhir/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/savannahghi/clinical/pkg/clinical/application/utils"
"github.com/savannahghi/clinical/pkg/clinical/domain"
dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset"
"github.com/savannahghi/clinical/pkg/clinical/repository"
"github.com/savannahghi/converterandformatter"
"github.com/savannahghi/scalarutils"
)
Expand All @@ -23,61 +24,6 @@ const (
timeFormatStr = "2006-01-02T15:04:05+03:00"
)

// FHIR represents all the FHIR logic
type FHIR interface {
CreateEpisodeOfCare(ctx context.Context, episode domain.FHIREpisodeOfCare) (*domain.EpisodeOfCarePayload, error)
SearchFHIRCondition(ctx context.Context, params map[string]interface{}) (*domain.FHIRConditionRelayConnection, error)
CreateFHIRCondition(ctx context.Context, input domain.FHIRConditionInput) (*domain.FHIRConditionRelayPayload, error)
CreateFHIROrganization(ctx context.Context, input domain.FHIROrganizationInput) (*domain.FHIROrganizationRelayPayload, error)
SearchFHIROrganization(ctx context.Context, params map[string]interface{}) (*domain.FHIROrganizationRelayConnection, error)
FindOrganizationByID(ctx context.Context, organisationID string) (*domain.FHIROrganizationRelayPayload, error)
SearchEpisodesByParam(ctx context.Context, searchParams url.Values) ([]*domain.FHIREpisodeOfCare, error)
HasOpenEpisode(
ctx context.Context,
patient domain.FHIRPatient,
) (bool, error)
OpenEpisodes(
ctx context.Context, patientReference string) ([]*domain.FHIREpisodeOfCare, error)
CreateFHIREncounter(ctx context.Context, input domain.FHIREncounterInput) (*domain.FHIREncounterRelayPayload, error)
GetFHIREpisodeOfCare(ctx context.Context, id string) (*domain.FHIREpisodeOfCareRelayPayload, error)
Encounters(ctx context.Context, patientReference string, status *domain.EncounterStatusEnum) ([]*domain.FHIREncounter, error)
SearchFHIREpisodeOfCare(ctx context.Context, params map[string]interface{}) (*domain.FHIREpisodeOfCareRelayConnection, error)
StartEncounter(ctx context.Context, episodeID string) (string, error)
SearchEpisodeEncounter(
ctx context.Context,
episodeReference string,
) (*domain.FHIREncounterRelayConnection, error)
EndEncounter(ctx context.Context, encounterID string) (bool, error)
EndEpisode(ctx context.Context, episodeID string) (bool, error)
GetActiveEpisode(ctx context.Context, episodeID string) (*domain.FHIREpisodeOfCare, error)
SearchFHIRServiceRequest(ctx context.Context, params map[string]interface{}) (*domain.FHIRServiceRequestRelayConnection, error)
CreateFHIRServiceRequest(ctx context.Context, input domain.FHIRServiceRequestInput) (*domain.FHIRServiceRequestRelayPayload, error)
SearchFHIRAllergyIntolerance(ctx context.Context, params map[string]interface{}) (*domain.FHIRAllergyIntoleranceRelayConnection, error)
CreateFHIRAllergyIntolerance(ctx context.Context, input domain.FHIRAllergyIntoleranceInput) (*domain.FHIRAllergyIntoleranceRelayPayload, error)
UpdateFHIRAllergyIntolerance(ctx context.Context, input domain.FHIRAllergyIntoleranceInput) (*domain.FHIRAllergyIntoleranceRelayPayload, error)
SearchFHIRComposition(ctx context.Context, params map[string]interface{}) (*domain.FHIRCompositionRelayConnection, error)
CreateFHIRComposition(ctx context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error)
UpdateFHIRComposition(ctx context.Context, input domain.FHIRCompositionInput) (*domain.FHIRCompositionRelayPayload, error)
DeleteFHIRComposition(ctx context.Context, id string) (bool, error)
UpdateFHIRCondition(ctx context.Context, input domain.FHIRConditionInput) (*domain.FHIRConditionRelayPayload, error)
GetFHIREncounter(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, error)
SearchFHIREncounter(ctx context.Context, params map[string]interface{}) (*domain.FHIREncounterRelayConnection, error)
SearchFHIRMedicationRequest(ctx context.Context, params map[string]interface{}) (*domain.FHIRMedicationRequestRelayConnection, error)
CreateFHIRMedicationRequest(ctx context.Context, input domain.FHIRMedicationRequestInput) (*domain.FHIRMedicationRequestRelayPayload, error)
UpdateFHIRMedicationRequest(ctx context.Context, input domain.FHIRMedicationRequestInput) (*domain.FHIRMedicationRequestRelayPayload, error)
DeleteFHIRMedicationRequest(ctx context.Context, id string) (bool, error)
SearchFHIRObservation(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error)
CreateFHIRObservation(ctx context.Context, input domain.FHIRObservationInput) (*domain.FHIRObservationRelayPayload, error)
DeleteFHIRObservation(ctx context.Context, id string) (bool, error)
GetFHIRPatient(ctx context.Context, id string) (*domain.FHIRPatientRelayPayload, error)
DeleteFHIRPatient(ctx context.Context, id string) (bool, error)
DeleteFHIRServiceRequest(ctx context.Context, id string) (bool, error)
DeleteFHIRResourceType(results []map[string]string) error
CreateFHIRMedicationStatement(ctx context.Context, input domain.FHIRMedicationStatementInput) (*domain.FHIRMedicationStatementRelayPayload, error)
CreateFHIRMedication(ctx context.Context, input domain.FHIRMedicationInput) (*domain.FHIRMedicationRelayPayload, error)
SearchFHIRMedicationStatement(ctx context.Context, params map[string]interface{}) (*domain.FHIRMedicationStatementRelayConnection, error)
}

// StoreImpl represents the FHIR infrastructure implementation
type StoreImpl struct {
Dataset dataset.FHIRRepository
Expand All @@ -86,7 +32,7 @@ type StoreImpl struct {
// NewFHIRStoreImpl initializes the new FHIR implementation
func NewFHIRStoreImpl(
dataset dataset.FHIRRepository,
) FHIR {
) repository.FHIR {
return &StoreImpl{
Dataset: dataset,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/clinical/infrastructure/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package infrastructure
import (
"github.com/savannahghi/clinical/pkg/clinical/application/common"
"github.com/savannahghi/clinical/pkg/clinical/application/extensions"
fhir "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir"
dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/mycarehub"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab"
"github.com/savannahghi/clinical/pkg/clinical/repository"
)

// Infrastructure ...
type Infrastructure struct {
FHIRRepo dataset.FHIRRepository
FHIR fhir.FHIR
FHIR repository.FHIR
OpenConceptLab openconceptlab.ServiceOCL
BaseExtension extensions.BaseExtension
MyCareHub mycarehub.IServiceMyCareHub
Expand All @@ -22,7 +22,7 @@ type Infrastructure struct {
func NewInfrastructureInteractor(
ext extensions.BaseExtension,
fhirRepository dataset.FHIRRepository,
fhir fhir.FHIR,
fhir repository.FHIR,
openconceptlab openconceptlab.ServiceOCL,
) Infrastructure {
myCareHubClient := common.NewInterServiceClient("mycarehub", ext)
Expand Down
26 changes: 11 additions & 15 deletions pkg/clinical/infrastructure/services/pubsub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/savannahghi/clinical/pkg/clinical/application/extensions"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/usecases/clinical"
fhirUsecase "github.com/savannahghi/clinical/pkg/clinical/usecases/fhir"
"github.com/savannahghi/clinical/pkg/clinical/usecases/ocl"
"github.com/savannahghi/serverutils"
)
Expand Down Expand Up @@ -57,30 +56,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
patient clinical.UseCasesClinical
fhir fhirUsecase.UseCasesFHIR
ocl ocl.UseCasesOCL
client *pubsub.Client
baseExt extensions.BaseExtension
infra infrastructure.Infrastructure
clinical clinical.UseCasesClinical
ocl ocl.UseCasesOCL
}

// NewServicePubSubMessaging returns a new instance of pubsub
func NewServicePubSubMessaging(
client *pubsub.Client,
baseExt extensions.BaseExtension,
infra infrastructure.Infrastructure,
patient clinical.UseCasesClinical,
fhir fhirUsecase.UseCasesFHIR,
clinical clinical.UseCasesClinical,
ocl ocl.UseCasesOCL,
) (*ServicePubSubMessaging, error) {
s := &ServicePubSubMessaging{
client: client,
baseExt: baseExt,
infra: infra,
patient: patient,
fhir: fhir,
ocl: ocl,
client: client,
baseExt: baseExt,
infra: infra,
clinical: clinical,
ocl: ocl,
}

ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func InitializeTestPubSub(t *testing.T) (*pubsubmessaging.ServicePubSubMessaging
baseExtension,
infrastructure,
usecases,
usecases,
oclUseCase,
)
if err != nil {
Expand Down
26 changes: 13 additions & 13 deletions pkg/clinical/infrastructure/services/pubsub/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
Active: profile.Active,
}

patient, err := ps.patient.RegisterPatient(ctx, payload)
patient, err := ps.clinical.RegisterPatient(ctx, payload)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand Down Expand Up @@ -131,7 +131,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
},
}

response, err := ps.fhir.CreateFHIROrganization(ctx, input)
response, err := ps.clinical.CreateFHIROrganization(ctx, input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand Down Expand Up @@ -168,7 +168,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
return
}

_, err = ps.fhir.CreateFHIRObservation(ctx, *input)
_, err = ps.clinical.CreateFHIRObservation(ctx, *input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand Down Expand Up @@ -197,7 +197,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
return
}

_, err = ps.fhir.CreateFHIRAllergyIntolerance(ctx, *input)
_, err = ps.clinical.CreateFHIRAllergyIntolerance(ctx, *input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand Down Expand Up @@ -226,7 +226,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
return
}

_, err = ps.fhir.CreateFHIRMedicationStatement(ctx, *input)
_, err = ps.clinical.CreateFHIRMedicationStatement(ctx, *input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand Down Expand Up @@ -255,7 +255,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
return
}

_, err = ps.fhir.CreateFHIRObservation(ctx, *input)
_, err = ps.clinical.CreateFHIRObservation(ctx, *input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Expand All @@ -280,7 +280,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
// ComposeTestResultInput composes a test result input from data received
func (ps ServicePubSubMessaging) ComposeTestResultInput(ctx context.Context, input dto.CreatePatientTestResultPubSubMessage) (*domain.FHIRObservationInput, error) {
var patientName string
patient, err := ps.patient.FindPatientByID(ctx, input.PatientID)
patient, err := ps.clinical.FindPatientByID(ctx, input.PatientID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func (ps ServicePubSubMessaging) ComposeTestResultInput(ctx context.Context, inp
}

if input.OrganizationID != "" {
organization, err := ps.fhir.FindOrganizationByID(ctx, input.OrganizationID) // rename organization response
organization, err := ps.clinical.FindOrganizationByID(ctx, input.OrganizationID) // rename organization response
if err != nil {
//Should not fail if the organization is not found
log.Printf("the error is: %v", err)
Expand Down Expand Up @@ -387,7 +387,7 @@ func (ps ServicePubSubMessaging) ComposeVitalsInput(ctx context.Context, input d
ValueString: &input.Value,
}

patient, err := ps.patient.FindPatientByID(ctx, input.PatientID)
patient, err := ps.clinical.FindPatientByID(ctx, input.PatientID)
if err != nil {
return nil, err
}
Expand All @@ -399,7 +399,7 @@ func (ps ServicePubSubMessaging) ComposeVitalsInput(ctx context.Context, input d
}

if input.OrganizationID != "" {
organization, err := ps.fhir.FindOrganizationByID(ctx, input.OrganizationID)
organization, err := ps.clinical.FindOrganizationByID(ctx, input.OrganizationID)
if err != nil {
//Should not fail if organization is not found
log.Printf("the error is: %v", err)
Expand Down Expand Up @@ -462,7 +462,7 @@ func (ps ServicePubSubMessaging) ComposeMedicationStatementInput(ctx context.Con
},
}

patient, err := ps.patient.FindPatientByID(ctx, input.PatientID)
patient, err := ps.clinical.FindPatientByID(ctx, input.PatientID)
if err != nil {
return nil, err
}
Expand All @@ -474,7 +474,7 @@ func (ps ServicePubSubMessaging) ComposeMedicationStatementInput(ctx context.Con
}

if input.OrganizationID != "" {
organization, err := ps.fhir.FindOrganizationByID(ctx, input.OrganizationID) // rename organization response
organization, err := ps.clinical.FindOrganizationByID(ctx, input.OrganizationID) // rename organization response
if err != nil {
log.Printf("the error is: %v", err)
}
Expand Down Expand Up @@ -530,7 +530,7 @@ func (ps ServicePubSubMessaging) ComposeAllergyIntoleranceInput(ctx context.Cont
Day: day,
}

patient, err := ps.patient.FindPatientByID(ctx, input.PatientID)
patient, err := ps.clinical.FindPatientByID(ctx, input.PatientID)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clinical/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func Router(ctx context.Context) (*mux.Router, error) {

infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl)
usecases := usecases.NewUsecasesInteractor(infrastructure)
h := rest.NewPresentationHandlers(infrastructure, usecases)
h := rest.NewPresentationHandlers(usecases)

pubSub, err := pubsubmessaging.NewServicePubSubMessaging(pubSubClient, baseExtension, infrastructure, usecases, usecases, ocl)
pubSub, err := pubsubmessaging.NewServicePubSubMessaging(pubSubClient, baseExtension, infrastructure, usecases, ocl)
if err != nil {
return nil, fmt.Errorf("failed to initialize pubsub messaging service: %v", err)
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/clinical/presentation/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package interactor
import (
"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/usecases/clinical"
fhir "github.com/savannahghi/clinical/pkg/clinical/usecases/fhir"
"github.com/savannahghi/clinical/pkg/clinical/usecases/ocl"
)

// Usecases is an interface that combines of all usescases
type Usecases interface {
clinical.UseCasesClinical
fhir.UseCasesFHIR
ocl.UseCasesOCL
}

// Interactor is an implementation of the usecases interface
type Interactor struct {
clinical.UseCasesClinical
fhir.UseCasesFHIR
infrastructure.Infrastructure
ocl.UseCasesOCL
}
Expand All @@ -27,12 +24,10 @@ func NewUsecasesInteractor(
infrastructure infrastructure.Infrastructure,
) Usecases {
clinical := clinical.NewUseCasesClinicalImpl(infrastructure)
fhir := fhir.NewUseCasesFHIRImpl(infrastructure)
ocl := ocl.NewUseCasesOCLImpl(infrastructure)

impl := &Interactor{
clinical,
fhir,
infrastructure,
ocl,
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/clinical/presentation/rest/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/savannahghi/clinical/pkg/clinical/application/utils"
"github.com/savannahghi/clinical/pkg/clinical/domain"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/usecases"
"github.com/savannahghi/serverutils"
)
Expand All @@ -18,13 +17,12 @@ type PresentationHandlers interface {

// PresentationHandlersImpl represents the usecase implementation object
type PresentationHandlersImpl struct {
usecases usecases.Interactor
infrastructure infrastructure.Infrastructure
usecases usecases.Interactor
}

// NewPresentationHandlers initializes a new rest handlers usecase
func NewPresentationHandlers(infrastructure infrastructure.Infrastructure, usecases usecases.Interactor) PresentationHandlers {
return &PresentationHandlersImpl{infrastructure: infrastructure, usecases: usecases}
func NewPresentationHandlers(usecases usecases.Interactor) PresentationHandlers {
return &PresentationHandlersImpl{usecases: usecases}
}

// DeleteFHIRPatientByPhone handler exposes an endpoint that takes a
Expand Down

0 comments on commit 60fdd25

Please sign in to comment.