lib/sdp/importers/phin_vads_importer.rb
# Create a new ResponseSet set based on the the PHIN VADS Valueset and Version
Create a new ResponseSet set based on the the PHIN VADS Valueset and Version
Create a new ResponseSet set based on the the PHIN VADS Valueset and Version
def create_vs_and_responses(vset, ver)
        rset = ResponseSet.where(oid: vset.oid.strip, version: ver.versionNumber).first
        if rset && !params[:force_reload]
          logger.debug "Valueset #{vset.oid} version: #{ver.versionNumber} already exists in systems "
        elsif rset && params[:force_reload]
          rset.name = (vset.name || '').force_encoding('ISO-8859-1').encode('UTF-8').delete("\u0000")
          rset.description = (vset.definitionText || '').force_encoding('ISO-8859-1').encode('UTF-8').delete("\u0000")
          rset.responses = []
          import_valueset_codes(rset, ver.id)
          rset.save
        else
          prev = ResponseSet.where(oid: vset.oid.strip, version: ver.versionNumber - 1).first
          status = RS_STATUS_MAPPING[ver.status] || 'draft'
          stage = RS_STAGE_MAPPING[ver.status] || 'Draft'
          rset = ResponseSet.new(name: (vset.name || '').force_encoding('ISO-8859-1').encode('UTF-8').delete("\u0000"),
                                 description: (vset.definitionText || '').force_encoding('ISO-8859-1').encode('UTF-8').delete("\u0000"),
                                 parent_id: nil,
                                 oid: vset.oid.strip.delete("\u0000"),
                                 version: ver.versionNumber,
                                 status: status.delete("\u0000"),
                                 content_stage: stage.delete("\u0000"),
                                 created_by: user,
                                 parent: prev,
                                 version_independent_id: prev ? prev.version_independent_id : nil,
                                 source: 'PHIN_VADS')
          import_valueset_codes(rset, ver.id)
          rset.save
        end
        rset
      end
def create_vs_and_responses ( vset , ver ) rset = ResponseSet . where ( oid : vset . oid . strip , version : ver . versionNumber ) . first if rset && ! params [ :force_reload ] logger . debug "Valueset #{vset.oid} version: #{ver.versionNumber} already exists in systems " elsif rset && params [ :force_reload ] rset . name = ( vset . name || '' ) . force_encoding ( 'ISO-8859-1' ) . encode ( 'UTF-8' ) . delete ( "\u0000" ) rset . description = ( vset . definitionText || '' ) . force_encoding ( 'ISO-8859-1' ) . encode ( 'UTF-8' ) . delete ( "\u0000" ) rset . responses = [ ] import_valueset_codes ( rset , ver . id ) rset . save else prev = ResponseSet . where ( oid : vset . oid . strip , version : ver . versionNumber - 1 ) . first status = RS_STATUS_MAPPING [ ver . status ] || 'draft' stage = RS_STAGE_MAPPING [ ver . status ] || 'Draft' rset = ResponseSet . new ( name : ( vset . name || '' ) . force_encoding ( 'ISO-8859-1' ) . encode ( 'UTF-8' ) . delete ( "\u0000" ) , description : ( vset . definitionText || '' ) . force_encoding ( 'ISO-8859-1' ) . encode ( 'UTF-8' ) . delete ( "\u0000" ) , parent_id : nil , oid : vset . oid . strip . delete ( "\u0000" ) , version : ver . versionNumber , status : status . delete ( "\u0000" ) , content_stage : stage . delete ( "\u0000" ) , created_by : user , parent : prev , version_independent_id : prev ? prev . version_independent_id : nil , source : 'PHIN_VADS' ) import_valueset_codes ( rset , ver . id ) rset . save end rset end
Create a new ResponseSet set based on the the PHIN VADS Valueset and Version
Create a new ResponseSet set based on the the PHIN VADS Valueset and Version
# make sure it doesn't exist yet # are there already response sets in the db for the valueset oid # need to force encode name and definitionText fields due to the way the hessian lib works # some ugly chars come across in the fields at times and need to be dealt with before # saving to the database
vset
ver