Search in sources :

Example 1 with RMObject

use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.

the class ContributionServiceHelperTest method unmarshalMapContentToRmObjectCheck.

// helper method with the actual logical tests
private void unmarshalMapContentToRmObjectCheck(List<Version> versions, CompositionFormat format, ContributionServiceImp.SupportedClasses classType) {
    for (Version version : versions) {
        RMObject versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) version.getData(), format);
        assertNotNull(ContributionServiceImp.SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase()));
        assertEquals(classType, ContributionServiceImp.SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase()));
    }
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject)

Example 2 with RMObject

use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.

the class ContributionServiceHelper method extractVersionObjects.

/**
 * returns a list of RM VERSIONs extracted from given serialization
 * @param listVersions List of still serialized version objects
 * @param format Format of the serialization
 * @return List of deserialized version objects
 * @throws IllegalArgumentException when processing of given input fails
 */
public static List<Version> extractVersionObjects(ArrayList listVersions, CompositionFormat format) {
    List<Version> versionsList = new LinkedList<>();
    switch(format) {
        case JSON:
            for (Object version : listVersions) {
                try {
                    // TODO CONTRIBUTION: round trip ((string->)object->string->object) really necessary?
                    String json = JacksonUtil.getObjectMapper().writeValueAsString(version);
                    RMObject versionRmObject = new CanonicalJson().unmarshal(json, RMObject.class);
                    if (versionRmObject instanceof Version) {
                        versionsList.add((Version) versionRmObject);
                    } else {
                        throw new IllegalArgumentException("Wrong input. At least one VERSION in this contribution is invalid.");
                    }
                } catch (JsonProcessingException e) {
                    throw new IllegalArgumentException("Error while processing given json input: " + e.getMessage());
                }
            }
            break;
        case XML:
        default:
            throw new UnexpectedSwitchCaseException(format);
    }
    return versionsList;
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) UnexpectedSwitchCaseException(org.ehrbase.api.exception.UnexpectedSwitchCaseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RMObject(com.nedap.archie.rm.RMObject)

Example 3 with RMObject

use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.

the class ContributionServiceImp method commitContribution.

@Override
public UUID commitContribution(UUID ehrId, String content, CompositionFormat format) {
    // pre-step: check for valid ehrId
    if (!ehrService.hasEhr(ehrId)) {
        throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrId.toString());
    }
    // create new empty/standard-value contribution - will be updated later with full details
    I_ContributionAccess contributionAccess = I_ContributionAccess.getInstance(this.getDataAccess(), ehrId);
    // parse and set audit information from input
    AuditDetails audit = ContributionServiceHelper.parseAuditDetails(content, format);
    contributionAccess.setAuditDetailsValues(audit);
    // commits with all default values (but without audit handling as it is done above)
    UUID contributionId = contributionAccess.commit(null, null, null);
    List<Version> versions = ContributionServiceHelper.parseVersions(content, format);
    if (versions.isEmpty())
        throw new InvalidApiParameterException("Invalid Contribution, must have at least one Version object.");
    // go through those RM objects and execute the action of it (as listed in its audit) and connect it to new contribution
    for (Version version : versions) {
        Object versionData = version.getData();
        if (versionData != null) {
            // the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
            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:
                    try {
                        processCompositionVersion(ehrId, contributionId, version, (Composition) versionRmObject);
                    } catch (UnprocessableEntityException e) {
                        throw new ValidationException(e.getMessage());
                    }
                    break;
                case EHRSTATUS:
                    processEhrStatusVersion(ehrId, contributionId, version, (EhrStatus) versionRmObject);
                    break;
                case FOLDER:
                    processFolderVersion(ehrId, contributionId, version, (Folder) versionRmObject);
                    break;
                default:
                    throw new UnexpectedSwitchCaseException(versionClass);
            }
        } else {
            // version doesn't contain "data", so it is only a metadata one to, for instance, delete a specific object via ID regardless of type
            processMetadataVersion(ehrId, contributionId, version);
        }
    }
    return contributionId;
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) RMObject(com.nedap.archie.rm.RMObject)

Example 4 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class RoundTripTest method checkTestCase.

public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
    String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
    RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
    Composition composition = flatJson.unmarshal(value);
    Flattener flattener = new Flattener(new TestDataTemplateProvider());
    Object flatten = flattener.flatten(composition, testCase.dtoClass);
    Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
    RMObject actual = unflattener.unflatten(flatten);
    String actualFlat = flatJson.marshal(actual);
    List<String> errors = compere(actualFlat, value);
    softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
    softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObject(com.nedap.archie.rm.RMObject) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) RMObject(com.nedap.archie.rm.RMObject)

Example 5 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class NormalizerTest method normalize.

@Test
public void normalize() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
    OptSkeletonBuilder skeletonBuilder = new OptSkeletonBuilder();
    RMObject rmObject = skeletonBuilder.generate(template);
    Normalizer cut = new Normalizer();
    Composition actual = (Composition) cut.normalize(rmObject);
    assertThat(actual).isNotNull();
    assertThat(actual.getContent()).size().isEqualTo(0);
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) Normalizer(org.ehrbase.normalizer.Normalizer) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Aggregations

RMObject (com.nedap.archie.rm.RMObject)57 Test (org.junit.Test)19 Composition (com.nedap.archie.rm.composition.Composition)10 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)9 QueryResponseData (org.ehrbase.response.openehr.QueryResponseData)8 Locatable (com.nedap.archie.rm.archetyped.Locatable)7 List (java.util.List)7 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)6 Collectors (java.util.stream.Collectors)5 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Map (java.util.Map)4 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)4 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)3 Version (com.nedap.archie.rm.changecontrol.Version)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3