Skip to content
Permalink
Browse files

6/6/2019 - Version 1.1.2.0 (Fixed Again)

  • Loading branch information
Grant Teakell
Grant Teakell committed Jun 6, 2019
1 parent f622425 commit 1b5733becdc0365dd4708017b8eca6d766a7c2df
Showing with 327 additions and 0 deletions.
  1. +189 −0 CarsonDB/Prescrip.cs
  2. +138 −0 CarsonDBTest/PrescripUnitTest.cs
@@ -0,0 +1,189 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarsonDB
{
public class Prescrip : CarsonBackend
{
public enum PrescripFieldOrdinals
{
Id,
PrescripRecd,
PrescripPatient,
PrescripItem,
PrescripDateIssued,
PrescripDateExpires,
PrescripStatus,
PrescripLabelPrintDate,
PrescripClosedDate,
PrescripLastRefillDate,
PrescripFillLocation
}

public static class PrescripFields
{
public static readonly string Id = "ID";
public static readonly string PrescripRecd = "PRESCRIPTION_RECD";
public static readonly string PrescripPatient = "PRESCRIPTION_PATIENT";
public static readonly string PrescripItem = "PRESCRIPTION_ITEM";
public static readonly string PrescripDateIssued = "PRESCRIPTION_DATE_ISSUED";
public static readonly string PrescripDateExpires = "PRESCRIPTION_DATE_EXPIRES";
public static readonly string PrescripStatus = "PRESCRIPTION_STATUS";
public static readonly string PrescripLabelPrintDate = "PRESCRIPTION_LABEL_PRINT_DATE";
public static readonly string PrescripClosedDate = "PRESCRIPTION_CLOSED_DATE";
public static readonly string PrescripLastRefillDate = "PRESCRIPTION_LAST_REFILL_DATE";
public static readonly string PrescripFillLocation = "PRESCRIPTION_FILL_LOCATION";
}

public class PrescripData : ICrc
{
private int _recordNumber;
private Prescrip _prescrip;

public PrescripData(Prescrip prescrip, int recordNumber)
{
_prescrip = prescrip;
_recordNumber = recordNumber;
}

public int Id
{
get
{
return _prescrip.IntegerFieldValue(PrescripFieldOrdinals.Id, _recordNumber);
}
}

public string PrescripRecd
{
get
{
return _prescrip.CharacterFieldValue(PrescripFieldOrdinals.PrescripRecd, _recordNumber);
}
}

public int PrescripPatient
{
get
{
return _prescrip.IntegerFieldValue(PrescripFieldOrdinals.PrescripPatient, _recordNumber);
}
}

public int PrescripItem
{
get
{
return _prescrip.IntegerFieldValue(PrescripFieldOrdinals.PrescripItem, _recordNumber);
}
}

public DateTime PrescripDateIssued
{
get
{
return _prescrip.DateFieldValue(PrescripFieldOrdinals.PrescripDateIssued, _recordNumber);
}
}

public DateTime PrescripDateExpires
{
get
{
return _prescrip.DateFieldValue(PrescripFieldOrdinals.PrescripDateExpires, _recordNumber);
}
}

public int PrescripStatus
{
get
{
return _prescrip.IntegerFieldValue(PrescripFieldOrdinals.PrescripStatus, _recordNumber);
}
}

public DateTime PrescripLabelPrintDate
{
get
{
return _prescrip.DateFieldValue(PrescripFieldOrdinals.PrescripLabelPrintDate, _recordNumber);
}
}

public DateTime PrescripClosedDate
{
get
{
return _prescrip.DateFieldValue(PrescripFieldOrdinals.PrescripClosedDate, _recordNumber);
}
}

public DateTime PrescripLastRefillDate
{
get
{
return _prescrip.DateFieldValue(PrescripFieldOrdinals.PrescripLastRefillDate, _recordNumber);
}
}

public int PrescripFillLocation
{
get
{
return _prescrip.IntegerFieldValue(PrescripFieldOrdinals.PrescripFillLocation, _recordNumber);
}
}

[System.ComponentModel.DefaultValue(RecordStatus.None)]
public RecordStatus RecordState
{
get;
set;
}
}

public Prescrip(string databasePath)
{
AddDatabaseDefinitions(databasePath);
}

private void AddDatabaseDefinitions(string databasePath)
{
this.DatabaseName = "PRESCRIP";
this.DatabasePath = databasePath;
this.TableId = TableInstance.Prescrip;

this.AddFieldDefinition(PrescripFields.Id, PrescripFieldOrdinals.Id, AVImarkDataType.AVImarkAutoNumber);
this.AddFieldDefinition(PrescripFields.PrescripRecd, PrescripFieldOrdinals.PrescripRecd, AVImarkDataType.AVImarkCharacter);
this.AddFieldDefinition(PrescripFields.PrescripPatient, PrescripFieldOrdinals.PrescripPatient, AVImarkDataType.AVImarkDoubleWord);
this.AddFieldDefinition(PrescripFields.PrescripItem, PrescripFieldOrdinals.PrescripItem, AVImarkDataType.AVImarkDoubleWord);
this.AddFieldDefinition(PrescripFields.PrescripDateIssued, PrescripFieldOrdinals.PrescripDateIssued, AVImarkDataType.AVImarkDate);
this.AddFieldDefinition(PrescripFields.PrescripDateExpires, PrescripFieldOrdinals.PrescripDateExpires, AVImarkDataType.AVImarkDate);
this.AddFieldDefinition(PrescripFields.PrescripStatus, PrescripFieldOrdinals.PrescripStatus, AVImarkDataType.AVImarkDoubleWord);
this.AddFieldDefinition(PrescripFields.PrescripLabelPrintDate, PrescripFieldOrdinals.PrescripLabelPrintDate, AVImarkDataType.AVImarkDate);
this.AddFieldDefinition(PrescripFields.PrescripClosedDate, PrescripFieldOrdinals.PrescripClosedDate, AVImarkDataType.AVImarkDate);
this.AddFieldDefinition(PrescripFields.PrescripLastRefillDate, PrescripFieldOrdinals.PrescripLastRefillDate, AVImarkDataType.AVImarkDate);
this.AddFieldDefinition(PrescripFields.PrescripFillLocation, PrescripFieldOrdinals.PrescripFillLocation, AVImarkDataType.AVImarkDoubleWord);
}

public List<PrescripData> PrescripList()
{
List<PrescripData> prescripList = new List<PrescripData>();
this.Open();

int recordCount = this.RetrieveRecords();
this.MoveFirst();

for (int x = 1; x <= recordCount; x++)
{
PrescripData prescripData = new PrescripData(this, x);
prescripList.Add(prescripData);
}

return prescripList;
}
}
}
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualBasic.FileIO;
using CarsonDB;

namespace CarsonDBTest
{
[TestClass]
public class PrescripUnitTest
{
//there is no legacy for Prescrip - it did not exist back then.
private string _modernSourcePath = Path.Combine(Directory.GetCurrentDirectory(), "MODERN");

[TestInitialize]
public void PrescripTestInit()
{
Shared.BuildPrescripRecords();
}

[TestCleanup]
public void PrescripTestCleanup()
{
Shared.UnloadDll();
}

[TestMethod]
public void PrescripTest1()
{
int lineNumber = 0;

using (Prescrip prescrip = new Prescrip(_modernSourcePath))
{
var prescripList = prescrip.PrescripList();

var lines = File.ReadLines(Path.Combine(Directory.GetCurrentDirectory(), "prescrip.csv"));

foreach (var line in lines)
{
TextFieldParser parser = new TextFieldParser(new StringReader(line));
parser.HasFieldsEnclosedInQuotes = true;
parser.SetDelimiters(",");
string[] fields = parser.ReadFields();

if (!PrescripRecordCompare(prescripList, fields, lineNumber))
{
Assert.Fail("Match failed on line: " + (lineNumber + 1).ToString());
}

lineNumber++;
}
}

Assert.IsFalse(false, "PrescripTest1 Passed!!");
}

[TestMethod]
public void PrescripTest2()
{
for (int y = 0; y < 1000; y++)
{
string[] fields = null;

var lines = File.ReadLines(Path.Combine(Directory.GetCurrentDirectory(), "prescrip.csv"));
int lineCount = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "prescrip.csv")).Length;

if (y > lineCount - 1)
break;

var line = new List<string>(lines)[y];

TextFieldParser parser = new TextFieldParser(new StringReader(line));
parser.HasFieldsEnclosedInQuotes = true;
parser.SetDelimiters(",");
fields = parser.ReadFields();

using (Prescrip prescrip = new Prescrip(_modernSourcePath))
{
if (fields[0].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripRecd, ComparisonType.EqualTo, fields[0]);

if (fields[1].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripPatient, ComparisonType.EqualTo, fields[1]);

if (fields[2].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripItem, ComparisonType.EqualTo, fields[2]);

if (fields[3].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripDateIssued, ComparisonType.EqualTo, DateTime.Parse(fields[3]));

if (fields[4].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripDateExpires, ComparisonType.EqualTo, DateTime.Parse(fields[4]));

if (fields[5].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripStatus, ComparisonType.EqualTo, fields[5]);

if (fields[6].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripLabelPrintDate, ComparisonType.EqualTo, DateTime.Parse(fields[6]));

if (fields[7].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripClosedDate, ComparisonType.EqualTo, DateTime.Parse(fields[7]));

if (fields[8].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripLastRefillDate, ComparisonType.EqualTo, DateTime.Parse(fields[8]));

if (fields[9].Length > 0)
prescrip.AddFilterCriteria(Prescrip.PrescripFields.PrescripFillLocation, ComparisonType.EqualTo, fields[9]);

var prescripList = prescrip.PrescripList();

if (prescripList.Count == 0)
{
Assert.Fail("Match failed on line: " + (y + 1).ToString());
}
}
}

Assert.IsTrue(true, "PrescripTest2 Passed!!");
}

private bool PrescripRecordCompare(List<Prescrip.PrescripData> prescripList, string[] fields, int lineNumber)
{
if (prescripList[lineNumber].PrescripRecd == fields[0] && Shared.CompareAmount(prescripList[lineNumber].PrescripPatient, fields[1]) &&
Shared.CompareAmount(prescripList[lineNumber].PrescripItem, fields[2]) && (prescripList[lineNumber].PrescripDateIssued - DateTime.Parse(fields[3])).TotalDays == 0 &&
(prescripList[lineNumber].PrescripDateExpires - DateTime.Parse(fields[4])).TotalDays == 0 && Shared.CompareAmount(prescripList[lineNumber].PrescripStatus, fields[5]) &&
(prescripList[lineNumber].PrescripLabelPrintDate - DateTime.Parse(fields[6])).TotalDays == 0 && (prescripList[lineNumber].PrescripClosedDate - DateTime.Parse(fields[7])).TotalDays == 0 &&
(prescripList[lineNumber].PrescripLastRefillDate - DateTime.Parse(fields[8])).TotalDays == 0 && Shared.CompareAmount(prescripList[lineNumber].PrescripFillLocation, fields[9]))
{
return true;
}
else
{
return false;
}
}
}
}

0 comments on commit 1b5733b

Please sign in to comment.
You can’t perform that action at this time.