Skip to content

Commit

Permalink
chore: create fhir organisation id isc
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Feb 24, 2023
1 parent 32deba7 commit f51b416
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/clinical/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func Router(ctx context.Context) (*mux.Router, error) {
isc.Path("/delete-patient").Methods(
http.MethodDelete,
).HandlerFunc(h.DeleteFHIRPatientByPhone())
isc.Path("/create-fhir-organisation").Methods(
http.MethodPost,
).HandlerFunc(h.CreateFHIROrganization())

//Authenticated routes
gqlR := r.Path("/graphql").Subrouter()
Expand Down
47 changes: 47 additions & 0 deletions pkg/clinical/presentation/rest/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// PresentationHandlers represents all the REST API logic
type PresentationHandlers interface {
DeleteFHIRPatientByPhone() http.HandlerFunc
CreateFHIROrganization() http.HandlerFunc
}

// PresentationHandlersImpl represents the usecase implementation object
Expand Down Expand Up @@ -70,3 +71,49 @@ func (p PresentationHandlersImpl) DeleteFHIRPatientByPhone() http.HandlerFunc {
)
}
}

// CreateFHIROrganization handler exposes an endpoint that takes a
// FHIR organization input and creates an organization
func (p PresentationHandlersImpl) CreateFHIROrganization() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

payload := domain.FHIROrganizationInput{}
type errResponse struct {
Err string `json:"error"`
}
serverutils.DecodeJSONToTargetStruct(w, r, payload)
if payload.ID == nil {
serverutils.WriteJSONResponse(
w,
errResponse{
Err: "expected an ID to be defined",
},
http.StatusBadRequest,
)
return
}
organization, err := p.usecases.CreateFHIROrganization(ctx, payload)
if err != nil {
utils.ReportErrorToSentry(err)
err := fmt.Sprintf("unable to delete patient: %v", err.Error())
serverutils.WriteJSONResponse(
w,
errResponse{
Err: err,
},
http.StatusInternalServerError,
)
return
}

type response struct {
Organization *domain.FHIROrganizationRelayPayload `json:"organization"`
}
serverutils.WriteJSONResponse(
w,
response{Organization: organization},
http.StatusOK,
)
}
}

0 comments on commit f51b416

Please sign in to comment.