Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- knex = require 'knex'
- knex = knex
- client: 'pg'
- connection:
- host: '127.0.0.1'
- user: 'testuser'
- password: 'test'
- database: 'tag_task'
- _ = require 'lodash'
- bookshelf = require('bookshelf') knex
- Patient = bookshelf.Model.extend tableName: 'patients'
- delete_closing_tag = (text) ->
- return_text = ""
- add = true
- for index in [0..text.length-1]
- add = false if index-1 < text.length && text[index] == '<' && text[index+1] == '/'
- return_text += text[index] if add
- add = true if !add && text[index] == '>'
- return_text
- delete_closing_tag_lodash = (text) ->
- text = text.split ''
- i = _.indexOf(text, "/")-1
- j = _.indexOf(text, ">", i)+1
- while i > 0
- _.fill text, '', i, j
- i = _.indexOf(text, "/")-1
- j = _.indexOf(text, ">", i)+1
- text.join ''
- Patient.forge().fetchAll()
- .then (patients) ->
- console.log typeof patients.models
- for elem in patients.models
- conversation = elem.get("conversation")
- for topic_key, topic_value of conversation.topics
- if topic_value.deleted != true && topic_value.name?
- topic_value.name = delete_closing_tag topic_value.name
- for question_key, question_value of conversation.questions
- if question_value.deleted != true && question_value.phrase?
- question_value.phrase = delete_closing_tag question_value.phrase
- for category_key, category_value of conversation.categories
- if category_value.deleted != true
- if category_value.name?
- category_value.name = delete_closing_tag category_value.name
- console.log category_value.name
- if category_value.response?
- category_value.response = delete_closing_tag category_value.response
- elem.set "conversation", conversation
- elem.save()
- .catch (error) ->
- console.log error
- .finally ->
- knex.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement