示例#1
0
func handleGetFeed(w http.ResponseWriter, req *http.Request) errors.Http {
	patientId := req.URL.Query().Get("patient_id")
	from := time.Now().AddDate(0, 0, -1)
	patientID, err := strconv.Atoi(patientId)
	if err != nil {
		return errors.BadRequest("Invalid patient id")
	}

	es, err := models.FindFeedEvents(from, patientID, db)
	if err != nil {
		return errors.NotFound("No events")
	}
	rend.JSON(w, 200, es)
	return nil
}
示例#2
0
func validateRecipe(w http.ResponseWriter, r *http.Request) errors.Http {
	pres_id, err := strconv.Atoi(r.URL.Query().Get("prescription_id"))
	if err != nil {
		return errors.BadRequest(err.Error())
	}

	rcpt := models.FetchReceipt(pres_id, db)
	if r.ParseForm() != nil {
		return errors.BadRequest("Invalid input")
	}
	if rcpt.UpdateStatus(models.RecipeStringToStatus(r.Form.Get("status")), db) != nil {
		return errors.NotFound("Not found")
	}
	rend.JSON(w, 200, "{}")
	return nil
}
示例#3
0
func retreiveProduct(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Product{}
	if err := BuildStructFromQueryString(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	products, err := p.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

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

	return nil
}
func retreivePurchaseProductsById(w http.ResponseWriter, r *http.Request) errors.Http {
	pp := models.PurchaseProduct{}

	if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	pproducts, err := pp.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(pproducts) != 1 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, pproducts[0])
	return nil
}
示例#5
0
func retreiveOrderById(w http.ResponseWriter, r *http.Request) errors.Http {
	o := models.Order{}

	if err := FillOrderIdWithUrlValue(&o, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	orders, err := o.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(orders) != 1 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, orders[0])
	return nil
}
示例#6
0
func retreiveTreatments(w http.ResponseWriter, r *http.Request) errors.Http {
	t := models.Treatment{}
	if err := BuildStructFromQueryString(&t, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

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

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

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

	return nil
}
示例#7
0
func retreiveMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medication{}
	if err := BuildStructFromQueryString(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

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

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

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

	return nil
}
示例#8
0
func retrievePacks(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Pack{}
	if err := BuildStructFromQueryString(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

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

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

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

	return nil
}
示例#9
0
func retrieveBoxes(w http.ResponseWriter, r *http.Request) errors.Http {
	b := models.Box{}
	if err := BuildStructFromQueryString(&b, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

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

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

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

	return nil
}
示例#10
0
func retreiveWithdrawal(w http.ResponseWriter, r *http.Request) errors.Http {
	withd := models.Withdrawal{}
	if err := BuildStructFromQueryString(&withd, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	withd.Query = r.URL.Query()

	ws, err := withd.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(ws) == 0 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, ws)

	return nil
}
示例#11
0
func retreiveOrder(w http.ResponseWriter, r *http.Request) errors.Http {
	queryString := r.URL.Query()
	var o models.Order
	decoder := decoder.NewDecoder()

	if err := decoder.DecodeURLValues(&o, queryString); err != nil {
		return errors.BadRequest(err.Error())
	}

	orders, err := o.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(orders) == 0 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, orders)
	return nil
}