diff --git a/docs/docs.go b/docs/docs.go index fd605f9..d7a8e6e 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -156,7 +156,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/diagnosa.DiagnosaModel" + "$ref": "#/definitions/diagnosa.DiagnosaResponse" } } }, @@ -269,7 +269,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/pasien.PasienModel" + "$ref": "#/definitions/pasien.PasienResponse" } } }, @@ -374,7 +374,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/tindakan.TindakanModel" + "$ref": "#/definitions/tindakan.TindakanResponse" } } }, @@ -626,16 +626,16 @@ const docTemplate = `{ } } }, - "diagnosa.DiagnosaModel": { + "diagnosa.DiagnosaResponse": { "type": "object", "properties": { - "jenisPenyakit": { + "keterangan": { "type": "string" }, - "kodeDiagnosa": { + "kodeicd": { "type": "string" }, - "sebabPenyakit": { + "select": { "type": "string" } } @@ -684,19 +684,22 @@ const docTemplate = `{ } } }, - "pasien.PasienModel": { + "pasien.PasienResponse": { "type": "object", "properties": { "alamat": { "type": "string" }, - "alamatKtp": { + "alamatktp": { "type": "string" }, - "id": { - "type": "integer" + "dataumur": { + "$ref": "#/definitions/pasien.dataUmurResponse" }, - "jenisKelamin": { + "id": { + "type": "string" + }, + "jeniskelamin": { "type": "string" }, "nama": { @@ -705,11 +708,34 @@ const docTemplate = `{ "nik": { "type": "string" }, - "noMr": { + "nomr": { "type": "string" }, - "tglLahir": { + "select": { "type": "string" + }, + "tgllahir": { + "type": "string" + }, + "umur": { + "type": "integer" + } + } + }, + "pasien.dataUmurResponse": { + "type": "object", + "properties": { + "bulan": { + "type": "integer" + }, + "hari": { + "type": "integer" + }, + "label": { + "type": "string" + }, + "tahun": { + "type": "integer" } } }, @@ -787,13 +813,16 @@ const docTemplate = `{ } } }, - "tindakan.TindakanModel": { + "tindakan.TindakanResponse": { "type": "object", "properties": { - "KodeTindakan": { + "keterangan": { "type": "string" }, - "Tindakan": { + "kode": { + "type": "string" + }, + "select": { "type": "string" } } diff --git a/docs/swagger.json b/docs/swagger.json index 2adefaa..33979fe 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -150,7 +150,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/diagnosa.DiagnosaModel" + "$ref": "#/definitions/diagnosa.DiagnosaResponse" } } }, @@ -263,7 +263,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/pasien.PasienModel" + "$ref": "#/definitions/pasien.PasienResponse" } } }, @@ -368,7 +368,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/tindakan.TindakanModel" + "$ref": "#/definitions/tindakan.TindakanResponse" } } }, @@ -620,16 +620,16 @@ } } }, - "diagnosa.DiagnosaModel": { + "diagnosa.DiagnosaResponse": { "type": "object", "properties": { - "jenisPenyakit": { + "keterangan": { "type": "string" }, - "kodeDiagnosa": { + "kodeicd": { "type": "string" }, - "sebabPenyakit": { + "select": { "type": "string" } } @@ -678,19 +678,22 @@ } } }, - "pasien.PasienModel": { + "pasien.PasienResponse": { "type": "object", "properties": { "alamat": { "type": "string" }, - "alamatKtp": { + "alamatktp": { "type": "string" }, - "id": { - "type": "integer" + "dataumur": { + "$ref": "#/definitions/pasien.dataUmurResponse" }, - "jenisKelamin": { + "id": { + "type": "string" + }, + "jeniskelamin": { "type": "string" }, "nama": { @@ -699,11 +702,34 @@ "nik": { "type": "string" }, - "noMr": { + "nomr": { "type": "string" }, - "tglLahir": { + "select": { "type": "string" + }, + "tgllahir": { + "type": "string" + }, + "umur": { + "type": "integer" + } + } + }, + "pasien.dataUmurResponse": { + "type": "object", + "properties": { + "bulan": { + "type": "integer" + }, + "hari": { + "type": "integer" + }, + "label": { + "type": "string" + }, + "tahun": { + "type": "integer" } } }, @@ -781,13 +807,16 @@ } } }, - "tindakan.TindakanModel": { + "tindakan.TindakanResponse": { "type": "object", "properties": { - "KodeTindakan": { + "keterangan": { "type": "string" }, - "Tindakan": { + "kode": { + "type": "string" + }, + "select": { "type": "string" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c89b18b..14badf1 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -158,13 +158,13 @@ definitions: kategori: type: string type: object - diagnosa.DiagnosaModel: + diagnosa.DiagnosaResponse: properties: - jenisPenyakit: + keterangan: type: string - kodeDiagnosa: + kodeicd: type: string - sebabPenyakit: + select: type: string type: object dokter.DokterResponse: @@ -196,24 +196,41 @@ definitions: - published type: string type: object - pasien.PasienModel: + pasien.PasienResponse: properties: alamat: type: string - alamatKtp: + alamatktp: type: string + dataumur: + $ref: '#/definitions/pasien.dataUmurResponse' id: - type: integer - jenisKelamin: + type: string + jeniskelamin: type: string nama: type: string nik: type: string - noMr: + nomr: type: string - tglLahir: + select: type: string + tgllahir: + type: string + umur: + type: integer + type: object + pasien.dataUmurResponse: + properties: + bulan: + type: integer + hari: + type: integer + label: + type: string + tahun: + type: integer type: object shared.BaseErrorResponse: properties: @@ -263,11 +280,13 @@ definitions: sub_spesialis: type: string type: object - tindakan.TindakanModel: + tindakan.TindakanResponse: properties: - KodeTindakan: + keterangan: type: string - Tindakan: + kode: + type: string + select: type: string type: object host: localhost:8080 @@ -368,7 +387,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/diagnosa.DiagnosaModel' + $ref: '#/definitions/diagnosa.DiagnosaResponse' type: array "500": description: Internal Server Error @@ -441,7 +460,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/pasien.PasienModel' + $ref: '#/definitions/pasien.PasienResponse' type: array "500": description: Internal Server Error @@ -508,7 +527,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/tindakan.TindakanModel' + $ref: '#/definitions/tindakan.TindakanResponse' type: array "500": description: Internal Server Error diff --git a/internal/domain/reference/diagnosa/handler.go b/internal/domain/reference/diagnosa/handler.go index eac431d..84376b1 100644 --- a/internal/domain/reference/diagnosa/handler.go +++ b/internal/domain/reference/diagnosa/handler.go @@ -20,7 +20,7 @@ func NewDiagnosaHandler(repo IDiagnosaRepository) DiagnosaHandler { // @Summary Get List Diagnosa // @Tags Reference // @Param search query string false "Search keyword" -// @Success 200 {object} []DiagnosaModel +// @Success 200 {object} []DiagnosaResponse // @Failure 500 {object} shared.BaseErrorResponse // @Router /reference/diagnosa/ [get] func (h DiagnosaHandler) ListDiagnosa(c *gin.Context) { diff --git a/internal/domain/reference/diagnosa/model.go b/internal/domain/reference/diagnosa/model.go index 854bbe7..c575dd0 100644 --- a/internal/domain/reference/diagnosa/model.go +++ b/internal/domain/reference/diagnosa/model.go @@ -7,14 +7,16 @@ type DiagnosaModel struct { } type DiagnosaResponse struct { - KodeDiagnosa string `db:"kode_diagnosa"` - Diagnosa string `db:"diagnosa"` + KodeIcd string `json:"kodeicd"` + Keterangan string `json:"keterangan"` + Select string `json:"select"` } func (m DiagnosaModel) ToResponse() DiagnosaResponse { return DiagnosaResponse{ - KodeDiagnosa: m.KodeDiagnosa, - Diagnosa: m.JenisPenyakit, + KodeIcd: m.KodeDiagnosa, + Keterangan: m.JenisPenyakit, + Select: m.KodeDiagnosa + " | " + m.JenisPenyakit, } } diff --git a/internal/domain/reference/pasien/handler.go b/internal/domain/reference/pasien/handler.go index b83a1a0..a6d4996 100644 --- a/internal/domain/reference/pasien/handler.go +++ b/internal/domain/reference/pasien/handler.go @@ -20,7 +20,7 @@ func NewPasienHandler(repo IPasienRepository) PasienHandler { // @Summary Get List Pasien // @Tags Reference // @Param search query string false "Search keyword" -// @Success 200 {object} []PasienModel +// @Success 200 {object} []PasienResponse // @Failure 500 {object} shared.BaseErrorResponse // @Router /reference/pasien/ [get] func (h PasienHandler) ListPasienOperasi(c *gin.Context) { @@ -35,7 +35,7 @@ func (h PasienHandler) ListPasienOperasi(c *gin.Context) { return } - response := baseResponse.ToBaseResponse(list, true, 200, "success get pasien") + response := baseResponse.ToBaseResponse(list.ToResponseList(), true, 200, "success get pasien") c.JSON(http.StatusOK, response) } diff --git a/internal/domain/reference/pasien/model.go b/internal/domain/reference/pasien/model.go index 5490b66..676cf1c 100644 --- a/internal/domain/reference/pasien/model.go +++ b/internal/domain/reference/pasien/model.go @@ -1,12 +1,77 @@ package pasien +import ( + "strconv" + "time" +) + type PasienModel struct { - Id int `db:"id"` - Alamat string `db:"alamat"` - AlamatKtp string `db:"alamat_ktp"` - JenisKelamin string `db:"jeniskelamin"` - Nama string `db:"nama"` - Nik string `db:"noktp"` - NoMr string `db:"nomr"` - TglLahir string `db:"tgllahir"` + Id int `db:"id"` + Alamat string `db:"alamat"` + AlamatKtp string `db:"alamat_ktp"` + JenisKelamin string `db:"jeniskelamin"` + Nama string `db:"nama"` + Nik string `db:"noktp"` + NoMr string `db:"nomr"` + TglLahir time.Time `db:"tgllahir"` +} + +type PasienResponse struct { + Id string `json:"id"` + NoMr string `json:"nomr"` + Nik string `json:"nik"` + Nama string `json:"nama"` + TglLahir string `json:"tgllahir"` + JenisKelamin string `json:"jeniskelamin"` + Umur int `json:"umur"` + DataUmur dataUmurResponse `json:"dataumur"` + Alamat string `json:"alamat"` + AlamatKtp string `json:"alamatktp"` + Select string `json:"select"` +} + +type dataUmurResponse struct { + Label string `json:"label"` + Tahun int `json:"tahun"` + Bulan int `json:"bulan"` + Hari int `json:"hari"` +} + +func (m PasienModel) ToResponse() PasienResponse { + idstring := strconv.Itoa(m.Id) + nowdate := time.Now() + + age := CalculateAge(m.TglLahir, nowdate) + + ageLabel := strconv.Itoa(age.Years) + "Th " + strconv.Itoa(age.Months) + "Bln " + strconv.Itoa(age.Days) + "Hr" + + return PasienResponse{ + Id: idstring, + NoMr: m.NoMr, + Nik: m.Nik, + Nama: m.Nama, + TglLahir: m.TglLahir.Format("2006-01-02"), + JenisKelamin: m.JenisKelamin, + Umur: age.Years, + DataUmur: dataUmurResponse{ + Label: ageLabel, + Tahun: age.Years, + Bulan: age.Months, + Hari: age.Days, + }, + Alamat: m.Alamat, + AlamatKtp: m.AlamatKtp, + Select: m.NoMr + " | " + m.Nama, + } +} + +type ListPasienModel []PasienModel + +func (rows ListPasienModel) ToResponseList() []PasienResponse { + result := make([]PasienResponse, 0, len(rows)) + for _, item := range rows { + result = append(result, item.ToResponse()) + } + + return result } diff --git a/internal/domain/reference/pasien/repository.go b/internal/domain/reference/pasien/repository.go index cd7c901..8d8b1f9 100644 --- a/internal/domain/reference/pasien/repository.go +++ b/internal/domain/reference/pasien/repository.go @@ -13,7 +13,7 @@ const DB_NAME = "db_simrs" const TBL_NAME = "m_pasien" type IPasienRepository interface { - SearchableListPasien(c *gin.Context) ([]PasienModel, error) + SearchableListPasien(c *gin.Context) (ListPasienModel, error) GetPasienByNoMr(c *gin.Context, id int) (PasienModel, error) } @@ -61,8 +61,8 @@ func baseSelectQuery() queryUtils.DynamicQuery { } } -func (r pasienRepo) SearchableListPasien(c *gin.Context) ([]PasienModel, error) { - var result []PasienModel +func (r pasienRepo) SearchableListPasien(c *gin.Context) (ListPasienModel, error) { + var result ListPasienModel search := c.Query("search") query := baseSelectQuery() @@ -94,7 +94,7 @@ func (r pasienRepo) SearchableListPasien(c *gin.Context) ([]PasienModel, error) } func (r pasienRepo) GetPasienByNoMr(c *gin.Context, id int) (PasienModel, error) { - var resultQuery []PasienModel + var resultQuery ListPasienModel var result PasienModel query := baseSelectQuery() diff --git a/internal/domain/reference/pasien/utils.go b/internal/domain/reference/pasien/utils.go new file mode 100644 index 0000000..71ce4a4 --- /dev/null +++ b/internal/domain/reference/pasien/utils.go @@ -0,0 +1,57 @@ +package pasien + +import "time" + +type Age struct { + Years int + Months int + Days int +} + +func CalculateAge(birthDate, now time.Time) Age { + // Pastikan jam = 00:00:00 biar konsisten + birthDate = time.Date( + birthDate.Year(), birthDate.Month(), birthDate.Day(), + 0, 0, 0, 0, birthDate.Location(), + ) + now = time.Date( + now.Year(), now.Month(), now.Day(), + 0, 0, 0, 0, now.Location(), + ) + + years := now.Year() - birthDate.Year() + months := int(now.Month()) - int(birthDate.Month()) + days := now.Day() - birthDate.Day() + + // Kalau hari negatif, pinjam dari bulan + if days < 0 { + previousMonth := now.AddDate(0, -1, 0) + days += daysInMonth(previousMonth) + months-- + } + + // Kalau bulan negatif, pinjam dari tahun + if months < 0 { + months += 12 + years-- + } + + if years < 0 { + return Age{} + } + + return Age{ + Years: years, + Months: months, + Days: days, + } +} + +func daysInMonth(t time.Time) int { + firstOfNextMonth := time.Date( + t.Year(), t.Month()+1, 1, + 0, 0, 0, 0, t.Location(), + ) + lastOfMonth := firstOfNextMonth.AddDate(0, 0, -1) + return lastOfMonth.Day() +} diff --git a/internal/domain/reference/tindakan/handler.go b/internal/domain/reference/tindakan/handler.go index 9fd5ba0..edefadd 100644 --- a/internal/domain/reference/tindakan/handler.go +++ b/internal/domain/reference/tindakan/handler.go @@ -20,7 +20,7 @@ func NewTindakanHandler(repo ITindakanRepository) TindakanHandler { // @Summary Get List Tindakan // @Tags Reference // @Param search query string false "Search keyword" -// @Success 200 {object} []TindakanModel +// @Success 200 {object} []TindakanResponse // @Failure 500 {object} shared.BaseErrorResponse // @Router /reference/tindakan/ [get] func (h TindakanHandler) ListDiagnosa(c *gin.Context) { @@ -35,7 +35,7 @@ func (h TindakanHandler) ListDiagnosa(c *gin.Context) { return } - response := baseResponse.ToBaseResponse(list, true, 200, "success get diagnosa") + response := baseResponse.ToBaseResponse(list.ToResponseList(), true, 200, "success get diagnosa") c.JSON(http.StatusOK, response) } diff --git a/internal/domain/reference/tindakan/model.go b/internal/domain/reference/tindakan/model.go index 7dcdc6b..5f4e431 100644 --- a/internal/domain/reference/tindakan/model.go +++ b/internal/domain/reference/tindakan/model.go @@ -4,3 +4,28 @@ type TindakanModel struct { KodeTindakan string `db:"kode" json:"KodeTindakan"` Keterangan string `db:"keterangan" json:"Tindakan"` } + +type TindakanResponse struct { + Kode string `json:"kode"` + Keterangan string `json:"keterangan"` + Select string `json:"select"` +} + +func (m TindakanModel) ToResponse() TindakanResponse { + return TindakanResponse{ + Kode: m.KodeTindakan, + Keterangan: m.Keterangan, + Select: m.KodeTindakan + " | " + m.Keterangan, + } +} + +type ListTindakanModel []TindakanModel + +func (rows ListTindakanModel) ToResponseList() []TindakanResponse { + result := make([]TindakanResponse, 0, len(rows)) + for _, item := range rows { + result = append(result, item.ToResponse()) + } + + return result +} diff --git a/internal/domain/reference/tindakan/repository.go b/internal/domain/reference/tindakan/repository.go index f5368a3..3c0aea2 100644 --- a/internal/domain/reference/tindakan/repository.go +++ b/internal/domain/reference/tindakan/repository.go @@ -12,7 +12,7 @@ const DB_NAME = "db_simrs" const TBL_NAME = "icd_cm" type ITindakanRepository interface { - SearchableListTindakan(c *gin.Context) ([]TindakanModel, error) + SearchableListTindakan(c *gin.Context) (ListTindakanModel, error) } type diagnosaRepo struct { @@ -33,8 +33,8 @@ func NewRepository(dbService database.Service) ITindakanRepository { } } -func (r diagnosaRepo) SearchableListTindakan(c *gin.Context) ([]TindakanModel, error) { - var result []TindakanModel +func (r diagnosaRepo) SearchableListTindakan(c *gin.Context) (ListTindakanModel, error) { + var result ListTindakanModel search := c.Query("search") query := queryUtils.DynamicQuery{