SORMAS-Foundation / SORMAS-Project

SORMAS (Surveillance, Outbreak Response Management and Analysis System) is an early warning and management system to fight the spread of infectious diseases.
https://sormas.org
GNU General Public License v3.0
293 stars 143 forks source link

Updating case data via sormas-rest #7459

Open ThomasSeitzKoeln opened 2 years ago

ThomasSeitzKoeln commented 2 years ago

Problem Description

While we are able to get case, person and sample data from the api, we are struggeling to update the cases in sormas after they have been edited in our system.

We are trying to post to /cases/postUpdate/{uuid} but all our tries have led to a Error 500 in response. One of the ways we tried is the following post request (sanitized test request):

curl --location --request POST 'https://test-***.sormas.netzlink.com/sormas-rest/cases/postUpdate/**GUHK-**IWLE-O2SO**-GROM***' \
--header 'Content-Type: application/json; charset=UTF-8' \
--header 'Authorization: Basic ***=' \
--data-raw '{
    "creationDate": 1634122267216,
    "changeDate": 163515029990,
    "uuid": "**GUHK-**IWLE-O2SO**-GROM***",
    "pseudonymized": false,
    "disease": "CORONAVIRUS",
    "diseaseVariant": {
        "value": "UNBEKANNT",
        "caption": "Unbekannt"
    },...

}'

How does a working post to this route have to look like?

Thank you for your feedback

MateStrysewske commented 2 years ago

@ThomasSeitzKoeln Please note that the postUpdate endpoint is experimental and isn't yet supposed to be used in production environments. We can't guarantee that there is no data loss when using it.

Since you're getting an internal server error, getting the error log messages from the server at the time such a request is sent would be necessary to figure out what the problem might be. Maybe @MartinWahnschaffe and @marius2301 can answer whether the format of the request seems fine in general.

JonasCir commented 2 years ago

@ThomasSeitzKoeln You might be interested in this as it allows you to generate clients to the API in a language of your choice. More convenient than using curl :)

ThomasSeitzKoeln commented 2 years ago

@MartinWahnschaffe @marius2301 MateStrysewske mentioned you might now how to update cases in sormas via rest api. Would you please take a look at my problem description and help out? Thank you very much.

MartinWahnschaffe commented 2 years ago

Hi @ThomasSeitzKoeln. I just had a look at this and have a few points that may cause the problem.

First of all: Ideally you would have access to the server log of the receiving server when experimenting with this. If that's not the case you could also setup a server on your local system for this. That's obviously nothing that you have to do, but it will make your live a lot easier if you can directly see what is going on.

The postUpdate method is meant to update existing entities. This has a few implications:

  1. The creationDate is not needed here, because the entity has already been created and this will not be overidden anyway
  2. The changeDate has to be greater or equal to the change date of the existing entity in the system. Otherwise the system will think that you are operating on an outdated version of the entity. You can you /cases/[UUID] to get the current change date of the case. This is most likely what is causing the error 500. We haven't clarified yet on how to deal with this - that's partly why the method is still experimental.
  3. The pseudonymized field is not needed here - it's not a property of the actual case, instead it informs you whether a retrieved case has been pseudonymized based on your user rights.
  4. The available options of diseaseVariant depend on what is configured in the server you are accessing.

Hope that helps. Most likely point two will cause your problem. With the experimental version of the method you can just leave the changeDate parameter out and it should work.