Skip to content

Commit

Permalink
feat: definitive profile creation on healthcrm service
Browse files Browse the repository at this point in the history
  • Loading branch information
biko committed Apr 15, 2024
1 parent ea951e1 commit 010628a
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ coverage.html
coverage.json
coverage_report.txt
.vscode/
venv
venv
.env/
27 changes: 27 additions & 0 deletions healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,30 @@ func (h *HealthCRMLib) GetService(ctx context.Context, serviceID string) (*Facil

return &service, nil
}

// CreateProfile is used to create profile in health CRM service
func (h *HealthCRMLib) CreateProfile(ctx context.Context, profile *Profile) (*ProfileOutput, error) {
path := "/v1/identities/profiles/"
response, err := h.client.MakeRequest(ctx, http.MethodPost, path, nil, profile)
if err != nil {
return nil, err
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusCreated {
return nil, errors.New(string(respBytes))
}

var profileResponse *ProfileOutput

err = json.Unmarshal(respBytes, &profileResponse)
if err != nil {
return nil, err
}

return profileResponse, nil
}
87 changes: 55 additions & 32 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,41 +40,64 @@ 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"`
}

type Profile 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"`
}

type ProfileIdentifierInput struct {
IdentifierValue string `json:"identifier_value"`
IdentifierType string `json:"identifier_type"`
}

type ProfileContactInput struct {
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
}
135 changes: 75 additions & 60 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,111 @@ import "time"

// FacilityPage is the hospitals model used to show facility details
type FacilityPage struct {
Count int `json:"count"`
Next string `json:"next"`
Previous any `json:"previous"`
PageSize int `json:"page_size"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
Results []FacilityOutput `json:"results"`
Count int `json:"count"`
Next string `json:"next"`
Previous any `json:"previous"`
PageSize int `json:"page_size"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
Results []FacilityOutput `json:"results"`
}

// CoordinatesOutput is used to show geographical coordinates
type CoordinatesOutput struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}

// ContactsOutput is used to show facility contacts
type ContactsOutput struct {
ID string `json:"id"`
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
Active bool `json:"active"`
Role string `json:"role"`
FacilityID string `json:"facility_id"`
ID string `json:"id"`
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
Active bool `json:"active"`
Role string `json:"role"`
FacilityID string `json:"facility_id"`
}

// IdentifiersOutput is used to display facility identifiers
type IdentifiersOutput struct {
ID string `json:"id"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
ValidFrom string `json:"valid_from"`
ValidTo string `json:"valid_to"`
FacilityID string `json:"facility_id"`
ID string `json:"id"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
ValidFrom string `json:"valid_from"`
ValidTo string `json:"valid_to"`
FacilityID string `json:"facility_id"`
}

// FacilityOutput is used to display facility(ies)
type FacilityOutput struct {
ID string `json:"id,omitempty"`
Created time.Time `json:"created,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"`
Coordinates CoordinatesOutput `json:"coordinates,omitempty"`
Distance float64 `json:"distance,omitempty"`
Status string `json:"status,omitempty"`
Address string `json:"address,omitempty"`
Contacts []ContactsOutput `json:"contacts,omitempty"`
Identifiers []IdentifiersOutput `json:"identifiers,omitempty"`
BusinessHours []BusinessHoursOutput `json:"businesshours,omitempty"`
Services []FacilityService `json:"services,omitempty"`
ID string `json:"id,omitempty"`
Created time.Time `json:"created,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"`
Coordinates CoordinatesOutput `json:"coordinates,omitempty"`
Distance float64 `json:"distance,omitempty"`
Status string `json:"status,omitempty"`
Address string `json:"address,omitempty"`
Contacts []ContactsOutput `json:"contacts,omitempty"`
Identifiers []IdentifiersOutput `json:"identifiers,omitempty"`
BusinessHours []BusinessHoursOutput `json:"businesshours,omitempty"`
Services []FacilityService `json:"services,omitempty"`
}

// BusinessHoursOutput models data that show facility's operational hours
type BusinessHoursOutput struct {
ID string `json:"id"`
Day string `json:"day"`
OpeningTime string `json:"opening_time"`
ClosingTime string `json:"closing_time"`
FacilityID string `json:"facility_id"`
ID string `json:"id"`
Day string `json:"day"`
OpeningTime string `json:"opening_time"`
ClosingTime string `json:"closing_time"`
FacilityID string `json:"facility_id"`
}

// FacilityServicePage models the services offered in a facility
type FacilityServicePage struct {
Results []FacilityService `json:"results"`
Count int `json:"count"`
Next string `json:"next"`
Previous string `json:"previous"`
PageSize int `json:"page_size"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
Results []FacilityService `json:"results"`
Count int `json:"count"`
Next string `json:"next"`
Previous string `json:"previous"`
PageSize int `json:"page_size"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
}

// FacilityService models the data class that is used to show facility services
type FacilityService struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Identifiers []*ServiceIdentifier `json:"identifiers"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Identifiers []*ServiceIdentifier `json:"identifiers"`
}

// ServiceIdentifier models the structure of facility's service identifiers
type ServiceIdentifier struct {
ID string `json:"id"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
ServiceID string `json:"service_id"`
ID string `json:"id"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
ServiceID string `json:"service_id"`
}

type ProfileOutput struct {
ID string `json:"id,omitempty"`
Created string `json:"created,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"`
}

0 comments on commit 010628a

Please sign in to comment.