From e7969f4ed53cd0dd4c99f4ff7eabaadaeeeeb000 Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Fri, 19 Jul 2019 13:21:15 +0200 Subject: [PATCH 1/3] Adds FHIR profiles for care related FHIR resources. --- app/src/test/resources/data.sql | 21 +++++----- .../fhir/metadata/model/AbstractRule.java | 13 +++++++ .../V1.1.0.40_0_0__DHIS2_FHIR_ID.sql | 39 +++++++++++++++++++ .../EnrollmentRuleRepositoryRestDocsTest.java | 4 ++ ...izationUnitRuleRepositoryRestDocsTest.java | 4 ++ ...rogramStageRuleRepositoryRestDocsTest.java | 4 ++ ...ackedEntityRuleRepositoryRestDocsTest.java | 4 ++ 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 fhir/src/main/resources/db/migration/production/V1.1.0.40_0_0__DHIS2_FHIR_ID.sql diff --git a/app/src/test/resources/data.sql b/app/src/test/resources/data.sql index 9e9babe3..cd52e6a1 100644 --- a/app/src/test/resources/data.sql +++ b/app/src/test/resources/data.sql @@ -475,14 +475,14 @@ INSERT INTO fhir_tracked_entity(id, version, name, description, tracked_entity_r VALUES ('4203754d21774a4486aa2de31ee4c8ee', 0, 'Person', 'Tracked entity for a patient.', 'NAME:Person', 'ID:Ewi7FUfcHAD'); -- Rule FHIR Patient to tracked entity type Person -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, transform_imp_script_id) -VALUES ('5f9ebdc9852e4c8387ca795946aabc35', 0, 'FHIR Patient to Person', NULL, TRUE, 0, 'PATIENT', 'TRACKED_ENTITY', '72451c8f7492470790b8a3e0796de19e'); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, transform_imp_script_id, simple_fhir_id) +VALUES ('5f9ebdc9852e4c8387ca795946aabc35', 0, 'FHIR Patient to Person', NULL, TRUE, 0, 'PATIENT', 'TRACKED_ENTITY', '72451c8f7492470790b8a3e0796de19e', TRUE); INSERT INTO fhir_tracked_entity_rule (id, tracked_entity_id, org_lookup_script_id, loc_lookup_script_id) VALUES ('5f9ebdc9852e4c8387ca795946aabc35', '4203754d21774a4486aa2de31ee4c8ee', '25a97bb47b394ed48677db4bcaa28ccf', 'ef90531f443848bd83b36370dd65875a'); -- Rule FHIR Related Person to tracked entity type Person -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, transform_imp_script_id, contained_allowed) -VALUES ('52227dd9c79c478b92af9aa1f33c76fd', 0, 'FHIR Related Person to Person', NULL, TRUE, 0, 'RELATED_PERSON', 'TRACKED_ENTITY', 'c6b2d08d3a73434ea5afee0ff13549a1', TRUE); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, transform_imp_script_id, contained_allowed, simple_fhir_id) +VALUES ('52227dd9c79c478b92af9aa1f33c76fd', 0, 'FHIR Related Person to Person', NULL, TRUE, 0, 'RELATED_PERSON', 'TRACKED_ENTITY', 'c6b2d08d3a73434ea5afee0ff13549a1', TRUE, TRUE); INSERT INTO fhir_tracked_entity_rule (id, tracked_entity_id, tei_lookup_script_id) VALUES ('52227dd9c79c478b92af9aa1f33c76fd', '4203754d21774a4486aa2de31ee4c8ee', '26e8880864ee446980837962b74ac48a'); @@ -780,8 +780,8 @@ VALUES ('5090c485a2254c2ea8f695fa74ce1618', 0, '655f55b538264fe7b38e1e29bcad09ec UPDATE fhir_executable_script SET base_executable_script_id = (SELECT id FROM fhir_executable_script WHERE id = '25a97bb47b394ed48677db4bcaa28ccf') WHERE id='5090c485a2254c2ea8f695fa74ce1618'; -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, applicable_exp_script_id, transform_exp_script_id, exp_enabled, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled) -VALUES ('b9546b024adc4868a4cdd5d7789f0df0', 0, 'DHIS Organization Unit to FHIR Location', NULL, TRUE, 1, 'LOCATION', 'ORGANIZATION_UNIT', FALSE, NULL, 'b918b4cd67fc4d4d9b7491f98730acd7', true, true, true, true); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, applicable_exp_script_id, transform_exp_script_id, exp_enabled, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, simple_fhir_id) +VALUES ('b9546b024adc4868a4cdd5d7789f0df0', 0, 'DHIS Organization Unit to FHIR Location', NULL, TRUE, 1, 'LOCATION', 'ORGANIZATION_UNIT', FALSE, NULL, 'b918b4cd67fc4d4d9b7491f98730acd7', true, true, true, true, true); INSERT INTO fhir_organization_unit_rule(id, identifier_lookup_script_id, mo_identifier_lookup_script_id) VALUES ('b9546b024adc4868a4cdd5d7789f0df0', '5090c485a2254c2ea8f695fa74ce1618', '66d12e44471c4318827a0b397f694b6a'); @@ -833,8 +833,9 @@ VALUES ('50544af8cf524e1e9a5dd44c736bc8d8', 0, '53fdf1da61454e259d25fc41b9baf09f 'Transforms DHIS Org Unit to FHIR Organization', 'TRANSFORM_DHIS_ORG_UNIT_FHIR_ORG', 'Transforms DHIS Organization Unit to FHIR Organization.'); -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, applicable_exp_script_id, transform_exp_script_id, exp_enabled, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled) -VALUES ('d0e1472a05e647c9b36bff1f06fec352', 0, 'DHIS Organization Unit to FHIR Organization', NULL, TRUE, 0, 'ORGANIZATION', 'ORGANIZATION_UNIT', FALSE, 'a84850454d624b3a9cfd5c36760b8d45', '50544af8cf524e1e9a5dd44c736bc8d8', TRUE, TRUE, TRUE, TRUE); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, applicable_exp_script_id, transform_exp_script_id, exp_enabled, fhir_create_enabled, fhir_update_enabled, +fhir_delete_enabled, simple_fhir_id) +VALUES ('d0e1472a05e647c9b36bff1f06fec352', 0, 'DHIS Organization Unit to FHIR Organization', NULL, TRUE, 0, 'ORGANIZATION', 'ORGANIZATION_UNIT', FALSE, 'a84850454d624b3a9cfd5c36760b8d45', '50544af8cf524e1e9a5dd44c736bc8d8', TRUE, TRUE, TRUE, TRUE, TRUE); INSERT INTO fhir_organization_unit_rule(id, identifier_lookup_script_id) VALUES ('d0e1472a05e647c9b36bff1f06fec352', '66d12e44471c4318827a0b397f694b6a'); INSERT INTO fhir_script (id, version, code, name, description, script_type, return_type) @@ -2886,9 +2887,9 @@ VALUES ('aa956fdb01074cb7b5c1ab6567162d9d', 0, 'e885f646626940c5a8126c2aa081e239 INSERT INTO fhir_resource_mapping(id, version, fhir_resource_type, tracked_entity_fhir_resource_type, imp_tei_lookup_script_id, imp_enrollment_org_lookup_script_id, imp_enrollment_date_lookup_script_id) VALUES('b6650f008462419bb9926775ca0a26cb', 0, 'CARE_PLAN', 'PATIENT', '762b4137a98b4b10a0f5629d93e23461', '25a97bb47b394ed48677db4bcaa28ccf', '0f79f2c88b5411e981f7ebd621029975'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id, simple_fhir_id) VALUES('c4e17e7d880e45b59bc5568da8c79742', 0, 'CARE_PLAN', 'ENROLLMENT', 'Default FHIR Care Plan to DHIS2 Enrollment', 'Default rule that transforms a FHIR Care Plan to a DHIS2 Enrollment.', -true, true, false, false, true, true, true, false, -2147483648, 'aa956fdb01074cb7b5c1ab6567162d9d'); +true, true, false, false, true, true, true, false, -2147483648, 'aa956fdb01074cb7b5c1ab6567162d9d', TRUE); INSERT INTO fhir_enrollment_rule(id, program_ref_lookup_script_id) VALUES ('c4e17e7d880e45b59bc5568da8c79742', '79d297065c1c47c582456069036072f8'); UPDATE fhir_rule SET evaluation_order = 100 WHERE fhir_resource_type = 'PATIENT' AND evaluation_order = 0; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java index 7dcca727..a36147f4 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java @@ -174,6 +174,8 @@ public abstract class AbstractRule extends VersionedBaseMetadata implements Seri private boolean grouping; + private boolean simpleFhirId; + private List dhisDataReferences; protected AbstractRule() @@ -426,6 +428,17 @@ public void setGrouping( boolean grouping ) this.grouping = grouping; } + @Column( name = "simpleFhirId", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE NOT NULL" ) + public boolean isSimpleFhirId() + { + return simpleFhirId; + } + + public void setSimpleFhirId( boolean simpleFhirId ) + { + this.simpleFhirId = simpleFhirId; + } + @JsonCacheIgnore @OneToMany( mappedBy = "rule", orphanRemoval = true, cascade = CascadeType.ALL ) @BatchSize( size = 100 ) diff --git a/fhir/src/main/resources/db/migration/production/V1.1.0.40_0_0__DHIS2_FHIR_ID.sql b/fhir/src/main/resources/db/migration/production/V1.1.0.40_0_0__DHIS2_FHIR_ID.sql new file mode 100644 index 00000000..385f3960 --- /dev/null +++ b/fhir/src/main/resources/db/migration/production/V1.1.0.40_0_0__DHIS2_FHIR_ID.sql @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO PROGRAM_STAGE_EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +-- @formatter:off + +ALTER TABLE fhir_rule ADD COLUMN simple_fhir_id BOOLEAN DEFAULT FALSE NOT NULL; +COMMENT ON COLUMN fhir_rule.simple_fhir_id IS 'Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type.'; + + +UPDATE fhir_rule SET simple_fhir_id=true WHERE id='52227dd9-c79c-478b-92af-9aa1f33c76fd'; +UPDATE fhir_rule SET simple_fhir_id=true WHERE id='c4e17e7d-880e-45b5-9bc5-568da8c79742'; +UPDATE fhir_rule SET simple_fhir_id=true WHERE id='b9546b02-4adc-4868-a4cd-d5d7789f0df0'; +UPDATE fhir_rule SET simple_fhir_id=true WHERE id='d0e1472a-05e6-47c9-b36b-ff1f06fec352'; +UPDATE fhir_rule SET simple_fhir_id=true WHERE id='5f9ebdc9-852e-4c83-87ca-795946aabc35'; diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/EnrollmentRuleRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/EnrollmentRuleRepositoryRestDocsTest.java index 51643014..ee5a55a8 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/EnrollmentRuleRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/EnrollmentRuleRepositoryRestDocsTest.java @@ -93,6 +93,8 @@ public void createEnrollmentRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "applicableCodeSet" ).description( "Link to the code set reference that is used to check if the incoming request is applicable for this rule." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "applicableImpScript" ).description( "Link to the executable script reference that is used to check if the incoming request is applicable for this rule when transforming from a FHIR to a DHIS2 resource. " + @@ -157,6 +159,8 @@ public void readEnrollmentRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "dhisDataReferences" ).description( "Contains the references to DHIS2 data elements in which the data that is processed by the assigned rule is stored." ).type( JsonFieldType.ARRAY ).optional(), diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java index 51c323f7..2510c9ff 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java @@ -95,6 +95,8 @@ public void createOrganizationUnitRule() throws Exception fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "applicableCodeSet" ).description( "Link to the code set reference that is used to check if the incoming request is applicable for this rule." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "applicableImpScript" ).description( "Link to the executable script reference that is used to check if the incoming request is applicable for this rule when transforming from a FHIR to a DHIS2 resource. " + @@ -167,6 +169,8 @@ public void readOrganizationUnitRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "dhisDataReferences" ).description( "Contains the references to DHIS2 data elements in which the data that is processed by the assigned rule is stored." ).type( JsonFieldType.ARRAY ).optional(), diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ProgramStageRuleRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ProgramStageRuleRepositoryRestDocsTest.java index 07c259c5..acc4cd8f 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ProgramStageRuleRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ProgramStageRuleRepositoryRestDocsTest.java @@ -97,6 +97,8 @@ public void createProgramStageRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "enrollmentCreationEnabled" ).description( "Specifies if the creation of an enrollment is allowed when processing the rule and the enrollment does not exist." ).type( JsonFieldType.BOOLEAN ), @@ -199,6 +201,8 @@ public void readProgramStageRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "enrollmentCreationEnabled" ).description( "Specifies if the creation of an enrollment is allowed when processing the rule and the enrollment does not exist." ).type( JsonFieldType.BOOLEAN ), diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/TrackedEntityRuleRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/TrackedEntityRuleRepositoryRestDocsTest.java index 2db1c6cf..09c6beb3 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/TrackedEntityRuleRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/TrackedEntityRuleRepositoryRestDocsTest.java @@ -100,6 +100,8 @@ public void createTrackedEntityRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "applicableCodeSet" ).description( "Link to the code set reference that is used to check if the incoming request is applicable for this rule." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "applicableImpScript" ).description( "Link to the executable script reference that is used to check if the incoming request is applicable for this rule when transforming from a FHIR to a DHIS2 resource. " + @@ -180,6 +182,8 @@ public void readTrackedEntityRule() throws Exception fields.withPath( "fhirDeleteEnabled" ).description( "Specifies if the deletion of a FHIR resource is enabled for output transformations from DHIS to FHIR for this rule (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "stop" ).description( "Specifies if this rule is the last applied rule. When the transformation should not stop further rules are applied as well." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "grouping" ).description( "Specifies if the FHIR resources groups references of other FHIR resources (e.g. FHIR Encounter)." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "simpleFhirId" ).description( "Specifies if the FHIR ID is just the DHIS2 ID without the rule ID. This feature must only be enabled if there is a distinct rule for the combination of FHIR and DHIS2 resource type." ) + .type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "evaluationOrder" ).description( "Specifies the precedence of this rule when several rules match. Higher values define a higher precedence." ).type( JsonFieldType.NUMBER ), fields.withPath( "containedAllowed" ).description( "Specified if this rule can process contained resources." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "dhisDataReferences" ).description( "Contains the references to DHIS2 data elements in which the data that is processed by the assigned rule is stored." ).type( JsonFieldType.ARRAY ).optional(), From 69239a7b7bcb63fe56147007b935f1fbde674c4a Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Sat, 20 Jul 2019 16:42:18 +0200 Subject: [PATCH 2/3] Removes not required full qualified IDs from test cases. --- .../adapter/Dstu3InterfaceDemoClient.java | 4 +- .../dhis2/fhir/adapter/R4BatchDemoClient.java | 2 +- .../fhir/adapter/R4InterfaceDemoClient.java | 4 +- .../dstu3/Dstu3OrgUnitFhirRestAppTest.java | 12 ++--- .../Dstu3ProgramStageFhirRestAppTest.java | 34 +++++++------- ...3TrackedEntityInstanceFhirRestAppTest.java | 46 +++++++++---------- .../server/r4/R4OrgUnitFhirRestAppTest.java | 12 ++--- .../r4/R4ProgramStageFhirRestAppTest.java | 40 ++++++++-------- ...4TrackedEntityInstanceFhirRestAppTest.java | 46 +++++++++---------- .../fhir/test/dstu3/create-batch-bundle.json | 10 ++-- .../fhir/test/dstu3/delete-batch-bundle.json | 6 +-- .../fhir/test/dstu3/update-batch-bundle.json | 6 +-- .../fhir/test/r4/create-batch-bundle.json | 10 ++-- .../fhir/test/r4/delete-batch-bundle.json | 6 +-- .../fhir/test/r4/update-batch-bundle.json | 6 +-- ...esourceFhirToDhisTransformerUtilsTest.java | 8 ++-- ...esourceFhirToDhisTransformerUtilsTest.java | 8 ++-- .../repository/DhisFhirResourceIdTest.java | 2 +- .../AbstractBundleResourceProviderTest.java | 34 +++++++------- .../FhirToDhisTransformerContextImplTest.java | 4 +- 20 files changed, 150 insertions(+), 150 deletions(-) diff --git a/app/src/main/java/org/dhis2/fhir/adapter/Dstu3InterfaceDemoClient.java b/app/src/main/java/org/dhis2/fhir/adapter/Dstu3InterfaceDemoClient.java index 7edef4d6..dae46f1e 100644 --- a/app/src/main/java/org/dhis2/fhir/adapter/Dstu3InterfaceDemoClient.java +++ b/app/src/main/java/org/dhis2/fhir/adapter/Dstu3InterfaceDemoClient.java @@ -115,7 +115,7 @@ public static void main( String[] args ) .setValue( new DecimalType( -13.262743 ) ) ); // FHIR reference to DHIS2 Organisation Unit with ID ldXIdLNUNEn child.setManagingOrganization( new Reference( - new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ); + new IdType( "Organization", "ldXIdLNUNEn" ) ) ); MethodOutcome methodOutcome = client.create().resource( child ).execute(); System.out.println( "Child " + methodOutcome.getId() + " (created=" + methodOutcome.getCreated() + ")" ); @@ -140,7 +140,7 @@ public static void main( String[] args ) imm1.addVaccinationProtocol().setDoseSequence( 1 ) .setSeries( "2" ); // FHIR reference to DHIS2 Organisation Unit with ID ldXIdLNUNEn - imm1.setLocation( new Reference( new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ); + imm1.setLocation( new Reference( new IdType( "Organization", "ldXIdLNUNEn" ) ) ); methodOutcome = client.create().resource( imm1 ).execute(); System.out.println( "Immunization 1 " + methodOutcome.getId() + " (created=" + methodOutcome.getCreated() + ")" ); diff --git a/app/src/main/java/org/dhis2/fhir/adapter/R4BatchDemoClient.java b/app/src/main/java/org/dhis2/fhir/adapter/R4BatchDemoClient.java index 56ee80d9..871dd8ce 100644 --- a/app/src/main/java/org/dhis2/fhir/adapter/R4BatchDemoClient.java +++ b/app/src/main/java/org/dhis2/fhir/adapter/R4BatchDemoClient.java @@ -132,7 +132,7 @@ public static void main( String[] args ) imm1.addProtocolApplied().setDoseNumber( new PositiveIntType( 1 ) ) .setSeries( "2" ); // FHIR reference to DHIS2 Organisation Unit with ID ldXIdLNUNEn - imm1.setLocation( new Reference( new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ); + imm1.setLocation( new Reference( new IdType( "Organization", "ldXIdLNUNEn" ) ) ); Observation bw1 = new Observation(); bw1.addCategory( new CodeableConcept().addCoding( diff --git a/app/src/main/java/org/dhis2/fhir/adapter/R4InterfaceDemoClient.java b/app/src/main/java/org/dhis2/fhir/adapter/R4InterfaceDemoClient.java index 07a97c3e..342fa6e2 100644 --- a/app/src/main/java/org/dhis2/fhir/adapter/R4InterfaceDemoClient.java +++ b/app/src/main/java/org/dhis2/fhir/adapter/R4InterfaceDemoClient.java @@ -116,7 +116,7 @@ public static void main( String[] args ) .setValue( new DecimalType( -13.262743 ) ) ); // FHIR reference to DHIS2 Organisation Unit with ID ldXIdLNUNEn child.setManagingOrganization( new org.hl7.fhir.r4.model.Reference( - new org.hl7.fhir.r4.model.IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ); + new org.hl7.fhir.r4.model.IdType( "Organization", "ldXIdLNUNEn" ) ) ); MethodOutcome methodOutcome = client.create().resource( child ).execute(); System.out.println( "Child " + methodOutcome.getId() + " (created=" + methodOutcome.getCreated() + ")" ); @@ -140,7 +140,7 @@ public static void main( String[] args ) imm1.addProtocolApplied().setDoseNumber( new PositiveIntType( 1 ) ) .setSeries( "2" ); // FHIR reference to DHIS2 Organisation Unit with ID ldXIdLNUNEn - imm1.setLocation( new Reference( new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ); + imm1.setLocation( new Reference( new IdType( "Organization", "ldXIdLNUNEn" ) ) ); methodOutcome = client.create().resource( imm1 ).execute(); System.out.println( "Immunization 1 " + methodOutcome.getId() + " (created=" + methodOutcome.getCreated() + ")" ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java index 01abe4b4..801abdd7 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java @@ -71,7 +71,7 @@ protected FhirVersion getFhirVersion() public void getLocationWithoutAuthorization() { final IGenericClient client = createGenericClient(); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -83,7 +83,7 @@ public void getLocationWithInvalidAuthorization() final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } @Test( expected = ResourceNotFoundException.class ) @@ -113,7 +113,7 @@ private void getLocationNotExists() throws Exception { final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.read().resource( Location.class ).withId( "ou-0dXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "0dXIdLNUNEn" ).execute(); } catch ( ResourceNotFoundException e ) { @@ -146,7 +146,7 @@ private void getLocationRuleNotFound() throws Exception { final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-a9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } catch ( ResourceNotFoundException e ) { @@ -177,7 +177,7 @@ private void getLocation() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Location location = client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + Location location = client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); Assert.assertEquals( "Test Hospital", location.getName() ); Assert.assertEquals( 1, location.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/location-identifier", location.getIdentifier().get( 0 ).getSystem() ); @@ -302,7 +302,7 @@ public void searchParentLocation() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Location.class ).where( Location.PARTOF.hasId( new IdType( "Location", "ou-bdXIaLNUNEp-b9546b024adc4868a4cdd5d7789f0df0" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Location.class ).where( Location.PARTOF.hasId( new IdType( "Location", "bdXIaLNUNEp" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Location location = (Location) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( "Test Hospital", location.getName() ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java index 2314df16..0eb709b4 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java @@ -127,8 +127,8 @@ private void getObservation( boolean skipCached ) throws Exception client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); Observation observation = client.read().resource( Observation.class ).withId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ).execute(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -196,8 +196,8 @@ private void searchObservation( boolean skipCached ) throws Exception Assert.assertEquals( 2, bundle.getEntry().size() ); Observation observation = (Observation) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -226,12 +226,12 @@ public void searchObservationPatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Observation.class ).where( Observation.PATIENT.hasId( new IdType( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Observation.class ).where( Observation.PATIENT.hasId( new IdType( "Patient", "JeR2Ul4mZfx" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Observation observation = (Observation) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -245,7 +245,7 @@ public void createObservationWithoutAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.create().resource( observation ).execute(); @@ -263,7 +263,7 @@ public void createObservationInvalidAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -294,8 +294,8 @@ public void createObservation() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); @@ -328,8 +328,8 @@ public void createObservationByCodeSetCode() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70-codeset.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); @@ -384,7 +384,7 @@ public void updateObservationWithoutAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.update().resource( observation ).execute(); @@ -402,7 +402,7 @@ public void updateObservationInvalidAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -442,8 +442,8 @@ public void updateObservation() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java index a8e1d447..ee32e225 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java @@ -75,7 +75,7 @@ protected FhirVersion getFhirVersion() public void getPatientWithoutAuthorization() { final IGenericClient client = createGenericClient(); - client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -89,7 +89,7 @@ public void getPatientWithInvalidAuthorization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); } @Test @@ -115,12 +115,12 @@ private void getPatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Patient patient = client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + Patient patient = client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); Assert.assertEquals( "West", patient.getNameFirstRep().getFamily() ); Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -178,7 +178,7 @@ private void getPatientByIdentifier() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -236,7 +236,7 @@ private void searchPatient() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -256,14 +256,14 @@ public void searchPatientOrganization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Patient.class ).where( Patient.ORGANIZATION.hasId( new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Patient.class ).where( Patient.ORGANIZATION.hasId( new IdType( "Organization", "ldXIdLNUNEn" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Patient patient = (Patient) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( "West", patient.getNameFirstRep().getFamily() ); Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -290,7 +290,7 @@ public void searchPatientGiven() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -305,7 +305,7 @@ public void createPatientWithoutAuthorization() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.create().resource( patient ).execute(); @@ -325,7 +325,7 @@ public void createPatientInvalidAuthorization() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -346,13 +346,13 @@ public void createPatient() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); MethodOutcome methodOutcome = client.create().resource( patient ).execute(); Assert.assertEquals( Boolean.TRUE, methodOutcome.getCreated() ); - Assert.assertEquals( "http://localhost:" + localPort + "/fhir/dstu3/default/Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", methodOutcome.getId().toString() ); + Assert.assertEquals( "http://localhost:" + localPort + "/fhir/dstu3/default/Patient/JeR2Ul4mZfx", methodOutcome.getId().toString() ); } @Test( expected = AuthenticationException.class ) @@ -363,8 +363,8 @@ public void updatePatientWithoutAuthorization() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -384,8 +384,8 @@ public void updatePatientInvalidAuthorization() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -412,8 +412,8 @@ public void updatePatient() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -421,7 +421,7 @@ public void updatePatient() throws Exception client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); MethodOutcome methodOutcome = client.update().resource( patient ).execute(); Assert.assertNotEquals( Boolean.TRUE, methodOutcome.getCreated() ); - Assert.assertEquals( "http://localhost:" + localPort + "/fhir/dstu3/default/Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", methodOutcome.getId().toString() ); + Assert.assertEquals( "http://localhost:" + localPort + "/fhir/dstu3/default/Patient/JeR2Ul4mZfx", methodOutcome.getId().toString() ); } @Test( expected = AuthenticationException.class ) @@ -430,7 +430,7 @@ public void deletePatientWithoutAuthorization() throws Exception expectTrackedEntityMetadataRequests(); final IGenericClient client = createGenericClient(); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -443,7 +443,7 @@ public void deletePatientInvalidAuthorization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); userDhis2Server.verify(); } @@ -458,7 +458,7 @@ public void deletePatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); userDhis2Server.verify(); } diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java index 7aa7bb84..4121bc46 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java @@ -71,7 +71,7 @@ protected FhirVersion getFhirVersion() public void getLocationWithoutAuthorization() { final IGenericClient client = createGenericClient(); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -83,7 +83,7 @@ public void getLocationWithInvalidAuthorization() final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } @Test @@ -107,7 +107,7 @@ private void getLocation() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Location location = client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + Location location = client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); Assert.assertEquals( "Test Hospital", location.getName() ); Assert.assertEquals( 1, location.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/location-identifier", location.getIdentifier().get( 0 ).getSystem() ); @@ -144,7 +144,7 @@ private void getLocationNotExists() throws Exception { final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.read().resource( Location.class ).withId( "ou-0dXIdLNUNEn-b9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "0dXIdLNUNEn" ).execute(); } catch ( ResourceNotFoundException e ) { @@ -177,7 +177,7 @@ private void getLocationRuleNotFound() throws Exception { final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.read().resource( Location.class ).withId( "ou-ldXIdLNUNEn-a9546b024adc4868a4cdd5d7789f0df0" ).execute(); + client.read().resource( Location.class ).withId( "ldXIdLNUNEn" ).execute(); } catch ( ResourceNotFoundException e ) { @@ -302,7 +302,7 @@ public void searchParentLocation() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Location.class ).where( Location.PARTOF.hasId( new IdType( "Location", "ou-bdXIaLNUNEp-b9546b024adc4868a4cdd5d7789f0df0" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Location.class ).where( Location.PARTOF.hasId( new IdType( "Location", "bdXIaLNUNEp" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Location location = (Location) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( "Test Hospital", location.getName() ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java index 19fa2a32..9be05db1 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java @@ -127,9 +127,9 @@ private void getObservation( boolean skipCached ) throws Exception client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); Observation observation = client.read().resource( Observation.class ).withId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ).execute(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); - Assert.assertEquals( "Encounter/ps-deR4kl4mnf7-9d342f13aec146299d654f03fd0e848c", observation.getEncounter().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Encounter/deR4kl4mnf7", observation.getEncounter().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -197,8 +197,8 @@ private void searchObservation( boolean skipCached ) throws Exception Assert.assertEquals( 2, bundle.getEntry().size() ); Observation observation = (Observation) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -226,12 +226,12 @@ public void searchObservationPatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Observation.class ).where( Observation.PATIENT.hasId( new IdType( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Observation.class ).where( Observation.PATIENT.hasId( new IdType( "Patient", "JeR2Ul4mZfx" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Observation observation = (Observation) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -263,8 +263,8 @@ public void searchObservationEncounter() throws Exception Assert.assertEquals( 2, bundle.getEntry().size() ); Observation observation = (Observation) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( 0, observation.getIdentifier().size() ); - Assert.assertEquals( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", observation.getSubject().getReference() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352", observation.getPerformerFirstRep().getReference() ); + Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -278,7 +278,7 @@ public void createObservationWithoutAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.create().resource( observation ).execute(); @@ -296,7 +296,7 @@ public void createObservationInvalidAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -327,8 +327,8 @@ public void createObservation() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); @@ -361,8 +361,8 @@ public void createObservationCodeSetCode() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70-codeset.json", StandardCharsets.UTF_8 ) ); observation.setId( (IdType) null ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); @@ -417,7 +417,7 @@ public void updateObservationWithoutAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.update().resource( observation ).execute(); @@ -435,7 +435,7 @@ public void updateObservationInvalidAuthorization() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -475,8 +475,8 @@ public void updateObservation() throws Exception Observation observation = (Observation) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-observation-70.json", StandardCharsets.UTF_8 ) ); observation.setId( "ps-deR4kl4mnf7-097d9ee0bdb344aeb9613b4584bad1db" ); - observation.setSubject( new Reference( "Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ) ); - observation.getPerformerFirstRep().setReference( "Organization/ou-ldXIdLNUNEp-d0e1472a05e647c9b36bff1f06fec352" ); + observation.setSubject( new Reference( "Patient/JeR2Ul4mZfx" ) ); + observation.getPerformerFirstRep().setReference( "Organization/ldXIdLNUNEp" ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java index 919fbd79..b95e83ae 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java @@ -75,7 +75,7 @@ protected FhirVersion getFhirVersion() public void getPatientWithoutAuthorization() { final IGenericClient client = createGenericClient(); - client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -89,7 +89,7 @@ public void getPatientWithInvalidAuthorization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); } @Test @@ -115,12 +115,12 @@ private void getPatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Patient patient = client.read().resource( Patient.class ).withId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + Patient patient = client.read().resource( Patient.class ).withId( "JeR2Ul4mZfx" ).execute(); Assert.assertEquals( "West", patient.getNameFirstRep().getFamily() ); Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -178,7 +178,7 @@ private void getPatientByIdentifier() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -236,7 +236,7 @@ private void searchPatient() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -256,14 +256,14 @@ public void searchPatientOrganization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - Bundle bundle = client.search().forResource( Patient.class ).where( Patient.ORGANIZATION.hasId( new IdType( "Organization", "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ) ).returnBundle( Bundle.class ).execute(); + Bundle bundle = client.search().forResource( Patient.class ).where( Patient.ORGANIZATION.hasId( new IdType( "Organization", "ldXIdLNUNEn" ) ) ).returnBundle( Bundle.class ).execute(); Assert.assertEquals( 2, bundle.getEntry().size() ); Patient patient = (Patient) bundle.getEntry().get( 0 ).getResource(); Assert.assertEquals( "West", patient.getNameFirstRep().getFamily() ); Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -290,7 +290,7 @@ public void searchPatientGiven() throws Exception Assert.assertEquals( 1, patient.getIdentifier().size() ); Assert.assertEquals( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier", patient.getIdentifier().get( 0 ).getSystem() ); Assert.assertEquals( "PT_81589", patient.getIdentifier().get( 0 ).getValue() ); - Assert.assertEquals( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352", patient.getManagingOrganization().getReference() ); + Assert.assertEquals( "Organization/ldXIdLNUNEn", patient.getManagingOrganization().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); @@ -305,7 +305,7 @@ public void createPatientWithoutAuthorization() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.create().resource( patient ).execute(); @@ -324,7 +324,7 @@ public void createPatientInvalidAuthorization() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); @@ -345,13 +345,13 @@ public void createPatient() throws Exception IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); patient.setId( (IdType) null ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); MethodOutcome methodOutcome = client.create().resource( patient ).execute(); Assert.assertEquals( Boolean.TRUE, methodOutcome.getCreated() ); - Assert.assertEquals( "http://localhost:" + localPort + "/fhir/r4/default/Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", methodOutcome.getId().toString() ); + Assert.assertEquals( "http://localhost:" + localPort + "/fhir/r4/default/Patient/JeR2Ul4mZfx", methodOutcome.getId().toString() ); } @Test( expected = AuthenticationException.class ) @@ -362,8 +362,8 @@ public void updatePatientWithoutAuthorization() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -383,8 +383,8 @@ public void updatePatientInvalidAuthorization() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -411,8 +411,8 @@ public void updatePatient() throws Exception Patient patient = (Patient) getFhirContext().newJsonParser().parseResource( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/" + getResourceDir() + "/get-patient-15.json", StandardCharsets.UTF_8 ) ); patient.getIdentifierFirstRep().setSystem( "http://www.dhis2.org/dhis2fhiradapter/systems/patient-identifier" ).setValue( "PT_88589" ); - patient.setId( "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ); - patient.setManagingOrganization( new Reference( "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + patient.setId( "JeR2Ul4mZfx" ); + patient.setManagingOrganization( new Reference( "Organization/ldXIdLNUNEn" ) ); patient.getNameFirstRep().setGiven( new ArrayList<>() ); patient.getNameFirstRep().addGiven( "Joe" ).addGiven( "Scott" ); @@ -420,7 +420,7 @@ public void updatePatient() throws Exception client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); MethodOutcome methodOutcome = client.update().resource( patient ).execute(); Assert.assertNotEquals( Boolean.TRUE, methodOutcome.getCreated() ); - Assert.assertEquals( "http://localhost:" + localPort + "/fhir/r4/default/Patient/te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35", methodOutcome.getId().toString() ); + Assert.assertEquals( "http://localhost:" + localPort + "/fhir/r4/default/Patient/JeR2Ul4mZfx", methodOutcome.getId().toString() ); } @Test( expected = AuthenticationException.class ) @@ -429,7 +429,7 @@ public void deletePatientWithoutAuthorization() throws Exception expectTrackedEntityMetadataRequests(); final IGenericClient client = createGenericClient(); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); } @Test( expected = AuthenticationException.class ) @@ -442,7 +442,7 @@ public void deletePatientInvalidAuthorization() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "invalid_1" ) ); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); userDhis2Server.verify(); } @@ -457,7 +457,7 @@ public void deletePatient() throws Exception final IGenericClient client = createGenericClient(); client.registerInterceptor( new BasicAuthInterceptor( "fhir_client", "fhir_client_1" ) ); - client.delete().resourceById( "Patient", "te-JeR2Ul4mZfx-5f9ebdc9852e4c8387ca795946aabc35" ).execute(); + client.delete().resourceById( "Patient", "JeR2Ul4mZfx" ).execute(); userDhis2Server.verify(); } diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/create-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/create-batch-bundle.json index f9d78967..c82b388b 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/create-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/create-batch-bundle.json @@ -50,7 +50,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -100,7 +100,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -144,7 +144,7 @@ "effectiveDateTime": "2018-11-11", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -205,7 +205,7 @@ "effectiveDateTime": "2018-11-12", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -239,7 +239,7 @@ "date": "2018-11-11T21:34:05+02:00", "primarySource": true, "location": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" }, "vaccinationProtocol": [ { diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/delete-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/delete-batch-bundle.json index ee926558..95ae2d5c 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/delete-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/delete-batch-bundle.json @@ -5,19 +5,19 @@ { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588d-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588d" } }, { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588e-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588e" } }, { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588f-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588f" } } ] diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/update-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/update-batch-bundle.json index a6c063fc..21347a4b 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/update-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/dstu3/update-batch-bundle.json @@ -50,7 +50,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -94,7 +94,7 @@ "effectiveDateTime": "2018-11-11", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -128,7 +128,7 @@ "date": "2018-11-11T21:34:05+02:00", "primarySource": true, "location": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" }, "vaccinationProtocol": [ { diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/create-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/create-batch-bundle.json index dc23544a..83a78259 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/create-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/create-batch-bundle.json @@ -50,7 +50,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -100,7 +100,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -144,7 +144,7 @@ "effectiveDateTime": "2018-11-11", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -205,7 +205,7 @@ "effectiveDateTime": "2018-11-12", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -239,7 +239,7 @@ "occurrenceDateTime": "2018-11-11T21:34:05+02:00", "primarySource": true, "location": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" }, "protocolApplied": [ { diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/delete-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/delete-batch-bundle.json index ee926558..95ae2d5c 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/delete-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/delete-batch-bundle.json @@ -5,19 +5,19 @@ { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588d-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588d" } }, { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588e-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588e" } }, { "request": { "method": "DELETE", - "url": "Patient/te-MyJuP2H588f-5f9ebdc9852e4c8387ca795946aabc35" + "url": "Patient/MyJuP2H588f" } } ] diff --git a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/update-batch-bundle.json b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/update-batch-bundle.json index ecf993ec..e6d76473 100644 --- a/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/update-batch-bundle.json +++ b/app/src/test/resources/org/dhis2/fhir/adapter/fhir/test/r4/update-batch-bundle.json @@ -50,7 +50,7 @@ } ], "managingOrganization": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } }, "request": { @@ -94,7 +94,7 @@ "effectiveDateTime": "2018-11-11", "performer": [ { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" } ], "valueQuantity": { @@ -128,7 +128,7 @@ "occurrenceDateTime": "2018-11-11T21:34:05+02:00", "primarySource": true, "location": { - "reference": "Organization/ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" + "reference": "Organization/ldXIdLNUNEn" }, "protocolApplied": [ { diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java index eace5cea..58665164 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java @@ -361,10 +361,10 @@ public void getAdapterReferenceDhisFhirIdentifier() Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID" ) ).when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); - Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ); + Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "l2C0N9u2e5q" ); final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getAdapterReference( new Reference() - .setIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ) ), "Patient" ); + .setIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "l2C0N9u2e5q" ) ), "Patient" ); Assert.assertNotNull( adapterReference ); Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "abcdef123456", ReferenceType.ID ), adapterReference ); @@ -447,10 +447,10 @@ public void getResourceAdapterReferenceDhisFhirIdentifier() Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID" ) ).when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); - Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ); + Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "l2C0N9u2e5q" ); final Patient patient = new Patient(); - patient.addIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ) ); + patient.addIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "l2C0N9u2e5q" ) ); final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getResourceAdapterReference( patient, "Patient" ); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java index 9e328c47..bbea185c 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java @@ -333,10 +333,10 @@ public void getAdapterReferenceDhisFhirIdentifier() Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID" ) ).when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); - Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ); + Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "l2C0N9u2e5q" ); final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getAdapterReference( new Reference() - .setIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ) ), "Patient" ); + .setIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "l2C0N9u2e5q" ) ), "Patient" ); Assert.assertNotNull( adapterReference ); Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "abcdef123456", ReferenceType.ID ), adapterReference ); @@ -419,10 +419,10 @@ public void getResourceAdapterReferenceDhisFhirIdentifier() Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID" ) ).when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); - Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ); + Mockito.doReturn( "abcdef123456" ).when( context ).extractDhisId( "l2C0N9u2e5q" ); final Patient patient = new Patient(); - patient.addIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "te-l2C0N9u2e5q-5f9ebdc9852e4c8387ca795946aabc35" ) ); + patient.addIdentifier( new Identifier().setSystem( System.DHIS2_FHIR_IDENTIFIER_URI ).setValue( "l2C0N9u2e5q" ) ); final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getResourceAdapterReference( patient, "Patient" ); diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java index 23c07511..e2c80dfb 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java @@ -53,6 +53,6 @@ public void isValidNot() @Test public void isValid() { - Assert.assertTrue( DhisFhirResourceId.isValid( "ou-ldXIdLNUNEn-d0e1472a05e647c9b36bff1f06fec352" ) ); + Assert.assertTrue( DhisFhirResourceId.isValid( "ldXIdLNUNEn" ) ); } } \ No newline at end of file diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/server/provider/AbstractBundleResourceProviderTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/server/provider/AbstractBundleResourceProviderTest.java index 232c4043..b637f000 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/server/provider/AbstractBundleResourceProviderTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/server/provider/AbstractBundleResourceProviderTest.java @@ -190,16 +190,16 @@ public void processInternal() throws Exception invalidPutOperation.getResult().badRequest( "Invalid data included" ); final List operations = new ArrayList<>(); - operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUNE1-d0e1472a05e647c9b36bff1f06fec351", baseResource1, null ) ); - operations.add( new FhirOperation( FhirOperationType.DELETE, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUNE4-d0e1472a05e647c9b36bff1f06fec354", null, null ) ); + operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUNE1", baseResource1, null ) ); + operations.add( new FhirOperation( FhirOperationType.DELETE, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUNE4", null, null ) ); operations.add( new FhirOperation( FhirOperationType.POST, FhirResourceType.OBSERVATION, observationClientResource, null, baseResource2, null ) ); - operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUNE2-d0e1472a05e647c9b36bff1f06fec352", baseResource3, + operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUNE2", baseResource3, new URI( "Patient?identifier=http%3A%2F%2Ftest.com%2Fpatient%7C8972" ) ) ); operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, null, baseResource4, new URI( "Patient?identifier=http%3A%2F%2Ftest.com%2Fpatient%7C8973" ) ) ); - operations.add( new FhirOperation( FhirOperationType.DELETE, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUNE2-d0e1472a05e647c9b36bff1f06fec352", null, null ) ); - operations.add( new FhirOperation( FhirOperationType.POST, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUN12-d0e1472a05e647c9b36bff1f06fec312", baseResource5, null ) ); - operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "te-ldXIdLNUN22-d0e1472a05e647c9b36bff1f06fec322", baseResource6, null ) ); + operations.add( new FhirOperation( FhirOperationType.DELETE, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUNE2", null, null ) ); + operations.add( new FhirOperation( FhirOperationType.POST, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUN12", baseResource5, null ) ); + operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "ldXIdLNUN22", baseResource6, null ) ); operations.add( invalidDeleteOperation ); operations.add( invalidPostOperation ); @@ -216,23 +216,23 @@ public void processInternal() throws Exception Mockito.when( bundleResourceProvider.createBatchResponse( Mockito.same( batchRequest ) ) ).thenReturn( resultBaseBundle ); Mockito.when( fhirRepository.save( Mockito.same( patientClientResource ), Mockito.same( baseResource1 ), Mockito.eq( new FhirRepositoryOperation( FhirRepositoryOperationType.UPDATE ) ) ) ) - .thenReturn( new FhirRepositoryOperationOutcome( "te-ldXIdLNUNE1-d0e1472a05e647c9b36bff1f06fec351", false ) ); - Mockito.when( fhirRepository.delete( Mockito.same( patientClientResource ), Mockito.eq( DhisFhirResourceId.parse( "te-ldXIdLNUNE4-d0e1472a05e647c9b36bff1f06fec354" ) ) ) ) + .thenReturn( new FhirRepositoryOperationOutcome( "ldXIdLNUNE1", false ) ); + Mockito.when( fhirRepository.delete( Mockito.same( patientClientResource ), Mockito.eq( DhisFhirResourceId.parse( "ldXIdLNUNE4" ) ) ) ) .thenReturn( true ); Mockito.when( fhirRepository.save( Mockito.same( observationClientResource ), Mockito.same( baseResource2 ), Mockito.eq( new FhirRepositoryOperation( FhirRepositoryOperationType.CREATE ) ) ) ) - .thenReturn( new FhirRepositoryOperationOutcome( "te-ldXIdLNUNE9-d0e1472a05e647c9b36bff1f06fec359", true ) ); + .thenReturn( new FhirRepositoryOperationOutcome( "ldXIdLNUNE9", true ) ); Mockito.when( dhisRepository.readByIdentifier( Mockito.same( patientClientResource.getFhirClient() ), Mockito.eq( FhirResourceType.PATIENT ), Mockito.eq( "8972" ) ) ) .thenReturn( Optional.empty() ); Mockito.when( fhirRepository.save( Mockito.same( patientClientResource ), Mockito.same( baseResource3 ), Mockito.eq( new FhirRepositoryOperation( FhirRepositoryOperationType.CREATE ) ) ) ) - .thenReturn( new FhirRepositoryOperationOutcome( "te-ldXIdLNUNE8-d0e1472a05e647c9b36bff1f06fec358", true ) ); - Mockito.when( baseResource4.getIdElement() ).thenReturn( new IdDt( "te-ldXIdLNUNE7-d0e1472a05e647c9b36bff1f06fec357" ) ); + .thenReturn( new FhirRepositoryOperationOutcome( "ldXIdLNUNE8", true ) ); + Mockito.when( baseResource4.getIdElement() ).thenReturn( new IdDt( "ldXIdLNUNE7" ) ); Mockito.when( dhisRepository.readByIdentifier( Mockito.same( patientClientResource.getFhirClient() ), Mockito.eq( FhirResourceType.PATIENT ), Mockito.eq( "8973" ) ) ) .thenReturn( Optional.of( baseResource4 ) ); Mockito.when( fhirRepository.save( Mockito.same( patientClientResource ), Mockito.same( baseResource4 ), Mockito.eq( new FhirRepositoryOperation( FhirRepositoryOperationType.UPDATE ) ) ) ) - .thenReturn( new FhirRepositoryOperationOutcome( "te-ldXIdLNUNE4-d0e1472a05e647c9b36bff1f06fec354", false ) ); + .thenReturn( new FhirRepositoryOperationOutcome( "ldXIdLNUNE4", false ) ); Mockito.when( fhirRepository.save( Mockito.same( patientClientResource ), Mockito.same( baseResource7 ), Mockito.eq( new FhirRepositoryOperation( FhirRepositoryOperationType.CREATE_OR_UPDATE ) ) ) ) - .thenReturn( new FhirRepositoryOperationOutcome( "te-lxXIdLNUNE4-d0e1472a05e647c9b36bff1f06fec354", false ) ); - Mockito.when( fhirRepository.delete( Mockito.same( patientClientResource ), Mockito.eq( DhisFhirResourceId.parse( "te-ldXIdLNUNE2-d0e1472a05e647c9b36bff1f06fec352" ) ) ) ) + .thenReturn( new FhirRepositoryOperationOutcome( "lxXIdLNUNE4", false ) ); + Mockito.when( fhirRepository.delete( Mockito.same( patientClientResource ), Mockito.eq( DhisFhirResourceId.parse( "ldXIdLNUNE2" ) ) ) ) .thenReturn( false ); Assert.assertSame( resultBaseBundle, bundleResourceProvider.processInternal( requestDetails, baseBundle ) ); @@ -247,11 +247,11 @@ public void processInternal() throws Exception Assert.assertNull( operations.get( 2 ).getResult().getIssue() ); Assert.assertEquals( FhirOperationResult.CREATED_STATUS_CODE, operations.get( 2 ).getResult().getStatusCode() ); - Assert.assertEquals( new IdDt( "te-ldXIdLNUNE9-d0e1472a05e647c9b36bff1f06fec359" ), operations.get( 2 ).getResult().getId() ); + Assert.assertEquals( new IdDt( "ldXIdLNUNE9" ), operations.get( 2 ).getResult().getId() ); Assert.assertNull( operations.get( 3 ).getResult().getIssue() ); Assert.assertEquals( FhirOperationResult.CREATED_STATUS_CODE, operations.get( 3 ).getResult().getStatusCode() ); - Assert.assertEquals( new IdDt( "te-ldXIdLNUNE8-d0e1472a05e647c9b36bff1f06fec358" ), operations.get( 3 ).getResult().getId() ); + Assert.assertEquals( new IdDt( "ldXIdLNUNE8" ), operations.get( 3 ).getResult().getId() ); Assert.assertNull( operations.get( 4 ).getResult().getIssue() ); Assert.assertEquals( FhirOperationResult.OK_STATUS_CODE, operations.get( 4 ).getResult().getStatusCode() ); @@ -278,7 +278,7 @@ public void processInternal() throws Exception Assert.assertNull( operations.get( 11 ).getResult().getIssue() ); Assert.assertEquals( FhirOperationResult.OK_STATUS_CODE, operations.get( 11 ).getResult().getStatusCode() ); - Assert.assertEquals( new IdDt( "te-lxXIdLNUNE4-d0e1472a05e647c9b36bff1f06fec354" ), operations.get( 11 ).getResult().getId() ); + Assert.assertEquals( new IdDt( "lxXIdLNUNE4" ), operations.get( 11 ).getResult().getId() ); Assert.assertNotNull( repositoryContainerReference.get() ); Mockito.verify( requestCacheContext, Mockito.times( 9 ) ).setAttribute( Mockito.eq( LocalDhisResourceRepositoryTemplate.RESOURCE_KEY_REQUEST_CACHE_ATTRIBUTE_NAME ), diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java index 26a9155d..41c4627f 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java @@ -109,7 +109,7 @@ public void extractDhisIdSimple() @Test public void extractDhisIdComplex() { - Assert.assertEquals( "LMYkcW3hE5b", context.extractDhisId( "te-LMYkcW3hE5b-5f9ebdc9852e4c8387ca795946aabc35" ) ); + Assert.assertEquals( "LMYkcW3hE5b", context.extractDhisId( "LMYkcW3hE5b" ) ); } @Test @@ -121,7 +121,7 @@ public void extractDhisIdLocale() @Test public void extractDhisIdType() { - Assert.assertEquals( "LMYkcW3hE5b", context.extractDhisId( new IdDt( "Patient/te-LMYkcW3hE5b-5f9ebdc9852e4c8387ca795946aabc35" ) ) ); + Assert.assertEquals( "LMYkcW3hE5b", context.extractDhisId( new IdDt( "Patient/LMYkcW3hE5b" ) ) ); } @Test( expected = TransformerDataException.class ) From 5a22b4cb422323cd639e3f59690e3cde0f827e42 Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Sun, 21 Jul 2019 11:16:39 +0200 Subject: [PATCH 3/3] Removes not required full qualified IDs from algorithms. --- .../r4/R4ProgramStageFhirRestAppTest.java | 2 +- app/src/test/resources/data.sql | 8 +- .../adapter/spring/EmptyObjectProvider.java | 69 ++++ .../fhir/metadata/model/AbstractRule.java | 2 +- .../impl/CustomRuleRepositoryImpl.java | 2 + .../fhir/repository/DhisFhirResourceId.java | 69 +++- .../repository/impl/DhisRepositoryImpl.java | 30 +- .../repository/impl/FhirRepositoryImpl.java | 15 +- .../dhis/DhisToFhirTransformerRequest.java | 2 + .../DhisToFhirTransformerRequestImpl.java | 10 + .../DhisToFhirTransformerServiceImpl.java | 51 ++- .../transform/dhis/search/SearchFilter.java | 4 +- .../FhirToDhisTransformerServiceImpl.java | 22 +- .../repository/DhisFhirResourceIdTest.java | 59 ++++ .../impl/DhisRepositoryImplTest.java | 181 ++++++++++ .../impl/FhirRepositoryImplTest.java | 34 ++ .../DhisToFhirTransformerRequestImplTest.java | 121 +++++++ .../DhisToFhirTransformerServiceImplTest.java | 321 ++++++++++++++++++ .../FhirToDhisTransformerContextImplTest.java | 3 +- .../FhirToDhisTransformerServiceImplTest.java | 134 ++++++++ 20 files changed, 1104 insertions(+), 35 deletions(-) create mode 100644 common/src/main/java/org/dhis2/fhir/adapter/spring/EmptyObjectProvider.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImplTest.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImplTest.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImplTest.java diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java index 9be05db1..b00b8858 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java @@ -129,7 +129,7 @@ private void getObservation( boolean skipCached ) throws Exception Assert.assertEquals( 0, observation.getIdentifier().size() ); Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); - Assert.assertEquals( "Encounter/deR4kl4mnf7", observation.getEncounter().getReference() ); + Assert.assertEquals( "Encounter/ps-deR4kl4mnf7-9d342f13aec146299d654f03fd0e848c", observation.getEncounter().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); diff --git a/app/src/test/resources/data.sql b/app/src/test/resources/data.sql index cd52e6a1..e87dc1c9 100644 --- a/app/src/test/resources/data.sql +++ b/app/src/test/resources/data.sql @@ -1948,14 +1948,14 @@ INSERT INTO fhir_code_set_value(code_set_id, code_id) UPDATE fhir_code_set_value SET preferred_export=true WHERE code_id='d308a6acad84453d9fb6e04f6a468469'; -- Encounter Child Programme, Birth -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, transform_exp_script_id, fhir_create_enabled, fhir_update_enabled, exp_enabled, grouping) -VALUES ('9d342f13aec146299d654f03fd0e848c', 0, 'Child Programme Birth Encounter', NULL, TRUE, 1000, 'ENCOUNTER', 'PROGRAM_STAGE_EVENT', TRUE, '5eab76a90ff443b0a7d05a6e726ca80e', TRUE, TRUE, TRUE, TRUE); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, transform_exp_script_id, fhir_create_enabled, fhir_update_enabled, exp_enabled, grouping, simple_fhir_id) +VALUES ('9d342f13aec146299d654f03fd0e848c', 0, 'Child Programme Birth Encounter', NULL, TRUE, 1000, 'ENCOUNTER', 'PROGRAM_STAGE_EVENT', TRUE, '5eab76a90ff443b0a7d05a6e726ca80e', TRUE, TRUE, TRUE, TRUE, TRUE); INSERT INTO fhir_program_stage_rule (id, program_stage_id) VALUES ('9d342f13aec146299d654f03fd0e848c', '4c074c85be494b9d89739e16b9615dad'); -- Encounter Child Programme, Baby Postnatal -INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, transform_exp_script_id, fhir_create_enabled, fhir_update_enabled, exp_enabled, grouping) -VALUES ('1f2da6ec41b04b6499d9e98fca864b0f', 0, 'Child Programme Baby Postnatal Encounter', NULL, TRUE, 1000, 'ENCOUNTER', 'PROGRAM_STAGE_EVENT', FALSE, '5eab76a90ff443b0a7d05a6e726ca80e', TRUE, TRUE, TRUE, TRUE); +INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, transform_exp_script_id, fhir_create_enabled, fhir_update_enabled, exp_enabled, grouping, simple_fhir_id) +VALUES ('1f2da6ec41b04b6499d9e98fca864b0f', 0, 'Child Programme Baby Postnatal Encounter', NULL, TRUE, 1000, 'ENCOUNTER', 'PROGRAM_STAGE_EVENT', FALSE, '5eab76a90ff443b0a7d05a6e726ca80e', TRUE, TRUE, TRUE, TRUE, TRUE); INSERT INTO fhir_program_stage_rule (id, program_stage_id) VALUES ('1f2da6ec41b04b6499d9e98fca864b0f', '526b4e01774747efa25df32ccd739e87'); diff --git a/common/src/main/java/org/dhis2/fhir/adapter/spring/EmptyObjectProvider.java b/common/src/main/java/org/dhis2/fhir/adapter/spring/EmptyObjectProvider.java new file mode 100644 index 00000000..6757015f --- /dev/null +++ b/common/src/main/java/org/dhis2/fhir/adapter/spring/EmptyObjectProvider.java @@ -0,0 +1,69 @@ +package org.dhis2.fhir.adapter.spring; + +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.ObjectProvider; + +import javax.annotation.Nonnull; + +/** + * Object provider that contains no object. + * + * @param the concrete type of the object. + */ +public class EmptyObjectProvider implements ObjectProvider +{ + @Override + @Nonnull + public T getObject( @Nonnull Object... args ) throws BeansException + { + throw new BeanCreationException( "No object available." ); + } + + @Override + public T getIfAvailable() throws BeansException + { + return null; + } + + @Override + public T getIfUnique() throws BeansException + { + return null; + } + + @Override + @Nonnull + public T getObject() throws BeansException + { + throw new BeanCreationException( "No object available." ); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java index a36147f4..c4520893 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java @@ -428,7 +428,7 @@ public void setGrouping( boolean grouping ) this.grouping = grouping; } - @Column( name = "simpleFhirId", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE NOT NULL" ) + @Column( name = "simple_fhir_id", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE NOT NULL" ) public boolean isSimpleFhirId() { return simpleFhirId; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/impl/CustomRuleRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/impl/CustomRuleRepositoryImpl.java index b4da94e1..e3f460e9 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/impl/CustomRuleRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/impl/CustomRuleRepositoryImpl.java @@ -181,6 +181,7 @@ public Optional> findOneExpByDhisFhirInputData( { final List rules = new ArrayList<>( entityManager.createNamedQuery( AbstractRule.FIND_EXP_RULES_BY_FHIR_TYPE_NAMED_QUERY, AbstractRule.class ) .setParameter( "fhirResourceType", fhirResourceType ).setMaxResults( 2 ).getResultList() ); + if ( rules.size() != 1 ) { return Optional.empty(); @@ -188,6 +189,7 @@ public Optional> findOneExpByDhisFhirInputData( final AbstractRule rule = rules.get( 0 ); Hibernate.initialize( rule.getDhisDataReferences() ); + return Optional.of( new RuleInfo<>( rule, rule.getDhisDataReferences() ) ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceId.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceId.java index 341a7936..18a9a2c9 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceId.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceId.java @@ -57,14 +57,18 @@ public class DhisFhirResourceId implements Serializable private final UUID ruleId; - public DhisFhirResourceId( @Nonnull DhisResourceType type, @Nonnull String id, @Nonnull UUID ruleId ) + public DhisFhirResourceId( @Nullable DhisResourceType type, @Nonnull String id, @Nullable UUID ruleId ) { this.type = type; this.id = id; this.ruleId = ruleId; } - @Nonnull + public DhisFhirResourceId( @Nonnull String id ) + { + this( null, id, null ); + } + public DhisResourceType getType() { return type; @@ -76,16 +80,34 @@ public String getId() return id; } - @Nonnull public UUID getRuleId() { return ruleId; } @Nonnull - public DhisResourceId getDhisResourceId() + public DhisResourceId getDhisResourceId() throws FhirRepositoryException { - return new DhisResourceId( getType(), getId() ); + final DhisResourceType type = getType(); + + if ( type == null ) + { + throw new FhirRepositoryException( + "Type of DHIS2 FHIR Resource ID has not been specified." ); + } + + return new DhisResourceId( type, getId() ); + } + + public boolean isQualified() + { + return type != null && ruleId != null; + } + + @Nonnull + public DhisFhirResourceId toQualified( @Nonnull DhisResourceType type, @Nonnull UUID ruleId ) + { + return new DhisFhirResourceId( type, getId(), ruleId ); } @Override @@ -103,7 +125,7 @@ public boolean equals( Object o ) DhisFhirResourceId that = (DhisFhirResourceId) o; - return getType() == that.getType() && getId().equals( that.getId() ) && getRuleId().equals( that.getRuleId() ); + return getType() == that.getType() && getId().equals( that.getId() ) && Objects.equals( getRuleId(), that.getRuleId() ); } @Override @@ -120,9 +142,23 @@ public String toString() } @Nonnull - public static String toString( @Nonnull DhisResourceType type, @Nonnull String id, @Nonnull UUID ruleId ) + public static String toString( @Nullable DhisResourceType type, @Nonnull String id, @Nullable UUID ruleId ) { - return type.getAbbreviation() + "-" + id + "-" + StringUtils.remove( ruleId.toString(), '-' ); + final StringBuilder sb = new StringBuilder(); + + if ( type != null ) + { + sb.append( type.getAbbreviation() ).append( '-' ); + } + + sb.append( id ); + + if ( ruleId != null ) + { + sb.append( '-' ).append( StringUtils.remove( ruleId.toString(), '-' ) ); + } + + return sb.toString(); } public static boolean isValid( @Nullable String value ) @@ -148,40 +184,55 @@ public static boolean isValid( @Nullable String value ) public static DhisFhirResourceId parse( @Nonnull String value ) throws IllegalArgumentException { final int firstIndex = value.indexOf( '-' ); - if ( firstIndex <= 0 ) + + if ( firstIndex < 0 ) + { + return new DhisFhirResourceId( value ); + } + + if ( firstIndex == 0 ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } + final int secondIndex = value.indexOf( '-', firstIndex + 1 ); + if ( secondIndex < 0 ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } final DhisResourceType type = DhisResourceType.getByAbbreviation( value.substring( 0, firstIndex ) ); + if ( type == null ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } + final String id = value.substring( firstIndex + 1, secondIndex ); + if ( StringUtils.isBlank( id ) || !StringUtils.isAlphanumeric( id ) ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } + final UUID ruleId; try { final Matcher matcher = UUID_PATTERN.matcher( value.substring( secondIndex + 1 ) ); + if ( !matcher.matches() ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } + ruleId = UUID.fromString( matcher.replaceAll( "$1-$2-$3-$4-$5" ) ); } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException( "Invalid DHIS FHIR ID: " + value ); } + return new DhisFhirResourceId( type, id, ruleId ); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java index 306b33d7..a1554c05 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java @@ -168,27 +168,48 @@ public void save( @Nonnull DhisSyncGroup syncGroup, @Nonnull DhisResource resour @Nonnull public Optional read( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisFhirResourceId dhisFhirResourceId ) { + final DhisResourceType dhisResourceType; + final UUID ruleId; + + if ( dhisFhirResourceId.isQualified() ) + { + dhisResourceType = dhisFhirResourceId.getType(); + ruleId = dhisFhirResourceId.getRuleId(); + } + else + { + final RuleInfo ruleInfo = dhisToFhirTransformerService.findSingleRule( fhirClient, fhirResourceType ); + + if ( ruleInfo == null || !ruleInfo.getRule().isSimpleFhirId() ) + { + return Optional.empty(); + } + + dhisResourceType = ruleInfo.getRule().getDhisResourceType(); + ruleId = ruleInfo.getRule().getId(); + } + return new OneDhisResourceReader() { @Nonnull @Override protected UUID getRuleId() { - return dhisFhirResourceId.getRuleId(); + return ruleId; } @Nullable @Override protected DhisToFhirTransformerRequest createTransformerRequest( @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisRequest dhisRequest, @Nonnull DhisResource dhisResource ) { - return dhisToFhirTransformerService.createTransformerRequest( fhirClient, dhisRequest, dhisResource, fhirResourceType, dhisFhirResourceId.getRuleId() ); + return dhisToFhirTransformerService.createTransformerRequest( fhirClient, dhisRequest, dhisResource, fhirResourceType, ruleId ); } @Nullable @Override protected DhisResource getDhisResource() { - return dhisResourceRepository.findRefreshed( dhisFhirResourceId.getDhisResourceId() ).orElse( null ); + return dhisResourceRepository.findRefreshed( dhisFhirResourceId.toQualified( dhisResourceType, ruleId ).getDhisResourceId() ).orElse( null ); } }.read( fhirClient, fhirResourceType ); } @@ -199,10 +220,12 @@ protected DhisResource getDhisResource() public Optional readByIdentifier( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull String identifier ) { final RuleInfo ruleInfo = dhisToFhirTransformerService.findSingleRule( fhirClient, fhirResourceType ); + if ( ruleInfo == null ) { return Optional.empty(); } + return new OneDhisResourceReader() { @Nonnull @@ -455,6 +478,7 @@ public Optional read( @Nonnull FhirClient fhirClient, @Nonnull Fh try ( final RequestCacheContext requestCacheContext = requestCacheService.createRequestCacheContext( true ) ) { final DhisResource dhisResource = getDhisResource(); + if ( dhisResource == null ) { logger.debug( "DHIS resource could not be found." ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java index d5b86fc6..931410d5 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java @@ -405,7 +405,7 @@ protected FhirRepositoryOperationOutcome saveInternally( @Nonnull FhirClientReso if ( operationOutcome == null ) { - final String dhisFhirResourceId = DhisFhirResourceId.toString( persistedDhisResource.getResourceType(), persistedDhisResource.getId(), outcome.getRule().getId() ); + final String dhisFhirResourceId = createDhisFhirResourceId( outcome, persistedDhisResource ); if ( fhirRequest.isDhisFhirId() && ( resource.getIdElement().isEmpty() || resource.getIdElement().isLocal() || !DhisFhirResourceId.isValid( resource.getIdElement().getIdPart() ) ) ) { @@ -424,6 +424,19 @@ protected FhirRepositoryOperationOutcome saveInternally( @Nonnull FhirClientReso return operationOutcome; } + @Nonnull + protected String createDhisFhirResourceId( @Nonnull FhirToDhisTransformOutcome outcome, @Nonnull DhisResource persistedDhisResource ) + { + if ( outcome.getRule().isSimpleFhirId() ) + { + return DhisFhirResourceId.toString( null, persistedDhisResource.getId(), null ); + } + else + { + return DhisFhirResourceId.toString( persistedDhisResource.getResourceType(), persistedDhisResource.getId(), outcome.getRule().getId() ); + } + } + @Nonnull protected FhirRequestMethod getRequestMethod( @Nonnull FhirRepositoryOperation fhirRepositoryOperation ) { diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java index 72d14a96..d1edb2f2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java @@ -57,4 +57,6 @@ public interface DhisToFhirTransformerRequest extends Serializable @Nonnull FhirClient getFhirClient(); + + boolean isSimpleFhirIdRule(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImpl.java index ed2b6b71..1248979f 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImpl.java @@ -64,6 +64,8 @@ public class DhisToFhirTransformerRequestImpl implements DhisToFhirTransformerRe private int ruleIndex; + private final boolean simpleFhirIdRule; + public DhisToFhirTransformerRequestImpl( @Nonnull DhisToFhirTransformerContext context, @Nullable ScriptedDhisResource input, @Nonnull FhirClient fhirClient, @Nonnull List> rules, @Nonnull Map transformerUtils ) { @@ -72,6 +74,8 @@ public DhisToFhirTransformerRequestImpl( @Nonnull DhisToFhirTransformerContext c this.fhirClient = fhirClient; this.rules = rules; this.transformerUtils = transformerUtils; + + this.simpleFhirIdRule = rules.size() == 1 && rules.get( 0 ).getRule().isSimpleFhirId(); } @Nonnull @@ -127,6 +131,12 @@ public UUID getRuleId() return rules.get( ruleIndex ).getRule().getId(); } + @Override + public boolean isSimpleFhirIdRule() + { + return simpleFhirIdRule; + } + public final boolean isFirstRule() { return (ruleIndex == 0); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java index 158e9ccb..e40ccffb 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import ca.uhn.fhir.model.primitive.IdDt; import org.dhis2.fhir.adapter.cache.RequestCacheContext; import org.dhis2.fhir.adapter.cache.RequestCacheService; import org.dhis2.fhir.adapter.dhis.model.DhisResource; @@ -209,34 +210,60 @@ public List resolveFhirReferences( @Nonnull FhirClient fhirClien DhisToFhirTransformerRequest transformerRequest = createTransformerRequest( fhirClient, new ImmutableDhisRequest( dhisRequest ), dhisResource, fhirResourceTypes ); + if ( transformerRequest == null ) { logger.debug( "No matching rule has been found for FHIR references." ); return Collections.emptyList(); } - final AbstractFhirResourceDhisToFhirTransformerUtils fhirResourceTransformerUtils = getFhirResourceTransformerUtils( fhirClient.getFhirVersion() ); final List references = new ArrayList<>(); - do + + if ( transformerRequest.isSimpleFhirIdRule() ) { - final DhisToFhirTransformOutcome outcome = transform( transformerRequest ); - if ( outcome == null ) - { - transformerRequest = null; - } - else + references.add( resolveSimpleFhirIdReference( transformerRequest ) ); + } + else + { + final AbstractFhirResourceDhisToFhirTransformerUtils fhirResourceTransformerUtils = getFhirResourceTransformerUtils( fhirClient.getFhirVersion() ); + + do { - if ( outcome.getResource() != null ) + final DhisToFhirTransformOutcome outcome = transform( transformerRequest ); + if ( outcome == null ) { - references.add( fhirResourceTransformerUtils.createReference( outcome.getResource() ) ); + transformerRequest = null; + } + else + { + if ( outcome.getResource() != null ) + { + references.add( fhirResourceTransformerUtils.createReference( outcome.getResource() ) ); + } + + transformerRequest = outcome.getNextTransformerRequest(); } - transformerRequest = outcome.getNextTransformerRequest(); } + while ( transformerRequest != null && references.size() < max ); } - while ( (transformerRequest != null) && (references.size() < max) ); + return references; } + @Nonnull + protected IBaseReference resolveSimpleFhirIdReference( @Nonnull DhisToFhirTransformerRequest transformerRequest ) + { + final AbstractFhirResourceDhisToFhirTransformerUtils fhirResourceTransformerUtils = getFhirResourceTransformerUtils( transformerRequest.getContext().getFhirVersion() ); + final DhisToFhirTransformerRequestImpl transformerRequestImpl = (DhisToFhirTransformerRequestImpl) transformerRequest; + final RuleInfo ruleInfo = Objects.requireNonNull( transformerRequestImpl.nextRule() ); + + final FhirResourceType fhirResourceType = ruleInfo.getRule().getFhirResourceType(); + final IBaseResource resource = fhirResourceTransformerUtils.createResource( fhirResourceType ); + resource.setId( new IdDt( fhirResourceType.getResourceTypeName(), transformerRequestImpl.getInput().getId() ) ); + + return fhirResourceTransformerUtils.createReference( resource ); + } + @Nullable protected DhisToFhirTransformerRequest createTransformerRequest( @Nonnull FhirClient fhirClient, @Nonnull DhisRequest dhisRequest, @Nonnull ScriptedDhisResource scriptedDhisResource, @Nullable Set fhirResourceTypes ) { diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java index d1e4c2f2..ba7bab39 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java @@ -123,10 +123,12 @@ private DhisFhirResourceId getSearchedDhisResourceId( @Nonnull String fhirSearch } final DhisFhirResourceId dhisFhirResourceId = extractDhisFhirResourceId( spv.getValues().get( 0 ) ); - if ( !dhisFhirResourceId.getType().equals( dhisType ) ) + + if ( dhisFhirResourceId.isQualified() && !dhisFhirResourceId.getType().equals( dhisType ) ) { throw new DhisToFhirDataProviderException( "Search filter contains unexpected FHIR resource reference: " + dhisFhirResourceId ); } + return dhisFhirResourceId; } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java index e374bf92..6cff6c1b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java @@ -167,8 +167,7 @@ public FhirToDhisTransformerRequest createTransformerRequest( @Nonnull FhirReque @Override public FhirToDhisDeleteTransformOutcome delete( @Nonnull FhirClientResource fhirClientResource, @Nonnull DhisFhirResourceId dhisFhirResourceId ) throws TransformerException { - final RuleInfo ruleInfo = ruleRepository.findOneImpByDhisFhirInputData( - Objects.requireNonNull( fhirClientResource.getFhirResourceType() ), Objects.requireNonNull( dhisFhirResourceId.getType() ), dhisFhirResourceId.getRuleId() ).orElse( null ); + final RuleInfo ruleInfo = getDeleteRuleInfo( fhirClientResource, dhisFhirResourceId ); if ( ruleInfo == null ) { @@ -188,6 +187,25 @@ public FhirToDhisDeleteTransformOutcome delete( @Nonnull return transformer.transformDeletionCasted( fhirClientResource, ruleInfo, dhisFhirResourceId ); } + @Nullable + protected RuleInfo getDeleteRuleInfo( @Nonnull FhirClientResource fhirClientResource, @Nonnull DhisFhirResourceId dhisFhirResourceId ) + { + final RuleInfo ruleInfo; + + if ( dhisFhirResourceId.isQualified() ) + { + ruleInfo = ruleRepository.findOneImpByDhisFhirInputData( Objects.requireNonNull( fhirClientResource.getFhirResourceType() ), + dhisFhirResourceId.getType(), dhisFhirResourceId.getRuleId() ).orElse( null ); + } + else + { + ruleInfo = ruleRepository.findOneExpByDhisFhirInputData( fhirClientResource.getFhirResourceType() ) + .filter( ri -> ri.getRule().isSimpleFhirId() ).orElse( null ); + } + + return ruleInfo; + } + @Nullable @Override public FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransformerRequest transformerRequest ) throws TransformerException diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java index e2c80dfb..ed121e70 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/DhisFhirResourceIdTest.java @@ -28,9 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.junit.Assert; import org.junit.Test; +import java.util.UUID; + /** * Unit tests for {@link DhisFhirResourceId}. * @@ -55,4 +59,59 @@ public void isValid() { Assert.assertTrue( DhisFhirResourceId.isValid( "ldXIdLNUNEn" ) ); } + + @Test + public void getDhisResourceId() + { + Assert.assertEquals( new DhisResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890" ), + new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890", UUID.randomUUID() ).getDhisResourceId() ); + } + + @Test( expected = FhirRepositoryException.class ) + public void getDhisResourceIdUnqualified() + { + new DhisFhirResourceId( "a1234567890" ).getDhisResourceId(); + } + + @Test + public void isQualified() + { + Assert.assertTrue( new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890", UUID.randomUUID() ).isQualified() ); + } + + @Test + public void isUnqualified() + { + Assert.assertFalse( new DhisFhirResourceId( "a1234567890" ).isQualified() ); + } + + @Test + public void toQualified() + { + final UUID ruleId = UUID.randomUUID(); + + Assert.assertEquals( new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890", ruleId ), + new DhisFhirResourceId( "a1234567890" ).toQualified( DhisResourceType.TRACKED_ENTITY, ruleId ) ); + } + + @Test + public void parseUnqualified() + { + Assert.assertEquals( new DhisFhirResourceId( "a1234567890" ), DhisFhirResourceId.parse( "a1234567890" ) ); + } + + @Test + public void toUnqualifiedString() + { + Assert.assertEquals( "a1234567890", new DhisFhirResourceId( "a1234567890" ).toString() ); + } + + @Test + public void toQualifiedString() + { + final UUID ruleId = UUID.fromString( "7a6ceb64-3ab0-4a3d-acc1-65d9d562d589" ); + + Assert.assertEquals( "te-a1234567890-7a6ceb643ab04a3dacc165d9d562d589", + new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890", ruleId ).toString() ); + } } \ No newline at end of file diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImplTest.java new file mode 100644 index 00000000..a6b0fd0d --- /dev/null +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImplTest.java @@ -0,0 +1,181 @@ +package org.dhis2.fhir.adapter.fhir.repository.impl; + +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.auth.Authorization; +import org.dhis2.fhir.adapter.auth.AuthorizationContext; +import org.dhis2.fhir.adapter.cache.RequestCacheService; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceRepository; +import org.dhis2.fhir.adapter.dhis.sync.StoredDhisResourceService; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; +import org.dhis2.fhir.adapter.fhir.data.repository.FhirDhisAssignmentRepository; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirClient; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; +import org.dhis2.fhir.adapter.fhir.repository.DhisFhirResourceId; +import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.transform.config.FhirRestInterfaceConfig; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerRequest; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerService; +import org.dhis2.fhir.adapter.lock.LockManager; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.Collections; +import java.util.Optional; +import java.util.UUID; + +/** + * Unit tests for {@link DhisRepositoryImpl}. + * + * @author volsch + */ +public class DhisRepositoryImplTest +{ + @Mock + private AuthorizationContext authorizationContext; + + @Mock + private Authorization systemDhis2Authorization; + + @Mock + private LockManager lockManager; + + @Mock + private RequestCacheService requestCacheService; + + @Mock + private StoredDhisResourceService storedItemService; + + @Mock + private DhisResourceRepository dhisResourceRepository; + + @Mock + private DhisToFhirTransformerService dhisToFhirTransformerService; + + @Mock + private FhirResourceRepository fhirResourceRepository; + + @Mock + private FhirDhisAssignmentRepository fhirDhisAssignmentRepository; + + @Mock + private FhirRestInterfaceConfig fhirRestInterfaceConfig; + + @Mock + private FhirClient fhirClient; + + private final UUID ruleId = UUID.randomUUID(); + + private TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance(); + + @Mock + private DhisToFhirTransformerRequest transformerRequest; + + private final TrackedEntityRule rule = new TrackedEntityRule(); + + @Mock + private IBaseResource resultResource; + + @InjectMocks + private DhisRepositoryImpl repository; + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Test + public void readQualifiedId() + { + Mockito.doReturn( Optional.of( trackedEntityInstance ) ).when( dhisResourceRepository ) + .findRefreshed( Mockito.eq( new DhisResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890" ) ) ); + Mockito.doReturn( transformerRequest ).when( dhisToFhirTransformerService ) + .createTransformerRequest( Mockito.same( fhirClient ), Mockito.any(), Mockito.same( trackedEntityInstance ), Mockito.eq( FhirResourceType.PATIENT ), Mockito.eq( ruleId ) ); + Mockito.doReturn( ruleId ).when( transformerRequest ).getRuleId(); + Mockito.doReturn( new DhisToFhirTransformOutcome<>( rule, resultResource ) ).when( dhisToFhirTransformerService ).transform( Mockito.same( transformerRequest ) ); + + final Optional result = repository.read( fhirClient, FhirResourceType.PATIENT, new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890", ruleId ) ); + + Assert.assertTrue( result.isPresent() ); + Assert.assertSame( resultResource, result.get() ); + } + + @Test + public void readNonQualifiedIdNoRule() + { + Mockito.doReturn( null ).when( dhisToFhirTransformerService ).findSingleRule( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.PATIENT ) ); + + final Optional result = repository.read( fhirClient, FhirResourceType.PATIENT, new DhisFhirResourceId( "a1234567890" ) ); + + Assert.assertFalse( result.isPresent() ); + } + + @Test + public void readNonQualifiedIdNoSimpleIdRule() + { + rule.setId( ruleId ); + rule.setSimpleFhirId( false ); + + Mockito.doReturn( new RuleInfo<>( rule, Collections.emptyList() ) ).when( dhisToFhirTransformerService ).findSingleRule( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.PATIENT ) ); + + final Optional result = repository.read( fhirClient, FhirResourceType.PATIENT, new DhisFhirResourceId( "a1234567890" ) ); + + Assert.assertFalse( result.isPresent() ); + } + + @Test + public void readNonQualifiedId() + { + rule.setId( ruleId ); + rule.setSimpleFhirId( true ); + + Mockito.doReturn( new RuleInfo<>( rule, Collections.emptyList() ) ).when( dhisToFhirTransformerService ).findSingleRule( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.PATIENT ) ); + Mockito.doReturn( Optional.of( trackedEntityInstance ) ).when( dhisResourceRepository ) + .findRefreshed( Mockito.eq( new DhisResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890" ) ) ); + Mockito.doReturn( transformerRequest ).when( dhisToFhirTransformerService ) + .createTransformerRequest( Mockito.same( fhirClient ), Mockito.any(), Mockito.same( trackedEntityInstance ), Mockito.eq( FhirResourceType.PATIENT ), Mockito.eq( ruleId ) ); + Mockito.doReturn( ruleId ).when( transformerRequest ).getRuleId(); + Mockito.doReturn( new DhisToFhirTransformOutcome<>( rule, resultResource ) ).when( dhisToFhirTransformerService ).transform( Mockito.same( transformerRequest ) ); + + final Optional result = repository.read( fhirClient, FhirResourceType.PATIENT, new DhisFhirResourceId( "a1234567890" ) ); + + Assert.assertTrue( result.isPresent() ); + Assert.assertSame( resultResource, result.get() ); + } +} \ No newline at end of file diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImplTest.java index 376866f1..949b3cd2 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImplTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImplTest.java @@ -31,14 +31,17 @@ import org.dhis2.fhir.adapter.auth.AuthorizationContext; import org.dhis2.fhir.adapter.cache.RequestCacheService; import org.dhis2.fhir.adapter.dhis.sync.DhisResourceRepository; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; import org.dhis2.fhir.adapter.fhir.client.StoredFhirResourceService; import org.dhis2.fhir.adapter.fhir.data.repository.FhirDhisAssignmentRepository; import org.dhis2.fhir.adapter.fhir.data.repository.SubscriptionFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientResourceRepository; import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientSystemRepository; import org.dhis2.fhir.adapter.fhir.repository.FhirRepositoryOperation; import org.dhis2.fhir.adapter.fhir.repository.FhirRepositoryOperationType; import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerService; import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequestMethod; import org.dhis2.fhir.adapter.lock.LockManager; @@ -50,6 +53,8 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; +import java.util.UUID; + /** * Unit tests for {@link FhirResourceRepositoryImpl}. * @@ -116,4 +121,33 @@ public void getRequestMethodCreateOrUpdate() final FhirRepositoryOperation operation = new FhirRepositoryOperation( FhirRepositoryOperationType.CREATE_OR_UPDATE ); Assert.assertEquals( FhirRequestMethod.CREATE_OR_UPDATE, repository.getRequestMethod( operation ) ); } + + @Test + public void createDhisFhirResourceIdNonSimple() + { + final TrackedEntityRule rule = new TrackedEntityRule(); + rule.setId( UUID.fromString( "1f989050-500c-4eaa-b6dd-0bef9fef7023" ) ); + + final TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance(); + trackedEntityInstance.setId( "b1234567890" ); + + final FhirToDhisTransformOutcome outcome = new FhirToDhisTransformOutcome<>( rule, trackedEntityInstance, true ); + + Assert.assertEquals( "te-b1234567890-1f989050500c4eaab6dd0bef9fef7023", repository.createDhisFhirResourceId( outcome, trackedEntityInstance ) ); + } + + @Test + public void createDhisFhirResourceIdSimple() + { + final TrackedEntityRule rule = new TrackedEntityRule(); + rule.setId( UUID.fromString( "1f989050-500c-4eaa-b6dd-0bef9fef7023" ) ); + rule.setSimpleFhirId( true ); + + final TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance(); + trackedEntityInstance.setId( "b1234567890" ); + + final FhirToDhisTransformOutcome outcome = new FhirToDhisTransformOutcome<>( rule, trackedEntityInstance, true ); + + Assert.assertEquals( "b1234567890", repository.createDhisFhirResourceId( outcome, trackedEntityInstance ) ); + } } \ No newline at end of file diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImplTest.java new file mode 100644 index 00000000..eb56b55a --- /dev/null +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerRequestImplTest.java @@ -0,0 +1,121 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl; + +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.fhir.metadata.model.AbstractRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirClient; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.DhisToFhirTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedDhisResource; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Tests {@link DhisToFhirTransformerRequestImpl}. + * + * @author volsch + */ +public class DhisToFhirTransformerRequestImplTest +{ + @Mock + private DhisToFhirTransformerContext context; + + @Mock + private ScriptedDhisResource input; + + @Mock + private FhirClient fhirClient; + + private final Map transformerUtils = new HashMap<>(); + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Test + public void isSimpleFhirId() + { + final List> ruleInfos = new ArrayList<>(); + + final TrackedEntityRule trackedEntityRule = new TrackedEntityRule(); + trackedEntityRule.setSimpleFhirId( true ); + ruleInfos.add( new RuleInfo<>( trackedEntityRule, Collections.emptyList() ) ); + + final DhisToFhirTransformerRequestImpl transformerRequest = new DhisToFhirTransformerRequestImpl( + context, input, fhirClient, ruleInfos, transformerUtils ); + + Assert.assertTrue( transformerRequest.isSimpleFhirIdRule() ); + } + + @Test + public void isNotSimpleFhirId() + { + final List> ruleInfos = new ArrayList<>(); + + final TrackedEntityRule trackedEntityRule = new TrackedEntityRule(); + trackedEntityRule.setSimpleFhirId( false ); + ruleInfos.add( new RuleInfo<>( trackedEntityRule, Collections.emptyList() ) ); + + final DhisToFhirTransformerRequestImpl transformerRequest = new DhisToFhirTransformerRequestImpl( + context, input, fhirClient, ruleInfos, transformerUtils ); + + Assert.assertFalse( transformerRequest.isSimpleFhirIdRule() ); + } + + @Test + public void isNotSimpleFhirIdMultiple() + { + final List> ruleInfos = new ArrayList<>(); + + final TrackedEntityRule trackedEntityRule1 = new TrackedEntityRule(); + trackedEntityRule1.setSimpleFhirId( false ); + + final TrackedEntityRule trackedEntityRule2 = new TrackedEntityRule(); + trackedEntityRule2.setSimpleFhirId( false ); + + ruleInfos.add( new RuleInfo<>( trackedEntityRule1, Collections.emptyList() ) ); + ruleInfos.add( new RuleInfo<>( trackedEntityRule2, Collections.emptyList() ) ); + + final DhisToFhirTransformerRequestImpl transformerRequest = new DhisToFhirTransformerRequestImpl( + context, input, fhirClient, ruleInfos, transformerUtils ); + + Assert.assertFalse( transformerRequest.isSimpleFhirIdRule() ); + } +} diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java new file mode 100644 index 00000000..967efc05 --- /dev/null +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java @@ -0,0 +1,321 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl; + +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.model.primitive.IdDt; +import org.dhis2.fhir.adapter.cache.RequestCacheService; +import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnitService; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirClient; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; +import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientResourceRepository; +import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientSystemRepository; +import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; +import org.dhis2.fhir.adapter.fhir.model.FhirVersion; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.AbstractFhirResourceDhisToFhirTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedDhisResource; +import org.dhis2.fhir.adapter.lock.LockManager; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseMetaType; +import org.hl7.fhir.instance.model.api.IBaseReference; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Unit tests of {@link DhisToFhirTransformerServiceImpl}. + * + * @author volsch + */ +public class DhisToFhirTransformerServiceImplTest +{ + @Mock + private LockManager lockManager; + + @Mock + private FhirClientResourceRepository fhirClientResourceRepository; + + @Mock + private FhirClientSystemRepository fhirClientSystemRepository; + + @Mock + private OrganizationUnitService organizationUnitService; + + @Mock + private RuleRepository ruleRepository; + + @Mock + private RequestCacheService requestCacheService; + + @Mock + private ScriptExecutor scriptExecutor; + + private DhisToFhirTransformerServiceImpl service; + + @Mock + private FhirClient fhirClient; + + @Mock + private ScriptedDhisResource scriptedDhisResource; + + @Mock + private DhisToFhirTransformerRequestImpl transformerRequest; + + private AbstractFhirResourceDhisToFhirTransformerUtils resourceTransformerUtils; + + @Mock + private DhisToFhirTransformerContext context; + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Before + public void setUp() + { + resourceTransformerUtils = Mockito.mock( AbstractFhirResourceDhisToFhirTransformerUtils.class, Mockito.CALLS_REAL_METHODS ); + Mockito.doReturn( FhirVersion.R4_ONLY ).when( resourceTransformerUtils ).getFhirVersions(); + + service = new DhisToFhirTransformerServiceImpl( + lockManager, fhirClientResourceRepository, fhirClientSystemRepository, organizationUnitService, + ruleRepository, requestCacheService, + new StaticObjectProvider<>( new ArrayList<>() ), + new StaticObjectProvider<>( new ArrayList<>() ), + new StaticObjectProvider<>( new ArrayList<>() ), + new StaticObjectProvider<>( Collections.singletonList( resourceTransformerUtils ) ), + scriptExecutor ); + service = Mockito.spy( service ); + } + + @Test + public void resolveFhirReferenceSimpleId() + { + final TrackedEntityRule trackedEntityRule = new TrackedEntityRule(); + trackedEntityRule.setFhirResourceType( FhirResourceType.PATIENT ); + trackedEntityRule.setSimpleFhirId( true ); + + Mockito.doReturn( transformerRequest ).when( service ).createTransformerRequest( Mockito.same( fhirClient ), Mockito.any(), Mockito.same( scriptedDhisResource ), Mockito.any() ); + Mockito.when( scriptedDhisResource.getId() ).thenReturn( "a1234567890" ); + Mockito.when( transformerRequest.isSimpleFhirIdRule() ).thenReturn( true ); + Mockito.when( transformerRequest.getInput() ).thenReturn( scriptedDhisResource ); + Mockito.when( scriptedDhisResource.getId() ).thenReturn( "a1234567890" ); + Mockito.when( transformerRequest.getContext() ).thenReturn( context ); + Mockito.when( context.getFhirVersion() ).thenReturn( FhirVersion.R4 ); + Mockito.doReturn( new RuleInfo<>( trackedEntityRule, Collections.emptyList() ) ).when( transformerRequest ).nextRule(); + Mockito.doReturn( new TestResource() ).when( resourceTransformerUtils ).createResource( Mockito.eq( "Patient" ) ); + Mockito.doAnswer( invocation -> new TestReference( ( (IBaseResource) invocation.getArgument( 0 ) ).getIdElement().toString() ) ).when( resourceTransformerUtils ).createReference( Mockito.any() ); + + final List references = service.resolveFhirReferences( fhirClient, scriptedDhisResource, Collections.singleton( FhirResourceType.PATIENT ), 10 ); + Assert.assertEquals( 1, references.size() ); + Assert.assertEquals( "Patient/a1234567890", references.get( 0 ).toString() ); + } + + @Test + public void resolveFhirReference() + { + final TrackedEntityRule trackedEntityRule = new TrackedEntityRule(); + trackedEntityRule.setFhirResourceType( FhirResourceType.PATIENT ); + trackedEntityRule.setSimpleFhirId( true ); + + final IBaseResource resource = new TestResource(); + resource.setId( new IdDt( "Patient", "a1234567890" ) ); + + final DhisToFhirTransformOutcome outcome = new DhisToFhirTransformOutcome<>( trackedEntityRule, resource, false ); + + Mockito.when( fhirClient.getFhirVersion() ).thenReturn( FhirVersion.R4 ); + Mockito.doReturn( transformerRequest ).when( service ).createTransformerRequest( Mockito.same( fhirClient ), Mockito.any(), Mockito.same( scriptedDhisResource ), Mockito.any() ); + Mockito.doReturn( outcome ).when( service ).transform( Mockito.same( transformerRequest ) ); + Mockito.when( scriptedDhisResource.getId() ).thenReturn( "a1234567890" ); + Mockito.when( transformerRequest.isSimpleFhirIdRule() ).thenReturn( false ); + Mockito.doAnswer( invocation -> new TestReference( ( (IBaseResource) invocation.getArgument( 0 ) ).getIdElement().toString() ) ).when( resourceTransformerUtils ).createReference( Mockito.same( resource ) ); + + final List references = service.resolveFhirReferences( fhirClient, scriptedDhisResource, Collections.singleton( FhirResourceType.PATIENT ), 10 ); + Assert.assertEquals( 1, references.size() ); + Assert.assertEquals( "Patient/a1234567890", references.get( 0 ).toString() ); + } + + public static class TestResource implements IBaseResource + { + private static final long serialVersionUID = -2782382154208526668L; + + private IIdType id; + + @Override + public IBaseMetaType getMeta() + { + return null; + } + + @Override + public IIdType getIdElement() + { + return id; + } + + @Override + public IBaseResource setId( String theId ) + { + id = new IdDt( theId ); + return this; + } + + @Override + public IBaseResource setId( IIdType theId ) + { + id = theId; + return this; + } + + @Override + public FhirVersionEnum getStructureFhirVersionEnum() + { + return null; + } + + @Override + public boolean isEmpty() + { + return false; + } + + @Override + public boolean hasFormatComment() + { + return false; + } + + @Override + public List getFormatCommentsPre() + { + return null; + } + + @Override + public List getFormatCommentsPost() + { + return null; + } + } + + public static class TestReference implements IBaseReference + { + private static final long serialVersionUID = -3963810347197066321L; + + private String reference; + + public TestReference( String reference ) + { + this.reference = reference; + } + + @Override + public IBaseResource getResource() + { + return null; + } + + @Override + public void setResource( IBaseResource theResource ) + { + // nothing to be done + } + + @Override + public IIdType getReferenceElement() + { + return null; + } + + @Override + public IBaseReference setReference( String theReference ) + { + reference = theReference; + return this; + } + + @Override + public IBase setDisplay( String theValue ) + { + return null; + } + + @Override + public IPrimitiveType getDisplayElement() + { + return null; + } + + @Override + public boolean isEmpty() + { + return false; + } + + @Override + public boolean hasFormatComment() + { + return false; + } + + @Override + public List getFormatCommentsPre() + { + return null; + } + + @Override + public List getFormatCommentsPost() + { + return null; + } + + @Override + public String toString() + { + return reference; + } + } +} diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java index 41c4627f..2112ae12 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java @@ -55,7 +55,8 @@ public class FhirToDhisTransformerContextImplTest private FhirToDhisTransformerContextImpl context; - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); @Before public void before() diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImplTest.java new file mode 100644 index 00000000..b7e54e83 --- /dev/null +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImplTest.java @@ -0,0 +1,134 @@ +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; + +/* + * Copyright (c) 2004-2019, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.AbstractRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirClientResource; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; +import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; +import org.dhis2.fhir.adapter.fhir.repository.DhisFhirResourceId; +import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; +import org.dhis2.fhir.adapter.lock.LockManager; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Optional; +import java.util.UUID; + +/** + * Unit tests for {@link FhirToDhisTransformerServiceImpl}. + * + * @author volsch + */ +public class FhirToDhisTransformerServiceImplTest +{ + @Mock + private LockManager lockManager; + + @Mock + private FhirResourceRepository fhirResourceRepository; + + @Mock + private RuleRepository ruleRepository; + + @Mock + private ScriptExecutor scriptExecutor; + + @Mock + private FhirClientResource fhirClientResource; + + private FhirToDhisTransformerServiceImpl service; + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Before + public void setUp() + { + service = new FhirToDhisTransformerServiceImpl( lockManager, fhirResourceRepository, ruleRepository, + new StaticObjectProvider<>( new ArrayList<>() ), new StaticObjectProvider<>( new ArrayList<>() ), + scriptExecutor ); + service = Mockito.spy( service ); + } + + @Test + public void getDeleteRuleInfo() + { + final UUID ruleId = UUID.randomUUID(); + final RuleInfo ruleInfo = new RuleInfo<>( new TrackedEntityRule(), Collections.emptyList() ); + + Mockito.doReturn( FhirResourceType.PATIENT ).when( fhirClientResource ).getFhirResourceType(); + Mockito.doReturn( Optional.of( ruleInfo ) ).when( ruleRepository ).findOneImpByDhisFhirInputData( Mockito.eq( FhirResourceType.PATIENT ), + Mockito.eq( DhisResourceType.TRACKED_ENTITY ), Mockito.eq( ruleId ) ); + + final RuleInfo result = service.getDeleteRuleInfo( fhirClientResource, new DhisFhirResourceId( DhisResourceType.TRACKED_ENTITY, "a0123456789", ruleId ) ); + Assert.assertSame( ruleInfo, result ); + } + + @Test + public void getDeleteRuleInfoSimpleId() + { + final UUID ruleId = UUID.randomUUID(); + final RuleInfo ruleInfo = new RuleInfo<>( new TrackedEntityRule(), Collections.emptyList() ); + ruleInfo.getRule().setSimpleFhirId( true ); + + Mockito.doReturn( FhirResourceType.PATIENT ).when( fhirClientResource ).getFhirResourceType(); + Mockito.doReturn( Optional.of( ruleInfo ) ).when( ruleRepository ).findOneExpByDhisFhirInputData( Mockito.eq( FhirResourceType.PATIENT ) ); + + final RuleInfo result = service.getDeleteRuleInfo( fhirClientResource, new DhisFhirResourceId( "a0123456789" ) ); + Assert.assertSame( ruleInfo, result ); + } + + @Test + public void getDeleteRuleInfoNonSimpleId() + { + final UUID ruleId = UUID.randomUUID(); + final RuleInfo ruleInfo = new RuleInfo<>( new TrackedEntityRule(), Collections.emptyList() ); + ruleInfo.getRule().setSimpleFhirId( false ); + + Mockito.doReturn( FhirResourceType.PATIENT ).when( fhirClientResource ).getFhirResourceType(); + Mockito.doReturn( Optional.of( ruleInfo ) ).when( ruleRepository ).findOneExpByDhisFhirInputData( Mockito.eq( FhirResourceType.PATIENT ) ); + + final RuleInfo result = service.getDeleteRuleInfo( fhirClientResource, new DhisFhirResourceId( "a0123456789" ) ); + Assert.assertNull( result ); + } +} \ No newline at end of file