IHTSDO / snowstorm

Scalable SNOMED CT Terminology Server using Elasticsearch
Other
208 stars 83 forks source link

Default module id not working #588

Open liquid36 opened 6 months ago

liquid36 commented 6 months ago

Hi! I'm dealing with an issue trying yo create concepts. I created a new branch and set the default namespaces and module id. But if I create new concepts without moduleId, Snowstorm is still using de CORE_MODULE ID (900000000000207008).

Debugging the code i found out the problem (i think):

First, when concept is created, the CORE_MODULE is using as default:

https://github.com/IHTSDO/snowstorm/blob/master/src/main/java/org/snomed/snowstorm/core/data/domain/Concept.java#L97

So, the following conditions is always false:

https://github.com/IHTSDO/snowstorm/blob/master/src/main/java/org/snomed/snowstorm/core/data/services/ConceptUpdateHelper.java#L260

Descriptions and relationships is working fine.

kaicode commented 6 months ago

The core module should only be used when no default module is found in the branch metadata, including ancestor branches until the Codesystem branch. The core module that you found in the java constructor should only be used by unit tests. It should get set to null when deserialising JSON. Can you confirm that you are setting the module in the branch metadata using the key defaultModuleId. Can you also confirm that this module is being used for the new descriptions? Could you send an example request body too please? I can help debug this.

liquid36 commented 6 months ago

Yes, i'm using the key defaultModuleId. Look what I'm doing:

  1. Create codesystem
    
    curl -X 'POST' \
    'http://localhost:8080/codesystems' \
    -H 'accept: */*' \
    -H 'Content-Type: application/json' \
    -d '{
    "name": "TEST",
    "owner": "",
    "shortName": "TEST",
    "branchPath": "MAIN/SNOMEDCT-ES/SNOMEDCT-AR/TEST",
    "dependantVersionEffectiveTime": 20231130,
    "defaultLanguageCode": "es",
    "countryCode": "ar"

}'


2. Update branch metadata:

curl -X 'PUT' \ 'http://localhost:8080/branches/MAIN%2FSNOMEDCT-ES%2FSNOMEDCT-AR%2FTEST/metadata-upsert' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "defaultNamespace": "1000309", "defaultModuleId" : "733690761000309105"

}'


3. Create concept

curl -X 'POST' \ 'http://localhost:8080/browser/MAIN%2FSNOMEDCT-ES%2FSNOMEDCT-AR%2FTEST/concepts?validate=false' \ -H 'accept: application/json' \ -H 'Accept-Language: en-X-900000000000509007,en-X-900000000000508004,en' \ -H 'Content-Type: application/json' \ -d '{ "descriptions": [ { "active": true, "term": "test concept (finding)", "acceptabilityMap": { "450828004": "PREFERRED" }, "typeId": "900000000000003001", "type": "FSN", "lang": "es", "caseSignificance": "ENTIRE_TERM_CASE_SENSITIVE" }, { "active": true, "term": "test concept", "typeId": "900000000000013009", "acceptabilityMap": { "450828004": "PREFERRED" }, "type": "SYNONYM", "lang": "es", "caseSignificance": "ENTIRE_TERM_CASE_SENSITIVE" } ],

        "classAxioms": [

        ]
    }'
The response: 
```JSON
{
  "conceptId": "706832731000309109",
  "fsn": {},
  "pt": {},
  "active": true,
  "released": false,
  "moduleId": "900000000000207008",
  "definitionStatus": "PRIMITIVE",
  "descriptions": [
    {
      "active": true,
      "moduleId": "733690761000309105",
      "released": false,
      "descriptionId": "104253741000309115",
      "term": "test concept",
      "conceptId": "706832731000309109",
      "typeId": "900000000000013009",
      "acceptabilityMap": {
        "450828004": "PREFERRED"
      },
      "type": "SYNONYM",
      "lang": "es",
      "caseSignificance": "ENTIRE_TERM_CASE_SENSITIVE"
    },
    {
      "active": true,
      "moduleId": "733690761000309105",
      "released": false,
      "descriptionId": "819473001000309118",
      "term": "test concept (finding)",
      "conceptId": "706832731000309109",
      "typeId": "900000000000003001",
      "acceptabilityMap": {
        "450828004": "PREFERRED"
      },
      "type": "FSN",
      "lang": "es",
      "caseSignificance": "ENTIRE_TERM_CASE_SENSITIVE"
    }
  ],
  "annotations": [],
  "classAxioms": [],
  "gciAxioms": [],
  "relationships": [],
  "alternateIdentifiers": [],
  "validationResults": []
}

As you can see, the descriptions has the proper module Id but the main concept not.

The question is: Do I set the module id manually or not? if so, what is the pourpuse of defaultModuleId?

kaicode commented 6 months ago

It looks like you are right that the core module will be used in the JSON to Java object deserialisation.

kaicode commented 6 months ago

This is a bug. Setting the proper moduleId in the request body would be a good workaround. This is how the SNOMED International authoring UI makes requests. That is why the bug was not discovered sooner. The defaultModuleId is supposed to be used in this case.