Skip to content

Commit

Permalink
fix(Crossref): Add DOI and URL as encode options
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Nov 19, 2020
1 parent ff6ff74 commit 535e2c4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<p>Endometriosis is a chronic painful disease highly prevalent in women that is defined by growth of endometrial tissue outside the uterine cavity and lacks adequate treatment. Medical use of cannabis derivatives is a current hot topic and it is unknown whether phytocannabinoids may modify endometriosis symptoms and development. Here we evaluate the effects of repeated exposure to Δ9-tetrahydrocannabinol (THC) in a mouse model of surgically-induced endometriosis. In this model, female mice develop mechanical hypersensitivity in the caudal abdomen, mild anxiety-like behavior and substantial memory deficits associated with the presence of extrauterine endometrial cysts. Interestingly, daily treatments with THC (2 mg/kg) alleviate mechanical hypersensitivity and pain unpleasantness, modify uterine innervation and restore cognitive function without altering the anxiogenic phenotype. Strikingly, THC also inhibits the development of endometrial cysts. These data highlight the interest of scheduled clinical trials designed to investigate possible benefits of THC for women with endometriosis.</p>
</abstract>
<doi_data>
<doi>10.47704/1</doi>
<doi>10.5555/12345</doi>
<resource>https://example.org</resource>
</doi_data>
</posted_content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</related_item>
</program>
<doi_data>
<doi>10.47704/1</doi>
<doi>10.5555/12345</doi>
<resource>https://example.org</resource>
</doi_data>
</peer_review>
Expand Down
18 changes: 12 additions & 6 deletions src/codecs/crossref/crossref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ describe('decode', () => {

describe('encode', () => {
test('eLife article', async () => {
expect(await crossref.dump(elife50356)).toMatchFile(
snapshot('article-elife-50356.xml')
)
expect(
await crossref.dump(elife50356, {
doi: '10.5555/12345',
url: 'https://example.org',
})
).toMatchFile(snapshot('article-elife-50356.xml'))
})

test('review of eLife article', async () => {
Expand All @@ -47,8 +50,11 @@ describe('encode', () => {
datePublished: '2020-11-12',
itemReviewed: elife50356,
}
expect(await crossref.dump(review)).toMatchFile(
snapshot('review-elife-50356.xml')
)
expect(
await crossref.dump(review, {
doi: '10.5555/12345',
url: 'https://example.org',
})
).toMatchFile(snapshot('review-elife-50356.xml'))
})
})
32 changes: 26 additions & 6 deletions src/codecs/crossref/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as http from '../../util/http'
import * as vfile from '../../util/vfile'
import * as xml from '../../util/xml'
import { decodeCsl } from '../csl'
import { Codec } from '../types'
import { Codec, CommonEncodeOptions } from '../types'
import { getLogger } from '@stencila/logga'
import { TxtCodec } from '../txt'
import { encodeAbstract } from '../jats'
Expand All @@ -22,6 +22,18 @@ interface Review extends schema.CreativeWork {

type ContributorRole = 'author' | 'reviewer'

interface EncodeOptions extends CommonEncodeOptions {
/**
* The DOI for the node
*/
doi?: string

/**
* The URL for the node
*/
url?: string
}

const log = getLogger('encoda:crossref')

export class CrossrefCodec extends Codec implements Codec {
Expand Down Expand Up @@ -69,17 +81,25 @@ export class CrossrefCodec extends Codec implements Codec {
* See https://www.crossref.org/education/content-registration/crossrefs-metadata-deposit-schema/crossref-xsd-schema-quick-reference/
* Generated XML can be validated via https://www.crossref.org/02publishers/parser.html
*/
public readonly encode = (node: schema.Node): Promise<vfile.VFile> => {
public readonly encode = (
node: schema.Node,
options: EncodeOptions = this.commonEncodeDefaults
): Promise<vfile.VFile> => {
// The following "options" are actually required so throw an error
// if not supplied
const { doi, url } = options
if (doi === undefined) throw new Error(`The "doi" parameter is required.`)
if (url === undefined) throw new Error(`The "url" parameter is required.`)

// These constant may be added to options later.
const {
doi = '10.47704/1',
url = 'https://example.org',
depositorName = 'Stencila',
depositorEmail = '[email protected]',
registrantName = 'Stencila',
version = '4.4.2',
} = {}

const version = '4.4.2'

// The root XMl document to create
const doc = {
declaration: {
attributes: {
Expand Down

0 comments on commit 535e2c4

Please sign in to comment.