---
# System prepended metadata

title: Database

---

# Database 

## Collections relevant to NPEU


| Collection     | Field        | Type      | Description                                                                      |
|----------------|--------------|-----------|----------------------------------------------------------------------------------|
| records        | study_id     | string    | Child's NPEU trial ID                                                            |
|                | child_id     | string    | Child's Newcastle database ID                                                    |
|                | date         | timestamp | Date records refers to                                                           |
|                | supplement   | string    | Have you given your baby their DOLFIN supplement today?                          |
|                | reason       | string    | It would be helpful for us to know why:                                          |
|                | other_reason | string    | It would be helpful for us to know why: Other (free text)                        |
| weekly_records | study_id     | string    | Child's NPEU trial ID                                                            |
|                | child_id     | string    | Child's Newcastle database ID                                                    |
|                | date         | timestamp | Record refers to 7 days prior to this date                                       |
|                | supplement   | string    | How many days did your baby have their DOLFIN supplement in the last seven days? |
|                | problem      | boolean   | Were there any problems giving the DOLFIN supplement according to the instructions? |
|                | reason       | string    | It would be helpful for us to know why:                                          |
|                | other_reason | string    | It would be helpful for us to know why: Other (free text)                        |
| admissions     | study_id     | string    | Child's NPEU trial ID                                                            |
|                | child_id     | string    | Child's Newcastle database ID                                                    |
|                | date         | timestamp | Date submitted                                                                   |
| weights        | study_id     | string    | Child's NPEU trial ID                                                            |
|                | child_id     | string    | Child's Newcastle database ID                                                    |
|                | date         | timestamp | Date submitted                                                                   |
|                | weight       | number    | Weight in grams                                                                  |
|                | num_scoops   | number    | Number of scoops                                                                 |


## Accessing Firestore collections

The research team will provide a public key to be uploaded to Google Firebase by Newcastle University RSE team. This will be provided with read only access to Google Firestore collections within the Dolfin project. This will provide the most secure and straightforward way to access the data.

Requirements for public key are [here](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). 

Firebase provides documentation on how to implement access using the private key in a variety of languages [here](https://firebase.google.com/docs/firestore/quickstart#python_3).

For more complex queries, see documentation [here](https://firebase.google.com/docs/firestore/query-data/get-data)

### Example code
For example, to access the `records` collection using Python.

*Install Firebase Admin SDK*: `pip install --upgrade firebase-admin`   

*Initialise Cloud Firestore SDK and provide credentials and read data*:   
```python
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

# Use a service account
cred = credentials.Certificate('path/to/serviceAccount.json')
firebase_admin.initialize_app(cred)

db = firestore.client()

users_ref = db.collection(u'records')
docs = users_ref.stream()

for doc in docs:
    print(f'{doc.id} => {doc.to_dict()}')

```



