feat (reference): done
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package reference
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
e "simrs-vx/internal/domain/bpjs-entities/reference"
|
||||
ibpjs "simrs-vx/internal/infra/bpjs"
|
||||
)
|
||||
|
||||
func endpointMapper(input *e.ReadListDto) string {
|
||||
switch input.ReferenceType {
|
||||
case e.RTProvince:
|
||||
return ibpjs.O.BaseUrl + "provinces"
|
||||
case e.RTCities:
|
||||
return ibpjs.O.BaseUrl + "cities/" + input.PathValue1
|
||||
case e.RTDistrict:
|
||||
return ibpjs.O.BaseUrl + "districts/" + input.PathValue1
|
||||
case e.RTDiagnose:
|
||||
return ibpjs.O.BaseUrl + "diagnosa/" + input.PathValue1
|
||||
case e.RTDiagnosePrb:
|
||||
return ibpjs.O.BaseUrl + "diagnosaprb"
|
||||
case e.RTMedicinePrb:
|
||||
return ibpjs.O.BaseUrl + "obatprb/" + input.PathValue1
|
||||
case e.RTUnit:
|
||||
if input.QParam == "" {
|
||||
return ibpjs.O.BaseUrl + "referensi/poli"
|
||||
}
|
||||
return ibpjs.O.BaseUrl + "referensi/poli/" + input.QParam
|
||||
case e.RTHealthcare:
|
||||
return fmt.Sprintf("%sreferensi/faskes?faskes=%s&jenis-faskes=%s", ibpjs.O.BaseUrl, input.PathValue1, input.PathValue2)
|
||||
case e.RTDoctor:
|
||||
return fmt.Sprintf("%sreferensi/dokter-dpjp?jenis-pelayanan=%s&tgl-pelayanan=%s&kode-spesialis=%s", ibpjs.O.BaseUrl, input.PathValue1, input.PathValue2, input.PathValue3)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package reference
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
e "simrs-vx/internal/domain/bpjs-entities/reference"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func ReadList(input *e.ReadListDto, data *e.Response, tx *gorm.DB) error {
|
||||
endpoint := endpointMapper(input)
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &data); err != nil {
|
||||
return fmt.Errorf("failed to parse response JSON: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user