import DataType from "../../model/dataTypes/DataType"; import MemberVariable from "../../model/dataTypes/MemberVariable"; export declare const source = "module {{ dataType.namespace }}\n # {{# getRobyDoc dataType}}{{/ getRobyDoc}}\n class {{ dataType.normalizedName }}{{# if parentDataType }} < {{ parentDataType.normalizedName }}{{/if}}\n include Mongoid::Document\n {{#each memberVariables}}\n {{# each this.choiceTypes }}\n {{> mongoidComplexMember variableName=( jsonChoiceName ../variableName this.typeName ) bidirectional=../bidirectional dataType=this relationshipType=../relationshipType }}\n \n {{ else }}\n {{> mongoidComplexMember variableName=( toModelVariableName this.variableName) bidirectional=this.bidirectional dataType=this.dataType relationshipType=this.relationshipType }}\n \n {{/ each }}\n {{/each}}\n{{# if (eq dataType.normalizedName \"Resource\") }}\n\n def initialize(attrs = nil)\n super(attrs)\n self.resourceType = self.class.name.split(\"::\")[1].to_s\n end \n{{/ if }}\n{{# if (eq dataType.normalizedName \"Extension\") }}\n\n def self.serializePrimitiveExtension(primitive)\n result = nil\n unless primitive.fhirId.nil? || primitive.extension.nil?\n result = Hash.new\n result['id'] = primitive.fhirId\n result['extension'] = primitive.extension.map { |x| x.as_json() }\n end\n result\n end\n\n def self.serializePrimitiveExtensionArray(primitives)\n result = primitives.map{ |p| Extension.serializePrimitiveExtension(p) }\n result.compact\n if (result.empty?) \n return nil\n end\n result\n end\n{{/ if }}\n \n def as_json(*args)\n result = {{# if parentDataType ~}}\n super\n {{~ else ~}}\n Hash.new\n {{~/ if }}\n \n {{# each memberVariables }} \n {{# each choiceTypes }}\n unless self.{{ jsonChoiceName ../variableName this.typeName }}.nil?\n result['{{ jsonChoiceName ../variableName this.typeName }}'] = self.{{ jsonChoiceName ../variableName this.typeName }}\n {{~# unless systemType ~}}\n {{~# if primitive ~}}\n .value \n {{~ else ~}}\n .as_json(*args) \n {{~/ if ~}}\n {{~/ unless }}\n \n {{# if primitive }}\n serialized = Extension.serializePrimitiveExtension(self.{{ jsonChoiceName ../variableName this.typeName }}) \n result['_{{ jsonChoiceName ../variableName this.typeName }}'] = serialized unless serialized.nil?\n {{/ if }}\n end \n {{ else }} \n unless self.{{ toModelVariableName variableName }}.nil? {{# if isArray}} || !self.{{ toModelVariableName variableName }}.any? {{/ if}}\n result['{{ variableName }}'] = self.{{ toModelVariableName variableName }}\n {{~# unless dataType.systemType ~}}\n {{~# if isArray ~}}\n {{~# if dataType.primitive ~}}\n .compact().map{ |x| x.value } \n {{~ else ~}}\n .map{ |x| x.as_json(*args) }\n {{~/ if ~}}\n {{~ else ~}}\n {{~# if dataType.primitive ~}}\n .value\n {{~ else ~}}\n .as_json(*args)\n {{~/ if ~}}\n {{~/ if ~}}\n {{~/ unless }}\n\n {{# if dataType.primitive }}\n {{# if isArray }}\n serialized = Extension.serializePrimitiveExtensionArray(self.{{ toModelVariableName variableName }}) \n result['_{{ variableName }}'] = serialized unless serialized.nil? || !serialized.any?\n {{ else }}\n serialized = Extension.serializePrimitiveExtension(self.{{ toModelVariableName variableName }}) \n result['_{{ variableName }}'] = serialized unless serialized.nil?\n {{/ if }}\n {{/ if }}\n end\n {{/ each }}\n {{/ each }}\n {{!--\n Drop default id\n --}} \n result.delete('id')\n {{!--\n Handle fhirId\n --}} \n unless self.fhirId.nil?\n result['id'] = self.fhirId\n result.delete('fhirId')\n end \n result\n end\n\n def self.transform_json(json_hash{{~# isPrimitiveType this.dataType ~}}, extension_hash{{~/ isPrimitiveType ~}}, target = {{ dataType.normalizedName }}.new)\n {{!--\n --}}\n {{# if (eq dataType.normalizedName \"Resource\") }}\n if 'Resource' == target.class.name.split('::').last && 'Resource' != json_hash['resourceType']\n return Object.const_get('FHIR::' + json_hash['resourceType']).transform_json(json_hash)\n end\n {{/ if }}\n \n {{!--\n If we're transforming a primitive type 'foo', we also need to get the 'id' and 'extension'\n values from the '_foo' attributes and set them accordingly \n --}}\n {{# isPrimitiveType this.dataType }}\n result = target\n unless extension_hash.nil?\n result['fhirId'] = extension_hash['id'] unless extension_hash['id'].nil?\n result['extension'] = extension_hash['extension'].map { |ext| Extension.transform_json(ext) }\n end\n {{ else }}\n {{# if parentDataType }}\n result = self.superclass.transform_json(json_hash, target)\n {{ else }}\n result = target\n {{/ if }}\n {{/ isPrimitiveType ~}}\n\n {{!--\n If this is a primitive type, the json_hash isn't really a hash, it's the value\n --}}\n {{# isPrimitiveType this.dataType }}\n result['value'] = json_hash\n {{~ else ~}}\n\n {{!--\n For non-primitive types, loop over each member variable and add the conversion logic from the Measure JSON to \n the Mongo JSON we're using internally\n --}}\n {{# each memberVariables }}\n\n {{~!--\n If we're looking at a system type, there is no conversion necessary \n --}}\n {{# isSystemType this.dataType }}\n {{# ifEquals this.variableName 'id'}}\n result['fhirId'] = json_hash['id'] unless json_hash['id'].nil?\n {{ else }}\n {{~!-- do nothing for fhirId --}}\n {{# ifEquals this.variableName 'fhirId' }}\n {{ else }}\n result['{{ toModelVariableName this.variableName }}'] = json_hash['{{this.variableName}}'] unless json_hash['{{ this.variableName }}'].nil?\n {{/ ifEquals }} \n {{/ ifEquals }} \n {{!--\n Dealing with a non-system type, so we have to convert \n --}}\n {{ else }}\n \n {{~!--\n If it's an array, we have to transform each element in the array before assigning it\n --}}\n {{# if this.isArray }}\n {{!--\n Primitive arrays are even trickier, as the extension data is stored in a separate array\n --}}\n {{# isPrimitiveType this.dataType }}\n result['{{ toModelVariableName this.variableName }}'] = json_hash['{{this.variableName}}'].each_with_index.map do |var, i|\n extension_hash = json_hash['_{{this.variableName}}'] && json_hash['_{{this.variableName}}'][i]\n {{ this.dataType.normalizedName }}.transform_json(var, extension_hash)\n end unless json_hash['{{ this.variableName }}'].nil?\n {{ else }}\n result['{{ toModelVariableName this.variableName }}'] = json_hash['{{this.variableName}}'].map { |var| {{this.dataType.normalizedName}}.transform_json(var) } unless json_hash['{{ this.variableName }}'].nil?\n {{/ isPrimitiveType }}\n {{!--\n If it's not an array, we can transform just the single element\n --}}\n {{ else }}\n {{# each this.choiceTypes }}\n {{> transformMember variableName=../variableName className=this.normalizedName primitive=this.primitive choiceType=this.typeName }}\n\n {{ else }}\n {{> transformMember variableName=this.variableName className=this.dataType.normalizedName primitive=this.dataType.primitive}}\n\n {{/ each }}\n {{/ if }}\n {{/ isSystemType }}\n {{~/ each }}\n {{~/ isPrimitiveType }}\n\n result\n end\n end\nend\n"; export interface TemplateContext { dataType: DataType; parentDataType: DataType | null; memberVariables: Array; } declare const _default: HandlebarsTemplateDelegate; export default _default; //# sourceMappingURL=classTemplate.d.ts.map