Skip to content

Commit

Permalink
chore(CPL-319): Closing open server requests and code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BiKodes committed Apr 17, 2024
1 parent 3de223b commit 011acac
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 133 deletions.
14 changes: 14 additions & 0 deletions healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func (h *HealthCRMLib) CreateFacility(ctx context.Context, facility *Facility) (
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -75,6 +77,8 @@ func (h *HealthCRMLib) GetFacilityByID(ctx context.Context, id string) (*Facilit
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -102,6 +106,8 @@ func (h *HealthCRMLib) UpdateFacility(ctx context.Context, id string, updatePayl
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -177,6 +183,8 @@ func (h *HealthCRMLib) GetFacilitiesOfferingAService(ctx context.Context, servic
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -205,6 +213,8 @@ func (h *HealthCRMLib) CreateService(ctx context.Context, input FacilityServiceI
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -233,6 +243,8 @@ func (h *HealthCRMLib) LinkServiceToFacility(ctx context.Context, facilityID str
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down Expand Up @@ -319,6 +331,8 @@ func (h *HealthCRMLib) GetFacilities(ctx context.Context, location *Coordinates,
return nil, err
}

defer response.Body.Close()

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
Expand Down
96 changes: 48 additions & 48 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import "fmt"

// Facility is the hospitals data class
type Facility struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
FacilityType string `json:"facility_type,omitempty"`
County string `json:"county,omitempty"`
Country string `json:"country,omitempty"`
Address string `json:"address,omitempty"`
Coordinates *Coordinates `json:"coordinates,omitempty"`
Contacts []Contacts `json:"contacts,omitempty"`
Identifiers []Identifiers `json:"identifiers,omitempty"`
BusinessHours []BusinessHours `json:"businesshours,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
FacilityType string `json:"facility_type,omitempty"`
County string `json:"county,omitempty"`
Country string `json:"country,omitempty"`
Address string `json:"address,omitempty"`
Coordinates *Coordinates `json:"coordinates,omitempty"`
Contacts []Contacts `json:"contacts,omitempty"`
Identifiers []Identifiers `json:"identifiers,omitempty"`
BusinessHours []BusinessHours `json:"businesshours,omitempty"`
}

// Coordinates represents geographical coordinates using latitude and longitude.
// Latitude measures the north-south position, while longitude measures
// the east-west position.
type Coordinates struct {
Latitude string `json:"latitude,omitempty"`
Longitude string `json:"longitude,omitempty"`
Radius string `json:"radius,omitempty"`
Latitude string `json:"latitude,omitempty"`
Longitude string `json:"longitude,omitempty"`
Radius string `json:"radius,omitempty"`
}

// ToString returns the location in comma-separated values format.
Expand All @@ -40,67 +40,67 @@ func (c Coordinates) ToString() (string, error) {

// Contacts models facility's model data class
type Contacts struct {
ContactType string `json:"contact_type,omitempty"`
ContactValue string `json:"contact_value,omitempty"`
Role string `json:"role,omitempty"`
}
ContactType string `json:"contact_type,omitempty"`
ContactValue string `json:"contact_value,omitempty"`
Role string `json:"role,omitempty"`
}

// Identifiers models facility's identifiers; can be MFL Code, Slade Code etc...
type Identifiers struct {
IdentifierType string `json:"identifier_type,omitempty"`
IdentifierValue string `json:"identifier_value,omitempty"`
ValidFrom string `json:"valid_from,omitempty"`
ValidTo string `json:"valid_to,omitempty"`
IdentifierType string `json:"identifier_type,omitempty"`
IdentifierValue string `json:"identifier_value,omitempty"`
ValidFrom string `json:"valid_from,omitempty"`
ValidTo string `json:"valid_to,omitempty"`
}

// BusinessHours models data to store business hours
type BusinessHours struct {
Day string `json:"day"`
OpeningTime string `json:"opening_time"`
ClosingTime string `json:"closing_time"`
Day string `json:"day"`
OpeningTime string `json:"opening_time"`
ClosingTime string `json:"closing_time"`
}

// Pagination is used to hold pagination values
type Pagination struct {
Page string `json:"page"`
PageSize string `json:"page_size"`
Page string `json:"page"`
PageSize string `json:"page_size"`
}

// FacilityServiceInput models is used to create a new service
type FacilityServiceInput struct {
Name string `json:"name"`
Description string `json:"description"`
Identifiers []*ServiceIdentifierInput `json:"identifiers"`
Name string `json:"name"`
Description string `json:"description"`
Identifiers []*ServiceIdentifierInput `json:"identifiers"`
}

// ServiceIdentifierInput is used to create an identifier
type ServiceIdentifierInput struct {
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
}

// ProfileInput is the host of users data or a brief description of a person
type ProfileInput struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
OtherName string `json:"other_name"`
DateOfBirth string `json:"date_of_birth"`
Gender string `json:"gender"`
EnrolmentDate string `json:"enrolment_date"`
SladeCode string `json:"slade_code"`
ServiceCode string `json:"service_code"`
Contacts []*ProfileContactInput `json:"contacts,omitempty"`
Identifiers []*ProfileIdentifierInput `json:"identifiers,omitempty"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
OtherName string `json:"other_name"`
DateOfBirth string `json:"date_of_birth"`
Gender string `json:"gender"`
EnrolmentDate string `json:"enrolment_date"`
SladeCode string `json:"slade_code"`
ServiceCode string `json:"service_code"`
Contacts []*ProfileContactInput `json:"contacts,omitempty"`
Identifiers []*ProfileIdentifierInput `json:"identifiers,omitempty"`
}

// ProfileIdentifierInput is used to create profile(s) identifier(s)
// ProfileIdentifierInput is used to create profile(s) identifier(s)
type ProfileIdentifierInput struct {
IdentifierValue string `json:"identifier_value"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
IdentifierType string `json:"identifier_type"`
}

// ProfileContanctInput is used to create profile(s) contact(s)
// ProfileContanctInput is used to create profile(s) contact(s)
type ProfileContactInput struct {
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
}
Loading

0 comments on commit 011acac

Please sign in to comment.