public override void Map(string inputLine, MapperContext context) { //Step to Identify the Practice or Prescription data set //Using the SDK, tried to use the MapperContext.InputFileName property: it is always empty //So decided to use items count of each datasets //Items count 8 for practice and Items count 9 for prescription char[] delimiterChars = { ',' }; //split up the passed in line string[] individualItems = inputLine.Trim().Split(delimiterChars); if (individualItems.Count() == 9) { Prescription prescription = reader.ExtractPrescriptionsFromCsvLineFormat(inputLine); if (String.IsNullOrWhiteSpace(prescription.PracticeId)) { return; } //Ignore, practise name cannot be null //Filter by peppermint oil if (prescription.BNFName.ToLower() != "peppermint oil") { return; } //Ignore, if filtor not matched context.EmitKeyValue(prescription.BNFName, prescription.ActualCost.ToString("0.00")); } }
public override void Map(string inputLine, MapperContext context) { char[] delimiterChars = { ',' }; //split up the passed in line string[] individualItems = inputLine.Trim().Split(delimiterChars); //Step to Identify the Practice or Prescription data set //Using the SDK, tried to use the MapperContext.InputFileName property: it is always empty //So decided to use items count of each datasets //Items count 8 for practice and Items count 9 for prescription if (individualItems.Count() == 8) { Practices practice = practiceLinereader.ExtractPracticesFromCsvLineFormat(inputLine); if (String.IsNullOrWhiteSpace(practice.ReferenceId)) { return; } //Ignore, practise name cannot be null if (String.IsNullOrWhiteSpace(practice.Name)) { return; } //Ignore, practise name cannot be null if (String.IsNullOrWhiteSpace(practice.PostCode)) { return; } //Ignore, practise name cannot be null context.EmitKeyValue(practice.ReferenceId, Convert.ToString(practice.PostCode)); } //Items count 9 for prescription if (individualItems.Count() == 9) { Prescription prescription = prescriptionLinereader.ExtractPrescriptionsFromCsvLineFormat(inputLine); if (String.IsNullOrWhiteSpace(prescription.PracticeId)) { return; } //Ignore, practise name cannot be null // parctice Id with Amount context.EmitKeyValue(prescription.PracticeId, prescription.ActualCost.ToString("0.00")); } }
public void ReadPrescriptionFromCsvReturnCorrectData() { string filepath = "PrescriptionTest.csv"; //Q30,5D7,A86021,0102000T0,Peppermint Oil ,0000012,00000088.55,00000081.98,201109 var prescription = new Prescription(); using (var sr = new StreamReader(filepath)) { string line = null; //Read and display lines from the file until the end of the file is reached. while ((line = sr.ReadLine()) != null) { prescription = lineReader.ExtractPrescriptionsFromCsvLineFormat(line); } } Assert.That(prescription.PracticeId, Is.EqualTo("A86021")); Assert.That(prescription.BNFName, Is.EqualTo("Peppermint Oil")); Assert.That(prescription.Items, Is.EqualTo(12)); Assert.That(prescription.ActualCost / 100, Is.EqualTo(81.98)); }