Giter VIP home page Giter VIP logo

ocds-helper's Introduction

ocds-helper v2

This plugin allows access to the properties of an OCDS file (json). It can read:

  • releases,
  • records,
  • release packages,
  • and record packages.

In the case of a release package, it accesses the first one in the array. For the record packages, it can only read the first compiledRelease (for now).

In addition to allowing access to the properties of an ocds, it also allows filtering them. It also generate a series of properties that indicate:

  • the status of the contracting process (planning, tender, award, contract, implementation);
  • the days that have elapsed from the publication date
  • some red flags (if it has a supplier, if it has items, the budget difference between the award and the contract, the number of days to apply to the tender, if it is a competitive process)

It also has a method to access the amounts at each stage of the process.

How to use it

import the plugin:

const readOCDS = require("ocds_helper");

pass the json to the plugin so that it returns an object of type ocds_helper

const helper = readOCDS(someOCDS)

to access the full release, it is through the "data" property

console.log(helper.data);

expected output:

{planning..., tender..., awards..., ...}

to get any value inside the standard file, write a string with the property tree separated by a dot. if the property is inside an array, the helper returns te value for each element of the array (like the description in awards) or the value if it's from a single node. If the function don't find any value, it returns null

example 1: get a property within a collection of objects

helper.getData("awards.description")

expected output:

["description 1", "description 2"]

example 2: get a nested property outside of an array

helper.getData("planning.budget.amount")

expected output:

{amount: 123, currency : "MXN"}

example 3: get a property that is not defined

helper.getData("planning.budget.amount.bananas")

expected output:

null

get the amounts

To obtain the amount of a contracting process in its current state (contract, award, etc ...), the "amount" property can be consulted.

This will return an object with the source of the amount, and an array of amounts, where each element represents a currency. If all the elements to be added are in the same currency, this array will only contain one element.

example

console.log(helper.amount);

expected output:

{
  "source": "contract",
  "data": [
    {
      "currency": "COP",
      "amount": 12326533
    }
  ]
}

If you want the amount of another stage, you have to use the "getStateAmount" method, and pass the name of the state from which you want to obtain the information. The possible states are inside helper.constants.states and are as follows:

  • PLANNING
  • TENDER
  • AWARD
  • CONTRACT
  • IMPLEMENTATION

example

helper.getStateAmount(helper.constants.states.PLANNING)

expected output:

{
  "source": "planning",
  "data": [
    {
      "currency": "COP",
      "amount": 12326533
    }
  ]
}

precalculated properties

type: the ocsd file type

helper.type

expected output:

"release"

daysDiff: the days that have passed since the publication of the ocds

helper.daysDiff

expected output:

1046

state: the state of the contracting process

helper.type

expected output:

"contract"

red flags

To calculate the red flags, you need to call the methods inside "indices".

hasSupplier: if it has a supplier

helper.indices.hasSupplier()

expected output:

true

hasItems: if it has items

helper.indices.hasItems()

expected output:

false

awardContractDiff: the budget difference between the award and the contract

helper.indices.awardContractDiff()

expected output:

0

tenderPeriodDays: the number of days to apply to the tender

helper.indices.awardContractDiff()

expected output:

0

isCompetitive: if it is a competitive process

helper.indices.isCompetitive()

expected output:

true

filter the properties

It is possible to filter the elements of an array if they meet a condition. If the elements of the array are also arrays, you must pass an object with the following properties:

{
  type : 'contains',
  field : 'the-name-of-the-property-to-validate',
  value : 'the-value-to-find-inside-the-field'
}

example: get the suppliers inside the parties array.

First, it must target the "parties" array, and then, search every party inside the roles array for the value "supplier"

helper.getData("parties", {type : "contains", field : "roles", value : "supplier"}) 

expected output:

[
  {
    "name": "El Mundo es Tuyo, S.A. de C.V.",
    "id": "MX-RFC-MET8908305M9",
    "identifier": {
      "scheme": "MX-RFC",
      "id": "MET8908305M9",
      "legalName": "El Mundo es Tuyo, S.A. de C.V.",
      "juridicalPersonhood": "legalPerson"
    },
    "address": {
      "streetAddress": "Diagonal San Antonio 1216",
      "locality": "Benito Juarez",
      "region": "Ciudad de México",
      "postalCode": "03020",
      "countryName": "México"
    },
    "contactPoint": {
      "name": "Marco Antonio Cárdenas López",
      "email": "[email protected]",
      "telephone": "56396464",
      "faxNumber": "56398192",
      "url": "http://www.elmundoestuyo.com.mx/",
      "givenName": "Marco Antonio Cárdenas López"
    },
    "roles": [
      "supplier",
      "tenderer",
      "payee",
      "invitedSupplier"
    ]
  }
]

ocds-helper's People

Contributors

elcoruco avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.