Fix update patient
This commit is contained in:
@@ -89,6 +89,7 @@ type MPasienDto struct {
|
||||
func (mp MPasienDto) ToPatient() e.Patient {
|
||||
|
||||
patient := e.Patient{
|
||||
// TODO get patient person_id from database
|
||||
Person_Id: &mp.Id,
|
||||
NewBornStatus: mp.ParentNomr != nil,
|
||||
RegisteredAt: parseTimeDateOnly(mp.Tgldaftar),
|
||||
@@ -115,7 +116,7 @@ func (mp MPasienDto) ToPatient() e.Patient {
|
||||
BirthDate: parseTimeDateOnly(mp.Tgllahir),
|
||||
BirthRegency_Code: &bc,
|
||||
Gender_Code: &gc,
|
||||
ResidentIdentityNumber: nilEmptyString(*mp.Nip),
|
||||
ResidentIdentityNumber: nilEmptyString(mp.Noktp),
|
||||
PassportNumber: nilEmptyString(*mp.Paspor),
|
||||
DrivingLicenseNumber: nilEmptyString(*mp.Sim),
|
||||
Religion_Code: &rc,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
p "simrs-vx/internal/domain/simgos-entities/m-pasien"
|
||||
@@ -16,8 +17,6 @@ type myBase struct{}
|
||||
|
||||
var O myBase
|
||||
|
||||
const baseUrl string = "http://localhost:8000/v1/"
|
||||
|
||||
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
dto := p.MPasienDto{}
|
||||
if !rw.ValidateStructByIOR(w, r.Body, &dto) {
|
||||
@@ -32,7 +31,7 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
// fmt.Println(string(jsonPatient))
|
||||
// kirim request ke api sim-baru
|
||||
reqBody := bytes.NewBuffer(jsonPatient)
|
||||
err = send(http.MethodPost, baseUrl+"patient", reqBody)
|
||||
err = send(http.MethodPost, "patient", reqBody)
|
||||
if err != nil {
|
||||
fmt.Println("request error:", err)
|
||||
}
|
||||
@@ -44,12 +43,21 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
patient := dto.ToPatient()
|
||||
jsonPatient, err := json.Marshal(patient)
|
||||
// TODO DELETE BELOW,
|
||||
var (
|
||||
personId uint = 68
|
||||
patientId uint = 34
|
||||
)
|
||||
patient.Person_Id = &personId
|
||||
patient.Id = patientId
|
||||
patient.Person.Id = personId
|
||||
// TODO DELETE ABOVE
|
||||
jsonPatient, err := json.MarshalIndent(patient, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// fmt.Println(string(jsonPatient))
|
||||
url := fmt.Sprintf("%s%s%v", baseUrl, "patient/", *patient.Person_Id)
|
||||
fmt.Println(string(jsonPatient))
|
||||
url := fmt.Sprintf("%s%v", "patient/", patient.Id)
|
||||
fmt.Println(url)
|
||||
reqBody := bytes.NewBuffer(jsonPatient)
|
||||
err = send(http.MethodPatch, url, reqBody)
|
||||
@@ -68,7 +76,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(err)
|
||||
}
|
||||
reqBody := bytes.NewBuffer(jsonPatient)
|
||||
err = send(http.MethodDelete, fmt.Sprintf("%s%s%v", baseUrl, "patient/", *patient.Person_Id), reqBody)
|
||||
err = send(http.MethodDelete, fmt.Sprintf("%s%v", "patient/", *patient.Person_Id), reqBody)
|
||||
if err != nil {
|
||||
fmt.Println("request error:", err)
|
||||
}
|
||||
@@ -77,7 +85,8 @@ func (obj myBase) CreateLog(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func send(method string, url string, body *bytes.Buffer) error {
|
||||
func send(method string, endpoint string, body *bytes.Buffer) error {
|
||||
var url string = cfg.O.NewHost + endpoint
|
||||
req, err := http.NewRequest(method, url, body)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -85,10 +94,13 @@ func send(method string, url string, body *bytes.Buffer) error {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Sync-Source", cfg.O.OldSource)
|
||||
req.Header.Set("X-Sync-SecretKey", cfg.O.NewSecretKey)
|
||||
req.Header.Set("X-Sync-UserName", "dave")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
fmt.Println(resp.StatusCode, string(respBody), method, url)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user