Add MCU prefix for MCU registrations
This commit is contained in:
@@ -144,7 +144,7 @@ func registerPatientInTransaction(ctx context.Context, tx *sql.Tx, params Regist
|
||||
now := time.Now().In(jakarta)
|
||||
nowText := now.Format("2006-01-02 15:04:05")
|
||||
regDate := params.RegistrationDate.Format("2006-01-02")
|
||||
prefix := "P" + params.RegistrationDate.Format("0601")
|
||||
prefix := registrationIDPrefix(params.RegistrationType, params.RegistrationDate)
|
||||
regID, err := nextRegistrationID(ctx, tx, prefix)
|
||||
if err != nil {
|
||||
return RegistrationOutcome{}, err
|
||||
@@ -489,6 +489,14 @@ func nextRegistrationID(ctx context.Context, tx *sql.Tx, prefix string) (string,
|
||||
return fmt.Sprintf("%s%05d", prefix, number+1), nil
|
||||
}
|
||||
|
||||
func registrationIDPrefix(registrationType int64, registrationDate time.Time) string {
|
||||
prefix := "P"
|
||||
if registrationType == 2 {
|
||||
prefix = "MCU"
|
||||
}
|
||||
return prefix + registrationDate.Format("0601")
|
||||
}
|
||||
|
||||
func registrationOutcome(statusCode int, success bool, status, message string, data any) RegistrationOutcome {
|
||||
return RegistrationOutcome{HTTPStatus: statusCode, Success: success, Status: status, Message: message, Data: data}
|
||||
}
|
||||
|
||||
17
internal/repository/registration_prefix_test.go
Normal file
17
internal/repository/registration_prefix_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRegistrationIDPrefix(t *testing.T) {
|
||||
registrationDate := time.Date(2026, time.September, 7, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
if got, want := registrationIDPrefix(2, registrationDate), "MCU2609"; got != want {
|
||||
t.Fatalf("MCU prefix = %q; want %q", got, want)
|
||||
}
|
||||
if got, want := registrationIDPrefix(1, registrationDate), "P2609"; got != want {
|
||||
t.Fatalf("regular prefix = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user