Skip to content

Commit

Permalink
Merge pull request #3 from HDRUK/feature/GAT-2765-logic
Browse files Browse the repository at this point in the history
simplifies and returns list where a list should be returned, and data…
  • Loading branch information
loki-sinclair-hdruk authored Dec 12, 2023
2 parents 1a52207 + 0829fb0 commit ce4b634
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules

/dist

.env

package-lock.json
Expand Down
1 change: 0 additions & 1 deletion files/2.json

This file was deleted.

93 changes: 93 additions & 0 deletions files/dataset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"@schema": "https://raw.githubusercontent.com/HDRUK/schemata/master/schema/dataset/2.1.0/dataset.schema.json",
"identifier": "e96e36ba-30ca-4c25-bc55-fab02d72a51c",
"version": "1.0.0",
"issued": "2021-08-30T21:00:00+00:00",
"modified": "2021-08-30T21:00:00+00:00",
"revisions": [],
"summary": {
"title": "Bones Dataset",
"abstract": "Test description",
"publisher": {
"identifier": "http://bones.com",
"name": "Bones",
"logo": "http://example.com",
"description": "A publisher",
"contactPoint": [],
"memberOf": "ALLIANCE",
"accessRights": [],
"accessService": "Many many options",
"accessRequestCost": "Thousands of pounds"
},
"contactPoint": "[email protected]",
"keywords": [
"bones",
"Blood"
],
"doiName": "10.1093/ajae/aaq063"
},
"coverage": {
"spatial": [],
"typicalAgeRange": "25-80"
},
"provenance": {
"origin": {
"purpose": "COVID-19",
"source": "Routine Surveilance"
},
"temporal": {
"accrualPeriodicity": "IRREGULAR",
"distributionReleaseDate": "2021-08-30T21:00:00+00:00",
"startDate": "2021-08-10T21:00:00+00:00",
"endDate": "2021-08-30T21:00:00+00:00",
"timeLag": "1-2 WEEKS"
}
},
"accessibility": {
"usage": {
"dataUseRequirements": "none",
"resourceCreator": "Someone",
"investigations": [],
"isReferencedBy": []
},
"access": {
"accessRights": [
"http://test.bones.com"
],
"accessService": "Many many options",
"accessRequestCost": "Thousands",
"jurisdiction": [
"GB-NIR"
],
"dataProcessor": "Some guy somewhere",
"dataController": "This is the data controller"
},
"formatAndStandards": {
"vocabularyEncodingScheme": [
"OPCS4"
],
"conformsTo": [
"HL7 CDA"
],
"language": [
"en"
],
"format": [
"audio"
]
}
},
"enrichmentAndLinkage": {
"qualifiedRelation": [],
"derivation": [],
"tools": []
},
"observations": [
{
"observedNode": "PERSONS",
"measuredValue": 3,
"observationDate": "2021-08-10T21:00:00+00:00",
"measuredProperty": "Count"
}
]
}
22 changes: 22 additions & 0 deletions files/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"items": [
{
"name": "HDRUK Simulation Test Server 1",
"@schema": "https://raw.githubusercontent.com/HDRUK/schemata/master/schema/dataset/2.1.0/dataset.schema.json",
"description": "Sample description here",
"type": "dataset",
"persistentId": "e96e36ba-30ca-4c25-bc55-fab02d72a51c",
"self": "https://fair.preview.aridhia.io/api/datasets/e96e36ba-30ca-4c25-bc55-fab02d72a51c",
"version": "0.0.0",
"issued": "2023-02-13T14:10:31.640Z",
"modified": "2023-09-04T10:53:01.239Z",
"source": "HDRUK"
}
],
"query": {
"q": "",
"total": 1,
"limit": 0,
"offset": 0
}
}
77 changes: 18 additions & 59 deletions src/api/v1/services/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,25 @@ import fs from 'fs';

export default class DatasetService {
public async getDatasets(q: string, offset: number, limit: number): Promise<dataset[]> {
// The files directory contains a set of example JSON files
const files = fs.readdirSync("./files");
let datasets = [];

for (let i = 0; i < files.length; i++)
{
const file = fs.readFileSync("./files/" + files[i], 'utf-8');
const parsedJSON = JSON.parse(file);
const datasetData = {
persistentId : parsedJSON.identifier,
"@schema" : parsedJSON["@schema"],
version : parsedJSON.version,
issued : parsedJSON.issued,
modified : parsedJSON.modified,
name : parsedJSON.summary.title,
description : parsedJSON.summary.abstract,
type : "dataset",
source : parsedJSON.summary.publisher.name,
self : "http://example-url.com/api/datasets/" + parsedJSON.identifier
}

// If the search query isn't blank
if (q !== '')
{
// If the query can be found in the description
if (parsedJSON.summary.abstract.search(q) !== -1)
{
datasets.push(datasetData);
}
}
else
{
datasets.push(datasetData);
}
const file = fs.readFileSync("./files/list.json", 'utf-8');
const parsedJSON = JSON.parse(file);
const datasetData = {
persistentId : parsedJSON.identifier,
"@schema" : parsedJSON["@schema"],
version : parsedJSON.version,
issued : parsedJSON.issued,
modified : parsedJSON.modified,
name : parsedJSON.summary.title,
description : parsedJSON.summary.abstract,
type : "dataset",
source : parsedJSON.summary.publisher.name,
self : "http://example-url.com/api/datasets/" + parsedJSON.identifier
}

datasets.push(datasetData);

// Check the offset is valid
if (offset < datasets.length)
{
Expand All @@ -54,34 +37,10 @@ export default class DatasetService {
}

public async getDataset(pid: string) {
const file = fs.readFileSync("./files/dataset.json", 'utf-8');
const parsedJSON = JSON.parse(file);

// The files directory contains a set of example JSON files
const files = fs.readdirSync("./files");

for (let i = 0; i < files.length; i++)
{
const file = fs.readFileSync("./files/" + files[i], 'utf-8');
const parsedJSON = JSON.parse(file);

// This is the dataset the user is looking for
if (parsedJSON.identifier === pid)
{
return {
persistentId : parsedJSON.identifier,
"@schema" : parsedJSON["@schema"],
version : parsedJSON.version,
issued : parsedJSON.issued,
modified : parsedJSON.modified,
name : parsedJSON.summary.title,
description : parsedJSON.summary.abstract,
type : "dataset",
source : parsedJSON.summary.publisher.name,
self : "http://example-url.com/api/datasets/" + parsedJSON.identifier
}
}

}
return;
return parsedJSON;
}

public async getDatasetCount() {
Expand Down

0 comments on commit ce4b634

Please sign in to comment.