feat (prescription-item, medicine-mix, medication-item): adjust field, calculate qty
This commit is contained in:
@@ -20,7 +20,6 @@ type CreateDto struct {
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IsRedeemed bool `json:"isRedeemed"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Note *string `json:"note" gorm:"size:1024"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,10 +15,11 @@ type CreateDto struct {
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Frequency *uint16 `json:"frequency"`
|
||||
Dose float64 `json:"dose"`
|
||||
Usage float64 `json:"usage"`
|
||||
Usage string `json:"usage"`
|
||||
Interval uint8 `json:"interval"`
|
||||
IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"`
|
||||
IntervalMultiplier *uint16 `json:"intervalMultiplier"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -21,8 +21,12 @@ 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
|
||||
}
|
||||
|
||||
@@ -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