示例#1
0
        public V0100.Objects.Calibration Add(V0100.Objects.Calibration calibration)
        {
            // Get the device that authenticated.
            DeviceEntity device = GetDevice();

            // Device must be active.
            if (device.DeviceState != DeviceState.Active)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_STATE_INVALID, HttpStatusCode.NotAcceptable);
            }

            // If the calibration specifies a different device, switch to that one.
            // This allows uploading a calibration for a previously-attached scanner.
            if (!string.IsNullOrEmpty(calibration.DeviceGuid) && calibration.DeviceGuid != device.UniqueIdentifier)
            {
                // Get device. It must exist.
                device = DeviceUtils.GetByUid(calibration.DeviceGuid);
                if (device == null)
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_NOT_FOUND, HttpStatusCode.PreconditionFailed);
                }
            }

            // Get the calibration if it exists.
            CalibrationEntity calibrationEntity = CalibrationUtils.GetByUid(calibration.Guid);

            if (calibrationEntity == null)
            {
                // Not found. Creating a new one. Be sure the image set exists.
                ImageSetEntity imageSet = ImageSetUtils.GetByUid(calibration.ImageSetGuid);
                if (imageSet == null)
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.PreconditionFailed);
                }

                // Create new calibration.
                calibration.CalibrationId = CalibrationUtils.Create(device.DeviceId, calibration.Guid, calibration.Timestamp, calibration.PerformedBy, imageSet.ImageSetId);
            }
            else
            {
                // Calibration already exists. Device IDs must match.
                if (calibrationEntity.DeviceId != device.DeviceId)
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.CALIBRATION_INVALID, HttpStatusCode.Conflict);
                }

                // Get existing ID.
                calibration.CalibrationId = calibrationEntity.CalibrationId;
            }

            // Return it with the ID provided.
            return(calibration);
        }
示例#2
0
        public long Add(string guid, string checksum, Stream stream)
        {
            DeviceEntity device = GetDevice();

            if (device.DeviceState != DeviceState.Active)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_STATE_INVALID, HttpStatusCode.NotAcceptable);
            }

            try
            {
                MemoryStream images = new MemoryStream();
                stream.CopyTo(images);

                // Seek to start so checksum validation can use the stream.
                images.Seek(0, SeekOrigin.Begin);

                if (string.IsNullOrWhiteSpace(guid))
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.GUID_INVALID, HttpStatusCode.PreconditionFailed);
                }

                if (ImageSetUtils.GetByUid(guid) != null)
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_INVALID, HttpStatusCode.Conflict);
                }

                if (!CurrentAPI::EPICCentralServiceAPI.REST.Core.Checksum.Validate(images, checksum))
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.CHECKSUM_INVALID, HttpStatusCode.BadRequest);
                }

                return(ImageSetUtils.Create(guid, images.ToArray()));
            }
            catch (WebFaultException <string> )
            {
                throw;
            }
            catch (Exception e)
            {
                Log.Error(string.Format("Error adding image set: {0}, device: {1}", guid, device.DeviceId), e);

                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.INTERNAL_IO_ERROR, HttpStatusCode.InternalServerError);
            }
        }
示例#3
0
        public long GetId(string guid)
        {
            DeviceEntity device = GetDevice();

            if (device.DeviceState != DeviceState.Active)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_STATE_INVALID, HttpStatusCode.NotAcceptable);
            }

            ImageSetEntity imageSet = ImageSetUtils.GetByUid(guid);

            if (imageSet == null)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.NotFound);
            }

            return(imageSet.ImageSetId);
        }
        public long Add(V0100.Objects.Treatment treatment)
        {
            DeviceEntity device = GetDevice();

            if (device.DeviceState != DeviceState.Active)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_STATE_INVALID, HttpStatusCode.NotAcceptable);
            }

            if (TreatmentUtils.GetByUid(treatment.Guid) != null)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.TREATMENT_INVALID, HttpStatusCode.Conflict);
            }

            PatientEntity patient = PatientUtils.GetByUid(treatment.PatientGuid);

            if (patient == null)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.PATIENT_NOT_FOUND, HttpStatusCode.PreconditionFailed);
            }

            CalibrationEntity calibration = CalibrationUtils.GetByUid(treatment.CalibrationGuid);

            if (calibration == null)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.CALIBRATION_NOT_FOUND, HttpStatusCode.PreconditionFailed);
            }

            ImageSetEntity energizedImageSet = ImageSetUtils.GetByUid(treatment.EnergizedImageSetGuid);

            if (energizedImageSet == null)
            {
                throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.PreconditionFailed);
            }

            ImageSetEntity fingerImageSet = null;

            if (treatment.FingerImageSetGuid != null)
            {
                fingerImageSet = ImageSetUtils.GetByUid(treatment.FingerImageSetGuid);
                if (fingerImageSet == null)
                {
                    throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.PreconditionFailed);
                }
            }

            // TODO: Refactor this into the utilities class.
            // Need to consider if it is worth it. The utilities classes exist to make support for
            // multiple versions easier. Unlike the other data layer objects, this is more complicated
            // and will need to be refactored differently.

            TreatmentEntity treatmentEntity = new TreatmentEntity
            {
                UniqueIdentifier       = treatment.Guid,
                PatientId              = patient.PatientId,
                CalibrationId          = calibration.CalibrationId,
                TreatmentType          = (TreatmentType)Enum.Parse(typeof(TreatmentType), treatment.TreatmentType.ToString()),
                TreatmentTime          = treatment.TreatmentTime,
                PerformedBy            = treatment.PerformedBy,
                EnergizedImageSetId    = energizedImageSet.ImageSetId,
                FingerImageSetId       = fingerImageSet != null ? fingerImageSet.ImageSetId : (long?)null,
                SoftwareVersion        = treatment.SoftwareVersion,
                FirmwareVersion        = treatment.FirmwareVersion,
                AnalysisTime           = treatment.AnalysisTime,
                PatientPrescanQuestion = new PatientPrescanQuestionEntity
                {
                    AlcoholQuestion  = treatment.AlcoholQuestion,
                    WheatQuestion    = treatment.WheatQuestion,
                    CaffeineQuestion = treatment.CaffeineQuestion
                }
            };

            foreach (V0100.Objects.NBAnalysisResult result in treatment.NBAnalysisResults)
            {
                NBAnalysisResultEntity resultEntity = treatmentEntity.NBAnalysisResults.AddNew();
                resultEntity.OrganSystemId         = (short)ConvertAnalysisGroup(result.NBAnalysisGroup);
                resultEntity.ResultScoreFiltered   = result.ResultScoreFiltered;
                resultEntity.ResultScoreUnfiltered = result.ResultScoreUnfiltered;
                resultEntity.ProbabilityFiltered   = result.ProbabilityFiltered;
                resultEntity.ProbabilityUnfiltered = result.ProbabilityUnfiltered;
            }

            foreach (V0100.Objects.AnalysisResult result in treatment.AnalysisResults)
            {
                AnalysisResultEntity resultEntity = treatmentEntity.AnalysisResults.AddNew();
                resultEntity.AnalysisTime       = result.AnalysisTime;
                resultEntity.IsFiltered         = result.IsFiltered;
                resultEntity.FingerDesc         = result.FingerDescription;
                resultEntity.FingerType         = result.FingerType;
                resultEntity.SectorNumber       = result.SectorNumber;
                resultEntity.StartAngle         = result.StartAngle;
                resultEntity.EndAngle           = result.EndAngle;
                resultEntity.SectorArea         = result.SectorArea;
                resultEntity.IntegralArea       = result.IntegralArea;
                resultEntity.NormalizedArea     = result.NormalizedArea;
                resultEntity.AverageIntensity   = result.AverageIntensity;
                resultEntity.Entropy            = result.Entropy;
                resultEntity.FormCoefficient    = result.FormCoefficient;
                resultEntity.FractalCoefficient = result.FractalCoefficient;
                resultEntity.JsInteger          = result.JsInteger;
                resultEntity.CenterX            = result.CenterX;
                resultEntity.CenterY            = result.CenterY;
                resultEntity.RadiusMin          = result.RadiusMin;
                resultEntity.RadiusMax          = result.RadiusMax;
                resultEntity.AngleOfRotation    = result.AngleOfRotation;
                resultEntity.Form2            = result.Form2;
                resultEntity.NoiseLevel       = result.NoiseLevel;
                resultEntity.BreakCoefficient = result.BreakCoefficient;
                resultEntity.SoftwareVersion  = result.SoftwareVersion;
                resultEntity.AI1           = result.AI1;
                resultEntity.AI2           = result.AI2;
                resultEntity.AI3           = result.AI3;
                resultEntity.AI4           = result.AI4;
                resultEntity.Form11        = result.Form11;
                resultEntity.Form12        = result.Form12;
                resultEntity.Form13        = result.Form13;
                resultEntity.Form14        = result.Form14;
                resultEntity.RingThickness = result.RingThickness;
                resultEntity.RingIntensity = result.RingIntensity;
                resultEntity.Form2Prime    = result.Form2Prime;
                resultEntity.UserName      = result.UserName;
            }

            foreach (V0100.Objects.Severity severity in treatment.Severities)
            {
                SeverityEntity severityEntity = treatmentEntity.Severities.AddNew();
                severityEntity.OrganId       = severity.OrganId;
                severityEntity.PhysicalRight = severity.PhysicalRight;
                severityEntity.PhysicalLeft  = severity.PhysicalLeft;
                severityEntity.MentalRight   = severity.MentalRight;
                severityEntity.MentalLeft    = severity.MentalLeft;
            }

            foreach (V0100.Objects.CalculationDebug calculationDebug in treatment.CalculationDebugs)
            {
                CalculationDebugDataEntity calculationDebugDataEntity = treatmentEntity.CalculationDebugDatas.AddNew();
                calculationDebugDataEntity.FingerSector     = calculationDebug.FingerSector;
                calculationDebugDataEntity.IsFiltered       = calculationDebug.IsFiltered;
                calculationDebugDataEntity.OrganComponent   = (OrganComponent)Enum.Parse(typeof(OrganComponent), calculationDebug.OrganComponent, true);
                calculationDebugDataEntity.Area             = calculationDebug.Area;
                calculationDebugDataEntity.AverageIntensity = calculationDebug.AverageIntensity;
                calculationDebugDataEntity.BreakCoefficient = calculationDebug.BreakCoefficient;
                calculationDebugDataEntity.Entropy          = calculationDebug.Entropy;
                calculationDebugDataEntity.NS              = calculationDebug.NS;
                calculationDebugDataEntity.Fractal         = calculationDebug.Fractal;
                calculationDebugDataEntity.Form            = calculationDebug.Form;
                calculationDebugDataEntity.Form2           = calculationDebug.Form2;
                calculationDebugDataEntity.AI1             = calculationDebug.AI1;
                calculationDebugDataEntity.AI2             = calculationDebug.AI2;
                calculationDebugDataEntity.AI3             = calculationDebug.AI3;
                calculationDebugDataEntity.AI4             = calculationDebug.AI4;
                calculationDebugDataEntity.Form11          = calculationDebug.Form11;
                calculationDebugDataEntity.Form12          = calculationDebug.Form12;
                calculationDebugDataEntity.Form13          = calculationDebug.Form13;
                calculationDebugDataEntity.Form14          = calculationDebug.Form14;
                calculationDebugDataEntity.RingIntensity   = calculationDebug.RingIntensity;
                calculationDebugDataEntity.RingThickness   = calculationDebug.RingThickness;
                calculationDebugDataEntity.Form2Prime      = calculationDebug.Form2Prime;
                calculationDebugDataEntity.EPICBaseScore   = calculationDebug.EPICBaseScore;
                calculationDebugDataEntity.EPICBonusScore  = calculationDebug.EPICBonusScore;
                calculationDebugDataEntity.EPICScore       = calculationDebug.EPICScore;
                calculationDebugDataEntity.EPICScaledScore = calculationDebug.EPICScaledScore;
                calculationDebugDataEntity.EPICRank        = calculationDebug.EPICRank;
                calculationDebugDataEntity.LRRank          = calculationDebug.LRRank;
                calculationDebugDataEntity.LRScore         = calculationDebug.LRScore;
                calculationDebugDataEntity.LRScaledScore   = calculationDebug.LRScaledScore;
                calculationDebugDataEntity.SumZScore       = calculationDebug.SumZScore;
            }

            treatmentEntity.Save(true);

            return(treatmentEntity.TreatmentId);
        }