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 12, 2024
1 parent ea951e1 commit 15702b8
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 33 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) (*ProfileResult, 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 *ProfileResult

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

return profileResponse, nil
}
88 changes: 56 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,65 @@ 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 {
ID string `json:"id,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"`
}

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"`
}
4 changes: 4 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ type ServiceIdentifier struct {
IdentifierValue string `json:"identifier_value"`
ServiceID string `json:"service_id"`
}

type ProfileResult struct {
ID string `json:"id"`
}

0 comments on commit 15702b8

Please sign in to comment.