/app/src/main/java/info/nightscout/android/upload/nightscout/TreatmentsEndpoints.java

https://github.com/pazaan/600SeriesAndroidUploader · Java · 371 lines · 263 code · 93 blank · 15 comment · 0 complexity · 043676b245dab1acc853cef99d819be3 MD5 · raw file

  1. package info.nightscout.android.upload.nightscout;
  2. import com.google.gson.annotations.SerializedName;
  3. import java.math.BigDecimal;
  4. import java.util.Date;
  5. import java.util.List;
  6. import okhttp3.ResponseBody;
  7. import retrofit2.Call;
  8. import retrofit2.http.Body;
  9. import retrofit2.http.DELETE;
  10. import retrofit2.http.GET;
  11. import retrofit2.http.Headers;
  12. import retrofit2.http.POST;
  13. import retrofit2.http.Path;
  14. import retrofit2.http.Query;
  15. /**
  16. * Created by Pogman on 3.11.17.
  17. */
  18. public interface TreatmentsEndpoints {
  19. class Treatment {
  20. @SerializedName("_id")
  21. private String _id;
  22. @SerializedName("key600")
  23. private String key600;
  24. @SerializedName("pumpMAC600")
  25. private String pumpMAC600;
  26. @SerializedName("eventType")
  27. private String eventType;
  28. @SerializedName("created_at")
  29. private String created_at;
  30. @SerializedName("device")
  31. private String device;
  32. @SerializedName("notes")
  33. private String notes;
  34. @SerializedName("enteredBy")
  35. private String enteredBy;
  36. @SerializedName("reason")
  37. private String reason;
  38. @SerializedName("profile")
  39. private String profile;
  40. @SerializedName("enteredinsulin")
  41. private String enteredinsulin;
  42. @SerializedName("splitNow")
  43. private String splitNow;
  44. @SerializedName("splitExt")
  45. private String splitExt;
  46. @SerializedName("units")
  47. private String units;
  48. @SerializedName("glucoseType")
  49. private String glucoseType;
  50. @SerializedName("insulin")
  51. private Float insulin;
  52. @SerializedName("duration")
  53. private Float duration;
  54. @SerializedName("absolute")
  55. private Float absolute;
  56. @SerializedName("percent")
  57. private Float percent;
  58. @SerializedName("relative")
  59. private Float relative;
  60. @SerializedName("preBolus")
  61. private Float preBolus;
  62. @SerializedName("carbs")
  63. private Float carbs;
  64. @SerializedName("glucose")
  65. private BigDecimal glucose;
  66. @SerializedName("isAnnouncement")
  67. private Boolean isAnnouncement;
  68. public String get_id() {
  69. return _id;
  70. }
  71. public void set_id(String _id) {
  72. this._id = _id;
  73. }
  74. public String getKey600() {
  75. return key600;
  76. }
  77. public void setKey600(String key600) {
  78. this.key600 = key600;
  79. }
  80. public String getPumpMAC600() {
  81. return pumpMAC600;
  82. }
  83. public void setPumpMAC600(String pumpMAC600) {
  84. this.pumpMAC600 = pumpMAC600;
  85. }
  86. public String getEventType() {
  87. return eventType;
  88. }
  89. public void setEventType(String eventType) {
  90. this.eventType = eventType;
  91. }
  92. public String getCreated_at() {
  93. return created_at;
  94. }
  95. public String getDevice() {
  96. return device;
  97. }
  98. public void setDevice(String device) {
  99. this.device = device;
  100. }
  101. public String getNotes() {
  102. return notes;
  103. }
  104. public void setNotes(String notes) {
  105. this.notes = notes;
  106. }
  107. public String getEnteredBy() {
  108. return enteredBy;
  109. }
  110. public void setEnteredBy(String enteredBy) {
  111. this.enteredBy = enteredBy;
  112. }
  113. public String getReason() {
  114. return reason;
  115. }
  116. public void setReason(String reason) {
  117. this.reason = reason;
  118. }
  119. public String getProfile() {
  120. return profile;
  121. }
  122. public void setProfile(String profile) {
  123. this.profile = profile;
  124. }
  125. public String getEnteredinsulin() {
  126. return enteredinsulin;
  127. }
  128. public void setEnteredinsulin(String enteredinsulin) {
  129. this.enteredinsulin = enteredinsulin;
  130. }
  131. public String getSplitNow() {
  132. return splitNow;
  133. }
  134. public void setSplitNow(String splitNow) {
  135. this.splitNow = splitNow;
  136. }
  137. public String getSplitExt() {
  138. return splitExt;
  139. }
  140. public void setSplitExt(String splitExt) {
  141. this.splitExt = splitExt;
  142. }
  143. public String getUnits() {
  144. return units;
  145. }
  146. public void setUnits(String units) {
  147. this.units = units;
  148. }
  149. public String getGlucoseType() {
  150. return glucoseType;
  151. }
  152. public void setGlucoseType(String glucoseType) {
  153. this.glucoseType = glucoseType;
  154. }
  155. public Float getInsulin() {
  156. return insulin;
  157. }
  158. public void setInsulin(Float insulin) {
  159. this.insulin = insulin;
  160. }
  161. public Float getDuration() {
  162. return duration;
  163. }
  164. public void setDuration(Float duration) {
  165. this.duration = duration;
  166. }
  167. public Float getAbsolute() {
  168. return absolute;
  169. }
  170. public void setAbsolute(Float absolute) {
  171. this.absolute = absolute;
  172. }
  173. public Float getPercent() {
  174. return percent;
  175. }
  176. public void setPercent(Float percent) {
  177. this.percent = percent;
  178. }
  179. public Float getRelative() {
  180. return relative;
  181. }
  182. public void setRelative(Float relative) {
  183. this.relative = relative;
  184. }
  185. public Float getPreBolus() {
  186. return preBolus;
  187. }
  188. public void setPreBolus(Float preBolus) {
  189. this.preBolus = preBolus;
  190. }
  191. public Float getCarbs() {
  192. return carbs;
  193. }
  194. public void setCarbs(Float carbs) {
  195. this.carbs = carbs;
  196. }
  197. public BigDecimal getGlucose() {
  198. return glucose;
  199. }
  200. public void setGlucose(BigDecimal glucose) {
  201. this.glucose = glucose;
  202. }
  203. public Boolean getAnnouncement() {
  204. return isAnnouncement;
  205. }
  206. public void setAnnouncement(Boolean announcement) {
  207. isAnnouncement = announcement;
  208. }
  209. public void setCreated_at(Date created_at) {
  210. this.created_at = NightscoutUploadProcess.formatDateForNS(created_at);
  211. }
  212. }
  213. // https://docs.mongodb.com/v3.6/reference/operator/query/
  214. // find treatments using key
  215. @GET("/api/v1/treatments.json")
  216. Call<List<Treatment>> findKey(@Query("find[created_at][$gte]") String from,
  217. @Query("find[key600]") String key);
  218. // find treatments using key within date range
  219. @GET("/api/v1/treatments.json")
  220. Call<List<Treatment>> findKey(@Query("find[created_at][$gte]") String from,
  221. @Query("find[created_at][$lte]") String to,
  222. @Query("find[key600]") String key);
  223. // find treatments using date range
  224. @GET("/api/v1/treatments.json")
  225. Call<List<Treatment>> findDateRangeCount(@Query("find[created_at][$gte]") String from,
  226. @Query("find[created_at][$lte]") String to,
  227. @Query("count") String count);
  228. // find non-keyed treatments exclude by eventType
  229. @GET("/api/v1/treatments.json")
  230. Call<List<Treatment>> findCleanupItems(@Query("find[created_at][$gte]") String from,
  231. @Query("find[created_at][$lte]") String to,
  232. @Query("find[eventType][$ne]") String type,
  233. @Query("find[key600][$not][$exists]") String empty,
  234. @Query("count") String count);
  235. // find treatment using partial key within date range
  236. @GET("/api/v1/treatments.json")
  237. Call<List<Treatment>> findKeyRegex(@Query("find[created_at][$gte]") String from,
  238. @Query("find[created_at][$lte]") String to,
  239. @Query("find[key600][$regex]") String key,
  240. @Query("count") String count);
  241. @GET("/api/v1/treatments.json")
  242. Call<List<Treatment>> findNotesRegex(@Query("find[created_at][$gte]") String from,
  243. @Query("find[created_at][$lte]") String to,
  244. @Query("find[notes][$regex]") String notes,
  245. @Query("count") String count);
  246. @GET("/api/v1/treatments.json")
  247. Call<List<Treatment>> findKeyRegexNoPumpMAC(@Query("find[created_at][$gte]") String from,
  248. @Query("find[created_at][$lte]") String to,
  249. @Query("find[key600][$regex]") String key,
  250. @Query("find[pumpMAC600][$not][$exists]") String pumpMAC600,
  251. @Query("count") String count);
  252. @GET("/api/v1/treatments.json")
  253. Call<List<Treatment>> findNotesRegexNoPumpMAC(@Query("find[created_at][$gte]") String from,
  254. @Query("find[created_at][$lte]") String to,
  255. @Query("find[notes][$regex]") String notes,
  256. @Query("find[key600][$exists]") String key600,
  257. @Query("find[pumpMAC600][$not][$exists]") String pumpMAC600,
  258. @Query("count") String count);
  259. // NS v0.11.1 delete handling changed to work as query based
  260. // regression caused the id based method to be limited to 4 days max causing deletes older then this to not complete
  261. // delete using id
  262. @DELETE("/api/v1/treatments/{id}")
  263. Call<ResponseBody> deleteID(@Path("id") String id);
  264. // query based delete
  265. @DELETE("/api/v1/treatments.json")
  266. Call<ResponseBody> deleteID(@Query("find[created_at]") String date,
  267. @Query("find[_id]") String id);
  268. @Headers({
  269. "Accept: application/json",
  270. "Content-type: application/json"
  271. })
  272. // post single treatment
  273. @POST("/api/v1/treatments")
  274. Call<ResponseBody> sendTreatment(@Body Treatment treatment);
  275. // post bulk treatments
  276. @POST("/api/v1/treatments")
  277. Call<ResponseBody> sendTreatments(@Body List<Treatment> treatments);
  278. }