Exemplo n.º 1
0
        /// <summary>
        /// Converts an ADAPT NumericRepresentation value with an included Representation mapped to a DDI to the appropriate int value for ISO
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mapper"></param>
        /// <returns></returns>
        public static int AsIntViaMappedDDI(this NumericRepresentationValue value, RepresentationMapper mapper)
        {
            int?ddi = mapper.Map(value.Representation);

            if (ddi.HasValue)
            {
                ISOUnit unit = UnitFactory.Instance.GetUnitByDDI(ddi.Value);
                return((int)unit.ConvertToIsoUnit(value.Value.Value));
            }
            else if (value.Representation != null && value.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI)
            {
                //No need to convert if the value is natively a DDI
                return((int)value.Value.Value);
            }
            return(0);
        }
Exemplo n.º 2
0
        private ISOProcessDataVariable ExportProcessDataVariable(RxRate rxRate, Prescription rx)
        {
            ISOProcessDataVariable processDataVariable = new ISOProcessDataVariable();
            RxProductLookup        lookup = rx.RxProductLookups.FirstOrDefault(l => l.Id.ReferenceId == rxRate.RxProductLookupId);

            if (lookup != null)
            {
                processDataVariable.ProductIdRef   = TaskDataMapper.InstanceIDMap.GetISOID(lookup.ProductId.Value);
                processDataVariable.ProcessDataDDI = DetermineVariableDDI(lookup.Representation, lookup.UnitOfMeasure).AsHexDDI();
                ISOUnit unit = UnitFactory.Instance.GetUnitByDDI(processDataVariable.ProcessDataDDI.AsInt32DDI());
                if (unit != null)
                {
                    processDataVariable.ProcessDataValue = (int)unit.ConvertToIsoUnit(rxRate.Rate);
                }
                else
                {
                    throw new ApplicationException("Missing unit on rate calculation from PDV.");
                }
            }
            return(processDataVariable);
        }
Exemplo n.º 3
0
        private string WriteType2GridFile(RasterGridPrescription prescription, ISOTreatmentZone treatmentZone)
        {
            var gridFileName = GenerateId(5);
            Dictionary <string, ISOUnit> unitsByDDI = new Dictionary <string, ISOUnit>();

            using (var binaryWriter = CreateWriter(Path.ChangeExtension(gridFileName, ".bin")))
            {
                byte[] previousBytes = BitConverter.GetBytes(0);
                foreach (var rxCellLookup in prescription.Rates)
                {
                    if (rxCellLookup.RxRates == null || !rxCellLookup.RxRates.Any())
                    {
                        //If there is null or no rate, write the previous rate (or 0 if we have not yet entered a valid rate)
                        binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                    }
                    else
                    {
                        for (int index = 0; index < rxCellLookup.RxRates.Count; index++)
                        {
                            ISOProcessDataVariable pdv = treatmentZone.ProcessDataVariables[index];
                            var rate = rxCellLookup.RxRates[index].Rate;

                            ISOUnit unit = null;
                            if (!unitsByDDI.ContainsKey(pdv.ProcessDataDDI))
                            {
                                unit = UnitFactory.Instance.GetUnitByDDI(pdv.ProcessDataDDI.AsInt32DDI());
                                unitsByDDI.Add(pdv.ProcessDataDDI, unit);
                            }
                            unit = unitsByDDI[pdv.ProcessDataDDI];

                            previousBytes = BitConverter.GetBytes((int)Math.Round(unit.ConvertToIsoUnit(rate), 0));
                            binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                        }
                    }
                }
            }

            return(gridFileName);
        }