step 13 : fix time NOW ketika insert data
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -946,6 +947,369 @@ func (ug *ServicesMdDoctor) GetMdDoctorByID(id string) (models.DoctorV1, error)
|
||||
}
|
||||
|
||||
// PROSES ADD DOCTOR
|
||||
func (su *ServicesMdDoctor) AddMdDoctorV0(inp models.DoctorV1) (models.DoctorV1, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
var data models.DoctorV1
|
||||
var datacek []models.DoctorV1
|
||||
|
||||
defer logger.Sync()
|
||||
logger.Error("VALUE YANG DI ADD",
|
||||
zap.Any("INPUTAN VALUE", inp),
|
||||
)
|
||||
|
||||
prm := "%" + strings.TrimSpace(inp.M_DoctorName) + "%"
|
||||
qryCek := `SELECT M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorName LIKE ?
|
||||
AND M_DoctorIsActive = 'Y'`
|
||||
err := dbx.Handlex.Select(&datacek, qryCek, prm)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error cek data by doctorname",
|
||||
zap.String("doctorname", inp.M_DoctorName),
|
||||
zap.Any("datacek", datacek),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED")
|
||||
}
|
||||
if len(datacek) > 0 {
|
||||
defer logger.Sync()
|
||||
logger.Error("Doctor Name already taken by another data",
|
||||
zap.String("doctorname", inp.M_DoctorName),
|
||||
)
|
||||
return data, fmt.Errorf("doctor Name sudah dipakai")
|
||||
}
|
||||
|
||||
// VARIABLE START
|
||||
M_DoctorM_TitleID := 0
|
||||
M_DoctorCode := ""
|
||||
M_DoctorPrefix := ""
|
||||
M_DoctorPrefix2 := ""
|
||||
M_DoctorName := inp.M_DoctorName
|
||||
M_DoctorSuffix := ""
|
||||
M_DoctorSuffix2 := ""
|
||||
M_DoctorGender := inp.M_DoctorGender
|
||||
M_DoctorDOB := "0000-00-00 00:00:00"
|
||||
M_DoctorReligionCode := ""
|
||||
M_DoctorReligionSystem := ""
|
||||
M_DoctorBloodTypeCode := ""
|
||||
M_DoctorBloodTypeSystem := ""
|
||||
M_DoctorBloodRhCode := ""
|
||||
M_DoctorBloodRhSystem := ""
|
||||
M_DoctorEducationCode := ""
|
||||
M_DoctorEducationSystem := ""
|
||||
M_DoctorCitizenship := inp.M_DoctorCitizenship
|
||||
M_DoctorEtnicCode := ""
|
||||
M_DoctorEtnicSystem := ""
|
||||
M_DoctorIdentifierCode := ""
|
||||
M_DoctorIdentifierSystem := ""
|
||||
M_DoctorIdentifierValue := inp.M_DoctorIdentifierValue
|
||||
M_DoctorHp := ""
|
||||
M_DoctorEmail := ""
|
||||
M_DoctorS_SpecialistID := 0
|
||||
M_DoctorAddress := ""
|
||||
M_DoctorAddressRegionalCd := 0
|
||||
M_DoctorAddressCity := ""
|
||||
M_DoctorAddressDistrict := ""
|
||||
M_DoctorAddressState := ""
|
||||
M_DoctorAddressCountry := ""
|
||||
// VARIABLE END
|
||||
|
||||
// CHECK PARAMS
|
||||
if inp.M_DoctorM_TitleID != 0 {
|
||||
M_DoctorM_TitleID = inp.M_DoctorM_TitleID
|
||||
}
|
||||
|
||||
if inp.M_DoctorCode != "" {
|
||||
M_DoctorCode = inp.M_DoctorCode
|
||||
}
|
||||
|
||||
if inp.M_DoctorPrefix != "" {
|
||||
M_DoctorPrefix = inp.M_DoctorPrefix
|
||||
}
|
||||
|
||||
if inp.M_DoctorPrefix2 != "" {
|
||||
M_DoctorPrefix2 = inp.M_DoctorPrefix2
|
||||
}
|
||||
|
||||
if inp.M_DoctorSuffix != "" {
|
||||
M_DoctorSuffix = inp.M_DoctorSuffix
|
||||
}
|
||||
|
||||
if inp.M_DoctorSuffix2 != "" {
|
||||
M_DoctorSuffix2 = inp.M_DoctorSuffix2
|
||||
}
|
||||
|
||||
if inp.M_DoctorDOB != "" {
|
||||
M_DoctorDOB = inp.M_DoctorDOB
|
||||
}
|
||||
|
||||
if inp.M_DoctorReligionCode != "default" {
|
||||
M_DoctorReligionCode = inp.M_DoctorReligionCode
|
||||
M_DoctorReligionSystem = inp.M_DoctorReligionSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorBloodTypeCode != "default" {
|
||||
M_DoctorBloodTypeCode = inp.M_DoctorBloodTypeCode
|
||||
M_DoctorBloodTypeSystem = inp.M_DoctorBloodTypeSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorBloodRhCode != "default" {
|
||||
M_DoctorBloodRhCode = inp.M_DoctorBloodRhCode
|
||||
M_DoctorBloodRhSystem = inp.M_DoctorBloodRhSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorEducationCode != "default" {
|
||||
M_DoctorEducationCode = inp.M_DoctorEducationCode
|
||||
M_DoctorEducationSystem = inp.M_DoctorEducationSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorEtnicCode != "default" {
|
||||
M_DoctorEtnicCode = inp.M_DoctorEtnicCode
|
||||
M_DoctorEtnicSystem = inp.M_DoctorEtnicSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorIdentifierCode != "default" {
|
||||
M_DoctorIdentifierCode = inp.M_DoctorIdentifierCode
|
||||
M_DoctorIdentifierSystem = inp.M_DoctorIdentifierSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorHp != "" {
|
||||
M_DoctorHp = inp.M_DoctorHp
|
||||
}
|
||||
|
||||
if inp.M_DoctorEmail != "" {
|
||||
M_DoctorEmail = inp.M_DoctorEmail
|
||||
}
|
||||
|
||||
if inp.M_DoctorM_SpecialistID != "0" {
|
||||
M_DoctorS_SpecialistID, err = strconv.Atoi(inp.M_DoctorM_SpecialistID)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error CONVERT DOCTOR SPECIALIS",
|
||||
zap.Any("M_SpecialistID", M_DoctorS_SpecialistID),
|
||||
)
|
||||
return data, fmt.Errorf("error CONVERT DOCTOR SPECIALIS")
|
||||
}
|
||||
}
|
||||
|
||||
if inp.M_DoctorAddressRegionalCd != 0 {
|
||||
M_DoctorAddressRegionalCd = inp.M_DoctorAddressRegionalCd
|
||||
M_DoctorAddress = inp.M_DoctorAddress
|
||||
M_DoctorAddressCity = inp.M_DoctorAddressCity
|
||||
M_DoctorAddressDistrict = inp.M_DoctorAddressDistrict
|
||||
M_DoctorAddressState = inp.M_DoctorAddressState
|
||||
M_DoctorAddressCountry = inp.M_DoctorAddressCountry
|
||||
}
|
||||
|
||||
// CHECK PARAMS
|
||||
query := `INSERT INTO m_doctor
|
||||
(
|
||||
M_DoctorM_TitleID,
|
||||
M_DoctorCode,
|
||||
M_DoctorPrefix,
|
||||
M_DoctorPrefix2,
|
||||
M_DoctorName,
|
||||
M_DoctorSuffix,
|
||||
M_DoctorSuffix2,
|
||||
M_DoctorGender,
|
||||
M_DoctorDOB,
|
||||
M_DoctorReligionCode,
|
||||
M_DoctorReligionSystem,
|
||||
M_DoctorBloodTypeCode,
|
||||
M_DoctorBloodTypeSystem,
|
||||
M_DoctorBloodRhCode,
|
||||
M_DoctorBloodRhSystem,
|
||||
M_DoctorEducationCode,
|
||||
M_DoctorEducationSystem,
|
||||
M_DoctorCitizenship,
|
||||
M_DoctorEtnicCode,
|
||||
M_DoctorEtnicSystem,
|
||||
M_DoctorIdentifierCode,
|
||||
M_DoctorIdentifierSystem,
|
||||
M_DoctorIdentifierValue,
|
||||
M_DoctorHp,
|
||||
M_DoctorEmail,
|
||||
M_DoctorM_SpecialistID,
|
||||
M_DoctorAddress,
|
||||
M_DoctorAddressRegionalCd,
|
||||
M_DoctorAddressCity,
|
||||
M_DoctorAddressDistrict,
|
||||
M_DoctorAddressState,
|
||||
M_DoctorAddressCountry,
|
||||
M_DoctorIsActive,
|
||||
M_DoctorCreatedUserID,
|
||||
M_DoctorCreated
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
rst := dbx.Handlex.MustExec(query,
|
||||
M_DoctorM_TitleID,
|
||||
M_DoctorCode,
|
||||
M_DoctorPrefix,
|
||||
M_DoctorPrefix2,
|
||||
M_DoctorName,
|
||||
M_DoctorSuffix,
|
||||
M_DoctorSuffix2,
|
||||
M_DoctorGender,
|
||||
M_DoctorDOB,
|
||||
M_DoctorReligionCode,
|
||||
M_DoctorReligionSystem,
|
||||
M_DoctorBloodTypeCode,
|
||||
M_DoctorBloodTypeSystem,
|
||||
M_DoctorBloodRhCode,
|
||||
M_DoctorBloodRhSystem,
|
||||
M_DoctorEducationCode,
|
||||
M_DoctorEducationSystem,
|
||||
M_DoctorCitizenship,
|
||||
M_DoctorEtnicCode,
|
||||
M_DoctorEtnicSystem,
|
||||
M_DoctorIdentifierCode,
|
||||
M_DoctorIdentifierSystem,
|
||||
M_DoctorIdentifierValue,
|
||||
M_DoctorHp,
|
||||
M_DoctorEmail,
|
||||
M_DoctorS_SpecialistID,
|
||||
M_DoctorAddress,
|
||||
M_DoctorAddressRegionalCd,
|
||||
M_DoctorAddressCity,
|
||||
M_DoctorAddressDistrict,
|
||||
M_DoctorAddressState,
|
||||
M_DoctorAddressCountry,
|
||||
"Y",
|
||||
"1",
|
||||
time.Now(),
|
||||
)
|
||||
insertedID, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error Insert doctor",
|
||||
zap.Any("object doctoraddv1", inp),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED LastInsertId")
|
||||
}
|
||||
s := strconv.Itoa(int(insertedID))
|
||||
|
||||
// json after start
|
||||
var dataJSON models.DoctorJSONv1
|
||||
qryJson := `select *
|
||||
from m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y'
|
||||
AND M_DoctorID = ?`
|
||||
|
||||
err = dbx.HandlexLog.Get(&dataJSON, qryJson, insertedID)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get json by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
dbx.Handlex.MustBegin().Rollback()
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA JSON AFTER INSERT")
|
||||
}
|
||||
|
||||
// Mengubah slice dari struct menjadi JSON string
|
||||
jsonData, err := json.Marshal(dataJSON)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error format JSON",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED ERROR CONVERT JSON")
|
||||
}
|
||||
|
||||
// Mengubah JSON byte slice menjadi string
|
||||
jsonStringInsert := string(jsonData)
|
||||
|
||||
qryInsertLog := `INSERT INTO cpone_log
|
||||
(
|
||||
Log_DoctorM_DoctorID,
|
||||
Log_DoctorDate,
|
||||
Log_DoctorCode,
|
||||
Log_DoctorJsonBefore,
|
||||
Log_DoctorJsonAfter,
|
||||
Log_DoctorUserID
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
_, err = dbx.HandlexLog.Exec(qryInsertLog,
|
||||
insertedID,
|
||||
time.Now(),
|
||||
"ADD",
|
||||
"",
|
||||
jsonStringInsert,
|
||||
"1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error inserting query log",
|
||||
zap.Error(err),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED INSERT_LOG")
|
||||
}
|
||||
|
||||
// json after end
|
||||
data, err = su.GetMdDoctorByID(s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get doctor by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA AFTER INSERT")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
var data models.DoctorV1
|
||||
@@ -1102,7 +1466,6 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
}
|
||||
|
||||
// CHECK PARAMS
|
||||
|
||||
query := `INSERT INTO m_doctor
|
||||
(
|
||||
M_DoctorM_TitleID,
|
||||
@@ -1177,7 +1540,7 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
NOW()
|
||||
)`
|
||||
|
||||
rst := dbx.Handlex.MustExec(query,
|
||||
@@ -1215,7 +1578,6 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
M_DoctorAddressCountry,
|
||||
"Y",
|
||||
"1",
|
||||
time.Now(),
|
||||
)
|
||||
insertedID, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
@@ -1226,6 +1588,75 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
return data, fmt.Errorf("QUERY_FAILED LastInsertId")
|
||||
}
|
||||
s := strconv.Itoa(int(insertedID))
|
||||
|
||||
// insert cpone_log.log_doctor start
|
||||
var dataJSON models.DoctorJSONv1
|
||||
qryJson := `select *
|
||||
from m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y'
|
||||
AND M_DoctorID = ?`
|
||||
|
||||
err = dbx.Handlex.Get(&dataJSON, qryJson, s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get json by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA JSON AFTER INSERT")
|
||||
}
|
||||
|
||||
// Mengubah slice dari struct menjadi JSON string
|
||||
jsonData, err := json.Marshal(dataJSON)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error format JSON",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED ERROR CONVERT JSON")
|
||||
}
|
||||
|
||||
// Mengubah JSON byte slice menjadi string
|
||||
jsonStringInsert := string(jsonData)
|
||||
|
||||
qryInsertLog := `INSERT INTO log_doctor
|
||||
(
|
||||
Log_DoctorM_DoctorID,
|
||||
Log_DoctorDate,
|
||||
Log_DoctorCode,
|
||||
Log_DoctorJsonBefore,
|
||||
Log_DoctorJsonAfter,
|
||||
Log_DoctorUserID
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
NOW(),
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
_, err = dbx.HandlexLog.Exec(qryInsertLog,
|
||||
insertedID,
|
||||
"ADD",
|
||||
"",
|
||||
jsonStringInsert,
|
||||
"1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error inserting query log",
|
||||
zap.Any("ERROR MSG INSERT LOG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED INSERT_LOG")
|
||||
}
|
||||
|
||||
// insert cpone_log.log_doctor end
|
||||
data, err = su.GetMdDoctorByID(s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
|
||||
Reference in New Issue
Block a user