feat(cpone): support company lab registrations
This commit is contained in:
@@ -115,13 +115,11 @@ func validateLabRegistration(payload map[string]any) (validatedLabRegistration,
|
||||
return validatedLabRegistration{}, "Dokter pengirim atau perujuk wajib diisi"
|
||||
}
|
||||
|
||||
patientType, patientTypePresent, message := optionalString(payload, "jenis_pasien_id", 0)
|
||||
patientType, message := requiredString(payload, "jenis_pasien_id", 20, "Jenis pasien wajib diisi")
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
if patientTypePresent && patientType != "0" {
|
||||
return validatedLabRegistration{}, "Registrasi laboratorium API saat ini hanya mendukung pasien umum"
|
||||
}
|
||||
patientType = strings.TrimSpace(patientType)
|
||||
|
||||
tariffPeriodID, message := requiredInteger(payload, "periode_tarif_id", "Periode tarif wajib diisi")
|
||||
if message != "" {
|
||||
@@ -131,6 +129,60 @@ func validateLabRegistration(payload map[string]any) (validatedLabRegistration,
|
||||
return validatedLabRegistration{}, "The periode tarif id must be at least 1."
|
||||
}
|
||||
|
||||
companyID, companyPresent, message := optionalString(payload, "perusahaan_id", 50)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
insuranceID, insurancePresent, message := optionalString(payload, "asuransi_id", 50)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
providerID, _, message := optionalString(payload, "provider_id", 50)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
policyNumber, _, message := optionalString(payload, "nomer_polis", 100)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
employeeID, _, message := optionalString(payload, "nik_karyawan", 100)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
employeeName, _, message := optionalString(payload, "nama_karyawan", 255)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
}
|
||||
|
||||
var groupTariffID int64
|
||||
if value, present := nullableValue(payload, "group_tarif_id"); present {
|
||||
parsed, ok := parseInteger(value)
|
||||
if !ok {
|
||||
return validatedLabRegistration{}, "The group tarif id must be an integer."
|
||||
}
|
||||
if parsed < 1 && patientType != "0" {
|
||||
return validatedLabRegistration{}, "The group tarif id must be at least 1."
|
||||
}
|
||||
groupTariffID = parsed
|
||||
}
|
||||
|
||||
if patientType != "0" {
|
||||
if !companyPresent || strings.TrimSpace(companyID) == "" {
|
||||
return validatedLabRegistration{}, "Perusahaan wajib diisi untuk pasien penjamin"
|
||||
}
|
||||
if !insurancePresent || strings.TrimSpace(insuranceID) == "" {
|
||||
return validatedLabRegistration{}, "Asuransi/penanggung wajib diisi untuk pasien penjamin"
|
||||
}
|
||||
if groupTariffID < 1 {
|
||||
return validatedLabRegistration{}, "Group tarif wajib diisi untuk pasien penjamin"
|
||||
}
|
||||
} else {
|
||||
companyID = ""
|
||||
insuranceID = ""
|
||||
providerID = ""
|
||||
groupTariffID = 0
|
||||
}
|
||||
|
||||
classID, classPresent, message := optionalString(payload, "kelas_id", 50)
|
||||
if message != "" {
|
||||
return validatedLabRegistration{}, message
|
||||
@@ -184,7 +236,15 @@ func validateLabRegistration(payload map[string]any) (validatedLabRegistration,
|
||||
DoctorID: doctorID,
|
||||
SenderDoctorID: senderDoctorID,
|
||||
Referrer: referrer,
|
||||
PatientType: patientType,
|
||||
TariffPeriodID: tariffPeriodID,
|
||||
CompanyID: strings.TrimSpace(companyID),
|
||||
InsuranceID: strings.TrimSpace(insuranceID),
|
||||
ProviderID: strings.TrimSpace(providerID),
|
||||
GroupTariffID: groupTariffID,
|
||||
PolicyNumber: strings.TrimSpace(policyNumber),
|
||||
EmployeeID: strings.TrimSpace(employeeID),
|
||||
EmployeeName: strings.TrimSpace(employeeName),
|
||||
ClassID: classID,
|
||||
DailyShiftID: dailyShiftID,
|
||||
WorkingDiagnosis: workingDiagnosis,
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestRegisterLabValidPayloadAndResponseParity(t *testing.T) {
|
||||
if recorder.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d, want %d; body=%s", recorder.Code, http.StatusCreated, recorder.Body.String())
|
||||
}
|
||||
const expected = `{"success":true,"status":"registered","message":"Registrasi laboratorium berhasil disimpan","data":{"registration":{"RegID":"CPLAB2608180001","MEDRECID":"00001234","Tanggal":"2026-08-18 10:11:12","DepartemenID":"LAB","DokterID":"DR01","JenisPasienID":0,"JenisRegID":3,"PeriodeTarifID":10},"transaction":{"TrxDepartemenID":99,"TrxID":"CPLAB2608180001","GrandTotal":0},"layanan":[]}}` + "\n"
|
||||
const expected = `{"success":true,"status":"registered","message":"Registrasi laboratorium berhasil disimpan","data":{"registration":{"RegID":"CPLAB2608180001","MEDRECID":"00001234","Tanggal":"2026-08-18 10:11:12","DepartemenID":"LAB","DokterID":"DR01","JenisPasienID":0,"JenisRegID":3,"PeriodeTarifID":10,"PerusahaanID":null,"AsuransiID":null,"ProviderID":null,"GroupTarifID":null,"NomerPolis":null},"transaction":{"TrxDepartemenID":99,"TrxID":"CPLAB2608180001","GrandTotal":0},"layanan":[]}}` + "\n"
|
||||
if recorder.Body.String() != expected {
|
||||
t.Fatalf("body mismatch\n got: %s\nwant: %s", recorder.Body.String(), expected)
|
||||
}
|
||||
@@ -96,12 +96,57 @@ func TestRegisterLabValidPayloadAndResponseParity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterLabCompanyPayload(t *testing.T) {
|
||||
repo := &fakeLabRegistrationRepository{outcome: repository.LabRegistrationOutcome{
|
||||
HTTPStatus: http.StatusCreated,
|
||||
Success: true,
|
||||
Status: "registered",
|
||||
Message: "Registrasi laboratorium berhasil disimpan",
|
||||
}}
|
||||
handler := Handler{labRepo: repo}
|
||||
body := `{
|
||||
"medrec_id":"00409575",
|
||||
"departemen_id":"MED-PNJ-LAB",
|
||||
"dokter_id":"SPP01_003",
|
||||
"dokter_pengirim_id":"Luar",
|
||||
"perujuk":"DOKTER PERUJUK LUAR",
|
||||
"jenis_pasien_id":"1",
|
||||
"periode_tarif_id":7,
|
||||
"perusahaan_id":"PE260700001",
|
||||
"asuransi_id":"PE260700001",
|
||||
"provider_id":"",
|
||||
"group_tarif_id":1980,
|
||||
"nomer_polis":"POLIS-001",
|
||||
"nik_karyawan":"TSB2026002",
|
||||
"nama_karyawan":"INTAN SEPTIANI",
|
||||
"kelas_id":"Default",
|
||||
"shift_harian_id":48049,
|
||||
"diagnosa_kerja":"Test diagnosa"
|
||||
}`
|
||||
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/cpone/patients/lab-registration", strings.NewReader(body))
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.RegisterLab(recorder, request)
|
||||
|
||||
if recorder.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d, want %d; body=%s", recorder.Code, http.StatusCreated, recorder.Body.String())
|
||||
}
|
||||
params := repo.params
|
||||
if params.PatientType != "1" || params.CompanyID != "PE260700001" || params.InsuranceID != "PE260700001" || params.GroupTariffID != 1980 {
|
||||
t.Fatalf("company guarantor params mismatch: %+v", params)
|
||||
}
|
||||
if params.PolicyNumber != "POLIS-001" || params.EmployeeID != "TSB2026002" || params.EmployeeName != "INTAN SEPTIANI" {
|
||||
t.Fatalf("company employee params mismatch: %+v", params)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterLabValidationParity(t *testing.T) {
|
||||
baseline := map[string]any{
|
||||
"medrec_id": "00001234",
|
||||
"departemen_id": "LAB",
|
||||
"dokter_id": "DR01",
|
||||
"dokter_pengirim_id": "DR02",
|
||||
"jenis_pasien_id": "0",
|
||||
"periode_tarif_id": 10,
|
||||
"diagnosa_kerja": "Pemeriksaan laboratorium",
|
||||
}
|
||||
@@ -130,9 +175,14 @@ func TestRegisterLabValidationParity(t *testing.T) {
|
||||
message: "Dokter pengirim atau perujuk wajib diisi",
|
||||
},
|
||||
{
|
||||
name: "non-general patient",
|
||||
name: "missing company for guarantor",
|
||||
mutate: func(payload map[string]any) { payload["jenis_pasien_id"] = "1" },
|
||||
message: "Registrasi laboratorium API saat ini hanya mendukung pasien umum",
|
||||
message: "Perusahaan wajib diisi untuk pasien penjamin",
|
||||
},
|
||||
{
|
||||
name: "missing patient type",
|
||||
mutate: func(payload map[string]any) { delete(payload, "jenis_pasien_id") },
|
||||
message: "Jenis pasien wajib diisi",
|
||||
},
|
||||
{
|
||||
name: "invalid tariff period type",
|
||||
@@ -203,7 +253,7 @@ func TestRegisterLabRepositoryErrorsMatchLaravelEnvelope(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
const validBody = `{"medrec_id":"00001234","departemen_id":"LAB","dokter_id":"DR01","dokter_pengirim_id":"DR02","periode_tarif_id":10,"diagnosa_kerja":"Pemeriksaan laboratorium"}`
|
||||
const validBody = `{"medrec_id":"00001234","departemen_id":"LAB","dokter_id":"DR01","dokter_pengirim_id":"DR02","jenis_pasien_id":"0","periode_tarif_id":10,"diagnosa_kerja":"Pemeriksaan laboratorium"}`
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
handler := Handler{labRepo: &fakeLabRegistrationRepository{err: test.err}}
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestAddLabServicesValidPayloadAndResponseParity(t *testing.T) {
|
||||
if recorder.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d; body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
const expected = `{"success":true,"status":"services_added","message":"Layanan laboratorium berhasil ditambahkan","data":{"registration":{"RegID":"CPLAB2608180001","MEDRECID":"00001234","Tanggal":"2026-08-18 10:11:12","DepartemenID":"LAB","DokterID":"DR01","JenisPasienID":0,"JenisRegID":3,"PeriodeTarifID":10},"transaction":{"TrxDepartemenID":99,"TrxID":"CPLAB2608180001","GrandTotal":125000},"layanan":[],"added_layanan_ids":["6413"],"skipped_layanan_ids":["6414"]}}` + "\n"
|
||||
const expected = `{"success":true,"status":"services_added","message":"Layanan laboratorium berhasil ditambahkan","data":{"registration":{"RegID":"CPLAB2608180001","MEDRECID":"00001234","Tanggal":"2026-08-18 10:11:12","DepartemenID":"LAB","DokterID":"DR01","JenisPasienID":0,"JenisRegID":3,"PeriodeTarifID":10,"PerusahaanID":null,"AsuransiID":null,"ProviderID":null,"GroupTarifID":null,"NomerPolis":null},"transaction":{"TrxDepartemenID":99,"TrxID":"CPLAB2608180001","GrandTotal":125000},"layanan":[],"added_layanan_ids":["6413"],"skipped_layanan_ids":["6414"]}}` + "\n"
|
||||
if recorder.Body.String() != expected {
|
||||
t.Fatalf("body mismatch\n got: %s\nwant: %s", recorder.Body.String(), expected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user