ЕСОЗ - публічна документація

API. Create Care Plan activity_EN

Purpose

This WS allows to add activity to the specified Care plan.

Key points

  1. With one request can be added only one activity to the Care plan

  2. Activity can be added by the employee who has an Approval granted by the patient on write Care plan resource

  3. Activity adds in async way. Result of the activity addition job should be link on the created activity (look at Get Care plan activity by ID).

  4. Activity should be signed with DS. Signed content stores in the media storage.

Specification

Apiary

Authorization

  • Verify the validity of access token

    • Return (401, 'Invalid access token') in case of validation fails

  • Verify that token is not expired

    • in case of error - return (401, 'Invalid access token')

  • Check user scopes in order to perform this action (scope = 'care_plan:write')

    • Return (403, 'Your scope does not allow to access this resource. Missing allowances: care_plan:write') in case of invalid scope(s)

  • Extract client_id from token

  • Check legal entity status is ACTIVE

    • In case of error - return 409 ('client_id refers to legal entity that is not active')

  • Check legal entity type in ME_ALLOWED_TRANSACTIONS_LE_TYPES config parameter

    • in case of error - return 409 ('client_id refers to legal entity with type that is not allowed to create medical events transactions')

Validate Care plan

  • Get Care plan identifier from the URL

  • Check Care plan:

    • belongs to patient (from url)

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

    • is not in final status

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

    • Care plan’s period.end >= current date.

      • in case of error - return 422 ('Care Plan end date is expired')

Validate Patient

  • Get person_id from URL

  • Validate patient status is active

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

  • Validate patient's verification_status is not equal to NOT_VERIFIED.

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

Validate User

  • Extract user_id from token.

  • Check user has an active and approved employee from legal entity (token) that:

    • has an active Approval granted by the Patient on write the Care plan resource (care plan id from URL)

      • Return 403 ('Access denied') in case employee has no Approval on write

Validate Digital Sign

  • Validate request is signed

    • in case of error - return 422 (“document must be signed by 1 signer but contains 0 signatures”)

  • Check DS is valid and not expired

  • Validate that DS belongs to the author of the activity

    • Check that DRFO from DS and user's party.tax_id matches

      • in case of error - return 409 (“Signer DRFO doesn't match with requester tax_id“)

Validate activity

Activity should be validated. User fills following fields in the activity:

Validate activity identifier

Validate value in the field $.id, required

  • Check it is unique within Care plan and has UUID format

    • Return 422 ("Activity with such id already exists")

Validate care plan identifier

As care plan identifier should be contained in signed content, $.care_plan required in the request body.

  • Check value matches with care plan identifier from URL

    • in case of error - return 409 ('Care Plan from url does not match to Care Plan ID specified in body')

Validate activity author

Validate value in the field $.author, required

  • Check employee belongs to the user and legal entity (from token)

  • Employee is:

    • an employee who has active Approval on write the Care plan

    • belongs to user

      • in case of error - return 422 ('User is not allowed to create care plan activity for the employee')

Validate activity detail

1. Kind

Validate value in the field $.detail.kind, required

  • Check value in enum: medication_request, service_request

    • Return 422 ('value is not allowed in enum')

2. Product

Validate value in the field $.detail.product_reference, required

If $detail.kind=medication_request:

  • Check the value is valid reference on medication resource.

    • Return 422 ('Cannot refer to service for kind = medication_request')

  • Check medication:

    • is active

      • in case of error - return 422 ('Medication should be active')

    • type is INNM_DOSAGE

      • in case of error - return 422 ('Medication does not exist')

  • Check there is no duplicated activities (status=scheduled, in_progress) with the same medication in the Care plan

    • Return 422 (“Another activity with status ‘scheduled' or ‘in_progress' already exists in the current Care plan”)

If $.detail.kind=service_request:

  • Check that value is a reference on service or service_group

    • Return 422 ('Cannot refer to medication for kind = service_request')

  • Check service or service_group is active

    • Return 422 ('<Service/Service group> should be active')

  • Check there is no activities (status=scheduled, in_progress) with the same service or service_group in the Care plan

    • Return 422 (“Another activity with status ‘scheduled' or ‘in_progress' already exists in the current Care plan“)

3. Reason code

Validate value in the field $.detail.reason_code, if submitted

  • Check that value matches with values in eHealth/ICD10_AM/condition_codes dictionary

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

4. Reason reference

Validate value in the field $.detail.reason_reference, if submitted

  • Check that value is an array with references of condition, observation or diagnostic report types.

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

  • Check that each reference:

    • is valid ME

    • belongs to the patient ($.subject)

      • in case of error - return 422 ('<medical event type> with such ID is not found')

5. Goal

Validate value in the field $.detail.goal, if submitted

  • Check that value matches with values in eHealth/care_plan_activity_goals dictionary

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

6. Quantity

Validate value in the field $.quantity, if submitted

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

    • Return 422 schema validation error

  • Set remaining_quantity.value = $.quantity.value

7. Scheduled

If submitted, validate there is one of the $.detail.scheduled_[x] field: scheduled_timing, scheduled_period or scheduled_string.

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

Validate value in scheduled_timing, if submitted:

  • Validate value with schema of Timing type

    • in case of error - return 422 schema validation error

  • If submitted, check values of the event within $.CarePlan.Period value

    • in case of error - return 422 ('event is not within care plan period range')

  • If submitted, check bounds_period within $.CarePlan.Period value

    • in case of bounds_period.end validation error - return 422 ('Period end time must be within care plan period range, after period start date')

    • in case of bounds_period.start validation error - return 422 ('Period start time must be within care plan period range')

  • If submitted, check bounds_duration within $.CarePlan.Period value. Calculate bounds start date as care plan period start date if activity creates before care plan has started, else if activity creates during care plan performing - bound start date calculates as activity creation date. Bounds end date as bounds start date plus count of days specified in bounds_duration.

    • If comparator field in bounds_duration - use it to compare bounds_duration value and care plan duration (possible values >, >=, =, <=, <)

    • in case of error - return 422 ('Bounds duration must be within care plan period range')

  • If submitted, check when field values are in EVENT_TIMING dictionary

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

  • If submitted, check bounds_range within $.CarePlan.Period value: calculate bounds start - end date for bounds_range.low and bounds_range.high as described for bounds_duration (but w/o comparator field). Also, validate low.code = high.code, high.value > low.value

    • in case bounds_range.low validation error - return 422 ('low must be within care plan period range, less than high, have the same code as high')

    • in case bounds_range.high validation error - return 422 ('high must be within care plan period range')

Validate value in scheduled_period, if submitted:

  • Validate value with schema of the Period type

    • in case of error - return 422 schema validation error

  • Check values within $.CarePlan.Period

    • in case period.end validation error - return 422 ('Period end time must be within care plan period range, after period start date')

    • in case period.start validation error - return 422 ('Period start time must be within care plan period range')

8. Location

Validate value in the field $.detail.location, if submitted

  • Check the value is valid reference on division resource

  • Check the division is active and division’s legal entity has active status

    • Return 422 ('Division is not active')

9. Performer

Validate value in the field $.detail.performer, if submitted

  • Check the value is valid reference o employee resource

  • Check employee is active and approved

    • Return 422 ('Invalid employee status')

10. Daily amount

Validate value in the field $.detail.daily_amount, if submitted.

  • Check activity kind is medication_request

    • Return 422 ('Field is allowed for medication request activities only') in case kind is not medication_request

11. Medical program

Validate value in the field $.program, if submitted

  • Сheck program exists and active

    • in case not found or is_active==false return 404 "Program not found"

  • Validate product is program participant:

    • If product is medication - validate that medication has brand that is an active member of the program (program_medications table)

      • in case not found or is_active==false return 422 "Medication is not included in the program"

    • If product is service - validate that service is an active member of the program

      • in case not found or is_active==false return 422 "Service is not included in the program"

    • if product is service_group - validate that service group is an active member of the program

      • in case not found or is_active==false return 422 "Service group is not included in the program"

  • Validate medical program settings (prm.medical_programs table):

    • if there is a parameter SPECIALITY_TYPES_ALLOWED:

      • Check author’s speciality is present in SPECIALITY_TYPES_ALLOWED

        • in case of error - return 422 “Author’s specialty doesn't allow to create activity with medical program from request”

    • if there is a parameter CONDITIONS_ICD10_AM_ALLOWED or/and CONDITIONS_ICPC2_ALLOWED:

      • Check related Care plan has condition codes in addresses field that correspond to codes pointed in CONDITIONS_ICD10_AM_ALLOWED or/and CONDITIONS_ICPC2_ALLOWED (depending on dictionary - eHealth/ICD10_AM/condition_codes or eHealth/ICPC2/condition_codes)

        • in case of error - return 422 “Care plan diagnosis is not allowed for the medical program“

    • If there is a parameter PROVIDING_CONDITIONS_ALLOWED:

      • Check related Care plan has a value in terms_of_service field that is included in the list of PROVIDING_CONDITIONS_ALLOWED parameter

        • in case of error - return 422 “Care plan’s terms of service are not allowed for the medical program“

SELECT *

FROM medications MI -- 2nd level: Medication - type = INNM_DOSAGE

INNER JOIN ingredients I

ON I.medication_child_id = MI.id

AND I.is_primary =TRUE

INNER JOIN medications MED -- 3rd level: Medication - type = BRAND

ON MED.type == BRAND

AND I.parent_id = MED.id

AND MED.is_active == TRUE

INNER JOIN program_medications MP

ON MP.medical_program_id == `$.product.identifier.value`

MED.id = MP.medication_id

AND MP.is_active == TRUE

AND MP.medication_request_allowed == TRUE

WHERE MI.id == $.medication_id

AND MI.type == INNM_DOSAGE

AND MI.is_active == TRUE

12. Do not perform flag

Validate value in the field $.do_not_perform

  • Check it is false

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

Service logic

  1. Save signed content to media storage

  2. Save data to care_plan_activities collection in DB according to https://e-health-ua.atlassian.net/wiki/spaces/EH/pages/2125038856/Care+plan+data+model+EN

  3. Save link from media storage to the $.signed_content_links field in care plan activities collection

  4. If Care plan has status = new:

    • Set care plan status = active

    • Check if patient has another active or/and new Care plans with such condition code in the addresses field and the same terms of service:

      • If such Care plans found - set these Care plans statuses to TERMINATED

  5. Create job and return it’s id.

ЕСОЗ - публічна документація