Merge pull request #38 from dikstub-rssa/feat/medicine-mix-prescription-37
Feat/medicine mix prescription 37
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
-- Modify "MedicationItem" table
|
||||
ALTER TABLE "public"."MedicationItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL;
|
||||
-- Modify "PrescriptionItem" table
|
||||
ALTER TABLE "public"."PrescriptionItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL;
|
||||
-- Modify "MedicineMix" table
|
||||
ALTER TABLE "public"."MedicineMix" ADD COLUMN "Uom_Code" character varying(10) NULL, ADD CONSTRAINT "fk_MedicineMix_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Rename a column from "CheckupCategory_Code" to "McuSrcCategory_Code"
|
||||
ALTER TABLE "public"."McuSrc" RENAME COLUMN "CheckupCategory_Code" TO "McuSrcCategory_Code";
|
||||
-- Modify "McuSrc" table
|
||||
ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_CheckupCategory", ADD CONSTRAINT "fk_McuSrc_McuSrcCategory" FOREIGN KEY ("McuSrcCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
@@ -1,4 +1,4 @@
|
||||
h1:UQi1THfG0QI80rmHgbXNK/vgQv+5eUA5VRy3zqfWdbI=
|
||||
h1:X7LbOLpbDhciJ1O92KiWgnrVP60dDAyBKJqQKJnom+M=
|
||||
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
|
||||
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
|
||||
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
|
||||
@@ -19,3 +19,5 @@ h1:UQi1THfG0QI80rmHgbXNK/vgQv+5eUA5VRy3zqfWdbI=
|
||||
20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ=
|
||||
20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg=
|
||||
20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34=
|
||||
20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y=
|
||||
20250930140351.sql h1:aqXw0j09+xjFqemWlo0enw3tn/IT1FMxw3oUPljkjks=
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Code string `json:"code" validate:"maxLength=20"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
CheckupCategory_Code *string `json:"checkupCategory_code" validate:"maxLength=20"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Code string `json:"code" validate:"maxLength=20"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
McuSrcCategory_Code *string `json:"mcuSrcCategory_code" validate:"maxLength=20"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -19,9 +19,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
CheckupCategory_Code *string `json:"checkupCategory_code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
McuSrcCategory_Code *string `json:"mcuSrcCategory_code"`
|
||||
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
@@ -50,20 +50,20 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
CheckupCategory_Code *string `json:"checkupCategory_code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Item *ei.Item `json:"item,omitempty"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
McuSrcCategory_Code *string `json:"mcuSrcCategory_code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Item *ei.Item `json:"item,omitempty"`
|
||||
}
|
||||
|
||||
func (d McuSrc) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
CheckupCategory_Code: d.CheckupCategory_Code,
|
||||
Item_Id: d.Item_Id,
|
||||
Item: d.Item,
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
McuSrcCategory_Code: d.McuSrcCategory_Code,
|
||||
Item_Id: d.Item_Id,
|
||||
Item: d.Item,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type McuSrc struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
CheckupCategory_Code *string `json:"checkupCategory_code" gorm:"size:20"`
|
||||
CheckupCategory *emsc.McuSrcCategory `json:"checkupCategory,omitempty" gorm:"foreignKey:CheckupCategory_Code;references:Code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
|
||||
ecore.Main // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
McuSrcCategory_Code *string `json:"mcuSrcCategory_code" gorm:"size:20"`
|
||||
McuSrcCategory *emsc.McuSrcCategory `json:"mcuSrcCategory,omitempty" gorm:"foreignKey:McuSrcCategory_Code;references:Code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
|
||||
}
|
||||
|
||||
@@ -9,16 +9,19 @@ import (
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Medication_Id *uint `json:"medication_id"`
|
||||
IsMix bool `json:"isMix"`
|
||||
Medicine_Id *uint `json:"medicine_id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Usage float64 `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IsRedeemed bool `json:"isRedeemed"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Note *string `json:"note" gorm:"size:1024"`
|
||||
Medication_Id *uint `json:"medication_id"`
|
||||
IsMix bool `json:"isMix"`
|
||||
Medicine_Id *uint `json:"medicine_id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Frequency *uint16 `json:"frequency"`
|
||||
Dose float64 `json:"dose"`
|
||||
Usage string `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IsRedeemed bool `json:"isRedeemed"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Note *string `json:"note" gorm:"size:1024"`
|
||||
IntervalMultiplier *uint16 `json:"intervalMultiplier"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -71,7 +74,7 @@ type ResponseDto struct {
|
||||
Medicine *em.Medicine `json:"medicine,omitempty"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"`
|
||||
Usage float64 `json:"usage"`
|
||||
Usage string `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IsRedeemed bool `json:"isRedeemed"`
|
||||
|
||||
@@ -18,7 +18,9 @@ type MedicationItem struct {
|
||||
Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"`
|
||||
Usage float64 `json:"usage"`
|
||||
Frequency *uint16 `json:"frequency"`
|
||||
Dose float64 `json:"dose"`
|
||||
Usage string `json:"usage" gorm:"size:255"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IsRedeemed bool `json:"isRedeemed"`
|
||||
|
||||
@@ -7,11 +7,13 @@ import (
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
Uom_Code *string `json:"uom_code" validate:"maxLength=10"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
Uom_Code *string `json:"uom_code"`
|
||||
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
@@ -40,12 +42,14 @@ type MetaDto struct {
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Name string `json:"name"`
|
||||
Uom_Code *string `json:"uom_code"`
|
||||
MixItems []*emmi.MedicineMixItem `json:"mixItems"`
|
||||
}
|
||||
|
||||
func (d MedicineMix) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Name: d.Name,
|
||||
Uom_Code: d.Uom_Code,
|
||||
MixItems: d.MixItems,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
|
||||
@@ -3,10 +3,13 @@ package medicinemix
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
emmi "simrs-vx/internal/domain/main-entities/medicine-mix-item"
|
||||
eu "simrs-vx/internal/domain/main-entities/uom"
|
||||
)
|
||||
|
||||
type MedicineMix struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
Uom_Code *string `json:"uom_code" gorm:"size:10"`
|
||||
Uom *eu.Uom `json:"uom" gorm:"foreignKey:Uom_Code;references:Code"`
|
||||
MixItems []*emmi.MedicineMixItem `json:"mixItems" gorm:"foreignKey:MedicineMix_Id;references:Id"`
|
||||
}
|
||||
|
||||
@@ -9,14 +9,17 @@ import (
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Prescription_Id *uint `json:"prescription_id"`
|
||||
IsMix bool `json:"isMix"`
|
||||
Medicine_Id *uint `json:"medicine_id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Usage float64 `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Prescription_Id *uint `json:"prescription_id"`
|
||||
IsMix bool `json:"isMix"`
|
||||
Medicine_Id *uint `json:"medicine_id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Frequency *uint16 `json:"frequency" validate:"required"`
|
||||
Dose float64 `json:"dose" validate:"required"`
|
||||
Usage string `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IntervalMultiplier *uint16 `json:"intervalMultiplier" validate:"required"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -67,7 +70,9 @@ type ResponseDto struct {
|
||||
Medicine *em.Medicine `json:"medicine,omitempty"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"`
|
||||
Usage float64 `json:"usage"`
|
||||
Frequency *uint16 `json:"frequency"`
|
||||
Dose float64 `json:"dose"`
|
||||
Usage string `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
@@ -82,6 +87,8 @@ func (d PrescriptionItem) ToResponse() ResponseDto {
|
||||
Medicine: d.Medicine,
|
||||
MedicineMix_Id: d.MedicineMix_Id,
|
||||
MedicineMix: d.MedicineMix,
|
||||
Frequency: d.Frequency,
|
||||
Dose: d.Dose,
|
||||
Usage: d.Usage,
|
||||
Interval: d.Interval,
|
||||
IntervalUnit_Code: d.IntervalUnit_Code,
|
||||
|
||||
@@ -18,7 +18,9 @@ type PrescriptionItem struct {
|
||||
Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"`
|
||||
Usage float64 `json:"usage"`
|
||||
Frequency *uint16 `json:"frequency"`
|
||||
Dose float64 `json:"dose"`
|
||||
Usage string `json:"usage" gorm:"size:255"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
|
||||
@@ -142,6 +142,7 @@ func createMedication(encounter_id uint, event *pl.Event, tx *gorm.DB) error {
|
||||
medicationCreate := em.CreateDto{
|
||||
Encounter_Id: &encounter_id,
|
||||
IssuedAt: pu.GetTimeNow(),
|
||||
Status_Code: erc.DSCNew,
|
||||
}
|
||||
medication, err := um.CreateData(medicationCreate, event, tx)
|
||||
if err != nil {
|
||||
@@ -168,7 +169,8 @@ func createMedicineMixAndItem(input emi.MedicineMix, event *pl.Event, tx *gorm.D
|
||||
pl.SetLogInfo(event, nil, "started", "createMedicineMix")
|
||||
|
||||
medicineMixCreate := emi.CreateDto{
|
||||
Name: input.Name,
|
||||
Name: input.Name,
|
||||
Uom_Code: input.Uom_Code,
|
||||
}
|
||||
medicineMix, err := umi.CreateData(medicineMixCreate, event, tx)
|
||||
if err != nil {
|
||||
|
||||
@@ -29,8 +29,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSrc) {
|
||||
|
||||
data.Code = inputSrc.Code
|
||||
data.Name = inputSrc.Name
|
||||
data.CheckupCategory_Code = inputSrc.CheckupCategory_Code
|
||||
data.Item_Id = inputSrc.Item_Id
|
||||
data.McuSrcCategory_Code = inputSrc.McuSrcCategory_Code
|
||||
}
|
||||
|
||||
func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
|
||||
|
||||
@@ -21,8 +21,23 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicationItem) {
|
||||
data.IsMix = inputSrc.IsMix
|
||||
data.Medicine_Id = inputSrc.Medicine_Id
|
||||
data.MedicineMix_Id = inputSrc.MedicineMix_Id
|
||||
data.Frequency = inputSrc.Frequency
|
||||
data.Dose = inputSrc.Dose
|
||||
data.Usage = inputSrc.Usage
|
||||
data.Interval = inputSrc.Interval
|
||||
data.IntervalUnit_Code = inputSrc.IntervalUnit_Code
|
||||
data.IsRedeemed = inputSrc.IsRedeemed
|
||||
data.Quantity = inputSrc.Quantity
|
||||
data.Note = inputSrc.Note
|
||||
|
||||
if inputSrc.IntervalMultiplier != nil {
|
||||
data.Quantity = countQty(*inputSrc)
|
||||
}
|
||||
}
|
||||
|
||||
func countQty(input e.CreateDto) float64 {
|
||||
if input.Frequency != nil && input.Dose != 0 && input.IntervalMultiplier != nil {
|
||||
return (float64(*input.Frequency) * float64(input.Dose)) * float64(*input.IntervalMultiplier)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -18,4 +18,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicineMix) {
|
||||
}
|
||||
|
||||
data.Name = inputSrc.Name
|
||||
data.Uom_Code = inputSrc.Uom_Code
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
input.Quantity = countQty(input)
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
|
||||
@@ -21,8 +21,17 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PrescriptionItem) {
|
||||
data.IsMix = inputSrc.IsMix
|
||||
data.Medicine_Id = inputSrc.Medicine_Id
|
||||
data.MedicineMix_Id = inputSrc.MedicineMix_Id
|
||||
data.Frequency = inputSrc.Frequency
|
||||
data.Dose = inputSrc.Dose
|
||||
data.Usage = inputSrc.Usage
|
||||
data.Interval = inputSrc.Interval
|
||||
data.IntervalUnit_Code = inputSrc.IntervalUnit_Code
|
||||
data.Quantity = inputSrc.Quantity
|
||||
}
|
||||
|
||||
func countQty(input e.CreateDto) float64 {
|
||||
if input.Frequency != nil && input.Dose != 0 && input.IntervalMultiplier != nil {
|
||||
return (float64(*input.Frequency) * float64(input.Dose)) * float64(*input.IntervalMultiplier)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -85,7 +85,8 @@ func createMedicineMixAndItem(input emi.MedicineMix, event *pl.Event, tx *gorm.D
|
||||
pl.SetLogInfo(event, nil, "started", "createMedicineMix")
|
||||
|
||||
medicineMixCreate := emi.CreateDto{
|
||||
Name: input.Name,
|
||||
Name: input.Name,
|
||||
Uom_Code: input.Uom_Code,
|
||||
}
|
||||
medicineMix, err := umi.CreateData(medicineMixCreate, event, tx)
|
||||
if err != nil {
|
||||
@@ -116,6 +117,8 @@ func createMedicationItem(medication_id uint, input epi.PrescriptionItem, event
|
||||
IsMix: input.IsMix,
|
||||
Medicine_Id: input.Medicine_Id,
|
||||
MedicineMix_Id: input.MedicineMix_Id,
|
||||
Frequency: input.Frequency,
|
||||
Dose: input.Dose,
|
||||
Usage: input.Usage,
|
||||
Interval: input.Interval,
|
||||
IntervalUnit_Code: input.IntervalUnit_Code,
|
||||
|
||||
Reference in New Issue
Block a user