approve and switch poly
This commit is contained in:
@@ -1,167 +0,0 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
)
|
||||
|
||||
func Create(input *e.Encounter) error {
|
||||
endpoint := getPrefixEndpoint()
|
||||
|
||||
jsonData, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
||||
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()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
jsonData, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
||||
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()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Update(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
|
||||
jsonData, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
||||
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()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
|
||||
jsonData, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
||||
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()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/encounter", sync.O.Host, sync.O.Prefix)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
)
|
||||
|
||||
func Create(input *e.Encounter) error {
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func Checkin(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/checkin", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Checkout(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/checkout", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Cancel(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/cancel", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/encounter", sync.O.Host, sync.O.Prefix)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func DoJsonRequest(input any, method, endpoint string) error {
|
||||
jsonData, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, endpoint, bytes.NewReader(jsonData))
|
||||
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()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+2
-2
@@ -164,9 +164,9 @@ func Delete(input *e.DeleteDto) error {
|
||||
|
||||
func GenerateNomrPatient() (*string, error) {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s-nomr-generator", prefixEndpoint)
|
||||
endpoint := fmt.Sprintf("%s/nomr", prefixEndpoint)
|
||||
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
req, err := http.NewRequest("POST", endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Reference in New Issue
Block a user