createPrescription method
Future<Map?>
createPrescription(
- int patient,
- int drug,
- String drug_form,
- int dose,
- int strength,
- String unit,
- String period,
- String length,
- String frequency,
- String route,
- String additional_note,
)
Implementation
Future<Map?> createPrescription(
int patient,
int drug,
String drug_form,
int dose,
int strength,
String unit,
String period,
String length,
String frequency,
String route,
String additional_note) async {
///date format [dateTime] is 2021-04-22 06:00:00
dynamic returnable;
await SharedPreferences.getInstance().then((pref) async {
String? token = pref.getString("token");
Map data = {
"patient": patient,
"drug": drug,
"drug_form": drug_form,
"dose": dose,
"strength": strength,
"unit": unit,
"period": period,
"length": length,
"frequency": frequency,
"route": route,
"additional_note": additional_note
};
String? client_id = iAmA == "consultant"
? Params.consultant_client_id
: Params.patient_client_id;
/*Calling the API url */
var jsonData;
final response = await http.post(
Uri.parse(Params.base_url + "/records/prescriptions/"),
body: data,
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"],
"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"]
};
}
// if dateTime in the past
else {
if (debug) print("Error Requesting API");
returnable = null;
}
});
return returnable;
}