<ProgramFilesX64>\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll
<RuntimeDirectory>\System.Data.Entity.Design.dll
Amazon.Lambda.S3Events
AWSSDK.Core
AWSSDK.S3
LINQtoCSV
Amazon
Amazon.Auth.AccessControlPolicy
Amazon.Auth.AccessControlPolicy.ActionIdentifiers
Amazon.Internal
Amazon.Lambda.S3Events
Amazon.MissingTypes
Amazon.Runtime
Amazon.Runtime.CredentialManagement
Amazon.Runtime.CredentialManagement.Internal
Amazon.Runtime.EventStreams
Amazon.Runtime.EventStreams.Internal
Amazon.Runtime.Internal
Amazon.Runtime.Internal.Auth
Amazon.Runtime.Internal.Settings
Amazon.Runtime.Internal.Transform
Amazon.Runtime.Internal.Util
Amazon.Runtime.SharedInterfaces
Amazon.Runtime.SharedInterfaces.Internal
Amazon.S3
Amazon.S3.Encryption
Amazon.S3.Encryption.Internal
Amazon.S3.Internal
Amazon.S3.IO
Amazon.S3.Model
Amazon.S3.Model.Internal.MarshallTransformations
Amazon.S3.Transfer
Amazon.S3.Util
Amazon.Util
Amazon.Util.Internal
Amazon.Util.Internal.PlatformServices
LINQPad.Extensibility.DataContext.DbSchema
LINQtoCSV
Newtonsoft.Json
Newtonsoft.Json.Converters
Newtonsoft.Json.Linq
Newtonsoft.Json.Schema
Newtonsoft.Json.Serialization
System
System.Diagnostics
System.Diagnostics.Tracing
System.Globalization
System.IO.Compression
ThirdParty.BouncyCastle.Asn1
ThirdParty.BouncyCastle.Asn1.Utilities
ThirdParty.BouncyCastle.Math
ThirdParty.BouncyCastle.OpenSsl
ThirdParty.BouncyCastle.Utilities.IO.Pem
ThirdParty.Ionic.Zlib
ThirdParty.Json.LitJson
ThirdParty.MD5
System.Data.Entity.Design.PluralizationServices
private static PluralizationService ps => PluralizationService.CreateService(new CultureInfo("en-US"));
void Main()
{
var path = @"C:\Users\tlamb\downloads";
var newPath = @"C:\Users\tlamb\downloads\Solehope 190705";
var file = "medical inventory July 5 2019.2.csv";
var filepath = Path.Combine(path, file);
CsvFileDescription inputFileDescription = new CsvFileDescription
{
SeparatorChar = ',',
FirstLineHasColumnNames = true,
IgnoreUnknownColumns = true
};
CsvFileDescription outputFileDescription = new CsvFileDescription
{
SeparatorChar = ',',
FirstLineHasColumnNames = true
};
CsvContext cc = new CsvContext();
IEnumerable medications;
IEnumerable inventory;
IEnumerable intake;
var meds = cc.Read(filepath, inputFileDescription).ToList();
meds.Dump(file);
medications = meds.ConvertAll(med => (MedicationOut)med);
inventory = meds.ConvertAll(med => (Inventory)med);
inventory = inventory.OrderBy(i => i.Medication)
.Select((i, idx) => { i.InventoryId = idx.ToString(); return i; });
intake = meds.ConvertAll(med => (Intake)med);
intake = intake
.Join(inventory, x => x.MedicationId, inv => inv.MedicationId, (x, inv) => new { intake = x, inv }).ToList()
.ConvertAll(u => { u.intake.InventoryId = u.inv.InventoryId; return u.intake; });
var updates = cc.Read(Path.Combine(@"C:\Users\tlamb\downloads\Solehope 190819", "intake2.csv"), inputFileDescription).ToList()
.Join(inventory, x => x.InventoryId, inv => inv.InventoryId, (x, inv) => new { intake = x, inv }).ToList()
.ConvertAll(u => { u.intake.MedicationId = u.inv.MedicationId; return u.intake; });
newPath.Dump("New Path");
medications.Dump("Medications");
inventory.Dump("Inventory");
intake.Dump("Intake - from Medications");
updates.Dump("Updates");
file = "medication.csv";
filepath = Path.Combine(newPath, file);
cc.Write(medications, filepath, outputFileDescription);
file = "inventory.csv";
filepath = Path.Combine(newPath, file);
cc.Write(inventory, filepath, outputFileDescription);
file = "intake.csv";
filepath = Path.Combine(newPath, file);
cc.Write(intake, filepath, outputFileDescription);
file = "updates.csv";
filepath = Path.Combine(newPath, file);
cc.Write(updates, filepath, outputFileDescription);
}
// Define other methods and classes here
public class Med
{
public string Id { get; set; }
public string Type { get; set; }
[CsvColumn(Name = "Medication")]
public string MedicationStr { get; set; }
internal string Medications => box.Match(MedicationStr.Trim()).Success ? box.Replace(MedicationStr.Trim(), "$1").Trim() : MedicationStr.Trim();
public string Strength { get; set; }
[CsvColumn(Name = "Quantity")]
public string Start { get; set; }
internal int StartCnt => Convert.ToInt32(regex.Replace(string.IsNullOrEmpty(Start) ? "0" : Start, ""));
[CsvColumn(Name = "Minimum")]
public string MinimumStr { get; set; }
internal int MinimumCnt => Convert.ToInt32(regex.Replace(string.IsNullOrEmpty(MinimumStr) ? "0" : MinimumStr, ""));
public string Unit { get; set; }
public string Package { get; set; }
[CsvColumn(Name = "Number")]
public string NumberStr { get; set; }
internal int NumberCnt => box.Match(MedicationStr.Trim()).Success ? Convert.ToInt32(box.Replace(MedicationStr.Trim(), "$2"))
: Convert.ToInt32(regex.Replace(string.IsNullOrEmpty(NumberStr) ? "0" : NumberStr, ""));
[CsvColumn(Name = "Expiration Date")]
public string Expiry { get; set; }
internal DateTime ExpiryDate => GetDateFromString(Expiry);
internal string Form => string.IsNullOrEmpty(Package) ? ""
: Package.Trim() == "Tube/Cream" ? "Cream" : ps.Singularize(Package.Trim());
internal string UnitOut => !string.IsNullOrEmpty(UnitNoBox)
? ps.Singularize(UnitNoBox)
: string.IsNullOrEmpty(Package)
? string.Empty
: Package.Trim() == "Tube/Cream"
? "Tube"
: string.Empty;
public string Label => $"{Medications} {Strength} {Form} {NumberCnt} / {UnitOut}";
internal string UnitNoBox => box.Match(MedicationStr.Trim()).Success ? "Box" : Unit?.Trim() ?? "";
internal Regex regex = new Regex(@"[^\d]");
internal Regex date = new Regex(@"([\d]{1,2})/([\d]{1,2})/([\d]{1,4})");
internal Regex shortDate = new Regex(@"([\d]{1,2})/([\d]{1,2})");
internal Regex box = new Regex(@"^(\D*)([\d]*)/Box$");
internal DateTime GetDateFromString(string theDate)
{
DateTime result = DateTime.MaxValue;
DateTime work;
if (string.IsNullOrEmpty(theDate) || theDate == "0/0")
work = result;
else if (date.IsMatch(theDate))
work = Convert.ToDateTime(theDate);
else if (shortDate.IsMatch(theDate))
work = Convert.ToDateTime(shortDate.Replace(theDate, "$1/5/$2"));
else
work = result;
work = new DateTime(work.Year, work.Month, DateTime.DaysInMonth(work.Year, work.Month));
return work;
}
}
public class MedicationOut
{
public string Id { get; set; }
public string Type { get; set; }
public string Medication { get; set; }
public int Minimum { get; set; }
public string Strength { get; set; }
public string Form { get; set; }
public int Number { get; set; }
public string Unit { get; set; }
public string Label { get; internal set; }
public static explicit operator MedicationOut(Med med)
{
return new MedicationOut
{
Id = med.Id,
Type = med.Type,
Medication = med.Medications,
Minimum = med.MinimumCnt,
Strength = med.Strength ?? "",
Form = med.Form,
Number = med.NumberCnt,
Unit = !string.IsNullOrEmpty(med.UnitNoBox)
? ps.Singularize(med.UnitNoBox)
: string.IsNullOrEmpty(med.Package)
? string.Empty
: med.Package.Trim() == "Tube/Cream"
? "Tube"
: string.Empty,
Label = med.Label
};
}
}
public class Inventory
{
public string MedicationId { get; set; }
public string InventoryId { get; set; }
public string Medication { get; set; }
public int Start => 0;
public string Label { get; internal set; }
public string Note { get; set; }
public static explicit operator Inventory(Med med)
{
return new Inventory
{
MedicationId = med.Id,
Medication = med.Medications,
Label = med.Label,
Note = string.Empty
};
}
}
public class Intake
{
public string MedicationId { get; set; }
public string InventoryId { get; set; }
public string Medication { get; set; }
public int Received { get; set; }
public DateTime Date { get; set; }
public DateTime Expiry { get; set; }
internal string MedLabel { get; set; }
public string Label => $"({Received}) {MedLabel}";
public static explicit operator Intake(Med med)
{
return new Intake
{
MedicationId = med.Id,
Medication = med.Medications,
Received = med.StartCnt,
Date = new DateTime(2019, 7, 5),
Expiry = med.ExpiryDate,
MedLabel = med.Label
};
}
}