func (cs *CHA2DS2VAScPluginSuite) TestFemaleWithEveryFactor(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Congestive Heart Failure", "428.0", time.Date(1993, time.March, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("3", "Hypertension", "401.0", time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("4", "Diabetes", "250.0", time.Date(2000, time.May, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("5", "Stroke", "434.91", time.Date(2004, time.June, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("6", 65, time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("7", "Vascular Disease", "443.9", time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("8", 75, time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 8) cs.assertResult(c, results[0], time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC), 1, 1.3, "1223", 0, 0, 0, 0, 0, 0, 1) cs.assertResult(c, results[1], time.Date(1993, time.March, 15, 15, 0, 0, 0, time.UTC), 2, 2.2, "1223", 1, 0, 0, 0, 0, 0, 1) cs.assertResult(c, results[2], time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC), 3, 3.2, "1223", 1, 1, 0, 0, 0, 0, 1) cs.assertResult(c, results[3], time.Date(2000, time.May, 15, 15, 0, 0, 0, time.UTC), 4, 4.0, "1223", 1, 1, 1, 0, 0, 0, 1) cs.assertResult(c, results[4], time.Date(2004, time.June, 15, 15, 0, 0, 0, time.UTC), 6, 9.8, "1223", 1, 1, 1, 2, 0, 0, 1) cs.assertResult(c, results[5], time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC), 7, 9.6, "1223", 1, 1, 1, 2, 0, 1, 1) cs.assertResult(c, results[6], time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC), 8, 6.7, "1223", 1, 1, 1, 2, 1, 1, 1) cs.assertResult(c, results[7], time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC), 9, 15.2, "1223", 1, 1, 1, 2, 1, 2, 1) }
func (cs *SimplePluginSuite) TestFutureEventsAreIgnored(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) afibStart, afibEnd := conditionStartAndEndEvents("1", "Atrial Fibrillation", "427.31", time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), time.Date(2035, time.May, 15, 15, 0, 0, 0, time.UTC)) aspirinStart, aspirinEnd := medicationStartAndEndEvents("2", "Aspirin", "1191", time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC), time.Date(2015, time.May, 15, 15, 30, 0, 0, time.UTC)) es.Events = append(es.Events, afibStart) es.Events = append(es.Events, aspirinStart) es.Events = append(es.Events, conditionEvent("3", "Hypertension", "401.0", time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("4", "Lisinopril", "104377", time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, aspirinEnd) // This future event should not be counted! es.Events = append(es.Events, conditionEvent("5", "Stroke", "434.91", time.Date(2030, time.June, 15, 15, 0, 0, 0, time.UTC))) // This future event end should not be counted! es.Events = append(es.Events, afibEnd) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 5) cs.assertResult(c, results[0], time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), 1, "1223", 1, 0) cs.assertResult(c, results[1], time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC), 2, "1223", 1, 1) cs.assertResult(c, results[2], time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC), 3, "1223", 2, 1) cs.assertResult(c, results[3], time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC), 4, "1223", 2, 2) cs.assertResult(c, results[4], time.Date(2015, time.May, 15, 15, 30, 0, 0, time.UTC), 3, "1223", 2, 1) }
func (cs *CHA2DS2VAScPluginSuite) TestNonSignificantEvents(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Skin Rash", "782.1", time.Date(1985, time.January, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Atrial Fibrillation", "427.31", time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC))) weightFloat := float64(163) weight := models.Quantity{Value: &weightFloat, Unit: "lb_av"} es.Events = append(es.Events, observationEvent("3", "Body Weight", "29463-7", weight, time.Date(1991, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("4", "Congestive Heart Failure", "428.0", time.Date(1993, time.March, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("5", "Hypertension", "401.0", time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("6", "Diabetes", "250.0", time.Date(2000, time.May, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("7", "Stroke", "434.91", time.Date(2004, time.June, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("8", 65, time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("9", "Ganglion Cyst", "727.4", time.Date(2006, time.July, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("10", "Vascular Disease", "443.9", time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("11", 75, time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, encounterEvent("12", "Consultation", "11429006", time.Date(2016, time.February, 15, 15, 0, 0, 0, time.UTC))) weightFloat = float64(147) weight = models.Quantity{Value: &weightFloat, Unit: "lb_av"} es.Events = append(es.Events, observationEvent("13", "Body Weight", "29463-7", weight, time.Date(2016, time.February, 15, 15, 5, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 8) cs.assertResult(c, results[0], time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC), 1, 1.3, "1223", 0, 0, 0, 0, 0, 0, 1) cs.assertResult(c, results[1], time.Date(1993, time.March, 15, 15, 0, 0, 0, time.UTC), 2, 2.2, "1223", 1, 0, 0, 0, 0, 0, 1) cs.assertResult(c, results[2], time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC), 3, 3.2, "1223", 1, 1, 0, 0, 0, 0, 1) cs.assertResult(c, results[3], time.Date(2000, time.May, 15, 15, 0, 0, 0, time.UTC), 4, 4.0, "1223", 1, 1, 1, 0, 0, 0, 1) cs.assertResult(c, results[4], time.Date(2004, time.June, 15, 15, 0, 0, 0, time.UTC), 6, 9.8, "1223", 1, 1, 1, 2, 0, 0, 1) cs.assertResult(c, results[5], time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC), 7, 9.6, "1223", 1, 1, 1, 2, 0, 1, 1) cs.assertResult(c, results[6], time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC), 8, 6.7, "1223", 1, 1, 1, 2, 1, 1, 1) cs.assertResult(c, results[7], time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC), 9, 15.2, "1223", 1, 1, 1, 2, 1, 2, 1) }
func (cs *CHA2DS2VAScPluginSuite) TestMaleWithAFibOnly(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1980, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "male", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 1) cs.assertResult(c, results[0], time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC), 0, 0.0, "1223", 0, 0, 0, 0, 0, 0, 0) }
// BundleToEventStream takes a bundle of resources and converts them to an EventStream. Currently only a // limited set of resource types are supported, with unsupported resource types resulting in an error. If // the bundle contains more than one patient, this is also considered an error. func BundleToEventStream(bundle *models.Bundle) (es *plugin.EventStream, err error) { var patient *models.Patient events := make([]plugin.Event, 0, len(bundle.Entry)) for _, entry := range bundle.Entry { switch r := entry.Resource.(type) { default: err = fmt.Errorf("Unsupported: Converting %s to Event", reflect.TypeOf(r).Elem().Name()) return case *models.Patient: if patient != nil { err = errors.New("Found more than one patient in resources") return } patient = r case *models.Condition: if r.VerificationStatus != "confirmed" { continue } if onset, err := findDate(false, r.OnsetDateTime, r.OnsetPeriod, r.DateRecorded); err == nil { events = append(events, plugin.Event{Date: onset, Type: "Condition", End: false, Value: r}) } if abatement, err := findDate(true, r.AbatementDateTime, r.AbatementPeriod); err == nil { events = append(events, plugin.Event{Date: abatement, Type: "Condition", End: true, Value: r}) } // TODO: What happens if there is no date at all? case *models.MedicationStatement: if r.Status == "" || r.Status == "entered-in-error" { continue } if active, err := findDate(false, r.EffectiveDateTime, r.EffectivePeriod, r.DateAsserted); err == nil { events = append(events, plugin.Event{Date: active, Type: "MedicationStatement", End: false, Value: r}) } if inactive, err := findDate(true, r.EffectivePeriod); err == nil { events = append(events, plugin.Event{Date: inactive, Type: "MedicationStatement", End: true, Value: r}) } // TODO: What happens if there is no date at all? case *models.Observation: if r.Status != "final" && r.Status != "amended" && r.Status != "preliminary" && r.Status != "registered" { continue } if effective, err := findDate(false, r.EffectiveDateTime, r.EffectivePeriod, r.Issued); err == nil { events = append(events, plugin.Event{Date: effective, Type: "Observation", End: false, Value: r}) } if ineffective, err := findDate(true, r.EffectivePeriod); err == nil { events = append(events, plugin.Event{Date: ineffective, Type: "Observation", End: true, Value: r}) } // TODO: What happens if there is no date at all? } } es = plugin.NewEventStream(patient) plugin.SortEventsByDate(events) es.Events = events return es, nil }
func (cs *SimplePluginSuite) TestPatientWithNoConditionsAndSomeMeds(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, medicationEvent("1", "Aspirin", "1191", time.Date(2010, time.April, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("2", "Lisinopril", "104377", time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 2) cs.assertResult(c, results[0], time.Date(2010, time.April, 15, 15, 30, 0, 0, time.UTC), 1, "1223", 0, 1) cs.assertResult(c, results[1], time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC), 2, "1223", 0, 2) }
func (cs *SimplePluginSuite) TestPatientWithSomeConditionsAndNoMeds(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Hypertension", "401.0", time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 2) cs.assertResult(c, results[0], time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), 1, "1223", 1, 0) cs.assertResult(c, results[1], time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC), 2, "1223", 2, 0) }
func (cs *SimplePluginSuite) TestPatientWithNoConditionsAndNoMeds(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) // We expect one result with an asof time of now(ish) c.Assert(results, HasLen, 1) // Since we don't have a good way of knowing the exact expected timestamp, just check that it is recent and then // take it as an expected value so it doesn't fail the assertResult call t := results[0].AsOf c.Assert(time.Since(t).Minutes() < 1.0, Equals, true) cs.assertResult(c, results[0], t, 0, "1223", 0, 0) }
func (cs *CHA2DS2VAScPluginSuite) TestNoAFib(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) // None of these events should matter because this score is only valid for patients with atrial fibrillation es.Events = append(es.Events, ageEvent("1", 65, time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Congestive Heart Failure", "428.0", time.Date(2006, time.March, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("4", "Diabetes", "250.0", time.Date(2012, time.May, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("5", 75, time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, NotNil) c.Assert(err, FitsTypeOf, plugin.NotApplicableError{}) c.Assert(err.Error(), Equals, "CHA2DS2-VASc is only applicable to patients with Atrial Fibrillation") c.Assert(results, HasLen, 0) }
func (cs *CHA2DS2VAScPluginSuite) TestFactorsBeforeAFib(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) // These first two events shouldn't trigger risk calculation results since they are *before* afib es.Events = append(es.Events, ageEvent("1", 65, time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Congestive Heart Failure", "428.0", time.Date(2006, time.March, 15, 15, 0, 0, 0, time.UTC))) // Once afib is diagnosed, the previous events should already be factored in the score es.Events = append(es.Events, conditionEvent("3", "Atrial Fibrillation", "427.31", time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("4", "Diabetes", "250.0", time.Date(2012, time.May, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("5", 75, time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 3) cs.assertResult(c, results[0], time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), 3, 3.2, "1223", 1, 0, 0, 0, 0, 1, 1) cs.assertResult(c, results[1], time.Date(2012, time.May, 15, 15, 0, 0, 0, time.UTC), 4, 4.0, "1223", 1, 0, 1, 0, 0, 1, 1) cs.assertResult(c, results[2], time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC), 5, 6.7, "1223", 1, 0, 1, 0, 0, 2, 1) }
func (cs *SimplePluginSuite) TestNonSignificantEvents(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("2", "Aspirin", "1191", time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, encounterEvent("3", "Consultation", "11429006", time.Date(2012, time.March, 15, 15, 0, 0, 0, time.UTC))) weightFloat := float64(163) weight := models.Quantity{Value: &weightFloat, Unit: "lb_av"} es.Events = append(es.Events, observationEvent("4", "Body Weight", "29463-7", weight, time.Date(2012, time.March, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("5", "Hypertension", "401.0", time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("6", "Lisinopril", "104377", time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 4) cs.assertResult(c, results[0], time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), 1, "1223", 1, 0) cs.assertResult(c, results[1], time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC), 2, "1223", 1, 1) cs.assertResult(c, results[2], time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC), 3, "1223", 2, 1) cs.assertResult(c, results[3], time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC), 4, "1223", 2, 2) }
func (cs *CHA2DS2VAScPluginSuite) TestFutureEventsAreIgnored(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("2", "Hypertension", "401.0", time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("3", 65, time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("4", "Vascular Disease", "443.9", time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, ageEvent("5", 75, time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC))) // This future event should not be counted! es.Events = append(es.Events, conditionEvent("6", "Stroke", "434.91", time.Date(2035, time.June, 15, 15, 0, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 5) cs.assertResult(c, results[0], time.Date(1990, time.February, 15, 15, 0, 0, 0, time.UTC), 1, 1.3, "1223", 0, 0, 0, 0, 0, 0, 1) cs.assertResult(c, results[1], time.Date(1997, time.April, 15, 15, 0, 0, 0, time.UTC), 2, 2.2, "1223", 0, 1, 0, 0, 0, 0, 1) cs.assertResult(c, results[2], time.Date(2005, time.July, 1, 0, 0, 0, 0, time.UTC), 3, 3.2, "1223", 0, 1, 0, 0, 0, 1, 1) cs.assertResult(c, results[3], time.Date(2007, time.July, 15, 15, 0, 0, 0, time.UTC), 4, 4.0, "1223", 0, 1, 0, 0, 1, 1, 1) cs.assertResult(c, results[4], time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC), 5, 6.7, "1223", 0, 1, 0, 0, 1, 2, 1) }
func (cs *SimplePluginSuite) TestPatientWithDuplicates(c *C) { birthDate := &models.FHIRDateTime{Time: time.Date(1940, time.July, 1, 0, 0, 0, 0, time.UTC), Precision: models.Date} patient := &models.Patient{Gender: "female", BirthDate: birthDate} patient.Id = "1223" es := plugin.NewEventStream(patient) es.Events = append(es.Events, conditionEvent("1", "Atrial Fibrillation", "427.31", time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("2", "Aspirin", "1191", time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("3", "Hypertension", "401.0", time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("4", "Lisinopril", "104377", time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC))) es.Events = append(es.Events, conditionEvent("5", "Hypertension", "401.0", time.Date(2015, time.May, 1, 15, 0, 0, 0, time.UTC))) es.Events = append(es.Events, medicationEvent("6", "Lisinopril", "104377", time.Date(2015, time.May, 1, 15, 30, 0, 0, time.UTC))) results, err := cs.Plugin.Calculate(es, cs.FHIREndpointURL) c.Assert(err, IsNil) c.Assert(results, HasLen, 6) cs.assertResult(c, results[0], time.Date(2010, time.February, 15, 15, 0, 0, 0, time.UTC), 1, "1223", 1, 0) cs.assertResult(c, results[1], time.Date(2010, time.February, 15, 15, 30, 0, 0, time.UTC), 2, "1223", 1, 1) cs.assertResult(c, results[2], time.Date(2015, time.April, 15, 15, 0, 0, 0, time.UTC), 3, "1223", 2, 1) cs.assertResult(c, results[3], time.Date(2015, time.April, 15, 15, 30, 0, 0, time.UTC), 4, "1223", 2, 2) cs.assertResult(c, results[4], time.Date(2015, time.May, 1, 15, 0, 0, 0, time.UTC), 4, "1223", 2, 2) cs.assertResult(c, results[5], time.Date(2015, time.May, 1, 15, 30, 0, 0, time.UTC), 4, "1223", 2, 2) }