Skip to content

Beavj/Patient_geo

Repository files navigation

Patient Geolocation Service

A Node.js service that processes patient CSV data to geocode patient addresses using the MapMyIndia (Mappls) API. It calculates the distance between each patient and their assigned healthcare facility.

Features

  • Bulk geocoding of patient addresses via MapMyIndia API
  • Chunked CSV processing with concurrent workers
  • Auto-resume: skips already-processed rows on restart
  • Start-from-ID support to resume mid-chunk
  • Distance calculation (patient ↔ facility) in metres

Project Structure

patient_geo/
├── src/
│   ├── index.js              # Express API server entry point
│   ├── api/
│   │   └── geolocation.js    # MapMyIndia API calls (eLoc + coords)
│   ├── services/
│   │   ├── csvService.js     # Core CSV stream processor
│   │   └── splitService.js   # CSV chunker/splitter
│   └── utils/
│       └── distance.js       # Haversine distance calculator
├── run_multiple_chunks.js    # Batch runner for multiple chunk files
├── run_specific_chunk.js     # Runner for a single chunk
├── sample.csv                # Example input CSV
└── .env.example              # Environment variable template

Setup

1. Install dependencies

npm install

2. Configure environment variables

cp .env.example .env

Edit .env and add your MapMyIndia API credentials.

3. Run the API server

npm start
# or for development with auto-reload:
npm run dev

4. Process chunks in batch

Edit run_multiple_chunks.js to set your chunk directory and range, then:

node run_multiple_chunks.js

Input CSV Format

The input CSV should contain at minimum:

  • alternate_id or patient_id — unique row identifier
  • address or patient_address — full patient address
  • Facility geolocation: geolocation column (e.g. "lat, lon") OR latitude/longitude columns

Output

Processed CSVs are written to the processed/ directory with added columns:

  • patient_eLoc — MapMyIndia place code
  • patient_latitude
  • patient_longitude
  • distance_to_facility_m — distance in metres

Environment Variables

Variable Description
MAP_MY_INDIA_KEY MapMyIndia REST API key
MAPMYINDIA_CLIENT_ID OAuth2 client ID
MAPMYINDIA_CLIENT_SECRET OAuth2 client secret

Get credentials at: https://apis.mappls.com/console/

About

Mapping patient to facilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors