{
  "resourceType": "Bundle",
  "identifier": {
    "system": "http://www.saude.gov.br/fhir/r4/NamingSystem/BRRNDS-41484",
    "value": String(item.identifier_value)
  },
  "type": "document",
  "timestamp": new Date().toISOString(),
  "entry": [
    {
      "fullUrl": "urn:uuid:transient-0",
      "resource": {
        "resourceType": "Composition",
        "meta": {
          "profile": [
            "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRRegulacaoAssistencial"
          ]
        },
        "status": "final",
        "type": {
          "coding": [
            {
              "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRTipoDocumento",
              "code": "RA"
            }
          ]
        },
        "category": [
          {
            "coding": [
              {
                "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRModalidadeAssistencial",
                "code": "09"
              }
            ]
          }
        ],
        "subject": {
          "identifier": {
            "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRIndividuo-1.0",
            "value": String(item.cpf_paciente || item.cns_paciente)
          }
        },
        "date": String(item.data_registro_fim),
        "author": [
          {
            "identifier": {
              "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BREstabelecimentoSaude-1.0",
              "value": String(item.cnes_estabelecimento || '6479286')
            }
          }
        ],
        "title": "Regulação Assistencial",
        "event": [
          {
            "code": [
              {
                "coding": [
                  {
                    "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRStatusRegulacaoAssistencial",
                    "code": "pending"
                  }
                ]
              }
            ],
            "period": {
              "end": String(item.data_registro_fim)
            },
            "detail": [
              {
                "identifier": {
                  "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BREstabelecimentoSaude-1.0",
                  "value": String(item.cnes_estabelecimento || '6479286')
                }
              },
              {
                "reference": "urn:uuid:transient-2"
              }
            ]
          }
        ],
        "section": [
          {
            "entry": [
              {
                "reference": "urn:uuid:transient-1"
              }
            ]
          }
        ]
      }
    },
    {
      "fullUrl": "urn:uuid:transient-1",
      "resource": {
        "resourceType": "Appointment",
        "meta": {
          "profile": [
            "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRAgendamentoRegulacaoAssistencial"
          ]
        },
        "status": "booked",
        "serviceCategory": [
          {
            "coding": [
              {
                "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRModalidadeAssistencial",
                "code": "09"
              }
            ]
          }
        ],
        "serviceType": [
          {
            "coding": [
              {
                "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRTabelaSUS",
                "code": String(item.codigo_sus)
              }
            ]
          }
        ],
        "specialty": [
          {
            "coding": [
              {
                "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRCBO",
                "code": String(item.codigo_cbo || '225133')
              }
            ]
          }
        ],
        "appointmentType": {
          "coding": [
            {
              "system": "http://hl7.org/fhir/request-priority",
              "code": String(item.id_rnds)
            }
          ]
        },
        "reasonReference": [
          {
            "reference": "urn:uuid:transient-3"
          }
        ],
        "start": String(item.data_registro_criado),
        "end": String(item.data_registro_fim),
        "created": String(item.data_registro_criado),
        "basedOn": [
          {
            "reference": "urn:uuid:transient-2"
          }
        ],
        "participant": [
          {
            "type": [
              {
                "coding": [
                  {
                    "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRTipoParticipante",
                    "code": "PCT"
                  }
                ]
              }
            ],
            "actor": {
              "identifier": {
                "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRIndividuo-1.0",
                "value": String(item.cpf_paciente|| item.cns_paciente)
              }
            },
            "status": "accepted"
          }
        ]
      }
    },
    {
      "fullUrl": "urn:uuid:transient-2",
      "resource": {
        "resourceType": "ServiceRequest",
        "meta": {
          "profile": [
            "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRRequisicaoRegulacaoAssistencial"
          ]
        },
        "status": "active",
        "intent": "proposal",
        "category": [
          {
            "coding": [
              {
                "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRModalidadeAssistencial",
                "code": "09"
              }
            ]
          }
        ],
        "priority": "routine",
        "code": {
          "coding": [
            {
              "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRTabelaSUS",
              "code": String(item.codigo_sus)
            }
          ]
        },
        "subject": {
          "identifier": {
            "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRIndividuo-1.0",
            "value": String(item.cpf_paciente|| item.cns_paciente)
          }
        },
        "authoredOn": String(item.data_registro_criado),
        "requester": {
          "identifier": {
            "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BREstabelecimentoSaude-1.0",
            "value": String(item.cnes_estabelecimento || '6479286')
          }
        },
        "performerType": {
          "coding": [
            {
              "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRCBO",
              "code": String(item.codigo_cbo || '225125')
            }
          ]
        },
        "reasonReference": [
          {
            "reference": "urn:uuid:transient-3"
          }
        ]
      }
    },
    {
      "fullUrl": "urn:uuid:transient-3",
      "resource": {
        "resourceType": "Condition",
        "meta": {
          "profile": [
            "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRCID10Avaliado-1.0"
          ]
        },
        "code": {
          "coding": [
            {
              "system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRCID10",
              "code": String(item.CID)
            }
          ]
        },
        "subject": {
          "identifier": {
            "system": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRIndividuo-1.0",
            "value": String(item.cpf_paciente || item.cns_paciente)
          }
        },
        "note": [
          {
            "text": String(item.observacao_agendamento)
          }
        ]
      }
    }
  ]
}