hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.02k stars 1.32k forks source link

Error Creating Patient Resource #386

Closed YasiAap closed 4 years ago

YasiAap commented 8 years ago

Hi James!

I have a problem which I don't know how to solve it. I am developing an application using android Studio. I have added three following HAPI FHIR Jar files libs folder of the app: (hapi-fhir-android-1.5 , hapi-fhir-base-1.5 , hapi-fhir-structures-dstu2-1.5)

and here is piece code I've written to create a simple Patient Resource: ` Patient patient = new Patient(); HumanNameDt na=patient.addName(); na.addFamily(lName).addGiven(fName);

    IdentifierDt id=patient.addIdentifier();
    id.setSystem("http://acme.org/MRNs").setValue(patientIdentity);

    switch (sex) {
        case "Male":
            patient.setGender(AdministrativeGenderEnum.MALE);
            break;
        case "Female":
            patient.setGender(AdministrativeGenderEnum.FEMALE);
            break;
        default:
            patient.setGender(AdministrativeGenderEnum.OTHER);
            break;
    }

    ContactPointDt contact=patient.addTelecom();     contact.setUse(ContactPointUseEnum.HOME).setSystem(ContactPointSystemEnum.PHONE).setValue(tel1);

    AddressDt ad=patient.addAddress();
    ad.setUse(AddressUseEnum.HOME).setType(AddressTypeEnum.POSTAL);
    ad.setText(add1).setCity(city).setState(state).setPostalCode(postalCode).setCountry(country);

    FhirContext ctx = FhirContext.forDstu2();
    ctx.newXmlParser();

    IParser p= ctx.newXmlParser();
    p.setPrettyPrint(true);

    String encode=p.encodeResourceToString(patient);
    System.out.println(encode);`

following is the error I face:

6-15 21:44:24.931 17816-17816/polimi.aap.yas.personalhealthrecord E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: polimi.aap.yas.personalhealthrecord, PID: 17816
                                                                                     ca.uhn.fhir.context.ConfigurationException: Unknown class[ca.uhn.fhir.model.primitive.XhtmlDt] for data type definition: xhtml
                                                                                         at ca.uhn.fhir.context.ModelScanner.scanVersionPropertyFile(ModelScanner.java:832)
                                                                                         at ca.uhn.fhir.context.ModelScanner.init(ModelScanner.java:192)
                                                                                         at ca.uhn.fhir.context.ModelScanner.<init>(ModelScanner.java:114)
                                                                                         at ca.uhn.fhir.context.FhirContext.scanResourceTypes(FhirContext.java:473)
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:145)
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:118)
                                                                                         at ca.uhn.fhir.context.FhirContext.forDstu2(FhirContext.java:611)
                                                                                         at polimi.aap.yas.personalhealthrecord.SendDemoRecord.onClick(SendDemoRecord.java:227)
                                                                                         at android.view.View.performClick(View.java:4508)
                                                                                         at android.view.View$PerformClick.run(View.java:18675)
                                                                                         at android.os.Handler.handleCallback(Handler.java:733)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:136)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5590)
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
                                                                                         at dalvik.system.NativeStart.main(Native Method)
                                                                                      Caused by: java.lang.ClassNotFoundException: ca.uhn.fhir.model.primitive.XhtmlDt
                                                                                         at java.lang.Class.classForName(Native Method)
                                                                                         at java.lang.Class.forName(Class.java:251)
                                                                                         at java.lang.Class.forName(Class.java:216)
                                                                                         at ca.uhn.fhir.context.ModelScanner.scanVersionPropertyFile(ModelScanner.java:815)
                                                                                         at ca.uhn.fhir.context.ModelScanner.init(ModelScanner.java:192) 
                                                                                         at ca.uhn.fhir.context.ModelScanner.<init>(ModelScanner.java:114) 
                                                                                         at ca.uhn.fhir.context.FhirContext.scanResourceTypes(FhirContext.java:473) 
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:145) 
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:118) 
                                                                                         at ca.uhn.fhir.context.FhirContext.forDstu2(FhirContext.java:611) 
                                                                                         at polimi.aap.yas.personalhealthrecord.SendDemoRecord.onClick(SendDemoRecord.java:227) 
                                                                                         at android.view.View.performClick(View.java:4508) 
                                                                                         at android.view.View$PerformClick.run(View.java:18675) 
                                                                                         at android.os.Handler.handleCallback(Handler.java:733) 
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                         at android.os.Looper.loop(Looper.java:136) 
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5590) 
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
                                                                                         at dalvik.system.NativeStart.main(Native Method) 
                                                                                      Caused by: java.lang.VerifyError: ca/uhn/fhir/model/primitive/XhtmlDt
                                                                                         at java.lang.Class.classForName(Native Method) 
                                                                                         at java.lang.Class.forName(Class.java:251) 
                                                                                         at java.lang.Class.forName(Class.java:216) 
                                                                                         at ca.uhn.fhir.context.ModelScanner.scanVersionPropertyFile(ModelScanner.java:815) 
                                                                                         at ca.uhn.fhir.context.ModelScanner.init(ModelScanner.java:192) 
                                                                                         at ca.uhn.fhir.context.ModelScanner.<init>(ModelScanner.java:114) 
                                                                                         at ca.uhn.fhir.context.FhirContext.scanResourceTypes(FhirContext.java:473) 
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:145) 
                                                                                         at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:118) 
                                                                                         at ca.uhn.fhir.context.FhirContext.forDstu2(FhirContext.java:611) 
                                                                                         at polimi.aap.yas.personalhealthrecord.SendDemoRecord.onClick(SendDemoRecord.java:227) 
                                                                                         at android.view.View.performClick(View.java:4508) 
                                                                                         at android.view.View$PerformClick.run(View.java:18675) 
                                                                                         at android.os.Handler.handleCallback(Handler.java:733) 
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                         at android.os.Looper.loop(Looper.java:136) 
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5590) 
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
                                                                                         at dalvik.system.NativeStart.main(Native Method) 

Can you tell me what is the problem? and how can I solve it?

YasiAap commented 8 years ago

even I copied your code exactly , and only with a little change as following:

`  // Create a Patient
        Patient pat = new Patient();
        pat.addName().addFamily("Simpson").addGiven("Homer").addGiven("J");
        pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
       // pat.addIdentifier().setLabel("Library Card 12345").setValue("12345");
        pat.addTelecom().setUse(ContactPointUseEnum.HOME).setSystem(ContactPointSystemEnum.PHONE).setValue("1 (416) 340-4800");
        pat.setGender(AdministrativeGenderEnum.MALE);

        // Create a context
        FhirContext ctx = new FhirContext();

        // Create a XML parser
        IParser parser = ctx.newXmlParser();
        parser.setPrettyPrint(true);

        String encode = parser.encodeResourceToString(pat);
        System.out.println(encode);`

I use dstu2 instead of dstu in the sample. But again I face an error said : ca.uhn.fhir.context.ConfigurationException: Unknown class[ca.uhn.fhir.model.primitive.XhtmlDt] for data type definition: xhtml

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.