Ejemplo n.º 1
0
func sendTreatmentCreated(t *models.Treatment) {
	topic, _ := common_io.BuildTopicFromCommonEvent(common_io.EVENT_CREATED, "treatment")

	/*
	*	marshal
	 */

	patient := models.Patient{}
	patient.ID = t.PatientId
	ps, err := patient.Retrieve(db)
	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
		return
	}

	if len(ps) != 1 {
		fmt.Println("[FATAL] More then one patient with the same ID...")
		return
	}

	t.Email = ps[0].Email

	b, err := json.Marshal(&t)
	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
		return
	}

	producer.Publish(topic, b)
}
Ejemplo n.º 2
0
func FillPatientIdWIthUrlValue(p *models.Patient, params url.Values) error {
	id, err := strconv.Atoi(params.Get("id"))
	if err != nil {
		return err
	}
	p.ID = id

	return nil
}
Ejemplo n.º 3
0
/*
*	Handlers
 */
func handleUserCreated(msg []byte) {
	var usr authModels.User
	err := json.Unmarshal(msg, &usr)

	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
	}

	switch usr.Scope {
	case "patient":
		p := models.Patient{}
		p.ID = usr.ID
		p.Name = usr.FirstName + " " + usr.LastName
		p.Email = usr.Email

		err = p.Save(db)

		createFeedEvent(p)
		return

	case "medic":
		m := models.Medic{}
		m.ID = usr.ID
		m.Name = usr.FirstName + " " + usr.LastName
		m.Email = usr.Email

		err = m.Create(db)

		return

	case "pharmacist":
		p := models.Pharmacist{}
		p.ID = usr.ID
		p.Name = usr.FirstName + " " + usr.LastName
		p.Email = usr.Email

		err = p.Save(db)
		return
	}
	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
	}

}