|
|
|
|
@ -5,6 +5,7 @@ import 'dart:io';
|
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/date_uitl.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/generic_response_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/get_approves_list_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/get_contact_dff_structure_list.dart';
|
|
|
|
|
@ -29,6 +30,25 @@ import 'package:mohem_flutter_app/models/profile/patient_info_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/start_phone_approval_process_model.dart';
|
|
|
|
|
|
|
|
|
|
// The ERP WCF service's DataContractJsonSerializer rejects any DateTime-typed field unless
|
|
|
|
|
// it's wrapped as "/Date(ms)/" - confirmed by its own error on this exact call:
|
|
|
|
|
// "DateTime content '6/23/1989 12:00:00 AM' does not start with '/Date(' and end with ')/'
|
|
|
|
|
// as required for JSON." GET_EMPLOYEE_CONTACTS hands DATE_OF_BIRTH back as a plain
|
|
|
|
|
// "M/d/yyyy h:mm:ss a" string, so it has to be converted before going back out as P_BIRTH_DATE.
|
|
|
|
|
String? _toWcfJsonDate(rawDate) {
|
|
|
|
|
if (rawDate == null) return null;
|
|
|
|
|
String raw = rawDate.toString().trim();
|
|
|
|
|
if (raw.isEmpty) return null;
|
|
|
|
|
if (raw.contains('/Date(')) return raw;
|
|
|
|
|
try {
|
|
|
|
|
DateTime parsed = DateUtil.convertSimpleStringDateToDate(raw);
|
|
|
|
|
int utcMillis = DateTime.utc(parsed.year, parsed.month, parsed.day).millisecondsSinceEpoch;
|
|
|
|
|
return "/Date($utcMillis)/";
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ProfileApiClient {
|
|
|
|
|
static final ProfileApiClient _instance = ProfileApiClient._internal();
|
|
|
|
|
|
|
|
|
|
@ -505,9 +525,22 @@ class ProfileApiClient {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericResponseModel?> processContactMazayaAccess({required String accessAction, int? contactRelationshipId, int? contactPersonId, int? personId}) async {
|
|
|
|
|
Future<GenericResponseModel?> processContactMazayaAccess({
|
|
|
|
|
required String accessAction,
|
|
|
|
|
int? contactRelationshipId,
|
|
|
|
|
int? contactPersonId,
|
|
|
|
|
int? personId,
|
|
|
|
|
// Same shape as the NHIC-style patient-info call: PatientIdentificationID is the
|
|
|
|
|
// dependent's national ID (GetEmployeeContactsList.nATIONALIDENTIFIER), PatientOutSA is
|
|
|
|
|
// always 0, and the other two are passed straight through from that same contact's
|
|
|
|
|
// P_BIRTH_DATE / P_NHIC_VERIFIED_FLAG response fields.
|
|
|
|
|
String? patientIdentificationId,
|
|
|
|
|
patientBirthDate,
|
|
|
|
|
String? nhicVerifiedFlag,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = "${ApiConsts.erpRest}PROCESS_CONTACT_MAZAYA_ACCESS";
|
|
|
|
|
String action = accessAction.trim().toLowerCase() == "revoke" ? "Revoke" : "Grant";
|
|
|
|
|
bool isGrant = action == "Grant";
|
|
|
|
|
Map<String, dynamic> postParams = {"P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": -999, "P_ACCESS_ACTION": action};
|
|
|
|
|
if (contactRelationshipId != null) {
|
|
|
|
|
postParams["P_CONTACT_RELATIONSHIP_ID"] = contactRelationshipId;
|
|
|
|
|
@ -518,6 +551,19 @@ class ProfileApiClient {
|
|
|
|
|
if (personId != null) {
|
|
|
|
|
postParams["P_PERSON_ID"] = personId;
|
|
|
|
|
}
|
|
|
|
|
// Only the Grant call carries these - Revoke's payload stays exactly as it was before
|
|
|
|
|
// this feature. P_BIRTH_DATE/P_NHIC_VERIFIED_FLAG are always sent (even as null, if the
|
|
|
|
|
// source contact from GET_EMPLOYEE_CONTACTS didn't have a value) once we're granting.
|
|
|
|
|
if (isGrant) {
|
|
|
|
|
postParams["PatientOutSA"] = 0;
|
|
|
|
|
postParams["P_BIRTH_DATE"] = _toWcfJsonDate(patientBirthDate);
|
|
|
|
|
postParams["P_NHIC_VERIFIED_FLAG"] = nhicVerifiedFlag?.trim();
|
|
|
|
|
if (patientIdentificationId != null && patientIdentificationId.trim().isNotEmpty) {
|
|
|
|
|
// National ID comes formatted with dashes (e.g. "2-5616-1545-7") - the backend wants
|
|
|
|
|
// the plain digit string (e.g. "2561615457").
|
|
|
|
|
postParams["PatientIdentificationID"] = patientIdentificationId.replaceAll('-', '').trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
(json) {
|
|
|
|
|
|