func conditionEvent(id, name, icd9Code string, onset time.Time) plugin.Event {
	condition := new(models.Condition)
	condition.Id = id
	condition.Code = &models.CodeableConcept{
		Coding: []models.Coding{
			models.Coding{System: "http://hl7.org/fhir/sid/icd-9", Code: icd9Code, Display: name},
		},
		Text: name,
	}
	condition.OnsetDateTime = &models.FHIRDateTime{Time: onset, Precision: models.Timestamp}
	condition.VerificationStatus = "confirmed"

	return plugin.Event{
		Date:  onset,
		Type:  "Condition",
		End:   false,
		Value: condition,
	}
}
Ejemplo n.º 2
0
func generateCondition(name string, yearOffset int, md []ConditionMetadata) models.Condition {
	c := models.Condition{VerificationStatus: "confirmed"}
	cmd := conditionByName(name, md)
	c.Code = &models.CodeableConcept{Coding: []models.Coding{{Code: cmd.ICD9, System: "http://hl7.org/fhir/sid/icd-9"}}, Text: cmd.Display}
	c.OnsetDateTime = &models.FHIRDateTime{Time: randomOnset(yearOffset), Precision: models.Date}
	recoveryDiceRoll := rand.Intn(100)
	if recoveryDiceRoll <= cmd.AbatementChance {
		switch cmd.RecoveryEstimate {
		case "week":
			c.AbatementDateTime = &models.FHIRDateTime{Time: c.OnsetDateTime.Time.AddDate(0, 0, 7), Precision: models.Date}
		case "threeMonths":
			c.AbatementDateTime = &models.FHIRDateTime{Time: c.OnsetDateTime.Time.AddDate(0, 3, 0), Precision: models.Date}
		case "sixMonths":
			c.AbatementDateTime = &models.FHIRDateTime{Time: c.OnsetDateTime.Time.AddDate(0, 6, 0), Precision: models.Date}
		case "threeYears":
			c.AbatementDateTime = &models.FHIRDateTime{Time: c.OnsetDateTime.Time.AddDate(3, 0, 0), Precision: models.Date}
		}
	}

	return c
}
Ejemplo n.º 3
0
func GenerateConditions(ctx Context, md []ConditionMetadata) []models.Condition {
	conditions := []models.Condition{}
	if ctx.Hypertention == "Hypertension" {
		ht := generateCondition("Hypertension", 2, md)
		conditions = append(conditions, ht)
		complication := rand.Intn(5)
		if complication == 1 {
			chf := models.Condition{VerificationStatus: "confirmed"}
			chfmd := conditionByName("Congestive Heart Failure", md)
			chf.Code = &models.CodeableConcept{Coding: []models.Coding{{Code: chfmd.ICD9, System: "http://hl7.org/fhir/sid/icd-9"}}, Text: chfmd.Display}
			chf.OnsetDateTime = &models.FHIRDateTime{Time: ht.OnsetDateTime.Time.AddDate(rand.Intn(2), rand.Intn(10), rand.Intn(28)), Precision: models.Date}
			conditions = append(conditions, chf)
		}
		if complication == 2 {
			phd := models.Condition{VerificationStatus: "confirmed"}
			phdmd := conditionByName("Pulmonary Heart Disease", md)
			phd.Code = &models.CodeableConcept{Coding: []models.Coding{{Code: phdmd.ICD9, System: "http://hl7.org/fhir/sid/icd-9"}}, Text: phdmd.Display}
			phd.OnsetDateTime = &models.FHIRDateTime{Time: ht.OnsetDateTime.Time.AddDate(rand.Intn(2), rand.Intn(10), rand.Intn(28)), Precision: models.Date}
			conditions = append(conditions, phd)
		}
	}
	if ctx.Diabetes == "Diabetes" {
		dia := generateCondition("Diabetes", 2, md)
		conditions = append(conditions, dia)
	}

	if ctx.Smoker == "Smoker" {
		complication := rand.Intn(5)
		if complication == 1 {
			e := generateCondition("Emphysema", 2, md)
			conditions = append(conditions, e)
		}
		if complication == 2 {
			lc := generateCondition("Lung Cancer", 2, md)
			conditions = append(conditions, lc)
		}
	}
	// per http://www.cdc.gov/dhdsp/data_statistics/fact_sheets/fs_atrial_fibrillation.htm
	var afibChance int
	if time.Now().AddDate(-65, 0, 0).After(ctx.BirthDate) {
		afibChance = 9
	} else {
		afibChance = 2
	}

	afibDiceRoll := rand.Intn(100)
	if afibDiceRoll <= afibChance {
		afib := generateCondition("Atrial Fibrillation", 3, md)
		conditions = append(conditions, afib)
	}

	otherConditions := rand.Intn(3)
	previouslySelected := &intsets.Sparse{}
	for index := 0; index < otherConditions; index++ {
		randomCondition := 2 + rand.Intn(76)
		if !previouslySelected.Has(randomCondition) {
			rmd := conditionByID(randomCondition, md)
			rc := generateCondition(rmd.Display, index, md)
			previouslySelected.Insert(randomCondition)
			conditions = append(conditions, rc)
		}
	}

	return conditions
}