From 7abc40baaa67e9b0b1fda9b34d5fdbee0720a76e Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Thu, 15 Jun 2023 17:21:03 +0200 Subject: [PATCH 1/6] Adding shipment doc --- documentation/docs/developments.md | 6 +----- documentation/docs/index.md | 4 ++-- documentation/docs/installation.md | 7 ++++--- documentation/mkdocs.yml | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/documentation/docs/developments.md b/documentation/docs/developments.md index 7d569193..9448cddd 100644 --- a/documentation/docs/developments.md +++ b/documentation/docs/developments.md @@ -48,11 +48,7 @@ npm test -- --grep "logbook/:sessionId/investigation/id/:investigationId/tag" NYC (successor of [Instambul](https://github.com/istanbuljs/nyc)) is used for coverage support and a report is generated when it is run. -- Report is generated on public/coverage then accessible from: `http(s)://{server}/coverage` - -Example: `https://icatplus.esrf.fr/coverage` - -The coverage report from the main branch is also available from [here](https://icat.gitlab-pages.esrf.fr/icat-plus/coverage/). +The coverage report from the main branch is available from [here](https://icat.gitlab-pages.esrf.fr/icat-plus/coverage/). - In order to run the coverage tool and update the report run: diff --git a/documentation/docs/index.md b/documentation/docs/index.md index 48b310df..42b9a9f4 100644 --- a/documentation/docs/index.md +++ b/documentation/docs/index.md @@ -1,8 +1,8 @@ # ICAT+ -ICAT+ is a NodeJS package that exposes a RestFul API and uses a MongoDB database. It allows: +ICAT+ is a NodeJS application that exposes a RestFul API and uses a MongoDB database. It allows: -- Linking a logbook to an existing investigation. +- Logbook: Register and read events from the e-logbook database. - Sample tracking - Managing external resources such as images or any file. - Controlled access to the resources by using a Metadata Catalogue (currently [ICAT](https://icatproject.org/)) diff --git a/documentation/docs/installation.md b/documentation/docs/installation.md index b7e64db5..375b4e9a 100644 --- a/documentation/docs/installation.md +++ b/documentation/docs/installation.md @@ -1,13 +1,14 @@ # Installation -1. Download the source code from github repository -2. Install dependencies +## Download the source code from github repository + +## Install dependencies ```bash npm install ``` -3. A MongoDB instance is required. The following command will download and install a docker image containing mongoDB database. Then it will start a mongoDB instance listening at port 27017. +## A MongoDB instance is required. The following command will download and install a docker image containing mongoDB database. Then it will start a mongoDB instance listening at port 27017. ```bash docker run -p 27017:27017 mongo diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index 52db273d..4efb476e 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -12,3 +12,4 @@ nav: - API: api.md - Elastic Search: elasticsearch.md - Logbook: logbook.md + - Sample tracking and sample preparation: tracking.md -- GitLab From 51473765231fa1655f8dc021f3718ccf4e60b1ce Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Fri, 16 Jun 2023 09:08:52 +0200 Subject: [PATCH 2/6] Adding documentation --- documentation/docs/tracking.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 documentation/docs/tracking.md diff --git a/documentation/docs/tracking.md b/documentation/docs/tracking.md new file mode 100644 index 00000000..df35ddb0 --- /dev/null +++ b/documentation/docs/tracking.md @@ -0,0 +1,16 @@ +# Sample tracking and experiment preparation + +## Shipment + +Any participant of an investigation can create a shipment. A shipment is needed when samples are sent to the facility and it is linked to a **scheduled investigation**. It is specially important to track parcels and sample on-site. + +A shipment is mainly composed by: + +- Sender and return addresses. These are default addresses that they can be overrided for each aprcel +- A list of parcels: a parcel is the "thing" that will be sent by courier and has a status that allows determine in which stage (or place) the parcel is. A label containing a Qr code can be printed from the application and which identifies phisically a parcel. + +Shipments are persisted in a MongoDB database. The full scheme description can be found here: [schema](https://gitlab.esrf.fr/icat/icat-plus/-/blob/master/app/models/shipment.model.js) + +## Parcel and items + +A parcel is a "box" which is sent to the facility with the samples and tools needed to perform the experiment. A parcel has one status depending on which stage the parcel is and it is described [here](https://confluence.esrf.fr/pages/viewpage.action?spaceKey=PROJSAMPLETRACKING&title=Parcel+status+diagram) -- GitLab From 2af76701620eba0054dcb7522aec037b716987b8 Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Mon, 19 Jun 2023 10:42:19 +0200 Subject: [PATCH 3/6] Adding item documentation --- documentation/docs/tracking.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/documentation/docs/tracking.md b/documentation/docs/tracking.md index df35ddb0..41ece746 100644 --- a/documentation/docs/tracking.md +++ b/documentation/docs/tracking.md @@ -11,6 +11,12 @@ A shipment is mainly composed by: Shipments are persisted in a MongoDB database. The full scheme description can be found here: [schema](https://gitlab.esrf.fr/icat/icat-plus/-/blob/master/app/models/shipment.model.js) -## Parcel and items +## Parcel A parcel is a "box" which is sent to the facility with the samples and tools needed to perform the experiment. A parcel has one status depending on which stage the parcel is and it is described [here](https://confluence.esrf.fr/pages/viewpage.action?spaceKey=PROJSAMPLETRACKING&title=Parcel+status+diagram) + +## Items + +The content of a parcel is filled by items. An item can be: + +1. -- GitLab From 280dfde3991fbc67336a46c5a109b0d08c5ade2b Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Mon, 19 Jun 2023 17:01:34 +0200 Subject: [PATCH 4/6] Improved comments --- app/routes/address.routes.js | 4 ++-- app/routes/parcel.routes.js | 4 ++-- test.ipynb | 0 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 test.ipynb diff --git a/app/routes/address.routes.js b/app/routes/address.routes.js index def65514..509522bc 100644 --- a/app/routes/address.routes.js +++ b/app/routes/address.routes.js @@ -35,8 +35,8 @@ module.exports = (app) => { * @swagger * /tracking/{sessionId}/address: * get: - * summary: Returns a list of addresses associated to an investigation - * description : Return a list of address associated to an investigation. The requester should be a participant, instrument scientists or manager. + * summary: Returns all addresses associated to an user + * description : Return a list of address associated to an user. The requester should be a participant, instrument scientists or manager. * parameters: * - $ref: '#/components/parameters/sessionId' * responses: diff --git a/app/routes/parcel.routes.js b/app/routes/parcel.routes.js index a329f4f8..ffd3b5f6 100644 --- a/app/routes/parcel.routes.js +++ b/app/routes/parcel.routes.js @@ -43,8 +43,8 @@ module.exports = (app) => { * @swagger * /tracking/{sessionId}/setup: * get: - * summary: Returns the setup allowed for sample tracking - * description : Returns the containers, experiment and processing plan allowed for each investigation + * summary: Returns the the list of container types and parameters allowed to define experiment and processing plans + * description : Given an investigationId it returns the whole container type, experiment and processing plan configuration. This configuration depends on the investigation (and more precisely the instrument where the experiment is carried out) * parameters: * - $ref: '#/components/parameters/queryInvestigationId' * - $ref: '#/components/parameters/sessionId' diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 00000000..e69de29b -- GitLab From 61f0ed45f8d51e9eb1f188f6a915362e44573bd7 Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Tue, 20 Jun 2023 10:54:32 +0200 Subject: [PATCH 5/6] Added documentaiton --- app/models/item.model.js | 1 + documentation/docs/tracking.md | 402 +++++++++++++++++++- documentation/shipment.ipynb | 658 +++++++++++++++++++++++++++++++++ 3 files changed, 1057 insertions(+), 4 deletions(-) create mode 100644 documentation/shipment.ipynb diff --git a/app/models/item.model.js b/app/models/item.model.js index f3bac027..c3564dd2 100644 --- a/app/models/item.model.js +++ b/app/models/item.model.js @@ -30,6 +30,7 @@ const ItemSchema = mongoose.Schema( enum: ["SAMPLESHEET", "TOOL", "OTHER", "CONTAINER"], }, containerType: { type: ContainerType, required: isContainer }, + sampleContainerPosition: { type: String }, content: [this], experimentPlan: [ParameterType], processingPlan: [ParameterType], diff --git a/documentation/docs/tracking.md b/documentation/docs/tracking.md index 41ece746..cfdf61a5 100644 --- a/documentation/docs/tracking.md +++ b/documentation/docs/tracking.md @@ -1,6 +1,8 @@ # Sample tracking and experiment preparation -## Shipment +## Entities + +### Shipment Any participant of an investigation can create a shipment. A shipment is needed when samples are sent to the facility and it is linked to a **scheduled investigation**. It is specially important to track parcels and sample on-site. @@ -11,12 +13,404 @@ A shipment is mainly composed by: Shipments are persisted in a MongoDB database. The full scheme description can be found here: [schema](https://gitlab.esrf.fr/icat/icat-plus/-/blob/master/app/models/shipment.model.js) -## Parcel +### Parcel A parcel is a "box" which is sent to the facility with the samples and tools needed to perform the experiment. A parcel has one status depending on which stage the parcel is and it is described [here](https://confluence.esrf.fr/pages/viewpage.action?spaceKey=PROJSAMPLETRACKING&title=Parcel+status+diagram) -## Items +### Items The content of a parcel is filled by items. An item can be: -1. +1. Tool +2. Sample linked to a sample sheet +3. Container +4. Other + +## Tutorial + +# Creation of a shipment and a parcel + +This notebook shows how to create addresses, shipment and a parcel from an existing investigation. It uses the ICAT+ API and needs to have a existing user with permissions to such investigation + +```python +import requests +import json +``` + +## Configuration + +As mentioned it needs a running instance of ICAT+, a valid user credentials and an existing investigation. + +```python +#icatplus_server = "http://dau-dm-03:8000" +icatplus_server = "http://lalex.esrf.fr:8000" +credential = { + "plugin": "db", + "username": "admin", + "password": "test_admin" +} +investigationId = 124564607 + +``` + +## Login + +This logs into ICAT in order to get the token that is called `sessionId`. The `sessionId` expires depending of the ICAT configuration and it is returned in the variable `lefeTimeMinutes` + +```python +session = requests.post(icatplus_server + "/session", data = credential) +session = json.loads(session.text) +sessionId = session["sessionId"] +``` + +```python +print(session) +``` + + {'name': 'admin', 'username': 'admin', 'fullName': 'adminFullName', 'lifeTimeMinutes': 719.9995333333334, 'isAdministrator': True, 'isInstrumentScientist': False, 'isMinter': False, 'sessionId': '8d4728d0-e84d-40fb-b6d2-543e296ba194', 'usersByPrefix': []} + +## Get Investigation + +```python +url = (f'{icatplus_server}/catalogue/{sessionId}/investigation?ids={investigationId}') +print(url) +``` + + http://lalex.esrf.fr:8000/catalogue/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation?ids=124564607 + +```python +investigation = requests.get(f'{url}') +``` + +```python +print(json.dumps(json.loads(investigation.text), indent=2)) +``` + + [ + { + "name": "ID002306", + "startDate": "2023-06-19T13:28:44.492+02:00", + "id": 124564607, + "title": "ID002306", + "visitId": "id00", + "parameters": { + "__datasetCount": "6", + "__sampleCount": "2", + "__fileCount": "0", + "__volume": "0", + "__elapsedTime": "0", + "__acquisitionDatasetCount": "4", + "__processedDatasetCount": "2", + "__acquisitionFileCount": "0", + "__processedFileCount": "0", + "__acquisitionVolume": "0", + "__processedVolume": "0" + }, + "instrument": { + "name": "ID00", + "id": 92177647 + }, + "investigationUsers": [], + "meta": { + "page": { + "totalWithoutFilters": 1, + "total": 1, + "totalPages": 1, + "currentPage": 1 + } + }, + "type": { + "id": 325, + "createId": "root", + "createTime": "2014-06-18T15:00:43.500+02:00", + "modId": "root", + "modTime": "2014-06-18T15:00:43.500+02:00", + "description": "Test investigation", + "investigations": [], + "name": "TEST" + } + } + ] + +## Shipment and addresses + +### List Shipment + +```python +url_shipment = f'{icatplus_server}/tracking/{sessionId}/investigation/id/{investigationId}/shipment' +print(url_shipment) +``` + + http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation/id/124564607/shipment + +```python +shipment = requests.get(f'{url_shipment}') +``` + +```python +print(json.dumps(json.loads(shipment.text), indent=2)) +``` + + [] + +## List addresses + +```python +url_address = f'{icatplus_server}/tracking/{sessionId}/investigation/id/{investigationId}/address' +print(url_address) +``` + + http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation/id/124564607/address + +```python +addresses = requests.get(f'{url_address}') +print(addresses.text) +``` + + [] + +## Create address + +```python +address = { + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584" +} + +``` + +```python +address = requests.post(f'{url_address}', data=address) +print(json.dumps(json.loads(address.text), indent=2)) +``` + + { + "status": "ACTIVE", + "_id": "649168052e95f7e77d8c8cae", + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584", + "investigationName": "ID002306", + "createdBy": "admin", + "investigationId": 124564607, + "createdAt": "2023-06-20T08:49:09.978Z", + "updatedAt": "2023-06-20T08:49:09.978Z", + "__v": 0 + } + +## Create shipment + +```python +shipment = { + "name": "my new Shipment", + "investigationId":investigationId, + "defaultReturnAddress": json.loads(address.text)["_id"], + "defaultShippingAddress": json.loads(address.text)["_id"] +} +``` + +```python +shipment = requests.post(f'{url_shipment}', data=shipment) +print(json.dumps(json.loads(shipment.text), indent=2)) +``` + + { + "status": "OPENED", + "parcels": [], + "_id": "649168062e95f7e77d8c8caf", + "name": "my new Shipment", + "investigationId": 124564607, + "defaultReturnAddress": { + "status": "ACTIVE", + "_id": "649168052e95f7e77d8c8cae", + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584", + "investigationName": "ID002306", + "createdBy": "admin", + "investigationId": 124564607, + "createdAt": "2023-06-20T08:49:09.978Z", + "updatedAt": "2023-06-20T08:49:09.978Z", + "__v": 0 + }, + "defaultShippingAddress": { + "status": "ACTIVE", + "_id": "649168052e95f7e77d8c8cae", + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584", + "investigationName": "ID002306", + "createdBy": "admin", + "investigationId": 124564607, + "createdAt": "2023-06-20T08:49:09.978Z", + "updatedAt": "2023-06-20T08:49:09.978Z", + "__v": 0 + }, + "investigationName": "ID002306", + "createdAt": "2023-06-20T08:49:10.054Z", + "updatedAt": "2023-06-20T08:49:10.054Z", + "__v": 0 + } + +```python +shipment = requests.get(f'{url_shipment}') +shipmentId = json.loads(shipment.text)[0]["_id"] +print(json.dumps(json.loads(shipment.text), indent=2)) +``` + + [ + { + "status": "OPENED", + "parcels": [], + "_id": "649168062e95f7e77d8c8caf", + "name": "my new Shipment", + "investigationId": 124564607, + "defaultReturnAddress": { + "status": "ACTIVE", + "_id": "649168052e95f7e77d8c8cae", + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584", + "investigationName": "ID002306", + "createdBy": "admin", + "investigationId": 124564607, + "createdAt": "2023-06-20T08:49:09.978Z", + "updatedAt": "2023-06-20T08:49:09.978Z", + "__v": 0 + }, + "defaultShippingAddress": { + "status": "ACTIVE", + "_id": "649168052e95f7e77d8c8cae", + "name": "Name", + "surname": "Surname", + "companyName": "My Company", + "address": "Rue Victor Hugo", + "city": "Grenoble", + "region": "Isere", + "postalCode": "38000", + "country": "France", + "email": "myemail@email.com", + "phoneNumber": "065222584", + "investigationName": "ID002306", + "createdBy": "admin", + "investigationId": 124564607, + "createdAt": "2023-06-20T08:49:09.978Z", + "updatedAt": "2023-06-20T08:49:09.978Z", + "__v": 0 + }, + "investigationName": "ID002306", + "createdAt": "2023-06-20T08:49:10.054Z", + "updatedAt": "2023-06-20T08:49:10.054Z", + "__v": 0 + } + ] + +## Create parcels + +```python +url_parcel = f'{icatplus_server}/tracking/{sessionId}/parcel?investigationId={investigationId}&shipmentId={shipmentId}' +print(url_parcel) +``` + + http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/parcel?investigationId=124564607&shipmentId=649168062e95f7e77d8c8caf + +```python +content = [ + { + "name": "My Container", + "type": "CONTAINER", + "containerType": { + "containerName": "SPINEPUCK", + "capacity": 10, + }, + "content": [ + { + "type": "TOOL", + "name": "A tool within a container", + }, + ], + }, + ] +parcel = { + "name": "Parcel created by investigation user", + "description": "This parcel has been automatically generated by the unit tests", + "shipmentId" : shipmentId, + "comment": "This is the comment", + "storageConditions": "Fridge", + "content": [ + { + "name": "My Container", + "type": "CONTAINER", + "containerType": { + "containerName": "SPINEPUCK", + "capacity": 10, + }, + "content": [ + { + "type": "TOOL", + "name": "A tool within a container", + }, + ], + }, + ] + } +``` + +```python +parcelResponse = requests.put(f'{url_parcel}', json=(parcel)) +print(parcelResponse) +``` + + <Response [200]> + +```python +print(requests.get(f'{url_parcel}').text) +``` + + [{"type":"DEFAULT","localContactNames":[],"items":[],"_id":"649168062e95f7e77d8c8cb4","name":"Parcel created by investigation user","description":"This parcel has been automatically generated by the unit tests","shipmentId":"649168062e95f7e77d8c8caf","storageConditions":"Fridge","content":[{"content":[{"type":"TOOL","name":"A tool within a container"}],"experimentPlan":[],"processingPlan":[],"_id":"649168062e95f7e77d8c8cb5","name":"My Container","type":"CONTAINER","containerType":{"_id":"649168062e95f7e77d8c8cb6","containerName":"SPINEPUCK","capacity":10,"id":"649168062e95f7e77d8c8cb6"},"createdAt":"2023-06-20T08:49:10.235Z","updatedAt":"2023-06-20T08:49:10.235Z","id":"649168062e95f7e77d8c8cb5"}],"investigationId":124564607,"statuses":[{"status":"CREATED","_id":"649168062e95f7e77d8c8cb7","createdBy":"admin","createdAt":"2023-06-20T08:49:10.235Z","updatedAt":"2023-06-20T08:49:10.235Z","createdByFullName":"adminFullName","id":"649168062e95f7e77d8c8cb7"},{"status":"SCHEDULED","_id":"649168062e95f7e77d8c8cb8","createdBy":"admin","createdAt":"2023-06-20T08:49:10.235Z","updatedAt":"2023-06-20T08:49:10.235Z","createdByFullName":"adminFullName","id":"649168062e95f7e77d8c8cb8"}],"currentStatus":"SCHEDULED","investigationName":"ID002306","createdAt":"2023-06-20T08:49:10.235Z","updatedAt":"2023-06-20T08:49:10.235Z","__v":0,"status":"SCHEDULED","investigation":{"name":"ID002306","startDate":"2023-06-19T13:28:44.492+02:00","id":124564607,"title":"ID002306","visitId":"id00","parameters":{"__datasetCount":"6","__sampleCount":"2","__fileCount":"0","__volume":"0","__elapsedTime":"0","__acquisitionDatasetCount":"4","__processedDatasetCount":"2","__acquisitionFileCount":"0","__processedFileCount":"0","__acquisitionVolume":"0","__processedVolume":"0"},"instrument":{"name":"ID00","id":92177647},"investigationUsers":[],"meta":{"page":{"totalWithoutFilters":1650,"total":1650,"totalPages":1,"currentPage":1}},"type":{"id":325,"createId":"root","createTime":"2014-06-18T15:00:43.500+02:00","modId":"root","modTime":"2014-06-18T15:00:43.500+02:00","description":"Test investigation","investigations":[],"name":"TEST"}},"localContactFullnames":[],"id":"649168062e95f7e77d8c8cb4","meta":{"page":{"total":1,"totalPages":1,"currentPage":1}}}] + +```python +print(json.dumps(json.loads(parcelResponse.text)[0]["content"])) +``` + + [{"content": [{"type": "TOOL", "name": "A tool within a container"}], "experimentPlan": [], "processingPlan": [], "_id": "649168062e95f7e77d8c8cb5", "name": "My Container", "type": "CONTAINER", "containerType": {"_id": "649168062e95f7e77d8c8cb6", "containerName": "SPINEPUCK", "capacity": 10, "id": "649168062e95f7e77d8c8cb6"}, "createdAt": "2023-06-20T08:49:10.235Z", "updatedAt": "2023-06-20T08:49:10.235Z", "id": "649168062e95f7e77d8c8cb5"}] + +```python + +``` diff --git a/documentation/shipment.ipynb b/documentation/shipment.ipynb new file mode 100644 index 00000000..0a91b95c --- /dev/null +++ b/documentation/shipment.ipynb @@ -0,0 +1,658 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Creation of a shipment and a parcel\n", + "\n", + "This notebook shows how to create addresses, shipment and a parcel from an existing investigation. It uses the ICAT+ API and needs to have a existing user with permissions to such investigation" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Configuration\n", + "\n", + "As mentioned it needs a running instance of ICAT+, a valid user credentials and an existing investigation." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#icatplus_server = \"http://dau-dm-03:8000\"\n", + "icatplus_server = \"http://lalex.esrf.fr:8000\"\n", + "credential = {\n", + " \"plugin\": \"db\",\n", + " \"username\": \"admin\",\n", + " \"password\": \"test_admin\"\n", + "}\n", + "investigationId = 124564607 \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Login\n", + "\n", + "This logs into ICAT in order to get the token that is called `sessionId`. The `sessionId` expires depending of the ICAT configuration and it is returned in the variable `lefeTimeMinutes`" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "session = requests.post(icatplus_server + \"/session\", data = credential)\n", + "session = json.loads(session.text)\n", + "sessionId = session[\"sessionId\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'name': 'admin', 'username': 'admin', 'fullName': 'adminFullName', 'lifeTimeMinutes': 719.9995333333334, 'isAdministrator': True, 'isInstrumentScientist': False, 'isMinter': False, 'sessionId': '8d4728d0-e84d-40fb-b6d2-543e296ba194', 'usersByPrefix': []}\n" + ] + } + ], + "source": [ + "print(session)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Get Investigation\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://lalex.esrf.fr:8000/catalogue/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation?ids=124564607\n" + ] + } + ], + "source": [ + "url = (f'{icatplus_server}/catalogue/{sessionId}/investigation?ids={investigationId}')\n", + "print(url)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "investigation = requests.get(f'{url}')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[\n", + " {\n", + " \"name\": \"ID002306\",\n", + " \"startDate\": \"2023-06-19T13:28:44.492+02:00\",\n", + " \"id\": 124564607,\n", + " \"title\": \"ID002306\",\n", + " \"visitId\": \"id00\",\n", + " \"parameters\": {\n", + " \"__datasetCount\": \"6\",\n", + " \"__sampleCount\": \"2\",\n", + " \"__fileCount\": \"0\",\n", + " \"__volume\": \"0\",\n", + " \"__elapsedTime\": \"0\",\n", + " \"__acquisitionDatasetCount\": \"4\",\n", + " \"__processedDatasetCount\": \"2\",\n", + " \"__acquisitionFileCount\": \"0\",\n", + " \"__processedFileCount\": \"0\",\n", + " \"__acquisitionVolume\": \"0\",\n", + " \"__processedVolume\": \"0\"\n", + " },\n", + " \"instrument\": {\n", + " \"name\": \"ID00\",\n", + " \"id\": 92177647\n", + " },\n", + " \"investigationUsers\": [],\n", + " \"meta\": {\n", + " \"page\": {\n", + " \"totalWithoutFilters\": 1,\n", + " \"total\": 1,\n", + " \"totalPages\": 1,\n", + " \"currentPage\": 1\n", + " }\n", + " },\n", + " \"type\": {\n", + " \"id\": 325,\n", + " \"createId\": \"root\",\n", + " \"createTime\": \"2014-06-18T15:00:43.500+02:00\",\n", + " \"modId\": \"root\",\n", + " \"modTime\": \"2014-06-18T15:00:43.500+02:00\",\n", + " \"description\": \"Test investigation\",\n", + " \"investigations\": [],\n", + " \"name\": \"TEST\"\n", + " }\n", + " }\n", + "]\n" + ] + } + ], + "source": [ + "print(json.dumps(json.loads(investigation.text), indent=2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Shipment and addresses" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### List Shipment" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation/id/124564607/shipment\n" + ] + } + ], + "source": [ + "url_shipment = f'{icatplus_server}/tracking/{sessionId}/investigation/id/{investigationId}/shipment'\n", + "print(url_shipment)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "shipment = requests.get(f'{url_shipment}')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], + "source": [ + "print(json.dumps(json.loads(shipment.text), indent=2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## List addresses" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/investigation/id/124564607/address\n" + ] + } + ], + "source": [ + "url_address = f'{icatplus_server}/tracking/{sessionId}/investigation/id/{investigationId}/address'\n", + "print(url_address)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], + "source": [ + "addresses = requests.get(f'{url_address}')\n", + "print(addresses.text)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create address" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "address = {\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\"\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"status\": \"ACTIVE\",\n", + " \"_id\": \"649168052e95f7e77d8c8cae\",\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\",\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdBy\": \"admin\",\n", + " \"investigationId\": 124564607,\n", + " \"createdAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"__v\": 0\n", + "}\n" + ] + } + ], + "source": [ + "address = requests.post(f'{url_address}', data=address)\n", + "print(json.dumps(json.loads(address.text), indent=2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create shipment" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "shipment = {\n", + " \"name\": \"my new Shipment\",\n", + " \"investigationId\":investigationId,\n", + " \"defaultReturnAddress\": json.loads(address.text)[\"_id\"],\n", + " \"defaultShippingAddress\": json.loads(address.text)[\"_id\"]\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"status\": \"OPENED\",\n", + " \"parcels\": [],\n", + " \"_id\": \"649168062e95f7e77d8c8caf\",\n", + " \"name\": \"my new Shipment\",\n", + " \"investigationId\": 124564607,\n", + " \"defaultReturnAddress\": {\n", + " \"status\": \"ACTIVE\",\n", + " \"_id\": \"649168052e95f7e77d8c8cae\",\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\",\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdBy\": \"admin\",\n", + " \"investigationId\": 124564607,\n", + " \"createdAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"__v\": 0\n", + " },\n", + " \"defaultShippingAddress\": {\n", + " \"status\": \"ACTIVE\",\n", + " \"_id\": \"649168052e95f7e77d8c8cae\",\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\",\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdBy\": \"admin\",\n", + " \"investigationId\": 124564607,\n", + " \"createdAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"__v\": 0\n", + " },\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdAt\": \"2023-06-20T08:49:10.054Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:10.054Z\",\n", + " \"__v\": 0\n", + "}\n" + ] + } + ], + "source": [ + "shipment = requests.post(f'{url_shipment}', data=shipment)\n", + "print(json.dumps(json.loads(shipment.text), indent=2))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[\n", + " {\n", + " \"status\": \"OPENED\",\n", + " \"parcels\": [],\n", + " \"_id\": \"649168062e95f7e77d8c8caf\",\n", + " \"name\": \"my new Shipment\",\n", + " \"investigationId\": 124564607,\n", + " \"defaultReturnAddress\": {\n", + " \"status\": \"ACTIVE\",\n", + " \"_id\": \"649168052e95f7e77d8c8cae\",\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\",\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdBy\": \"admin\",\n", + " \"investigationId\": 124564607,\n", + " \"createdAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"__v\": 0\n", + " },\n", + " \"defaultShippingAddress\": {\n", + " \"status\": \"ACTIVE\",\n", + " \"_id\": \"649168052e95f7e77d8c8cae\",\n", + " \"name\": \"Name\",\n", + " \"surname\": \"Surname\",\n", + " \"companyName\": \"My Company\",\n", + " \"address\": \"Rue Victor Hugo\",\n", + " \"city\": \"Grenoble\",\n", + " \"region\": \"Isere\",\n", + " \"postalCode\": \"38000\",\n", + " \"country\": \"France\",\n", + " \"email\": \"myemail@email.com\",\n", + " \"phoneNumber\": \"065222584\",\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdBy\": \"admin\",\n", + " \"investigationId\": 124564607,\n", + " \"createdAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:09.978Z\",\n", + " \"__v\": 0\n", + " },\n", + " \"investigationName\": \"ID002306\",\n", + " \"createdAt\": \"2023-06-20T08:49:10.054Z\",\n", + " \"updatedAt\": \"2023-06-20T08:49:10.054Z\",\n", + " \"__v\": 0\n", + " }\n", + "]\n" + ] + } + ], + "source": [ + "shipment = requests.get(f'{url_shipment}')\n", + "shipmentId = json.loads(shipment.text)[0][\"_id\"]\n", + "print(json.dumps(json.loads(shipment.text), indent=2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create parcels" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://lalex.esrf.fr:8000/tracking/8d4728d0-e84d-40fb-b6d2-543e296ba194/parcel?investigationId=124564607&shipmentId=649168062e95f7e77d8c8caf\n" + ] + } + ], + "source": [ + "url_parcel = f'{icatplus_server}/tracking/{sessionId}/parcel?investigationId={investigationId}&shipmentId={shipmentId}'\n", + "print(url_parcel)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "content = [\n", + " {\n", + " \"name\": \"My Container\",\n", + " \"type\": \"CONTAINER\",\n", + " \"containerType\": {\n", + " \"containerName\": \"SPINEPUCK\",\n", + " \"capacity\": 10,\n", + " },\n", + " \"content\": [\n", + " {\n", + " \"type\": \"TOOL\",\n", + " \"name\": \"A tool within a container\",\n", + " },\n", + " ],\n", + " },\n", + " ]\n", + "parcel = {\n", + " \"name\": \"Parcel created by investigation user\",\n", + " \"description\": \"This parcel has been automatically generated by the unit tests\",\n", + " \"shipmentId\" : shipmentId,\n", + " \"comment\": \"This is the comment\",\n", + " \"storageConditions\": \"Fridge\",\n", + " \"content\": [\n", + " {\n", + " \"name\": \"My Container\",\n", + " \"type\": \"CONTAINER\",\n", + " \"containerType\": {\n", + " \"containerName\": \"SPINEPUCK\",\n", + " \"capacity\": 10,\n", + " },\n", + " \"content\": [\n", + " {\n", + " \"type\": \"TOOL\",\n", + " \"name\": \"A tool within a container\",\n", + " },\n", + " ],\n", + " },\n", + " ]\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<Response [200]>\n" + ] + } + ], + "source": [ + "parcelResponse = requests.put(f'{url_parcel}', json=(parcel))\n", + "print(parcelResponse)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{\"type\":\"DEFAULT\",\"localContactNames\":[],\"items\":[],\"_id\":\"649168062e95f7e77d8c8cb4\",\"name\":\"Parcel created by investigation user\",\"description\":\"This parcel has been automatically generated by the unit tests\",\"shipmentId\":\"649168062e95f7e77d8c8caf\",\"storageConditions\":\"Fridge\",\"content\":[{\"content\":[{\"type\":\"TOOL\",\"name\":\"A tool within a container\"}],\"experimentPlan\":[],\"processingPlan\":[],\"_id\":\"649168062e95f7e77d8c8cb5\",\"name\":\"My Container\",\"type\":\"CONTAINER\",\"containerType\":{\"_id\":\"649168062e95f7e77d8c8cb6\",\"containerName\":\"SPINEPUCK\",\"capacity\":10,\"id\":\"649168062e95f7e77d8c8cb6\"},\"createdAt\":\"2023-06-20T08:49:10.235Z\",\"updatedAt\":\"2023-06-20T08:49:10.235Z\",\"id\":\"649168062e95f7e77d8c8cb5\"}],\"investigationId\":124564607,\"statuses\":[{\"status\":\"CREATED\",\"_id\":\"649168062e95f7e77d8c8cb7\",\"createdBy\":\"admin\",\"createdAt\":\"2023-06-20T08:49:10.235Z\",\"updatedAt\":\"2023-06-20T08:49:10.235Z\",\"createdByFullName\":\"adminFullName\",\"id\":\"649168062e95f7e77d8c8cb7\"},{\"status\":\"SCHEDULED\",\"_id\":\"649168062e95f7e77d8c8cb8\",\"createdBy\":\"admin\",\"createdAt\":\"2023-06-20T08:49:10.235Z\",\"updatedAt\":\"2023-06-20T08:49:10.235Z\",\"createdByFullName\":\"adminFullName\",\"id\":\"649168062e95f7e77d8c8cb8\"}],\"currentStatus\":\"SCHEDULED\",\"investigationName\":\"ID002306\",\"createdAt\":\"2023-06-20T08:49:10.235Z\",\"updatedAt\":\"2023-06-20T08:49:10.235Z\",\"__v\":0,\"status\":\"SCHEDULED\",\"investigation\":{\"name\":\"ID002306\",\"startDate\":\"2023-06-19T13:28:44.492+02:00\",\"id\":124564607,\"title\":\"ID002306\",\"visitId\":\"id00\",\"parameters\":{\"__datasetCount\":\"6\",\"__sampleCount\":\"2\",\"__fileCount\":\"0\",\"__volume\":\"0\",\"__elapsedTime\":\"0\",\"__acquisitionDatasetCount\":\"4\",\"__processedDatasetCount\":\"2\",\"__acquisitionFileCount\":\"0\",\"__processedFileCount\":\"0\",\"__acquisitionVolume\":\"0\",\"__processedVolume\":\"0\"},\"instrument\":{\"name\":\"ID00\",\"id\":92177647},\"investigationUsers\":[],\"meta\":{\"page\":{\"totalWithoutFilters\":1650,\"total\":1650,\"totalPages\":1,\"currentPage\":1}},\"type\":{\"id\":325,\"createId\":\"root\",\"createTime\":\"2014-06-18T15:00:43.500+02:00\",\"modId\":\"root\",\"modTime\":\"2014-06-18T15:00:43.500+02:00\",\"description\":\"Test investigation\",\"investigations\":[],\"name\":\"TEST\"}},\"localContactFullnames\":[],\"id\":\"649168062e95f7e77d8c8cb4\",\"meta\":{\"page\":{\"total\":1,\"totalPages\":1,\"currentPage\":1}}}]\n" + ] + } + ], + "source": [ + "print(requests.get(f'{url_parcel}').text)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{\"content\": [{\"type\": \"TOOL\", \"name\": \"A tool within a container\"}], \"experimentPlan\": [], \"processingPlan\": [], \"_id\": \"649168062e95f7e77d8c8cb5\", \"name\": \"My Container\", \"type\": \"CONTAINER\", \"containerType\": {\"_id\": \"649168062e95f7e77d8c8cb6\", \"containerName\": \"SPINEPUCK\", \"capacity\": 10, \"id\": \"649168062e95f7e77d8c8cb6\"}, \"createdAt\": \"2023-06-20T08:49:10.235Z\", \"updatedAt\": \"2023-06-20T08:49:10.235Z\", \"id\": \"649168062e95f7e77d8c8cb5\"}]\n" + ] + } + ], + "source": [ + "print(json.dumps(json.loads(parcelResponse.text)[0][\"content\"]))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} -- GitLab From 491f2c330dec2f55cf7084d783158dcf3210586a Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos <demariaa@esrf.fr> Date: Tue, 20 Jun 2023 10:57:07 +0200 Subject: [PATCH 6/6] Added documentaiton --- documentation/docs/tracking.md | 4 ++-- documentation/shipment.ipynb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/documentation/docs/tracking.md b/documentation/docs/tracking.md index cfdf61a5..366ce089 100644 --- a/documentation/docs/tracking.md +++ b/documentation/docs/tracking.md @@ -46,8 +46,8 @@ As mentioned it needs a running instance of ICAT+, a valid user credentials and icatplus_server = "http://lalex.esrf.fr:8000" credential = { "plugin": "db", - "username": "admin", - "password": "test_admin" + "username": "********", + "password": "********" } investigationId = 124564607 diff --git a/documentation/shipment.ipynb b/documentation/shipment.ipynb index 0a91b95c..865d31a9 100644 --- a/documentation/shipment.ipynb +++ b/documentation/shipment.ipynb @@ -34,12 +34,12 @@ "metadata": {}, "outputs": [], "source": [ - "#icatplus_server = \"http://dau-dm-03:8000\"\n", - "icatplus_server = \"http://lalex.esrf.fr:8000\"\n", + "icatplus_server = \"http://dau-dm-03:8000\"\n", + "\n", "credential = {\n", " \"plugin\": \"db\",\n", - " \"username\": \"admin\",\n", - " \"password\": \"test_admin\"\n", + " \"username\": \"****\",\n", + " \"password\": \"*****\"\n", "}\n", "investigationId = 124564607 \n" ] -- GitLab