@sussex-occ/occ-data-mapper

0.0.1 • Public • Published

Data Mapper

A command line tool to transform CSV data by applying mappings to it and generating one or more JSON files. Typical functionality includes column/field renaming, re-formatting values such as dates, and constraining numbers to a given range. Transform functions operate on a row by row basis, so it is possible to map multiple CSV columns to a single JSON field, or single CSV field to multiple JSON fields.

Installation

> npm install occ-data-mapper -g

TODO - need to package up and push to npm so that the above install command will work.

Usage

If you are not using one of the built in transform mapping, you will need to create a mapping file manually or generate one from a simple CSV file. If the latter, firstly prepare your CSV file with the following columns as in this example:

SystemName,Dataset,ExtractName,MasterName,DataType
ESHT_SUS,EDCDS,CDS_Unique_ID,ED.Act_ID,nvarchar
ESHT_SUS,EDCDS,Emergency_Care_Acuity,ED.Acu,nvarchar
ESHT_SUS,EDCDS,Age_at_CDS_Activity_Date,ED.Age,nvarchar

The DataType dictates how the column will be transformed. Possible values are:

  • nvarchar
  • int
  • datetime
  • date
  • time
  • postcodepart

Dates will be reformatted from dd/mm/yyyy format to yyyy-mm-dd.

Now use the generatemappingfile command to convert the CSV file to the required JSON mapping file:

> generatemappingfile ESHTexport-20240117-103905_enha-Table.csv

This generates a new mapping file ESHTexport-20240117-103905_enha-Table.json

Now you can perform the conversion:

> datamapper data/test.csv -m ESHTexport-20240117-103905_enha-Table.json --chunkSize 10000

This will generate one or more JSON files with the transformed fields and values. The above command will generate files in the format data/test-1.json, data/test-2.json etc.

Readme

Keywords

none

Package Sidebar

Install

npm i @sussex-occ/occ-data-mapper

Weekly Downloads

1

Version

0.0.1

License

ISC

Unpacked Size

14.1 kB

Total Files

4

Last publish

Collaborators

  • davidc-occ