public static void dynamoInsertDicom()

in aws-blog-mirth-healthcare-hub/mirth-aws-sample-app/src/main/java/org/mirth/project/MCAWS.java [176:242]


    public static void dynamoInsertDicom(String dicomJson, String mirthTable, String mirthId, String mirthDate) {
        System.out.println( "Performing insert into DynamoDB" );
        String firstName = "EMPTY";
        String lastName = "EMPTY";
        String dob = "EMPTY";
        String docType = "dicom";

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.withRegion(Regions.US_WEST_2);
        DynamoDB dynamoDB = new DynamoDB(client);
        Table table = dynamoDB.getTable(mirthTable);

        try {
        JSONObject obj = new JSONObject(dicomJson);

	//DICOM stores patient name in tag 00100010
        if(obj.has("00100010")) {
                if(obj.getJSONObject("00100010").has("Value")) {
                        JSONArray lastNameArray = obj.getJSONObject("00100010").getJSONArray("Value");
                        if(lastNameArray !=null) {
                                JSONObject lastNameObj = lastNameArray.getJSONObject(0);
                                if(lastNameObj.has("Alphabetic")) {
                                        String patientName = lastNameObj.getString("Alphabetic");
                                        String[] patientNameArray = patientName.split("\\^");

					//some sample DICOM files only have one name string rather than 
					//delimited strings like in production messages.
					//in that case, we use that string as the last name
					//the else statement covers when we have a first and last name
                                        if(patientNameArray.length == 1) {
                                                lastName = lastNameObj.getString("Alphabetic");
                                        } else if(patientNameArray.length > 1) {
                                                lastName = patientNameArray[0];
                                                firstName = patientNameArray[1];
                                                }
                                        }
                                }
                        }
                }

	//DICOM stores Date of Birth in tag 00100030
        if(obj.has("00100030")) {
                if(obj.getJSONObject("00100030").has("Value")) {
                        JSONArray dobArray = obj.getJSONObject("00100030").getJSONArray("Value");
                        if(dobArray !=null) {
				dob = dobArray.getString(0);
                                }
                        }
                }

        } catch (org.json.JSONException e) { System.out.println("JSON ERROR"); }

        //ccdJson = ccdJson.replaceAll("\"\"","\"NONE\"");

        Item item =
            new Item()
                .withPrimaryKey("mirthid", mirthId)
                .withString("mirthdate", mirthDate)
                .withString("type", docType)
                .withString("FirstName", firstName)
                .withString("LastName", lastName)
                .withString("DOB", dob)
                .withString("Processed", "N")
                .withJSON("document", dicomJson);

        table.putItem(item);
    }