private bool ValidateConsumableTimeLimit(BarcodeModel consumableModel, ReadPatients_Result currentPatient) { if (currentPatient == null) { return(true); } var newBarcodeGtin = Convert.ToInt64(consumableModel.GTIN); var consumableType = consumableHelper.GetConsumableType(consumableModel); var currentPatientDbId = currentPatient.DbId; if (consumableType == null || consumableType.TimeLimit == -1) { return(true); } else if (consumableModel.UsedDate != null) { var hours = (DateTime.Now - consumableModel.UsedDate).Value.TotalHours; if (hours > consumableType.TimeLimit) { return(false); } } else { var testResult = BarcodeRepository.GetBarcodeTests(newBarcodeGtin, consumableModel.TagId); if (testResult == null) { return(true); } var barcodeProceduresAssignedToCurrentPatient = testResult.Where(t => t.Study.patient_id == currentPatientDbId); if (!barcodeProceduresAssignedToCurrentPatient.Any()) { return(true); } var procedureTime = barcodeProceduresAssignedToCurrentPatient.First().test_time; var hours = (DateTime.Now - procedureTime).TotalHours; if (hours > consumableType.TimeLimit) { return(false); } } return(true); }
private bool ValidateConsumablePatientUsage(BarcodeModel consumableModel, ReadPatients_Result currentPatient) { if (currentPatient == null) { return(true); } var newBarcodeGtin = Convert.ToInt64(consumableModel.GTIN); var currentPatientDbId = currentPatient.DbId; var currentPatientGuid = currentPatient.Uuid.ToString(); if (consumableModel.PatientGuid?.Length > 0 && !consumableModel.PatientGuid.Equals(currentPatientGuid, StringComparison.InvariantCultureIgnoreCase)) { return(false); } else if (consumableModel.PatientIdCrc != null) { var curPatientIdBytes = Encoding.UTF8.GetBytes(currentPatientGuid); var curPatientIdCrc16 = General.CalculateCRC16(curPatientIdBytes, (ushort)curPatientIdBytes.Length); if (curPatientIdCrc16 != BitConverter.ToUInt16(consumableModel.PatientIdCrc, 0)) { return(false); } } else { var testResult = BarcodeRepository.GetBarcodeTests(newBarcodeGtin, consumableModel.TagId); if (testResult == null) { return(true); } var barcodeProceduresAssignedToOtherPatients = testResult.Where(t => t.Study.patient_id != currentPatientDbId); if (barcodeProceduresAssignedToOtherPatients.Any()) { return(false); } } return(true); }
public bool Validate(BarcodeModel consumableModel, ReadPatients_Result currentPatient, IEnumerable <BarcodeModel> barcodeList, IEnumerable <InvestigationConsumable> requiredConsumables) { if (!ValidateLotAndSerialNumber(consumableModel)) { throw new InvalidConsumableException(Language.Error_OverflowException); } if (!ValidateGtin(consumableModel)) { throw new InvalidConsumableException(Language.Error_ConsumableWithUnknownCategory); } if (!ValidateExpiry(consumableModel)) { throw new InvalidConsumableException(Language.Error_ConsumableExpired); } if (!ValidateBarcodeUsage(consumableModel, currentPatient)) { if (!ValidateConsumablePatientUsage(consumableModel, currentPatient)) { throw new InvalidConsumableException(Language.Error_ConsumableIsUsedByOtherPatientException); } if (!ValidateConsumableTimeLimit(consumableModel, currentPatient)) { throw new InvalidConsumableException(Language.Error_ConsumableTimeLimitExpiredException); } } if (!ValidateRequiredConsumables(consumableModel, requiredConsumables)) { throw new InvalidConsumableException(Language.Error_ConsumableWithUnwantedCategory); } if (!ValidateConsumableIfDuplicate(consumableModel, barcodeList)) { throw new InvalidConsumableException(Language.Error_ConsumableWithDuplicateBarcodeExistsException); } return(true); }
private bool ValidateBarcodeUsage(BarcodeModel consumableModel, ReadPatients_Result currentPatient) { var existingConsumable = BarcodeRepository.GetBarcode(Convert.ToInt64(consumableModel.GTIN), consumableModel.TagId); return(consumableModel.PatientIdCrc == null && consumableModel.UsedDate == null && existingConsumable == null); }