如何在类中获取 PATH 注释

问题描述 投票:0回答:1

我有下一个我无法解决的问题

我不知道如何访问与主类不同的类中的下一个注释(IdentificationCluster 的@Path 注释)。问题是我遵循使用 getAnnotation() 方法获取注释的典型方法,但无法获取。

package org.example.n2composition;

import com.nedap.archie.rm.archetyped.FeederAudit;
import com.nedap.archie.rm.generic.Participation;
import com.nedap.archie.rm.generic.PartyIdentified;
import com.nedap.archie.rm.generic.PartyProxy;
import java.lang.String;
import java.time.temporal.TemporalAccessor;
import java.util.List;
import javax.annotation.processing.Generated;
import org.ehrbase.client.annotations.Archetype;
import org.ehrbase.client.annotations.Entity;
import org.ehrbase.client.annotations.Id;
import org.ehrbase.client.annotations.Path;
import org.ehrbase.client.annotations.Template;
import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;
import org.ehrbase.client.classgenerator.shareddefinition.Category;
import org.ehrbase.client.classgenerator.shareddefinition.Language;
import org.ehrbase.client.classgenerator.shareddefinition.Setting;
import org.ehrbase.client.classgenerator.shareddefinition.Territory;
import org.ehrbase.client.openehrclient.VersionUid;
import org.example.n2composition.definition.CodedTextDefiningCode;
import org.example.n2composition.definition.IdentificationCluster;
import org.example.n2composition.definition.PatientroleCluster;
import org.example.n2composition.definition.ProblemDiagnosisEvaluation;

@Entity
@Archetype("openEHR-EHR-COMPOSITION.information.v0")
@Generated(
    value = "org.ehrbase.client.classgenerator.ClassGenerator",
    date = "2023-03-24T11:50:15.994180+01:00",
    comments = "https://github.com/ehrbase/openEHR_SDK Version: 1.26.0-SNAPSHOT"
)
@Template("2")
public class N2Composition implements CompositionEntity {
  /**
   * Path: 2/Coded text
   */
  @Path("/category[at0001]|defining_code")
  private CodedTextDefiningCode codedTextDefiningCode;

  /**
   * Path: 2/Event Context/CLUSTER/identification
   * Description: identification
   */
  @Path("/context[at0002]/other_context[at0018]/items[at0019]/items[openEHR-EHR-CLUSTER.identification.v0]")
  private IdentificationCluster identification;

一旦我尝试调用注释,就会发生下一个错误。

package org.example;



import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.nedap.archie.rm.datavalues.DvCodedText;
import org.ehrbase.client.annotations.Template;
import org.example.n2composition.N2Composition;
import org.example.n2composition.definition.IdentificationCluster;


import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws NoSuchFieldException {

        //Lectura del fichero para obtener los path y los valores

        ReadingFile r = new ReadingFile();

        r.resultado();

        String s1 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\MAPEO1_1.txt";

        String s2 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\ATRIBUTOSYVALORES-DIAGNÓSTICO2.txt";

        r.reading(s1,s2);

        /*System.out.println(r.getResult1());

        System.out.println(r.getResult1().size());

        System.out.println(r.getResult2());

        System.out.println(r.getResult2().size());

        System.out.println(r.getElements());

        System.out.println(r.getElements().size());*/

        List<String> list1 = r.getResult1();

        List<String> list2 = r.getResult2();

        //Finalización de la lectura del path

        //Creación de la composición y empezar a darle valores

        N2Composition n2 = new N2Composition(); //crear nueva COMPOSITION

        IdentificationCluster i = new IdentificationCluster();

        DvCodedText dv = new DvCodedText();

        dv.setValue("hola");

        i.setDvCodedText(dv);

        Field f = N2Composition.class.getDeclaredField("identification");

        String p = f.getAnnotation(Path.class).value();

        n2.setIdentification(i);

        //String p = s.g

        //System.out.println(p);






        //n2.setIdentification((i.setDvCodedText(dv.setValue(list2[])));

    }


}

enter image description here

有谁知道怎么解决吗?

java path annotations
1个回答
0
投票

看起来你的导入不正确。

在 N2Composition 类中,您正在使用 import

org.ehrbase.client.annotations.Path;

然后在主类中(以及错误消息中)

java.nio.file.Path

© www.soinside.com 2019 - 2024. All rights reserved.