feat (medication-item): add qty calculation if intervalMultiplier is not nil
This commit is contained in:
@@ -9,18 +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"`
|
||||
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"`
|
||||
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 {
|
||||
|
||||
@@ -29,4 +29,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicationItem) {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user