{
	"info": {
		"_postman_id": "bddd37d9-6d5e-4fc4-b706-35f436a9b325",
		"name": "MPI X-Road",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "5159090"
	},
	"item": [
		{
			"name": "1. Auth",
			"item": [
				{
					"name": "1.1 Get token",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"token\", pm.response.json().accessToken);",
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"auth": {
							"type": "noauth"
						},
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"user\": {\n        \"personalCode\": \"49909090014\"\n    },\n    \"organization\": \"70009770\",\n    \"role\": \"doctor\",\n    \"application\": \"tto-tis-client-application\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{AUTH_URL}}/v2/token",
							"host": [
								"{{AUTH_URL}}"
							],
							"path": [
								"v2",
								"token"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "2. Patient",
			"item": [
				{
					"name": "2.1 Create patient",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"FAKE_FIN_ID\", '' + _.random(300000000000, 9000000000000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"const getLocationRegex = () => /.*\\/Patient\\/([0-9]+)/g;",
									"",
									"pm.test(\"Should return 201\", () => {",
									"    pm.response.to.have.status(201);",
									"});",
									"",
									"pm.test(\"Location header is present\", () => {",
									"  pm.response.to.have.header(\"Location\");",
									"});",
									"",
									"pm.test(\"Location have patient ID\", () => {",
									"    const location = pm.response.headers.get(\"Location\");",
									"    pm.expect(location).to.matches(getLocationRegex());",
									"",
									"    ",
									"    const fhirPatinetId = getLocationRegex().exec(location)[1];",
									"    console.log(\"fhirPatinetId: \", fhirPatinetId);",
									"    pm.collectionVariables.set('PATIENT_FHIR_ID', fhirPatinetId);",
									"",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"resourceType\": \"Patient\",\n  \"meta\": {\n    \"profile\": [\n      \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-patient-verified\"\n    ]\n  },\n  \"text\": {\n    \"status\": \"generated\",\n    \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">text</div>\"\n  },\n  \"identifier\": [\n    {\n      \"system\": \"https://fhir.ee/sid/pid/fin/ni\",\n      \"value\": \"{{FAKE_FIN_ID}}\"\n    }\n  ],\n  \"active\": true,\n  \"name\": [\n    {\n      \"use\": \"official\",\n      \"family\": \"Hakkinen\",\n      \"given\": [\n        \"Pekko\"\n      ]\n    }\n  ],\n  \"telecom\": [\n    {\n      \"system\": \"phone\",\n      \"value\": \"+37253535353\",\n      \"use\": \"home\",\n      \"rank\": 1\n    }\n  ],\n  \"gender\": \"male\",\n  \"birthDate\": \"1974-12-25\",\n  \"address\": [\n    {\n      \"use\": \"home\",\n      \"type\": \"both\",\n      \"text\": \"Mäkelänkatu 25 B 13\",\n      \"line\": [\n        \"Mäkelänkatu 25\"\n      ],\n      \"_line\": [\n        {\n          \"extension\": [\n            {\n              \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-streetName\",\n              \"valueString\": \"Mäkelänkatu St\"\n            },\n            {\n              \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-houseNumber\",\n              \"valueString\": \"25 B\"\n            },\n            {\n              \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-additionalLocator\",\n              \"valueString\": \"13\"\n            }\n          ]\n        }\n      ],\n      \"country\": \"FI\",\n      \"city\": \"Helsinki\",\n      \"postalCode\": \"05550\",\n      \"period\": {\n        \"start\": \"1974-12-25\"\n      }\n    }\n  ]\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/Patient",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.2 Load Patient",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Should have identifier\", () => {",
									"    const patient = pm.response.json();",
									"    pm.expect(patient.resourceType).eq('Patient');",
									"    pm.expect(patient.identifier[0].value).eq(pm.collectionVariables.get('FAKE_FIN_ID'));",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/{{PATIENT_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"{{PATIENT_FHIR_ID}}"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.3 Update patient",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"randomPhone\", \"+358\"+_.random(1000000, 900000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "PUT",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"Patient\",\n    \"meta\": {\n        \"lastUpdated\": \"2024-04-26T12:52:36.527+03:00\",\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-patient-verified\"\n        ]\n    },\n    \"identifier\": [\n        {\n            \"system\": \"https://fhir.ee/sid/pid/fin/ni\",\n            \"value\": \"{{FAKE_FIN_ID}}\"\n        }\n    ],\n    \"active\": true,\n    \"name\": [\n        {\n            \"use\": \"official\",\n            \"family\": \"Lappinen\",\n            \"given\": [\n                \"Pekko\"\n            ]\n        }\n    ],\n    \"telecom\": [\n        {\n            \"system\": \"phone\",\n            \"value\": \"{{randomPhone}}\",\n            \"use\": \"home\",\n            \"rank\": 1\n        }\n    ],\n    \"gender\": \"male\",\n    \"birthDate\": \"1974-12-25\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/{{PATIENT_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"{{PATIENT_FHIR_ID}}"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.4 Search Patient by identifier",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient?identifier=https%3A%2F%2Ffhir.ee%2Fsid%2Fpid%2Ffin%2Fni%7C{{FAKE_FIN_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient"
							],
							"query": [
								{
									"key": "identifier",
									"value": "https%3A%2F%2Ffhir.ee%2Fsid%2Fpid%2Ffin%2Fni%7C{{FAKE_FIN_ID}}"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "2.5 Search Foreign Patient",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"encodedRandomPhone\", encodeURIComponent(pm.collectionVariables.get(\"randomPhone\")))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/$foreign?family=Lappinen&given=Pekko&telecom={{encodedRandomPhone}}&gender=male&birthdate=1974-12-25&identifier_country=FIN",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"$foreign"
							],
							"query": [
								{
									"key": "family",
									"value": "Lappinen"
								},
								{
									"key": "given",
									"value": "Pekko"
								},
								{
									"key": "telecom",
									"value": "{{encodedRandomPhone}}"
								},
								{
									"key": "gender",
									"value": "male"
								},
								{
									"key": "birthdate",
									"value": "1974-12-25"
								},
								{
									"key": "identifier_country",
									"value": "FIN"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "2.6 Search Est Patient",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient?identifier=https%3A%2F%2Ffhir.ee%2Fsid%2Fpid%2Fest%2Fni%7C52009010061",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient"
							],
							"query": [
								{
									"key": "identifier",
									"value": "https%3A%2F%2Ffhir.ee%2Fsid%2Fpid%2Fest%2Fni%7C52009010061"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "2.7 Patient generate MRN",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/$mrn",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"$mrn"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.8 Create unknown patient",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"UNK_ID\", _.random(30000000000, 600000000000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"const getLocationRegex = () => /.*\\/Patient\\/([0-9]+)/g;",
									"",
									"pm.test(\"Should return 201\", () => {",
									"    pm.response.to.have.status(201);",
									"});",
									"",
									"pm.test(\"Location header is present\", () => {",
									"  pm.response.to.have.header(\"Location\");",
									"});",
									"",
									"pm.test(\"Location have patient ID\", () => {",
									"    const location = pm.response.headers.get(\"Location\");",
									"    pm.expect(location).to.matches(getLocationRegex());",
									"",
									"    ",
									"    const fhirPatinetId = getLocationRegex().exec(location)[1];",
									"    console.log(\"fhirPatinetId: \", fhirPatinetId);",
									"    pm.collectionVariables.set('UNKNOWN_PATIENT_FHIR_ID', fhirPatinetId);",
									"",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"Patient\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-patient-unknown\"\n        ]\n    },\n    \"text\": {\n        \"status\": \"generated\",\n        \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">text</div>\"\n    },\n    \"identifier\": [\n        {\n            \"system\": \"https://fhir.ee/sid/pid/est/mr\",\n            \"value\": \"{{UNK_ID}}\"\n        }\n    ],\n    \"active\": false,\n    \"name\": [\n        {\n            \"use\": \"nickname\",\n            \"text\": \"Tundmatu mees\"\n        }\n    ],\n    \"gender\": \"male\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/Patient",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.9 Link patients",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"Parameters\",\n    \"parameter\": [\n        {\n            \"name\": \"source-patient\",\n            \"valueReference\": {\n                \"reference\": \"Patient/{{UNKNOWN_PATIENT_FHIR_ID}}\"\n            }\n        },\n        {\n            \"name\": \"target-patient\",\n            \"valueReference\": {\n                \"reference\": \"Patient/{{PATIENT_FHIR_ID}}\"\n            }\n        }\n    ]\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/$link",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"$link"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.10 Unlink patients",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"Parameters\",\n    \"id\": \"example\",\n    \"parameter\": [\n        {\n            \"name\": \"source-patient\",\n            \"valueReference\": {\n                \"reference\": \"Patient/{{PATIENT_FHIR_ID}}\"\n            }\n        },\n        {\n            \"name\": \"target-patient\",\n            \"valueReference\": {\n                \"reference\": \"Patient/{{UNKNOWN_PATIENT_FHIR_ID}}\"\n            }\n        }\n    ]\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/$unlink",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"$unlink"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.11 Patient history",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Should have history\", () => {",
									"    const history = pm.response.json();",
									"    pm.expect(history.entry.length).gte(2);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/{{PATIENT_FHIR_ID}}/_history",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"{{PATIENT_FHIR_ID}}",
								"_history"
							]
						}
					},
					"response": []
				},
				{
					"name": "1.14 Patient lookup",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value=52009010061",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"Patient",
								"$lookup"
							],
							"query": [
								{
									"key": "source",
									"value": "https://mpi.tehik.ee",
									"disabled": true
								},
								{
									"key": "source",
									"value": "https://rahvastikuregister.ee"
								},
								{
									"key": "identifier.value",
									"value": "52009010061"
								}
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "3. RelatedPerson",
			"item": [
				{
					"name": "2.1 Create RelatedPerson",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"FAKE_EST_ID\", _.random(30000000000, 600000000000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"const getLocationRegex = () => /.*\\/RelatedPerson\\/([0-9]+)/g;",
									"",
									"pm.test(\"Should return 201\", () => {",
									"    pm.response.to.have.status(201);",
									"});",
									"",
									"pm.test(\"Location header is present\", () => {",
									"  pm.response.to.have.header(\"Location\");",
									"});",
									"",
									"pm.test(\"Location have related person ID\", () => {",
									"    const location = pm.response.headers.get(\"Location\");",
									"    pm.expect(location).to.matches(getLocationRegex());",
									"",
									"    ",
									"    const fhirRpId = getLocationRegex().exec(location)[1];",
									"    console.log(\"RP_FHIR_ID: \", fhirRpId);",
									"    pm.collectionVariables.set('RP_FHIR_ID', fhirRpId);",
									"",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"RelatedPerson\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-related-person\"\n        ]\n    },\n    \"text\": {\n        \"status\": \"generated\",\n        \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">text</div>\"\n    },\n    \"identifier\": [\n        {\n            \"system\": \"https://fhir.ee/sid/pid/est/ni\",\n            \"value\": \"{{FAKE_EST_ID}}\"\n        }\n    ],\n    \"active\": true,\n    \"patient\": {\n        \"reference\": \"Patient/{{PATIENT_FHIR_ID}}\"\n    },\n    \"relationship\": [\n        {\n            \"coding\": [\n                {\n                    \"system\": \"http://terminology.hl7.org/CodeSystem/v3-RoleClass\",\n                    \"code\": \"CON\"\n                }\n            ]\n        },\n        {\n            \"coding\": [\n                {\n                    \"system\": \"http://snomed.info/sct\",\n                    \"code\": \"72705000\",\n                    \"display\": \"Mother (person)\"\n                }\n            ]\n        }\n    ],\n    \"name\": [\n        {\n            \"family\": \"Vask\",\n            \"given\": [\n                \"Annika\"\n            ]\n        }\n    ],\n    \"telecom\": [\n        {\n            \"system\": \"phone\",\n            \"value\": \"+37256218121\"\n        }\n    ],\n    \"period\": {\n        \"start\": \"2012\"\n    }\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.2 Load RelatedPerson",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson/{{RP_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson",
								"{{RP_FHIR_ID}}"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.3 Update RelatedPerson",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"FAKE_EST_ID\", _.random(30000000000, 600000000000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "PUT",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"resourceType\": \"RelatedPerson\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-related-person\"\n        ]\n    },\n    \"text\": {\n        \"status\": \"generated\",\n        \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">text</div>\"\n    },\n    \"identifier\": [\n        {\n            \"system\": \"https://fhir.ee/sid/pid/est/ni\",\n            \"value\": \"{{FAKE_EST_ID}}\"\n        }\n    ],\n    \"active\": true,\n    \"patient\": {\n        \"reference\": \"Patient/{{PATIENT_FHIR_ID}}\"\n    },\n    \"relationship\": [\n        {\n            \"coding\": [\n                {\n                    \"system\": \"http://snomed.info/sct\",\n                    \"code\": \"72705000\",\n                    \"display\": \"Mother (person)\"\n                }\n            ]\n        }\n    ],\n    \"name\": [\n       {\n            \"family\": \"Vask\",\n            \"given\": [\n                \"Annika\"\n            ]\n        }\n    ],\n    \"telecom\": [\n        {\n            \"system\": \"phone\",\n            \"value\": \"+37256218222\"\n        }\n    ],\n    \"period\": {\n        \"start\": \"2012\"\n    }\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson/{{RP_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson",
								"{{RP_FHIR_ID}}"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.4 Search RelatePerson",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson?patient=Patient/{{PATIENT_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson"
							],
							"query": [
								{
									"key": "patient",
									"value": "Patient/{{PATIENT_FHIR_ID}}"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "2.5 RelatedPerson history",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 200\", () => {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson/{{RP_FHIR_ID}}/_history",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson",
								"{{RP_FHIR_ID}}",
								"_history"
							]
						}
					},
					"response": []
				},
				{
					"name": "2.6 Delete RelatedPerson",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"pm.environment.set(\"FAKE_EST_ID\", _.random(30000000000, 600000000000))"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Should return 204\", () => {",
									"    pm.response.to.have.status(204);",
									"});"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "DELETE",
						"header": [
							{
								"key": "x-road-client",
								"value": "{{X_ROAD_CLIENT}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{MPI_FHIR}}/RelatedPerson/{{RP_FHIR_ID}}",
							"host": [
								"{{MPI_FHIR}}"
							],
							"path": [
								"RelatedPerson",
								"{{RP_FHIR_ID}}"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "4. Observation",
			"item": [
				{
					"name": "4.1 Incapacity for work",
					"item": [
						{
							"name": "4.1.1 Load patient for Incapacity",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"INC_EST_CODE\", '37311284711')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('INC_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{INC_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{INC_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.1.2 Incapacity for work operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring töövõime kohta visiiditasu soodustuse jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$incapacity-for-work?patient=Patient/{{INC_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$incapacity-for-work"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{INC_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.2 Disability level",
					"item": [
						{
							"name": "4.2.1 Load patient for Disability",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"DIS_EST_CODE\", '38307210278')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('DIS_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{DIS_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{DIS_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.2.2 Disability level operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring puude kohta visiiditasu soodustuse jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$disability?patient=Patient/{{DIS_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$disability"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{DIS_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.3 Education",
					"item": [
						{
							"name": "4.3.1 Load patient for Education",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"EDU_EST_CODE\", '49303080864')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('EDU_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{EDU_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{EDU_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.3.2 Education operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi haridustaseme kohta TAI registri jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$education?patient=Patient/{{EDU_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$education"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{EDU_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.4 Occupation",
					"item": [
						{
							"name": "4.4.1 Load patient for Occupation",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"OCCU_EST_CODE\", '38005280013')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('OCCU_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{OCCU_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{OCCU_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.4.2 Occupation operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi töökoha ja ameti kohta teenuse osutamise jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$occupation?patient=Patient/{{OCCU_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$occupation"
									],
									"query": [
										{
											"key": "nocache",
											"value": "true",
											"disabled": true
										},
										{
											"key": "patient",
											"value": "Patient/{{OCCU_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.5 Legal guardian operation",
					"item": [
						{
							"name": "4.5.1 Load patient for finding of ward",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"PAT_FIND_OF_WARD_EST_CODE\", '36502280009')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('PAT_FIND_OF_WARD_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{PAT_FIND_OF_WARD_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{PAT_FIND_OF_WARD_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.5.2 Legal guardian operation - finding of wardship",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains a resource inside Bundle\", () => {",
											"    pm.expect(pm.response.json().entry[0].resource).to.exist;",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi eestkoste kohta teenuse saamiseks õiguslikel alustel",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$legal-guardian?patient=Patient/{{PAT_FIND_OF_WARD_ID}}&legal-status=365569001",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$legal-guardian"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{PAT_FIND_OF_WARD_ID}}"
										},
										{
											"key": "legal-status",
											"value": "365569001",
											"description": "finding of wardship"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.5.3 Load patient for legal guardian",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"PAT_LEGAL_GUARD_EST_CODE\", '52009010061')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('PAT_LEGAL_GUARD_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{PAT_LEGAL_GUARD_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{PAT_LEGAL_GUARD_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.5.4 Legal guardian operation - legal guardian",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains a resource inside Bundle\", () => {",
											"    pm.expect(pm.response.json().entry[0].resource).to.exist;",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi eestkoste kohta teenuse saamiseks õiguslikel alustel",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$legal-guardian?patient=Patient/{{PAT_LEGAL_GUARD_ID}}&legal-status=58626002",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$legal-guardian"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{PAT_LEGAL_GUARD_ID}}"
										},
										{
											"key": "legal-status",
											"value": "58626002",
											"description": "legal guardian"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.6 Power of attorney",
					"item": [
						{
							"name": "4.6.1 Load patient for Power of attorney",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"POW_OF_ATT_EST_CODE\", '36502280009')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('POW_OF_ATT_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{POW_OF_ATT_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{POW_OF_ATT_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "3.6.2 Power of attorney operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi hooldusõiguse kohta  teenuse saamiseks õiguslikel alustel",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$power-of-attorney?patient=Patient/{{POW_OF_ATT_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$power-of-attorney"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{POW_OF_ATT_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.7 Marital status",
					"item": [
						{
							"name": "4.7.1 Create Observation Patient",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"FAKE_ID\", _.random(30000000000, 600000000000))",
											"pm.collectionVariables.set(\"FAKE_EST_ID_2\", _.random(30000000000, 600000000000))"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"const getLocationRegex = () => /.*\\/Patient\\/([0-9]+)/g;",
											"",
											"pm.test(\"Should return 201\", () => {",
											"    pm.response.to.have.status(201);",
											"});",
											"",
											"pm.test(\"Location header is present\", () => {",
											"  pm.response.to.have.header(\"Location\");",
											"});",
											"",
											"pm.test(\"Location have related person ID\", () => {",
											"    const location = pm.response.headers.get(\"Location\");",
											"    pm.expect(location).to.matches(getLocationRegex());",
											"",
											"    ",
											"    const fhirRpId = getLocationRegex().exec(location)[1];",
											"    pm.collectionVariables.set('OBS_PAT_ID', fhirRpId);",
											"});",
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "POST",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "{\n    \"resourceType\": \"Patient\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-patient-verified\"\n        ]\n    },\n    \"text\": {\n        \"status\": \"generated\",\n        \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">text</div>\"\n    },\n    \"identifier\": [\n        {\n            \"system\": \"https://fhir.ee/sid/pid/fin/ni\",\n            \"value\": \"{{FAKE_ID}}\"\n        }\n    ],\n    \"active\": true,\n    \"name\": [\n        {\n            \"use\": \"official\",\n            \"family\": \"Võsaülane\",\n            \"given\": [\n                \"Tiit\"\n            ]\n        }\n    ],\n    \"telecom\": [\n        {\n            \"system\": \"phone\",\n            \"value\": \"+37253535353\",\n            \"use\": \"work\",\n            \"rank\": 1\n        }\n    ],\n    \"gender\": \"male\",\n    \"birthDate\": \"1974-12-25\",\n    \"_birthDate\": {\n        \"extension\": [\n            {\n                \"url\": \"http://hl7.org/fhir/StructureDefinition/patient-birthTime\",\n                \"valueDateTime\": \"1974-12-25T14:35:45-05:00\"\n            }\n        ]\n    },\n    \"deceasedDateTime\": \"2003-12-25T14:35:45-05:00\",\n    \"address\": [\n        {\n            \"extension\": [\n                {\n                    \"url\": \"https://fhir.ee/base/StructureDefinition/ee-ads-adr-id\",\n                    \"valueCoding\": {\n                        \"system\": \"https://fhir.ee/base/CodeSystem/ads-adr-id\",\n                        \"code\": \"111122\"\n                    }\n                },\n                {\n                    \"url\": \"https://fhir.ee/base/StructureDefinition/ee-ehak\",\n                    \"valueCoding\": {\n                        \"system\": \"https://fhir.ee/sid/ehak\",\n                        \"code\": \"100300\"\n                    }\n                }\n            ],\n            \"country\": \"US\",\n            \"use\": \"home\",\n            \"type\": \"both\",\n            \"text\": \"534 Erewhon St PeasantVille, Rainbow, Vic  3999\",\n            \"line\": [\n                \"534 Erewhon St\"\n            ],\n            \"_line\": [\n                {\n                    \"extension\": [\n                        {\n                            \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-streetName\",\n                            \"valueString\": \"Erewhon St\"\n                        },\n                        {\n                            \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-houseNumber\",\n                            \"valueString\": \"534\"\n                        },\n                        {\n                            \"url\": \"http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-additionalLocator\",\n                            \"valueString\": \"110\"\n                        }\n                    ]\n                }\n            ],\n            \"city\": \"PleasantVille\",\n            \"district\": \"Rainbow\",\n            \"state\": \"Vic\",\n            \"postalCode\": \"3999\",\n            \"period\": {\n                \"start\": \"1974-12-25\"\n            }\n        }\n    ]\n}",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient"
									]
								}
							},
							"response": []
						},
						{
							"name": "4.7.2 Create Observation",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"const getLocationRegex = () => /.*\\/Observation\\/([0-9]+)/g;",
											"",
											"pm.test(\"Should return 201\", () => {",
											"    pm.response.to.have.status(201);",
											"});",
											"",
											"pm.test(\"Location header is present\", () => {",
											"  pm.response.to.have.header(\"Location\");",
											"});",
											"",
											"pm.test(\"Location have related person ID\", () => {",
											"    const location = pm.response.headers.get(\"Location\");",
											"    pm.expect(location).to.matches(getLocationRegex());",
											"",
											"    ",
											"    const fhirRpId = getLocationRegex().exec(location)[1];",
											"    console.log(\"OBS_FHIR_ID: \", fhirRpId);",
											"    pm.collectionVariables.set('OBS_FHIR_ID', fhirRpId);",
											"",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "POST",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "{\n    \"resourceType\": \"Observation\",\n    \"status\": \"final\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-socialhistory-marital-status\"\n        ]\n    },\n    \"category\": [\n        {\n            \"coding\": [\n                {\n                    \"system\": \"http://terminology.hl7.org/CodeSystem/observation-category\",\n                    \"code\": \"social-history\",\n                    \"display\": \"Social history\"\n                }\n            ]\n        }\n    ],\n    \"code\": {\n        \"coding\": [\n            {\n                \"system\": \"http://snomed.info/sct\",\n                \"code\": \"125680007\",\n                \"display\": \"Marital status\"\n            }\n        ]\n    },\n    \"subject\": {\n        \"reference\": \"Patient/{{OBS_PAT_ID}}\"\n    },\n    \"issued\": \"2013-04-03T15:30:10+01:00\",\n    \"valueCodeableConcept\": {\n        \"coding\": [\n            {\n                \"system\": \"http://terminology.hl7.org/CodeSystem/v3-MaritalStatus\",\n                \"code\": \"M\",\n                \"display\": \"Married\"\n            }\n        ]\n    }\n}",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Observation",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Observation"
									]
								}
							},
							"response": []
						},
						{
							"name": "4.7.3 Load Observation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Response status code is 200\", function () {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains a resource with type 'Observation'\", function () {",
											"    pm.expect(pm.response.json().resourceType).to.equal('Observation');",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi perekonnaseisu kohta TAI registri jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Observation/{{OBS_FHIR_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Observation",
										"{{OBS_FHIR_ID}}"
									]
								}
							},
							"response": []
						},
						{
							"name": "4.7.4 Update Observation",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "PUT",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "{\n    \"resourceType\": \"Observation\",\n    \"id\": \"{{OBS_FHIR_ID}}\",\n    \"status\": \"final\",\n    \"meta\": {\n        \"profile\": [\n            \"https://fhir.ee/mpi/StructureDefinition/ee-mpi-socialhistory-marital-status\"\n        ]\n    },\n    \"category\": [\n        {\n            \"coding\": [\n                {\n                    \"system\": \"http://terminology.hl7.org/CodeSystem/observation-category\",\n                    \"code\": \"social-history\",\n                    \"display\": \"Social history\"\n                }\n            ]\n        }\n    ],\n    \"code\": {\n        \"coding\": [\n            {\n                \"system\": \"http://snomed.info/sct\",\n                \"code\": \"125680007\",\n                \"display\": \"Marital status\"\n            }\n        ]\n    },\n    \"subject\": {\n        \"reference\": \"Patient/{{OBS_PAT_ID}}\"\n    },\n    \"issued\": \"2013-04-03T15:30:10+01:00\",\n    \"valueCodeableConcept\": {\n        \"coding\": [\n            {\n                \"system\": \"http://terminology.hl7.org/CodeSystem/v3-MaritalStatus\",\n                \"code\": \"D\",\n                \"display\": \"Divorced\"\n            }\n        ]\n    }\n}",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Observation/{{OBS_FHIR_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Observation",
										"{{OBS_FHIR_ID}}"
									]
								}
							},
							"response": []
						},
						{
							"name": "4.7.5 Search Observations",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains entry with valueCodeableConcept coding code D\", function () {",
											"    var jsonData = pm.response.json();",
											"    var entry = jsonData.entry.find(function (item) {",
											"        return item.resource.valueCodeableConcept.coding.some(function (coding) {",
											"            return coding.code === \"D\";",
											"        });",
											"    });",
											"    pm.expect(entry).to.exist;",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring patsiendi perekonnaseisu kohta TAI registri jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Observation?patient=Patient/{{OBS_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Observation"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{OBS_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				},
				{
					"name": "4.8 Legal status",
					"item": [
						{
							"name": "4.8.1 Load patient for Legal status",
							"event": [
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											"pm.collectionVariables.set(\"LS_EST_CODE\", '44304060017')"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Should return single patient record\", () => {",
											"    const patient = pm.response.json();",
											"    pm.expect(patient.entry[0].resource.id).to.not.be.empty;",
											"    pm.collectionVariables.set('LS_PAT_ID', patient.entry[0].resource.id);",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"protocolProfileBehavior": {
								"disableBodyPruning": true
							},
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									}
								],
								"body": {
									"mode": "raw",
									"raw": "",
									"options": {
										"raw": {
											"language": "json"
										}
									}
								},
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$lookup?source=https://rahvastikuregister.ee&identifier.value={{LS_EST_CODE}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$lookup"
									],
									"query": [
										{
											"key": "source",
											"value": "https://rahvastikuregister.ee"
										},
										{
											"key": "identifier.value",
											"value": "{{LS_EST_CODE}}"
										}
									]
								}
							},
							"response": []
						},
						{
							"name": "4.8.2 Incapacity for work operation",
							"event": [
								{
									"listen": "test",
									"script": {
										"exec": [
											"pm.test(\"Should return 200\", () => {",
											"    pm.response.to.have.status(200);",
											"});",
											"",
											"pm.test(\"Response contains entry\", () => {",
											"    pm.expect(pm.response.json()).to.have.property(\"entry\");",
											"});"
										],
										"type": "text/javascript",
										"packages": {}
									}
								},
								{
									"listen": "prerequest",
									"script": {
										"exec": [
											""
										],
										"type": "text/javascript",
										"packages": {}
									}
								}
							],
							"request": {
								"method": "GET",
								"header": [
									{
										"key": "x-road-client",
										"value": "{{X_ROAD_CLIENT}}",
										"type": "text"
									},
									{
										"key": "x-road-issue",
										"value": "Tervishoiuteenuse osutaja päring töövõime kohta visiiditasu soodustuse jaoks",
										"type": "text"
									}
								],
								"url": {
									"raw": "{{MPI_FHIR}}/Patient/$legal-status?patient=Patient/{{LS_PAT_ID}}",
									"host": [
										"{{MPI_FHIR}}"
									],
									"path": [
										"Patient",
										"$legal-status"
									],
									"query": [
										{
											"key": "patient",
											"value": "Patient/{{LS_PAT_ID}}"
										}
									]
								}
							},
							"response": []
						}
					]
				}
			]
		}
	],
	"auth": {
		"type": "bearer",
		"bearer": [
			{
				"key": "token",
				"value": "{{token}}",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "AUTH_URL",
			"value": "https://10.0.13.90/r1/ee-dev/GOV/70009770/tis/auth",
			"type": "string"
		},
		{
			"key": "MPI_FHIR",
			"value": "https://10.0.13.90/r1/ee-dev/GOV/70009770/tis/mpi",
			"type": "string"
		},
		{
			"key": "X_ROAD_CLIENT",
			"value": "ee-dev/GOV/70009770/tto-tis-klient",
			"type": "string"
		},
		{
			"key": "token",
			"value": ""
		},
		{
			"key": "FAKE_FIN_ID",
			"value": ""
		},
		{
			"key": "PATIENT_FHIR_ID",
			"value": ""
		},
		{
			"key": "randomPhone",
			"value": ""
		},
		{
			"key": "encodedRandomPhone",
			"value": ""
		},
		{
			"key": "UNK_ID",
			"value": ""
		},
		{
			"key": "UNKNOWN_PATIENT_FHIR_ID",
			"value": ""
		},
		{
			"key": "FAKE_EST_ID",
			"value": ""
		},
		{
			"key": "RP_FHIR_ID",
			"value": ""
		},
		{
			"key": "INC_EST_CODE",
			"value": ""
		},
		{
			"key": "INC_PAT_ID",
			"value": ""
		},
		{
			"key": "DIS_EST_CODE",
			"value": ""
		},
		{
			"key": "DIS_PAT_ID",
			"value": ""
		},
		{
			"key": "EDU_EST_CODE",
			"value": ""
		},
		{
			"key": "EDU_PAT_ID",
			"value": ""
		},
		{
			"key": "OCCU_EST_CODE",
			"value": ""
		},
		{
			"key": "OCCU_PAT_ID",
			"value": ""
		},
		{
			"key": "PAT_FIND_OF_WARD_EST_CODE",
			"value": ""
		},
		{
			"key": "PAT_FIND_OF_WARD_ID",
			"value": ""
		},
		{
			"key": "PAT_LEGAL_GUARD_EST_CODE",
			"value": ""
		},
		{
			"key": "PAT_LEGAL_GUARD_ID",
			"value": ""
		},
		{
			"key": "POW_OF_ATT_EST_CODE",
			"value": ""
		},
		{
			"key": "POW_OF_ATT_PAT_ID",
			"value": ""
		},
		{
			"key": "FAKE_ID",
			"value": ""
		},
		{
			"key": "FAKE_EST_ID_2",
			"value": ""
		},
		{
			"key": "OBS_PAT_ID",
			"value": ""
		},
		{
			"key": "OBS_RP_ID",
			"value": ""
		},
		{
			"key": "OBS_FHIR_ID",
			"value": ""
		},
		{
			"key": "LS_EST_CODE",
			"value": ""
		},
		{
			"key": "LEG_STAT_PAT_ID",
			"value": ""
		},
		{
			"key": "LS_PAT_ID",
			"value": ""
		}
	]
}
