Search in sources :

Example 1 with GenericId

use of com.nedap.archie.rm.support.identification.GenericId in project fhir-bridge by ehrbase.

the class EhrController method createEHR.

@PostMapping
public ResponseEntity<String> createEHR(@RequestParam String pPatientId) {
    try {
        // taken from EhrBase tests
        PartySelf subject = new PartySelf();
        PartyRef externalRef = new PartyRef();
        externalRef.setType("PARTY_REF");
        externalRef.setNamespace("patients");
        GenericId genericId = new GenericId();
        genericId.setScheme("id_scheme");
        genericId.setValue(pPatientId);
        externalRef.setId(genericId);
        subject.setExternalRef(externalRef);
        DvText dvText = new DvText("any EHR status");
        EhrStatus ehrStatus = new EhrStatus("openEHR-EHR-ITEM_TREE.generic.v1", dvText, subject, true, true, null);
        return ResponseEntity.ok(openEhrClient.ehrEndpoint().createEhr(ehrStatus).toString());
    } catch (Exception ex) {
        return new ResponseEntity<>("Error while creating an EHR for patient id " + pPatientId, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) GenericId(com.nedap.archie.rm.support.identification.GenericId) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) PartySelf(com.nedap.archie.rm.generic.PartySelf) DvText(com.nedap.archie.rm.datavalues.DvText) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with GenericId

use of com.nedap.archie.rm.support.identification.GenericId in project ehrbase by ehrbase.

the class PartyRefValue method attributes.

/**
 * extract the attributes of party_ref
 * @return
 */
PartyRefValue attributes() {
    if (// PartySelf f.e.
    partyProxy.getExternalRef() == null)
        return this;
    PartyRef partyRef = partyProxy.getExternalRef();
    namespace = partyRef != null ? partyRef.getNamespace() : null;
    ObjectId objectId = partyRef.getId();
    value = objectId != null ? objectId.getValue() : null;
    if (objectId != null && objectId instanceof GenericId)
        scheme = ((GenericId) objectId).getScheme();
    type = partyRef != null ? partyRef.getType() : null;
    objectIdType = partyRef != null ? PartyRefIdType.valueOf(new PersistedObjectId().objectIdClassSnakeCase(partyRef)) : PartyRefIdType.undefined;
    return this;
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) GenericId(com.nedap.archie.rm.support.identification.GenericId) ObjectId(com.nedap.archie.rm.support.identification.ObjectId)

Example 3 with GenericId

use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.

the class EntryMarshalPostprocessor method process.

/**
 * {@inheritDoc} Adds the encoding information
 */
@Override
public void process(String term, Entry rmObject, Map<String, Object> values, Context<Map<String, Object>> context) {
    values.put(term + PATH_DIVIDER + "encoding|code", "UTF-8");
    values.put(term + PATH_DIVIDER + "encoding|terminology", "IANA_character-sets");
    if (rmObject.getProvider() != null) {
        PartyIdentifiedStdConfig partyIdentifiedStdConfig = new PartyIdentifiedStdConfig();
        values.putAll(partyIdentifiedStdConfig.buildChildValues(term + PATH_DIVIDER + "_provider", (PartyIdentified) rmObject.getProvider(), null));
    }
    if (rmObject.getOtherParticipations() != null) {
        IntStream.range(0, rmObject.getOtherParticipations().size()).forEach(i -> {
            callMarshal(term, "_other_participation:" + i, rmObject.getOtherParticipations().get(i), values, context, context.getNodeDeque().peek().findChildById("participation").orElse(null));
            callPostprocess(term, "_other_participation:" + i, rmObject.getOtherParticipations().get(i), values, context, context.getNodeDeque().peek().findChildById("participation").orElse(null));
        });
    }
    if (rmObject.getWorkflowId() != null) {
        addValue(values, term + "/_work_flow_id", "id", Optional.of(rmObject.getWorkflowId()).map(ObjectRef::getId).map(ObjectId::getValue).orElse(null));
        addValue(values, term + "/_work_flow_id", "id_scheme", Optional.of(rmObject.getWorkflowId()).map(ObjectRef::getId).filter(i -> GenericId.class.isAssignableFrom(i.getClass())).map(GenericId.class::cast).map(GenericId::getScheme).orElse(null));
        addValue(values, term + "/_work_flow_id", "namespace", rmObject.getWorkflowId().getNamespace());
        addValue(values, term + "/_work_flow_id", "type", rmObject.getWorkflowId().getType());
    }
}
Also used : GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) PartyIdentifiedStdConfig(org.ehrbase.serialisation.flatencoding.std.marshal.config.PartyIdentifiedStdConfig)

Example 4 with GenericId

use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.

the class DefaultValuesTest method unmarshal.

@Test
public void unmarshal() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA_WITH_CONTEXT.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
    assertThat(actual.getCategory()).isNotNull();
    assertThat(actual.getCategory().getValue()).isEqualTo("event");
    assertThat(actual.getLanguage()).isNotNull();
    assertThat(actual.getLanguage().getCodeString()).isEqualTo(Language.DE.getCode());
    assertThat(actual.getComposer()).isNotNull();
    assertThat(actual.getComposer()).getClass().isAssignableFrom(PartyIdentified.class);
    assertThat(((PartyIdentified) actual.getComposer()).getName()).isEqualTo("Silvia Blake");
    assertThat(actual.getComposer().getExternalRef().getNamespace()).isEqualTo("HOSPITAL-NS");
    assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getScheme()).isEqualTo("HOSPITAL-NS");
    assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getValue()).isEqualTo("123");
    assertThat(actual.getContext().getHealthCareFacility().getName()).isEqualTo("Hospital");
    assertThat(actual.getContext().getStartTime()).isNotNull();
    assertThat(actual.getContext().getStartTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(actual.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
    Observation observation = actual.getContent().stream().filter(c -> Observation.class.isAssignableFrom(c.getClass())).map(Observation.class::cast).findAny().orElse(null);
    assertThat(observation).isNotNull();
    assertThat(observation.getData()).isNotNull();
    assertThat(observation.getData().getOrigin().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(observation.getData().getEvents().get(0).getTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(observation.getOtherParticipations()).extracting(p -> p.getFunction().getValue(), p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getPerformer().getExternalRef().getNamespace()).containsExactlyInAnyOrder(new Tuple("requester", "Dr. Marcus Johnson", "HOSPITAL-NS"), new Tuple("performer", "Lara Markham", "HOSPITAL-NS"));
    assertThat(observation.getOtherParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
    assertThat(observation.getWorkflowId()).isNotNull();
    assertThat(observation.getWorkflowId().getNamespace()).isEqualTo("HOSPITAL-NS");
    assertThat(observation.getWorkflowId().getId().getValue()).isEqualTo("567");
    assertThat(observation.getWorkflowId().getType()).isEqualTo("ORGANISATION");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Language(org.ehrbase.client.classgenerator.shareddefinition.Language) Composition(com.nedap.archie.rm.composition.Composition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) GenericId(com.nedap.archie.rm.support.identification.GenericId) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ZoneOffset(java.time.ZoneOffset) FlatJsonUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.FlatJsonUnmarshaller) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) Tuple(org.assertj.core.groups.Tuple) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) Iterator(java.util.Iterator) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) IOUtils(org.apache.commons.io.IOUtils) Observation(com.nedap.archie.rm.composition.Observation) XmlException(org.apache.xmlbeans.XmlException) OffsetDateTime(java.time.OffsetDateTime) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) GenericId(com.nedap.archie.rm.support.identification.GenericId) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Observation(com.nedap.archie.rm.composition.Observation) FlatJsonUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.FlatJsonUnmarshaller) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 5 with GenericId

use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.

the class EntryPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, Entry rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    consumedPaths.add(term + PATH_DIVIDER + "encoding|code");
    consumedPaths.add(term + PATH_DIVIDER + "encoding|terminology");
    Map<FlatPathDto, String> subjectValues = FlatHelper.filter(values, term + "/subject", false);
    if (!subjectValues.isEmpty()) {
        if (rmObject.getSubject() == null) {
            // If it was PartyRelated it would be set by now do to the relationship  and if it was
            // PartySelf subjectValues would be empty
            rmObject.setSubject(new PartyIdentified());
        }
        callUnmarshal(term, "subject", rmObject.getSubject(), values, consumedPaths, context, context.getNodeDeque().peek().findChildById("subject").orElse(buildDummyChild("subject", context.getNodeDeque().peek())));
    }
    PartyProxy subject = rmObject.getSubject();
    if (subject == null || (subject instanceof PartyIdentified && ((PartyIdentified) subject).getName() == null && CollectionUtils.isEmpty(((PartyIdentified) subject).getIdentifiers()) && subject.getExternalRef() == null && (!(subject instanceof PartyRelated) || ((PartyRelated) subject).getRelationship() == null || StringUtils.isEmpty(((PartyRelated) subject).getRelationship().getValue())))) {
        rmObject.setSubject(new PartySelf());
    }
    Map<FlatPathDto, String> providerList = values.entrySet().stream().filter(e -> e.getKey().startsWith(term + PATH_DIVIDER + "_provider")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    if (!MapUtils.isEmpty(providerList)) {
        if (!(rmObject.getProvider() instanceof PartyIdentified)) {
            rmObject.setProvider(new PartyIdentified());
        }
        PartyIdentifiedRMUnmarshaller partyIdentifiedRMUnmarshaller = new PartyIdentifiedRMUnmarshaller();
        partyIdentifiedRMUnmarshaller.handle(term + PATH_DIVIDER + "_provider", (PartyIdentified) rmObject.getProvider(), providerList, null, consumedPaths);
    }
    Map<Integer, Map<String, String>> other = extractMultiValued(term, "_other_participation", values);
    other.values().stream().map(Map::entrySet).map(s -> s.stream().collect(Collectors.toMap(e -> "ctx/" + DefaultValuePath.PARTICIPATION.getPath() + "_" + e.getKey().replace("identifiers_", "identifiers|"), e -> StringUtils.wrap(e.getValue(), '"'))).entrySet()).map(DefaultValues::buildParticipation).forEach(rmObject::addOtherParticipant);
    consumeAllMatching(term + PATH_DIVIDER + "_other_participation", values, consumedPaths, false);
    Map<FlatPathDto, String> workflowIdValues = filter(values, term + "/_work_flow_id", false);
    if (!workflowIdValues.isEmpty()) {
        ObjectRef<GenericId> ref = new ObjectRef<>();
        ref.setId(new GenericId());
        rmObject.setWorkflowId(ref);
        setValue(term + "/_work_flow_id", "id", workflowIdValues, s -> ref.getId().setValue(s), String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "id_scheme", workflowIdValues, s -> ref.getId().setScheme(s), String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "namespace", workflowIdValues, ref::setNamespace, String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "type", workflowIdValues, ref::setType, String.class, consumedPaths);
    }
}
Also used : Entry(com.nedap.archie.rm.composition.Entry) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PartySelf(com.nedap.archie.rm.generic.PartySelf) MapUtils(org.apache.commons.collections4.MapUtils) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) PartyIdentifiedRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.PartyIdentifiedRMUnmarshaller) PATH_DIVIDER(org.ehrbase.webtemplate.parser.OPTParser.PATH_DIVIDER) GenericId(com.nedap.archie.rm.support.identification.GenericId) Map(java.util.Map) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) PartySelf(com.nedap.archie.rm.generic.PartySelf) PartyIdentifiedRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.PartyIdentifiedRMUnmarshaller) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Map(java.util.Map)

Aggregations

GenericId (com.nedap.archie.rm.support.identification.GenericId)18 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)10 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)8 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)7 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)7 Map (java.util.Map)7 Composition (com.nedap.archie.rm.composition.Composition)5 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Entry (com.nedap.archie.rm.composition.Entry)4 Participation (com.nedap.archie.rm.generic.Participation)4 OffsetDateTime (java.time.OffsetDateTime)4 Test (org.junit.Test)4 WorkflowIdTest (care.better.platform.web.template.WorkflowIdTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Section (com.nedap.archie.rm.composition.Section)3 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)3 DvText (com.nedap.archie.rm.datavalues.DvText)3 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)3