Skip to content

Commit

Permalink
fix: create appointments
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed May 17, 2023
1 parent b0fb242 commit 0cabf17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
1 change: 1 addition & 0 deletions pkg/mycarehub/domain/appointments.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Appointment struct {
Provider string `json:"provider"`
HasRescheduledAppointment bool `json:"hasRescheduledApointment"`
ProgramID string `json:"programID"`
OrganisationID string `json:"organisationID"`
}

// AppointmentsPage is a list of paginated appointments
Expand Down
14 changes: 0 additions & 14 deletions pkg/mycarehub/infrastructure/database/postgres/gorm/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,26 +1267,12 @@ type Appointment struct {

// BeforeCreate is a hook run before creating an appointment
func (a *Appointment) BeforeCreate(tx *gorm.DB) (err error) {
ctx := tx.Statement.Context
if userID := utils.GetLoggedInUserID(ctx); userID != nil {
a.CreatedBy = userID
}

id := uuid.New().String()
a.ID = id

return
}

// BeforeUpdate is a hook called before updating Appointment.
func (a *Appointment) BeforeUpdate(tx *gorm.DB) (err error) {
ctx := tx.Statement.Context
if userID := utils.GetLoggedInUserID(ctx); userID != nil {
a.UpdatedBy = userID
}
return
}

// TableName references the table that we map data from
func (Appointment) TableName() string {
return "appointments_appointment"
Expand Down
17 changes: 9 additions & 8 deletions pkg/mycarehub/infrastructure/database/postgres/pg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,15 @@ func (d *MyCareHubDb) CreateAppointment(ctx context.Context, appointment domain.

date := appointment.Date.AsTime()
ap := &gorm.Appointment{
Active: true,
ExternalID: appointment.ExternalID,
ClientID: appointment.ClientID,
FacilityID: appointment.FacilityID,
Reason: appointment.Reason,
Provider: appointment.Provider,
Date: date,
ProgramID: appointment.ProgramID,
Active: true,
ExternalID: appointment.ExternalID,
ClientID: appointment.ClientID,
FacilityID: appointment.FacilityID,
Reason: appointment.Reason,
Provider: appointment.Provider,
Date: date,
ProgramID: appointment.ProgramID,
OrganisationID: appointment.OrganisationID,
}

return d.create.CreateAppointment(ctx, ap)
Expand Down
13 changes: 7 additions & 6 deletions pkg/mycarehub/usecases/appointments/appointment.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ func (a *UseCasesAppointmentsImpl) CreateKenyaEMRAppointments(ctx context.Contex
var errs error
for _, clientProfile := range clientProfiles {
appointment := domain.Appointment{
Date: input.AppointmentDate,
Reason: input.AppointmentReason,
FacilityID: *facility.ID,
ExternalID: input.ExternalID,
ClientID: *clientProfile.ID,
ProgramID: clientProfile.User.CurrentProgramID,
Date: input.AppointmentDate,
Reason: input.AppointmentReason,
FacilityID: *facility.ID,
ExternalID: input.ExternalID,
ClientID: *clientProfile.ID,
ProgramID: clientProfile.User.CurrentProgramID,
OrganisationID: clientProfile.User.CurrentOrganizationID,
}

err = a.Create.CreateAppointment(ctx, appointment)
Expand Down

0 comments on commit 0cabf17

Please sign in to comment.