func NewAllergyGenerator(hc *config.HL7Config, d *config.Data, c clock.Clock, dg DateGenerator) *AllergyGenerator {
	return &AllergyGenerator{
		Generator:    newGenerator(d.Allergies, hc.Allergy.Types, c, dg),
		severities:   hc.Allergy.Severities,
		reactions:    d.Allergy.Reactions,
		percentage:   d.Allergy.Percentage,
		maxAllergies: d.Allergy.MaximumAllergies,
	}
}
NewAllergyGenerator creates a new Generator with the allergies from the given configurations.
package codedelement
import (
	"fmt"
	"math/rand"
	"strings"
	"github.com/google/simhospital/pkg/clock"
	"github.com/google/simhospital/pkg/config"
	"github.com/google/simhospital/pkg/ir"
	"github.com/google/simhospital/pkg/pathway"
	cpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/codes_go_proto"
)
type AllergyGenerator struct {
	*Generator
	severities   []string
	reactions    []string
	percentage   int
	maxAllergies int
}
func (g *AllergyGenerator) DeriveIdentificationDateTime(a pathway.Allergy) ir.NullTime {
	return g.nullTimeOrRandom(a.IdentificationDateTime)
}
func (g *AllergyGenerator) DeriveCodingSystem(config config.HL7Allergy, a pathway.Allergy) string {
	if a.CodingSystem != "" {
		return a.CodingSystem
	}
	return config.CodingSystem
}
func (g *AllergyGenerator) randomSeverity() string {
	return g.severities[rand.Intn(len(g.severities))]
}
func (g *AllergyGenerator) randomReaction() string {
	return g.reactions[rand.Intn(len(g.reactions))]
}
func (g *AllergyGenerator) randomIdentificationDateTime() ir.NullTime {
	return g.nullTimeOrRandom(nil)
}
func (g *AllergyGenerator) GenerateRandomDistinctAllergies() []*ir.Allergy {
	var generatedAllergies []*ir.Allergy
	ra := rand.Intn(100)
	if ra >= g.percentage {
		return generatedAllergies
	}
	allergyCount := rand.Intn(g.maxAllergies) + 1
	selectedCodes := map[string]bool{}
	for len(generatedAllergies) < allergyCount {
		a := g.Random()
		if !selectedCodes[a.ID] {
			selectedCodes[a.ID] = true
			generatedAllergies = append(generatedAllergies, &ir.Allergy{
				Type:                   g.RandomType(),
				Description:            *a,
				Severity:               g.randomSeverity(),
				Reaction:               g.randomReaction(),
				IdentificationDateTime: g.randomIdentificationDateTime(),
			})
		}
	}
	return generatedAllergies
}