prescription refactoring

merge-requests/714/head
hussam al-habibeh 3 years ago
parent 764578f28e
commit da45f8c4b6

File diff suppressed because it is too large Load Diff

@ -0,0 +1,76 @@
import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class PrescriptionTextFiled extends StatefulWidget {
dynamic element;
final String elementError;
final List<dynamic> elementList;
final String keyName;
final String keyId;
final String hintText;
final double width;
final Function(dynamic) okFunction;
PrescriptionTextFiled(
{Key key,
@required this.element,
@required this.elementError,
this.width,
this.elementList,
this.keyName,
this.keyId,
this.hintText,
this.okFunction})
: super(key: key);
@override
_PrescriptionTextFiledState createState() => _PrescriptionTextFiledState();
}
class _PrescriptionTextFiledState extends State<PrescriptionTextFiled> {
@override
Widget build(BuildContext context) {
return Container(
width: widget.width ?? null,
child: InkWell(
onTap: widget.elementList != null
? () {
Helpers.hideKeyboard(context);
ListSelectDialog dialog = ListSelectDialog(
list: widget.elementList,
attributeName: '${widget.keyName}',
attributeValueId: '${widget.keyId}',
okText: TranslationBase.of(context).ok,
okFunction: (selectedValue) =>
widget.okFunction(selectedValue),
);
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return dialog;
},
);
}
: null,
child: AppTextFieldCustom(
hintText: widget.hintText,
dropDownText: widget.elementList.length == 1
? widget.elementList[0]['${widget.keyName}']
: widget.element != null
? widget.element['${widget.keyName}']
: null,
isTextFieldHasSuffix: true,
validationError:
widget.elementList.length != 1 ? widget.elementError : null,
enabled: false,
),
),
);
}
}

@ -1,5 +1,4 @@
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/prescription/add_prescription_form.dart';
@ -16,7 +15,6 @@ import 'package:doctor_app_flutter/widgets/shared/user-guid/in_patient_doctor_ca
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class PrescriptionsPage extends StatelessWidget {
@override
@ -86,9 +84,7 @@ class PrescriptionsPage extends StatelessWidget {
fontSize: 13,
),
AppText(
TranslationBase
.of(context)
.prescriptions,
TranslationBase.of(context).prescriptions,
bold: true,
fontSize: 22,
),
@ -96,15 +92,14 @@ class PrescriptionsPage extends StatelessWidget {
),
),
if ((patient.patientStatusType != null &&
patient.patientStatusType == 43) ||
patient.patientStatusType == 43) ||
(isFromLiveCare && patient.appointmentNo != null))
AddNewOrder(
onTap: () {
addPrescriptionForm(context, model, patient,
model.prescriptionList);
},
label: TranslationBase
.of(context)
label: TranslationBase.of(context)
.applyForNewPrescriptionsOrder,
),
...List.generate(
@ -132,7 +127,7 @@ class PrescriptionsPage extends StatelessWidget {
.clinicDescription,
isPrescriptions: true,
appointmentDate:
AppDateUtils.getDateTimeFromServerFormat(
AppDateUtils.getDateTimeFromServerFormat(
model.prescriptionsList[index]
.appointmentDate,
),
@ -201,7 +196,7 @@ class PrescriptionsPage extends StatelessWidget {
clinic: 'basheer',
isPrescriptions: true,
appointmentDate:
AppDateUtils.getDateTimeFromServerFormat(
AppDateUtils.getDateTimeFromServerFormat(
model.inPatientPrescription[index]
.prescriptionDatetime,
),

@ -7,7 +7,7 @@ class AppDateUtils {
return DateFormat(dateFormat).format(dateTime);
}
static DateTime convertISOStringToDateTime(String date){
static DateTime convertISOStringToDateTime(String date) {
DateTime newDate;
newDate = DateTime.parse(date);
@ -27,22 +27,20 @@ class AppDateUtils {
}
static DateTime getDateTimeFromServerFormat(String str) {
DateTime date= DateTime.now();
if (str!=null) {
DateTime date = DateTime.now();
if (str != null) {
const start = "/Date(";
const end = "+0300)";
if(str.contains("/Date")){
final startIndex = str.indexOf(start);
if (str.contains("/Date")) {
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);
date = new DateTime.fromMillisecondsSinceEpoch(
int.parse(str.substring(startIndex + start.length, endIndex)));
} else {
date = DateTime.now();
}
final endIndex = str.indexOf(end, startIndex + start.length);
date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
} else {
date = DateTime.now();
}
} else {
date = DateTime.parse(str);
}
@ -50,8 +48,7 @@ class AppDateUtils {
return date;
}
static String differenceBetweenDateAndCurrentInYearMonthDay(
DateTime firstDate, BuildContext context) {
static String differenceBetweenDateAndCurrentInYearMonthDay(DateTime firstDate, BuildContext context) {
DateTime now = DateTime.now();
// now = now.add(Duration(days: 400, minutes: 0));
var difference = firstDate.difference(now);
@ -71,15 +68,13 @@ class AppDateUtils {
return "$days ${TranslationBase.of(context).days}, $months ${TranslationBase.of(context).months}, $years ${TranslationBase.of(context).years}";
}
static String differenceBetweenDateAndCurrent(
DateTime firstDate, BuildContext context) {
static String differenceBetweenDateAndCurrent(DateTime firstDate, BuildContext context) {
DateTime now = DateTime.now();
// DateTime now = nows.add(Duration(days: 400, minutes: 25, hours: 0));
var difference = now.difference(firstDate);
int minutesInDays = difference.inMinutes;
int hoursInDays =
minutesInDays ~/ 60; // ~/ : truncating division to make the result int
int hoursInDays = minutesInDays ~/ 60; // ~/ : truncating division to make the result int
int minutes = minutesInDays % 60;
int days = hoursInDays ~/ 24;
int hours = hoursInDays % 24;
@ -89,8 +84,7 @@ class AppDateUtils {
return "$days ${TranslationBase.of(context).days}, $hours ${TranslationBase.of(context).hr}, $minutes ${TranslationBase.of(context).min}";
}
static String differenceBetweenServerDateAndCurrent(
String str, BuildContext context) {
static String differenceBetweenServerDateAndCurrent(String str, BuildContext context) {
const start = "/Date(";
const end = "+0300)";
@ -99,8 +93,7 @@ class AppDateUtils {
final endIndex = str.indexOf(end, startIndex + start.length);
var date = new DateTime.fromMillisecondsSinceEpoch(
int.parse(str.substring(startIndex + start.length, endIndex)));
var date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
return differenceBetweenDateAndCurrent(date, context);
}
@ -246,7 +239,10 @@ class AppDateUtils {
final startIndex = date.indexOf(start);
final endIndex = date.indexOf(end, startIndex + start.length);
DateTime newDate = DateTime.fromMillisecondsSinceEpoch(
int.parse(date.substring(startIndex + start.length, endIndex),),);
int.parse(
date.substring(startIndex + start.length, endIndex),
),
);
return newDate;
} else
return DateTime.now();
@ -256,35 +252,30 @@ class AppDateUtils {
/// [dateTime] convert DateTime to data formatted Arabic
static String getMonthDayYearDateFormattedAr(DateTime dateTime) {
if (dateTime != null)
return getMonthArabic(dateTime.month) +
" " +
dateTime.day.toString() +
", " +
dateTime.year.toString();
return getMonthArabic(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
else
return "";
}
/// get data formatted like Apr 26,2020
/// [dateTime] convert DateTime to data formatted
static String getMonthDayYearDateFormatted(DateTime dateTime,{bool isArabic = false}) {
static String getMonthDayYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null)
return isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) +
" " +
dateTime.day.toString() +
", " +
dateTime.year.toString();
return isArabic
? getMonthArabic(dateTime.month)
: getMonth(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
else
return "";
}
/// get data formatted like 26 Apr 2020
/// [dateTime] convert DateTime to data formatted
static String getDayMonthYearDateFormatted(DateTime dateTime,{bool isArabic = false}) {
static String getDayMonthYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null)
return dateTime.day.toString()+" "+ "${isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) }"+
return dateTime.day.toString() +
" " +
"${isArabic ? getMonthArabic(dateTime.month) : getMonth(dateTime.month)}" +
" " +
dateTime.year.toString();
else
return "";
@ -292,9 +283,9 @@ class AppDateUtils {
/// get data formatted like 26/4/2020
/// [dateTime] convert DateTime to data formatted
static String getDayMonthYearDate(DateTime dateTime,{bool isArabic = false}) {
static String getDayMonthYearDate(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null)
return dateTime.day.toString()+"/"+ "${dateTime.month}"+ "/" + dateTime.year.toString();
return dateTime.day.toString() + "/" + "${dateTime.month}" + "/" + dateTime.year.toString();
else
return "";
}
@ -302,15 +293,15 @@ class AppDateUtils {
/// get data formatted like 10:45 PM
/// [dateTime] convert DateTime to data formatted
static String getHour(DateTime dateTime) {
return DateFormat('hh:mm a').format(dateTime);
return DateFormat('hh:mm a').format(dateTime);
}
static String getAgeByBirthday(String birthOfDate, BuildContext context, { bool isServerFormat = true}) {
static String getAgeByBirthday(String birthOfDate, BuildContext context, {bool isServerFormat = true}) {
// https://leechy.dev/calculate-dates-diff-in-dart
DateTime birthDate;
if(birthOfDate.contains("/Date")) {
if (birthOfDate.contains("/Date")) {
birthDate = AppDateUtils.getDateTimeFromServerFormat(birthOfDate);
}else{
} else {
birthDate = DateTime.parse(birthOfDate);
}
final now = DateTime.now();
@ -328,24 +319,18 @@ class AppDateUtils {
return "$years ${TranslationBase.of(context).years} $months ${TranslationBase.of(context).months} $days ${TranslationBase.of(context).days}";
}
static bool isToday(DateTime dateTime){
static bool isToday(DateTime dateTime) {
DateTime todayDate = DateTime.now().toUtc();
if(dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) {
if (dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) {
return true;
}
return false;
}
static String getDate(DateTime dateTime) {
print(dateTime);
if (dateTime != null)
return getMonth(dateTime.month) +
" " +
dateTime.day.toString() +
"," +
dateTime.year.toString();
return getMonth(dateTime.month) + " " + dateTime.day.toString() + "," + dateTime.year.toString();
else
return "";
}
@ -353,28 +338,23 @@ class AppDateUtils {
static String getDateFormatted(DateTime dateTime) {
print(dateTime);
if (dateTime != null)
return dateTime.day.toString() +
"/" +
dateTime.month.toString() +
"/" +
dateTime.year.toString();
return dateTime.day.toString() + "/" + dateTime.month.toString() + "/" + dateTime.year.toString();
else
return "";
}
static String getTimeHHMMA(DateTime dateTime){
static String getTimeHHMMA(DateTime dateTime) {
return DateFormat('hh:mm a').format(dateTime);
}
static String getTimeHHMMA2 (DateTime dateTime){
static String getTimeHHMMA2(DateTime dateTime) {
return DateFormat('hh:mm').format(dateTime);
}
static String getStartTime(String dateTime){
String time=dateTime;
static String getStartTime(String dateTime) {
String time = dateTime;
if(dateTime.length>7)
time = dateTime.substring(0,5);
if (dateTime.length > 7) time = dateTime.substring(0, 5);
return time;
}

@ -105,37 +105,36 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
? widget.height - 22
: null,
child: TextField(
textAlign: projectViewModel.isArabic
? TextAlign.right
: TextAlign.left,
decoration: TextFieldsUtils
.textFieldSelectorDecoration(
widget.hintText, null, true),
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 1.7,
fontFamily: 'Poppins',
color: Color(0xFF575757),
),
controller: widget.controller,
keyboardType: widget.inputType ??
(widget.maxLines == 1
? TextInputType.text
: TextInputType.multiline),
enabled: widget.enabled,
minLines: widget.minLines,
maxLines: widget.maxLines,
inputFormatters:
widget.inputFormatters != null
? widget.inputFormatters
: [],
onChanged: (value) {
setState(() {});
if (widget.onChanged != null) {
widget.onChanged(value);
}
},
obscureText: widget.isSecure
),
textAlign: projectViewModel.isArabic
? TextAlign.right
: TextAlign.left,
decoration: TextFieldsUtils
.textFieldSelectorDecoration(
widget.hintText, null, true),
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 1.7,
fontFamily: 'Poppins',
color: Color(0xFF575757),
),
controller: widget.controller,
keyboardType: widget.inputType ??
(widget.maxLines == 1
? TextInputType.text
: TextInputType.multiline),
enabled: widget.enabled,
minLines: widget.minLines,
maxLines: widget.maxLines,
inputFormatters:
widget.inputFormatters != null
? widget.inputFormatters
: [],
onChanged: (value) {
setState(() {});
if (widget.onChanged != null) {
widget.onChanged(value);
}
},
obscureText: widget.isSecure),
)
: AppText(
widget.dropDownText,

@ -7,12 +7,11 @@ import '../app_texts_widget.dart';
class TextFieldsError extends StatelessWidget {
const TextFieldsError({
Key key,
@required this.error,
@required this.error,
}) : super(key: key);
final String error;
@override
Widget build(BuildContext context) {
return Container(
@ -27,12 +26,14 @@ class TextFieldsError extends StatelessWidget {
SizedBox(
width: 12,
),
AppText(
error,
fontFamily: 'Poppins',
fontSize: SizeConfig.textMultiplier * 1.7,
color: Colors.red.shade700,
fontWeight: FontWeight.w700,
Expanded(
child: AppText(
error,
fontFamily: 'Poppins',
fontSize: SizeConfig.textMultiplier * 1.7,
color: Colors.red.shade700,
fontWeight: FontWeight.w700,
),
),
],
),

Loading…
Cancel
Save