示例#1
0
文件: common_io.go 项目: asvins/core
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
}