Existing method: createComposition
Implemented changes:
…
Validation data request
prechecks - Initial checks of request input data
Check for “encounter.value” attribute:
If another Composition with the same type and category in the "Final" status has the same encounter.value - return 1127 (FINAL_COMPOSITION_FOR_ENCOUNTER_ALREADY_EXISTS)
If “relatesTo” isn’t null:
For Newborn Composition:
Validate that replacement is enabled
In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)
For Temporary Disability Composition:
If Composition.subject=person in current composition, Composition.subject = preperson in indicated composition in relatesTo.target.identifier and composition.status is FINAL, then the Refinement process is initiated
If Composition.status in indicated composition in relatesTo.target.identifier is ENTERED_IN_ERROR and replacement is enabled, then the Raplacement process is initiated
In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)
in other cases - return 1160 (INVALID_REPLACEMENT_ARGUMENT)
For Newborn Composition:
Checking for an already created Composition for preperson (“subject” attribute) which are according such requirements: Composition.type is Newborn and Composition.status isn’t ENTERED_IN_ERROR:
In case of existing appropriate Compositions - return 1002 (COMPOSITION_ALREADY_EXISTS_FOR_SUBJECT)
If in item b. was initiated Replacement flow:
Checking the Composition.type in current Composition and Composition.type indicated in relatesTo.target.identifier
In case of difference - return 1146 (CANT_REPLACE_DIFFERENT_TYPE)
Check if the indicated Composition is last in the chain:
In case of error (indicated Composition isn’t last in the chain) - return 1153 (CANT_AMEND_IS_APPENDED)
Check if the indicated Composition has ENTERED_IN_ERROR status:
In case of error (indicated Composition hasn’t ENTERED_IN_ERROR status) - return 1148 (CANT_REPLACE_IS_APPENDED)
Check if the indicated Composition was canceled with Replacement’s reason
In case of right Replacement’s reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_REPLACEMENT_CANCEL_TIMEOUT_NEWBORN. In case of error - return 1039 (INVALID_PERIOD)
In case of common cancelation reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_PERIOD_START_NEWBORN. In case of error - return 1039 (INVALID_PERIOD)
For Temporary Disability Composition:
If in item b. was initiated Replacement flow:
Checking the Composition.type in current Composition and Composition.type indicated in relatesTo.target.identifier
In case of difference - return 1146 (CANT_REPLACE_DIFFERENT_TYPE)
Check if the indicated Composition is last in the chain:
In case of error (indicated Composition isn’t last in the chain) - return 1153 (CANT_AMEND_IS_APPENDED)
Check if the indicated Composition has ENTERED_IN_ERROR status:
In case of error (indicated Composition hasn’t ENTERED_IN_ERROR status) - return 1148 (CANT_REPLACE_IS_APPENDED)
Check if the indicated Composition was canceled with Replacement’s reason
In case of right Replacement’s reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_REPLACEMENT_CANCEL_TIMEOUT_DISABILITY. In case of error - return 1039 (INVALID_PERIOD)
In case of common cancelation reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_PERIOD_START_DISABILITY. In case of error - return 1039 (INVALID_PERIOD)
Check “event.period.start” attribute for the possibility to specify in the future:
If event.period.start is specified in the future and it's not PREGNANCY category - return 1039 (INVALID_PERIOD)
Check the time difference between the start date (event.period.start) and the task creation date:
If the difference is more than allowed - return 1040 (PERIOD_TOLERANCE_EXCEEDED)
Check for TREATMENT_VIOLATION_DATE extension:
-search for a compositions inmc.composition
by subject, and dates and checkrelates_to
:in case when
relatesTo
is absent take value fromTREATMENT_VIOLATION_DATE
from the payload and takeevent.period.start
from the payload. Validate:event.period.start
(payload) < TREATMENT_VIOLATION_DATE(payload) < now() ORevent.period.end
from current composition (payload) (choose the date that comes earlier). In case of error - return 1172 (Treatment violation date should be >= composition start && <= now)
in case when value in
relatesTo.code
isappends
ortransforms
take value fromTREATMENT_VIOLATION_DATE
from the payload and takeevent.period.start
from the first composition in the chain (the oldest one, in whichrelatesTo
is empty). Validate:event.period.start
(related oldest composition1) < TREATMENT_VIOLATION_DATE(payload) < now() ORevent.period.end
from current composition (payload) (choose the date that comes earlier). In case of error - return 1172 (Treatment violation date should be >= composition start && <= now)
in case when value in
relatesTo.code
isreplaces
+ optionallyappends
/transforms
ORreplaces
1+replaces
2 + optionallyappends
/transforms
take value fromTREATMENT_VIOLATION_DATE
from the payload and takeevent.period.start
from the first composition withreplaces
inrelatesTo.code
in the chain (the oldest one, in whichrelatesTo
isreplaces
)
-in case if there are more than one composition withreplaces
inrelatesTo.code
– takeevent.period.start
from the first oldest one in the chain with status=FINAL
validate:event.period.start
(related oldest composition withreplaces
type) < TREATMENT_VIOLATION_DATE(payload) < now() ORevent.period.end
from current composition (payload) (choose the date that comes earlier
- If TREATMENT_VIOLATION_DATE is outside the period of incapacity (event.period.start - event.period.end) - return 1172 (Treatment violation date should be >= composition start && <= now)
If in item a. wasn’t initiated Replacement flow:
In case of IS_FORCE_RENEW=true - the function completes it's execution and does not perform further checks
Check for IS_FOREIGN_TREATMENT extension:
If extension IS_FOREIGN_TREATMENT= true - checks 3 and 4 don’t perform
Check of maximum length of one link of a medical opinion (disabilitySingleSpanFilter)
In case of error - return 1039 (INVALID_PERIOD), 1031 (DURATION_SINGLE_PERIOD_TOO_LONG)
Check for event.period.start attribute (periodStartFilter)
In case of error - return 1039 (INVALID_PERIOD), 1040 (PERIOD_TOLERANCE_EXCEEDED)
Search for previous compositions with the same type and category as in the request, overlapping with the period of validity for this composition for at least 1 day
If previous compositions wasn’t found - the function completes it's execution
If previous compositions was found - check validity period of compositions
In case of error - return 1143 (NEW_START_DATE_IS_BEFORE_PREVIOUS_START_DATE), 1103(SAME_END_DATE_FOR_NEW_AND_EXISTING_COMPOSITION)
Check for the maximum total length of the validity period (disabilityTotalSpanFilter)
In case of error - return 1039 (INVALID_PERIOD), 1032 (DURATION_TOTAL_PERIOD_TOO_LONG)
Additional checks for PREGNANCY category:
If event.period.start <= taskCreated - the procedure begins to create a New Pregnancy Composition
Check for “relatesTo” attribute:
If it’s not null - return 1218 (NEW_PREGNANCY_COMPOSITION_CANT_HAVE_RELATIONSHIPS)
Check for the length of the period of incapacity:
If it’s not match with value in EMAL_VALIDATION_PREGNANCY_NEW_COMPOSITION_ALLOWED_PERIODS - return 1219 (NEW_PREGNANCY_COMPOSITION_INVALID_PERIOD)
Check for “event.period.start” attribute:
If event.period.start > taskCreated - return 1220 (NEW_PREGNANCY_COMPOSITION_INVALID_PERIOD_STARTS_IN_FUTURE)
If event.period.start > taskCreated - the procedure begins to create a Prolongation for Previous Pregnancy Composition (appendingPregnancyComposition)
Check the connections between the first and second Compositions (in “relatesTo” attribute) and check for “event.period.start” attribute in second Composition:
If event.period.start < taskCreated - return 1222 (PREGNANCY_COMPOSITION_CONTINUATION_INVALID_PERIOD_STARTS_IN_PAST)
Check for “event.period.start” attribute:
If Event.period.startTempDisabilityComposition2 isn’t equal to Event.period.endTemporaryDisabilityComposition1+1day - return 1223 (PREGNANCY_COMPOSITION_CONTINUATION_INVALID_PERIOD_WRT_PREVIOUS)
Check for the length of the period of incapacity for Prolongation Pregnancy Composition (appendedPregnancyAllowedPeriod):
If it’s not match with value in EMAL_VALIDATION_PREGNANCY_APPENDED_COMPOSITION_ALLOWED_PERIOD - return 1224 (PREGNANCY_COMPOSITION_CONTINUATION_INVALID_PERIOD_LENGTH)
Check for “relatesTo” attribute:
If relatesTo.code = appends and it’s not a first prolongation - return 1225 (PREGNANCY_COMPOSITION_DEPTH_EXCEEDED)
If “relatesTo.code” it’s not “appends“ - return 1221 (PREGNANCY_COMPOSITION_INVALID_RELATIONSHIP).