Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Purpose

This WS allows to create Specimen entity by employees without submitting Encounter Data Package.

Specification

Link

 Apiary

Resource

 api/patients/patient_id/specimens

Scope

 specimen:write

Components

 Specimen

Microservices

 

Protocol type

 REST

Request type

 POST

Sync/Async

 Async

Public/Private/Internal

 Public

...

  • Get Patient identifier from the URL

  • Check it exists in the DB

    • Return 404 ('Person is not found') in case of error

  • Validate patient is an active person or preperson

    • in case of error - return 409 ('Patient Person is not active')

  • Validate person'sverification_status is not equal to NOT_VERIFIED (not for preperson).

    • in case NOT_VERIFIED - return error 409, "Patient is not verified"

...

  • Check each value is valid Reference on another Specimen resource

  • Validate referenced Specimen:

    • Check it belongs to the same patient ($.subject)

      • in case of error - return 422 ('Specimen with such id is not found')

    • Check status is available

      • in case of error - return 422 ('Invalid specimen status')

...

Validate each value in $.request, array of Reference type, if submitted

  • Array item has type of {Reference} to Service Request resource

    • in case of error - return 422 ('value is not allowed in enum')

  • Service Request exists in the DB and relates to the patient ($.subject)

    • in case of error - return 422 ("Service request with such id is not found")

  • Service Request’s status is active or program_processing_status is in_progress (any status is valid in case program_processing_status= in_progress)

    1. in case of error - return 422 ("Service request is not active or in progress")

  • If used_by_legal_entity is set in the Service request (program_processing_status=in_progress), then check it matches the client_id from token

    • in case of error - return 422 ("Service request is used by another must be related to the same legal entity")

  • Check if Service Request’s expiration date is less then or equal to current date

    1. in case of error - return 422 ("Service request expiration date must be greater than or equal to current date")

...

  • Check there is no specimen with the same ID in the DB

    • in case of error return 422 “Specimen with such id <id> already exists“

8. Managing organization

Validate value in the field $.managing_organization, Reference on legal entity, required

  • Check legal entity id exists in DB

    1. in case of error return 422 "Legal entity with such id is not found"

    Check $.managing_organization.identifier.value is equal to client_id from token

    • in case of error return 422 "Managing_organization does not correspond to user's legal_entity"

...

  • Check it references to employee or patient resource

    • in case of error - return 422 ('value is not allowed in enum')

  • If collector is an employee:

    • Check it exists in the DB

      • in case of error - return 422 ('Employee with such ID is not found')

    • Check it is active and approved

      • in case of error - return 422 ('Invalid employee status')

    • Check that employee is related to the legal entity (client_id) from token

      • in case of error - return 422 ('Employee doesn't belong to your legal entity')

  • If collector is a patient:

    • Check it is an existing current patient in the DB (mongosubject)

      • in case of error - return 422 ('Patient not found')

    • Check it is active

      • in case of error - return 422 ('Patient is not active')

2. Collected

      • In case collector is patient it must be the current patient')

2. Collected

Validate there is one of the required $.collection.collected_[x] field is set: collected_date_time or collected_period.

  • Return 422 ('Only At least one of the parameters must be present') in case more then one submitted

...

  • Validate value with schema of the {Period} type

    • in case of error - return 422 schema validation error

  • Check if period start is greater then (current_date - SPECIMEN_MAX_DAYS_PASSED) date

    • in case of error - return 422 ('Date must be greater than <current date - SPECIMEN_MAX_DAYS_PASSED>')

  • Check if period start is less then or equal to current datetime

    • in case of error - return 422 ('Start date must be in past')

  • Check end >= start

    • in case of error - return 422 ('End date must be greater than or equal the start date')

  • Check end <= current datetime (is not in the future)

    • in case of error - return 422 ('End date must be in past')

...

  • Check that $.collection.quantity.system is eHealth/ucum/units dictionary, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check that $.collection.quantity.code comply with $.collection.quantity.system, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check $.collection.quantity.value is not empty, is float, greater than zero

    • in case of error - return corresponding 422 schema validation error('value must be greater than 0')

  • Check that $.collection.quantity.value >= sum($.container.specimen_quantity.value)

    • in case of error - return 422 ('Collected quantity must not be exceeded by the specimen quantity distributed among the containers')

...

  • Check that $.collection.duration.system is eHealth/ucum/units dictionary, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check that $.collection.duration.code comply with $.collection.duration.system and one of SPECIMEN_DURATION_ALLOWED_CODES, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check $.collection.duration.value is not empty, is float, greater than zero

    • in case of error - return corresponding 422 schema validation error('must be greater than 0')

5. Method

Validate value in the field $.collection.method , CodeableConcept type, optional.

...

  • Check that $.container.capacity.system is eHealth/ucum/units dictionary, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check that $.container.capacity.code comply with $.container.capacity.system, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check $.container.capacity.value is not empty, is float, greater than zero

    • in case of error - return corresponding 422 schema validation error('value must be greater than 0')

4. Specimen quantity

Validate value in the field $container.specimen_quantity, SimpleQuantity type, required

  • Check that $.container.specimen_quantity.system is eHealth/ucum/units dictionary, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check that $.container.specimen_quantity.code comply with $.container.specimen_quantity.system, required

    • in case of error - return 422 ('value is not allowed in enum')

  • Check $.container.specimen_quantity.value is not empty, is float, greater than zero

    • in case of error - return corresponding 422 schema validation error('value must be greater than 0')

  • Check that $.container.specimen_quantity.code matches to $.collection.quantity.code

    • in case of error - return 422 (Does not match the code of the collected quantity)

...

  1. Save signed content to media storage, in the bucket pointed in MEDIA_STORAGE_SPECIMEN_BUCKET chart parameter

  2. Generate accession_identifier number:

    1. Generate requisition number (see Human readable requisition number) based on the specimen id. Note: requisition number should be unique for each specimen and should not match with number of another entities. So, if generated number match to existing in DB - it should be regenerated

    2. Encode and set it into $.accession_identifier attribute

  3. Set display_value for:

    1. registered_by attribute

    2. managing_organization attribute

    3. collection.collector attribute, only if type is employee (not patient)

  4. Set context, received_time, status_reason, collection.procedure to null

  5. Set subject with hashed mpi identifier

  6. Save data to specimens collection in DB according to /wiki/spaces/SPECIMEN/pages/17548214286 RC.__Specimen data model_EN

  7. Save link from media storage to the $.signed_content_links field in specimens collection

  8. Create job and return it’s id.

Response structure

See on Apiary

Example:

Expand
titleResponse example
Code Block
{
  "data": {
    "status": "pending",
    "eta": "2018-08-02T10:45:16.000Z",
    "links": [
      {
        "entity": "job",
        "href": "/Jobs/NBXk9EyErUZv1RhXgyvgg"
      }
    ]
  },
  "meta": {
    "code": 202,
    "url": "http://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda"
  }
}

HTTP status codes

HTTP status code

Message

What caused the error

200

400

 

Invalid signed content

 

401

Invalid access token

 

403

Access denied. Party is deceased

403

Access denied. Party is

deceased

not verified

403

Your scope does not allow to access this resource. Missing allowances: specimen:

cancel

write

 

 

404

Person is not found

409

client_id refers to legal entity that is not active

409

Patient is not verified

  • User is not allowed to perform actions with an enity that belongs to another legal entity

  • Employee is not the one who registered the specimen, doesn't have an approval or required employee type

  • Specimen in status <status> cannot be cancelled'

  • Specimen with such id

    409

    Person is not active

    422

    Collected quantity must not be exceeded by the specimen quantity distributed among the containers

    422

    Date must be greater than <current date - SPECIMEN_MAX_DAYS_PASSED>

    422

    Does not match the code of the collected quantity

    422

    Does not match the signer drfo

  • Invalid signed content

  • Service request expiration

    422

    Employee doesn't belong to your legal entity

    422

    Employee with such ID is not found

  • Invalid specimen status

  • value is not allowed in enum

  • Service request not found

  • Service request is not active or in progress

  • Service request is used by another legal entity

  • 422

    End date must be greater than or equal

    to current Legal entity with such id is not found

    the start date

  • User is not allowed to register a specimen for the employee

  • Invalid employee status

  • Employee doesn't belong to your legal entity

  • Specimen with id <id> already exists

  • Only one

    422

    End date must be in past

    422

    Identifier already exists in the specimen

    422

    In case collector is patient it must be the current patient

    422

    Invalid employee status

    422

    Invalid specimen status

    422

    Legal entity not found

    422

    Managing_organization does not correspond to user's legal_entity

  • Employee not found

  • Patient not found

  • Patient is not active

  • 422

    must be greater than 0

    422

    Must be in past

    422

    Only one of the parameters must be present

  • Date must be greater than <current date - SPECIMEN_MAX_DAYS_PASSED>

  • Must be in past

  • Start date must be in past

  • End

    422

    Person is not active

    422

    Person is not found

    422

    schema validation error

    422

    Service request expiration date must be greater than or equal

    the start

    to current date

  • End date must be in past

  • 'Collected quantity must not be exceeded by the specimen quantity distributed among the containers

  • Does not match the code of the collected quantity

  •  

    422

    Service request is not active or in progress

    422

    Service request must be related to the same legal entity

    422

    Service request not found

    422

    Specimen not found

    422

    Specimen with id <id> already exists

    422

    Start date must be in past

    422

    User is not allowed to register a specimen for the employee

    422

    value is not allowed in enum

    422

    value must be greater than 0