getPrescription method
Implementation
Future<Map?> getPrescription() async {
dynamic returnable;
await SharedPreferences.getInstance().then((pref) async {
String? token = pref.getString("token");
String? client_id = iAmA == "consultant"
? Params.consultant_client_id
: Params.patient_client_id;
/*Calling the API url */
var jsonData;
final response = await http.get(
Uri.parse(Params.base_url + "/records/prescriptions/"),
headers: {"Client-ID": "$client_id", "Authorization": "$token"});
if (debug) {
print('Status Code = ' +
response.statusCode.toString() +
". Response: " +
response.body);
}
/*If the response is 200 or 201 (success) then the response will be decoded */
if (response.statusCode == 200 || response.statusCode == 201) {
jsonData = json.decode(response.body);
returnable = {
"id": jsonData["id"],
"duration": jsonData["duration"],
"drugStrength": jsonData["drugStrength"],
"summary": jsonData["summary"],
"created": tools.dateUtil(jsonData["created"]),
"modified": tools.dateUtil(jsonData["modified"]),
"drugForm": jsonData["drugForm"],
"dose": jsonData["dose"],
"strength": jsonData["strength"],
"unit": jsonData["unit"],
"period": jsonData["period"],
"length": jsonData["length"],
"frequency": jsonData["frequency"],
"route": jsonData["route"],
"additionalNote": jsonData["additionalNote"],
"patient": jsonData["patient"],
"drug": jsonData["drug"],
"prescribedBy": jsonData["prescribedBy"]
};
} else {
if (debug) print("Error Requesting API");
returnable = null;
}
});
return returnable;
}