refactor: use static HIS database per instance

This commit is contained in:
2026-09-04 08:56:29 +07:00
parent 10fa7a6e38
commit 9afd5b792c
15 changed files with 174 additions and 783 deletions

View File

@@ -48,9 +48,8 @@ func TestStoreMedrecValidPayloadAndCreatedResponseParity(t *testing.T) {
IsNewPatient: true,
},
}}
handler := Handler{patientRepo: repo}
handler := Handler{patientRepo: repo, hospitalCode: "PRIMAYA"}
body := `{
"rs":" primaya ",
"nama":" Budi Santos ",
"jenis_kelamin":"l",
"tgl_lahir":"1990-01-15",
@@ -107,7 +106,6 @@ func TestStoreMedrecValidPayloadAndCreatedResponseParity(t *testing.T) {
func TestStoreMedrecValidationParity(t *testing.T) {
baseline := map[string]any{
"rs": "PRIMAYA",
"nama": "BUDI SANTOS",
"jenis_kelamin": "L",
"tgl_lahir": "1990-01-15",
@@ -122,7 +120,6 @@ func TestStoreMedrecValidationParity(t *testing.T) {
mutate func(map[string]any)
message string
}{
{name: "missing rs", mutate: func(p map[string]any) { delete(p, "rs") }, message: "Kode RS wajib diisi"},
{name: "missing name", mutate: func(p map[string]any) { delete(p, "nama") }, message: "Nama pasien wajib diisi"},
{name: "invalid gender", mutate: func(p map[string]any) { p["jenis_kelamin"] = "M" }, message: "Jenis kelamin harus L atau P"},
{name: "invalid date format", mutate: func(p map[string]any) { p["tgl_lahir"] = "15-01-1990" }, message: "Tanggal lahir harus format Y-m-d"},
@@ -131,7 +128,6 @@ func TestStoreMedrecValidationParity(t *testing.T) {
{name: "invalid ktp", mutate: func(p map[string]any) { p["nomer_sosial"] = "123" }, message: "NIK/KTP harus 16 digit angka"},
{name: "missing phone", mutate: func(p map[string]any) { delete(p, "telepon") }, message: "Telepon atau ponsel wajib diisi"},
{name: "invalid email", mutate: func(p map[string]any) { p["email"] = "invalid" }, message: "The email must be a valid email address."},
{name: "long hospital code", mutate: func(p map[string]any) { p["rs"] = strings.Repeat("X", 21) }, message: "The rs must not be greater than 20 characters."},
{name: "long dependant id", mutate: func(p map[string]any) { p["dependant_id"] = "D0001" }, message: "The dependant id must not be greater than 4 characters."},
}
@@ -172,7 +168,7 @@ func TestStoreMedrecNikFallbackAndOutcomeForwarding(t *testing.T) {
Data: data,
}}
handler := Handler{patientRepo: repo}
body := `{"rs":"PRIMAYA","nama":"BUDI","jenis_kelamin":"P","tgl_lahir":"1990-01-15","nik":"3174011501900001","ponsel":"08123"}`
body := `{"nama":"BUDI","jenis_kelamin":"P","tgl_lahir":"1990-01-15","nik":"3174011501900001","ponsel":"08123"}`
request := httptest.NewRequest(http.MethodPost, "/api/cpone/patients/medrec", strings.NewReader(body))
recorder := httptest.NewRecorder()
handler.StoreMedrec(recorder, request)
@@ -184,7 +180,7 @@ func TestStoreMedrecNikFallbackAndOutcomeForwarding(t *testing.T) {
func TestStoreMedrecRepositoryErrorParity(t *testing.T) {
handler := Handler{patientRepo: &fakePatientRepository{err: errors.New("database unavailable")}}
body := `{"rs":"PRIMAYA","nama":"BUDI","jenis_kelamin":"L","tgl_lahir":"1990-01-15","nomer_sosial":"3174011501900001","telepon":"08123"}`
body := `{"nama":"BUDI","jenis_kelamin":"L","tgl_lahir":"1990-01-15","nomer_sosial":"3174011501900001","telepon":"08123"}`
request := httptest.NewRequest(http.MethodPost, "/api/cpone/patients/medrec", strings.NewReader(body))
recorder := httptest.NewRecorder()
handler.StoreMedrec(recorder, request)