:green_heart: Fix tests.

:green_heart: Fix tests.

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";

declare %an:nondeterministic function local:test-facttable($expected as integer, $params as object) as item
{
    let $endpoint := "facts"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].FactTable[])
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:nondeterministic function local:test-empty($params as object) as item
{
    let $endpoint := "facts"
    let $res as object := test:invoke-raw($endpoint, $params)
    return if($res.status eq 200 and ($res.headers."Content-Length" eq "0" or empty($res.body.content))) then true else {
        url: test:url($endpoint, $params),
        unexpectedResponse: $res
    }
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

declare %an:nondeterministic function local:test-labels() as item
{
    let $endpoint := "facts"
    let $params := {
        concept: [ "fac:Assets", "us-gaap:CashAndCashEquivalentsAtCarryingValue" ],
        report: "FundamentalAccountingConcepts",
        format: "csv",
        ticker: "ko",
        fiscalYear: 2013,
        fiscalPeriod: "Q3",
        labels: true
    }
    let $res as object := test:invoke-raw($endpoint, $params)
    let $actual := $res.body.content
    let $expectedLines := (
        "SEC Acceptance Date [Axis],Archive [Axis],Fiscal Period [Axis],Fiscal Year [Axis],Fiscal Period Type [Axis],Period [Axis],Reporting Entity [Axis],Concept [Axis],Legal Entity [Axis],Unit,Value,Decimals\r\n20131024121047,0000021344-13-000050,Q3,2013,instant,\"September 27, 2013\",COCA COLA CO,\"Cash and Cash Equivalents, at Carrying Value\",Default Legal Entity [Member],USD,11118000000,-6\r\n20131024121047,0000021344-13-000050,Q3,2013,instant,\"September 27, 2013\",COCA COLA CO,Assets,Default Legal Entity [Member],USD,89432000000,-6\r\n"
    )
    return if($res.status eq 200 and (every $line in $expectedLines satisfies contains($actual,$line))) then true else {
        url: test:url($endpoint, $params),
        unexpectedResponse: $res,
        expected: $expectedLines
    }
};

declare %an:nondeterministic function local:test-labels-aids() as item
{
    let $endpoint := "facts"
    let $params := {
        concept: "disc:AdvertisingCostsPolicyTextBlock",
        report: "Disclosures",
        format: "json",
        fiscalYear: 2014,
        fiscalPeriod: "FY",
        labels: true,
        aid: "0000858877-14-000029"
    }
    let $res := test:invoke($endpoint, $params)
    let $actual := [
            for $labels in $res[2].FactTable[].Labels
            return (keys($labels) ! $labels.$$)
        ]
    let $expected := [ "Archive [Axis]", "SEC Acceptance Date [Axis]", "Fiscal Year [Axis]", "Non-Numeric [Member]", "Default Legal Entity [Member]", "Unit [Axis]", "Advertising Costs, Policy", "Fiscal Period [Axis]", "Concept [Axis]", "Reporting Entity [Axis]", "Legal Entity [Axis]", "Fiscal Period Type [Axis]", "Period [Axis]", "From July 28, 2013 to July 26, 2014", "CISCO SYSTEMS, INC." ]
    let $status as integer := $res[1]
    return test:assert-eq-array($expected, $actual, $status, test:url($endpoint, $params))
};

local:check({
    cocacola-latest:
    (: this test will fail and needs to be updated if a newer report has been filed.
       current latest filing: 2013 :)
    local:test-facttable(468, {
        ticker:"ko",
        fiscalYear: "ALL",
        fiscalPeriod: "FY"
    }),
    cocacola-all: local:test-facttable(468, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "instant", "YTD", "QTD" ]
    }),
    cocacola-all-q3: local:test-facttable(341, {
        ticker:"ko",
        fiscalYear: 2014,
        fiscalPeriod: [ "Q3" ],
        fiscalPeriodType: [ "instant", "YTD", "QTD" ]
    }),
    cocacola-instant: local:test-facttable(163, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "instant" ]
    }),
    cocacola-ytd: local:test-facttable(305, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "YTD" ]
    }),
    cocacola-qtd: local:test-facttable(90, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "Q2" ],
        fiscalPeriodType: [ "QTD" ]
    }),
    cocacolaCSVLabels: local:test-labels(),
    ciscoLabelsByAid: local:test-labels-aids(),
    tickerconcept: local:test-facttable(1, {
        ticker:"ko",
        concept:"us-gaap:Assets",
        fiscalYear: "ALL",
        fiscalPeriod: "FY"
    }),
    tickerfyfprole: local:test-facttable(1, {
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"Q1",
        concept:"us-gaap:Assets"
    }),
    tagconcept: local:test-facttable(30, {
        tag:"DOW30",
        concept:"us-gaap:Assets",
        fiscalYear: "ALL",
        fiscalPeriod: "FY"
    }),
    tagfyfprole: local:test-facttable(30, {
        tag:"DOW30",
        fiscalYear:"2012",
        fiscalPeriod:"Q1",
        concept:"us-gaap:Assets"
    }),
    testNoEntity4Sic: local:test-empty({
        concept:"fac:Assets",
        map:"FundamentalAccountingConcepts",
        format:"csv",
        sic:"5052",
        fiscalYear:"2010",
        fiscalPeriod:"Q3"
    }),
    quartersfact: local:test-facttable(0, { (: this fact is not reported in the raw XML filing :)
        aid: "0000051143-13-000007",
        concept: "disc:AssetRetirementObligationsPolicy",
        fiscalPeriod: "Q3",
        fiscalYear: "2013",
        map: "Disclosures"
    }),
    quartersfact2: local:test-facttable(1, {
        aid: "0001193125-12-207154",
        concept: "disc:CashFlowOperatingCapitalTableTextBlock",
        fiscalPeriod: "Q1",
        fiscalYear: "2012",
        map: "Disclosures"
    }),
    generic: local:test-facttable(2, {
        "xbrl:Entity":"http://www.sec.gov/CIK 0000021344",
        "sec:Accepted":"20140227132423",
        concept:"us-gaap:Assets",
        profile-name: "generic"
    })
})

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";

declare %an:nondeterministic function local:test-facttable($expected as integer, $params as object) as item
{
    let $endpoint := "facts"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].FactTable[])
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:nondeterministic function local:test-empty($params as object) as item
{
    let $endpoint := "facts"
    let $res as object := test:invoke-raw($endpoint, $params)
    return if($res.status eq 200 and ($res.headers."Content-Length" eq "0" or empty($res.body.content))) then true else {
        url: test:url($endpoint, $params),
        unexpectedResponse: $res
    }
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

declare %an:nondeterministic function local:test-labels() as item
{
    let $endpoint := "facts"
    let $params := {
        concept: [ "fac:Assets", "us-gaap:CashAndCashEquivalentsAtCarryingValue" ],
        report: "FundamentalAccountingConcepts",
        format: "csv",
        ticker: "ko",
        fiscalYear: 2013,
        fiscalPeriod: "Q3",
        labels: true
    }
    let $res as object := test:invoke-raw($endpoint, $params)
    let $actual := $res.body.content
    let $expectedLines := (
        "SEC Acceptance Date [Axis],Archive [Axis],Fiscal Period [Axis],Fiscal Year [Axis],Fiscal Period Type [Axis],Period [Axis],Reporting Entity [Axis],Concept [Axis],Legal Entity [Axis],Unit,Value,Decimals\r\n20131024121047,0000021344-13-000050,Q3,2013,instant,\"September 27, 2013\",COCA COLA CO,\"Cash and Cash Equivalents, at Carrying Value\",Default Legal Entity [Member],USD,11118000000,-6\r\n20131024121047,0000021344-13-000050,Q3,2013,instant,\"September 27, 2013\",COCA COLA CO,Assets,Default Legal Entity [Member],USD,89432000000,-6\r\n"
    )
    return if($res.status eq 200 and (every $line in $expectedLines satisfies contains($actual,$line))) then true else {
        url: test:url($endpoint, $params),
        unexpectedResponse: $res,
        expected: $expectedLines
    }
};

declare %an:nondeterministic function local:test-labels-aids() as item
{
    let $endpoint := "facts"
    let $params := {
        concept: "disc:AdvertisingCostsPolicyTextBlock",
        report: "Disclosures",
        format: "json",
        fiscalYear: 2014,
        fiscalPeriod: "FY",
        labels: true,
        aid: "0000858877-14-000029"
    }
    let $res := test:invoke($endpoint, $params)
    let $actual := [
            for $labels in $res[2].FactTable[].Labels
            return (keys($labels) ! $labels.$$)
        ]
    let $expected := [ "Archive [Axis]", "SEC Acceptance Date [Axis]", "Fiscal Year [Axis]", "Non-Numeric [Member]", "Default Legal Entity [Member]", "Unit [Axis]", "Advertising Costs, Policy", "Fiscal Period [Axis]", "Concept [Axis]", "Reporting Entity [Axis]", "Legal Entity [Axis]", "Fiscal Period Type [Axis]", "Period [Axis]", "From July 28, 2013 to July 26, 2014", "CISCO SYSTEMS, INC." ]
    let $status as integer := $res[1]
    return test:assert-eq-array($expected, $actual, $status, test:url($endpoint, $params))
};

local:check({
    cocacola-latest:
    (: this test will fail and needs to be updated if a newer report has been filed.
       current latest filing: 2013 :)
    local:test-facttable(468, {
        ticker:"ko"
    }),
    cocacola-all: local:test-facttable(468, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "instant", "YTD", "QTD" ]
    }),
    cocacola-all-q3: local:test-facttable(341, {
        ticker:"ko",
        fiscalYear: 2014,
        fiscalPeriod: [ "Q3" ],
        fiscalPeriodType: [ "instant", "YTD", "QTD" ]
    }),
    cocacola-instant: local:test-facttable(163, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "instant" ]
    }),
    cocacola-ytd: local:test-facttable(305, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "FY" ],
        fiscalPeriodType: [ "YTD" ]
    }),
    cocacola-qtd: local:test-facttable(90, {
        ticker:"ko",
        fiscalYear: 2013,
        fiscalPeriod: [ "Q2" ],
        fiscalPeriodType: [ "QTD" ]
    }),
    cocacolaCSVLabels: local:test-labels(),
    ciscoLabelsByAid: local:test-labels-aids(),
    tickerconcept: local:test-facttable(1, {
        ticker:"ko",
        concept:"us-gaap:Assets"
    }),
    tickerfyfprole: local:test-facttable(1, {
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"Q1",
        concept:"us-gaap:Assets"
    }),
    tagconcept: local:test-facttable(30, {
        tag:"DOW30",
        concept:"us-gaap:Assets"
    }),
    tagfyfprole: local:test-facttable(30, {
        tag:"DOW30",
        fiscalYear:"2012",
        fiscalPeriod:"Q1",
        concept:"us-gaap:Assets"
    }),
    testNoEntity4Sic: local:test-empty({
        concept:"fac:Assets",
        map:"FundamentalAccountingConcepts",
        format:"csv",
        sic:"5052",
        fiscalYear:"2010",
        fiscalPeriod:"Q3"
    }),
    quartersfact: local:test-facttable(0, { (: this fact is not reported in the raw XML filing :)
        aid: "0000051143-13-000007",
        concept: "disc:AssetRetirementObligationsPolicy",
        fiscalPeriod: "Q3",
        fiscalYear: "2013",
        map: "Disclosures"
    }),
    quartersfact2: local:test-facttable(1, {
        aid: "0001193125-12-207154",
        concept: "disc:CashFlowOperatingCapitalTableTextBlock",
        fiscalPeriod: "Q1",
        fiscalYear: "2012",
        map: "Disclosures"
    }),
    generic: local:test-facttable(2, {
        "xbrl:Entity":"http://www.sec.gov/CIK 0000021344",
        "sec:Accepted":"20140227132423",
        concept:"us-gaap:Assets",
        profile-name: "generic"
    })
})


fixed common stock shares outstanding in bfi report.

jsoniq version "1.0";
import module namespace http = "http://zorba.io/modules/http-client";
import module namespace request = "http://www.28msec.com/modules/http-request";

declare variable $id := "BasicFinancialInformation";
declare variable $report := parse-json(http:get("http://" || request:server-name() || ":" || request:server-port() || "/v1/_queries/public/export/fac.jq?_method=POST").body.content);
declare variable $desc :=
  "This report extends the fundamental accounting concepts report. Documentation about the fundamental accounting concepts defined in this report can be found at http://fundamentalaccountingconcepts.wikispaces.com/home";
declare variable $role := "http://xbrl.io/basic-financial-information";
declare variable $additionalRules :=
  (
    {
        "Id" : "gi_CommonStockSharesOutstanding",
        "Type" : "xbrl28:formula",
        "Label" : "CommonStockSharesOutstanding imputation",
        "DependsOn" : [ "fac:Assets" ],
        "Formula" : "(: workaround for bug: https://github.com/28msec/xbrl-infosetgenerator/issues/7 :)
let $aligned-filter-no-fiscal as object :=
    copy $new := $aligned-filter
    modify (
    if($new.Aspects.\"sec:FiscalPeriod\") then delete json $new.Aspects.\"sec:FiscalPeriod\" else (),
    if($new.Aspects.\"sec:FiscalYear\") then delete json $new.Aspects.\"sec:FiscalYear\" else ()
  )
  return $new
let $AllEntityCommonStockSharesOutstanding as object* :=
	facts:facts-for-internal((
      \"dei:EntityCommonStockSharesOutstanding\"
    ), $hypercube, $aligned-filter-no-fiscal, $concept-maps, $rules, $cache, $options)
for $facts in (facts:facts-for-internal((
      \"fac:CommonStockSharesOutstanding\", \"fac:Assets\"
    ), $hypercube, $aligned-filter, $concept-maps, $rules, $cache, $options)
  )
let $aligned-period := ( facts:duration-for-fact($facts).End, facts:instant-for-fact($facts), \"forever\")[1]
group by $canonical-filter-string :=
  facts:canonically-serialize-object($facts, ($facts:CONCEPT, \"_id\", \"IsInDefaultHypercube\", \"Type\", \"Value\", \"Decimals\", \"AuditTrails\", \"xbrl28:Type\", \"Balance\", $facts:PERIOD, $facts:UNIT))
  , $aligned-period
let $archive as string := distinct-values($facts.$facts:ASPECTS.\"sec:Archive\")
let $warnings as string* := ()
let $CommonStockSharesOutstanding as object* := $facts[$$.$facts:ASPECTS.$facts:CONCEPT eq \"fac:CommonStockSharesOutstanding\"]
let $EntityCommonStockSharesOutstanding as object* := $AllEntityCommonStockSharesOutstanding[$$.$facts:ASPECTS.\"sec:Archive\" eq $archive]
let $Assets as object* := $facts[$$.$facts:ASPECTS.$facts:CONCEPT eq \"fac:Assets\"]
let $warnings := ($warnings, if(count($Assets) gt 1)
                             then if(count(distinct-values($Assets.Value)) gt 1)
                                  then \"Cell collision with conflicting values for concept Assets.\"
                                  else \"Cell collision with consistent values for concept Assets.\"
                             else (),
                             if(count($CommonStockSharesOutstanding) gt 1)
                             then if(count(distinct-values($CommonStockSharesOutstanding.Value)) gt 1)
                                  then \"Cell collision with conflicting values for concept CommonStockSharesOutstanding.\"
                                  else \"Cell collision with consistent values for concept CommonStockSharesOutstanding.\"
                             else (),
							 if(count($EntityCommonStockSharesOutstanding) gt 1)
                             then if(count(distinct-values($EntityCommonStockSharesOutstanding.Value)) gt 1)
                                  then \"Cell collision with conflicting values for concept EntityCommonStockSharesOutstanding.\"
                                  else \"Cell collision with consistent values for concept EntityCommonStockSharesOutstanding.\"
                             else ())
let $CommonStockSharesOutstanding as object? := $CommonStockSharesOutstanding[1]
let $EntityCommonStockSharesOutstanding as object? := $EntityCommonStockSharesOutstanding[1]
let $Assets as object? := $Assets[1]
return
  switch (true)
  case exists($CommonStockSharesOutstanding) return $CommonStockSharesOutstanding
  case (exists($EntityCommonStockSharesOutstanding) and exists($Assets))
  return
    let $computed-value := rules:decimal-value($EntityCommonStockSharesOutstanding)
    let $audit-trail-message as string* :=
      rules:fact-trail({\"Aspects\": { \"xbrl:Unit\" : \"xbrli:shares\", \"xbrl:Concept\" : \"fac:CommonStockSharesOutstanding\" }, Value: $computed-value }) || \" = \" ||
         rules:fact-trail($EntityCommonStockSharesOutstanding, \"EntityCommonStockSharesOutstanding\") || \" [\" || (facts:duration-for-fact($EntityCommonStockSharesOutstanding).End, facts:instant-for-fact($EntityCommonStockSharesOutstanding)) || \"]\"
    let $audit-trail-message as string* := ($audit-trail-message, $warnings)
    let $source-facts as object* := ($EntityCommonStockSharesOutstanding)
    return
		copy $newfact :=
		  rules:create-computed-fact(
			$Assets,
			\"fac:CommonStockSharesOutstanding\",
			$computed-value,
			$rule,
			$audit-trail-message,
			$source-facts,
			$options)
		modify (
			if($newfact(\"Unit\"))
			then replace value of json $newfact(\"Unit\") with \"xbrli:shares\"
			else insert json { \"Unit\": \"xbrli:shares\" } into $newfact,
			if($newfact.$facts:ASPECTS.$facts:UNIT)
			then replace value of json $newfact.$facts:ASPECTS.$facts:UNIT with \"xbrli:shares\"
			else insert json { $facts:UNIT: \"xbrli:shares\" } into $newfact.$facts:ASPECTS
		  )
		return $newfact
  default return ()",
        "ComputableConcepts" : [ "fac:CommonStockSharesOutstanding" ]
      },
      {
          "Id" : "decimals_inf",
          "Type" : "xbrl28:formula",
          "Label" : "Align INF decimals",
          "Formula" : "for $fact in facts:facts-for-internal($concepts, $hypercube, $aligned-filter, $concept-maps, $rules, $cache, $options)
                             return
                               if(string($fact.Decimals) eq \"INF\")
                               then
                                 let $concept := $fact.Aspects.\"xbrl:Concept\"
                                 let $audit-trail :=
                                   {
                                     \"Type\" : \"xbrl28:decimals-inf-alignment\",
                                     \"Label\" : \"Aligning Decimals to 3 instead of INF\",
                                     \"Message\" : $concept || \" = 0\",
                                     \"Data\" : {
                                       \"OutputConcept\" : $concept
                                     }
                                   }
                                 return
                                 copy $f := $fact
                                 modify (
                                     replace value of json $f.Decimals with 3,
                                     if(exists($f.AuditTrails))
                                     then append json $audit-trail into $f.AuditTrails
                                     else insert json { AuditTrails: [ $audit-trail ] } into $f
                                 )
                                 return $f
                               else $fact"
        }
  );

(: Presentation :)
let $presentation := $report.Networks[][$$.ShortName eq "Presentation"]
let $concepts :=
    {
      "fac:CommonStockSharesAuthorized": {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "Id" : "e7c449eb-4e1b-4d20-af35-b783cfdab03e"
      },
      "fac:CommonStockSharesIssued": {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "Id" : "a8a4ae32-0424-437e-a645-428398f95f9c"
      },
      "fac:CommonStockSharesOutstanding": {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "Id" : "f51e72c7-a3ce-4639-99b0-47ca36d54a7b"
      }
    }
let $genInfo := $presentation.Trees."fac:FundamentalAccountingConceptsLineItems".To."fac:FundamentalAccountingConceptsHierarchy".To."fac:GeneralInformationHierarchy"
return
  {
    replace value of json $presentation.LinkRole with $role;
    replace value of json $genInfo.To with {| ( $genInfo.To, $concepts ) |};
  }

(: Hypercube :)
let $conceptsDomain := $report.Hypercubes."xbrl:DefaultHypercube".Aspects."xbrl:Concept".Domains."xbrl:ConceptDomain"
let $concepts :=
    {
      "fac:CommonStockSharesAuthorized": {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "Id" : "e7c449eb-4e1b-4d20-af35-b783cfdab03e"
      },
      "fac:CommonStockSharesIssued": {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "Id" : "a8a4ae32-0424-437e-a645-428398f95f9c"
      },
      "fac:CommonStockSharesOutstanding": {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "Id" : "f51e72c7-a3ce-4639-99b0-47ca36d54a7b"
      }
    }
return
  replace value of json $conceptsDomain.Members with {| $conceptsDomain.Members, $concepts |};

(: ConceptMap :)
let $conceptMap := $report.Networks[][$$.ShortName eq "ConceptMap"]
let $mappings :=
    {
      "fac:CommonStockSharesAuthorized" : {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "To" : {
          "us-gaap:CommonStockSharesAuthorized": {
            "Name" : "us-gaap:CommonStockSharesAuthorized",
            "Id" : "8ed0a312-9891-4d3d-b459-67604dce2124"
          }
        },
        "Id" : "372f39c9-c8ed-4654-a424-6f033bb0ddd2"

      },
      "fac:CommonStockSharesIssued" : {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "To" : {
          "us-gaap:CommonStockSharesIssued": {
            "Name" : "us-gaap:CommonStockSharesIssued",
            "Id" : "1359b87e-5f75-49f3-849b-d410cc399b50"
          }
        },
        "Id" : "66226139-512f-4edd-8c18-6d7e307a1f66"
      },
      "fac:CommonStockSharesOutstanding" : {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "To" : {
          "dei:EntityCommonStockSharesOutstanding": {
            "Name" : "dei:EntityCommonStockSharesOutstanding",
            "Id" : "b8d27670-5caa-411f-8305-860c0613c31f",
            "Order" : 1
          },
          "us-gaap:CommonStockSharesOutstanding" : {
            "Id" : "a91849bd-0aa2-4f1c-8dcb-c85537bf36a8",
            "Name" : "us-gaap:CommonStockSharesOutstanding",
            "Order" : 2
          }
        },
        "Id" : "91b87448-a8dd-4739-9cdf-2cdaef6a4ff6"
      }
    }
return
  {
    replace value of json $conceptMap.LinkRole with $role;
    replace value of json $conceptMap.Trees with {| $conceptMap.Trees, $mappings |};
  }

(: DefinitionModel :)
replace value of json $report.DefinitionModels[][1].Breakdowns.y[][1].BreakdownTrees[][1].LinkRole with $role;

(: remove default_zero rule :)
replace value of json $report.Rules with [ $report.Rules[][$$.Id ne "default_zero"] ];

{ "_id": $id,
  Archive: null,
  Label: "Basic Financial Information",
  Description: $desc,
  Prefix: "fac",
  Role: $role,
  Owner: "charlie@prudena.com",
  LastModified: string(current-dateTime()),
  ACL: [],
  Networks: $report.Networks,
  Hypercubes: $report.Hypercubes,
  DefinitionModels: $report.DefinitionModels,
  Rules: [ for $rule in ($report.Rules[], $additionalRules)
           order by $rule.ComputableConcepts[][1], $rule.Id descending empty least
           return $rule ],
  Filters: {
    cik: [  ],
    tag: [ "DOW30" ],
    fiscalYear : [ 2013 ],
    fiscalPeriod : [ "FY" ],
    sic : [  ]
  }
}

jsoniq version "1.0";
import module namespace http = "http://zorba.io/modules/http-client";
import module namespace request = "http://www.28msec.com/modules/http-request";

declare variable $id := "BasicFinancialInformation";
declare variable $report := parse-json(http:get("http://" || request:server-name() || ":" || request:server-port() || "/v1/_queries/public/export/fac.jq?_method=POST").body.content);
declare variable $desc :=
  "This report extends the fundamental accounting concepts report. Documentation about the fundamental accounting concepts defined in this report can be found at http://fundamentalaccountingconcepts.wikispaces.com/home";
declare variable $role := "http://xbrl.io/basic-financial-information";
declare variable $additionalRules :=
  (
    {
        "Id" : "gi_CommonStockSharesOutstanding",
        "Type" : "xbrl28:formula",
        "Label" : "CommonStockSharesOutstanding imputation",
        "Formula" : "(: workaround for bug: https://github.com/28msec/xbrl-infosetgenerator/issues/7 :)
                     let $aligned-filter-no-fiscal as object :=
    copy $new := $aligned-filter
    modify (
	  if($new.Aspects.\"sec:FiscalPeriod\") then delete json $new.Aspects.\"sec:FiscalPeriod\" else (),
	  if($new.Aspects.\"sec:FiscalYear\") then delete json $new.Aspects.\"sec:FiscalYear\" else ()
	)
	return $new
for $facts in (facts:facts-for-internal((
      \"fac:CommonStockSharesOutstanding\"
    ), $hypercube, $aligned-filter, $concept-maps, $rules, $cache, $options),
	facts:facts-for-internal((
      \"dei:EntityCommonStockSharesOutstanding\"
    ), $hypercube, $aligned-filter-no-fiscal, $concept-maps, $rules, $cache, $options)
	)
let $aligned-period := year-from-date(xs:date(( facts:duration-for-fact($facts).End, facts:instant-for-fact($facts))[1]))
group by $canonical-filter-string :=
  facts:canonically-serialize-object($facts, ($facts:CONCEPT, \"_id\", \"IsInDefaultHypercube\", \"Type\", \"Value\", \"Decimals\", \"AuditTrails\", \"xbrl28:Type\", \"Balance\", $facts:PERIOD))
  , $aligned-period
let $warnings as string* := ()
let $CommonStockSharesOutstanding as object* := $facts[$$.$facts:ASPECTS.$facts:CONCEPT eq \"fac:CommonStockSharesOutstanding\"]
let $EntityCommonStockSharesOutstanding as object* := $facts[$$.$facts:ASPECTS.$facts:CONCEPT eq \"dei:EntityCommonStockSharesOutstanding\"]
let $warnings := ($warnings, if(count($CommonStockSharesOutstanding) gt 1)
                             then if(count(distinct-values($CommonStockSharesOutstanding.Value)) gt 1)
                                  then \"Cell collision with conflicting values for concept CommonStockSharesOutstanding.\"
                                  else \"Cell collision with consistent values for concept CommonStockSharesOutstanding.\"
                             else (),
							 if(count($EntityCommonStockSharesOutstanding) gt 1)
                             then if(count(distinct-values($EntityCommonStockSharesOutstanding.Value)) gt 1)
                                  then \"Cell collision with conflicting values for concept EntityCommonStockSharesOutstanding.\"
                                  else \"Cell collision with consistent values for concept EntityCommonStockSharesOutstanding.\"
                             else ())
let $CommonStockSharesOutstanding as object? := $CommonStockSharesOutstanding[1]
let $EntityCommonStockSharesOutstanding as object? := $EntityCommonStockSharesOutstanding[1]
let $_unit := ($facts.$facts:ASPECTS.$facts:UNIT)[1]
return
  switch (true)
  case exists($CommonStockSharesOutstanding) return $CommonStockSharesOutstanding
  case (exists($EntityCommonStockSharesOutstanding) and true)
  return
    let $computed-value := rules:decimal-value($EntityCommonStockSharesOutstanding)
    let $audit-trail-message as string* :=
      rules:fact-trail({\"Aspects\": { \"xbrl:Unit\" : $_unit, \"xbrl:Concept\" : \"fac:CommonStockSharesOutstanding\" }, Value: $computed-value }) || \" = \" ||
         rules:fact-trail($EntityCommonStockSharesOutstanding, \"EntityCommonStockSharesOutstanding\") || \" [\" || (facts:duration-for-fact($facts).End, facts:instant-for-fact($facts)) || \"]\"
    let $audit-trail-message as string* := ($audit-trail-message, $warnings)
    let $source-facts as object* := ($EntityCommonStockSharesOutstanding)
    return
      if(string(number($computed-value)) != \"NaN\" and not($computed-value instance of xs:boolean) and $computed-value ne xs:integer($computed-value))
      then
        copy $newfact :=
          rules:create-computed-fact(
            $EntityCommonStockSharesOutstanding,
            \"fac:CommonStockSharesOutstanding\",
            $computed-value,
            $rule,
            $audit-trail-message,
            $source-facts,
            $options)
        modify (
            replace value of json $newfact(\"Decimals\") with 2
          )
        return $newfact
      else
        rules:create-computed-fact(
          $EntityCommonStockSharesOutstanding,
          \"fac:CommonStockSharesOutstanding\",
          $computed-value,
          $rule,
          $audit-trail-message,
          $source-facts,
            $options)
  default return ()",
        "ComputableConcepts" : [ "fac:CommonStockSharesOutstanding" ]
      },
      {
          "Id" : "decimals_inf",
          "Type" : "xbrl28:formula",
          "Label" : "Align INF decimals",
          "Formula" : "for $fact in facts:facts-for-internal($concepts, $hypercube, $aligned-filter, $concept-maps, $rules, $cache, $options)
                             return
                               if(string($fact.Decimals) eq \"INF\")
                               then
                                 let $concept := $fact.Aspects.\"xbrl:Concept\"
                                 let $audit-trail :=
                                   {
                                     \"Type\" : \"xbrl28:decimals-inf-alignment\",
                                     \"Label\" : \"Aligning Decimals to 3 instead of INF\",
                                     \"Message\" : $concept || \" = 0\",
                                     \"Data\" : {
                                       \"OutputConcept\" : $concept
                                     }
                                   }
                                 return
                                 copy $f := $fact
                                 modify (
                                     replace value of json $f.Decimals with 3,
                                     if(exists($f.AuditTrails))
                                     then append json $audit-trail into $f.AuditTrails
                                     else insert json { AuditTrails: [ $audit-trail ] } into $f
                                 )
                                 return $f
                               else $fact"
        }
  );

(: Presentation :)
let $presentation := $report.Networks[][$$.ShortName eq "Presentation"]
let $concepts :=
    {
      "fac:CommonStockSharesAuthorized": {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "Id" : "e7c449eb-4e1b-4d20-af35-b783cfdab03e"
      },
      "fac:CommonStockSharesIssued": {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "Id" : "a8a4ae32-0424-437e-a645-428398f95f9c"
      },
      "fac:CommonStockSharesOutstanding": {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "Id" : "f51e72c7-a3ce-4639-99b0-47ca36d54a7b"
      }
    }
let $genInfo := $presentation.Trees."fac:FundamentalAccountingConceptsLineItems".To."fac:FundamentalAccountingConceptsHierarchy".To."fac:GeneralInformationHierarchy"
return
  {
    replace value of json $presentation.LinkRole with $role;
    replace value of json $genInfo.To with {| ( $genInfo.To, $concepts ) |};
  }

(: Hypercube :)
let $conceptsDomain := $report.Hypercubes."xbrl:DefaultHypercube".Aspects."xbrl:Concept".Domains."xbrl:ConceptDomain"
let $concepts :=
    {
      "fac:CommonStockSharesAuthorized": {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "Id" : "e7c449eb-4e1b-4d20-af35-b783cfdab03e"
      },
      "fac:CommonStockSharesIssued": {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "Id" : "a8a4ae32-0424-437e-a645-428398f95f9c"
      },
      "fac:CommonStockSharesOutstanding": {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "Id" : "f51e72c7-a3ce-4639-99b0-47ca36d54a7b"
      }
    }
return
  replace value of json $conceptsDomain.Members with {| $conceptsDomain.Members, $concepts |};

(: ConceptMap :)
let $conceptMap := $report.Networks[][$$.ShortName eq "ConceptMap"]
let $mappings :=
    {
      "fac:CommonStockSharesAuthorized" : {
        "Name" : "fac:CommonStockSharesAuthorized",
        "Label" : "Common Stock Shares (authorized)",
        "To" : {
          "us-gaap:CommonStockSharesAuthorized": {
            "Name" : "us-gaap:CommonStockSharesAuthorized",
            "Id" : "8ed0a312-9891-4d3d-b459-67604dce2124"
          }
        },
        "Id" : "372f39c9-c8ed-4654-a424-6f033bb0ddd2"

      },
      "fac:CommonStockSharesIssued" : {
        "Name" : "fac:CommonStockSharesIssued",
        "Label" : "Common Stock Shares (issued)",
        "To" : {
          "us-gaap:CommonStockSharesIssued": {
            "Name" : "us-gaap:CommonStockSharesIssued",
            "Id" : "1359b87e-5f75-49f3-849b-d410cc399b50"
          }
        },
        "Id" : "66226139-512f-4edd-8c18-6d7e307a1f66"
      },
      "fac:CommonStockSharesOutstanding" : {
        "Name" : "fac:CommonStockSharesOutstanding",
        "Label" : "Common Stock Shares (outstanding)",
        "To" : {
          "dei:EntityCommonStockSharesOutstanding": {
            "Name" : "dei:EntityCommonStockSharesOutstanding",
            "Id" : "b8d27670-5caa-411f-8305-860c0613c31f",
            "Order" : 1
          },
          "us-gaap:CommonStockSharesOutstanding" : {
            "Id" : "a91849bd-0aa2-4f1c-8dcb-c85537bf36a8",
            "Name" : "us-gaap:CommonStockSharesOutstanding",
            "Order" : 2
          }
        },
        "Id" : "91b87448-a8dd-4739-9cdf-2cdaef6a4ff6"
      }
    }
return
  {
    replace value of json $conceptMap.LinkRole with $role;
    replace value of json $conceptMap.Trees with {| $conceptMap.Trees, $mappings |};
  }

(: DefinitionModel :)
replace value of json $report.DefinitionModels[1].Breakdowns.y[1].BreakdownTrees[1].LinkRole with $role;

(: remove default_zero rule :)
replace value of json $report.Rules with [ $report.Rules[][$$.Id ne "default_zero"] ];

{ "_id": $id,
  Archive: null,
  Label: "Basic Financial Information",
  Description: $desc,
  Prefix: "fac",
  Role: $role,
  Owner: "charlie@prudena.com",
  LastModified: string(current-dateTime()),
  ACL: [],
  Networks: $report.Networks,
  Hypercubes: $report.Hypercubes,
  DefinitionModels: $report.DefinitionModels,
  Rules: [ for $rule in ($report.Rules[], $additionalRules)
           order by $rule.ComputableConcepts[][1], $rule.Id descending empty least
           return $rule ],
  Filters: {
    cik: [  ],
    tag: [ "DOW30" ],
    fiscalYear : [ 2013 ],
    fiscalPeriod : [ "FY" ],
    sic : [  ]
  }
}


removed hard coded definition models

removed hard coded definition models

jsoniq version "1.0";

declare variable $id := "FundamentalAccountingConcepts";
declare variable $report := find("reports",{ "_id" :  $id });
declare variable $desc :=
  "Documentation about the fundamental accounting concepts defined in this report can be found at http://fundamentalaccountingconcepts.wikispaces.com/home";
declare variable $acl :=
    [
       {
          "Type": "Group",
          "Grantee": "http://28.io/groups/AllUsers",
          "Permission": "READ"
       }
    ];

declare function local:convert($item as item)
{
    typeswitch($item)
    case $object as object return {|
        for $key in keys($object)
        return
            switch($key)
            (:case "To" return { $key : [ (values($object.$key)) ! (local:convert($$)) ] }:)
            case "children" return ()
            case "expanded" return ()
            case "$$hashKey" return ()
            default return { $key : local:convert($object.$key) }
    |}
    case $array as array return [ ($array[]) ! (local:convert($$)) ]
    default return $item
};

if($id eq "FundamentalAccountingConcepts")
then
    {
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."xbrl:Entity" with
            {
              "Name": "xbrl:Entity",
              "Label": "Reporting Entity",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "xbrl:EntityDomain",
                "Label": "Entity Domain",
                "Enumeration": [ "http://www.sec.gov/CIK 0001403161","http://www.sec.gov/CIK 0000004962","http://www.sec.gov/CIK 0000019617","http://www.sec.gov/CIK 0000030554","http://www.sec.gov/CIK 0000034088","http://www.sec.gov/CIK 0000040545","http://www.sec.gov/CIK 0000066740","http://www.sec.gov/CIK 0000078003","http://www.sec.gov/CIK 0000080424","http://www.sec.gov/CIK 0000093410","http://www.sec.gov/CIK 0000101829","http://www.sec.gov/CIK 0000310158","http://www.sec.gov/CIK 0000320187","http://www.sec.gov/CIK 0000354950","http://www.sec.gov/CIK 0000732712","http://www.sec.gov/CIK 0000732717","http://www.sec.gov/CIK 0000789019","http://www.sec.gov/CIK 0000858877","http://www.sec.gov/CIK 0000886982","http://www.sec.gov/CIK 0001001039","http://www.sec.gov/CIK 0000012927","http://www.sec.gov/CIK 0000018230","http://www.sec.gov/CIK 0000021344","http://www.sec.gov/CIK 0000050863","http://www.sec.gov/CIK 0000051143","http://www.sec.gov/CIK 0000063908","http://www.sec.gov/CIK 0000086312","http://www.sec.gov/CIK 0000104169","http://www.sec.gov/CIK 0000200406","http://www.sec.gov/CIK 0000731766" ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalYear" with
            {
              "Name": "sec:FiscalYear",
              "Label": "Fiscal Year",
              "Kind": "TypedDimension",
              "Type": "integer",
              "DomainRestriction": {
                "Name": "sec:FiscalYearDomain",
                "Label": "Fiscal Year Domain",
                "Enumeration": [ 2013 ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalPeriod" with
            {
              "Name": "sec:FiscalPeriod",
              "Label": "Fiscal Period",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "sec:FiscalPeriodDomain",
                "Label": "Fiscal Period Domain",
                "Enumeration": [ "FY" ]
              }
            };
    }
else ();

(: remove archives filter :)
for $arch in $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive"
where exists($arch.DomainRestriction)
return
    replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive" with
    {
        "Name": "sec:Archive",
        "Label": "Archive ID"
    };

for $rule in $report.Rules[]
for $f in $rule.Formulae[]
where $f.Prereq or $f.Body or exists($f.valid) or exists($f.active)
return
    {
        if($f.Prereq)
        then delete json $f.Prereq;
        else ();
        if($f.Body)
        then delete json $f.Body;
        else ();
        if(exists($f.active))
        then delete json $f.active;
        else ();
        if(exists($f.valid))
        then delete json $f.valid;
        else ();
    }

local:convert(
    { "_id": $id,
      Archive: null,
      Label: "Fundamental Accounting Concepts",
      Description: $desc,
      Prefix: "fac",
      Role: "http://xbrl.io/fundamental-accounting-concepts",
      Owner: "admin@28.io",
      ACL: $acl,
      LastModified: string(current-dateTime()),
      Networks: $report.Networks,
      Hypercubes: $report.Hypercubes,
      DefinitionModels: $report.DefinitionModels,
      Rules: $report.Rules,
      Filters: {
        cik: [  ],
        tag: [ "DOW30" ],
        fiscalYear : [ 2013 ],
        fiscalPeriod : [ "FY" ],
        sic : [  ]
      }
    }
)

jsoniq version "1.0";

declare variable $id := "FundamentalAccountingConcepts";
declare variable $report := find("reports",{ "_id" :  $id });
declare variable $desc :=
  "Documentation about the fundamental accounting concepts defined in this report can be found at http://fundamentalaccountingconcepts.wikispaces.com/home";
declare variable $acl :=
    [
       {
          "Type": "Group",
          "Grantee": "http://28.io/groups/AllUsers",
          "Permission": "READ"
       }
    ];
declare variable $def :=
    [ {
        "ModelKind" : "DefinitionModel",
        "Labels" : [ "Fundamental Accounting Concepts" ],
        "Parameters" : {

        },
        "Breakdowns" : {
          "x" : [ {
            "BreakdownLabels" : [ "Reporting Entity Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Reporting Entity [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "xbrl:Entity"
              } ]
            } ]
          }, {
            "BreakdownLabels" : [ "Fiscal Year Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Fiscal Year [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "sec:FiscalYear"
              } ]
            } ]
          }, {
            "BreakdownLabels" : [ "Fiscal Period Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Fiscal Period [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "sec:FiscalPeriod"
              } ]
            } ]
          } ],
          "y" : [ {
            "BreakdownLabels" : [ "Breakdown on concepts" ],
            "BreakdownTrees" : [ {
              "Kind" : "ConceptRelationship",
              "LinkName" : "link:presentationLink",
              "LinkRole" : "http://xbrl.io/fundamental-accounting-concepts",
              "ArcName" : "link:presentationArc",
              "ArcRole" : "http://www.xbrl.org/2003/arcrole/parent-child",
              "RelationshipSource" : "fac:FundamentalAccountingConceptsLineItems",
              "FormulaAxis" : "descendant",
              "Generations" : 0
            } ]
          } ]
        },
        "TableFilters" : {

        }
      }
    ];

declare function local:convert($item as item)
{
    typeswitch($item)
    case $object as object return {|
        for $key in keys($object)
        return
            switch($key)
            (:case "To" return { $key : [ (values($object.$key)) ! (local:convert($$)) ] }:)
            case "children" return ()
            case "expanded" return ()
            case "$$hashKey" return ()
            default return { $key : local:convert($object.$key) }
    |}
    case $array as array return [ ($array[]) ! (local:convert($$)) ]
    default return $item
};

if($id eq "FundamentalAccountingConcepts")
then
    {
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."xbrl:Entity" with
            {
              "Name": "xbrl:Entity",
              "Label": "Reporting Entity",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "xbrl:EntityDomain",
                "Label": "Entity Domain",
                "Enumeration": [ "http://www.sec.gov/CIK 0001403161","http://www.sec.gov/CIK 0000004962","http://www.sec.gov/CIK 0000019617","http://www.sec.gov/CIK 0000030554","http://www.sec.gov/CIK 0000034088","http://www.sec.gov/CIK 0000040545","http://www.sec.gov/CIK 0000066740","http://www.sec.gov/CIK 0000078003","http://www.sec.gov/CIK 0000080424","http://www.sec.gov/CIK 0000093410","http://www.sec.gov/CIK 0000101829","http://www.sec.gov/CIK 0000310158","http://www.sec.gov/CIK 0000320187","http://www.sec.gov/CIK 0000354950","http://www.sec.gov/CIK 0000732712","http://www.sec.gov/CIK 0000732717","http://www.sec.gov/CIK 0000789019","http://www.sec.gov/CIK 0000858877","http://www.sec.gov/CIK 0000886982","http://www.sec.gov/CIK 0001001039","http://www.sec.gov/CIK 0000012927","http://www.sec.gov/CIK 0000018230","http://www.sec.gov/CIK 0000021344","http://www.sec.gov/CIK 0000050863","http://www.sec.gov/CIK 0000051143","http://www.sec.gov/CIK 0000063908","http://www.sec.gov/CIK 0000086312","http://www.sec.gov/CIK 0000104169","http://www.sec.gov/CIK 0000200406","http://www.sec.gov/CIK 0000731766" ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalYear" with
            {
              "Name": "sec:FiscalYear",
              "Label": "Fiscal Year",
              "Kind": "TypedDimension",
              "Type": "integer",
              "DomainRestriction": {
                "Name": "sec:FiscalYearDomain",
                "Label": "Fiscal Year Domain",
                "Enumeration": [ 2013 ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalPeriod" with
            {
              "Name": "sec:FiscalPeriod",
              "Label": "Fiscal Period",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "sec:FiscalPeriodDomain",
                "Label": "Fiscal Period Domain",
                "Enumeration": [ "FY" ]
              }
            };
    }
else ();

(: remove archives filter :)
for $arch in $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive"
where exists($arch.DomainRestriction)
return
    replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive" with
    {
        "Name": "sec:Archive",
        "Label": "Archive ID"
    };

for $rule in $report.Rules[]
for $f in $rule.Formulae[]
where $f.Prereq or $f.Body or exists($f.valid) or exists($f.active)
return
    {
        if($f.Prereq)
        then delete json $f.Prereq;
        else ();
        if($f.Body)
        then delete json $f.Body;
        else ();
        if(exists($f.active))
        then delete json $f.active;
        else ();
        if(exists($f.valid))
        then delete json $f.valid;
        else ();
    }

local:convert(
    { "_id": $id,
      Archive: null,
      Label: "Fundamental Accounting Concepts",
      Description: $desc,
      Prefix: "fac",
      Role: "http://xbrl.io/fundamental-accounting-concepts",
      Owner: "admin@28.io",
      ACL: $acl,
      LastModified: string(current-dateTime()),
      Networks: $report.Networks,
      Hypercubes: $report.Hypercubes,
      DefinitionModels: $def,
      Rules: $report.Rules,
      Filters: {
        cik: [  ],
        tag: [ "DOW30" ],
        fiscalYear : [ 2013 ],
        fiscalPeriod : [ "FY" ],
        sic : [  ]
      }
    }
)