Пример #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)
}
Пример #2
0
func handlePatientRetrieve(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Patient{}
	if err := BuildStructFromQueryString(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	p.Base.Query = r.URL.Query()

	ps, err := p.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

	if len(ps) == 0 {
		return errors.NotFound("record not found")
	}
	rend.JSON(w, http.StatusOK, ps)

	return nil
}