Skip to content

Unable to update the records on your server #40

@pavan3202

Description

@pavan3202

I am trying to update the record in the FHIR server it is throwing me following exception with 500 status. I am not sure some this is missing.
Below is the Exception I am getting

" Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://fhir.dev.aimsplatform.com/Patient/1272431_format=xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.test.HttpURLConnectionExample.updatePatientRecord(HttpURLConnectionExample.java:157)
at com.test.HttpURLConnectionExample.main(HttpURLConnectionExample.java:30)"

Following is the code snippet I am using. Please help me on this

//update particular patient record
private void updatePatientRecord(int PatientID) throws Exception {

        String url = "http://fhir.dev.aimsplatform.com/Patient/" + PatientID +"_format=xml";            
        //PUT https://example.com/path/{resourceType}/{id}

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

         String authStr = "client"+":"+"secret";
            System.out.println("Original String is " + authStr);

        // encode data on your side using BASE64
            byte[] bytesEncoded = Base64.getEncoder().encode(authStr .getBytes());
            String authEncoded = new String(bytesEncoded);
            con.setRequestProperty("Authorization", "Basic "+authEncoded);  
        // optional default is PUT
        con.setRequestMethod("PUT");  


        con.setDoOutput(true);
        con.setDoInput(true);
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("Accept", "application/json");             

        JSONObject details = new JSONObject();      

        details.put("city","california");
        details.put("country","usa");

        OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
        wr.write(details.toString());;
        wr.flush(); 


         InputStream ins = con.getInputStream();
         InputStreamReader isr = new InputStreamReader(ins);
         BufferedReader in = new BufferedReader(isr);

         //output the information        

         String inputLine;
         while ((inputLine = in.readLine()) != null)
         {
             System.out.println(inputLine);
         }
         in.close();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions