private static void ccmNames() { using (Pnyx p = new Pnyx()) { p.read("C:/dev/asclepius/prod_import/ccm_names.csv"); p.parseCsv(hasHeader: true); p.rowTransformerFunc(row => { String lastName = row[1]; Tuple <String, String> lastNameSuffix = NameUtil.parseSuffix(lastName); if (lastNameSuffix.Item2 == null) { return(null); } // Expands name into 2 columns row = RowUtil.replaceColumn(row, 2, lastNameSuffix.Item1, lastNameSuffix.Item2); return(row); }); p.rowTransformerFunc(row => { for (int i = 0; i < row.Count; i++) { row[i] = TextUtil.encodeSqlValue(row[i]); } return(row); }); p.print("update bhc_patient_ccm set lastname=$2, suffix=$3 where patientid=$1;"); p.write("C:/dev/asclepius/prod_import/ccm_names_update.sql"); p.process(); } }
private static void transform() { using (Pnyx p = new Pnyx()) { p.read("C:/dev/asclepius/prod_import/BHC Patients from 1-1-15 thru 10-31-2018.csv"); p.parseCsv(hasHeader: true); p.withColumns(p2 => p2.lineTransformer(new DateTransform { formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE }), 4, 5, 6); p.rowTransformerFunc(row => { String fullName = row[2]; Name name = NameUtil.parseFullName(fullName); if (name == null) { return(null); } // Expands name into 4 columns row = RowUtil.replaceColumn(row, 3, name.firstName, name.middleName, name.lastName, name.suffix); return(row); }); p.tee(p2 => { p2.removeColumns(7 + 3, 8 + 3, 9 + 3); // plus 3 from name split above p2.rowFilter(new RepeatFilter()); p2.write("C:/dev/asclepius/prod_import/bhc_discharges.csv"); }); p.widthColumns(9 + 3); // plus 3 from name split above p.write("C:/dev/asclepius/prod_import/bhc_discharges_diagnosis.csv"); p.process(); } }
public static int fix() { using (Pnyx p = new Pnyx()) { p.setSettings(outputNewline: "\n"); p.read("C:/dev/asclepius/prod_import/mirPatients.csv"); p.parseCsv(hasHeader: false); p.widthColumns(10, null); p.rowTransformerFunc(x => new System.Collections.Generic.List <string> { x[1], x[4], x[5], x[9] ?? x[8] ?? x[7] ?? x[6] ?? x[5] ?? x[4] }); p.rowTransformerFunc(row => { var fullName = row[0]; var name = pnyx.net.util.NameUtil.parseFullName(fullName); if (name == null) { return(null); } return(pnyx.net.util.RowUtil.replaceColumn(row, 1, name.firstName, name.lastName)); }); p.rowTransformerFunc(x => { x[2] = PhoneUtil.parsePhone(x[2]); x[3] = PhoneUtil.parsePhone(x[3]); return(x.ToList()); }); p.tee(px => px.writeStdout()); p.write("C:/dev/asclepius/prod_import/mirPatients.out.csv"); p.process(); } return(0); }
// pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleRow transformerFunc public static void transformerFunc() { const String input = @"Line one,KEEPER Line two,LOSER "; using (Pnyx p = new Pnyx()) { p.readString(input); p.parseCsv(); p.rowTransformerFunc(x => new List <string> { NameUtil.toTitleCase(x[1]) }); p.writeStdout(); } // outputs: // Keeper // Loser }
public static int main() { using (Pnyx p = new Pnyx()) { p.read("nya.csv"); p.parseCsv(); p.rowTransformerFunc(row => { var fullName = row[1]; var name = pnyx.net.util.NameUtil.parseFullName(fullName); if (name == null) { return(null); } return(pnyx.net.util.RowUtil.replaceColumn(row, 2, name.firstName, name.lastName)); }); p.selectColumns(2, 3, 5); p.columnTransformer(3, new pnyx.net.impl.DateTransform { formatSource = "M-d-yyyy", formatDestination = "yyyy-M-d" }); p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x)); p.print("insert into tmp_name values($1,$2,$3);"); p.write("nya.sql"); } using (Pnyx p = new Pnyx()) { p.read(@"C:\dev\asclepius\prod_import\alt.txt"); p.parseTab(); p.rowTransformerFunc(row => { var fullName = row[0]; var name = pnyx.net.util.NameUtil.parseFullName(fullName); if (name == null) { return(null); } return(pnyx.net.util.RowUtil.replaceColumn(row, 1, name.firstName, name.middleName, name.lastName)); }); p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x)); p.sortRow(new[] { 1, 3 }); p.writeCsv(@"C:\dev\asclepius\prod_import\alt.csv"); } using (Pnyx p = new Pnyx()) { p.read(@"C:\dev\asclepius\prod_import\alt_names.csv"); p.parseCsv(); p.columnTransformer(3, new DateTransform { formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE }); p.rowTransformerFunc(row => { for (int i = 0; i < row.Count; i++) { row[i] = TextUtil.encodeSqlValue(row[i]); } return(row); }); p.print("insert into to_import value($1,$2,$3);"); p.write(@"C:\dev\asclepius\prod_import\names.sql"); } return(0); }
public static int main() { using (Pnyx p = new Pnyx()) { p.setSettings(outputNewline: StreamInformation.newlineString(NewLineEnum.Unix)); p.read(@"c:/dev/asclepius/prod_import/American Academy of Private Physicians.csv"); p.parseCsv(hasHeader: true); p.hasColumns(true, 2); p.withColumns(p2 => { p2.lineTransformerFunc(line => line == "" ? "-66" : line); }, 1, 2, 3, 4, 5); p.rowTransformerFunc(row => { row[3] = TextUtil.extractAlpha(row[3]); // removes periods from title return(row); }); p.rowTransformerFunc(row => { row[7] = ZipCodeUtil.parseZipCode(row[7], true); return(row); }); p.rowTransformerFunc(row => { row[8] = PhoneUtil.parsePhone(row[8]); return(row); }); p.rowTransformerFunc(row => { row[9] = EmailUtil.validateAndRepair(row[9]); return(row); }); p.rowTransformerFunc(row => { String firstName = row[1]; String lastName = row[2]; firstName = firstName.Replace(",", " "); lastName = lastName.Replace(",", " "); String wholeName = firstName + " " + lastName; Name name = NameUtil.parseFullName(wholeName); row[1] = name.firstName; row[2] = name.lastName; row = RowUtil.insertColumns(row, 4, name.suffix); row = RowUtil.insertColumns(row, 3, name.middleName); return(row); }); p.widthColumns(13); p.headerNames("Credentials", "FirstName", "MiddleName", "LastName", "Suffix", "Title", "StreetAddress", "City", "State", "ZipCode", "Phone", "Email", "CompanyName"); p.write(@"c:/dev/asclepius/prod_import/aapp.csv"); } using (Pnyx p = new Pnyx()) { p.read(@"c:/dev/asclepius/prod_import/aapp.csv"); p.parseCsv(); p.columnDefinition(hasHeaderRow: true, maxWidth: true, nullable: true); p.swapColumnsAndRows(); p.writeStdout(); } return(0); }