Compare commits

...

2 Commits

Author SHA1 Message Date
Benoy Bose
d82cac35f2 Merge branch 'dev' of cosqnet.com:cosqnet/medora-provider into dev 2024-11-27 16:32:38 +05:30
471ce430b0 feature/medora-55 (#11)
Removed address type

Co-authored-by: Jipson George <152465898+Jipson-cosq@users.noreply.github.com>
Co-authored-by: Benoy Bose <benoybose@gmail.com>
Reviewed-on: cosqnet/telemednet#11
Reviewed-by: Benoy Bose <benoybose@cosq.net>
Co-authored-by: DhanshCOSQ <dhanshas@cosq.net>
Co-committed-by: DhanshCOSQ <dhanshas@cosq.net>
2024-11-27 10:54:09 +00:00
4 changed files with 36 additions and 92 deletions

View File

@ -57,14 +57,6 @@ class PatientController {
model.address.city = city; model.address.city = city;
} }
void updateAddressType(String addressType) {
model.address.addressType = addressType;
}
void updateOtherLabel(String otherLabel) {
model.address.otherLabel = otherLabel;
}
void addFamilyMember(FamilyMember member) { void addFamilyMember(FamilyMember member) {
model.familyMembers.add(member); model.familyMembers.add(member);
} }

View File

@ -92,20 +92,15 @@ class PatientAddress {
String? country; String? country;
String? state; String? state;
String? city; String? city;
String? addressType;
String? otherLabel;
PatientAddress({ PatientAddress(
this.houseNo, {this.houseNo,
this.line, this.line,
this.town, this.town,
this.pincode, this.pincode,
this.country, this.country,
this.state, this.state,
this.city, this.city});
this.addressType,
this.otherLabel,
});
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
@ -116,8 +111,6 @@ class PatientAddress {
'country': country, 'country': country,
'state': state, 'state': state,
'city': city, 'city': city,
'addressType': addressType,
'otherLabel': otherLabel,
}; };
} }
@ -129,7 +122,5 @@ class PatientAddress {
country = json['country']; country = json['country'];
state = json['state']; state = json['state'];
city = json['city']; city = json['city'];
addressType = json['addressType'];
otherLabel = json['otherLabel'];
} }
} }

View File

@ -17,7 +17,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
late TextEditingController _lineController; late TextEditingController _lineController;
late TextEditingController _townController; late TextEditingController _townController;
late TextEditingController _pincodeController; late TextEditingController _pincodeController;
late TextEditingController _otherLabelController;
final String country = 'India'; final String country = 'India';
String? state; String? state;
String? city; String? city;
@ -38,11 +37,9 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
_lineController = TextEditingController(text: address.line ?? ''); _lineController = TextEditingController(text: address.line ?? '');
_townController = TextEditingController(text: address.town ?? ''); _townController = TextEditingController(text: address.town ?? '');
_pincodeController = TextEditingController(text: address.pincode ?? ''); _pincodeController = TextEditingController(text: address.pincode ?? '');
_otherLabelController =
TextEditingController(text: address.otherLabel ?? '');
state = address.state; state = address.state;
city = address.city; city = address.city;
addressType = address.addressType;
} }
@override @override
@ -140,21 +137,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildSectionContainer(
'Address Type',
Column(
children: [
_buildAddressTypeChips(),
if (addressType == 'Other')
_buildTextField(
'Other Label',
_otherLabelController,
(value) => widget.controller!.updateOtherLabel(value),
icon: Icons.label_outline,
),
],
),
),
], ],
), ),
), ),
@ -180,7 +162,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
if (pincode.isEmpty) { if (pincode.isEmpty) {
_errors['pincode'] = 'Pincode is required'; _errors['pincode'] = 'Pincode is required';
_hasErrors = true; _hasErrors = true;
} else if (!RegExp(r'^\d{6}$').hasMatch(pincode)) { } else if (!RegExp(r'^[1-9][0-9]{5}$').hasMatch(pincode)) {
_errors['pincode'] = 'Enter a valid 6-digit pincode'; _errors['pincode'] = 'Enter a valid 6-digit pincode';
_hasErrors = true; _hasErrors = true;
} }
@ -194,16 +176,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
_errors['city'] = 'City is required'; _errors['city'] = 'City is required';
_hasErrors = true; _hasErrors = true;
} }
if (addressType == null || addressType!.isEmpty) {
_errors['addressType'] = 'Please select an address type';
_hasErrors = true;
}
if (addressType == 'Other' && _otherLabelController.text.trim().isEmpty) {
_errors['otherLabel'] = 'Please specify other label';
_hasErrors = true;
}
}); });
return !_hasErrors; return !_hasErrors;
@ -301,24 +273,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
); );
} }
Widget _buildAddressTypeChips() {
return Wrap(
spacing: 8.0,
children: ['Home', 'Office', 'Other'].map((String type) {
return ChoiceChip(
label: Text(type),
selected: addressType == type,
onSelected: (bool selected) {
setState(() {
addressType = selected ? type : addressType;
});
widget.controller!.updateAddressType(addressType!);
},
);
}).toList(),
);
}
void _saveAndExit() { void _saveAndExit() {
if (_validateFields()) { if (_validateFields()) {
widget.controller!.updateHouseNo(_houseNoController.text); widget.controller!.updateHouseNo(_houseNoController.text);
@ -328,8 +282,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
widget.controller!.updateCountry(country); widget.controller!.updateCountry(country);
widget.controller!.updateState(state ?? ''); widget.controller!.updateState(state ?? '');
widget.controller!.updateCity(city ?? ''); widget.controller!.updateCity(city ?? '');
widget.controller!.updateAddressType(addressType ?? '');
widget.controller!.updateOtherLabel(_otherLabelController.text);
widget.controller!.updatePatientData(); widget.controller!.updatePatientData();
Navigator.pop(context, true); Navigator.pop(context, true);
} else { } else {
@ -375,7 +328,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
_lineController.dispose(); _lineController.dispose();
_townController.dispose(); _townController.dispose();
_pincodeController.dispose(); _pincodeController.dispose();
_otherLabelController.dispose();
super.dispose(); super.dispose();
} }
} }

View File

@ -137,6 +137,8 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
} }
void _showResultDialog(bool isSuccess) { void _showResultDialog(bool isSuccess) {
if (!mounted) return;
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@ -178,14 +180,7 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: IconButton( child: IconButton(
onPressed: () { onPressed: _handleProfileSave,
if (_validateAllFields()) {
_controller.savePatientData();
_showResultDialog(true);
} else {
_showValidationErrors();
}
},
icon: const Icon(Icons.check, color: Colors.blue, weight: 50), icon: const Icon(Icons.check, color: Colors.blue, weight: 50),
), ),
), ),
@ -556,12 +551,6 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
_errors['address'] = 'Please complete all required address fields'; _errors['address'] = 'Please complete all required address fields';
_hasErrors = true; _hasErrors = true;
} }
if (address.addressType == 'Other' &&
(address.otherLabel?.isEmpty ?? true)) {
_errors['address'] = 'Please specify other address label';
_hasErrors = true;
}
}); });
return !_hasErrors; return !_hasErrors;
@ -603,6 +592,27 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
); );
} }
Future<void> _handleProfileSave() async {
if (_validateAllFields()) {
try {
final bool isSuccess = await _controller.savePatientData();
if (mounted) {
Navigator.pop(context);
}
_showResultDialog(isSuccess);
} catch (e) {
if (mounted) {
Navigator.pop(context);
}
_showResultDialog(false);
}
} else {
_showValidationErrors();
}
}
Widget _buildNavigationField( Widget _buildNavigationField(
String label, IconData icon, VoidCallback onTap) { String label, IconData icon, VoidCallback onTap) {
bool isAddressField = label == 'Address'; bool isAddressField = label == 'Address';
@ -672,8 +682,7 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
return Text( return Text(
'${address.houseNo}, ${address.line}\n' '${address.houseNo}, ${address.line}\n'
'${address.city}, ${address.state} ${address.pincode}\n' '${address.city}, ${address.state} ${address.pincode}\n',
'${address.addressType}${address.addressType == "Other" ? ": ${address.otherLabel}" : ""}',
style: const TextStyle(color: Colors.black87), style: const TextStyle(color: Colors.black87),
); );
} }