Search in sources :

Example 6 with Version

use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.

the class ContributionServiceHelperTest method extractVersionObjects.

@Test
public void extractVersionObjects() {
    // pre-step: call splitContent with first test data input (assumed to be correct as tested separately)
    Map<String, Object> splitContent = extractVersionObjectsPreStep(ContributionTestDataCanonicalJson.ONE_ENTRY_COMPOSITION.getStream(), CompositionFormat.JSON);
    // actual test
    Object versionsContent = splitContent.get("versions");
    List<Version> versions = ContributionServiceHelper.extractVersionObjects((ArrayList) versionsContent, CompositionFormat.JSON);
    extractVersionObjectsCheck(versions, 1);
    // pre-step: call splitContent with second test data input (assumed to be correct as tested separately)
    Map<String, Object> splitContent2 = extractVersionObjectsPreStep(ContributionTestDataCanonicalJson.TWO_ENTRIES_COMPOSITION.getStream(), CompositionFormat.JSON);
    // actual test
    Object versionsContent2 = splitContent2.get("versions");
    List<Version> versions2 = ContributionServiceHelper.extractVersionObjects((ArrayList) versionsContent2, CompositionFormat.JSON);
    extractVersionObjectsCheck(versions2, 2);
// TODO add more test data and XML when ready
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Example 7 with Version

use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.

the class ContributionServiceHelperTest method extractVersionObjectsCheck.

// helper method with the actual logical tests
private void extractVersionObjectsCheck(List<Version> versions, int numVersions) {
    assertEquals(numVersions, versions.size());
    for (Version version : versions) {
        assertNotNull(version.getData());
        assertTrue(version.getData() instanceof LinkedHashMap);
    }
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Version

use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.

the class ContributionServiceImp method getListOfTemplates.

@Override
public Set<String> getListOfTemplates(String contribution, CompositionFormat format) {
    List<Version> versions = ContributionServiceHelper.parseVersions(contribution, format);
    Set<String> templates = new HashSet<>();
    for (Version version : versions) {
        Object versionData = version.getData();
        // the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
        if (versionData != null) {
            RMObject versionRmObject;
            if (versionData instanceof LinkedHashMap) {
                versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) versionData, format);
            } else {
                throw new IllegalArgumentException("Contribution input can't be processed");
            }
            // switch to allow acting depending on exact type
            SupportedClasses versionClass;
            try {
                versionClass = SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase());
            } catch (Exception e) {
                throw new InvalidApiParameterException("Invalid version object in contribution. " + versionRmObject.getClass().getSimpleName().toUpperCase() + " not supported.");
            }
            switch(versionClass) {
                case COMPOSITION:
                    TemplateId templateId = ((Composition) versionRmObject).getArchetypeDetails().getTemplateId();
                    if (templateId != null) {
                        templates.add(templateId.getValue());
                    }
                    break;
                // TODO: might add later, if other_details support templated content
                case EHRSTATUS:
                case FOLDER:
                default:
                    throw new IllegalArgumentException("Contribution input contains invalid version class");
            }
        }
    }
    return templates;
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) RMObject(com.nedap.archie.rm.RMObject)

Aggregations

Version (com.nedap.archie.rm.changecontrol.Version)8 RMObject (com.nedap.archie.rm.RMObject)6 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)1 AuditDetails (com.nedap.archie.rm.generic.AuditDetails)1 InputStream (java.io.InputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 UnexpectedSwitchCaseException (org.ehrbase.api.exception.UnexpectedSwitchCaseException)1 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)1