{
	"info": {
		"name": "Ultrasound API",
		"description": "Pre-admission API for facilities running on the Ultrasound platform.\n\nSet the `clientId` and `clientSecret` collection variables to the credentials issued to you, then run `Request a token`. The token is stored automatically and every other request sends it as a bearer token. Tokens expire after 15 minutes; rerun the auth request when a call returns 401.\n\nFor local development set `baseUrl` to http://localhost:5190.\n\nThe bookingGuid variable defaults to the editable test booking (11111111-...). Reserved test bookings cover every state; see the docs site.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"auth": {
		"type": "bearer",
		"bearer": [
			{
				"key": "token",
				"value": "{{accessToken}}",
				"type": "string"
			}
		]
	},
	"variable": [
		{
			"key": "baseUrl",
			"value": "https://api.ultrasound.africa"
		},
		{
			"key": "clientId",
			"value": ""
		},
		{
			"key": "clientSecret",
			"value": ""
		},
		{
			"key": "accessToken",
			"value": ""
		},
		{
			"key": "bookingGuid",
			"value": "11111111-1111-1111-1111-111111111111",
			"description": "Defaults to the editable test booking; see the Test bookings section of the docs for the other reserved states."
		},
		{
			"key": "facilityId",
			"value": "14"
		},
		{
			"key": "medicalAidId",
			"value": "1"
		}
	],
	"item": [
		{
			"name": "Security",
			"item": [
				{
					"name": "Request a token",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"if (pm.response.code === 200) {",
									"    pm.collectionVariables.set('accessToken', pm.response.json().token);",
									"}",
									"pm.test('Token issued', () => pm.response.to.have.status(200));"
								]
							}
						}
					],
					"request": {
						"auth": {
							"type": "noauth"
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"clientId\": \"{{clientId}}\",\n  \"clientSecret\": \"{{clientSecret}}\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/security/v1/auth",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"security",
								"v1",
								"auth"
							]
						},
						"description": "Exchanges the machine credential for a bearer token. The test script stores the token in the accessToken variable for the rest of the collection."
					}
				}
			]
		},
		{
			"name": "Admissions",
			"item": [
				{
					"name": "Fetch the admission",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}"
							]
						},
						"description": "Previously captured pre-admission data for prefill plus booking context. An expired link returns 410 Gone."
					}
				},
				{
					"name": "Save the admission (partial)",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"patientName\": \"Thandi\",\n  \"patientSurname\": \"Mokoena\",\n  \"dateOfBirth\": \"1986-03-12T00:00:00\",\n  \"mobileNumber\": \"0821234567\",\n  \"emailAddress\": \"thandi@example.com\",\n  \"identificationNumber\": \"8603120000089\",\n  \"residentialAddress\": \"12 Protea Street\",\n  \"patientTypeID\": 2,\n  \"genderID\": 2,\n  \"nationalityID\": 1,\n  \"titleID\": 2,\n  \"languageID\": 1,\n  \"medicalAidID\": 1,\n  \"medicalAidSchemeID\": 4,\n  \"medicalAidNumber\": \"123456789\",\n  \"mainMember\": true,\n  \"nextOfKinFullName\": \"Sipho Mokoena\",\n  \"nextOfKinContactDetails\": \"0837654321\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}"
							]
						},
						"description": "Partial saves are supported; the response lists the fields still outstanding. isComplete turns true once everything validates."
					}
				},
				{
					"name": "Validate without saving",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"patientName\": \"Thandi\",\n  \"patientSurname\": \"Mokoena\",\n  \"dateOfBirth\": \"1986-03-12T00:00:00\",\n  \"mobileNumber\": \"0821234567\",\n  \"emailAddress\": \"thandi@example.com\",\n  \"identificationNumber\": \"8603120000089\",\n  \"residentialAddress\": \"12 Protea Street\",\n  \"patientTypeID\": 2,\n  \"genderID\": 2,\n  \"nationalityID\": 1,\n  \"titleID\": 2,\n  \"languageID\": 1,\n  \"medicalAidID\": 1,\n  \"medicalAidSchemeID\": 4,\n  \"medicalAidNumber\": \"123456789\",\n  \"mainMember\": true,\n  \"nextOfKinFullName\": \"Sipho Mokoena\",\n  \"nextOfKinContactDetails\": \"0837654321\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}/validate",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}",
								"validate"
							]
						},
						"description": "Dry-run of the save validation: returns isComplete and missingFields without persisting anything."
					}
				},
				{
					"name": "List uploaded documents",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}/documents",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}",
								"documents"
							]
						},
						"description": "Metadata of the documents uploaded so far, one entry per document type."
					}
				},
				{
					"name": "Upload a document",
					"request": {
						"method": "POST",
						"body": {
							"mode": "formdata",
							"formdata": [
								{
									"key": "file",
									"type": "file",
									"src": []
								},
								{
									"key": "documentType",
									"value": "IDOrPassport",
									"type": "text",
									"description": "IDOrPassport, MainMemberIDOrPassport, MedicalAidCard or MedicalAidAuthorisation"
								}
							]
						},
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}/documents",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}",
								"documents"
							]
						},
						"description": "One call per document type; re-uploading a type supersedes the previous file."
					}
				},
				{
					"name": "Download a document",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/{{bookingGuid}}/documents/IDOrPassport",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"{{bookingGuid}}",
								"documents",
								"IDOrPassport"
							]
						},
						"description": "Streams the stored file through the API with the bearer token. Replace the last segment with any of the four document types."
					}
				}
			]
		},
		{
			"name": "Facility lookups",
			"item": [
				{
					"name": "Titles",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/titles",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"titles"
							]
						}
					}
				},
				{
					"name": "Genders",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/genders",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"genders"
							]
						}
					}
				},
				{
					"name": "Nationalities",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/nationalities",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"nationalities"
							]
						}
					}
				},
				{
					"name": "Languages",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/languages",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"languages"
							]
						}
					}
				},
				{
					"name": "Religions",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/religions",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"religions"
							]
						}
					}
				},
				{
					"name": "Patient types",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/patient-types",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"patient-types"
							]
						}
					}
				},
				{
					"name": "Medical aids",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/medical-aids",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"medical-aids"
							]
						}
					}
				},
				{
					"name": "Medical aid schemes",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/medical-aids/{{medicalAidId}}/schemes",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"medical-aids",
								"{{medicalAidId}}",
								"schemes"
							]
						},
						"description": "Schemes belong to a medical aid; filter after the patient selects one."
					}
				},
				{
					"name": "Meal times",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/meal-times",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"meal-times"
							]
						}
					}
				},
				{
					"name": "Meal types",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/meal-types",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"meal-types"
							]
						}
					}
				},
				{
					"name": "Meals",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/meals",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"meals"
							]
						}
					}
				},
				{
					"name": "Beverages",
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/facilities/{{facilityId}}/beverages",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"facilities",
								"{{facilityId}}",
								"beverages"
							]
						}
					}
				}
			]
		},
		{
			"name": "Test scenarios",
			"description": "Runnable checks against the reserved test bookings, one per state. Authenticate first (Security > Request a token); every request here requires the bearer token. Run the whole folder with the collection runner for a pass/fail conformance report.",
			"item": [
				{
					"name": "Editable: prefill",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('200 with prefill', () => { pm.response.to.have.status(200); pm.expect(pm.response.json().patientName).to.be.a('string'); });"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/11111111-1111-1111-1111-111111111111",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"11111111-1111-1111-1111-111111111111"
							]
						}
					}
				},
				{
					"name": "Editable: partial save reports missing fields",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('saved with missing fields listed', () => { pm.response.to.have.status(200); const r = pm.response.json(); pm.expect(r.saved).to.be.true; pm.expect(r.isComplete).to.be.false; pm.expect(r.missingFields).to.not.be.empty; });"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/11111111-1111-1111-1111-111111111111",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"11111111-1111-1111-1111-111111111111"
							]
						},
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"patientName\": \"Conformance\",\n  \"patientSurname\": \"Test\"\n}"
						}
					}
				},
				{
					"name": "Editable: validate without saving",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('dry-run returns missing fields', () => { pm.response.to.have.status(200); pm.expect(pm.response.json().missingFields).to.not.be.empty; });"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/11111111-1111-1111-1111-111111111111/validate",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"11111111-1111-1111-1111-111111111111",
								"validate"
							]
						},
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"patientName\": \"Conformance\"\n}"
						}
					}
				},
				{
					"name": "Editable: list documents",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('document list returns', () => { pm.response.to.have.status(200); pm.expect(pm.response.json()).to.be.an('array'); });"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/11111111-1111-1111-1111-111111111111/documents",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"11111111-1111-1111-1111-111111111111",
								"documents"
							]
						}
					}
				},
				{
					"name": "Complete: admission reads complete",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('isComplete is true', () => { pm.response.to.have.status(200); pm.expect(pm.response.json().isComplete).to.be.true; });"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/22222222-2222-2222-2222-222222222222",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"22222222-2222-2222-2222-222222222222"
							]
						}
					}
				},
				{
					"name": "Locked: save refused 409",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('409 with reason', () => { pm.response.to.have.status(409); pm.expect(pm.response.json().title).to.include('no longer'); });"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/33333333-3333-3333-3333-333333333333",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"33333333-3333-3333-3333-333333333333"
							]
						},
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"patientName\": \"x\"\n}"
						}
					}
				},
				{
					"name": "Locked: read still works",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('reads stay open on locked bookings', () => pm.response.to.have.status(200));"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/33333333-3333-3333-3333-333333333333",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"33333333-3333-3333-3333-333333333333"
							]
						}
					}
				},
				{
					"name": "Forbidden facility: 403",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('facility access denied', () => { pm.response.to.have.status(403); pm.expect(pm.response.json().title).to.include('Facility'); });"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/44444444-4444-4444-4444-444444444444",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"44444444-4444-4444-4444-444444444444"
							]
						}
					}
				},
				{
					"name": "Expired link: 410",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('expired link is gone', () => { pm.response.to.have.status(410); pm.expect(pm.response.json().title).to.include('expired'); });"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/00000000-0000-0000-0000-000000000000",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"00000000-0000-0000-0000-000000000000"
							]
						}
					}
				},
				{
					"name": "No token: 401",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('unauthenticated is refused', () => pm.response.to.have.status(401));"
								]
							}
						}
					],
					"request": {
						"method": "GET",
						"url": {
							"raw": "{{baseUrl}}/preadmit/v1/admissions/11111111-1111-1111-1111-111111111111",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"preadmit",
								"v1",
								"admissions",
								"11111111-1111-1111-1111-111111111111"
							]
						},
						"auth": {
							"type": "noauth"
						}
					}
				}
			]
		}
	]
}