func chooseOptionalValue(pathwayString pathway.OptionalRandomString, random string, original string) string {
	switch {
	case pathwayString.IsFixedValue():
		return pathwayString.String()
	case !pathwayString.IsSet() && original != "":
		return original
	default:
		return random
	}
}
chooseOptionalValue returns an appropriate value based on whether "pathwayString", "original" and "random" are set.
package person
import (
	"fmt"
	"math/rand"
	"github.com/google/simhospital/pkg/clock"
	"github.com/google/simhospital/pkg/gender"
	"github.com/google/simhospital/pkg/generator/id"
	"github.com/google/simhospital/pkg/generator/names"
	"github.com/google/simhospital/pkg/ir"
	"github.com/google/simhospital/pkg/pathway"
)
type AddressGenerator interface {
	Random() *ir.Address
}
type Generator struct {
	Clock              clock.Clock
	NameGenerator      *names.Generator
	GenderConvertor    gender.Convertor
	EthnicityGenerator EthnicityGenerator
	AddressGenerator   AddressGenerator
	MRNGenerator       id.Generator
}
func (g Generator) NewPerson(pathwayPerson *pathway.Person) *ir.Person {
	person := &ir.Person{
		Suffix:      g.NameGenerator.Suffix(),
		Degree:      g.NameGenerator.Degree(),
		Ethnicity:   g.EthnicityGenerator.Random(),
		PhoneNumber: g.phoneNumber(),
	}
	g.UpdatePersonFromPathway(person, pathwayPerson)
	return person
}
func (g Generator) UpdatePersonFromPathway(person *ir.Person, pathwayPerson *pathway.Person) {
	if pathwayPerson == nil {
		pathwayPerson = &pathway.Person{}
	}
	switch {
	case pathwayPerson.DateOfBirth != nil:
		person.Birth = ir.NewValidTime(*pathwayPerson.DateOfBirth)
	case pathwayPerson.Age != nil:
		person.Birth = ir.NewValidTime(pathwayPerson.Age.Birthdate(g.Clock))
	case !person.Birth.Valid:
		person.Birth = ir.NewValidTime(pathway.RandomBirthdate(g.Clock))
	}
	originalGender := person.Gender
	person.Gender = g.chooseGenderValue(pathwayPerson.Gender, person.Gender)
	internalGender := g.GenderConvertor.HL7ToInternal(person.Gender)
	if person.Gender != originalGender {
		person.MiddleName = g.NameGenerator.MiddleName(internalGender)
		person.Prefix = g.NameGenerator.Prefix(internalGender)
	}
	person.FirstName = chooseValue(pathwayPerson.FirstName, g.NameGenerator.FirstName(internalGender,
		person.Birth.Year()), person.FirstName)
	person.Surname = chooseOptionalValue(pathwayPerson.Surname, g.NameGenerator.Surname(),
		person.Surname)
	person.Address = g.mergeAddressFromPathway(pathwayPerson.Address, person.Address)
	person.NHS = chooseValue(pathwayPerson.NHS, newNHSNumber(), person.NHS)
	person.MRN = chooseValueLazy(pathwayPerson.MRN, func() string { return g.MRNGenerator.NewID() }, person.MRN)
}
func (g Generator) mergeAddressFromPathway(a *pathway.Address, p *ir.Address) *ir.Address {
	random := g.AddressGenerator.Random()
	if p == nil {
		p = random
	}
	if a == nil {
		return p
	}
	if a.AllRandom {
		return random
	}
	p.FirstLine = chooseOptionalValue(a.FirstLine, random.FirstLine, p.FirstLine)
	if a.FirstLine.IsSet() {
		if a.SecondLine == "" {
			p.SecondLine = ""
		} else {
			p.SecondLine = chooseOptionalValue(a.SecondLine, random.SecondLine, p.SecondLine)
		}
	}
	p.City = chooseOptionalValue(a.City, random.City, p.City)
	p.PostalCode = chooseOptionalValue(a.Postcode, random.PostalCode, p.PostalCode)
	p.Country = chooseOptionalValue(a.Country, random.Country, p.Country)
	p.Type = chooseOptionalValue(a.Type, random.Type, p.Type)
	return p
}