mdpasien add edit
This commit is contained in:
@@ -542,7 +542,7 @@ func GetTerminologyList(inp models.TerminologyParamv0) ([]models.TerminologyV0,
|
||||
|
||||
if err := dbx.Handlex.Select(&term, query,
|
||||
inp.CodeSystem,
|
||||
inp.CodeSystem); err != nil {
|
||||
inp.AttributePath); err != nil {
|
||||
return nil, fmt.Errorf("error querying database terminology: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,17 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"cpone/services"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func NewMdPasienServices(uStore db.AppStore) *MdPasienServices {
|
||||
@@ -44,7 +52,12 @@ func (su *MdPasienServices) GetListMdPasien(
|
||||
return nil, 0, fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
query := `
|
||||
SELECT m_patient.*
|
||||
SELECT m_patient.*,
|
||||
CASE
|
||||
WHEN M_PatientGender = "MALE" THEN "Laki-laki"
|
||||
WHEN M_PatientGender = "FEMALE" THEN "Perempuan"
|
||||
ELSE ""
|
||||
END AS M_PatientGender
|
||||
FROM m_patient
|
||||
JOIN m_title
|
||||
ON M_PatientM_TitleID = M_TitleID
|
||||
@@ -85,3 +98,519 @@ func (su *MdPasienServices) GetMdPasienBreadCrumb(title string) (models.BreadCru
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
func (su *MdPasienServices) GetPasienTitle() ([]models.SapaanPasien, error) {
|
||||
var sapaanList []models.SapaanPasien
|
||||
query := `
|
||||
SELECT * FROM m_title WHERE M_TitleIsActive = 'Y'
|
||||
`
|
||||
|
||||
if err := dbx.Handlex.Select(&sapaanList, query); err != nil {
|
||||
return nil, fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
|
||||
return sapaanList, nil
|
||||
|
||||
}
|
||||
func (su *MdPasienServices) Addpasien(prm models.PasienFormServicesPrm) (string, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
tx := dbx.Handlex.MustBegin()
|
||||
var numbering string
|
||||
var newFileName string
|
||||
if prm.Foto != nil {
|
||||
_, b, _, _ := runtime.Caller(0)
|
||||
basepath := filepath.Dir(b)
|
||||
println("Basepath")
|
||||
println(basepath)
|
||||
// defer logger.Sync()
|
||||
// logger.Info("FIlE",
|
||||
// zap.Any("filename", file.Filename),
|
||||
// )
|
||||
src, err := prm.Foto.Open()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error open file")
|
||||
}
|
||||
defer src.Close()
|
||||
ext := filepath.Ext(prm.Foto.Filename)
|
||||
newFileName = utils.GenerateRandomID(prm.Foto.Filename) + ext
|
||||
uploadDir := filepath.Join(basepath, "..", "..", "uploads", "patient")
|
||||
println(uploadDir)
|
||||
// Menentukan path file tujuan
|
||||
dstPath := filepath.Join(uploadDir, newFileName)
|
||||
// Membuat direktori jika belum ada
|
||||
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||
return "", fmt.Errorf("error mkdir")
|
||||
}
|
||||
// Membuka file tujuan
|
||||
dst, err := os.Create(dstPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error create file")
|
||||
}
|
||||
defer dst.Close()
|
||||
// Menyalin konten file yang diupload ke file tujuan
|
||||
if _, err = io.Copy(dst, src); err != nil {
|
||||
return "", fmt.Errorf("error copy file")
|
||||
}
|
||||
}
|
||||
|
||||
qryNum :=
|
||||
`SELECT fn_numbering("P") AS numbering`
|
||||
if err := tx.Get(&numbering, qryNum); err != nil {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get numbering",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return "", fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
gender := strings.Trim(prm.Gender, "@")
|
||||
bloodType := []string{}
|
||||
if prm.Goldar == "" {
|
||||
bloodType = append(bloodType, "")
|
||||
bloodType = append(bloodType, "")
|
||||
} else {
|
||||
bloodType = strings.Split(prm.Goldar, "@")
|
||||
if prm.Goldar != "" && len(bloodType) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split bloodtype",
|
||||
zap.Any("blood Type", bloodType),
|
||||
)
|
||||
return "", fmt.Errorf("error bloodtype")
|
||||
}
|
||||
}
|
||||
rhesus := []string{}
|
||||
if prm.Rhesus == "" {
|
||||
rhesus = append(rhesus, "")
|
||||
rhesus = append(rhesus, "")
|
||||
} else {
|
||||
rhesus = strings.Split(prm.Rhesus, "@")
|
||||
if prm.Rhesus != "" && len(rhesus) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split rhesus",
|
||||
zap.Any("blood Type", rhesus),
|
||||
)
|
||||
return "", fmt.Errorf("error rhesus")
|
||||
}
|
||||
}
|
||||
education := []string{}
|
||||
if prm.Pendidikan == "" {
|
||||
education = append(education, "")
|
||||
education = append(education, "")
|
||||
} else {
|
||||
education = strings.Split(prm.Pendidikan, "@")
|
||||
if prm.Pendidikan != "" && len(education) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split education",
|
||||
zap.Any("blood Type", education),
|
||||
)
|
||||
return "", fmt.Errorf("error education")
|
||||
}
|
||||
}
|
||||
etnis := []string{}
|
||||
if prm.Etnis == "" {
|
||||
etnis = append(etnis, "")
|
||||
etnis = append(etnis, "")
|
||||
} else {
|
||||
etnis = strings.Split(prm.Etnis, "@")
|
||||
if prm.Etnis != "" && len(etnis) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split etnis",
|
||||
zap.Any("blood Type", etnis),
|
||||
)
|
||||
return "", fmt.Errorf("error etnis")
|
||||
}
|
||||
}
|
||||
identifier := strings.Split(prm.Identitas, "@")
|
||||
if len(identifier) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split identifier",
|
||||
zap.Any("blood Type", identifier),
|
||||
)
|
||||
return "", fmt.Errorf("error identifier")
|
||||
}
|
||||
|
||||
query := `
|
||||
INSERT INTO m_patient
|
||||
(M_PatientNoReg,
|
||||
M_PatientM_TitleID,
|
||||
M_PatientPrefix,
|
||||
M_PatientName,
|
||||
M_PatientSuffix,
|
||||
M_PatientGender,
|
||||
M_PatientDOB,
|
||||
M_PatientReligionCode,
|
||||
M_PatientReligionSystem,
|
||||
M_PatientBloodTypeCode,
|
||||
M_PatientBloodTypeSystem,
|
||||
M_PatientBloodRhCode,
|
||||
M_PatientBloodRhSystem,
|
||||
M_PatientEducationCode,
|
||||
M_PatientEducationSystem,
|
||||
M_PatientCitizenship,
|
||||
M_PatientEtnicCode,
|
||||
M_PatientEtnicSystem,
|
||||
M_PatientIdentifierCode,
|
||||
M_PatientIdentifierSystem,
|
||||
M_PatientIdentifierValue,
|
||||
M_PatientJob,
|
||||
M_PatientPosisi,
|
||||
M_PatientDivisi,
|
||||
M_PatientHp,
|
||||
M_PatientEmail,
|
||||
M_PatientPhoto,
|
||||
M_PatientAddress,
|
||||
M_PatientAddressRegionalCd,
|
||||
M_PatientAddressCity,
|
||||
M_PatientAddressDistrict,
|
||||
M_PatientAddressState,
|
||||
M_PatientAddressCountry,
|
||||
M_PatientCreatedUserID
|
||||
)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
`
|
||||
|
||||
rst := tx.MustExec(query,
|
||||
numbering,
|
||||
prm.Sapaan,
|
||||
prm.Imbuhanawal,
|
||||
prm.Nama,
|
||||
prm.Imbuhanakhir,
|
||||
gender,
|
||||
prm.Dob,
|
||||
"",
|
||||
"",
|
||||
bloodType[0],
|
||||
bloodType[1],
|
||||
rhesus[0],
|
||||
rhesus[1],
|
||||
education[0],
|
||||
education[1],
|
||||
prm.Nationality,
|
||||
etnis[0],
|
||||
etnis[1],
|
||||
identifier[0],
|
||||
identifier[1],
|
||||
prm.Nomoridentitas,
|
||||
prm.Pekerjaan,
|
||||
prm.Posisi,
|
||||
prm.Departement,
|
||||
prm.Hp,
|
||||
prm.Email,
|
||||
newFileName,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
prm.UserID,
|
||||
)
|
||||
_, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error insert db",
|
||||
zap.Any("rows Affected", rst),
|
||||
zap.Any("Error", err.Error()),
|
||||
)
|
||||
return "", fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
tx.Commit()
|
||||
return numbering, nil
|
||||
|
||||
}
|
||||
func (su *MdPasienServices) GetPasienByID(id string) (*models.Pasien, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
|
||||
var pasien models.Pasien
|
||||
query := `SELECT * FROM m_patient WHERE M_PatientID = ?`
|
||||
err := dbx.Handlex.Get(&pasien, query, id)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get patient",
|
||||
zap.Any("Error", err.Error()),
|
||||
)
|
||||
return nil, fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
return &pasien, nil
|
||||
}
|
||||
|
||||
func (su *MdPasienServices) GetPasienTermonology() (
|
||||
sapaan []models.SapaanPasien,
|
||||
gender []models.TerminologyV0,
|
||||
goldar []models.TerminologyV0,
|
||||
rh []models.TerminologyV0,
|
||||
pendidikan []models.TerminologyV0,
|
||||
etnis []models.TerminologyV0,
|
||||
idType []models.TerminologyV0,
|
||||
err error) {
|
||||
logger, err := zap.NewProduction()
|
||||
sapaanList, err := su.GetPasienTitle()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET SAPAAN LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get sapaan")
|
||||
}
|
||||
genderList := []models.TerminologyV0{{Code: "MALE", Display: "Laki Laki"}, {Code: "FEMALE", Display: "Perempuan"}}
|
||||
goldarList, err := services.GetTerminologyList(models.TerminologyParamv0{AttributePath: "Person.blood.type", CodeSystem: "http://loinc.org"})
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET GOLDAR LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get tipe golongan darah")
|
||||
}
|
||||
rhesusList, err := services.GetTerminologyList(models.TerminologyParamv0{AttributePath: "Person.blood.rhesus", CodeSystem: "http://snomed.info/sct"})
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET RH LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get tipe rhesus")
|
||||
|
||||
}
|
||||
pendidikanList, err := services.GetTerminologyList(models.TerminologyParamv0{AttributePath: "Person.education", CodeSystem: "xhis.code.education.level"})
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET PENDIDIKAN LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get pendidikan")
|
||||
|
||||
}
|
||||
etnisList, err := services.GetTerminologyList(models.TerminologyParamv0{AttributePath: "Person.etnicity", CodeSystem: "xhis.code.etnicity"})
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET ETNIS LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get sapaan")
|
||||
|
||||
}
|
||||
idTypeList, err := services.GetTerminologyList(models.TerminologyParamv0{AttributePath: "Person.identifier.type", CodeSystem: "http://terminology.hl7.org/CodeSystem/v2-0203"})
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERRO GET ID TYPE LIST",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("error get tipe identitas")
|
||||
|
||||
}
|
||||
return sapaanList,
|
||||
genderList,
|
||||
goldarList,
|
||||
rhesusList,
|
||||
pendidikanList,
|
||||
etnisList,
|
||||
idTypeList,
|
||||
nil
|
||||
}
|
||||
|
||||
func (su *MdPasienServices) EditPasien(prm models.PasienFormServicesPrm) (string, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
tx := dbx.Handlex.MustBegin()
|
||||
var newFileName string
|
||||
if prm.Foto != nil {
|
||||
_, b, _, _ := runtime.Caller(0)
|
||||
basepath := filepath.Dir(b)
|
||||
println("Basepath")
|
||||
println(basepath)
|
||||
// defer logger.Sync()
|
||||
// logger.Info("FIlE",
|
||||
// zap.Any("filename", file.Filename),
|
||||
// )
|
||||
src, err := prm.Foto.Open()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error open file")
|
||||
}
|
||||
defer src.Close()
|
||||
ext := filepath.Ext(prm.Foto.Filename)
|
||||
newFileName = utils.GenerateRandomID(prm.Foto.Filename) + ext
|
||||
uploadDir := filepath.Join(basepath, "..", "..", "uploads", "patient")
|
||||
println(uploadDir)
|
||||
// Menentukan path file tujuan
|
||||
dstPath := filepath.Join(uploadDir, newFileName)
|
||||
// Membuat direktori jika belum ada
|
||||
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||
return "", fmt.Errorf("error mkdir")
|
||||
}
|
||||
// Membuka file tujuan
|
||||
dst, err := os.Create(dstPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error create file")
|
||||
}
|
||||
defer dst.Close()
|
||||
// Menyalin konten file yang diupload ke file tujuan
|
||||
if _, err = io.Copy(dst, src); err != nil {
|
||||
return "", fmt.Errorf("error copy file")
|
||||
}
|
||||
}
|
||||
updateFotoPath := ""
|
||||
if newFileName != "" {
|
||||
updateFotoPath = "M_PatientPhoto = '" + newFileName + "',"
|
||||
}
|
||||
gender := strings.Trim(prm.Gender, "@")
|
||||
bloodType := []string{}
|
||||
if prm.Goldar == "" {
|
||||
bloodType = append(bloodType, "")
|
||||
bloodType = append(bloodType, "")
|
||||
} else {
|
||||
bloodType = strings.Split(prm.Goldar, "@")
|
||||
if prm.Goldar != "" && len(bloodType) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split bloodtype",
|
||||
zap.Any("blood Type", bloodType),
|
||||
)
|
||||
return "", fmt.Errorf("error bloodtype")
|
||||
}
|
||||
}
|
||||
rhesus := []string{}
|
||||
if prm.Rhesus == "" {
|
||||
rhesus = append(rhesus, "")
|
||||
rhesus = append(rhesus, "")
|
||||
} else {
|
||||
rhesus = strings.Split(prm.Rhesus, "@")
|
||||
if prm.Rhesus != "" && len(rhesus) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split rhesus",
|
||||
zap.Any("blood Type", rhesus),
|
||||
)
|
||||
return "", fmt.Errorf("error rhesus")
|
||||
}
|
||||
}
|
||||
education := []string{}
|
||||
if prm.Pendidikan == "" {
|
||||
education = append(education, "")
|
||||
education = append(education, "")
|
||||
} else {
|
||||
education = strings.Split(prm.Pendidikan, "@")
|
||||
if prm.Pendidikan != "" && len(education) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split education",
|
||||
zap.Any("blood Type", education),
|
||||
)
|
||||
return "", fmt.Errorf("error education")
|
||||
}
|
||||
}
|
||||
etnis := []string{}
|
||||
if prm.Etnis == "" {
|
||||
etnis = append(etnis, "")
|
||||
etnis = append(etnis, "")
|
||||
} else {
|
||||
etnis = strings.Split(prm.Etnis, "@")
|
||||
if prm.Etnis != "" && len(etnis) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split etnis",
|
||||
zap.Any("blood Type", etnis),
|
||||
)
|
||||
return "", fmt.Errorf("error etnis")
|
||||
}
|
||||
}
|
||||
identifier := strings.Split(prm.Identitas, "@")
|
||||
if len(identifier) != 2 {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error split identifier",
|
||||
zap.Any("blood Type", identifier),
|
||||
)
|
||||
return "", fmt.Errorf("error identifier")
|
||||
}
|
||||
|
||||
query := `
|
||||
UPDATE m_patient
|
||||
SET
|
||||
M_PatientM_TitleID = ?,
|
||||
M_PatientPrefix = ?,
|
||||
M_PatientName = ?,
|
||||
M_PatientSuffix = ?,
|
||||
M_PatientGender = ?,
|
||||
M_PatientDOB = ?,
|
||||
M_PatientReligionCode = ?,
|
||||
M_PatientReligionSystem = ?,
|
||||
M_PatientBloodTypeCode = ?,
|
||||
M_PatientBloodTypeSystem = ?,
|
||||
M_PatientBloodRhCode = ?,
|
||||
M_PatientBloodRhSystem = ?,
|
||||
M_PatientEducationCode = ?,
|
||||
M_PatientEducationSystem = ?,
|
||||
M_PatientCitizenship = ?,
|
||||
M_PatientEtnicCode = ?,
|
||||
M_PatientEtnicSystem = ?,
|
||||
M_PatientIdentifierCode = ?,
|
||||
M_PatientIdentifierSystem = ?,
|
||||
M_PatientIdentifierValue = ?,
|
||||
M_PatientJob = ?,
|
||||
M_PatientPosisi = ?,
|
||||
M_PatientDivisi = ?,
|
||||
M_PatientHp = ?,
|
||||
M_PatientEmail = ?,
|
||||
` + updateFotoPath + `
|
||||
M_PatientAddress = ?,
|
||||
M_PatientAddressRegionalCd = ?,
|
||||
M_PatientAddressCity = ?,
|
||||
M_PatientAddressDistrict = ?,
|
||||
M_PatientAddressState = ?,
|
||||
M_PatientAddressCountry = ?,
|
||||
M_PatientCreatedUserID = ?
|
||||
WHERE M_PatientID = ?
|
||||
`
|
||||
|
||||
rst := tx.MustExec(query,
|
||||
prm.Sapaan,
|
||||
prm.Imbuhanawal,
|
||||
prm.Nama,
|
||||
prm.Imbuhanakhir,
|
||||
gender,
|
||||
prm.Dob,
|
||||
"",
|
||||
"",
|
||||
bloodType[0],
|
||||
bloodType[1],
|
||||
rhesus[0],
|
||||
rhesus[1],
|
||||
education[0],
|
||||
education[1],
|
||||
prm.Nationality,
|
||||
etnis[0],
|
||||
etnis[1],
|
||||
identifier[0],
|
||||
identifier[1],
|
||||
prm.Nomoridentitas,
|
||||
prm.Pekerjaan,
|
||||
prm.Posisi,
|
||||
prm.Departement,
|
||||
prm.Hp,
|
||||
prm.Email,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
prm.UserID,
|
||||
prm.PasienID,
|
||||
)
|
||||
_, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
defer logger.Sync()
|
||||
logger.Error("Error update db",
|
||||
zap.Any("rows Affected", rst),
|
||||
zap.Any("Error", err.Error()),
|
||||
)
|
||||
return "", fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
tx.Commit()
|
||||
return "", nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user