Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
patient notes migration (#13)
Browse files Browse the repository at this point in the history
* patient notes migration

Tied to #32 in hospitalrun-frontend

* mislabeled name of the file

* Removed old _id from migrated data because it is not needed

Also, this field was causing confusion.

* Changed to use bulk update and fixed various issues.
  • Loading branch information
tangollama authored and jkleinsc committed Apr 8, 2016
1 parent 73b7aef commit 282eb40
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ start.sh

stop.sh

newrelic.js

newrelic_agent.log

newrelic.js
42 changes: 42 additions & 0 deletions utils/patient-notes-mig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var config = require('../config.js');
var nano = require('nano')(config.couchAuthDbURL);
var maindb = nano.use('main');
var uuid = require('node-uuid');
var recordsToUpdate = [];

maindb.list({startkey: 'visit_', endkey: 'visit_\uffff', include_docs: true}, function(err, results) {
if (!err) {
results.rows.forEach(function(result) {
var visitDoc = result.doc.data;
if (visitDoc !== null && visitDoc.notes && !visitDoc.patientNotes) {
var noteUuid = uuid.v4();
var visitId = result.doc._id.substr(8);
var patientNote = {
_id: 'patientNote_2_' + noteUuid,
data: {
content: visitDoc.notes,
createdBy: 'system',
date: new Date(),
noteType: 'General',
patient: visitDoc.patient,
visit: visitId
}
};
recordsToUpdate.push(patientNote);
result.doc.data.patientNotes = [noteUuid];
recordsToUpdate.push(result.doc);
}
});
if (recordsToUpdate.length > 0) {
maindb.bulk({ docs: recordsToUpdate}, function(err, results) {
if (err) {
console.log('Error updating patient notes records.', err);
} else {
console.log('Success updating patient notes records.', JSON.stringify(results, null, 2));
}
});
}
} else {
console.log('ERROR fetching visit records', err);
}
});
1 change: 1 addition & 0 deletions utils/pouch-mig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function migrateRecords() {
data: result.doc
};
existingKeys[newDocId] = true;
delete newDoc.data._id;
delete newDoc.data._rev;

switch (parsedId.doctype) {
Expand Down

0 comments on commit 282eb40

Please sign in to comment.