update nomr patient
This commit is contained in:
@@ -162,6 +162,46 @@ func Delete(input *e.DeleteDto) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GenerateNomrPatient() (*string, error) {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s-nomr-generator", prefixEndpoint)
|
||||
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
errors := d.FieldError{}
|
||||
_ = json.Unmarshal(bodyBytes, &errors)
|
||||
|
||||
return nil, fmt.Errorf(errors.Message)
|
||||
}
|
||||
|
||||
var result map[string]any
|
||||
if err = json.Unmarshal(bodyBytes, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dataMap := result["data"].(map[string]any)
|
||||
nomr := dataMap["nomr"].(string)
|
||||
|
||||
return &nomr, nil
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/patient", sync.O.Host, sync.O.Prefix)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user